Loading...
Searching...
No Matches
QGraphicsCombo.hpp
1#pragma once
2#include <score/graphics/widgets/Constants.hpp>
3
4#include <QFont>
5#include <QGraphicsItem>
6#include <QObject>
7#include <QPointer>
8#include <QStringList>
9
10#include <score_lib_base_export.h>
11
12#include <array>
13#include <optional>
14#include <verdigris>
15
16class QGraphicsProxyWidget;
17
18namespace score
19{
20class Skin;
21class SCORE_LIB_BASE_EXPORT QGraphicsCombo final
22 : public QObject
23 , public QGraphicsItem
24{
25 W_OBJECT(QGraphicsCombo)
26 SCORE_GRAPHICS_ITEM_TYPE(30)
27 friend struct DefaultComboImpl;
28 QRectF m_rect{defaultSliderSize};
29
30public:
31 QStringList array;
32
33private:
34 int m_value{};
35 bool m_grab{};
36 bool m_editable{};
37
40 bool m_dragged{};
41
44 int m_pressedStep{};
45
47 bool m_stepArmed{};
48
52 QPointer<QGraphicsProxyWidget> m_editor;
53
54 std::optional<QFont> m_font;
55
56public:
57 template <std::size_t N>
58 QGraphicsCombo(const std::array<const char*, N>& arr, QGraphicsItem* parent)
59 : QGraphicsCombo{parent}
60 {
61 array.reserve(N);
62 for(auto str : arr)
63 array.push_back(str);
64
65 init();
66 }
67
68 QGraphicsCombo(QStringList arr, QGraphicsItem* parent)
69 : QGraphicsCombo{parent}
70 {
71 array = std::move(arr);
72 init();
73 }
74
75 explicit QGraphicsCombo(QGraphicsItem* parent);
76
78 static const constexpr double stepperWidth = 12.;
79
80 void init();
81 void setRect(const QRectF& r);
82 void setValue(int v);
83 int value() const;
84
86 QRectF stepperRect() const noexcept;
88 bool stepperVisible() const noexcept;
89
91 void step(int n);
92
94 const QFont& font() const noexcept;
96 void setFont(const QFont& f);
97
99 void setEditable(bool b);
100 bool editable() const noexcept { return m_editable; }
101
103 void openEditor(QPointF scenePos);
104
105 bool moving = false;
106
107 void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
108 void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
109
111 void valueEdited(const QString& text) E_SIGNAL(SCORE_LIB_BASE_EXPORT, valueEdited, text)
112
113 void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
114 void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
115 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
116 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
117 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
118 bool sceneEvent(QEvent* event) override;
119 QRectF boundingRect() const override;
120 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
121 override;
122
123private:
124 void paintStepper(QPainter& painter, const score::Skin& skin);
125};
126}
Definition QGraphicsCombo.hpp:24
Definition Skin.hpp:100
Base toolkit upon which the software is built.
Definition Application.cpp:83
Definition QGraphicsCombo.cpp:55