Engauge Digitizer 2
Loading...
Searching...
No Matches
DigitizeStateAbstractBase.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "CmdMediator.h"
8#include "CmdMoveBy.h"
11#include "Document.h"
12#include "EngaugeAssert.h"
14#include "GraphicsItemType.h"
15#include "GraphicsScene.h"
16#include "GraphicsView.h"
17#include "Logger.h"
18#include "MainWindow.h"
19#include "MainWindowModel.h"
20#include "MimePointsDetector.h"
21#include <QCursor>
22#include <QGraphicsScene>
23#include <QImage>
24#include <QSize>
25#include <QTimer>
26#include "QtToString.h"
27#include "Transformation.h"
28
29const QString MOVE_TEXT_DOWN (QObject::tr ("Move down"));
30const QString MOVE_TEXT_LEFT (QObject::tr ("Move left"));
31const QString MOVE_TEXT_RIGHT (QObject::tr ("Move right"));
32const QString MOVE_TEXT_UP (QObject::tr ("Move up"));
33
38
42
44 const QSize &viewSize) const
45{
46 MimePointsDetector mimePointsDetector;
47
48 return mimePointsDetector.isMimePointsData (transformation,
49 viewSize);
50}
51
56
58{
59 return m_context;
60}
61
63 Qt::Key key,
64 bool atLeastOneSelectedItem)
65{
66 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleKeyPressArrow"
67 << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
68
69 if (atLeastOneSelectedItem) {
70
71 if (key == Qt::Key_Down ||
72 key == Qt::Key_Up ||
73 key == Qt::Key_Left ||
74 key == Qt::Key_Right) {
75
76 keyPressArrow (cmdMediator,
77 key);
78
79 }
80 }
81}
82
83void DigitizeStateAbstractBase::keyPressArrow (CmdMediator *cmdMediator,
84 Qt::Key key)
85{
86 QPointF deltaScreen;
87 QString moveText;
88 switch (key) {
89 case Qt::Key_Down:
90 deltaScreen = QPointF (0, zoomedToUnzoomedScreenY ());
91 moveText = moveTextDown();
92 break;
93
94 case Qt::Key_Left:
95 deltaScreen = QPointF (-1 * zoomedToUnzoomedScreenX (), 0);
96 moveText = moveTextLeft();
97 break;
98
99 case Qt::Key_Right:
100 deltaScreen = QPointF (zoomedToUnzoomedScreenX (), 0);
101 moveText = moveTextRight();
102 break;
103
104 case Qt::Key_Up:
105 deltaScreen = QPointF (0, -1 * zoomedToUnzoomedScreenY ());
106 moveText = moveTextUp();
107 break;
108
109 default:
110 ENGAUGE_ASSERT (false);
111 }
112
113 // Create command to move points
114 GraphicsItemsExtractor graphicsItemsExtractor;
115 const QList<QGraphicsItem*> &items = context().mainWindow().scene ().selectedItems();
116 CmdMoveBy *cmd = new CmdMoveBy (context().mainWindow(),
117 cmdMediator->document(),
118 deltaScreen,
119 moveText,
120 graphicsItemsExtractor.selectedPointIdentifiers (items));
121 context().appendNewCmd (cmdMediator,
122 cmd);
123}
124
126{
127 return MOVE_TEXT_DOWN;
128}
129
131{
132 return MOVE_TEXT_LEFT;
133}
134
136{
137 return MOVE_TEXT_RIGHT;
138}
139
141{
142 return MOVE_TEXT_UP;
143}
144
146{
147 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAbstractBase::setCursor";
148
149 // Note that we are setting the QGraphicsView cursor and NOT the QApplication override cursor
150 m_context.view ().setCursor (cursor (cmdMediator));
151}
152
153double DigitizeStateAbstractBase::zoomedToUnzoomedScreenX () const
154{
155 double m11 = context().mainWindow ().view ().transform().m11 ();
156 return 1.0 / m11;
157}
158
159double DigitizeStateAbstractBase::zoomedToUnzoomedScreenY () const
160{
161 double m22 = context().mainWindow ().view ().transform().m22 ();
162 return 1.0 / m22;
163}
const QString MOVE_TEXT_UP(QObject::tr("Move up"))
const QString MOVE_TEXT_DOWN(QObject::tr("Move down"))
const QString MOVE_TEXT_LEFT(QObject::tr("Move left"))
const QString MOVE_TEXT_RIGHT(QObject::tr("Move right"))
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Definition Logger.cpp:14
Command queue stack.
Definition CmdMediator.h:24
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
QString moveTextUp() const
Display text for up arrow.
QString moveTextDown() const
Display text for down arrow.
QString moveTextLeft() const
Display text for left arrow.
virtual void handleKeyPressArrow(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
If the key is an arrow (left, right, up, down) then move currently selected items.
DigitizeStateAbstractBase(DigitizeStateContext &context)
Single constructor.
QString moveTextRight() const
Display text for right arrow.
virtual QCursor cursor(CmdMediator *cmdMediator) const =0
Returns the state-specific cursor shape.
bool canPasteProtected(const Transformation &transformation, const QSize &viewSize) const
Protected version of canPaste method. Some, but not all, leaf classes use this method.
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 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.
QStringList selectedPointIdentifiers(const QList< QGraphicsItem * > &items) const
Return list of selected point identifiers.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
Detect if text is acceptable for ingestion by MimePoints.
bool isMimePointsData(const Transformation &transforation, const QSize &screenSize) const
Returns true if text is acceptable mime data.
Affine transformation between screen and graph coordinates, based on digitized axis points.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20