]> Shamusworld >> Repos - architektonas/commitdiff
Initial stab at getting Circle to respond to selection rectangle.
authorShamus Hammons <jlhamm@acm.org>
Mon, 8 Jul 2013 04:31:45 +0000 (23:31 -0500)
committerShamus Hammons <jlhamm@acm.org>
Mon, 8 Jul 2013 04:31:45 +0000 (23:31 -0500)
src/arc.cpp
src/circle.cpp
src/drawingview.cpp
src/drawingview.h
src/line.cpp
src/object.cpp
src/object.h

index c29e38db2a54c79a2fc47dfec6eef2be737f4f03..8fc66319bbe540ef96a153ed193c6ec4635993e9 100644 (file)
@@ -102,14 +102,16 @@ Arc::~Arc()
                        pen = QPen(QColor(0x00, 0xFF, 0x00), 1.0, Qt::SolidLine);
                        painter->SetPen(pen);
                        painter->SetBrush(QBrush(QColor(0x40, 0xFF, 0x40, 0x9F)));
-                       QRectF textRect(10.0, 10.0, 260.0, 60.0);       // x, y, w, h
+                       QRectF textRect(10.0, 10.0, 270.0, 70.0);       // x, y, w, h
                        painter->DrawRoundedRect(textRect, 7.0, 7.0);
 
                        textRect.setLeft(textRect.left() + 14);
                        painter->SetFont(*Object::font);
-                       pen = QPen(QColor(0xDF, 0x5F, 0x00), 1.0, Qt::SolidLine);
+//                     pen = QPen(QColor(0xDF, 0x5F, 0x00), 1.0, Qt::SolidLine);
+                       pen = QPen(QColor(0x00, 0x5F, 0xDF));
                        painter->SetPen(pen);
                        painter->DrawText(textRect, Qt::AlignVCenter, text);
+                       painter->SetPen(QPen(QColor(0xDF, 0x5F, 0x00)));
                }
        }
        else
