Loading...
Searching...
No Matches
QGraphicsTimeChooser.hpp
1#pragma once
2#include <score/graphics/widgets/Constants.hpp>
3
4#include <ossia/network/value/vec.hpp>
5
6#include <QGraphicsItem>
7#include <QObject>
8
9#include <score_lib_base_export.h>
10
11#include <verdigris>
12
13namespace score
14{
15// A time value that is either free-running (seconds, continuous) or
16// tempo-synced (a musical division). Renders as a standard knob with the
17// readout below it; dragging the knob changes the value, clicking the
18// readout toggles the mode (with per-mode memory so no value jumps). In
19// sync mode the knob steps through the whole division table: straight,
20// dotted and triplet, from 1/64th to four bars.
21//
22// The value is vec2f{x, sync}: x is a normalized 0..1 position when free
23// (the consumer maps it to seconds), a fraction of a whole note when synced.
24class SCORE_LIB_BASE_EXPORT QGraphicsTimeChooser final
25 : public QObject
26 , public QGraphicsItem
27{
28 W_OBJECT(QGraphicsTimeChooser)
29 SCORE_GRAPHICS_ITEM_TYPE(230)
30 friend struct DefaultGraphicsKnobImpl;
31
32public:
33 double min{}, max{1.}, init{};
34 bool moving{};
35
36 explicit QGraphicsTimeChooser(QGraphicsItem* parent);
38
39 void setRange(double min, double max, double init);
40 void setRect(const QRectF& r);
41 void setValue(ossia::vec2f v);
42
43 [[nodiscard]] ossia::vec2f value() const noexcept;
44 void setExecutionValue(ossia::vec2f v);
45 void resetExecution();
46
47 void syncChanged(bool sync);
48
49 QRectF boundingRect() const override;
50
51 void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
52 void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
53
54private:
55 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
56 override;
57 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
58 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
59 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
60 bool sceneEvent(QEvent* event) override;
61 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
62 void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
63 void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
64
65 int syncIndex() const noexcept;
66 QString freeText() const;
67
68 QRectF m_rect{0., 0., 35., 35.};
69
70 double m_value{}; // knob position, 0..1, in the current mode
71 double m_execValue{};
72 double m_other01{}; // remembered position of the inactive mode
73 bool m_sync{};
74 bool m_grab{};
75 bool m_hasExec{};
76 bool m_hover{};
77};
78}
Definition QGraphicsTimeChooser.hpp:27
Base toolkit upon which the software is built.
Definition Application.cpp:113
Definition DefaultGraphicsKnobImpl.hpp:26