From: Shamus Hammons Date: Tue, 27 Aug 2013 23:56:38 +0000 (-0500) Subject: Beginning to make the Layer widget functional. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=642cf72c11b49a9e00128ab6258a2438c785a5ab Beginning to make the Layer widget functional. Basically all you can do is add a layer; nothing else works though it does notify the DrawingView when the selection changes. Also added infrastructure to the Object class to support layers. Every Object now has a layer attribute. --- diff --git a/TODO b/TODO index 48c82e3..c54924f 100644 --- a/TODO +++ b/TODO @@ -18,7 +18,7 @@ Stuff To Be Implemented/Fixed - Add fill/hatch to Objects - Fix zooming to be more intuitive - Add other Dimension types, like radial, diametric, leader - - Mirror tool + - Mirror tool (started, needs actual mirroring implementation) - Restrict movement horizontal/vertical tool - Trim tool - Fix Arc manipulator. Idea: split edge handles so that the inner half controls diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 8220a0e..bf9baf4 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -85,6 +85,8 @@ ApplicationWindow::ApplicationWindow(): ReadSettings(); setUnifiedTitleAndToolBarOnMac(true); Object::SetFont(new QFont("Verdana", 15, QFont::Bold)); + + connect(lw, SIGNAL(LayerSelected(int)), drawing, SLOT(SetCurrentLayer(int))); } diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 9572117..3020368 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -49,8 +49,8 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), document(Vector(0, 0)), /*gridSpacing(12.0),*/ gridPixels(0), collided(false), rotateTool(false), rx(150.0), ry(150.0), - scrollDrag(false), addLineTool(false), addCircleTool(false), - addDimensionTool(false), +// scrollDrag(false), addLineTool(false), addCircleTool(false), +// addDimensionTool(false), toolAction(NULL) { document.isTopLevelContainer = true; @@ -266,6 +266,13 @@ void DrawingView::AddNewObjectToDocument(Object * object) } +void DrawingView::SetCurrentLayer(int layer) +{ + Object::currentLayer = layer; +//printf("DrawingView::CurrentLayer = %i\n", layer); +} + + QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event) { // This is undoing the transform, e.g. going from client coords to local coords. diff --git a/src/drawingview.h b/src/drawingview.h index da1912f..55384fa 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -15,19 +15,13 @@ class DrawingView: public QWidget public: void SetRotateToolActive(bool state = true); -#if 0 - void SetAddLineToolActive(bool state = true); - void SetAddCircleToolActive(bool state = true); - void SetAddArcToolActive(bool state = true); - void SetAddDimensionToolActive(bool state = true); -#endif -// void SetToolActive(Action * action, bool state = true); - void SetToolActive(Action * action);//, bool state = true); + void SetToolActive(Action * action); void SetGridSize(uint32_t); void UpdateGridBackground(void); public slots: void AddNewObjectToDocument(Object *); + void SetCurrentLayer(int); protected: void paintEvent(QPaintEvent * event); @@ -41,21 +35,17 @@ class DrawingView: public QWidget private: QPoint GetAdjustedMousePosition(QMouseEvent * event); QPoint GetAdjustedClientPosition(int x, int y); -// Vector SnapPointToGrid(Vector); public: bool useAntialiasing; private: -// QBrush * backgroundBrush; QPixmap gridBackground; double scale; // Window scaling factor int32_t offsetX, offsetY; // Window offsets public: Container document; -// double gridSpacing; // Grid spacing in base units uint32_t gridPixels; // Grid size in pixels -// double gridBaseUnits; // Grid size in base units private: bool collided; //Should this go into Object's class variables??? @@ -64,9 +54,9 @@ class DrawingView: public QWidget double rx, ry; bool scrollDrag; Vector oldPoint; - bool addLineTool; - bool addCircleTool; - bool addDimensionTool; +// bool addLineTool; +// bool addCircleTool; +// bool addDimensionTool; public: Action * toolAction; diff --git a/src/layerwidget.cpp b/src/layerwidget.cpp index 6561256..adc717e 100644 --- a/src/layerwidget.cpp +++ b/src/layerwidget.cpp @@ -15,7 +15,8 @@ #include "layeritemwidget.h" -LayerWidget::LayerWidget(void): QWidget() +LayerWidget::LayerWidget(void): QWidget(), + list(new QListWidget) { LayerItemWidget * liw1 = new LayerItemWidget("Guidelines"); LayerItemWidget * liw2 = new LayerItemWidget("Floor #1"); @@ -23,23 +24,37 @@ LayerWidget::LayerWidget(void): QWidget() LayerItemWidget * liw4 = new LayerItemWidget("List Widget"); LayerItemWidget * liw5 = new LayerItemWidget("Background"); - QListWidget * qlw = new QListWidget; - QListWidgetItem * qli1 = new QListWidgetItem(qlw); - QListWidgetItem * qli2 = new QListWidgetItem(qlw); - QListWidgetItem * qli3 = new QListWidgetItem(qlw); - QListWidgetItem * qli4 = new QListWidgetItem(qlw); - QListWidgetItem * qli5 = new QListWidgetItem(qlw); - qlw->setItemWidget(qli1, liw1); - qlw->setItemWidget(qli2, liw2); - qlw->setItemWidget(qli3, liw3); - qlw->setItemWidget(qli4, liw4); - qlw->setItemWidget(qli5, liw5); +// QListWidget * qlw = new QListWidget; + QListWidgetItem * qli1 = new QListWidgetItem(list); + QListWidgetItem * qli2 = new QListWidgetItem(list); + QListWidgetItem * qli3 = new QListWidgetItem(list); + QListWidgetItem * qli4 = new QListWidgetItem(list); + QListWidgetItem * qli5 = new QListWidgetItem(list); + list->setItemWidget(qli1, liw1); + list->setItemWidget(qli2, liw2); + list->setItemWidget(qli3, liw3); + list->setItemWidget(qli4, liw4); + list->setItemWidget(qli5, liw5); +#if 0 QPushButton * pb1 = new QPushButton("+"); QPushButton * pb2 = new QPushButton("-"); QPushButton * pb3 = new QPushButton("Edit"); QPushButton * pb4 = new QPushButton("^"); QPushButton * pb5 = new QPushButton("v"); +#else + QToolButton * pb1 = new QToolButton; + QToolButton * pb2 = new QToolButton; + QToolButton * pb3 = new QToolButton; + QToolButton * pb4 = new QToolButton; + QToolButton * pb5 = new QToolButton; + + pb1->setIcon(QIcon(":/res/generic-tool.png")); + pb2->setIcon(QIcon(":/res/generic-tool.png")); + pb3->setIcon(QIcon(":/res/generic-tool.png")); + pb4->setIcon(QIcon(":/res/generic-tool.png")); + pb5->setIcon(QIcon(":/res/generic-tool.png")); +#endif QHBoxLayout * hbox1 = new QHBoxLayout; hbox1->addWidget(pb1); @@ -50,10 +65,18 @@ LayerWidget::LayerWidget(void): QWidget() hbox1->addStretch(); QVBoxLayout * mainLayout = new QVBoxLayout; - mainLayout->addWidget(qlw); + mainLayout->addWidget(list); mainLayout->addLayout(hbox1); setLayout(mainLayout); + + connect(list, SIGNAL(currentRowChanged(int)), this, SLOT(HandleLayerSelected(int))); + list->setCurrentRow(4); + connect(pb1, SIGNAL(clicked()), this, SLOT(AddLayer())); + connect(pb2, SIGNAL(clicked()), this, SLOT(DeleteLayer())); + connect(pb3, SIGNAL(clicked()), this, SLOT(EditLayer())); + connect(pb4, SIGNAL(clicked()), this, SLOT(MoveLayerUp())); + connect(pb5, SIGNAL(clicked()), this, SLOT(MoveLayerDown())); } @@ -61,3 +84,41 @@ LayerWidget::~LayerWidget() { } + +void LayerWidget::HandleLayerSelected(int currentRow) +{ +//printf("LayerWidget::HandleLayerSelected(): currentRow = %i\n", currentRow); + emit(LayerSelected(currentRow)); +} + + +void LayerWidget::AddLayer(void) +{ + int count = list->count(); + QString text = QString("Layer #%1").arg(count); + LayerItemWidget * liw = new LayerItemWidget(text); + QListWidgetItem * qlwi = new QListWidgetItem(); + list->insertItem(0, qlwi); + list->setItemWidget(qlwi, liw); +} + + +void LayerWidget::DeleteLayer(void) +{ +} + + +void LayerWidget::EditLayer(void) +{ +} + + +void LayerWidget::MoveLayerUp(void) +{ +} + + +void LayerWidget::MoveLayerDown(void) +{ +} + diff --git a/src/layerwidget.h b/src/layerwidget.h index 33000ea..082c81d 100644 --- a/src/layerwidget.h +++ b/src/layerwidget.h @@ -11,6 +11,20 @@ class LayerWidget: public QWidget LayerWidget(void); ~LayerWidget(); + private slots: + void HandleLayerSelected(int); + void AddLayer(void); + void DeleteLayer(void); + void EditLayer(void); + void MoveLayerUp(void); + void MoveLayerDown(void); + + signals: + void LayerSelected(int); + + private: + QListWidget * list; }; #endif // __LAYERWIDGET_H__ + diff --git a/src/mirroraction.cpp b/src/mirroraction.cpp index 500f59d..61b14ac 100644 --- a/src/mirroraction.cpp +++ b/src/mirroraction.cpp @@ -13,6 +13,7 @@ #include "mirroraction.h" #include "line.h" +#include "mathconstants.h" #include "painter.h" //#include "vector.h" @@ -48,8 +49,13 @@ MirrorAction::~MirrorAction() painter->DrawLine(p1, p2); painter->DrawHandle(p2); - QString text = tr("Length: %1 in."); - text = text.arg(Vector::Magnitude(p1, p2)); + double absAngle = (Vector(p2 - p1).Angle()) * RADIANS_TO_DEGREES; +// double absLength = Vector(position - endpoint).Magnitude(); + + QString text = QChar(0x2221) + QObject::tr(": %1"); + text = text.arg(absAngle); +// QString text = tr("Length: %1 in."); +// text = text.arg(Vector::Magnitude(p1, p2)); painter->DrawInformativeText(text); } } diff --git a/src/object.cpp b/src/object.cpp index 93af822..346c19a 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -33,17 +33,18 @@ bool Object::dontMove = false; bool Object::selectionInProgress = false; QRectF Object::selection; double Object::gridSpacing; +int Object::currentLayer = 0; Object::Object(): position(Vector(0, 0)), parent(0), type(OTObject), - state(OSInactive), oldState(OSInactive), needUpdate(false) + state(OSInactive), layer(0), oldState(OSInactive), needUpdate(false) //, attachedDimension(0) { } Object::Object(Vector v, Object * passedInParent/*= 0*/): position(v), - parent(passedInParent), state(OSInactive), oldState(OSInactive), + parent(passedInParent), state(OSInactive), layer(0), oldState(OSInactive), needUpdate(false)//, attachedDimension(0) { } diff --git a/src/object.h b/src/object.h index b8fdd9d..0a72328 100644 --- a/src/object.h +++ b/src/object.h @@ -67,6 +67,7 @@ class Object public: ObjectType type; ObjectState state; + unsigned int layer; protected: ObjectState oldState; bool needUpdate; @@ -90,6 +91,7 @@ class Object static bool selectionInProgress; static QRectF selection; static double gridSpacing; // Grid spacing in base units + static int currentLayer; }; #endif // __OBJECT_H__