]> Shamusworld >> Repos - architektonas/commitdiff
Fixed click selection and pen functionality.
authorShamus Hammons <jlhamm@acm.org>
Sat, 11 Dec 2021 01:07:32 +0000 (19:07 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sat, 11 Dec 2021 01:07:32 +0000 (19:07 -0600)
Now when a stack of objects is clicked on, clicking on the stack will
select them one at a time.  Now it's possible to grab objects in a
rational way!  Also, removed unnecessary pen functions that caused more
problems than they solved.  Now you must use the stamp function to
change objects' visible attributes.

src/applicationwindow.cpp
src/applicationwindow.h
src/drawingview.cpp
src/drawingview.h
src/penwidget.cpp
src/penwidget.h

index 47f8149634a40942d86940167bb6afbd7b1eed86..ef77f8b4e961f916a889fbdef162cafee57178ee 100644 (file)
@@ -153,7 +153,8 @@ void ApplicationWindow::FileNew(void)
        drawing->dirty = false;
        drawing->update();
        documentName.clear();
-       setWindowTitle("Architektonas - Untitled");
+//     setWindowTitle("Architektonas - Untitled");
+       setWindowFilePath(documentName);
        statusBar()->showMessage(tr("New drawing is ready."));
 }
 
@@ -1095,9 +1096,6 @@ void ApplicationWindow::CreateToolbars(void)
        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)));
        connect(pw->tbStamp, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenStamp(QAction *)));
        connect(pw->tbDropper, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenDropper(QAction *)));
 }
index d5a9c08b2474572630066ce0af3fffdaec868803..651add7eacb4a2ea5296e7542559922ba7c0ef90 100644 (file)
@@ -126,7 +126,6 @@ class ApplicationWindow: public QMainWindow
                QAction * editPasteAct;
                QAction * selectAllAct;
                QAction * printPreviewAct;
-//             QAction * moveToLayerAct;
                QList<QAction *> layerAct;
                QList<QAction *> mruAct;
 
index 4ae021c6da555d0091cda947e9296638efb3e9c4..d8726fed5d91d82d86e2616877306ba2a1401cb6 100644 (file)
@@ -193,7 +193,6 @@ void DrawingView::DrawSubGrid(Painter * painter, uint32_t color, double step, Ve
 //
 void DrawingView::DeleteCurrentLayer(int layer)
 {
-//printf("DrawingView::DeleteCurrentLayer(): currentLayer = %i\n", layer);
        VPVectorIter i = document.objects.begin();
 
        while (i != document.objects.end())
@@ -230,7 +229,6 @@ void DrawingView::HandleLayerToggle(void)
 //
 void DrawingView::HandleLayerSwap(int layer1, int layer2)
 {
-//printf("DrawingView: Swapping layers %i and %i.\n", layer1, layer2);
        HandleLayerSwap(layer1, layer2, document.objects);
 }
 
@@ -253,42 +251,6 @@ void DrawingView::HandleLayerSwap(int layer1, int layer2, VPVector & v)
        }
 }
 
-void DrawingView::HandlePenWidth(float width)
-{
-       for(VPVectorIter i=select.begin(); i!=select.end(); i++)
-       {
-               Object * obj = (Object *)(*i);
-               obj->thickness = width;
-       }
-
-       supressSelected = true;
-       update();
-}
-
-void DrawingView::HandlePenStyle(int style)
-{
-       for(VPVectorIter i=select.begin(); i!=select.end(); i++)
-       {
-               Object * obj = (Object *)(*i);
-               obj->style = style;
-       }
-
-       supressSelected = true;
-       update();
-}
-
-void DrawingView::HandlePenColor(uint32_t color)
-{
-       for(VPVectorIter i=select.begin(); i!=select.end(); i++)
-       {
-               Object * obj = (Object *)(*i);
-               obj->color = color;
-       }
-
-       supressSelected = true;
-       update();
-}
-
 void DrawingView::HandlePenStamp(QAction * action)
 {
        PenWidget * pw = (PenWidget *)action->parentWidget();
@@ -340,7 +302,6 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
 
 void DrawingView::focusOutEvent(QFocusEvent * /*event*/)
 {
-//     printf("DrawingView::focusOutEvent()...\n");
        // Make sure all modkeys being held are marked as released when the app
        // loses focus (N.B.: This only works because the app sets the focus policy
        // of this object to something other than Qt::NoFocus)
@@ -355,9 +316,6 @@ void DrawingView::focusInEvent(QFocusEvent * /*event*/)
                setCursor(curMarker);
        else if (Global::penDropper)
                setCursor(curDropper);
-//FocusOut already set this...
-//     else
-//             setCursor(Qt::ArrowCursor);
 }
 
 void DrawingView::paintEvent(QPaintEvent * /*event*/)
@@ -723,16 +681,45 @@ Where is the text offset?  It looks like it's drawing in the center, but obvious
 }
 
 //
