7#include "CmdMediator.h"
10#include "DigitizeStateContext.h"
11#include "DigitizeStateSelect.h"
12#include "EngaugeAssert.h"
13#include "GraphicsItemType.h"
14#include "GraphicsScene.h"
15#include "GraphicsView.h"
17#include "MainWindow.h"
19#include <QGraphicsItem>
22#include <QtToString.h>
24const QString MOVE_TEXT_DOWN (QObject::tr (
"Move down"));
25const QString MOVE_TEXT_LEFT (QObject::tr (
"Move left"));
26const QString MOVE_TEXT_RIGHT (QObject::tr (
"Move right"));
27const QString MOVE_TEXT_UP (QObject::tr (
"Move up"));
34DigitizeStateSelect::~DigitizeStateSelect ()
46 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::begin";
51 setCursorForPoints ();
57 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateSelect::cursor";
59 return QCursor (Qt::ArrowCursor);
64 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::end";
66 unsetCursorForPoints ();
71 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleCurveChange";
76 bool atLeastOneSelectedItem)
78 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleKeyPress"
79 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
81 if (atLeastOneSelectedItem) {
83 if (key == Qt::Key_Down ||
85 key == Qt::Key_Left ||
86 key == Qt::Key_Right) {
88 keyPressArrow (cmdMediator,
104 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMousePress"
105 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
109 m_movingStart = posScreen;
115 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::handleMouseRelease"
116 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();
118 QPointF deltaScreen = posScreen - m_movingStart;
121 bool positionHasChanged = (positionHasChangedIdentifers.count () > 0);
123 if (positionHasChanged && (
124 deltaScreen.x () != 0 ||
125 deltaScreen.y () != 0)) {
127 QString moveText = moveTextFromDeltaScreen (deltaScreen);
134 positionHasChangedIdentifers);
146void DigitizeStateSelect::keyPressArrow (
CmdMediator *cmdMediator,
153 deltaScreen = QPointF (0, zoomedToUnzoomedScreenY ());
154 moveText = MOVE_TEXT_DOWN;
158 deltaScreen = QPointF (-1 * zoomedToUnzoomedScreenX (), 0);
159 moveText = MOVE_TEXT_LEFT;
163 deltaScreen = QPointF (zoomedToUnzoomedScreenX (), 0);
164 moveText = MOVE_TEXT_RIGHT;
168 deltaScreen = QPointF (0, -1 * zoomedToUnzoomedScreenY ());
169 moveText = MOVE_TEXT_UP;
173 ENGAUGE_ASSERT (
false);
181 context().mainWindow().scene ().selectedPointIdentifiers ());
186QString DigitizeStateSelect::moveTextFromDeltaScreen (
const QPointF &deltaScreen)
195 bool downOrRight = (deltaScreen.y () > -1.0 * deltaScreen.x ());
196 bool upOrRight = (deltaScreen.y () < deltaScreen.x ());
197 if (downOrRight && upOrRight) {
198 moveText = MOVE_TEXT_RIGHT;
199 }
else if (downOrRight && !upOrRight) {
200 moveText = MOVE_TEXT_DOWN;
201 }
else if (!downOrRight && upOrRight) {
202 moveText = MOVE_TEXT_UP;
204 moveText = MOVE_TEXT_LEFT;
210void DigitizeStateSelect::setCursorForPoints()
212 QCursor
cursor (Qt::OpenHandCursor);
215 QList<QGraphicsItem*>::iterator itr;
216 for (itr = items.begin (); itr != items.end (); itr++) {
218 QGraphicsItem *item = *itr;
219 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
227 return "DigitizeStateSelect";
230void DigitizeStateSelect::unsetCursorForPoints()
233 QList<QGraphicsItem*>::iterator itr;
234 for (itr = items.begin (); itr != items.end (); itr++) {
236 QGraphicsItem *item = *itr;
237 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_POINT) {
238 item->unsetCursor ();
246 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelDigitizeCurve";
251 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateSelect::updateModelSegments";
254double DigitizeStateSelect::zoomedToUnzoomedScreenX ()
const
260double DigitizeStateSelect::zoomedToUnzoomedScreenY ()
const
Command for moving all selected Points by a specified translation.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses,...
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual void handleMouseMove(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
DigitizeStateSelect(DigitizeStateContext &context)
Single constructor.
virtual QString state() const
State name for debugging.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Model for DlgSettingsSegments and CmdSettingsSegments.
QStringList positionHasChangedPointIdentifiers() const
Return a list of identifiers for the points that have moved since the last call to resetPositionHasCh...
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
void updateAfterMouseRelease()
Call MainWindow::updateControls (which is private) after the very specific case - a mouse press/relea...
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.