]> Shamusworld >> Repos - architektonas/commitdiff
Selection of Lines works, ctrl held for multi-select.
authorShamus Hammons <jlhamm@acm.org>
Fri, 24 Apr 2015 00:26:56 +0000 (19:26 -0500)
committerShamus Hammons <jlhamm@acm.org>
Fri, 24 Apr 2015 00:26:56 +0000 (19:26 -0500)
src/applicationwindow.cpp
src/drawingview.cpp
src/drawingview.h

index 5a435a21ae3e6bfe8d82cffdf3408afaa9181f82..f5013ad8ae940bf714003b4d4e8e1d7f699bde5b 100644 (file)
@@ -546,6 +546,7 @@ else
                container->state = OSSelected;
                statusBar()->showMessage(QString(tr("Grouped %1 objects.")).arg(itemsSelected));
        }
+#else
 #endif
 
        drawing->update();
@@ -617,6 +618,7 @@ printf("   -> intersects = %i, t=%lf, u=%lf\n", intersects, t, u);
                        }
                }
        }
+#else
 #endif
 }
 
index 99c4da9f2779054f5edbb6e607ee4e4f8f44371e..957aaf87a56d27b70fb622fccfb45ad07b990d3d 100644 (file)
@@ -45,7 +45,8 @@
 
 DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        // The value in the settings file will override this.
-       useAntialiasing(true), numSelected(0),
+       useAntialiasing(true), numSelected(0), numHovered(0), shiftDown(false),
+       ctrlDown(false),
        gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE),
        scale(1.0), offsetX(-10), offsetY(-10),// document(Vector(0, 0)),
        gridPixels(0), collided(false)//, toolAction(NULL)
@@ -540,6 +541,53 @@ void DrawingView::DeleteSelectedItems(void)
 }
 
 
+void DrawingView::ClearSelection(void)
+{
+       std::vector<void *>::iterator i;
+
+       for(i=document.objects.begin(); i!=document.objects.end(); i++)
+               ((Object *)(*i))->selected = false;
+}
+
+
+void DrawingView::AddHoveredToSelection(void)
+{
+       std::vector<void *>::iterator i;
+
+       for(i=document.objects.begin(); i!=document.objects.end(); i++)
+       {
+               if (((Object *)(*i))->hovered)
+                       ((Object *)(*i))->selected = true;
+       }
+}
+
+
+void DrawingView::GetSelection(std::vector<void *> & v)
+{
+       v.empty();
+       std::vector<void *>::iterator i;
+
+       for(i=v.begin(); i!=v.end(); i++)
+       {
+               if (((Object *)(*i))->selected)
+                       v.push_back(*i);
+       }
+}
+
+
+void DrawingView::GetHovered(std::vector<void *> & v)
+{
+       v.empty();
+       std::vector<void *>::iterator i;
+
+       for(i=v.begin(); i!=v.end(); i++)
+       {
+               if (((Object *)(*i))->hovered)
+                       v.push_back(*i);
+       }
+}
+
+
 void DrawingView::resizeEvent(QResizeEvent * /*event*/)
 {
        Global::screenSize = Vector(size().width(), size().height());
@@ -558,6 +606,9 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
                // Do an update if collided with at least *one* object in the document
 //             if (collided)
 //                     update();
+               // Actually, we already know what we're going to click on as all the collision
+               // detection already happened in the mouse move function...!
+//printf("MouseDown: ctrl=%s, numHovered=%i\n", (ctrlDown ? "DOWN" : "up"), numHovered);
 
 #if 0
                if (toolAction)
@@ -572,11 +623,22 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
 
                        toolAction->MouseDown(point);
                }
+#else
+               if (Global::tool)
+               {
+                       return;
+               }
 #endif
 
+               if (!ctrlDown)
+                       ClearSelection();
+
+               if (numHovered > 0)
+                       AddHoveredToSelection();
+
 #if 1
                // Didn't hit any object and not using a tool, so do a selection rectangle
