]> Shamusworld >> Repos - architektonas/blob - src/penwidget.cpp
2a557e39d150f54ab48e080eace9d234d0425aee
[architektonas] / src / penwidget.cpp
1 // penwidget.cpp: Pen tweaking widget
2 //
3 // Part of the Architektonas Project
4 // (C) 2017 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // WHO  WHEN        WHAT
10 // ---  ----------  -----------------------------------------------------------
11 // JLH  05/07/2017  Created this file
12 //
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
16
17
18 #include "penwidget.h"
19
20
21 PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0), programChange(false)
22 {
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;
28
29         QLabel * l1 = new QLabel(tr("Width:"));
30         QLabel * l2 = new QLabel(tr("RGB:"));
31         QLabel * l3 = new QLabel(tr("Style:"));
32
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"));
38
39         width->setFixedWidth(72);
40         red->setMaxLength(2);
41         red->setFixedWidth(36);
42         green->setMaxLength(2);
43         green->setFixedWidth(36);
44         blue->setMaxLength(2);
45         blue->setFixedWidth(36);
46
47         red->setInputMask("HH");
48         green->setInputMask("HH");
49         blue->setInputMask("HH");
50
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"));
56
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);
66         hbox1->addStretch(1);
67
68         setLayout(hbox1);
69
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)));
75 }
76
77
78 PenWidget::~PenWidget()
79 {
80 }
81
82
83 void PenWidget::SetFields(Object * obj)
84 {
85         // Sanity check
86         if (obj == NULL)
87                 return;
88
89         // We don't handle groups properly--yet--so punt:
90         if (obj->type == OTContainer)
91                 return;
92
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;
104 }
105
106
107 void PenWidget::HandleWidthSelected(QString text)
108 {
109         // Parse the text in the control
110         bool ok;
111         double value = text.toDouble(&ok);
112
113         if (!ok)
114                 return;
115
116         Global::penWidth = value;
117         emit WidthSelected(Global::penWidth);
118 }
119
120
121 void PenWidget::HandleStyleSelected(int selected)
122 {
123         // Change was programmatic, don't do anything
124         if (programChange)
125                 return;
126
127         // Styles are 1-based, but the combobox is 0-based, so we compensate for
128         // that here
129         Global::penStyle = selected + 1;
130         emit StyleSelected(Global::penStyle);
131 }
132
133
134 void PenWidget::HandleRedSelected(QString text)
135 {
136         // Parse the text in the control
137         bool ok;
138         int value = text.toInt(&ok, 16);
139
140         if (!ok)
141                 return;
142
143         r = value;
144         Global::penColor = (r << 16) | (g << 8) | b;
145         emit ColorSelected(Global::penColor);
146 }
147
148
149 void PenWidget::HandleGreenSelected(QString text)
150 {
151         // Parse the text in the control
152         bool ok;
153         int value = text.toInt(&ok, 16);
154
155         if (!ok)
156                 return;
157
158         g = value;
159         Global::penColor = (r << 16) | (g << 8) | b;
160         emit ColorSelected(Global::penColor);
161 }
162
163
164 void PenWidget::HandleBlueSelected(QString text)
165 {
166         // Parse the text in the control
167         bool ok;
168         int value = text.toInt(&ok, 16);
169
170         if (!ok)
171                 return;
172
173         b = value;
174         Global::penColor = (r << 16) | (g << 8) | b;
175         emit ColorSelected(Global::penColor);
176 }
177