Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2025 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #pragma once
23 :
24 : #include <qqmlintegration.h>
25 :
26 : #include <QObject>
27 :
28 : #include "global/types/val.h"
29 :
30 : namespace muse::uicomponents {
31 : class TableViewCell : public QObject
32 : {
33 : Q_OBJECT
34 : QML_ELEMENT;
35 :
36 : Q_PROPERTY(QVariant value READ value_property WRITE setValue_property NOTIFY valueChanged)
37 :
38 : Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged FINAL)
39 : Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged FINAL)
40 :
41 : Q_PROPERTY(bool hovered READ hovered WRITE setHovered NOTIFY hoveredChanged FINAL)
42 : Q_PROPERTY(bool pressed READ pressed WRITE setPressed NOTIFY pressedChanged FINAL)
43 :
44 : public:
45 : explicit TableViewCell(QObject* parent = nullptr);
46 :
47 : Val value() const;
48 : void setValue(const Val& value);
49 :
50 0 : virtual Val sortValue() const { return m_val; }
51 :
52 : void setRequestChangeFunction(const std::function<bool(int, int, const Val&)>& func);
53 :
54 : QVariant value_property() const;
55 : void setValue_property(const QVariant& newValue);
56 :
57 : int row() const;
58 : void setRow(int row);
59 :
60 : bool hovered() const;
61 : void setHovered(bool hovered);
62 :
63 : bool pressed() const;
64 : void setPressed(bool pressed);
65 :
66 : int column() const;
67 : void setColumn(int column);
68 :
69 : signals:
70 : void valueChanged();
71 :
72 : void rowChanged();
73 : void columnChanged();
74 :
75 : void hoveredChanged();
76 : void pressedChanged();
77 :
78 : void requestEdit();
79 :
80 : protected:
81 : Val m_val;
82 :
83 : std::function<bool(int /*row*/, int /*column*/, const Val& /*newValue*/)> m_requestChangeFunction;
84 :
85 : int m_row = -1;
86 : int m_column = -1;
87 :
88 : bool m_hovered = false;
89 : bool m_pressed = false;
90 : };
91 : }
|