index d6ed3064b175b7fd2fe2310d8a8da0a3bce7b2df..6473440ccdb287408e24870b501b23ebbd611551 100644 (file)
@@ -87,6 +87,17 @@ Circle::~Circle()
 
 /*virtual*/ void Circle::PointerMoved(Vector point)
 {
+       if (selectionInProgress)
+       {
+               // Check for whether or not the rect contains this circle
+               if (selection.normalized().contains(Extents()))
+                       state = OSSelected;
+               else
+                       state = OSInactive;
+
+               return;
+       }
+
        // Hit test tells us what we hit (if anything) through boolean variables. It
        // also tells us whether or not the state changed.
        needUpdate = HitTest(point);
index 1c095f4a73b41a3a5b070e880c81f4cb8372c04e..23c1d49100ad95f26a55aeb7e1a441a1a8875d0b 100644 (file)
@@ -51,7 +51,7 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        gridSpacing(12.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
        scrollDrag(false), addLineTool(false), addCircleTool(false),
        addDimensionTool(false),
-       selectionInProgress(false),
+//     selectionInProgress(false),
        toolAction(NULL)
 {
        document.isTopLevelContainer = true;
@@ -284,13 +284,13 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
        if (toolAction)
                toolAction->Draw(&painter);
 
-       if (selectionInProgress)
+       if (Object::selectionInProgress)
        {
 //             painter.SetPen(QPen(Qt::green, 1.0, Qt::SolidLine));
                painter.SetPen(QPen(QColor(255, 127, 0, 255)));
 //             painter.SetBrush(QBrush(Qt::NoBrush));
                painter.SetBrush(QBrush(QColor(255, 127, 0, 100)));
-               painter.DrawRect(selection);
+               painter.DrawRect(Object::selection);
        }
 }
 
@@ -311,9 +311,9 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
                // Didn't hit any object and not using a tool, so do a selection rectangle
                if (!(collided || toolAction))
                {
-                       selectionInProgress = true;
-                       selection.setTopLeft(QPointF(point.x, point.y));
-                       selection.setBottomRight(QPointF(point.x, point.y));
+                       Object::selectionInProgress = true;
+                       Object::selection.setTopLeft(QPointF(point.x, point.y));
+                       Object::selection.setBottomRight(QPointF(point.x, point.y));
                }
        }
        else if (event->button() == Qt::MiddleButton)
@@ -329,7 +329,7 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
 void DrawingView::mouseMoveEvent(QMouseEvent * event)
 {
        Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
-       selection.setBottomRight(QPointF(point.x, point.y));
+       Object::selection.setBottomRight(QPointF(point.x, point.y));
 
        if (event->buttons() & Qt::MiddleButton)
        {
@@ -373,7 +373,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 //changed...
        document.PointerMoved(point);
 
-       if (document.NeedsUpdate() || selectionInProgress)
+       if (document.NeedsUpdate() || Object::selectionInProgress)
                update();
 
        if (toolAction)
@@ -400,10 +400,10 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
                if (toolAction)
                        toolAction->MouseReleased();
 
-               if (selectionInProgress)
+               if (Object::selectionInProgress)
                {
                        // Select all the stuff inside of selection
-                       selectionInProgress = false;
+                       Object::selectionInProgress = false;
                }
        }
        else if (event->button() == Qt::MiddleButton)
index eaf8826f564e4d6ab747ed78bd61bb6044de6c8a..cd76d1e9aba034be6e7e93ce335280bc42e48530 100644 (file)
@@ -54,8 +54,8 @@ class DrawingView: public QWidget
                bool addLineTool;
                bool addCircleTool;
                bool addDimensionTool;
-               bool selectionInProgress;
-               QRectF selection;
+//             bool selectionInProgress;
+//             QRectF selection;
 
        public:
                Action * toolAction;
index 5f3a611023e6faceb395d166bface63ea8b3bbf6..da9717c1af65810bbe2975e33b9c8048c3798610 100644 (file)
@@ -273,6 +273,8 @@ Like so:
 
                oldPoint = point;
                needUpdate = true;
+
+//doesn't work         QMainWindow::statusBar()->setText("You are manipulating a line");
        }
 
 /*
@@ -285,18 +287,20 @@ Ugly ways to do it:
 
 More elegant ways:
  - Pass the point in a notification function (how?)
- - Pass the point as a reference to the class instance object (&endpoint). This way, the line
-   doesn't have to care about keeping track of Dimensions connected to it. But still have to
-   care about other connected entities (other Lines, Circles, Arcs, Splines, Texts, etc). I
-   think I'd be OK with this.
-   Since the Dimension has a pointer to our object, all we have to do is update our coordinates
-   and the Dimension object will adjust itself on the next repaint. Problem solved, and we don't
-   have to know anything about how many Dimensions are connected to us, or where! \o/
+ - Pass the point as a reference to the class instance object (&endpoint). This
+   way, the line doesn't have to care about keeping track of Dimensions
+   connected to it. But still have to care about other connected entities
+   (other Lines, Circles, Arcs, Splines, Texts, etc). I think I'd be OK with
+   this. Since the Dimension has a pointer to our object, all we have to do is
+   update our coordinates and the Dimension object will adjust itself on the
+   next repaint. Problem solved, and we don't have to know anything about how
+   many Dimensions are connected to us, or where! \o/
    The question then becomes, how do we do this kind of coupling???
 
-We need to know about connected entities so that we can have them either move in expected ways
-or constrain the movement of this Line object. This is how we will be a cut above all other CAD
-software currently out there: the GUI will try to do the right thing, most of the time. :-)
+We need to know about connected entities so that we can have them either move
+in expected ways or constrain the movement of this Line object. This is how we
+will be a cut above all other CAD software currently out there: the GUI will
+try to do the right thing, most of the time. :-)
 */
        if (needUpdate)
        {
index 197fa8d0f63c202d07f0a9c38183d65cb01eab92..8ba3295b5510088a68f13ff8646838c6dd738432 100644 (file)
@@ -29,6 +29,8 @@ bool Object::snapToGrid = true;
 //snapToPoints all well here?
 bool Object::ignoreClicks = false;
 bool Object::dontMove = false;
+bool Object::selectionInProgress = false;
+QRectF Object::selection;
 
 
 Object::Object(): position(Vector(0, 0)), parent(0), type(OTObject),
index 34063a76e522d44f976a54f3db3d47c9f5d29287..5d51f57d79f254ea933b8b58f3c7dc218c6bc877 100644 (file)
@@ -78,6 +78,9 @@ class Object
                static bool snapToGrid;
                static bool ignoreClicks;
                static bool dontMove;
+       public:
+               static bool selectionInProgress;
+               static QRectF selection;
 };
 
 #endif // __OBJECT_H__