From 126ec55314d2dcc4d768a7efb2e4ea805549b1e9 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 9 Jul 2023 17:48:20 +0200 Subject: [PATCH] Enable horizontal direction of manipulation Extend `FloatModelEditorBase` so that it also allows manipulation of the values when the mouse is moved in horizontal directions. The default is to use the vertical direction. Make use of this new feature in `BarModelEditor` which now reacts to horizontal movements when changing values. --- include/FloatModelEditorBase.h | 11 ++++++++++- src/gui/widgets/BarModelEditor.cpp | 2 +- src/gui/widgets/FloatModelEditorBase.cpp | 10 ++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/FloatModelEditorBase.h b/include/FloatModelEditorBase.h index 35fab8195..043885d52 100644 --- a/include/FloatModelEditorBase.h +++ b/include/FloatModelEditorBase.h @@ -52,7 +52,14 @@ class LMMS_EXPORT FloatModelEditorBase : public QWidget, public FloatModelView void initUi( const QString & _name ); //!< to be called by ctors public: - FloatModelEditorBase( QWidget * _parent = nullptr, const QString & _name = QString() ); //!< default ctor + + enum class DirectionOfManipulation + { + Vertical, + Horizontal + }; + + FloatModelEditorBase( DirectionOfManipulation directionOfManipulation = DirectionOfManipulation::Vertical, QWidget * _parent = nullptr, const QString & _name = QString() ); //!< default ctor FloatModelEditorBase( const FloatModelEditorBase& other ) = delete; // TODO: remove @@ -109,6 +116,8 @@ private: QPoint m_lastMousePos; //!< mouse position in last mouseMoveEvent float m_leftOver; bool m_buttonPressed; + + DirectionOfManipulation m_directionOfManipulation; }; diff --git a/src/gui/widgets/BarModelEditor.cpp b/src/gui/widgets/BarModelEditor.cpp index 74c2e2b1f..0464fb789 100644 --- a/src/gui/widgets/BarModelEditor.cpp +++ b/src/gui/widgets/BarModelEditor.cpp @@ -7,7 +7,7 @@ namespace lmms::gui { BarModelEditor::BarModelEditor(QString text, FloatModel * floatModel, QWidget * parent) : - FloatModelEditorBase(parent), + FloatModelEditorBase(DirectionOfManipulation::Horizontal, parent), m_text(text) { setModel(floatModel); diff --git a/src/gui/widgets/FloatModelEditorBase.cpp b/src/gui/widgets/FloatModelEditorBase.cpp index 44aa60448..d96938d7e 100644 --- a/src/gui/widgets/FloatModelEditorBase.cpp +++ b/src/gui/widgets/FloatModelEditorBase.cpp @@ -51,12 +51,13 @@ namespace lmms::gui SimpleTextFloat * FloatModelEditorBase::s_textFloat = nullptr; -FloatModelEditorBase::FloatModelEditorBase(QWidget * _parent, const QString & _name ) : +FloatModelEditorBase::FloatModelEditorBase(DirectionOfManipulation directionOfManipulation, QWidget * _parent, const QString & _name ) : QWidget( _parent ), FloatModelView( new FloatModel( 0, 0, 0, 1, nullptr, _name, true ), this ), m_volumeKnob( false ), m_volumeRatio( 100.0, 0.0, 1000000.0 ), - m_buttonPressed( false ) + m_buttonPressed( false ), + m_directionOfManipulation(directionOfManipulation) { initUi( _name ); } @@ -80,10 +81,11 @@ void FloatModelEditorBase::initUi( const QString & _name ) float FloatModelEditorBase::getValue( const QPoint & _p ) { - float value; + // Find out which direction/coordinate is relevant for this control + int const coordinate = m_directionOfManipulation == DirectionOfManipulation::Vertical ? _p.y() : -_p.x(); // knob value increase is linear to mouse movement - value = .4f * _p.y(); + float value = .4f * coordinate; // if shift pressed we want slower movement if( getGUI()->mainWindow()->isShiftPressed() )