LcdSpinBox.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. bool m_mouseMoving;
  62. QPoint m_origMousePos;
  63. int m_displayOffset;
  64. void enterValue();
  65. signals:
  66. void manualChange();
  67. } ;
  68. typedef IntModel LcdSpinBoxModel;
  69. #endif