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 "TreeSettingsDialog.h"
23 
24 #include <QPushButton>
25 
26 #include <U2Core/U2SafePoints.h>
27 #include <U2Core/global.h>
28 
29 #include <U2Gui/HelpButton.h>
30 
31 namespace U2 {
32 
TreeSettingsDialog(QWidget * parent,const OptionsMap & settings,bool isRectLayout)33 TreeSettingsDialog::TreeSettingsDialog(QWidget *parent, const OptionsMap &settings, bool isRectLayout)
34     : BaseSettingsDialog(parent) {
35     setupUi(this);
36     new HelpButton(this, buttonBox, "65929724");
37     buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
38     buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
39 
40     heightSlider->setValue(settings[HEIGHT_COEF].toUInt());
41     widthlSlider->setValue(settings[WIDTH_COEF].toUInt());
42 
43     heightSlider->setEnabled(isRectLayout);
44 
45     scaleSpinBox->setValue(settings[SCALEBAR_RANGE].toDouble());
46 
47     treeViewCombo->addItem(getDefaultTreeModeText());
48     treeViewCombo->addItem(getPhylogramTreeModeText());
49     treeViewCombo->addItem(getCladogramTreeModeText());
50 
51     switch (settings[BRANCHES_TRANSFORMATION_TYPE].toUInt()) {
52         case DEFAULT:
53             treeViewCombo->setCurrentIndex(treeViewCombo->findText(getDefaultTreeModeText()));
54             break;
55         case PHYLOGRAM:
56             treeViewCombo->setCurrentIndex(treeViewCombo->findText(getPhylogramTreeModeText()));
57             break;
58         case CLADOGRAM:
59             treeViewCombo->setCurrentIndex(treeViewCombo->findText(getCladogramTreeModeText()));
60             break;
61         default:
62             assert(false && "Unexpected tree type value.");
63     }
64 
65     connect(treeViewCombo, SIGNAL(currentIndexChanged(int)), SLOT(sl_treeTypeChanged(int)));
66 }
67 
sl_treeTypeChanged(int value)68 void TreeSettingsDialog::sl_treeTypeChanged(int value) {
69     scaleLabel->setEnabled(value == PHYLOGRAM);
70     scaleSpinBox->setEnabled(value == PHYLOGRAM);
71 }
72 
accept()73 void TreeSettingsDialog::accept() {
74     updatedSettings[HEIGHT_COEF] = heightSlider->value();
75     updatedSettings[WIDTH_COEF] = widthlSlider->value();
76 
77     if (treeViewCombo->currentText() == getDefaultTreeModeText()) {
78         updatedSettings[BRANCHES_TRANSFORMATION_TYPE] = DEFAULT;
79     } else if (treeViewCombo->currentText() == getPhylogramTreeModeText()) {
80         updatedSettings[BRANCHES_TRANSFORMATION_TYPE] = PHYLOGRAM;
81     } else if (treeViewCombo->currentText() == getCladogramTreeModeText()) {
82         updatedSettings[BRANCHES_TRANSFORMATION_TYPE] = CLADOGRAM;
83     } else {
84         FAIL("Unexpected tree type value", );
85     }
86     if (scaleSpinBox->isEnabled()) {
87         updatedSettings[SCALEBAR_RANGE] = scaleSpinBox->value();
88     }
89 
90     QDialog::accept();
91 }
92 
getDefaultTreeModeText()93 QString TreeSettingsDialog::getDefaultTreeModeText() {
94     return tr("Default");
95 }
96 
getPhylogramTreeModeText()97 QString TreeSettingsDialog::getPhylogramTreeModeText() {
98     return tr("Phylogram");
99 }
100 
getCladogramTreeModeText()101 QString TreeSettingsDialog::getCladogramTreeModeText() {
102     return tr("Cladogram");
103 }
104 
105 }  // namespace U2
106