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"
11#include "GuidelineFormat.h"
15#include "Logger.h"
16#include <QGraphicsScene>
17#include <qmath.h>
18
23
27
29{
30 return m_context;
31}
32
34 GuidelineState stateHandle,
35 GuidelineState stateDeployed)
36{
37 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineStateAbstractBase::handleMousePressCommon "
38 << m_context.stateDump ().toLatin1().data();
39
40 // Unselect all selected items. This prevents the extremely confusing error where an
41 // a currently-selected axis point stays selected and gets dragged along with this Guideline,
42 // which moves the axis unexpectedly
43 QList<QGraphicsItem*>::iterator itr;
44 QList<QGraphicsItem*> items = m_context.guideline().scene().selectedItems();
45 for (itr = items.begin(); itr != items.end(); itr++) {
46 QGraphicsItem *item = *itr;
47
48 // How do we know which is the Guideline that we want to keep selected? By its type
49 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () != GRAPHICS_ITEM_TYPE_GUIDELINE) {
50 item->setSelected (false);
51 }
52 }
53
54 // Visible Guideline will follow this one. Its geometry will be set after every drag event. It is
55 // not registered with Guidelines container
57 stateDeployed);
58
59 GuidelineFormat guidelineFormat (context().color());
60 guidelineVisible->setGraphicsItemPen (guidelineFormat.colorDeployedNonHover (),
61 guidelineFormat.lineWidthNonHover ());
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
@ GRAPHICS_ITEM_TYPE_GUIDELINE
GuidelineState
Set of possible Guideline states. See class Guideline for more information.
log4cpp::Category * mainCat
Definition Logger.cpp:14
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.
This class centralizes the formatting information (color, line width, alpha) for the Guidelines.
QColor colorDeployedNonHover() const
Guideline color when not hovering.
double lineWidthNonHover() const
Guideline line width for narrow lines.
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.
GuidelineAbstract * createGuideline(const QString &identifier, GuidelineState stateInitial) const
Factory method for creating a new Guideline.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18