]> Shamusworld >> Repos - architektonas/blob - src/penwidget.cpp
Whitespace changes. :-P
[architektonas] / src / penwidget.cpp
1 //
2 // penwidget.cpp: Pen tweaking widget
3 //
4 // Part of the Architektonas Project
5 // (C) 2017 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
7 //
8 // JLH = James Hammons <jlhamm@acm.org>
9 //
10 // WHO  WHEN        WHAT
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/07/2017  Created this file
13 //
14 //maybe add a button to have it stamp attributes on all objects clicked on? [added Global::penStamp to facilitate this.]
15 //need to add to drawingview the ability to use attributes on new objects [DONE]
16 //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 [IN PROGRESS]
17
18 #include "penwidget.h"
19
20 PenWidget::PenWidget(void): QWidget(), width(new QLineEdit("1.0")), red(new QLineEdit("00")), green(new QLineEdit("00")), blue(new QLineEdit("00")), style(new QComboBox), r(0), g(0), b(0), programChange(false), stampAction(new QAction(QIcon(":/res/pen-stamp.png"), tr(""), this)), dropperAction(new QAction(QIcon(":/res/pen-dropper.png"), tr(""), this)), tbStamp(new QToolButton(this)), tbDropper(new QToolButton(this))
21 {
22         QLabel * l1 = new QLabel(tr("Width:"));
23         QLabel * l2 = new QLabel(tr("RGB:"));
24         QLabel * l3 = new QLabel(tr("Style:"));
25
26         stampAction->setToolTip(tr("Stamp Selected"));
27         stampAction->setStatusTip(tr("Stamp selected objects with pen attributes."));
28         stampAction->setShortcut(QKeySequence(tr("p,p")));
29         stampAction->setCheckable(true);
30         tbStamp->setDefaultAction(stampAction);
31
32         dropperAction->setToolTip(tr("Color Picker"));
33         dropperAction->setStatusTip(tr("Get pen attributes from objects."));
34         dropperAction->setShortcut(QKeySequence(tr("d,d")));
35         dropperAction->setCheckable(true);
36         tbDropper->setDefaultAction(dropperAction);
37
38         style->insertItem(1, tr("Solid"));
39         style->insertItem(2, tr("Dash"));
40         style->insertItem(3, tr("Dot"));
41         style->insertItem(4, tr("Dash Dot"));
42         style->insertItem(5, tr("Dash Dot Dot"));
43
44         width->setFixedWidth(72);
45         red->setMaxLength(2);
46         red->setFixedWidth(36);
47         green->setMaxLength(2);
48         green->setFixedWidth(36);
49         blue->setMaxLength(2);
50         blue->setFixedWidth(36);
51
52         red->setInputMask("HH");
53         green->setInputMask("HH");
54         blue->setInputMask("HH");
55
56         red->setToolTip(tr("Sets pen Red component"));
57         green->setToolTip(tr("Sets pen Green component"));
58         blue->setToolTip(tr("Sets pen Blue component"));
59         width->setToolTip(tr("Sets pen width in BU"));
60         style->setToolTip(tr("Sets pen style"));
61
62         QHBoxLayout * hbox1 = new QHBoxLayout;
63         hbox1->addWidget(l2, 0, Qt::AlignLeft);
64         hbox1->addWidget(red, 0, Qt::AlignLeft);
65         hbox1->addWidget(green, 0, Qt::AlignLeft);
66         hbox1->addWidget(blue, 0, Qt::AlignLeft);
67         hbox1->addWidget(l1, 0, Qt::AlignLeft);
68         hbox1->addWidget(width, 0, Qt::AlignLeft);
69         hbox1->addWidget(l3, 0, Qt::AlignLeft);
70         hbox1->addWidget(style, 0, Qt::AlignLeft);
71         hbox1->addWidget(tbStamp, 0, Qt::AlignLeft);
72         hbox1->addWidget(tbDropper, 0, Qt::AlignLeft);
73         hbox1->addStretch(1);
74
75         setLayout(hbox1);
76
77         connect(width, SIGNAL(textEdited(QString)), this, SLOT(HandleWidthSelected(QString)));
78         connect(red, SIGNAL(textEdited(QString)), this, SLOT(HandleRedSelected(QString)));
79         connect(green, SIGNAL(textEdited(QString)), this, SLOT(HandleGreenSelected(QString)));
80         connect(blue, SIGNAL(textEdited(QString)), this, SLOT(HandleBlueSelected(QString)));
81         connect(style, SIGNAL(currentIndexChanged(int)), this, SLOT(HandleStyleSelected(int)));
82 }
83
84 PenWidget::~PenWidget()
85 {
86 }
87
88 void PenWidget::SetFields(Object * obj)
89 {
90         // Sanity check
91         if (obj == NULL)
92                 return;
93
94         // We don't handle groups properly--yet--so punt:
95         if (obj->type == OTContainer)
96                 return;
97
98         r = (obj->color >> 16) & 0xFF;
99         g = (obj->color >> 8) & 0xFF;
100         b = (obj->color >> 0) & 0xFF;
101         width->setText(QString("%1").arg(obj->thickness));
102         red->setText(QString("%1").arg(r, 2, 16, QChar('0')));
103         green->setText(QString("%1").arg(g, 2, 16, QChar('0')));
104         blue->setText(QString("%1").arg(b, 2, 16, QChar('0')));
105         // Styles are 1-indexed while the combobox is 0-indexed
106         programChange = true;
107         style->setCurrentIndex(obj->style - 1);
108         programChange = false;
109 }
110
111 void PenWidget::HandleWidthSelected(QString text)
112 {
113         // Parse the text in the control
114         bool ok;
115         double value = text.toDouble(&ok);
116
117         if (!ok)
118                 return;
119
120         Global::penWidth = value;
121         emit WidthSelected(Global::penWidth);
122 }
123
124 void PenWidget::HandleStyleSelected(int selected)
125 {
126         // Change was programmatic, don't do anything
127         if (programChange)
128                 return;
129
130         // Styles are 1-based, but the combobox is 0-based, so we compensate for
131         // that here
132         Global::penStyle = selected + 1;
133         emit StyleSelected(Global::penStyle);
134 }
135
136 void PenWidget::HandleRedSelected(QString text)
137 {
138         // Parse the text in the control
139         bool ok;
140         int value = text.toInt(&ok, 16);
141
142         if (!ok)
143                 return;
144
145         r = value;
146         Global::penColor = (r << 16) | (g << 8) | b;
147         emit ColorSelected(Global::penColor);
148 }
149
150 void PenWidget::HandleGreenSelected(QString text)
151 {
152         // Parse the text in the control
153         bool ok;
154         int value = text.toInt(&ok, 16);
155
156         if (!ok)
157                 return;
158
159         g = value;
160         Global::penColor = (r << 16) | (g << 8) | b;
161         emit ColorSelected(Global::penColor);
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 }