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.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() )
|
||||
|
||||
Reference in New Issue
Block a user