AutomatableModelView.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * AutomatableModelView.h - provides AutomatableModelView base class and
  3. * provides BoolModelView, FloatModelView, IntModelView subclasses.
  4. *
  5. * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef AUTOMATABLE_MODEL_VIEW_H
  26. #define AUTOMATABLE_MODEL_VIEW_H
  27. #include "ModelView.h"
  28. #include "AutomatableModel.h"
  29. class QMenu;
  30. class QMouseEvent;
  31. class LMMS_EXPORT AutomatableModelView : public ModelView
  32. {
  33. public:
  34. AutomatableModelView( Model* model, QWidget* _this );
  35. virtual ~AutomatableModelView() = default;
  36. // some basic functions for convenience
  37. AutomatableModel* modelUntyped()
  38. {
  39. return castModel<AutomatableModel>();
  40. }
  41. const AutomatableModel* modelUntyped() const
  42. {
  43. return castModel<AutomatableModel>();
  44. }
  45. void setModel( Model* model, bool isOldModelValid = true ) override;
  46. template<typename T>
  47. inline T value() const
  48. {
  49. return modelUntyped() ? modelUntyped()->value<T>() : 0;
  50. }
  51. inline void setDescription( const QString& desc )
  52. {
  53. m_description = desc;
  54. }
  55. inline void setUnit( const QString& unit )
  56. {
  57. m_unit = unit;
  58. }
  59. void addDefaultActions( QMenu* menu );
  60. protected:
  61. virtual void mousePressEvent( QMouseEvent* event );
  62. QString m_description;
  63. QString m_unit;
  64. } ;
  65. class AutomatableModelViewSlots : public QObject
  66. {
  67. Q_OBJECT
  68. public:
  69. AutomatableModelViewSlots( AutomatableModelView* amv, QObject* parent );
  70. public slots:
  71. void execConnectionDialog();
  72. void removeConnection();
  73. void editSongGlobalAutomation();
  74. void unlinkAllModels();
  75. void removeSongGlobalAutomation();
  76. private slots:
  77. /// Copy the model's value to the clipboard.
  78. void copyToClipboard();
  79. /// Paste the model's value from the clipboard.
  80. void pasteFromClipboard();
  81. protected:
  82. AutomatableModelView* m_amv;
  83. } ;
  84. template <typename ModelType> class LMMS_EXPORT TypedModelView : public AutomatableModelView
  85. {
  86. public:
  87. TypedModelView( Model* model, QWidget* _this) :
  88. AutomatableModelView( model, _this )
  89. {}
  90. ModelType* model()
  91. {
  92. return castModel<ModelType>();
  93. }
  94. const ModelType* model() const
  95. {
  96. return castModel<ModelType>();
  97. }
  98. };
  99. using FloatModelView = TypedModelView<FloatModel>;
  100. using IntModelView = TypedModelView<IntModel>;
  101. using BoolModelView = TypedModelView<BoolModel>;
  102. #endif