1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 /* 4 Rosegarden 5 A MIDI and audio sequencer and musical notation editor. 6 Copyright 2000-2021 the Rosegarden development team. 7 8 Other copyrights also apply to some parts of this work. Please 9 see the AUTHORS file and individual file headers for details. 10 11 This program is free software; you can redistribute it and/or 12 modify it under the terms of the GNU General Public License as 13 published by the Free Software Foundation; either version 2 of the 14 License, or (at your option) any later version. See the file 15 COPYING included with this distribution for more information. 16 */ 17 18 #ifndef RG_ROSEGARDENSCROLLVIEW_H 19 #define RG_ROSEGARDENSCROLLVIEW_H 20 21 #include "gui/general/AutoScroller.h" 22 23 #include <QAbstractScrollArea> 24 #include <QDateTime> 25 #include <QPoint> 26 #include <QTimer> 27 28 29 class QMouseEvent; 30 class QPaintEvent; 31 class QRect; 32 class QResizeEvent; 33 class QScrollBar; 34 class QWheelEvent; 35 class QWidget; 36 37 38 namespace Rosegarden 39 { 40 41 42 class StandardRuler; 43 44 /// QAbstractScrollArea with auto-scroll and bottom ruler. 45 /** 46 * A QAbstractScrollArea with more elaborate auto-scrolling capabilities 47 * and the ability to have a vertically "fixed" StandardRuler at its 48 * bottom, just above the horizontal scrollbar. 49 * 50 * Some Q3ScrollView compatibility is provided to ease the transition 51 * from Q3ScrollView to QAbstractScrollArea. 52 * 53 * CompositionView derives from this class. 54 */ 55 class RosegardenScrollView : public QAbstractScrollArea 56 { 57 Q_OBJECT 58 59 public: 60 61 RosegardenScrollView(QWidget *parent); 62 63 /// Connect the bottom StandardRuler. 64 /** 65 * Sets the ruler widget which will be between the scrollable part of 66 * the view and the horizontal scrollbar. 67 * 68 * This is called by TrackEditor::init() to connect a StandardRuler 69 * instance. 70 */ 71 void setBottomRuler(StandardRuler *); 72 73 /// X coordinate of the contents that are at the left edge of the viewport. 74 int contentsX(); 75 /// Y coordinate of the contents that are at the top edge of the viewport. 76 int contentsY(); 77 78 QPoint viewportToContents(const QPoint &); 79 80 void updateContents(); 81 82 void startAutoScroll(); setFollowMode(FollowMode followMode)83 void setFollowMode(FollowMode followMode) 84 { m_autoScroller.setFollowMode(followMode); } 85 void stopAutoScroll(); 86 isAutoScrolling()87 bool isAutoScrolling() const { return m_autoScroller.isRunning(); } 88 89 /// Playback scrolling. 90 /** 91 * Scroll horizontally to make the given contents position visible, 92 * paging so as to get some visibility of the next screenful 93 * (for playback etc) 94 */ 95 void scrollHoriz(int x); 96 97 /// Track select scrolling. 98 /** 99 * Scroll vertically to make the given contents position visible. 100 * 101 * The main test case for this is selecting tracks with the 102 * arrow keys and making sure the view scrolls to show the 103 * selected track. 104 */ 105 void scrollVert(int y); 106 107 signals: 108 /// Used by TrackEditor to keep TrackButtons the right size. 109 void viewportResize(); 110 111 /// Emitted on Ctrl-Scroll Wheel Up. 112 /** 113 * TrackEditor connects this to RosegardenMainWindow::slotZoomIn(). 114 */ 115 void zoomIn(); 116 /// Emitted on Ctrl-Scroll Wheel Down. 117 /** 118 * TrackEditor connects this to RosegardenMainWindow::slotZoomOut(). 119 */ 120 void zoomOut(); 121 122 protected: 123 124 /// Sets the size of the contents area and updates the viewport accordingly. 125 /** 126 * Q3ScrollView compatible function. 127 */ 128 void resizeContents(int width, int height); 129 /// Width of the contents area. contentsWidth()130 int contentsWidth() { return m_contentsWidth; } 131 /// Height of the contents area. contentsHeight()132 int contentsHeight() { return m_contentsHeight; } 133 134 void updateContents(const QRect &); 135 136 /// Viewport resize. 137 void resizeEvent(QResizeEvent *) override; 138 139 void wheelEvent(QWheelEvent *) override; 140 141 private: 142 143 StandardRuler *m_bottomRuler; 144 /// Make sure the bottom ruler stays in the proper place. 145 void updateBottomRulerGeometry(); 146 147 int m_contentsWidth; 148 int m_contentsHeight; 149 150 /// Calls update() on a rectangle defined by x, y, w, h, translated appropriately. 151 /** 152 * Q3ScrollView compatible function. 153 */ 154 void updateContents(int x, int y, int width, int height); 155 156 /// Adjust the scrollbars' max and page step. 157 void updateScrollBars(); 158 159 // *** Auto Scrolling 160 161 AutoScroller m_autoScroller; 162 163 }; 164 165 166 } 167 168 #endif 169