TrackContainerView.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * TrackContainerView.h - view-component for TrackContainer
  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_CONTAINER_VIEW_H
  25. #define TRACK_CONTAINER_VIEW_H
  26. #include <QtCore/QVector>
  27. #include <QScrollArea>
  28. #include <QWidget>
  29. #include <QThread>
  30. #include "Track.h"
  31. #include "JournallingObject.h"
  32. #include "InstrumentTrack.h"
  33. class QVBoxLayout;
  34. class TrackContainer;
  35. class TrackContainerView : public QWidget, public ModelView,
  36. public JournallingObject,
  37. public SerializingObjectHook
  38. {
  39. Q_OBJECT
  40. public:
  41. TrackContainerView( TrackContainer* tc );
  42. virtual ~TrackContainerView();
  43. virtual void saveSettings( QDomDocument & _doc, QDomElement & _this );
  44. virtual void loadSettings( const QDomElement & _this );
  45. QScrollArea * contentWidget()
  46. {
  47. return( m_scrollArea );
  48. }
  49. inline const MidiTime & currentPosition() const
  50. {
  51. return( m_currentPosition );
  52. }
  53. virtual bool fixedTCOs() const
  54. {
  55. return( false );
  56. }
  57. inline float pixelsPerTact() const
  58. {
  59. return( m_ppt );
  60. }
  61. void setPixelsPerTact( int _ppt );
  62. const TrackView * trackViewAt( const int _y ) const;
  63. virtual bool allowRubberband() const;
  64. inline bool rubberBandActive() const
  65. {
  66. return( m_rubberBand->isEnabled() && m_rubberBand->isVisible() );
  67. }
  68. inline QVector<selectableObject *> selectedObjects()
  69. {
  70. return( m_rubberBand->selectedObjects() );
  71. }
  72. TrackContainer* model()
  73. {
  74. return m_tc;
  75. }
  76. const TrackContainer* model() const
  77. {
  78. return m_tc;
  79. }
  80. const QList<TrackView *> & trackViews() const
  81. {
  82. return( m_trackViews );
  83. }
  84. void moveTrackView( TrackView * trackView, int indexTo );
  85. void moveTrackViewUp( TrackView * trackView );
  86. void moveTrackViewDown( TrackView * trackView );
  87. void scrollToTrackView( TrackView * _tv );
  88. // -- for usage by trackView only ---------------
  89. TrackView * addTrackView( TrackView * _tv );
  90. void removeTrackView( TrackView * _tv );
  91. // -------------------------------------------------------
  92. void clearAllTracks();
  93. virtual QString nodeName() const
  94. {
  95. return( "trackcontainerview" );
  96. }
  97. RubberBand *rubberBand() const;
  98. public slots:
  99. void realignTracks();
  100. TrackView * createTrackView( Track * _t );
  101. void deleteTrackView( TrackView * _tv );
  102. virtual void dropEvent( QDropEvent * _de );
  103. virtual void dragEnterEvent( QDragEnterEvent * _dee );
  104. ///
  105. /// \brief selectRegionFromPixels
  106. /// \param x
  107. /// \param y
  108. /// Use the rubber band to select TCO from all tracks using x, y pixels
  109. void selectRegionFromPixels(int xStart, int xEnd);
  110. ///
  111. /// \brief stopRubberBand
  112. /// Removes the rubber band from display when finished with.
  113. void stopRubberBand();
  114. protected:
  115. static const int DEFAULT_PIXELS_PER_TACT = 16;
  116. virtual void mousePressEvent( QMouseEvent * _me );
  117. virtual void mouseMoveEvent( QMouseEvent * _me );
  118. virtual void mouseReleaseEvent( QMouseEvent * _me );
  119. virtual void resizeEvent( QResizeEvent * );
  120. MidiTime m_currentPosition;
  121. private:
  122. enum Actions
  123. {
  124. AddTrack,
  125. RemoveTrack
  126. } ;
  127. class scrollArea : public QScrollArea
  128. {
  129. public:
  130. scrollArea( TrackContainerView* parent );
  131. virtual ~scrollArea();
  132. protected:
  133. virtual void wheelEvent( QWheelEvent * _we );
  134. private:
  135. TrackContainerView* m_trackContainerView;
  136. } ;
  137. friend class TrackContainerView::scrollArea;
  138. TrackContainer* m_tc;
  139. typedef QList<TrackView *> trackViewList;
  140. trackViewList m_trackViews;
  141. scrollArea * m_scrollArea;
  142. QVBoxLayout * m_scrollLayout;
  143. float m_ppt;
  144. RubberBand * m_rubberBand;
  145. QPoint m_origin;
  146. signals:
  147. void positionChanged( const MidiTime & _pos );
  148. } ;
  149. class InstrumentLoaderThread : public QThread
  150. {
  151. Q_OBJECT
  152. public:
  153. InstrumentLoaderThread( QObject *parent = 0, InstrumentTrack *it = 0,
  154. QString name = "" );
  155. void run();
  156. private:
  157. InstrumentTrack *m_it;
  158. QString m_name;
  159. QThread *m_containerThread;
  160. };
  161. #endif