TimeLineWidget.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * TimeLineWidget.h - class timeLine, representing a time-line with position marker
  3. *
  4. * Copyright (c) 2004-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 TIMELINE_H
  25. #define TIMELINE_H
  26. #include <QWidget>
  27. #include "Song.h"
  28. class QPixmap;
  29. class QToolBar;
  30. class NStateButton;
  31. class TextFloat;
  32. class SongEditor;
  33. class TimeLineWidget : public QWidget, public JournallingObject
  34. {
  35. Q_OBJECT
  36. public:
  37. Q_PROPERTY( QColor barLineColor READ getBarLineColor WRITE setBarLineColor )
  38. Q_PROPERTY( QColor barNumberColor READ getBarNumberColor WRITE setBarNumberColor )
  39. Q_PROPERTY( QColor inactiveLoopColor READ getInactiveLoopColor WRITE setInactiveLoopColor )
  40. Q_PROPERTY( QBrush inactiveLoopBrush READ getInactiveLoopBrush WRITE setInactiveLoopBrush )
  41. Q_PROPERTY( QColor inactiveLoopInnerColor READ getInactiveLoopInnerColor WRITE setInactiveLoopInnerColor )
  42. Q_PROPERTY( QColor activeLoopColor READ getActiveLoopColor WRITE setActiveLoopColor )
  43. Q_PROPERTY( QBrush activeLoopBrush READ getActiveLoopBrush WRITE setActiveLoopBrush )
  44. Q_PROPERTY( QColor activeLoopInnerColor READ getActiveLoopInnerColor WRITE setActiveLoopInnerColor )
  45. Q_PROPERTY( int loopRectangleVerticalPadding READ getLoopRectangleVerticalPadding WRITE setLoopRectangleVerticalPadding )
  46. enum AutoScrollStates
  47. {
  48. AutoScrollEnabled,
  49. AutoScrollDisabled
  50. } ;
  51. enum LoopPointStates
  52. {
  53. LoopPointsDisabled,
  54. LoopPointsEnabled
  55. } ;
  56. enum BehaviourAtStopStates
  57. {
  58. BackToZero,
  59. BackToStart,
  60. KeepStopPosition
  61. } ;
  62. TimeLineWidget(int xoff, int yoff, float ppb, Song::PlayPos & pos,
  63. const TimePos & begin, Song::PlayModes mode, QWidget * parent);
  64. virtual ~TimeLineWidget();
  65. inline QColor const & getBarLineColor() const { return m_barLineColor; }
  66. inline void setBarLineColor(QColor const & barLineColor) { m_barLineColor = barLineColor; }
  67. inline QColor const & getBarNumberColor() const { return m_barNumberColor; }
  68. inline void setBarNumberColor(QColor const & barNumberColor) { m_barNumberColor = barNumberColor; }
  69. inline QColor const & getInactiveLoopColor() const { return m_inactiveLoopColor; }
  70. inline void setInactiveLoopColor(QColor const & inactiveLoopColor) { m_inactiveLoopColor = inactiveLoopColor; }
  71. inline QBrush const & getInactiveLoopBrush() const { return m_inactiveLoopBrush; }
  72. inline void setInactiveLoopBrush(QBrush const & inactiveLoopBrush) { m_inactiveLoopBrush = inactiveLoopBrush; }
  73. inline QColor const & getInactiveLoopInnerColor() const { return m_inactiveLoopInnerColor; }
  74. inline void setInactiveLoopInnerColor(QColor const & inactiveLoopInnerColor) { m_inactiveLoopInnerColor = inactiveLoopInnerColor; }
  75. inline QColor const & getActiveLoopColor() const { return m_activeLoopColor; }
  76. inline void setActiveLoopColor(QColor const & activeLoopColor) { m_activeLoopColor = activeLoopColor; }
  77. inline QBrush const & getActiveLoopBrush() const { return m_activeLoopBrush; }
  78. inline void setActiveLoopBrush(QBrush const & activeLoopBrush) { m_activeLoopBrush = activeLoopBrush; }
  79. inline QColor const & getActiveLoopInnerColor() const { return m_activeLoopInnerColor; }
  80. inline void setActiveLoopInnerColor(QColor const & activeLoopInnerColor) { m_activeLoopInnerColor = activeLoopInnerColor; }
  81. inline int const & getLoopRectangleVerticalPadding() const { return m_loopRectangleVerticalPadding; }
  82. inline void setLoopRectangleVerticalPadding(int const & loopRectangleVerticalPadding) { m_loopRectangleVerticalPadding = loopRectangleVerticalPadding; }
  83. inline Song::PlayPos & pos()
  84. {
  85. return( m_pos );
  86. }
  87. AutoScrollStates autoScroll() const
  88. {
  89. return m_autoScroll;
  90. }
  91. BehaviourAtStopStates behaviourAtStop() const
  92. {
  93. return m_behaviourAtStop;
  94. }
  95. bool loopPointsEnabled() const
  96. {
  97. return m_loopPoints == LoopPointsEnabled;
  98. }
  99. inline const TimePos & loopBegin() const
  100. {
  101. return ( m_loopPos[0] < m_loopPos[1] ) ?
  102. m_loopPos[0] : m_loopPos[1];
  103. }
  104. inline const TimePos & loopEnd() const
  105. {
  106. return ( m_loopPos[0] > m_loopPos[1] ) ?
  107. m_loopPos[0] : m_loopPos[1];
  108. }
  109. inline void savePos( const TimePos & pos )
  110. {
  111. m_savedPos = pos;
  112. }
  113. inline const TimePos & savedPos() const
  114. {
  115. return m_savedPos;
  116. }
  117. inline void setPixelsPerBar( float ppb )
  118. {
  119. m_ppb = ppb;
  120. update();
  121. }
  122. void setXOffset(const int x);
  123. void addToolButtons(QToolBar* _tool_bar );
  124. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  125. void loadSettings( const QDomElement & _this ) override;
  126. inline QString nodeName() const override
  127. {
  128. return "timeline";
  129. }
  130. inline int markerX( const TimePos & _t ) const
  131. {
  132. return m_xOffset + static_cast<int>( ( _t - m_begin ) *
  133. m_ppb / TimePos::ticksPerBar() );
  134. }
  135. signals:
  136. void regionSelectedFromPixels( int, int );
  137. void selectionFinished();
  138. public slots:
  139. void updatePosition( const TimePos & );
  140. void updatePosition()
  141. {
  142. updatePosition( TimePos() );
  143. }
  144. void toggleAutoScroll( int _n );
  145. void toggleLoopPoints( int _n );
  146. void toggleBehaviourAtStop( int _n );
  147. protected:
  148. void paintEvent( QPaintEvent * _pe ) override;
  149. void mousePressEvent( QMouseEvent * _me ) override;
  150. void mouseMoveEvent( QMouseEvent * _me ) override;
  151. void mouseReleaseEvent( QMouseEvent * _me ) override;
  152. private:
  153. static QPixmap * s_posMarkerPixmap;
  154. QColor m_inactiveLoopColor;
  155. QBrush m_inactiveLoopBrush;
  156. QColor m_inactiveLoopInnerColor;
  157. QColor m_activeLoopColor;
  158. QBrush m_activeLoopBrush;
  159. QColor m_activeLoopInnerColor;
  160. int m_loopRectangleVerticalPadding;
  161. QColor m_barLineColor;
  162. QColor m_barNumberColor;
  163. AutoScrollStates m_autoScroll;
  164. LoopPointStates m_loopPoints;
  165. BehaviourAtStopStates m_behaviourAtStop;
  166. bool m_changedPosition;
  167. int m_xOffset;
  168. int m_posMarkerX;
  169. float m_ppb;
  170. Song::PlayPos & m_pos;
  171. const TimePos & m_begin;
  172. const Song::PlayModes m_mode;
  173. TimePos m_loopPos[2];
  174. TimePos m_savedPos;
  175. TextFloat * m_hint;
  176. int m_initalXSelect;
  177. enum actions
  178. {
  179. NoAction,
  180. MovePositionMarker,
  181. MoveLoopBegin,
  182. MoveLoopEnd,
  183. SelectSongClip,
  184. } m_action;
  185. int m_moveXOff;
  186. signals:
  187. void positionChanged( const TimePos & _t );
  188. void loopPointStateLoaded( int _n );
  189. void positionMarkerMoved();
  190. void loadBehaviourAtStop( int _n );
  191. } ;
  192. #endif