Loading...
Searching...
No Matches
QGraphicsValueList.hpp
1#pragma once
2#include <score/graphics/widgets/Constants.hpp>
3
4#include <ossia/network/value/value.hpp>
5
6#include <QGraphicsItem>
7#include <QObject>
8#include <QStringList>
9
10#include <score_lib_base_export.h>
11
12#include <vector>
13
14#include <verdigris>
15
16namespace score
17{
21{
22 QString name;
23 double min{0.};
24 double max{127.};
25 double init{0.};
26 bool integral{true};
27 QStringList choices;
28};
29
42class SCORE_LIB_BASE_EXPORT QGraphicsValueList final
43 : public QObject
44 , public QGraphicsItem
45{
46 W_OBJECT(QGraphicsValueList)
47 SCORE_GRAPHICS_ITEM_TYPE(300)
48
49public:
50 explicit QGraphicsValueList(QGraphicsItem* parent);
52
53 void setColumns(std::vector<ValueListColumn> cols);
54 const std::vector<ValueListColumn>& columns() const noexcept { return m_columns; }
55 void setCountRange(int min, int max);
56 void setItemsPerLine(int n);
57
58 void setValue(const ossia::value& v);
59 ossia::value value() const;
60
61 QString toText() const;
63 bool setText(const QString& text);
64
66 void editAsText();
67
68 bool moving = false;
69
70 QRectF boundingRect() const override;
71
72public:
74 void sliderMoved() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderMoved)
76 void sliderReleased() E_SIGNAL(SCORE_LIB_BASE_EXPORT, sliderReleased)
78 void edited() E_SIGNAL(SCORE_LIB_BASE_EXPORT, edited)
79 void sizeChanged(QSizeF sz) E_SIGNAL(SCORE_LIB_BASE_EXPORT, sizeChanged, sz)
80
81private:
82 using Row = std::vector<double>;
83
84 bool scalar() const noexcept { return m_columns.size() == 1; }
85 int maxCount() const noexcept;
86 Row defaultRow() const;
87 Row clampRow(Row r) const;
88
89 void rebuild();
90 void updateCells();
91 void structuralEdit();
92
94 int rowAt(QPointF p) const noexcept;
95 QRectF cellRect(int row, int col) const noexcept;
96 QRectF removeRect(int row) const noexcept;
97 QRectF addRect() const noexcept;
98 QRectF popRect() const noexcept;
99 qreal headerHeight() const noexcept;
100 qreal columnWidth(int col) const noexcept;
101
102 void insertRow(int at, Row r);
103 void removeRow(int row);
104 void moveRow(int row, int dir);
105
106 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
107 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
108 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
109 void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
110 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
111 override;
112
113 std::vector<ValueListColumn> m_columns{ValueListColumn{}};
114 std::vector<Row> m_rows;
115 std::vector<std::vector<QGraphicsItem*>> m_cells;
116 QRectF m_rect;
117 int m_minCount{0};
118 int m_maxCount{-1};
119 int m_itemsPerLine{4};
122 int m_pressed{};
123};
124}
Definition QGraphicsValueList.hpp:45
void sliderMoved()
A cell is being dragged: the value changes continuously.
Base toolkit upon which the software is built.
Definition Application.cpp:83
STL namespace.
Definition QGraphicsValueList.hpp:21