-               if (!(collided))// || toolAction))
+               if (!(numHovered || Global::tool))
                {
                        Global::selectionInProgress = true;
                        Global::selection.setTopLeft(QPointF(point.x, point.y));
@@ -749,8 +811,11 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 
 #if 0
        // This returns true if we've moved over an object...
-       if (document.PointerMoved(point))
+       if (document.PointerMoved(point)) // <-- This
+       // This is where the object would do automagic dragging & shit. Since we don't
+       // do that anymore, we need a strategy to handle it.
        {
+
 /*
 Now objects handle mouse move snapping as well. The code below mainly works only
 for tools; we need to fix it so that objects work as well...
@@ -824,12 +889,12 @@ selected object last and thus fucks up the algorithm. Need to fix this...
        bool needUpdate = false;
 
        // Don't do this kind of checking unless we're not doing a selection rectangle!
-       // Hmm, lines don't stay selected if globally selected... !!! FIX !!!
+       // Hmm, lines don't stay selected if globally selected... !!! FIX !!! [DONE]
        // it's because there were extra state variables, the hit* vars...
        if (!Global::selectionInProgress)
        {
        std::vector<void *>::iterator i;
-       int numHovered = 0;
+       numHovered = 0;
 
        for(i=document.objects.begin(); i!=document.objects.end(); i++)
        {
@@ -892,14 +957,21 @@ selected object last and thus fucks up the algorithm. Need to fix this...
                default:
                        break;
                }
+
+               if (obj->hovered)
+               {
+                       numHovered++;
+//printf("MouseMove: OBJECT HOVERED (numHovered = %i)\n", numHovered);
+               }
        }
        }
+//printf("MouseMove: numHovered = %i\n", numHovered);
 
        // This is used to draw the tool crosshair...
        oldPoint = point;
 
 //     if (/*document.NeedsUpdate() ||*/ Global::selectionInProgress /*|| toolAction*/)
-       if (needUpdate || Global::selectionInProgress)
+       if (needUpdate || Global::selectionInProgress || Global::tool)
                update();
 }
 
@@ -928,6 +1000,23 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
                {
                        // Select all the stuff inside of selection
                        Global::selectionInProgress = false;
+
+                       // Clear our vectors
+                       select.empty();
+                       hover.empty();
+
+                       // Scoop 'em up
+                       std::vector<void *>::iterator i;
+
+                       for(i=document.objects.begin(); i!=document.objects.end(); i++)
+                       {
+                               if (((Object *)(*i))->selected)
+                                       select.push_back(*i);
+
+//hmm, this is no good, too late to do any good :-P
+//                             if ((*i)->hovered)
+//                                     hover.push_back(*i);
+                       }
                }
        }
        else if (event->button() == Qt::MiddleButton)
@@ -975,6 +1064,10 @@ void DrawingView::keyPressEvent(QKeyEvent * event)
        if (toolAction)
                toolAction->KeyDown(event->key());
 #endif
+       if (event->key() == Qt::Key_Shift)
+               shiftDown = true;
+       else if (event->key() == Qt::Key_Control)
+               ctrlDown = true;
 }
 
 
@@ -984,6 +1077,10 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event)
        if (toolAction)
                toolAction->KeyReleased(event->key());
 #endif
+       if (event->key() == Qt::Key_Shift)
+               shiftDown = false;
+       else if (event->key() == Qt::Key_Control)
+               ctrlDown = false;
 }
 
 //
index 1046f9c0938164b49cac58e07991d634f89f31b3..c4a7234fe733314ffc34bbebfcf98b3232a314e0 100644 (file)
@@ -21,6 +21,10 @@ class DrawingView: public QWidget
                Point SnapPointToGrid(Point);
                void RenderObjects(Painter *, Container *);
                void DeleteSelectedItems(void);
+               void ClearSelection(void);
+               void AddHoveredToSelection(void);
+               void GetSelection(std::vector<void *> &);
+               void GetHovered(std::vector<void *> &);
 
        public slots:
                void AddNewObjectToDocument(Object *);
@@ -44,6 +48,9 @@ class DrawingView: public QWidget
        public:
                bool useAntialiasing;
                uint32_t numSelected;
+               uint32_t numHovered;
+               bool shiftDown;
+               bool ctrlDown;
 
        private:
                QPixmap gridBackground;
@@ -58,6 +65,8 @@ class DrawingView: public QWidget
                Vector oldPoint;
 
        public:
+               std::vector<void *> select;
+               std::vector<void *> hover;
 //             Action * toolAction;
 
 //     public: