2 // penwidget.cpp: Pen tweaking widget
4 // Part of the Architektonas Project
5 // (C) 2017 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
8 // JLH = James Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/07/2017 Created this file
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]
18 #include "penwidget.h"
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))
22 QLabel * l1 = new QLabel(tr("Width:"));
23 QLabel * l2 = new QLabel(tr("RGB:"));
24 QLabel * l3 = new QLabel(tr("Style:"));
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);
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);
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"));
44 width->setFixedWidth(72);
46 red->setFixedWidth(36);
47 green->setMaxLength(2);
48 green->setFixedWidth(36);
49 blue->setMaxLength(2);
50 blue->setFixedWidth(36);
52 red->setInputMask("HH");
53 green->setInputMask("HH");
54 blue->setInputMask("HH");
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"));
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);
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)));
84 PenWidget::~PenWidget()
88 void PenWidget::SetFields(Object * obj)
94 // We don't handle groups properly--yet--so punt:
95 if (obj->type == OTContainer)
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;
111 void PenWidget::HandleWidthSelected(QString text)
113 // Parse the text in the control
115 double value = text.toDouble(&ok);
120 Global::penWidth = value;
121 emit WidthSelected(Global::penWidth);
124 void PenWidget::HandleStyleSelected(int selected)
126 // Change was programmatic, don't do anything
130 // Styles are 1-based, but the combobox is 0-based, so we compensate for
132 Global::penStyle = selected + 1;
133 emit StyleSelected(Global::penStyle);
136 void PenWidget::HandleRedSelected(QString text)
138 // Parse the text in the control
140 int value = text.toInt(&ok, 16);
146 Global::penColor = (r << 16) | (g << 8) | b;
147 emit ColorSelected(Global::penColor);
150 void PenWidget::HandleGreenSelected(QString text)
152 // Parse the text in the control
154 int value = text.toInt(&ok, 16);
160 Global::penColor = (r << 16) | (g << 8) | b;
161 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);