ClipView.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * ClipView.h - declaration of ClipView class
  3. *
  4. * Copyright (c) 2004-2014 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 TRACK_CONTENT_OBJECT_VIEW_H
  25. #define TRACK_CONTENT_OBJECT_VIEW_H
  26. #include <QtCore/QVector>
  27. #include "ModelView.h"
  28. #include "Rubberband.h"
  29. #include "Clip.h"
  30. class QMenu;
  31. class QContextMenuEvent;
  32. class DataFile;
  33. class TextFloat;
  34. class Clip;
  35. class TrackView;
  36. class ClipView : public selectableObject, public ModelView
  37. {
  38. Q_OBJECT
  39. // theming qproperties
  40. Q_PROPERTY( QColor mutedColor READ mutedColor WRITE setMutedColor )
  41. Q_PROPERTY( QColor mutedBackgroundColor READ mutedBackgroundColor WRITE setMutedBackgroundColor )
  42. Q_PROPERTY( QColor selectedColor READ selectedColor WRITE setSelectedColor )
  43. Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor )
  44. Q_PROPERTY( QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor )
  45. Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
  46. Q_PROPERTY( QColor patternClipBackground READ patternClipBackground WRITE setPatternClipBackground )
  47. Q_PROPERTY( bool gradient READ gradient WRITE setGradient )
  48. // We have to use a QSize here because using QPoint isn't supported.
  49. // width -> x, height -> y
  50. Q_PROPERTY( QSize mouseHotspotHand MEMBER m_mouseHotspotHand )
  51. Q_PROPERTY( QSize mouseHotspotKnife MEMBER m_mouseHotspotKnife )
  52. public:
  53. ClipView( Clip * clip, TrackView * tv );
  54. virtual ~ClipView();
  55. bool fixedClips();
  56. inline Clip * getClip()
  57. {
  58. return m_clip;
  59. }
  60. inline TrackView * getTrackView()
  61. {
  62. return m_trackView;
  63. }
  64. // qproperty access func
  65. QColor mutedColor() const;
  66. QColor mutedBackgroundColor() const;
  67. QColor selectedColor() const;
  68. QColor textColor() const;
  69. QColor textBackgroundColor() const;
  70. QColor textShadowColor() const;
  71. QColor patternClipBackground() const;
  72. bool gradient() const;
  73. void setMutedColor( const QColor & c );
  74. void setMutedBackgroundColor( const QColor & c );
  75. void setSelectedColor( const QColor & c );
  76. void setTextColor( const QColor & c );
  77. void setTextBackgroundColor( const QColor & c );
  78. void setTextShadowColor( const QColor & c );
  79. void setPatternClipBackground(const QColor& c);
  80. void setGradient( const bool & b );
  81. // access needsUpdate member variable
  82. bool needsUpdate();
  83. void setNeedsUpdate( bool b );
  84. // Method to get a QVector of Clips to be affected by a context menu action
  85. QVector<ClipView *> getClickedClips();
  86. // Methods to remove, copy, cut, paste and mute a QVector of Clip views
  87. void copy( QVector<ClipView *> clipvs );
  88. void cut( QVector<ClipView *> clipvs );
  89. void paste();
  90. // remove and toggleMute are static because they don't depend
  91. // being called from a particular Clip view, but can be called anywhere as long
  92. // as a valid Clip view list is given, while copy/cut require an instance for
  93. // some metadata to be written to the clipboard.
  94. static void remove( QVector<ClipView *> clipvs );
  95. static void toggleMute( QVector<ClipView *> clipvs );
  96. static void mergeClips(QVector<ClipView*> clipvs);
  97. // Returns true if selection can be merged and false if not
  98. static bool canMergeSelection(QVector<ClipView*> clipvs);
  99. QColor getColorForDisplay( QColor );
  100. void inline setMarkerPos(int x) { m_markerPos = x; }
  101. void inline setMarkerEnabled(bool e) { m_marker = e; }
  102. public slots:
  103. virtual bool close();
  104. void remove();
  105. void update() override;
  106. void selectColor();
  107. void randomizeColor();
  108. void resetColor();
  109. protected:
  110. enum ContextMenuAction
  111. {
  112. Remove,
  113. Cut,
  114. Copy,
  115. Paste,
  116. Mute,
  117. Merge
  118. };
  119. TrackView * m_trackView;
  120. TimePos m_initialClipPos;
  121. TimePos m_initialClipEnd;
  122. bool m_marker = false;
  123. int m_markerPos = 0;
  124. virtual void constructContextMenu( QMenu * )
  125. {
  126. }
  127. void contextMenuEvent( QContextMenuEvent * cme ) override;
  128. void contextMenuAction( ContextMenuAction action );
  129. void dragEnterEvent( QDragEnterEvent * dee ) override;
  130. void dropEvent( QDropEvent * de ) override;
  131. void mousePressEvent( QMouseEvent * me ) override;
  132. void mouseMoveEvent( QMouseEvent * me ) override;
  133. void mouseReleaseEvent( QMouseEvent * me ) override;
  134. void resizeEvent( QResizeEvent * re ) override
  135. {
  136. m_needsUpdate = true;
  137. selectableObject::resizeEvent( re );
  138. }
  139. bool unquantizedModHeld( QMouseEvent * me );
  140. TimePos quantizeSplitPos( TimePos, bool shiftMode );
  141. float pixelsPerBar();
  142. DataFile createClipDataFiles(const QVector<ClipView *> & clips) const;
  143. virtual void paintTextLabel(QString const & text, QPainter & painter);
  144. protected slots:
  145. void updateLength();
  146. void updatePosition();
  147. private:
  148. enum Actions
  149. {
  150. NoAction,
  151. Move,
  152. MoveSelection,
  153. Resize,
  154. ResizeLeft,
  155. Split,
  156. CopySelection,
  157. ToggleSelected
  158. } ;
  159. static TextFloat * s_textFloat;
  160. Clip * m_clip;
  161. Actions m_action;
  162. QPoint m_initialMousePos;
  163. QPoint m_initialMouseGlobalPos;
  164. QVector<TimePos> m_initialOffsets;
  165. TextFloat * m_hint;
  166. // qproperty fields
  167. QColor m_mutedColor;
  168. QColor m_mutedBackgroundColor;
  169. QColor m_selectedColor;
  170. QColor m_textColor;
  171. QColor m_textBackgroundColor;
  172. QColor m_textShadowColor;
  173. QColor m_patternClipBackground;
  174. bool m_gradient;
  175. QSize m_mouseHotspotHand; // QSize must be used because QPoint
  176. QSize m_mouseHotspotKnife; // isn't supported by property system
  177. QCursor m_cursorHand;
  178. QCursor m_cursorKnife;
  179. bool m_cursorSetYet;
  180. bool m_needsUpdate;
  181. inline void setInitialPos( QPoint pos )
  182. {
  183. m_initialMousePos = pos;
  184. m_initialMouseGlobalPos = mapToGlobal( pos );
  185. m_initialClipPos = m_clip->startPosition();
  186. m_initialClipEnd = m_initialClipPos + m_clip->length();
  187. }
  188. void setInitialOffsets();
  189. bool mouseMovedDistance( QMouseEvent * me, int distance );
  190. TimePos draggedClipPos( QMouseEvent * me );
  191. int knifeMarkerPos( QMouseEvent * me );
  192. void setColor(const QColor* color);
  193. //! Return true iff the clip could be split. Currently only implemented for samples
  194. virtual bool splitClip( const TimePos pos ){ return false; };
  195. void updateCursor(QMouseEvent * me);
  196. } ;
  197. #endif