TimeLineWidget.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 MidiTime & 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 MidiTime & loopBegin() const
  100. {
  101. return ( m_loopPos[0] < m_loopPos[1] ) ?
  102. m_loopPos[0] : m_loopPos[1];
  103. }
  104. inline const MidiTime & loopEnd() const
  105. {
  106. return ( m_loopPos[0] > m_loopPos[1] ) ?
  107. m_loopPos[0] : m_loopPos[1];
  108. }
  109. inline void savePos( const MidiTime & pos )
  110. {
  111. m_savedPos = pos;
  112. }
  113. inline const MidiTime & savedPos() const
  114. {
  115. return m_savedPos;
  116. }
  117. inline void setPixelsPerBar( float ppb )
  118. {
  119. m_ppb = ppb;
  120. update();
  121. }
  122. void addToolButtons(QToolBar* _tool_bar );
  123. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  124. void loadSettings( const QDomElement & _this ) override;
  125. inline QString nodeName() const override
  126. {
  127. return "timeline";
  128. }
  129. inline int markerX( const MidiTime & _t ) const
  130. {
  131. return m_xOffset + static_cast<int>( ( _t - m_begin ) *
  132. m_ppb / MidiTime::ticksPerBar() );
  133. }
  134. signals:
  135. void regionSelectedFromPixels( int, int );
  136. void selectionFinished();
  137. public slots:
  138. void updatePosition( const MidiTime & );
  139. void updatePosition()
  140. {
  141. updatePosition( MidiTime() );
  142. }
  143. void toggleAutoScroll( int _n );
  144. void toggleLoopPoints( int _n );
  145. void toggleBehaviourAtStop( int _n );
  146. protected:
  147. void paintEvent( QPaintEvent * _pe ) override;
  148. void mousePressEvent( QMouseEvent * _me ) override;
  149. void mouseMoveEvent( QMouseEvent * _me ) override;
  150. void mouseReleaseEvent( QMouseEvent * _me ) override;
  151. private:
  152. static QPixmap * s_posMarkerPixmap;
  153. QColor m_inactiveLoopColor;
  154. QBrush m_inactiveLoopBrush;
  155. QColor m_inactiveLoopInnerColor;
  156. QColor m_activeLoopColor;
  157. QBrush m_activeLoopBrush;
  158. QColor m_activeLoopInnerColor;
  159. int m_loopRectangleVerticalPadding;
  160. QColor m_barLineColor;
  161. QColor m_barNumberColor;
  162. AutoScrollStates m_autoScroll;
  163. LoopPointStates m_loopPoints;
  164. BehaviourAtStopStates m_behaviourAtStop;
  165. bool m_changedPosition;
  166. int m_xOffset;
  167. int m_posMarkerX;
  168. float m_ppb;
  169. Song::PlayPos & m_pos;
  170. const MidiTime & m_begin;
  171. const Song::PlayModes m_mode;
  172. MidiTime m_loopPos[2];
  173. MidiTime m_savedPos;
  174. TextFloat * m_hint;
  175. int m_initalXSelect;
  176. enum actions
  177. {
  178. NoAction,
  179. MovePositionMarker,
  180. MoveLoopBegin,
  181. MoveLoopEnd,
  182. SelectSongTCO,
  183. } m_action;
  184. int m_moveXOff;
  185. signals:
  186. void positionChanged( const MidiTime & _t );
  187. void loopPointStateLoaded( int _n );
  188. void positionMarkerMoved();
  189. } ;
  190. #endif