LMMS
Loading...
Searching...
No Matches
FloatModelEditorBase.h
Go to the documentation of this file.
1/*
2 * FloatModelEditorBase.h - Base editor for float models
3 *
4 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 * Copyright (c) 2023 Michael Gregorius
6 * Copyright (c) 2026 Dalton Messmer <messmer.dalton/at/gmail.com>
7 *
8 * This file is part of LMMS - https://lmms.io
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public
21 * License along with this program (see COPYING); if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301 USA.
24 *
25 */
26
27#ifndef LMMS_GUI_FLOAT_MODEL_EDITOR_BASE_H
28#define LMMS_GUI_FLOAT_MODEL_EDITOR_BASE_H
29
30#include <QPoint>
31#include <QWidget>
32#include <optional>
33
35
36namespace lmms::gui
37{
38
39class SimpleTextFloat;
40
41class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView
42{
43 Q_OBJECT
44
45 void initUi(const QString & name);
46
47public:
48 enum class DirectionOfManipulation : bool
49 {
50 Vertical,
51 Horizontal
52 };
53
54 FloatModelEditorBase(DirectionOfManipulation directionOfManipulation = DirectionOfManipulation::Vertical, QWidget * _parent = nullptr, const QString & _name = QString());
56
57 // TODO: remove
58 inline void setHintText(const QString & txt_before, const QString & txt_after)
59 {
60 setDescription(txt_before);
61 setUnit(txt_after);
62 }
63
78 void setToolTip(const QString& tip)
79 {
80 m_staticToolTip.emplace(tip);
81 }
82
83 QString toolTip() const { return m_staticToolTip.value_or(QString{}); }
84
90 void unsetToolTip() { m_staticToolTip.reset(); }
91
92signals:
95 void sliderMoved(float value);
96
97protected:
98 void contextMenuEvent(QContextMenuEvent * me) override;
99 void dragEnterEvent(QDragEnterEvent * dee) override;
100 void dropEvent(QDropEvent * de) override;
101 void focusOutEvent(QFocusEvent * fe) override;
102 void mousePressEvent(QMouseEvent * me) override;
103 void mouseReleaseEvent(QMouseEvent * me) override;
104 void mouseMoveEvent(QMouseEvent * me) override;
105 void mouseDoubleClickEvent(QMouseEvent * me) override;
106 void paintEvent(QPaintEvent * me) override;
107 void wheelEvent(QWheelEvent * me) override;
108
109#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
110 void enterEvent(QEnterEvent*) override;
111#else
112 void enterEvent(QEvent*) override;
113#endif
114 void leaveEvent(QEvent *event) override;
115
116 virtual float getValue(const QPoint & p);
117
126 virtual QString currentValueToText();
127
136 virtual std::optional<QString> currentValueToTextUpdate()
137 {
138 return currentValueToText();
139 }
140
149 virtual QString getDynamicFloatingText(const QString& currentValue) const;
150
151 void doConnections() override;
152
153 void showTextFloat(int msecBeforeDisplay, int msecDisplayTime, bool forceTextUpdate = false);
154 void showTextFloat(bool forceTextUpdate = false);
155
156 const SimpleTextFloat& textFloat() const { return *s_textFloat; }
157
158 void setPosition(const QPoint & p);
159
160 inline float pageSize() const
161 {
162 return (model()->maxValue() - model()->minValue()) / 100.0f;
163 }
164
166
168 enum class InteractionType : std::uint8_t
169 {
173
177 MouseHover,
178
181 MouseDrag,
182
185 MouseWheel
186 };
187
190
192 void updateInteractionState(QEvent* event);
193
194 enum class FloatingTextType : std::uint8_t
195 {
198
200 Static,
201
203 Dynamic
204 };
205
210 FloatingTextType floatingTextType() const;
211
214
215private slots:
216 virtual void enterValue();
217 void friendlyUpdate();
218 void toggleScale();
219
220private:
222
224
225 std::optional<QString> m_staticToolTip;
226
228};
229
230} // namespace lmms::gui
231
232#endif // LMMS_GUI_FLOAT_MODEL_EDITOR_BASE_H
void setUnit(const QString &unit)
Definition AutomatableModelView.h:69
void setDescription(const QString &desc)
Definition AutomatableModelView.h:64
T value() const
Definition AutomatableModelView.h:59
Definition FloatModelEditorBase.h:42
float pageSize() const
Definition FloatModelEditorBase.h:160
InteractionType
Types of user interaction with the control.
Definition FloatModelEditorBase.h:169
@ None
Definition FloatModelEditorBase.h:172
void mousePressEvent(QMouseEvent *me) override
Definition FloatModelEditorBase.cpp:198
void enterEvent(QEnterEvent *) override
Definition FloatModelEditorBase.cpp:271
FloatModelEditorBase(DirectionOfManipulation directionOfManipulation=DirectionOfManipulation::Vertical, QWidget *_parent=nullptr, const QString &_name=QString())
default ctor
Definition FloatModelEditorBase.cpp:63
void toggleScale()
Definition FloatModelEditorBase.cpp:164
DirectionOfManipulation directionOfManipulation() const
Definition FloatModelEditorBase.h:165
QPoint m_lastMousePos
mouse position in last mouseMoveEvent
Definition FloatModelEditorBase.h:212
const SimpleTextFloat & textFloat() const
Definition FloatModelEditorBase.h:156
void setHintText(const QString &txt_before, const QString &txt_after)
Definition FloatModelEditorBase.h:58
DirectionOfManipulation
Definition FloatModelEditorBase.h:49
void leaveEvent(QEvent *event) override
Definition FloatModelEditorBase.cpp:281
void paintEvent(QPaintEvent *me) override
Definition FloatModelEditorBase.cpp:302
void wheelEvent(QWheelEvent *me) override
Definition FloatModelEditorBase.cpp:324
QString toolTip() const
Definition FloatModelEditorBase.h:83
void initUi(const QString &name)
to be called by ctors
Definition FloatModelEditorBase.cpp:72
virtual void enterValue()
Definition FloatModelEditorBase.cpp:500
virtual std::optional< QString > currentValueToTextUpdate()
Definition FloatModelEditorBase.h:136
FloatModelEditorBase(const FloatModelEditorBase &other)=delete
void focusOutEvent(QFocusEvent *fe) override
Definition FloatModelEditorBase.cpp:288
DirectionOfManipulation m_directionOfManipulation
Definition FloatModelEditorBase.h:223
InteractionType m_interaction
Definition FloatModelEditorBase.h:221
void unsetToolTip()
Definition FloatModelEditorBase.h:90
std::optional< QString > m_staticToolTip
Definition FloatModelEditorBase.h:225
void mouseDoubleClickEvent(QMouseEvent *me) override
Definition FloatModelEditorBase.cpp:296
static SimpleTextFloat * s_textFloat
Definition FloatModelEditorBase.h:227
void mouseMoveEvent(QMouseEvent *me) override
Definition FloatModelEditorBase.cpp:232
void contextMenuEvent(QContextMenuEvent *me) override
Definition FloatModelEditorBase.cpp:146
float m_leftOver
Definition FloatModelEditorBase.h:213
void friendlyUpdate()
Definition FloatModelEditorBase.cpp:523
void dropEvent(QDropEvent *de) override
Definition FloatModelEditorBase.cpp:178
FloatingTextType
Definition FloatModelEditorBase.h:195
virtual QString currentValueToText()
Definition FloatModelEditorBase.cpp:549
InteractionType currentInteraction() const
Definition FloatModelEditorBase.h:189
virtual float getValue(const QPoint &p)
Definition FloatModelEditorBase.cpp:127
void mouseReleaseEvent(QMouseEvent *me) override
Definition FloatModelEditorBase.cpp:250
void dragEnterEvent(QDragEnterEvent *dee) override
Definition FloatModelEditorBase.cpp:171
void setToolTip(const QString &tip)
Sets the tooltip displayed when the mouse hovers over the control.
Definition FloatModelEditorBase.h:78
Definition SimpleTextFloat.h:39
FloatModel * model()
Definition AutomatableModelView.h:121
static const char * name
Definition pugl.h:1582
Definition AudioPortAudio.cpp:209
TypedModelView< FloatModel > FloatModelView
Definition AutomatableModelView.h:131
uch * p
Definition crypt.c:594
static ZCONST char Far None[]
Definition unzip.c:380