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 #ifndef GUIDELINE_LINE_H
8 #define GUIDELINE_LINE_H
9 
10 #include "GuidelineAbstract.h"
11 #include <QColor>
12 #include <QGraphicsLineItem>
13 
14 class QMouseEvent;
15 class QPainter;
16 class QGraphicsScene;
17 class QStyleOptionGraphicsItem;
18 class QWidget;
19 
20 /// Line version of GuidelineAbstract
21 class GuidelineLine : public GuidelineAbstract, public QGraphicsLineItem
22 {
23 public:
24   /// Single constructor.
25   GuidelineLine(QGraphicsScene &scene,
26                 Guidelines &guidelines,
27                 GuidelineState guidelineStateInitial,
28                 const QString &identifier);
29   ~GuidelineLine();
30 
31   virtual bool getGraphicsItemAcceptHover () const;
32 
33   virtual bool getGraphicsItemSelected () const;
34 
35   virtual QGraphicsItem::GraphicsItemFlags graphicsItemFlags () const;
36 
37   /// User toggled guideline visibility
38   void handleVisibilityChange (bool visible);
39 
40   /// Highlight this Guideline upon hover enter
41   virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
42 
43   /// Unset highlighting triggered by hover enter
44   virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
45 
46   virtual QString identifier () const;
47 
48   /// Forward movements to visible Guideline
49   virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
50 
51   /// Forward press event to state machine
52   virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
53 
54   /// Cleanup after being dragged
55   virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
56 
57   /// Override painting so this disappears when selected. Selected Guidelines are never visible
58   virtual void paint(QPainter *painter,
59                      const QStyleOptionGraphicsItem *option,
60                      QWidget *widget = Q_NULLPTR);
61 
62   virtual void removeFromScene (QGraphicsScene *scene);
63   virtual void setGraphicsItemAcceptHoverEvents (bool accept);
64   virtual void setGraphicsItemFlags (QGraphicsItem::GraphicsItemFlags flags);
65   virtual void setGraphicsItemLine (const QLineF &line);
66   virtual void setGraphicsItemPen (const QColor &color,
67                                    double lineWidth);
68   virtual void setGraphicsItemVisible (bool visible);
69   virtual void setGraphicsItemZValue (double z);
70   virtual void updateColor ();
71   virtual void updateGeometry (double valueGraph);
72   virtual void updateGeometry (const QPointF &posScreen);
73 
74 private:
75   GuidelineLine();
76 
77   // Forces use of setPenColor instead of QGraphicsLineItem::setPen
78   using QGraphicsLineItem::setPen;
79 
80 };
81 
82 #endif // GUIDELINE_LINE_H
83