X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpenwidget.cpp;h=65da6bb6034ea689b02778cdcfa5ffd30ef04116;hb=cdde036d71eb0ea9b450345bd297c8730591b26b;hp=50d90c6d52484ffecc7f7b532bce0834dfb69246;hpb=4708212b56a0c5645226e728f9a26ee1fd2d027d;p=architektonas diff --git a/src/penwidget.cpp b/src/penwidget.cpp index 50d90c6..65da6bb 100644 --- a/src/penwidget.cpp +++ b/src/penwidget.cpp @@ -1,3 +1,4 @@ +// // penwidget.cpp: Pen tweaking widget // // Part of the Architektonas Project @@ -10,22 +11,29 @@ // --- ---------- ----------------------------------------------------------- // JLH 05/07/2017 Created this file // +// Maybe add a "pen" pallete, to hold most frequently used pen colors/styles +// #include "penwidget.h" - -PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0) +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)) { - width = new QLineEdit("1.0"); - red = new QLineEdit("00"); - green = new QLineEdit("00"); - blue = new QLineEdit("00"); - style = new QComboBox; - QLabel * l1 = new QLabel(tr("Width:")); QLabel * l2 = new QLabel(tr("RGB:")); QLabel * l3 = new QLabel(tr("Style:")); + stampAction->setToolTip(tr("Stamp Selected")); + stampAction->setStatusTip(tr("Stamp selected objects with pen attributes.")); + stampAction->setShortcut(QKeySequence(tr("p,p"))); + stampAction->setCheckable(true); + tbStamp->setDefaultAction(stampAction); + + dropperAction->setToolTip(tr("Color Picker")); + dropperAction->setStatusTip(tr("Get pen attributes from objects.")); + dropperAction->setShortcut(QKeySequence(tr("d,d"))); + dropperAction->setCheckable(true); + tbDropper->setDefaultAction(dropperAction); + style->insertItem(1, tr("Solid")); style->insertItem(2, tr("Dash")); style->insertItem(3, tr("Dot")); @@ -51,14 +59,16 @@ PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0) style->setToolTip(tr("Sets pen style")); QHBoxLayout * hbox1 = new QHBoxLayout; - hbox1->addWidget(l1, 0, Qt::AlignLeft); - hbox1->addWidget(width, 0, Qt::AlignLeft); hbox1->addWidget(l2, 0, Qt::AlignLeft); hbox1->addWidget(red, 0, Qt::AlignLeft); hbox1->addWidget(green, 0, Qt::AlignLeft); hbox1->addWidget(blue, 0, Qt::AlignLeft); + hbox1->addWidget(l1, 0, Qt::AlignLeft); + hbox1->addWidget(width, 0, Qt::AlignLeft); hbox1->addWidget(l3, 0, Qt::AlignLeft); hbox1->addWidget(style, 0, Qt::AlignLeft); + hbox1->addWidget(tbStamp, 0, Qt::AlignLeft); + hbox1->addWidget(tbDropper, 0, Qt::AlignLeft); hbox1->addStretch(1); setLayout(hbox1); @@ -70,30 +80,33 @@ PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0) connect(style, SIGNAL(currentIndexChanged(int)), this, SLOT(HandleStyleSelected(int))); } - PenWidget::~PenWidget() { } - void PenWidget::SetFields(Object * obj) { // Sanity check if (obj == NULL) return; - int r = (obj->color >> 16) & 0xFF; - int g = (obj->color >> 8) & 0xFF; - int b = (obj->color >> 0) & 0xFF; + // We don't handle groups properly--yet--so punt: + if (obj->type == OTContainer) + return; + + r = (obj->color >> 16) & 0xFF; + g = (obj->color >> 8) & 0xFF; + b = (obj->color >> 0) & 0xFF; width->setText(QString("%1").arg(obj->thickness)); red->setText(QString("%1").arg(r, 2, 16, QChar('0'))); green->setText(QString("%1").arg(g, 2, 16, QChar('0'))); blue->setText(QString("%1").arg(b, 2, 16, QChar('0'))); // Styles are 1-indexed while the combobox is 0-indexed + programChange = true; style->setCurrentIndex(obj->style - 1); + programChange = false; } - void PenWidget::HandleWidthSelected(QString text) { // Parse the text in the control @@ -103,18 +116,20 @@ void PenWidget::HandleWidthSelected(QString text) if (!ok) return; - emit WidthSelected(value); + Global::penWidth = value; } - void PenWidget::HandleStyleSelected(int selected) { + // Change was programmatic, don't do anything + if (programChange) + return; + // Styles are 1-based, but the combobox is 0-based, so we compensate for // that here - emit StyleSelected(selected + 1); + Global::penStyle = selected + 1; } - void PenWidget::HandleRedSelected(QString text) { // Parse the text in the control @@ -125,10 +140,9 @@ void PenWidget::HandleRedSelected(QString text) return; r = value; - emit ColorSelected((r << 16) | (g << 8) | b); + Global::penColor = (r << 16) | (g << 8) | b; } - void PenWidget::HandleGreenSelected(QString text) { // Parse the text in the control @@ -139,10 +153,9 @@ void PenWidget::HandleGreenSelected(QString text) return; g = value; - emit ColorSelected((r << 16) | (g << 8) | b); + Global::penColor = (r << 16) | (g << 8) | b; } - void PenWidget::HandleBlueSelected(QString text) { // Parse the text in the control @@ -153,6 +166,5 @@ void PenWidget::HandleBlueSelected(QString text) return; b = value; - emit ColorSelected((r << 16) | (g << 8) | b); + Global::penColor = (r << 16) | (g << 8) | b; } -