]> Shamusworld >> Repos - architektonas/commitdiff
Beginning to make the Layer widget functional.
authorShamus Hammons <jlhamm@acm.org>
Tue, 27 Aug 2013 23:56:38 +0000 (18:56 -0500)
committerShamus Hammons <jlhamm@acm.org>
Tue, 27 Aug 2013 23:56:38 +0000 (18:56 -0500)
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.

TODO
src/applicationwindow.cpp
src/drawingview.cpp
src/drawingview.h
src/layerwidget.cpp
src/layerwidget.h
src/mirroraction.cpp
src/object.cpp
src/object.h

diff --git a/TODO b/TODO
index 48c82e3e4b48bd6034c2f6d164e010d84c886bc5..c54924f1971d3ded9b8898dfe7590ae4ba42f24a 100644 (file)
--- 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
index 8220a0eeca1138d6523c884ae70b26c828f92980..bf9baf45781fb076e8c9f9c733969f3f5784ba53 100644 (file)
@@ -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)));
 }
 
 
index 95721178a70be35ee56600f4a492390b8f1ed44c..3020368913cfa3b4358df95669b1b65649523d15 100644 (file)
@@ -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.
index da1912f39312fbcc20fc6e0d60ed96553f071a5c..55384fa48a3c7c686abc5ba2d44b46dd2d961718 100644 (file)
@@ -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;
index 6561256c5f4af3d8a7caf12363fb6ba55c0f73c6..adc717e7e1c63860a9cc2dfdd3ca8f8229ef1cc6 100644 (file)
@@ -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)
+{
+}
+
index 33000ea12a8594046fc5bd22dddc5f35ff2e7186..082c81d47dcfe657db198c98319dfbab660c2efb 100644 (file)
@@ -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__
+
index 500f59d9e6cd89633c1571e85ee2fe8b0de21083..61b14ac1276be53c1199b3b310db421e0ff07834 100644 (file)
@@ -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);
        }
 }
index 93af822b8476008c2f60e6158955078cdaf38c0d..346c19a11536d686a0ea63ba8f4d5883bdb8f9c6 100644 (file)
@@ -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)
 {
 }
index b8fdd9db76f70b0a2cf8fbd5e797951c278183e3..0a72328cc6d8446b0804d1792c38240407a1b5af 100644 (file)
@@ -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__