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
14 #include "penwidget.h"
17 PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0)
19 width = new QLineEdit("1.0");
20 red = new QLineEdit("00");
21 green = new QLineEdit("00");
22 blue = new QLineEdit("00");
23 style = new QComboBox;
25 QLabel * l1 = new QLabel(tr("Width:"));
26 QLabel * l2 = new QLabel(tr("RGB:"));
27 QLabel * l3 = new QLabel(tr("Style:"));
29 style->insertItem(1, tr("Solid"));
30 style->insertItem(2, tr("Dash"));
31 style->insertItem(3, tr("Dot"));
32 style->insertItem(4, tr("Dash Dot"));
33 style->insertItem(5, tr("Dash Dot Dot"));
35 width->setFixedWidth(72);
37 red->setFixedWidth(36);
38 green->setMaxLength(2);
39 green->setFixedWidth(36);
40 blue->setMaxLength(2);
41 blue->setFixedWidth(36);
43 red->setInputMask("HH");
44 green->setInputMask("HH");
45 blue->setInputMask("HH");
47 red->setToolTip(tr("Sets pen Red component"));
48 green->setToolTip(tr("Sets pen Green component"));
49 blue->setToolTip(tr("Sets pen Blue component"));
50 width->setToolTip(tr("Sets pen width in BU"));
51 style->setToolTip(tr("Sets pen style"));
53 QHBoxLayout * hbox1 = new QHBoxLayout;
54 hbox1->addWidget(l1, 0, Qt::AlignLeft);
55 hbox1->addWidget(width, 0, Qt::AlignLeft);
56 hbox1->addWidget(l2, 0, Qt::AlignLeft);
57 hbox1->addWidget(red, 0, Qt::AlignLeft);
58 hbox1->addWidget(green, 0, Qt::AlignLeft);
59 hbox1->addWidget(blue, 0, Qt::AlignLeft);
60 hbox1->addWidget(l3, 0, Qt::AlignLeft);
61 hbox1->addWidget(style, 0, Qt::AlignLeft);
66 connect(width, SIGNAL(textEdited(QString)), this, SLOT(HandleWidthSelected(QString)));
67 connect(red, SIGNAL(textEdited(QString)), this, SLOT(HandleRedSelected(QString)));
68 connect(green, SIGNAL(textEdited(QString)), this, SLOT(HandleGreenSelected(QString)));
69 connect(blue, SIGNAL(textEdited(QString)), this, SLOT(HandleBlueSelected(QString)));
70 connect(style, SIGNAL(currentIndexChanged(int)), this, SLOT(HandleStyleSelected(int)));
74 PenWidget::~PenWidget()
79 void PenWidget::SetFields(Object * obj)
85 int r = (obj->color >> 16) & 0xFF;
86 int g = (obj->color >> 8) & 0xFF;
87 int b = (obj->color >> 0) & 0xFF;
88 width->setText(QString("%1").arg(obj->thickness));
89 red->setText(QString("%1").arg(r, 2, 16, QChar('0')));
90 green->setText(QString("%1").arg(g, 2, 16, QChar('0')));
91 blue->setText(QString("%1").arg(b, 2, 16, QChar('0')));
92 // Styles are 1-indexed while the combobox is 0-indexed
93 style->setCurrentIndex(obj->style - 1);
97 void PenWidget::HandleWidthSelected(QString text)
99 // Parse the text in the control
101 double value = text.toDouble(&ok);
106 emit WidthSelected(value);
110 void PenWidget::HandleStyleSelected(int selected)
112 // Styles are 1-based, but the combobox is 0-based, so we compensate for
114 emit StyleSelected(selected + 1);
118 void PenWidget::HandleRedSelected(QString text)
120 // Parse the text in the control
122 int value = text.toInt(&ok, 16);
128 emit ColorSelected((r << 16) | (g << 8) | b);
132 void PenWidget::HandleGreenSelected(QString text)
134 // Parse the text in the control
136 int value = text.toInt(&ok, 16);
142 emit ColorSelected((r << 16) | (g << 8) | b);
146 void PenWidget::HandleBlueSelected(QString text)
148 // Parse the text in the control
150 int value = text.toInt(&ok, 16);
156 emit ColorSelected((r << 16) | (g << 8) | b);