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() )