Add LcdFloatSpinBox (extracted from microtonal PR) (#5865)

* Add changes extracted from microtonal PR

* Apply suggestions from code review

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Apply suggestions from code review

(adding oneliner spaces)

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Update src/gui/widgets/LcdFloatSpinBox.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>

* Apply suggestions from code review

Co-authored-by: Dominic Clark <mrdomclark@gmail.com>

* Implement suggestions from review

* Reorder constructor parameters, remove old code for cursor movement and hiding from Lcd*SpinBoxes

* Apply suggestions from code review

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Fix right margin width in seamless mode

* Add explanation to border drawing code

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>
Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: Dominic Clark <mrdomclark@gmail.com>
This commit is contained in:
Martin Pavelek
2021-03-15 18:06:48 +01:00
committed by GitHub
parent 8acb9222fd
commit 17ea61676f
6 changed files with 413 additions and 66 deletions

83
include/LcdFloatSpinBox.h Normal file
View File

@@ -0,0 +1,83 @@
/*
* LcdFloatSpinBox.h - class LcdFloatSpinBox (LcdSpinBox for floats)
*
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2020 Martin Pavelek <he29.HS/at/gmail.com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#ifndef LCD_FLOATSPINBOX_H
#define LCD_FLOATSPINBOX_H
#include <QString>
#include "LcdWidget.h"
#include "AutomatableModelView.h"
class LMMS_EXPORT LcdFloatSpinBox : public QWidget, public FloatModelView
{
Q_OBJECT
public:
LcdFloatSpinBox(int numWhole, int numFrac, const QString& name = QString(), QWidget* parent = nullptr);
LcdFloatSpinBox(int numWhole, int numFrac, const QString& style, const QString& name, QWidget* parent = nullptr);
void modelChanged() override
{
ModelView::modelChanged();
update();
}
void setLabel(const QString &label) { m_label = label; }
public slots:
virtual void update();
protected:
void contextMenuEvent(QContextMenuEvent *me) override;
void mousePressEvent(QMouseEvent *me) override;
void mouseMoveEvent(QMouseEvent *me) override;
void mouseReleaseEvent(QMouseEvent *me) override;
void wheelEvent(QWheelEvent *we) override;
void mouseDoubleClickEvent(QMouseEvent *me) override;
void paintEvent(QPaintEvent *pe) override;
private:
void layoutSetup(const QString &style = QString("19green"));
void enterValue();
float getStep() const;
LcdWidget m_wholeDisplay;
LcdWidget m_fractionDisplay;
bool m_mouseMoving;
bool m_intStep;
QPoint m_origMousePos;
int m_displayOffset;
QString m_label;
signals:
void manualChange();
};
using LcdFloatSpinBoxModel = FloatModel;
#endif

View File

@@ -40,9 +40,10 @@ class LMMS_EXPORT LcdWidget : public QWidget
Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
public:
LcdWidget( QWidget* parent, const QString& name = QString() );
LcdWidget( int numDigits, QWidget* parent, const QString& name = QString() );
LcdWidget( int numDigits, const QString& style, QWidget* parent, const QString& name = QString() );
explicit LcdWidget(QWidget* parent, const QString& name = QString(), bool leadingZero = false);
LcdWidget(int numDigits, QWidget* parent, const QString& name = QString(), bool leadingZero = false);
LcdWidget(int numDigits, const QString& style, QWidget* parent, const QString& name = QString(),
bool leadingZero = false);
virtual ~LcdWidget();
@@ -66,6 +67,15 @@ public:
QColor textShadowColor() const;
void setTextShadowColor( const QColor & c );
int cellHeight() const { return m_cellHeight; }
void setSeamless(bool left, bool right)
{
m_seamlessLeft = left;
m_seamlessRight = right;
updateSize();
}
public slots:
virtual void setMarginWidth( int width );
@@ -75,11 +85,6 @@ protected:
virtual void updateSize();
int cellHeight() const
{
return m_cellHeight;
}
private:
@@ -99,9 +104,12 @@ private:
int m_cellHeight;
int m_numDigits;
int m_marginWidth;
bool m_seamlessLeft;
bool m_seamlessRight;
bool m_leadingZero;
void initUi( const QString& name, const QString &style ); //!< to be called by ctors
} ;
};
#endif