TrackContainerView.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. if( allowRubberband() == true )
  71. {
  72. return( m_rubberBand->selectedObjects() );
  73. }
  74. return( QVector<selectableObject *>() );
  75. }
  76. TrackContainer* model()
  77. {
  78. return m_tc;
  79. }
  80. const TrackContainer* model() const
  81. {
  82. return m_tc;
  83. }
  84. const QList<TrackView *> & trackViews() const
  85. {
  86. return( m_trackViews );
  87. }
  88. void moveTrackView( TrackView * trackView, int indexTo );
  89. void moveTrackViewUp( TrackView * trackView );
  90. void moveTrackViewDown( TrackView * trackView );
  91. void scrollToTrackView( TrackView * _tv );
  92. // -- for usage by trackView only ---------------
  93. TrackView * addTrackView( TrackView * _tv );
  94. void removeTrackView( TrackView * _tv );
  95. // -------------------------------------------------------
  96. void clearAllTracks();
  97. virtual QString nodeName() const
  98. {
  99. return( "trackcontainerview" );
  100. }
  101. public slots:
  102. void realignTracks();
  103. TrackView * createTrackView( Track * _t );
  104. void deleteTrackView( TrackView * _tv );
  105. virtual void dropEvent( QDropEvent * _de );
  106. virtual void dragEnterEvent( QDragEnterEvent * _dee );
  107. ///
  108. /// \brief stopRubberBand
  109. /// Removes the rubber band from display when finished with.
  110. void stopRubberBand();
  111. protected:
  112. static const int DEFAULT_PIXELS_PER_TACT = 16;
  113. virtual void resizeEvent( QResizeEvent * );
  114. MidiTime m_currentPosition;
  115. RubberBand *rubberBand() const;
  116. private:
  117. enum Actions
  118. {
  119. AddTrack,
  120. RemoveTrack
  121. } ;
  122. class scrollArea : public QScrollArea
  123. {
  124. public:
  125. scrollArea( TrackContainerView* parent );
  126. virtual ~scrollArea();
  127. protected:
  128. virtual void wheelEvent( QWheelEvent * _we );
  129. private:
  130. TrackContainerView* m_trackContainerView;
  131. } ;
  132. TrackContainer* m_tc;
  133. typedef QList<TrackView *> trackViewList;
  134. trackViewList m_trackViews;
  135. scrollArea * m_scrollArea;
  136. QVBoxLayout * m_scrollLayout;
  137. float m_ppt;
  138. RubberBand * m_rubberBand;
  139. signals:
  140. void positionChanged( const MidiTime & _pos );
  141. } ;
  142. class InstrumentLoaderThread : public QThread
  143. {
  144. Q_OBJECT
  145. public:
  146. InstrumentLoaderThread( QObject *parent = 0, InstrumentTrack *it = 0,
  147. QString name = "" );
  148. void run();
  149. private:
  150. InstrumentTrack *m_it;
  151. QString m_name;
  152. QThread *m_containerThread;
  153. };
  154. #endif