TrackContainerView.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. void saveSettings( QDomDocument & _doc, QDomElement & _this ) override;
  44. void loadSettings( const QDomElement & _this ) override;
  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 pixelsPerBar() const
  58. {
  59. return m_ppb;
  60. }
  61. void setPixelsPerBar( int ppb );
  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. QString nodeName() const override
  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. void dropEvent( QDropEvent * _de ) override;
  103. void dragEnterEvent( QDragEnterEvent * _dee ) override;
  104. ///
  105. /// \brief stopRubberBand
  106. /// Removes the rubber band from display when finished with.
  107. void stopRubberBand();
  108. protected:
  109. static const int DEFAULT_PIXELS_PER_BAR = 16;
  110. void resizeEvent( QResizeEvent * ) override;
  111. MidiTime m_currentPosition;
  112. private:
  113. enum Actions
  114. {
  115. AddTrack,
  116. RemoveTrack
  117. } ;
  118. class scrollArea : public QScrollArea
  119. {
  120. public:
  121. scrollArea( TrackContainerView* parent );
  122. virtual ~scrollArea();
  123. protected:
  124. void wheelEvent( QWheelEvent * _we ) override;
  125. private:
  126. TrackContainerView* m_trackContainerView;
  127. } ;
  128. friend class TrackContainerView::scrollArea;
  129. TrackContainer* m_tc;
  130. typedef QList<TrackView *> trackViewList;
  131. trackViewList m_trackViews;
  132. scrollArea * m_scrollArea;
  133. QVBoxLayout * m_scrollLayout;
  134. float m_ppb;
  135. RubberBand * m_rubberBand;
  136. signals:
  137. void positionChanged( const MidiTime & _pos );
  138. } ;
  139. class InstrumentLoaderThread : public QThread
  140. {
  141. Q_OBJECT
  142. public:
  143. InstrumentLoaderThread( QObject *parent = 0, InstrumentTrack *it = 0,
  144. QString name = "" );
  145. void run() override;
  146. private:
  147. InstrumentTrack *m_it;
  148. QString m_name;
  149. QThread *m_containerThread;
  150. };
  151. #endif