From ab604f6b520f16e24aa2611db856b13505e28686 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sat, 9 May 2015 08:17:25 -0500 Subject: [PATCH] Add Circle manipulation, fix Line movement bug. --- src/action.cpp | 22 ---------------------- src/action.h | 37 ------------------------------------- src/drawingview.cpp | 36 +++++++++++++++++++++++++----------- src/drawingview.h | 1 + 4 files changed, 26 insertions(+), 70 deletions(-) delete mode 100644 src/action.cpp delete mode 100644 src/action.h diff --git a/src/action.cpp b/src/action.cpp deleted file mode 100644 index 817e1a0..0000000 --- a/src/action.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// action.cpp: Action base class -// -// Part of the Architektonas Project -// (C) 2011 Underground Software -// See the README and GPLv3 files for licensing and warranty information -// -// JLH = James Hammons -// -// WHO WHEN WHAT -// --- ---------- ------------------------------------------------------------ -// JLH 10/04/2011 Created this file -// - -#include "action.h" - -Action::Action(): QObject() -{ -} - -Action::~Action() -{ -} diff --git a/src/action.h b/src/action.h deleted file mode 100644 index f456d8f..0000000 --- a/src/action.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __ACTION_H__ -#define __ACTION_H__ - -#include -#include "vector.h" - -class Object; -class Painter; - -class Action: public QObject -{ - Q_OBJECT - - public: - Action(); - ~Action(); - - // These are all pure virtual functions: Derived classes must define - // ALL of them. - virtual void Draw(Painter *) = 0; - virtual void MouseDown(Vector) = 0; - virtual void MouseMoved(Vector) = 0; - virtual void MouseReleased(void) = 0; - virtual void KeyDown(int) = 0; - virtual void KeyReleased(int) = 0; - - signals: - void ObjectReady(Object *); - void NeedRefresh(void); - - // Class variables -// public: -// static unsigned int currentLayer; -}; - -#endif // __ACTION_H__ - diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 15579c9..f253bd9 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -308,6 +308,9 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/) // Do object rendering... RenderObjects(&painter, document.objects); + if (!informativeText.isEmpty()) + painter.DrawInformativeText(informativeText); + // Do tool rendering, if any... if (Global::tool) { @@ -717,7 +720,6 @@ void DrawingView::RotateHandler(int mode, Point p) if (obj.type == OTArc) { -//printf("Obj2->angle[0] = %f, obj.angle[0] = %f, angle = %f\n", obj2->angle[0], obj.angle[0], angle); obj2->angle[0] = obj.angle[0] + angle; if (obj2->angle[0] > PI_TIMES_2) @@ -814,6 +816,7 @@ void DrawingView::mousePressEvent(QMouseEvent * event) GetHovered(hover); // prolly needed // Needed for grab & moving objects + // We do it *after*... why? (doesn't seem to confer any advantage...) if (Global::snapToGrid) oldPoint = SnapPointToGrid(point); @@ -871,6 +874,9 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) // Handle object movement (left button down & over an object) if ((event->buttons() & Qt::LeftButton) && numHovered && !Global::tool) { + if (Global::snapToGrid) + point = SnapPointToGrid(point); + HandleObjectMovement(point); update(); oldPoint = point; @@ -919,7 +925,8 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) if (Global::selectionInProgress) Global::selectionInProgress = false; -// Should be we do this automagically? Hmm... + informativeText.clear(); +// Should we be doing this automagically? Hmm... // Clear our vectors select.clear(); hover.clear(); @@ -967,13 +974,11 @@ void DrawingView::wheelEvent(QWheelEvent * event) Global::zoom /= zoomFactor; } -#if 1 // Global::gridSpacing = gridPixels / Painter::zoom; // UpdateGridBackground(); SetGridSize(Global::gridSpacing * Global::zoom); update(); // zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Global::gridSpacing)); -#endif } @@ -1016,6 +1021,7 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event) } } + // // This looks strange, but it's really quite simple: We want a point that's // more than half-way to the next grid point to snap there while conversely we @@ -1221,10 +1227,8 @@ bool DrawingView::HitTestObjects(Point point) void DrawingView::HandleObjectMovement(Point point) { - if (Global::snapToGrid) - point = SnapPointToGrid(point); - Point delta = point - oldPoint; +//printf("HOM: old = (%f,%f), new = (%f, %f), delta = (%f, %f)\n", oldPoint.x, oldPoint.y, point.x, point.y, delta.x, delta.y); Object * obj = (Object *)hover[0]; //printf("Object type = %i (size=%i), ", obj->type, hover.size()); //printf("Object (%X) move: hp1=%s, hp2=%s, hl=%s\n", obj, (obj->hitPoint[0] ? "true" : "false"), (obj->hitPoint[1] ? "true" : "false"), (obj->hitObject ? "true" : "false")); @@ -1232,9 +1236,6 @@ void DrawingView::HandleObjectMovement(Point point) switch (obj->type) { case OTLine: - { -// Line * l = (Line *)obj; - if (obj->hitPoint[0]) obj->p[0] = point; else if (obj->hitPoint[1]) @@ -1246,7 +1247,20 @@ void DrawingView::HandleObjectMovement(Point point) } break; - } + case OTCircle: + if (obj->hitPoint[0]) + obj->p[0] = point; + else if (obj->hitObject) + { +//this doesn't work. we need to save this on mouse down for this to work correctly! +// double oldRadius = obj->radius[0]; + obj->radius[0] = Vector::Magnitude(obj->p[0], point); + + QString text = QObject::tr("Radius: %1");//\nScale: %2%"); + informativeText = text.arg(obj->radius[0], 0, 'd', 4);//.arg(obj->radius[0] / oldRadius * 100.0, 0, 'd', 0); + } + + break; default: break; } diff --git a/src/drawingview.h b/src/drawingview.h index ba35aff..162e968 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -67,6 +67,7 @@ class DrawingView: public QWidget bool collided; bool scrollDrag; Vector oldPoint; + QString informativeText; public: std::vector select; -- 2.37.2