-// This toggles the selection being hovered (typically, only 1 object)
+// This toggles the selection being hovered (typically, only 1 object).  We
+// toggle because the CTRL key might be held, in which case, we want to
+// deselect a selected object.
 //
-void DrawingView::AddHoveredToSelection(void)
+void DrawingView::HandleSelectionClick(VPVector & v)
 {
-       for(VPVectorIter i=document.objects.begin(); i!=document.objects.end(); i++)
+       if (ctrlDown)
+       {
+               for(VPVectorIter i=v.begin(); i!=v.end(); i++)
+               {
+                       Object * obj = (Object *)(*i);
+
+                       if (obj->hovered)
+                               obj->selected = !obj->selected;
+               }
+
+               return;
+       }
+
+       for(VPVectorIter i=v.begin(); i!=v.end(); i++)
+               ((Object *)(*i))->selected = false;
+
+       // Check if the hover changed, and if so, reset the selection stack
+       if (oldHover.size() != v.size())
        {
-               if (((Object *)(*i))->hovered)
-//                     ((Object *)(*i))->selected = true;
-                       ((Object *)(*i))->selected = !((Object *)(*i))->selected;
+               oldHover = v;
+               currentSelect = 0;
        }
+       else
+       {
+               // Select next object in the stack under the cursor
+               currentSelect++;
+
+               if (currentSelect >= v.size())
+                       currentSelect = 0;
+       }
+
+       dragged = (Object *)v[currentSelect];
+       dragged->selected = true;
 }
 
 VPVector DrawingView::GetSelection(void)
