LcdSpinBox.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * LcdSpinBox.h - class LcdSpinBox, an improved QLCDNumber
  3. *
  4. * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef LCD_SPINBOX_H
  25. #define LCD_SPINBOX_H
  26. #include "LcdWidget.h"
  27. #include "AutomatableModelView.h"
  28. class LMMS_EXPORT LcdSpinBox : public LcdWidget, public IntModelView
  29. {
  30. Q_OBJECT
  31. public:
  32. LcdSpinBox( int numDigits, QWidget* parent, const QString& name = QString() );
  33. LcdSpinBox( int numDigits, const QString& style, QWidget* parent, const QString& name = QString() );
  34. virtual ~LcdSpinBox() = default;
  35. void modelChanged() override
  36. {
  37. ModelView::modelChanged();
  38. update();
  39. }
  40. /*! Sets an offset which is always added to value of model so we can
  41. display values in a user-friendly way if they internally start at 0 */
  42. void setDisplayOffset( int offset )
  43. {
  44. m_displayOffset = offset;
  45. }
  46. /*! \brief Returns internal offset for displaying values */
  47. int displayOffset() const
  48. {
  49. return m_displayOffset;
  50. }
  51. public slots:
  52. virtual void update();
  53. protected:
  54. void contextMenuEvent( QContextMenuEvent * _me ) override;
  55. void mousePressEvent( QMouseEvent * _me ) override;
  56. void mouseMoveEvent( QMouseEvent * _me ) override;
  57. void mouseReleaseEvent( QMouseEvent * _me ) override;
  58. void wheelEvent( QWheelEvent * _we ) override;
  59. void mouseDoubleClickEvent( QMouseEvent * _me ) override;
  60. private:
  61. float m_remainder; //!< floating offset of spinbox in [-0.5, 0.5]
  62. bool m_mouseMoving;
  63. QPoint m_lastMousePos; //!< mouse position in last mouseMoveEvent
  64. int m_displayOffset;
  65. void enterValue();
  66. signals:
  67. void manualChange();
  68. } ;
  69. typedef IntModel LcdSpinBoxModel;
  70. #endif