LcdWidget.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. LcdWidget( QWidget* parent, const QString& name = QString() );
  37. LcdWidget( int numDigits, QWidget* parent, const QString& name = QString() );
  38. LcdWidget( int numDigits, const QString& style, QWidget* parent, const QString& name = QString() );
  39. virtual ~LcdWidget();
  40. void setValue( int value );
  41. void setLabel( const QString& label );
  42. void addTextForValue( int value, const QString& text )
  43. {
  44. m_textForValue[value] = text;
  45. update();
  46. }
  47. Q_PROPERTY( int numDigits READ numDigits WRITE setNumDigits )
  48. inline int numDigits() const { return m_numDigits; }
  49. inline void setNumDigits( int n ) { m_numDigits = n; updateSize(); }
  50. QColor textColor() const;
  51. void setTextColor( const QColor & c );
  52. QColor textShadowColor() const;
  53. void setTextShadowColor( const QColor & c );
  54. public slots:
  55. virtual void setMarginWidth( int width );
  56. protected:
  57. void paintEvent( QPaintEvent * pe ) override;
  58. virtual void updateSize();
  59. int cellHeight() const
  60. {
  61. return m_cellHeight;
  62. }
  63. private:
  64. static const int charsPerPixmap = 12;
  65. QMap<int, QString> m_textForValue;
  66. QString m_display;
  67. QString m_label;
  68. QPixmap* m_lcdPixmap;
  69. QColor m_textColor;
  70. QColor m_textShadowColor;
  71. int m_cellWidth;
  72. int m_cellHeight;
  73. int m_numDigits;
  74. int m_marginWidth;
  75. void initUi( const QString& name, const QString &style = QString("19green") ); //!< to be called by ctors
  76. } ;
  77. #endif