Loading...
Searching...
No Matches
QGraphicsTimeChooser.hpp
1#pragma once
2#include <functional>
3#include <score/graphics/widgets/Constants.hpp>
4
5#include <ossia/network/value/vec.hpp>
6
7#include <QGraphicsItem>
8#include <QObject>
9
10#include <score_lib_base_export.h>
11
12#include <verdigris>
13
14namespace score
15{
16// A time value that is either free-running (seconds, continuous) or
17// tempo-synced (a musical division). Renders as a standard knob with the
18// readout below it; dragging the knob changes the value, clicking the
19// readout toggles the mode (with per-mode memory so no value jumps). In
20// sync mode the knob steps through the whole division table: straight,
21// dotted and triplet, from 1/64th to four bars. A right-click on a free time
22// types it in, in seconds.
23//
24// The value is vec2f{x, sync}: x is a normalized 0..1 position when free
25// (the consumer maps it to seconds), a fraction of a whole note when synced.
26class SCORE_LIB_BASE_EXPORT QGraphicsTimeChooser final
27 : public QObject
28 , public QGraphicsItem
29{
30 W_OBJECT(QGraphicsTimeChooser)
31 SCORE_GRAPHICS_ITEM_TYPE(230)
32 friend struct DefaultControlImpl;
33 friend struct DefaultGraphicsKnobImpl;
34
35public:
36 double min{}, max{1.}, init{};
37 bool moving{};
38
42 std::function<double(double)> positionToSeconds;
43 std::function<double(double)> secondsToPosition;
44
45 explicit QGraphicsTimeChooser(QGraphicsItem* parent);
47
48 void setRange(double min, double max, double init);
49 void setRect(const QRectF& r);
50 void setValue(ossia::vec2f v);
51
52 [[nodiscard]] ossia::vec2f value() const noexcept;
53 void setExecutionValue(ossia::vec2f v);
54 [[nodiscard]] double executionPosition() const noexcept { return m_execValue; }
55 void resetExecution();
56
57 void syncChanged(bool sync);
58
61 void cycleMode();
62
64 enum class Feel : uint8_t
65 {
66 Straight,
67 Dotted,
68 Triplet
69 };
70 [[nodiscard]] bool synced() const noexcept { return m_sync; }
72 [[nodiscard]] QString freeText() const;
73 [[nodiscard]] Feel feel() const noexcept { return m_feel; }
74
75 QRectF boundingRect() const override;
76
77 void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
78 void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
79
80private:
81 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
82 override;
83 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
84 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
85 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
86 bool sceneEvent(QEvent* event) override;
87 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
88 void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
89 void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
90 void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
91
94 double map(double position) const noexcept;
95 double unmap(double seconds) const noexcept;
96 bool onReadout(QPointF pos) const noexcept;
97
98 int syncIndex() const noexcept;
100 double position(ossia::vec2f v) const noexcept;
101
102 QRectF m_rect{0., 0., 35., 35.};
103
104 double m_value{}; // knob position, 0..1, in the current mode
105 double m_execValue{};
106 double m_other01{}; // remembered position of the inactive mode
107 bool m_sync{};
108 Feel m_feel{Feel::Straight};
109 bool m_grab{};
110 bool m_hasExec{};
111 bool m_hover{};
112};
113}
Definition QGraphicsTimeChooser.hpp:29
Feel
Synced values the knob steps through (Alt or Shift: all of them).
Definition QGraphicsTimeChooser.hpp:65
std::function< double(double)> positionToSeconds
Definition QGraphicsTimeChooser.hpp:42
Base toolkit upon which the software is built.
Definition Application.cpp:83
Definition DefaultControlImpl.hpp:10
Definition DefaultGraphicsKnobImpl.hpp:27