From: Shamus Hammons Date: Fri, 12 May 2017 03:12:36 +0000 (-0500) Subject: Add pen toolbar widget. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=inline;h=4708212b56a0c5645226e728f9a26ee1fd2d027d;p=architektonas Add pen toolbar widget. Right now, you can change existing objects' attributes. Will probably have to add code to make it so that new objects pick up the attributes in the pen widget. --- diff --git a/architektonas.pro b/architektonas.pro index 5feda56..d79275e 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -62,6 +62,7 @@ HEADERS = \ src/main.h \ src/mathconstants.h \ src/objectwidget.h \ + src/penwidget.h \ src/painter.h \ src/rect.h \ src/settingsdialog.h \ @@ -84,6 +85,7 @@ SOURCES = \ src/layeritemwidget.cpp \ src/main.cpp \ src/objectwidget.cpp \ + src/penwidget.cpp \ src/painter.cpp \ src/rect.cpp \ src/settingsdialog.cpp \ diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 5093fb6..41e2f2c 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -37,6 +37,7 @@ #include "layerwidget.h" #include "objectwidget.h" #include "painter.h" +#include "penwidget.h" #include "settingsdialog.h" #include "structs.h" #include "utils.h" @@ -954,6 +955,15 @@ void ApplicationWindow::CreateToolbars(void) connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(HandleGridSizeInPixels(int))); connect(baseUnitInput, SIGNAL(textChanged(QString)), this, SLOT(HandleGridSizeInBaseUnits(QString))); connect(dimensionSizeInput, SIGNAL(textChanged(QString)), this, SLOT(HandleDimensionSize(QString))); + + PenWidget * pw = new PenWidget(); + toolbar = addToolBar(tr("Pen")); + toolbar->setObjectName(tr("Pen")); + toolbar->addWidget(pw); + connect(drawing, SIGNAL(ObjectSelected(Object *)), pw, SLOT(SetFields(Object *))); + connect(pw, SIGNAL(WidthSelected(float)), drawing, SLOT(HandlePenWidth(float))); + connect(pw, SIGNAL(StyleSelected(int)), drawing, SLOT(HandlePenStyle(int))); + connect(pw, SIGNAL(ColorSelected(uint32_t)), drawing, SLOT(HandlePenColor(uint32_t))); } diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 0ef95dd..30b1591 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -311,6 +311,42 @@ void DrawingView::HandleLayerSwap(int layer1, int layer2) } +void DrawingView::HandlePenWidth(float width) +{ + std::vector::iterator i = select.begin(); + + for(; i!=select.end(); i++) + { + Object * obj = (Object *)(*i); + obj->thickness = width; + } +} + + +void DrawingView::HandlePenStyle(int style) +{ + std::vector::iterator i = select.begin(); + + for(; i!=select.end(); i++) + { + Object * obj = (Object *)(*i); + obj->style = style; + } +} + + +void DrawingView::HandlePenColor(uint32_t color) +{ + std::vector::iterator i = select.begin(); + + for(; i!=select.end(); i++) + { + Object * obj = (Object *)(*i); + obj->color = color; + } +} + + QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event) { // This is undoing the transform, e.g. going from client coords to local @@ -833,7 +869,7 @@ void DrawingView::ToolDraw(Painter * painter) { if (toolPoint[0] == toolPoint[1]) return; - + Point mirrorPoint = toolPoint[0] + Vector(toolPoint[1], toolPoint[0]); painter->DrawLine(mirrorPoint, toolPoint[1]); @@ -1260,6 +1296,9 @@ void DrawingView::mousePressEvent(QMouseEvent * event) dragged = (Object *)hover[0]; draggingObject = true; + // Alert the pen widget + emit(ObjectSelected(dragged)); + // See if anything is using just a straight click on a handle if (HandleObjectClicked()) { diff --git a/src/drawingview.h b/src/drawingview.h index 92ac72a..29a47a7 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -44,9 +44,13 @@ class DrawingView: public QWidget void DeleteCurrentLayer(int); void HandleLayerToggle(void); void HandleLayerSwap(int, int); + void HandlePenWidth(float); + void HandlePenStyle(int); + void HandlePenColor(uint32_t); signals: void ObjectHovered(Object *); + void ObjectSelected(Object *); protected: void paintEvent(QPaintEvent * event); diff --git a/src/penwidget.cpp b/src/penwidget.cpp new file mode 100644 index 0000000..50d90c6 --- /dev/null +++ b/src/penwidget.cpp @@ -0,0 +1,158 @@ +// penwidget.cpp: Pen tweaking widget +// +// Part of the Architektonas Project +// (C) 2017 Underground Software +// See the README and GPLv3 files for licensing and warranty information +// +// JLH = James Hammons +// +// WHO WHEN WHAT +// --- ---------- ----------------------------------------------------------- +// JLH 05/07/2017 Created this file +// + +#include "penwidget.h" + + +PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0) +{ + 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:")); + + style->insertItem(1, tr("Solid")); + style->insertItem(2, tr("Dash")); + style->insertItem(3, tr("Dot")); + style->insertItem(4, tr("Dash Dot")); + style->insertItem(5, tr("Dash Dot Dot")); + + width->setFixedWidth(72); + red->setMaxLength(2); + red->setFixedWidth(36); + green->setMaxLength(2); + green->setFixedWidth(36); + blue->setMaxLength(2); + blue->setFixedWidth(36); + + red->setInputMask("HH"); + green->setInputMask("HH"); + blue->setInputMask("HH"); + + red->setToolTip(tr("Sets pen Red component")); + green->setToolTip(tr("Sets pen Green component")); + blue->setToolTip(tr("Sets pen Blue component")); + width->setToolTip(tr("Sets pen width in BU")); + 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(l3, 0, Qt::AlignLeft); + hbox1->addWidget(style, 0, Qt::AlignLeft); + hbox1->addStretch(1); + + setLayout(hbox1); + + connect(width, SIGNAL(textEdited(QString)), this, SLOT(HandleWidthSelected(QString))); + connect(red, SIGNAL(textEdited(QString)), this, SLOT(HandleRedSelected(QString))); + connect(green, SIGNAL(textEdited(QString)), this, SLOT(HandleGreenSelected(QString))); + connect(blue, SIGNAL(textEdited(QString)), this, SLOT(HandleBlueSelected(QString))); + 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; + 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 + style->setCurrentIndex(obj->style - 1); +} + + +void PenWidget::HandleWidthSelected(QString text) +{ + // Parse the text in the control + bool ok; + double value = text.toDouble(&ok); + + if (!ok) + return; + + emit WidthSelected(value); +} + + +void PenWidget::HandleStyleSelected(int selected) +{ + // Styles are 1-based, but the combobox is 0-based, so we compensate for + // that here + emit StyleSelected(selected + 1); +} + + +void PenWidget::HandleRedSelected(QString text) +{ + // Parse the text in the control + bool ok; + int value = text.toInt(&ok, 16); + + if (!ok) + return; + + r = value; + emit ColorSelected((r << 16) | (g << 8) | b); +} + + +void PenWidget::HandleGreenSelected(QString text) +{ + // Parse the text in the control + bool ok; + int value = text.toInt(&ok, 16); + + if (!ok) + return; + + g = value; + emit ColorSelected((r << 16) | (g << 8) | b); +} + + +void PenWidget::HandleBlueSelected(QString text) +{ + // Parse the text in the control + bool ok; + int value = text.toInt(&ok, 16); + + if (!ok) + return; + + b = value; + emit ColorSelected((r << 16) | (g << 8) | b); +} + diff --git a/src/penwidget.h b/src/penwidget.h new file mode 100644 index 0000000..7f096d9 --- /dev/null +++ b/src/penwidget.h @@ -0,0 +1,41 @@ +#ifndef __PENWIDGET_H__ +#define __PENWIDGET_H__ + +#include +#include "structs.h" + + +class PenWidget: public QWidget +{ + Q_OBJECT + + public: + PenWidget(void); + ~PenWidget(); + + public slots: + void SetFields(Object *); + + private slots: + void HandleWidthSelected(QString); + void HandleStyleSelected(int); + void HandleRedSelected(QString); + void HandleGreenSelected(QString); + void HandleBlueSelected(QString); + + signals: + void WidthSelected(float); + void StyleSelected(int); + void ColorSelected(uint32_t); + + private: + QLineEdit * width; + QLineEdit * red; + QLineEdit * green; + QLineEdit * blue; + QComboBox * style; + int r, g, b; +}; + +#endif // __PENWIDGET_H__ +