LcdWidget.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * LcdWidget.h - a widget for displaying numbers in LCD style
  3. *
  4. * Copyright (c) 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_WIDGET_H
  25. #define LCD_WIDGET_H
  26. #include <QtCore/QMap>
  27. #include <QWidget>
  28. #include "lmms_export.h"
  29. class LMMS_EXPORT LcdWidget : public QWidget
  30. {
  31. Q_OBJECT
  32. // theming qproperties
  33. Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor )
  34. Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
  35. public:
  36. explicit LcdWidget(QWidget* parent, const QString& name = QString(), bool leadingZero = false);
  37. LcdWidget(int numDigits, QWidget* parent, const QString& name = QString(), bool leadingZero = false);
  38. LcdWidget(int numDigits, const QString& style, QWidget* parent, const QString& name = QString(),
  39. bool leadingZero = false);
  40. virtual ~LcdWidget();
  41. void setValue( int value );
  42. void setLabel( const QString& label );
  43. void addTextForValue( int value, const QString& text )
  44. {
  45. m_textForValue[value] = text;
  46. update();
  47. }
  48. Q_PROPERTY( int numDigits READ numDigits WRITE setNumDigits )
  49. inline int numDigits() const { return m_numDigits; }
  50. inline void setNumDigits( int n ) { m_numDigits = n; updateSize(); }
  51. QColor textColor() const;
  52. void setTextColor( const QColor & c );
  53. QColor textShadowColor() const;
  54. void setTextShadowColor( const QColor & c );
  55. int cellHeight() const { return m_cellHeight; }
  56. void setSeamless(bool left, bool right)
  57. {
  58. m_seamlessLeft = left;
  59. m_seamlessRight = right;
  60. updateSize();
  61. }
  62. public slots:
  63. virtual void setMarginWidth( int width );
  64. protected:
  65. void paintEvent( QPaintEvent * pe ) override;
  66. virtual void updateSize();
  67. private:
  68. static const int charsPerPixmap = 12;
  69. QMap<int, QString> m_textForValue;
  70. QString m_display;
  71. QString m_label;
  72. QPixmap* m_lcdPixmap;
  73. QColor m_textColor;
  74. QColor m_textShadowColor;
  75. int m_cellWidth;
  76. int m_cellHeight;
  77. int m_numDigits;
  78. int m_marginWidth;
  79. bool m_seamlessLeft;
  80. bool m_seamlessRight;
  81. bool m_leadingZero;
  82. void initUi( const QString& name, const QString &style ); //!< to be called by ctors
  83. };
  84. #endif