TrackContainerView.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 "JournallingObject.h"
  31. #include "ModelView.h"
  32. #include "Rubberband.h"
  33. #include "TrackView.h"
  34. class QVBoxLayout;
  35. class InstrumentTrack;
  36. class TrackContainer;
  37. class TrackContainerView : public QWidget, public ModelView,
  38. public JournallingObject,
  39. public SerializingObjectHook
  40. {
  41. Q_OBJECT
  42. public:
  43. TrackContainerView( TrackContainer* tc );
  44. virtual ~TrackContainerView();
  45. void saveSettings( QDomDocument & _doc, QDomElement & _this ) override;
  46. void loadSettings( const QDomElement & _this ) override;
  47. QScrollArea * contentWidget()
  48. {
  49. return m_scrollArea;
  50. }
  51. inline const TimePos & currentPosition() const
  52. {
  53. return m_currentPosition;
  54. }
  55. virtual bool fixedClips() const
  56. {
  57. return false;
  58. }
  59. inline float pixelsPerBar() const
  60. {
  61. return m_ppb;
  62. }
  63. void setPixelsPerBar( int ppb );
  64. const TrackView * trackViewAt( const int _y ) const;
  65. virtual bool allowRubberband() const;
  66. virtual bool knifeMode() const;
  67. inline bool rubberBandActive() const
  68. {
  69. return m_rubberBand->isEnabled() && m_rubberBand->isVisible();
  70. }
  71. inline QVector<selectableObject *> selectedObjects()
  72. {
  73. return m_rubberBand->selectedObjects();
  74. }
  75. TrackContainer* model()
  76. {
  77. return m_tc;
  78. }
  79. const TrackContainer* model() const
  80. {
  81. return m_tc;
  82. }
  83. const QList<TrackView *> & trackViews() const
  84. {
  85. return( m_trackViews );
  86. }
  87. void moveTrackView( TrackView * trackView, int indexTo );
  88. void moveTrackViewUp( TrackView * trackView );
  89. void moveTrackViewDown( TrackView * trackView );
  90. void scrollToTrackView( TrackView * _tv );
  91. // -- for usage by trackView only ---------------
  92. TrackView * addTrackView( TrackView * _tv );
  93. void removeTrackView( TrackView * _tv );
  94. // -------------------------------------------------------
  95. void clearAllTracks();
  96. QString nodeName() const override
  97. {
  98. return "trackcontainerview";
  99. }
  100. RubberBand *rubberBand() const;
  101. public slots:
  102. void realignTracks();
  103. TrackView * createTrackView( Track * _t );
  104. void deleteTrackView( TrackView * _tv );
  105. void dropEvent( QDropEvent * _de ) override;
  106. void dragEnterEvent( QDragEnterEvent * _dee ) override;
  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_BAR = 16;
  113. void resizeEvent( QResizeEvent * ) override;
  114. TimePos m_currentPosition;
  115. private:
  116. enum Actions
  117. {
  118. AddTrack,
  119. RemoveTrack
  120. } ;
  121. class scrollArea : public QScrollArea
  122. {
  123. public:
  124. scrollArea( TrackContainerView* parent );
  125. virtual ~scrollArea();
  126. protected:
  127. void wheelEvent( QWheelEvent * _we ) override;
  128. private:
  129. TrackContainerView* m_trackContainerView;
  130. } ;
  131. friend class TrackContainerView::scrollArea;
  132. TrackContainer* m_tc;
  133. typedef QList<TrackView *> trackViewList;
  134. trackViewList m_trackViews;
  135. scrollArea * m_scrollArea;
  136. QVBoxLayout * m_scrollLayout;
  137. float m_ppb;
  138. RubberBand * m_rubberBand;
  139. signals:
  140. void positionChanged( const TimePos & _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() override;
  149. private:
  150. InstrumentTrack *m_it;
  151. QString m_name;
  152. QThread *m_containerThread;
  153. };
  154. #endif