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 #include "DrawHelper.h"
23
24 #include "U2Core/U2SafePoints.h"
25
26 #include "BaseWidthController.h"
27 #include "RowHeightController.h"
28 #include "ScrollController.h"
29 #include "ov_msa/MaCollapseModel.h"
30 #include "ov_msa/MaEditor.h"
31 #include "ov_msa/view_rendering/MaEditorSelection.h"
32 #include "ov_msa/view_rendering/MaEditorWgt.h"
33
34 namespace U2 {
35
DrawHelper(MaEditor * _editor)36 DrawHelper::DrawHelper(MaEditor *_editor)
37 : editor(_editor) {
38 }
39
getVisibleBases(int widgetWidth,bool countFirstClippedBase,bool countLastClippedBase) const40 U2Region DrawHelper::getVisibleBases(int widgetWidth, bool countFirstClippedBase, bool countLastClippedBase) const {
41 auto scrollController = editor->getUI()->getScrollController();
42 const int firstVisibleBase = scrollController->getFirstVisibleBase(countFirstClippedBase);
43 const int lastVisibleBase = scrollController->getLastVisibleBase(widgetWidth, countLastClippedBase);
44 return U2Region(firstVisibleBase, lastVisibleBase - firstVisibleBase + 1);
45 }
46
getVisibleViewRowsRegion(int widgetHeight,bool countFirstClippedRow,bool countLastClippedRow) const47 U2Region DrawHelper::getVisibleViewRowsRegion(int widgetHeight, bool countFirstClippedRow, bool countLastClippedRow) const {
48 auto scrollController = editor->getUI()->getScrollController();
49 const int firstVisibleRowNumber = scrollController->getFirstVisibleViewRowIndex(countFirstClippedRow);
50 const int lastVisibleRowNumber = scrollController->getLastVisibleViewRowIndex(widgetHeight, countLastClippedRow);
51 return U2Region(firstVisibleRowNumber, lastVisibleRowNumber - firstVisibleRowNumber + 1);
52 }
53
getVisibleMaRowIndexes(int widgetHeight,bool countFirstClippedRow,bool countLastClippedRow) const54 QList<int> DrawHelper::getVisibleMaRowIndexes(int widgetHeight, bool countFirstClippedRow, bool countLastClippedRow) const {
55 auto scrollController = editor->getUI()->getScrollController();
56 int firstVisibleViewRow = scrollController->getFirstVisibleViewRowIndex(countFirstClippedRow);
57 int lastVisibleViewRow = scrollController->getLastVisibleViewRowIndex(widgetHeight, countLastClippedRow);
58 U2Region viewRowsRegion(firstVisibleViewRow, lastVisibleViewRow - firstVisibleViewRow + 1);
59 return editor->getCollapseModel()->getMaRowIndexesByViewRowIndexes(viewRowsRegion);
60 }
61
getVisibleBasesCount(int widgetWidth,bool countFirstClippedBase,bool countLastClippedBase) const62 int DrawHelper::getVisibleBasesCount(int widgetWidth, bool countFirstClippedBase, bool countLastClippedBase) const {
63 return getVisibleBases(widgetWidth, countFirstClippedBase, countLastClippedBase).length;
64 }
65
getScreenRect(const QRect & columnsAndRowsRect) const66 QRect DrawHelper::getScreenRect(const QRect &columnsAndRowsRect) const {
67 CHECK(!columnsAndRowsRect.isEmpty(), QRect());
68
69 U2Region xRange = editor->getUI()->getBaseWidthController()->getBasesScreenRange(U2Region::fromXRange(columnsAndRowsRect));
70 U2Region yRange = editor->getUI()->getRowHeightController()->getScreenYRegionByViewRowsRegion(U2Region::fromYRange(columnsAndRowsRect));
71 return QRect(xRange.startPos, yRange.startPos, xRange.length, yRange.length);
72 }
73
74 } // namespace U2
75