]> Shamusworld >> Repos - architektonas/commitdiff
Add pen toolbar widget.
authorShamus Hammons <jlhamm@acm.org>
Fri, 12 May 2017 03:12:36 +0000 (22:12 -0500)
committerShamus Hammons <jlhamm@acm.org>
Fri, 12 May 2017 03:12:36 +0000 (22:12 -0500)
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.

architektonas.pro
src/applicationwindow.cpp
src/drawingview.cpp
src/drawingview.h
src/penwidget.cpp [new file with mode: 0644]
src/penwidget.h [new file with mode: 0644]

index 5feda569c159da471b70bb5a537ec7eac0907e78..d79275eefcadd61bec3c5b80dada29a802edf8ab 100644 (file)
@@ -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 \
index 5093fb6c3b5334e475064af01dd8584a1fbbb7d4..41e2f2c8a90176efa535fdcbce96d6fb9f13e030 100644 (file)
@@ -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)));
 }
 
 
index 0ef95dd7edece441097e24590038ed8fe4d550ab..30b159172248d04c0e87e75d6396f1f629bca807 100644 (file)
@@ -311,6 +311,42 @@ void DrawingView::HandleLayerSwap(int layer1, int layer2)
 }
 
 
+void DrawingView::HandlePenWidth(float width)
+{
+       std::vector<void *>::iterator i = select.begin();
+
+       for(; i!=select.end(); i++)
+       {
+               Object * obj = (Object *)(*i);
+               obj->thickness = width;
+       }
+}
+
+
+void DrawingView::HandlePenStyle(int style)
+{
+       std::vector<void *>::iterator i = select.begin();
+
+       for(; i!=select.end(); i++)
+       {
+               Object * obj = (Object *)(*i);
+               obj->style = style;
+       }
+}
+
+
+void DrawingView::HandlePenColor(uint32_t color)
+{
+       std::vector<void *>::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())
                        {
index 92ac72a692abc14945124569c45d8d6a699f66c4..29a47a7083e7c2f801d5deda81e6c1f3d543fd03 100644 (file)
@@ -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 (file)
index 0000000..50d90c6
--- /dev/null
@@ -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 <jlhamm@acm.org>
+//
+// 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 (file)
index 0000000..7f096d9
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef __PENWIDGET_H__
+#define __PENWIDGET_H__
+
+#include <QtWidgets>
+#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__
+