LcdFloatSpinBox.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * LcdFloatSpinBox.h - class LcdFloatSpinBox (LcdSpinBox for floats)
  3. *
  4. * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. * Copyright (c) 2020 Martin Pavelek <he29.HS/at/gmail.com>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef LCD_FLOATSPINBOX_H
  26. #define LCD_FLOATSPINBOX_H
  27. #include <QString>
  28. #include "LcdWidget.h"
  29. #include "AutomatableModelView.h"
  30. class LMMS_EXPORT LcdFloatSpinBox : public QWidget, public FloatModelView
  31. {
  32. Q_OBJECT
  33. public:
  34. LcdFloatSpinBox(int numWhole, int numFrac, const QString& name = QString(), QWidget* parent = nullptr);
  35. LcdFloatSpinBox(int numWhole, int numFrac, const QString& style, const QString& name, QWidget* parent = nullptr);
  36. void modelChanged() override
  37. {
  38. ModelView::modelChanged();
  39. update();
  40. }
  41. void setLabel(const QString &label) { m_label = label; }
  42. public slots:
  43. virtual void update();
  44. protected:
  45. void contextMenuEvent(QContextMenuEvent *me) override;
  46. void mousePressEvent(QMouseEvent *me) override;
  47. void mouseMoveEvent(QMouseEvent *me) override;
  48. void mouseReleaseEvent(QMouseEvent *me) override;
  49. void wheelEvent(QWheelEvent *we) override;
  50. void mouseDoubleClickEvent(QMouseEvent *me) override;
  51. void paintEvent(QPaintEvent *pe) override;
  52. private:
  53. void layoutSetup(const QString &style = QString("19green"));
  54. void enterValue();
  55. float getStep() const;
  56. LcdWidget m_wholeDisplay;
  57. LcdWidget m_fractionDisplay;
  58. bool m_mouseMoving;
  59. bool m_intStep;
  60. QPoint m_origMousePos;
  61. int m_displayOffset;
  62. QString m_label;
  63. signals:
  64. void manualChange();
  65. };
  66. using LcdFloatSpinBoxModel = FloatModel;
  67. #endif