From 59e5af9d8606aa091fa979e19f78e9325a1c0825 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sun, 7 Jul 2013 23:31:45 -0500 Subject: [PATCH] Initial stab at getting Circle to respond to selection rectangle. --- src/arc.cpp | 6 ++++-- src/circle.cpp | 11 +++++++++++ src/drawingview.cpp | 20 ++++++++++---------- src/drawingview.h | 4 ++-- src/line.cpp | 24 ++++++++++++++---------- src/object.cpp | 2 ++ src/object.h | 3 +++ 7 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/arc.cpp b/src/arc.cpp index c29e38d..8fc6631 100644 --- a/src/arc.cpp +++ b/src/arc.cpp @@ -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 diff --git a/src/circle.cpp b/src/circle.cpp index d6ed306..6473440 100644 --- a/src/circle.cpp +++ b/src/circle.cpp @@ -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); diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 1c095f4..23c1d49 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -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) diff --git a/src/drawingview.h b/src/drawingview.h index eaf8826..cd76d1e 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -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; diff --git a/src/line.cpp b/src/line.cpp index 5f3a611..da9717c 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -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) { diff --git a/src/object.cpp b/src/object.cpp index 197fa8d..8ba3295 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -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), diff --git a/src/object.h b/src/object.h index 34063a7..5d51f57 100644 --- a/src/object.h +++ b/src/object.h @@ -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__ -- 2.37.2