Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineStateAbstractBase.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2019 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 "DataKey.h"
8#include "EnumsToQt.h"
9#include "GraphicsItemType.h"
10#include "GuidelineAbstract.h"
14#include "Logger.h"
15#include <QGraphicsScene>
16#include <qmath.h>
17
22
26
28{
29 return m_context;
30}
31
33 GuidelineState stateHandle,
34 GuidelineState stateDeployed)
35{
36 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineStateAbstractBase::handleMousePressCommon "
37 << m_context.stateDump ().toLatin1().data();
38
39 // Unselect all selected items. This prevents the extremely confusing error where an
40 // a currently-selected axis point stays selected and gets dragged along with this Guideline,
41 // which moves the axis unexpectedly
42 QList<QGraphicsItem*>::iterator itr;
43 QList<QGraphicsItem*> items = m_context.guideline().scene().selectedItems();
44 for (itr = items.begin(); itr != items.end(); itr++) {
45 QGraphicsItem *item = *itr;
46
47 // How do we know which is the Guideline that we want to keep selected? By its type
48 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () != GRAPHICS_ITEM_TYPE_GUIDELINE) {
49 item->setSelected (false);
50 }
51 }
52
53 // Visible Guideline will follow this one. Its geometry will be set after every drag event. It is
54 // not registered with Guidelines container
56 stateDeployed);
57
58 DocumentModelGuideline modelGuideline = context ().modelGuideline ();
59
60 guidelineVisible->setGraphicsItemPen (ColorPaletteToQColor (modelGuideline.lineColor ()),
61 modelGuideline.lineWidthInactive ());
62
63 // Place new Guideline at cursor position
64 guidelineVisible->updateGeometry (posScene);
65
67
68 context().requestStateTransition (stateHandle);
69}
70
72{
73 return m_context.guideline().scene().sceneRect();
74}
@ DATA_KEY_GRAPHICS_ITEM_TYPE
Definition DataKey.h:15
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
@ GRAPHICS_ITEM_TYPE_GUIDELINE
GuidelineState
Set of possible Guideline states. See class Guideline for more information.
log4cpp::Category * mainCat
Definition Logger.cpp:14
Model for managing the coordinate values corresponding Guidelines.
double lineWidthInactive() const
Get method for line width when inactive.
ColorPalette lineColor() const
Get method for line color.
This class is a special case of the standard QGraphicsLineItem for guidelines, and serves as the base...
virtual void updateGeometry(double valueGraph)=0
Update the geometry so it passes through the specified coordinate value in graph coordinates.
void bindGuidelineVisibleToInvisible(GuidelineAbstract *guidelineVisible)
Bind a newly-created visible Guideline to this Guideline, and make this one invisible.
virtual void setGraphicsItemPen(const QColor &color, double lineWidth)=0
Wrapper for QGraphicsItem::setPen.
static QString next()
Create next identifier.
QRectF sceneRect() const
Scene rectangle in screen coordinates (=pixels)
void handleMousePressCommon(const QPointF &posAbsolute, GuidelineState stateHandle, GuidelineState stateDeployed)
Common mouse press handling.
GuidelineStateContext & context() const
Context in charge of the state classes.
GuidelineStateAbstractBase(GuidelineStateContext &context)
Single constructor.
Context class for state machine that belongs to the Guideline class.
QString stateDump() const
Dump state for debugging only.
GuidelineAbstract & guideline()
Guideline that owns this context class.
void requestStateTransition(GuidelineState guidelineState)
Request a state transition.
DocumentModelGuideline modelGuideline() const
Up-to-date guideline settings.
GuidelineAbstract * createGuideline(const QString &identifier, GuidelineState stateInitial) const
Factory method for creating a new Guideline.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18