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