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 "MsaEditorWgt.h"
23 
24 #include <U2Algorithm/MSADistanceAlgorithmRegistry.h>
25 
26 #include "MSAEditor.h"
27 #include "MSAEditorConsensusArea.h"
28 #include "MSAEditorOverviewArea.h"
29 #include "MSAEditorSequenceArea.h"
30 #include "MsaEditorNameList.h"
31 #include "MsaEditorSimilarityColumn.h"
32 #include "MsaEditorStatusBar.h"
33 #include "helpers/MsaRowHeightController.h"
34 #include "phy_tree/MSAEditorMultiTreeViewer.h"
35 
36 namespace U2 {
37 
MsaEditorWgt(MSAEditor * editor)38 MsaEditorWgt::MsaEditorWgt(MSAEditor *editor)
39     : MaEditorWgt(editor),
40       multiTreeViewer(nullptr),
41       similarityStatistics(nullptr) {
42     rowHeightController = new MsaRowHeightController(this);
43     initActions();
44     initWidgets();
45 }
46 
getEditor() const47 MSAEditor *MsaEditorWgt::getEditor() const {
48     return qobject_cast<MSAEditor *>(editor);
49 }
50 
getSequenceArea() const51 MSAEditorSequenceArea *MsaEditorWgt::getSequenceArea() const {
52     return qobject_cast<MSAEditorSequenceArea *>(sequenceArea);
53 }
54 
sl_onTabsCountChanged(int curTabsNumber)55 void MsaEditorWgt::sl_onTabsCountChanged(int curTabsNumber) {
56     if (curTabsNumber < 1) {
57         maSplitter.removeWidget(multiTreeViewer);
58         delete multiTreeViewer;
59         multiTreeViewer = nullptr;
60         emit si_hideTreeOP();
61     }
62 }
63 
createDistanceColumn(MSADistanceMatrix * matrix)64 void MsaEditorWgt::createDistanceColumn(MSADistanceMatrix *matrix) {
65     dataList->setMatrix(matrix);
66     dataList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
67     MsaEditorAlignmentDependentWidget *statisticsWidget = new MsaEditorAlignmentDependentWidget(dataList);
68 
69     maSplitter.addWidget(nameAreaContainer, statisticsWidget, 0.04, 1);
70 }
71 
addTreeView(GObjectViewWindow * treeView)72 void MsaEditorWgt::addTreeView(GObjectViewWindow *treeView) {
73     if (nullptr == multiTreeViewer) {
74         multiTreeViewer = new MSAEditorMultiTreeViewer(tr("Tree view"), getEditor());
75         maSplitter.addWidget(nameAreaContainer, multiTreeViewer, 0.35);
76         multiTreeViewer->addTreeView(treeView);
77         emit si_showTreeOP();
78         connect(multiTreeViewer, SIGNAL(si_tabsCountChanged(int)), SLOT(sl_onTabsCountChanged(int)));
79     } else {
80         multiTreeViewer->addTreeView(treeView);
81     }
82 }
83 
setSimilaritySettings(const SimilarityStatisticsSettings * settings)84 void MsaEditorWgt::setSimilaritySettings(const SimilarityStatisticsSettings *settings) {
85     similarityStatistics->setSettings(settings);
86 }
87 
refreshSimilarityColumn()88 void MsaEditorWgt::refreshSimilarityColumn() {
89     dataList->updateWidget();
90 }
91 
showSimilarity()92 void MsaEditorWgt::showSimilarity() {
93     if (nullptr == similarityStatistics) {
94         SimilarityStatisticsSettings settings;
95         settings.ma = getEditor()->getMaObject();
96         settings.algoId = AppContext::getMSADistanceAlgorithmRegistry()->getAlgorithmIds().at(0);
97         settings.ui = this;
98 
99         dataList = new MsaEditorSimilarityColumn(this, new QScrollBar(Qt::Horizontal), &settings);
100         dataList->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
101         similarityStatistics = new MsaEditorAlignmentDependentWidget(dataList);
102 
103         maSplitter.addWidget(nameAreaContainer, similarityStatistics, 0.04, 1);
104     } else {
105         similarityStatistics->show();
106     }
107 }
108 
hideSimilarity()109 void MsaEditorWgt::hideSimilarity() {
110     if (nullptr != similarityStatistics) {
111         similarityStatistics->hide();
112         similarityStatistics->cancelPendingTasks();
113     }
114 }
115 
getSimilarityWidget()116 const MsaEditorAlignmentDependentWidget *MsaEditorWgt::getSimilarityWidget() {
117     return similarityStatistics;
118 }
119 
initSeqArea(GScrollBar * shBar,GScrollBar * cvBar)120 void MsaEditorWgt::initSeqArea(GScrollBar *shBar, GScrollBar *cvBar) {
121     sequenceArea = new MSAEditorSequenceArea(this, shBar, cvBar);
122 }
123 
initOverviewArea()124 void MsaEditorWgt::initOverviewArea() {
125     overviewArea = new MSAEditorOverviewArea(this);
126 }
127 
initNameList(QScrollBar * nhBar)128 void MsaEditorWgt::initNameList(QScrollBar *nhBar) {
129     nameList = new MsaEditorNameList(this, nhBar);
130 }
131 
initConsensusArea()132 void MsaEditorWgt::initConsensusArea() {
133     consensusArea = new MSAEditorConsensusArea(this);
134 }
135 
initStatusBar()136 void MsaEditorWgt::initStatusBar() {
137     statusBar = new MsaEditorStatusBar(getEditor());
138 }
139 
getCurrentTree() const140 MSAEditorTreeViewer *MsaEditorWgt::getCurrentTree() const {
141     if (nullptr == multiTreeViewer) {
142         return nullptr;
143     }
144     GObjectViewWindow *page = qobject_cast<GObjectViewWindow *>(multiTreeViewer->getCurrentWidget());
145     if (nullptr == page) {
146         return nullptr;
147     }
148     return qobject_cast<MSAEditorTreeViewer *>(page->getObjectView());
149 }
150 
getMultiTreeViewer()151 MSAEditorMultiTreeViewer *MsaEditorWgt::getMultiTreeViewer() {
152     return multiTreeViewer;
153 }
154 
155 }  // namespace U2
156