#include "layerwidget.h"
#include "objectwidget.h"
#include "painter.h"
+#include "penwidget.h"
#include "settingsdialog.h"
#include "structs.h"
#include "utils.h"
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)));
}
}
+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
{
if (toolPoint[0] == toolPoint[1])
return;
-
+
Point mirrorPoint = toolPoint[0] + Vector(toolPoint[1], toolPoint[0]);
painter->DrawLine(mirrorPoint, toolPoint[1]);
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())
{
--- /dev/null
+// 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);
+}
+