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 <GTGlobals.h>
23 #include <drivers/GTMouseDriver.h>
24 #include <primitives/GTScrollBar.h>
25 
26 #include <U2Core/U2SafePoints.h>
27 
28 #include <U2View/BaseWidthController.h>
29 #include <U2View/McaEditorReferenceArea.h>
30 #include <U2View/McaEditorSequenceArea.h>
31 #include <U2View/McaEditorWgt.h>
32 #include <U2View/ScrollController.h>
33 
34 #include "GTUtilsMcaEditor.h"
35 #include "GTUtilsMcaEditorReference.h"
36 #include "GTUtilsMcaEditorSequenceArea.h"
37 
38 using namespace HI;
39 namespace U2 {
40 
41 #define GT_CLASS_NAME "GTUtilsMcaEditorReference"
42 
43 #define GT_METHOD_NAME "clickToPosition"
clickToPosition(HI::GUITestOpStatus & os,int position)44 void GTUtilsMcaEditorReference::clickToPosition(HI::GUITestOpStatus &os, int position) {
45     McaEditorReferenceArea *referenceArea = GTUtilsMcaEditor::getReferenceArea(os);
46     McaEditorWgt *mcaEditorWgt = GTUtilsMcaEditor::getEditorUi(os);
47     GT_CHECK(mcaEditorWgt->getSequenceArea()->isInRange(QPoint(position, 0)), QString("Position %1 is out of range").arg(position));
48 
49     scrollToPosition(os, position);
50 
51     const QPoint positionCenter(mcaEditorWgt->getBaseWidthController()->getBaseScreenCenter(position),
52                                 referenceArea->height() / 2);
53     GT_CHECK(referenceArea->rect().contains(positionCenter, false), QString("Position %1 is not visible").arg(position));
54 
55     GTMouseDriver::moveTo(referenceArea->mapToGlobal(positionCenter));
56     GTMouseDriver::click();
57 }
58 #undef GT_METHOD_NAME
59 
60 #define GT_METHOD_NAME "scrollToPosition"
scrollToPosition(HI::GUITestOpStatus & os,int position)61 void GTUtilsMcaEditorReference::scrollToPosition(HI::GUITestOpStatus &os, int position) {
62     const int scrollBarValue = GTUtilsMcaEditor::getEditorUi(os)->getBaseWidthController()->getBaseGlobalRange(position).center() -
63                                GTUtilsMcaEditor::getEditorUi(os)->getSequenceArea()->width() / 2;
64     CHECK(!GTUtilsMcaEditor::getReferenceArea(os)->getVisibleRange().contains(position), );
65     GTScrollBar::moveSliderWithMouseToValue(os,
66                                             GTUtilsMcaEditor::getHorizontalScrollBar(os),
67                                             scrollBarValue);
68 }
69 #undef GT_METHOD_NAME
70 
71 #undef GT_CLASS_NAME
72 
73 }  // namespace U2
74