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