AutomatableButton.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * AutomatableButton.h - class automatableButton, the base for all buttons
  3. *
  4. * Copyright (c) 2006-2008 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 AUTOMATABLE_BUTTON_H
  25. #define AUTOMATABLE_BUTTON_H
  26. #include <QPushButton>
  27. #include "AutomatableModelView.h"
  28. class automatableButtonGroup;
  29. class LMMS_EXPORT AutomatableButton : public QPushButton, public BoolModelView
  30. {
  31. Q_OBJECT
  32. public:
  33. AutomatableButton( QWidget * _parent, const QString & _name
  34. = QString() );
  35. virtual ~AutomatableButton();
  36. inline void setCheckable( bool _on )
  37. {
  38. QPushButton::setCheckable( _on );
  39. model()->setJournalling( _on );
  40. }
  41. void modelChanged() override;
  42. public slots:
  43. virtual void update();
  44. virtual void toggle();
  45. virtual void setChecked( bool _on )
  46. {
  47. // QPushButton::setChecked is called in update-slot
  48. model()->setValue( _on );
  49. }
  50. protected:
  51. void contextMenuEvent( QContextMenuEvent * _me ) override;
  52. void mousePressEvent( QMouseEvent * _me ) override;
  53. void mouseReleaseEvent( QMouseEvent * _me ) override;
  54. private:
  55. automatableButtonGroup * m_group;
  56. friend class automatableButtonGroup;
  57. using QPushButton::setChecked;
  58. using QPushButton::isChecked;
  59. } ;
  60. class LMMS_EXPORT automatableButtonGroup : public QWidget, public IntModelView
  61. {
  62. Q_OBJECT
  63. public:
  64. automatableButtonGroup( QWidget * _parent, const QString & _name
  65. = QString() );
  66. virtual ~automatableButtonGroup();
  67. void addButton( AutomatableButton * _btn );
  68. void removeButton( AutomatableButton * _btn );
  69. void activateButton( AutomatableButton * _btn );
  70. void modelChanged() override;
  71. private slots:
  72. void updateButtons();
  73. private:
  74. QList<AutomatableButton *> m_buttons;
  75. } ;
  76. #endif