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:"));
32 QToolButton * qtb = new QToolButton(this);
34 QAction * action = new QAction(QIcon(":/res/pen-stamp.png"), tr(""), this);
35 action->setToolTip(tr("Stamp Selected"));
36 action->setStatusTip(tr("Stamp selected objects with pen attributes."));
37 action->setShortcut(QKeySequence(tr("p,p")));
38 // action->setCheckable(checkable);
39 qtb->setDefaultAction(action);
41 style->insertItem(1, tr("Solid"));
42 style->insertItem(2, tr("Dash"));
43 style->insertItem(3, tr("Dot"));
44 style->insertItem(4, tr("Dash Dot"));
45 style->insertItem(5, tr("Dash Dot Dot"));
47 width->setFixedWidth(72);
49 red->setFixedWidth(36);
50 green->setMaxLength(2);
51 green->setFixedWidth(36);
52 blue->setMaxLength(2);
53 blue->setFixedWidth(36);
55 red->setInputMask("HH");
56 green->setInputMask("HH");
57 blue->setInputMask("HH");
59 red->setToolTip(tr("Sets pen Red component"));
60 green->setToolTip(tr("Sets pen Green component"));
61 blue->setToolTip(tr("Sets pen Blue component"));
62 width->setToolTip(tr("Sets pen width in BU"));
63 style->setToolTip(tr("Sets pen style"));
65 QHBoxLayout * hbox1 = new QHBoxLayout;
66 hbox1->addWidget(l1, 0, Qt::AlignLeft);
67 hbox1->addWidget(width, 0, Qt::AlignLeft);
68 hbox1->addWidget(l2, 0, Qt::AlignLeft);
69 hbox1->addWidget(red, 0, Qt::AlignLeft);
70 hbox1->addWidget(green, 0, Qt::AlignLeft);
71 hbox1->addWidget(blue, 0, Qt::AlignLeft);
72 hbox1->addWidget(l3, 0, Qt::AlignLeft);
73 hbox1->addWidget(style, 0, Qt::AlignLeft);
74 hbox1->addWidget(qtb, 0, Qt::AlignLeft);
79 connect(width, SIGNAL(textEdited(QString)), this, SLOT(HandleWidthSelected(QString)));
80 connect(red, SIGNAL(textEdited(QString)), this, SLOT(HandleRedSelected(QString)));
81 connect(green, SIGNAL(textEdited(QString)), this, SLOT(HandleGreenSelected(QString)));
82 connect(blue, SIGNAL(textEdited(QString)), this, SLOT(HandleBlueSelected(QString)));
83 connect(style, SIGNAL(currentIndexChanged(int)), this, SLOT(HandleStyleSelected(int)));
84 connect(qtb, SIGNAL(triggered(QAction *)), this, SLOT(HandleStamp(QAction *)));
88 PenWidget::~PenWidget()
93 void PenWidget::SetFields(Object * obj)
99 // We don't handle groups properly--yet--so punt:
100 if (obj->type == OTContainer)
103 r = (obj->color >> 16) & 0xFF;
104 g = (obj->color >> 8) & 0xFF;
105 b = (obj->color >> 0) & 0xFF;
106 width->setText(QString("%1").arg(obj->thickness));
107 red->setText(QString("%1").arg(r, 2, 16, QChar('0')));
108 green->setText(QString("%1").arg(g, 2, 16, QChar('0')));
109 blue->setText(QString("%1").arg(b, 2, 16, QChar('0')));
110 // Styles are 1-indexed while the combobox is 0-indexed
111 programChange = true;
112 style->setCurrentIndex(obj->style - 1);
113 programChange = false;
117 void PenWidget::HandleWidthSelected(QString text)
119 // Parse the text in the control
121 double value = text.toDouble(&ok);
126 Global::penWidth = value;
127 emit WidthSelected(Global::penWidth);
131 void PenWidget::HandleStyleSelected(int selected)
133 // Change was programmatic, don't do anything
137 // Styles are 1-based, but the combobox is 0-based, so we compensate for
139 Global::penStyle = selected + 1;
140 emit StyleSelected(Global::penStyle);
144 void PenWidget::HandleRedSelected(QString text)
146 // Parse the text in the control
148 int value = text.toInt(&ok, 16);
154 Global::penColor = (r << 16) | (g << 8) | b;
155 emit ColorSelected(Global::penColor);
159 void PenWidget::HandleGreenSelected(QString text)
161 // Parse the text in the control
163 int value = text.toInt(&ok, 16);
169 Global::penColor = (r << 16) | (g << 8) | b;
170 emit ColorSelected(Global::penColor);
174 void PenWidget::HandleBlueSelected(QString text)
176 // Parse the text in the control
178 int value = text.toInt(&ok, 16);
184 Global::penColor = (r << 16) | (g << 8) | b;
185 emit ColorSelected(Global::penColor);
189 void PenWidget::HandleStamp(QAction * /* action */)
191 emit StampSelected();