AutomatableModelView.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. void unsetModel() override;
  47. template<typename T>
  48. inline T value() const
  49. {
  50. return modelUntyped() ? modelUntyped()->value<T>() : 0;
  51. }
  52. inline void setDescription( const QString& desc )
  53. {
  54. m_description = desc;
  55. }
  56. inline void setUnit( const QString& unit )
  57. {
  58. m_unit = unit;
  59. }
  60. void addDefaultActions( QMenu* menu );
  61. void setConversionFactor( float factor );
  62. float getConversionFactor();
  63. protected:
  64. virtual void mousePressEvent( QMouseEvent* event );
  65. QString m_description;
  66. QString m_unit;
  67. float m_conversionFactor; // Factor to be applied when the m_model->value is displayed
  68. } ;
  69. class AutomatableModelViewSlots : public QObject
  70. {
  71. Q_OBJECT
  72. public:
  73. AutomatableModelViewSlots( AutomatableModelView* amv, QObject* parent );
  74. public slots:
  75. void execConnectionDialog();
  76. void removeConnection();
  77. void editSongGlobalAutomation();
  78. void unlinkAllModels();
  79. void removeSongGlobalAutomation();
  80. private slots:
  81. /// Copy the model's value to the clipboard.
  82. void copyToClipboard();
  83. /// Paste the model's value from the clipboard.
  84. void pasteFromClipboard();
  85. protected:
  86. AutomatableModelView* m_amv;
  87. } ;
  88. template <typename ModelType> class LMMS_EXPORT TypedModelView : public AutomatableModelView
  89. {
  90. public:
  91. TypedModelView( Model* model, QWidget* _this) :
  92. AutomatableModelView( model, _this )
  93. {}
  94. ModelType* model()
  95. {
  96. return castModel<ModelType>();
  97. }
  98. const ModelType* model() const
  99. {
  100. return castModel<ModelType>();
  101. }
  102. };
  103. using FloatModelView = TypedModelView<FloatModel>;
  104. using IntModelView = TypedModelView<IntModel>;
  105. using BoolModelView = TypedModelView<BoolModel>;
  106. #endif