@@ -1798,7 +1785,6 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
        {
-//printf("mousePressEvent::Qt::LeftButton numHovered=%li\n", numHovered);
                Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
 
                // Handle tool processing, if any
@@ -1819,17 +1805,11 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
                if (!ctrlDown)
                        ClearSelected(document.objects);
 
-               // If any objects are being hovered on click, add them to the selection
-               // & return
+               // If any objects are being hovered on click, deal with 'em
                if (numHovered > 0)
                {
-                       AddHoveredToSelection();
-                       update();       // needed??
-//                     GetHovered(hover);      // prolly needed
                        VPVector hover2 = GetHovered();
                        dragged = (Object *)hover2[0];
-                       draggingObject = true;
-//printf("mousePressEvent::numHovered > 0 (hover2[0]=$%llx, type=%s)\n", dragged, objName[dragged->type]);
 
                        // Alert the pen widget
                        if (Global::penDropper)
@@ -1838,26 +1818,27 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
                                Global::penWidth = dragged->thickness;
                                Global::penStyle = dragged->style;
                                emit ObjectSelected(dragged);
-                               ClearSelected(document.objects);
                                return;
                        }
-
-                       if (Global::penStamp)
+                       else if (Global::penStamp)
                        {
                                dragged->color = Global::penColor;
                                dragged->thickness = Global::penWidth;
                                dragged->style = Global::penStyle;
                                return;
                        }
-
-                       // See if anything is using just a straight click on a handle
-                       if (HandleObjectClicked())
+                       // See if anything is using just a straight click on a custom
+                       // object handle (like Dimension objects)
+                       else if (HandleObjectClicked())
                        {
-                               draggingObject = false;
                                update();
                                return;
                        }
 
+                       draggingObject = true;
+                       HandleSelectionClick(hover2);
+                       update();       // needed??
+
                        // Needed for grab & moving objects
                        // We do it *after*... why? (doesn't seem to confer any advantage...)
                        if (hoveringIntersection)
index 136380c127960ae21fa626e04cc8a7beebf61e18..5906766d35b6bd459e0c2ccf9cdca55405a2f60a 100644 (file)
@@ -22,7 +22,7 @@ class DrawingView: public QWidget
                Point SnapPointToGrid(Point);
                Point SnapPointToAngle(Point);
                void RenderObjects(Painter *, VPVector &, int, bool ignoreLayer = false);
-               void AddHoveredToSelection(void);
+               void HandleSelectionClick(VPVector &);
                VPVector GetSelection(void);
                VPVector GetHovered(bool exclude = false);
                void MoveSelectedToLayer(int);
@@ -51,9 +51,6 @@ class DrawingView: public QWidget
                void HandleLayerToggle(void);
                void HandleLayerSwap(int, int);
                void HandleLayerSwap(int, int, VPVector &);
-               void HandlePenWidth(float);
-               void HandlePenStyle(int);
-               void HandlePenColor(uint32_t);
                void HandlePenStamp(QAction *);
                void HandlePenDropper(QAction *);
 
@@ -93,12 +90,11 @@ class DrawingView: public QWidget
                bool supressSelected;
                QCursor curMarker;
                QCursor curDropper;
+               uint32_t currentSelect;
        public:
                Container document;
                uint32_t gridPixels;                                    // Grid size in pixels
                double gridPixelsF;                                             // Grid size in pixels (float)
-//     private:
-       public:
                bool collided;
                bool scrollDrag;
                Vector oldPoint;
@@ -110,6 +106,7 @@ class DrawingView: public QWidget
                VPVector toolObjects;
                std::vector<Object> toolScratch;
                VPVector toolScratch2;
+               VPVector oldHover;
                Point toolPoint[32];
                Object * toolObj[32];
                double toolParam[32];
index a20c0a22951d7805ca63bdf1ecd402a355a68dd3..65da6bb6034ea689b02778cdcfa5ffd30ef04116 100644 (file)
@@ -11,9 +11,8 @@
 // ---  ----------  -----------------------------------------------------------
 // JLH  05/07/2017  Created this file
 //
-//maybe add a button to have it stamp attributes on all objects clicked on? [added Global::penStamp to facilitate this.]
-//need to add to drawingview the ability to use attributes on new objects [DONE]
-//need to override the selection so you can see the attributes effects immediately when they are changed instead of having to deselect them to see [IN PROGRESS]
+// Maybe add a "pen" pallete, to hold most frequently used pen colors/styles
+//
 
 #include "penwidget.h"
 
@@ -118,7 +117,6 @@ void PenWidget::HandleWidthSelected(QString text)
                return;
 
        Global::penWidth = value;
-       emit WidthSelected(Global::penWidth);
 }
 
 void PenWidget::HandleStyleSelected(int selected)
@@ -130,7 +128,6 @@ void PenWidget::HandleStyleSelected(int selected)
        // Styles are 1-based, but the combobox is 0-based, so we compensate for
        // that here
        Global::penStyle = selected + 1;
-       emit StyleSelected(Global::penStyle);
 }
 
 void PenWidget::HandleRedSelected(QString text)
@@ -144,7 +141,6 @@ void PenWidget::HandleRedSelected(QString text)
 
        r = value;
        Global::penColor = (r << 16) | (g << 8) | b;
-       emit ColorSelected(Global::penColor);
 }
 
 void PenWidget::HandleGreenSelected(QString text)
@@ -158,7 +154,6 @@ void PenWidget::HandleGreenSelected(QString text)
 
        g = value;
        Global::penColor = (r << 16) | (g << 8) | b;
-       emit ColorSelected(Global::penColor);
 }
 
 void PenWidget::HandleBlueSelected(QString text)
@@ -172,5 +167,4 @@ void PenWidget::HandleBlueSelected(QString text)
 
        b = value;
        Global::penColor = (r << 16) | (g << 8) | b;
-       emit ColorSelected(Global::penColor);
 }
index c08d14bba50bd232b4437c1b92f70058a1c9609a..4fe0d4749f0f2dc9b8f55b36cc7d5d8075a6c745 100644 (file)
@@ -21,13 +21,8 @@ class PenWidget: public QWidget
                void HandleRedSelected(QString);
                void HandleGreenSelected(QString);
                void HandleBlueSelected(QString);
-//             void HandleStamp(QAction *);
-//             void HandleDropper(QAction *);
 
        signals:
-               void WidthSelected(float);
-               void StyleSelected(int);
-               void ColorSelected(uint32_t);
                void StampSelected(void);
                void DropperSelected(void);