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 "pen" pallete, to hold most frequently used pen colors/styles
17 #include "penwidget.h"
19 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 QLabel * l1 = new QLabel(tr("Width:"));
22 QLabel * l2 = new QLabel(tr("RGB:"));
23 QLabel * l3 = new QLabel(tr("Style:"));
25 stampAction->setToolTip(tr("Stamp Selected"));
26 stampAction->setStatusTip(tr("Stamp selected objects with pen attributes."));
27 stampAction->setShortcut(QKeySequence(tr("p,p")));
28 stampAction->setCheckable(true);
29 tbStamp->setDefaultAction(stampAction);
31 dropperAction->setToolTip(tr("Color Picker"));
32 dropperAction->setStatusTip(tr("Get pen attributes from objects."));
33 dropperAction->setShortcut(QKeySequence(tr("d,d")));
34 dropperAction->setCheckable(true);
35 tbDropper->setDefaultAction(dropperAction);
37 style->insertItem(1, tr("Solid"));
38 style->insertItem(2, tr("Dash"));
39 style->insertItem(3, tr("Dot"));
40 style->insertItem(4, tr("Dash Dot"));
41 style->insertItem(5, tr("Dash Dot Dot"));
43 width->setFixedWidth(72);
45 red->setFixedWidth(36);
46 green->setMaxLength(2);
47 green->setFixedWidth(36);
48 blue->setMaxLength(2);
49 blue->setFixedWidth(36);
51 red->setInputMask("HH");
52 green->setInputMask("HH");
53 blue->setInputMask("HH");
55 red->setToolTip(tr("Sets pen Red component"));
56 green->setToolTip(tr("Sets pen Green component"));
57 blue->setToolTip(tr("Sets pen Blue component"));
58 width->setToolTip(tr("Sets pen width in BU"));
59 style->setToolTip(tr("Sets pen style"));
61 QHBoxLayout * hbox1 = new QHBoxLayout;
62 hbox1->addWidget(l2, 0, Qt::AlignLeft);
63 hbox1->addWidget(red, 0, Qt::AlignLeft);
64 hbox1->addWidget(green, 0, Qt::AlignLeft);
65 hbox1->addWidget(blue, 0, Qt::AlignLeft);
66 hbox1->addWidget(l1, 0, Qt::AlignLeft);
67 hbox1->addWidget(width, 0, Qt::AlignLeft);
68 hbox1->addWidget(l3, 0, Qt::AlignLeft);
69 hbox1->addWidget(style, 0, Qt::AlignLeft);
70 hbox1->addWidget(tbStamp, 0, Qt::AlignLeft);
71 hbox1->addWidget(tbDropper, 0, Qt::AlignLeft);
76 connect(width, SIGNAL(textEdited(QString)), this, SLOT(HandleWidthSelected(QString)));
77 connect(red, SIGNAL(textEdited(QString)), this, SLOT(HandleRedSelected(QString)));
78 connect(green, SIGNAL(textEdited(QString)), this, SLOT(HandleGreenSelected(QString)));
79 connect(blue, SIGNAL(textEdited(QString)), this, SLOT(HandleBlueSelected(QString)));
80 connect(style, SIGNAL(currentIndexChanged(int)), this, SLOT(HandleStyleSelected(int)));
83 PenWidget::~PenWidget()
87 void PenWidget::SetFields(Object * obj)
93 // We don't handle groups properly--yet--so punt:
94 if (obj->type == OTContainer)
97 r = (obj->color >> 16) & 0xFF;
98 g = (obj->color >> 8) & 0xFF;
99 b = (obj->color >> 0) & 0xFF;
100 width->setText(QString("%1").arg(obj->thickness));
101 red->setText(QString("%1").arg(r, 2, 16, QChar('0')));
102 green->setText(QString("%1").arg(g, 2, 16, QChar('0')));
103 blue->setText(QString("%1").arg(b, 2, 16, QChar('0')));
104 // Styles are 1-indexed while the combobox is 0-indexed
105 programChange = true;
106 style->setCurrentIndex(obj->style - 1);
107 programChange = false;
110 void PenWidget::HandleWidthSelected(QString text)
112 // Parse the text in the control
114 double value = text.toDouble(&ok);
119 Global::penWidth = value;
122 void PenWidget::HandleStyleSelected(int selected)
124 // Change was programmatic, don't do anything
128 // Styles are 1-based, but the combobox is 0-based, so we compensate for
130 Global::penStyle = selected + 1;
133 void PenWidget::HandleRedSelected(QString text)
135 // Parse the text in the control
137 int value = text.toInt(&ok, 16);
143 Global::penColor = (r << 16) | (g << 8) | b;
146 void PenWidget::HandleGreenSelected(QString text)
148 // Parse the text in the control
150 int value = text.toInt(&ok, 16);
156 Global::penColor = (r << 16) | (g << 8) | b;
159 void PenWidget::HandleBlueSelected(QString text)
161 // Parse the text in the control
163 int value = text.toInt(&ok, 16);
169 Global::penColor = (r << 16) | (g << 8) | b;