1 /** 2 * UGENE - Integrated Bioinformatics Tools. 3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru> 4 * http://ugene.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #ifndef _U2_SCROLL_CONTROLLER_H_ 23 #define _U2_SCROLL_CONTROLLER_H_ 24 25 #include <U2Core/U2Region.h> 26 27 namespace U2 { 28 29 class GScrollBar; 30 class MaEditor; 31 class MaEditorSelection; 32 class MaEditorWgt; 33 34 class U2VIEW_EXPORT ScrollController : public QObject { 35 Q_OBJECT 36 public: 37 enum Direction { 38 None = 0, 39 Up = 1 << 0, 40 Down = 1 << 1, 41 Left = 1 << 2, 42 Right = 1 << 3 43 }; 44 Q_DECLARE_FLAGS(Directions, Direction) 45 46 ScrollController(MaEditor *maEditor, MaEditorWgt *ui); 47 48 void init(GScrollBar *hScrollBar, GScrollBar *vScrollBar); 49 50 QPoint getScreenPosition() const; // in pixels 51 QPoint getGlobalMousePosition(const QPoint &mousePos) const; 52 53 void updateVerticalScrollBar(); 54 55 void scrollToViewRow(int viewRowIndex, int widgetHeight); 56 void scrollToBase(int baseNumber, int widgetWidth); 57 void scrollToPoint(const QPoint &maPoint, const QSize &screenSize); 58 59 void centerBase(int baseNumber, int widgetWidth); 60 void centerViewRow(int viewRowIndex, int widgetHeight); 61 void centerPoint(const QPoint &maPoint, const QSize &widgetSize); 62 63 void setHScrollbarValue(int value); 64 void setVScrollbarValue(int value); 65 66 void setFirstVisibleBase(int firstVisibleBase); 67 void setFirstVisibleViewRow(int viewRowIndex); 68 void setFirstVisibleMaRow(int maRowIndex); 69 70 void scrollSmoothly(const Directions &directions); 71 void stopSmoothScrolling(); 72 73 void scrollStep(Direction direction); 74 void scrollPage(Direction direction); 75 void scrollToEnd(Direction direction); 76 77 void scrollToMovedSelection(int deltaX, int deltaY); 78 void scrollToMovedSelection(Direction direction); 79 80 int getFirstVisibleBase(bool countClipped = false) const; 81 int getLastVisibleBase(int widgetWidth, bool countClipped = false) const; 82 int getFirstVisibleMaRowIndex(bool countClipped = false) const; 83 int getFirstVisibleViewRowIndex(bool countClipped = false) const; 84 int getLastVisibleViewRowIndex(int widgetHeight, bool countClipped = false) const; 85 86 /* 87 * Maps screen coordinates into QPoint(row, column). 88 * Returns QPoint(-1, -1) if geom. position can't be mapped to any base and reportOverflow is false. 89 * If reportOverflow is true and one of the coordinates has overflow, returns rowCount/columnsCount for it. 90 */ 91 QPoint getViewPosByScreenPoint(const QPoint &point, bool reportOverflow = true) const; 92 93 GScrollBar *getHorizontalScrollBar() const; 94 GScrollBar *getVerticalScrollBar() const; 95 96 signals: 97 void si_visibleAreaChanged(); 98 99 public slots: 100 void sl_updateScrollBars(); 101 void sl_zoomScrollBars(); 102 103 private slots: 104 void sl_collapsibleModelIsAboutToBeChanged(); 105 void sl_collapsibleModelChanged(); 106 107 private: 108 int getAdditionalXOffset() const; // in pixels; 109 int getAdditionalYOffset() const; // in pixels; 110 111 U2Region getHorizontalRangeToDrawIn(int widgetWidth) const; // in pixels 112 U2Region getVerticalRangeToDrawIn(int widgetHeight) const; // in pixels 113 114 void zoomHorizontalScrollBarPrivate(); 115 void zoomVerticalScrollBarPrivate(); 116 void updateHorizontalScrollBarPrivate(); 117 void updateVerticalScrollBarPrivate(); 118 119 MaEditor *maEditor; 120 MaEditorWgt *ui; 121 GScrollBar *hScrollBar; 122 GScrollBar *vScrollBar; 123 124 int savedFirstVisibleMaRow; 125 int savedFirstVisibleMaRowOffset; 126 }; 127 128 Q_DECLARE_OPERATORS_FOR_FLAGS(ScrollController::Directions) 129 130 } // namespace U2 131 132 #endif // _U2_SCROLL_CONTROLLER_H_ 133