From: Shamus Hammons Date: Sun, 25 Aug 2013 20:58:20 +0000 (-0500) Subject: Added key modifiers to Actions. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=64482766268cddae393da1277987de31e69ffdd9 Added key modifiers to Actions. --- diff --git a/TODO b/TODO index 43ee39b..48c82e3 100644 --- a/TODO +++ b/TODO @@ -10,7 +10,6 @@ Stuff To Be Implemented/Fixed - Group selection (kind done, needs more work though) - Take movement code out of Objects and put it into top level Container (actually I think this should be more of the state code handling. Have to see.) - - Add OSD routines so they don't have to be implemented in Objects - Add OSD to Object creation - Add layers - Add blocks @@ -37,5 +36,7 @@ Stuff That's Done - Add Arc [Shamus 2013-08-14] - Fix snap to grid to allow picking up of handles when they are not on a grid point. [Shamus 2013-08-18] + - Add OSD routines so they don't have to be implemented in Objects [Shamus + 2013-08-24] diff --git a/src/action.h b/src/action.h index 6565f69..96e8e87 100644 --- a/src/action.h +++ b/src/action.h @@ -1,7 +1,7 @@ #ifndef __ACTION_H__ #define __ACTION_H__ -#include +#include #include "vector.h" class Object; @@ -21,9 +21,12 @@ class Action: public QObject virtual void MouseDown(Vector) = 0; virtual void MouseMoved(Vector) = 0; virtual void MouseReleased(void) = 0; + virtual bool KeyDown(int) = 0; + virtual bool KeyReleased(int) = 0; signals: void ObjectReady(Object *); }; #endif // __ACTION_H__ + diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index f9362ca..8600d2d 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -49,6 +49,7 @@ ApplicationWindow::ApplicationWindow(): { drawing = new DrawingView(this); drawing->setMouseTracking(true); // We want *all* mouse events...! + drawing->setFocusPolicy(Qt::StrongFocus); setCentralWidget(drawing); aboutWin = new AboutWindow(this); diff --git a/src/drawarcaction.cpp b/src/drawarcaction.cpp index 624e4ee..e416d3d 100644 --- a/src/drawarcaction.cpp +++ b/src/drawarcaction.cpp @@ -123,3 +123,15 @@ DrawArcAction::~DrawArcAction() } } + +/*virtual*/ bool DrawArcAction::KeyDown(int /*key*/) +{ + return false; +} + + +/*virtual*/ bool DrawArcAction::KeyReleased(int /*key*/) +{ + return false; +} + diff --git a/src/drawarcaction.h b/src/drawarcaction.h index f47d461..4c5c32b 100644 --- a/src/drawarcaction.h +++ b/src/drawarcaction.h @@ -15,6 +15,8 @@ class DrawArcAction: public Action virtual void MouseDown(Vector); virtual void MouseMoved(Vector); virtual void MouseReleased(void); + virtual bool KeyDown(int); + virtual bool KeyReleased(int); private: int state; @@ -24,3 +26,4 @@ class DrawArcAction: public Action }; #endif // __DRAWARCACTION_H__ + diff --git a/src/drawcircleaction.cpp b/src/drawcircleaction.cpp index 338bd53..a1ffe19 100644 --- a/src/drawcircleaction.cpp +++ b/src/drawcircleaction.cpp @@ -82,3 +82,16 @@ DrawCircleAction::~DrawCircleAction() p1 = p2; } } + + +/*virtual*/ bool DrawCircleAction::KeyDown(int /*key*/) +{ + return false; +} + + +/*virtual*/ bool DrawCircleAction::KeyReleased(int /*key*/) +{ + return false; +} + diff --git a/src/drawcircleaction.h b/src/drawcircleaction.h index d989e45..65dc6ec 100644 --- a/src/drawcircleaction.h +++ b/src/drawcircleaction.h @@ -15,6 +15,8 @@ class DrawCircleAction: public Action virtual void MouseDown(Vector); virtual void MouseMoved(Vector); virtual void MouseReleased(void); + virtual bool KeyDown(int); + virtual bool KeyReleased(int); private: int state; @@ -23,3 +25,4 @@ class DrawCircleAction: public Action }; #endif // __DRAWCIRCLEACTION_H__ + diff --git a/src/drawdimensionaction.cpp b/src/drawdimensionaction.cpp index 58fa095..e51f88d 100644 --- a/src/drawdimensionaction.cpp +++ b/src/drawdimensionaction.cpp @@ -87,3 +87,15 @@ DrawDimensionAction::~DrawDimensionAction() } } + +/*virtual*/ bool DrawDimensionAction::KeyDown(int /*key*/) +{ + return false; +} + + +/*virtual*/ bool DrawDimensionAction::KeyReleased(int /*key*/) +{ + return false; +} + diff --git a/src/drawdimensionaction.h b/src/drawdimensionaction.h index ccb9132..edd5c7b 100644 --- a/src/drawdimensionaction.h +++ b/src/drawdimensionaction.h @@ -15,6 +15,8 @@ class DrawDimensionAction: public Action virtual void MouseDown(Vector); virtual void MouseMoved(Vector); virtual void MouseReleased(void); + virtual bool KeyDown(int); + virtual bool KeyReleased(int); private: int state; @@ -23,3 +25,4 @@ class DrawDimensionAction: public Action }; #endif // __DRAWDIMENSIONACTION_H__ + diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 838d45a..9572117 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -496,3 +496,27 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) } } + +void DrawingView::keyPressEvent(QKeyEvent * event) +{ + if (toolAction) + { + bool needUpdate = toolAction->KeyDown(event->key()); + + if (needUpdate) + update(); + } +} + + +void DrawingView::keyReleaseEvent(QKeyEvent * event) +{ + if (toolAction) + { + bool needUpdate = toolAction->KeyReleased(event->key()); + + if (needUpdate) + update(); + } +} + diff --git a/src/drawingview.h b/src/drawingview.h index 819ab78..da1912f 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -35,6 +35,8 @@ class DrawingView: public QWidget void mousePressEvent(QMouseEvent * event); void mouseMoveEvent(QMouseEvent * event); void mouseReleaseEvent(QMouseEvent * event); + void keyPressEvent(QKeyEvent * event); + void keyReleaseEvent(QKeyEvent * event); private: QPoint GetAdjustedMousePosition(QMouseEvent * event); diff --git a/src/drawlineaction.cpp b/src/drawlineaction.cpp index d4b35db..e14ba81 100644 --- a/src/drawlineaction.cpp +++ b/src/drawlineaction.cpp @@ -18,11 +18,13 @@ //#include "vector.h" -#define FIRST_POINT 0 -#define NEXT_POINT 1 +//#define FIRST_POINT 0 +//#define NEXT_POINT 1 +enum { FIRST_POINT, NEXT_POINT }; -DrawLineAction::DrawLineAction(): state(0), line(NULL) +DrawLineAction::DrawLineAction(): state(FIRST_POINT), line(NULL), + shiftWasPressedOnNextPoint(false) { } @@ -37,6 +39,7 @@ DrawLineAction::~DrawLineAction() painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine)); // I think stuff like crosshairs should be done in the DrawingView, tho + // (and it's done there now...) if (state == FIRST_POINT) { painter->DrawHandle(p1); @@ -55,6 +58,9 @@ DrawLineAction::~DrawLineAction() /*virtual*/ void DrawLineAction::MouseDown(Vector point) { + // Clear our override... + shiftWasPressedOnNextPoint = false; + if (state == FIRST_POINT) p1 = point; else @@ -86,8 +92,38 @@ DrawLineAction::~DrawLineAction() // We don't need no stinkin' sentinels, when we have signals & slots! emit ObjectReady(line); -// p1 = p2; + p1 = p2; + state = NEXT_POINT; + } +} + + +/*virtual*/ bool DrawLineAction::KeyDown(int key) +{ + if ((key == Qt::Key_Shift) && (state == NEXT_POINT)) + { + shiftWasPressedOnNextPoint = true; + p1Save = p1; + p1 = p2; state = FIRST_POINT; + return true; + } + + return false; +} + + +/*virtual*/ bool DrawLineAction::KeyReleased(int key) +{ + if ((key == Qt::Key_Shift) && shiftWasPressedOnNextPoint) + { + shiftWasPressedOnNextPoint = false; + p2 = p1; + p1 = p1Save; + state = NEXT_POINT; + return true; } + + return false; } diff --git a/src/drawlineaction.h b/src/drawlineaction.h index 0736d30..bb9aa77 100644 --- a/src/drawlineaction.h +++ b/src/drawlineaction.h @@ -15,11 +15,15 @@ class DrawLineAction: public Action virtual void MouseDown(Vector); virtual void MouseMoved(Vector); virtual void MouseReleased(void); + virtual bool KeyDown(int); + virtual bool KeyReleased(int); private: int state; Line * line; - Vector p1, p2; + Vector p1, p2, p1Save; + bool shiftWasPressedOnNextPoint; }; #endif // __DRAWLINEACTION_H__ + diff --git a/src/drawtextaction.cpp b/src/drawtextaction.cpp index fafdf95..b6a0715 100644 --- a/src/drawtextaction.cpp +++ b/src/drawtextaction.cpp @@ -85,3 +85,15 @@ DrawTextAction::~DrawTextAction() } } + +/*virtual*/ bool DrawTextAction::KeyDown(int /*key*/) +{ + return false; +} + + +/*virtual*/ bool DrawTextAction::KeyReleased(int /*key*/) +{ + return false; +} + diff --git a/src/drawtextaction.h b/src/drawtextaction.h index 23c7c6a..68c4428 100644 --- a/src/drawtextaction.h +++ b/src/drawtextaction.h @@ -15,6 +15,8 @@ class DrawTextAction: public Action virtual void MouseDown(Vector); virtual void MouseMoved(Vector); virtual void MouseReleased(void); + virtual bool KeyDown(int); + virtual bool KeyReleased(int); private: int state; @@ -23,3 +25,4 @@ class DrawTextAction: public Action }; #endif // __DRAWTEXTACTION_H__ +