CurveSegmentView.hpp
1 #pragma once
2 #include <score/model/IdentifiedObjectMap.hpp>
3 #include <score/model/Identifier.hpp>
4 
5 #include <QGraphicsItem>
6 #include <QPainterPath>
7 #include <QPoint>
8 #include <QRect>
9 
10 #include <score_plugin_curve_export.h>
11 
12 #include <verdigris>
13 class QGraphicsSceneContextMenuEvent;
14 class QPainter;
15 class QStyleOptionGraphicsItem;
16 class QWidget;
17 
18 namespace Curve
19 {
20 class SegmentModel;
21 
22 struct Style;
23 class SCORE_PLUGIN_CURVE_EXPORT SegmentView final
24  : public QObject
25  , public QGraphicsItem
26 {
27  W_OBJECT(SegmentView)
28  Q_INTERFACES(QGraphicsItem)
29 public:
31  const SegmentModel* model, const Curve::Style& style, QGraphicsItem* parent);
32 
33  const Id<SegmentModel>& id() const;
34 
35  static const constexpr int Type = QGraphicsItem::UserType + 101;
36  int type() const final override { return Type; }
37 
38  QRectF boundingRect() const override;
39  QPainterPath shape() const override;
40  QPainterPath opaqueArea() const override;
41  bool contains(const QPointF& pt) const override;
42 
43  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
44  override;
45 
46  void setModel(const SegmentModel*);
47  const SegmentModel& model() const { return *m_model; }
48 
49  void setRect(const QRectF& theRect);
50 
51  void setSelected(bool selected);
52 
53  void enable();
54  void disable();
55 
56  void setTween(bool b);
57 
58 public:
59  void contextMenuRequested(const QPoint& arg_1, const QPointF& arg_2)
60  E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, contextMenuRequested, arg_1, arg_2)
61 
62 protected:
63  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
64 
65 private:
66  void recomputeStroke() const;
67  void updatePoints();
68  void updatePen();
69  // Takes a table of points and draws them in a square given by the
70  // boundingRect
71  // QGraphicsItem interface
72  QRectF m_rect;
73 
74  const SegmentModel* m_model{};
75  const QPen* m_pen{};
76  const Curve::Style& m_style;
77 
78  QPainterPath m_unstrokedShape;
79  mutable QPainterPath m_strokedShape;
80 
81  bool m_enabled{true};
82  bool m_tween{false};
83  bool m_selected{};
84  mutable bool m_needsRecompute{false};
85 };
86 }
87 
88 #if !defined(SCORE_ALL_UNITY)
89 //extern template class IdContainer<Curve::SegmentView, Curve::SegmentModel>;
90 #endif
Definition: CurveSegmentModel.hpp:32
Definition: CurveSegmentView.hpp:26
The id_base_t class.
Definition: Identifier.hpp:57
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12
Definition: CurveStyle.hpp:13