Engauge Digitizer 2
Loading...
Searching...
No Matches
DigitizeStateGuideline.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2020 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
8#include "CmdGuidelineAddXT.h"
9#include "CmdGuidelineAddYR.h"
10#include "CmdGuidelineMoveXT.h"
11#include "CmdGuidelineMoveYR.h"
12#include "CmdMediator.h"
13#include "ColorFilter.h"
14#include "CurveStyles.h"
15#include "DataKey.h"
18#include "Document.h"
19#include "EngaugeAssert.h"
20#include "EnumsToQt.h"
21#include "GraphicsItemType.h"
22#include "GraphicsScene.h"
23#include "Logger.h"
24#include "MainWindow.h"
25#include <QApplication>
26#include <QCursor>
27#include <QGraphicsEllipseItem>
28#include <QGraphicsItem>
29#include <QGraphicsScene>
30#include <QImage>
31#include <qmath.h>
32#include <QMessageBox>
33#include <QPen>
34#include <QSize>
35#include "Transformation.h"
36
42
47
52
54 DigitizeState /* previousState */)
55{
56 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateGuideline::beginn";
57
58 setCursor(cmdMediator);
59 context().setDragMode(QGraphicsView::NoDrag);
60 lockNonGuidelinesAndUnlockGuidelines (true);
61}
62
63bool DigitizeStateGuideline::canPaste (const Transformation & /* transformation */,
64 const QSize & /* viewSize */) const
65{
66 return false;
67}
68
70 double valueSelected)
71{
72 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateGuideline::createGuidelineCommand";
73
74 CmdAbstract *cmd = nullptr;
75 if (selectedXT) {
76 cmd = new CmdGuidelineAddXT (context().mainWindow(),
77 context().mainWindow().cmdMediator()->document(),
78 valueSelected);
79 } else {
80 cmd = new CmdGuidelineAddYR (context().mainWindow(),
81 context().mainWindow().cmdMediator()->document(),
82 valueSelected);
83 }
84
85 context().appendNewCmd (context().mainWindow().cmdMediator(),
86 cmd);
87}
88
89QCursor DigitizeStateGuideline::cursor(CmdMediator * /* cmdMediator */) const
90{
91 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateGuideline::cursor";
92
93 return QCursor (Qt::ArrowCursor);
94}
95
97{
98 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateGuideline::end";
99
100 lockNonGuidelinesAndUnlockGuidelines (false);
101}
102
104{
105 return false;
106}
107
109 const QString &pointIdentifier)
110{
111 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateGuideline::handleContextMenuEventAxis "
112 << " point=" << pointIdentifier.toLatin1 ().data ();
113}
114
116 const QStringList &pointIdentifiers)
117{
118 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateGuideline ::handleContextMenuEventGraph "
119 << "points=" << pointIdentifiers.join(",").toLatin1 ().data ();
120}
121
123{
124}
125
127 Qt::Key key,
128 bool atLeastOneSelectedItem)
129{
130 m_context->handleKeyPress (key,
131 atLeastOneSelectedItem);
132}
133
135 QPointF posScreen)
136{
137 m_context->handleMouseMove (posScreen);
138}
139
141 QPointF posScreen)
142{
143 m_context->handleMousePress (&context().mainWindow ().scene (),
144 context().mainWindow ().transformation (),
145 cmdMediator->document ().modelGuideline (),
146 cmdMediator->document ().modelCoords (),
147 posScreen,
148 hitTestForGraphics (posScreen));
149}
150
152 QPointF posScreen)
153{
154 m_context->handleMouseRelease (posScreen);
155}
156
157bool DigitizeStateGuideline::hitTestForGraphics (const QPointF &posScreen)
158{
159 // Create temporary graphics item representing click
160 QGraphicsItem *itemClick = new QGraphicsRectItem (QRectF (posScreen - QPointF (2, 2),
161 posScreen + QPointF (2, 2)));
163 context().mainWindow().scene().addItem (itemClick);
164
165 // Iterate through existing graphics items
166
167 QList<QGraphicsItem*> items = context().mainWindow().scene().items();
168 QList<QGraphicsItem*>::iterator itr;
169
170 bool gotHit = false;
171
172 for (itr = items.begin (); itr != items.end (); itr++) {
173
174 QGraphicsItem *item = *itr;
175
176 // Object has to be a Guideline, visible, selectable and overlapping with itemClick to be applicable
177 bool isGuideline = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE) == GRAPHICS_ITEM_TYPE_GUIDELINE);
178 bool isVisible = item->isVisible();
179 bool isCollision = item->collidesWithItem (itemClick);
180 if (isGuideline && isVisible && isCollision) {
181 gotHit = true;
182 break;
183 }
184 }
185
186 // Remove temporary graphics item
187 context().mainWindow().scene().removeItem (itemClick);
188 delete itemClick;
189
190 return gotHit;
191}
192
193void DigitizeStateGuideline::lockNonGuidelinesAndUnlockGuidelines (bool lockdown)
194{
195 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateGuideline::lockNonGuidelinesAndUnlockGuidelines";
196
197 QList<QGraphicsItem*> items = context().mainWindow().scene().items();
198 QList<QGraphicsItem*>::iterator itr;
199 for (itr = items.begin (); itr != items.end (); itr++) {
200
201 QGraphicsItem *item = *itr;
202 GraphicsItemType type = static_cast<GraphicsItemType> (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt());
203 if (type == GRAPHICS_ITEM_TYPE_LINE ||
204 type == GRAPHICS_ITEM_TYPE_POINT ||
207
208 item->setFlag (QGraphicsItem::ItemIsSelectable, !lockdown);
209 item->setFlag (QGraphicsItem::ItemIsMovable, !lockdown);
210 item->setFlag (QGraphicsItem::ItemIsFocusable, !lockdown);
211
212 } else if (type == GRAPHICS_ITEM_TYPE_GUIDELINE) {
213
214 item->setFlag (QGraphicsItem::ItemIsSelectable, lockdown);
215 item->setFlag (QGraphicsItem::ItemIsMovable, lockdown);
216 item->setFlag (QGraphicsItem::ItemIsFocusable, lockdown);
217 item->setAcceptHoverEvents (lockdown);
218 item->setVisible (true);
219
220 }
221 }
222}
223
225{
226 return "DigitizeStateGuideline";
227}
228
232
234 const DocumentModelDigitizeCurve & /* curve */)
235{
236}
237
239{
240}
@ DATA_KEY_GRAPHICS_ITEM_TYPE
Definition DataKey.h:15
DigitizeState
Set of possible states of Digitize toolbar.
GraphicsItemType
Runtime type identification (RTTI) for QGraphicsItem objects.
@ GRAPHICS_ITEM_TYPE_GUIDELINE
@ GRAPHICS_ITEM_TYPE_SCALE_BAR
@ GRAPHICS_ITEM_TYPE_SEGMENT
@ GRAPHICS_ITEM_TYPE_LINE
@ GRAPHICS_ITEM_TYPE_POINT
log4cpp::Category * mainCat
Definition Logger.cpp:14
State context class for tracking the steps involved in creating centipedes in preparation for creatin...
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition CmdAbstract.h:24
Command for adding one X/T Guideline value.
Command for adding one Y/R Guideline value.
Command queue stack.
Definition CmdMediator.h:24
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
DigitizeStateAbstractBase(DigitizeStateContext &context)
Single constructor.
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 handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual bool canPaste(const Transformation &transformation, const QSize &viewSize) const
Return true if there is good data in the clipboard for pasting, and that is compatible with the curre...
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
virtual QString state() const
State name for debugging.
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual bool guidelinesAreSelectable() const
Enable/disable guidelines according to state.
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
void createGuidelineCommand(bool selectedXT, double valueSelected)
Create command to add Guideline for CentipedeStateContext.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
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...
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
DigitizeStateGuideline(DigitizeStateContext &context)
Single constructor.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &curve)
Update the digitize curve settings.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Model for DlgSettingsSegments and CmdSettingsSegments.
DocumentModelGuideline modelGuideline() const
Get method for DocumentModelGuideline.
Definition Document.cpp:756
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition Document.cpp:707
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
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