1 // penwidget.cpp: Pen tweaking widget
3 // Part of the Architektonas Project
4 // (C) 2017 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
7 // JLH = James Hammons <jlhamm@acm.org>
10 // --- ---------- -----------------------------------------------------------
11 // JLH 05/07/2017 Created this file
13 //maybe add a button to have it stamp attributes on all objects clicked on? [added Global::penStamp to facilitate this.]
14 //need to add to drawingview the ability to use attributes on new objects [DONE]
15 //need to override the selection so you can see the attributes effects immediately when they are changed instead of having to deselect them to see
18 #include "penwidget.h"
21 PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0), programChange(false)
23 width = new QLineEdit("1.0");
24 red = new QLineEdit("00");
25 green = new QLineEdit("00");
26 blue = new QLineEdit("00");
27 style = new QComboBox;
29 QLabel * l1 = new QLabel(tr("Width:"));
30 QLabel * l2 = new QLabel(tr("RGB:"));
31 QLabel * l3 = new QLabel(tr("Style:"));
33 style->insertItem(1, tr("Solid"));
34 style->insertItem(2, tr("Dash"));
35 style->insertItem(3, tr("Dot"));
36 style->insertItem(4, tr("Dash Dot"));
37 style->insertItem(5, tr("Dash Dot Dot"));
39 width->setFixedWidth(72);
41 red->setFixedWidth(36);
42 green->setMaxLength(2);
43 green->setFixedWidth(36);
44 blue->setMaxLength(2);
45 blue->setFixedWidth(36);
47 red->setInputMask("HH");
48 green->setInputMask("HH");
49 blue->setInputMask("HH");
51 red->setToolTip(tr("Sets pen Red component"));
52 green->setToolTip(tr("Sets pen Green component"));
53 blue->setToolTip(tr("Sets pen Blue component"));
54 width->setToolTip(tr("Sets pen width in BU"));
55 style->setToolTip(tr("Sets pen style"));
57 QHBoxLayout * hbox1 = new QHBoxLayout;
58 hbox1->addWidget(l1, 0, Qt::AlignLeft);
59 hbox1->addWidget(width, 0, Qt::AlignLeft);
60 hbox1->addWidget(l2, 0, Qt::AlignLeft);
61 hbox1->addWidget(red, 0, Qt::AlignLeft);
62 hbox1->addWidget(green, 0, Qt::AlignLeft);
63 hbox1->addWidget(blue, 0, Qt::AlignLeft);
64 hbox1->addWidget(l3, 0, Qt::AlignLeft);
65 hbox1->addWidget(style, 0, Qt::AlignLeft);
70 connect(width, SIGNAL(textEdited(QString)), this, SLOT(HandleWidthSelected(QString)));
71 connect(red, SIGNAL(textEdited(QString)), this, SLOT(HandleRedSelected(QString)));
72 connect(green, SIGNAL(textEdited(QString)), this, SLOT(HandleGreenSelected(QString)));
73 connect(blue, SIGNAL(textEdited(QString)), this, SLOT(HandleBlueSelected(QString)));
74 connect(style, SIGNAL(currentIndexChanged(int)), this, SLOT(HandleStyleSelected(int)));
78 PenWidget::~PenWidget()
83 void PenWidget::SetFields(Object * obj)
89 // We don't handle groups properly--yet--so punt:
90 if (obj->type == OTContainer)
93 r = (obj->color >> 16) & 0xFF;
94 g = (obj->color >> 8) & 0xFF;
95 b = (obj->color >> 0) & 0xFF;
96 width->setText(QString("%1").arg(obj->thickness));
97 red->setText(QString("%1").arg(r, 2, 16, QChar('0')));
98 green->setText(QString("%1").arg(g, 2, 16, QChar('0')));
99 blue->setText(QString("%1").arg(b, 2, 16, QChar('0')));
100 // Styles are 1-indexed while the combobox is 0-indexed
101 programChange = true;
102 style->setCurrentIndex(obj->style - 1);
103 programChange = false;
107 void PenWidget::HandleWidthSelected(QString text)
109 // Parse the text in the control
111 double value = text.toDouble(&ok);
116 Global::penWidth = value;
117 emit WidthSelected(Global::penWidth);
121 void PenWidget::HandleStyleSelected(int selected)
123 // Change was programmatic, don't do anything
127 // Styles are 1-based, but the combobox is 0-based, so we compensate for
129 Global::penStyle = selected + 1;
130 emit StyleSelected(Global::penStyle);
134 void PenWidget::HandleRedSelected(QString text)
136 // Parse the text in the control
138 int value = text.toInt(&ok, 16);
144 Global::penColor = (r << 16) | (g << 8) | b;
145 emit ColorSelected(Global::penColor);
149 void PenWidget::HandleGreenSelected(QString text)
151 // Parse the text in the control
153 int value = text.toInt(&ok, 16);
159 Global::penColor = (r << 16) | (g << 8) | b;
160 emit ColorSelected(Global::penColor);
164 void PenWidget::HandleBlueSelected(QString text)
166 // Parse the text in the control
168 int value = text.toInt(&ok, 16);
174 Global::penColor = (r << 16) | (g << 8) | b;
175 emit ColorSelected(Global::penColor);