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 "TextSettingsDialog.h"
23 
24 #include <QColorDialog>
25 #include <QProxyStyle>
26 #include <QStyleFactory>
27 
28 #include <U2Gui/HelpButton.h>
29 
30 namespace U2 {
31 
TextSettingsDialog(QWidget * parent,const OptionsMap & settings)32 TextSettingsDialog::TextSettingsDialog(QWidget *parent, const OptionsMap &settings)
33     : BaseSettingsDialog(parent) {
34     setupUi(this);
35     new HelpButton(this, buttonBox, "65929735");
36     buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
37     buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
38 
39     curColor = qvariant_cast<QColor>(settings[LABEL_COLOR]);
40 
41     QStyle *buttonStyle = new QProxyStyle(QStyleFactory::create("fusion"));
42     buttonStyle->setParent(colorButton);
43     colorButton->setStyle(buttonStyle);
44 
45     updateColorButton();
46     QFont curFont = qvariant_cast<QFont>(settings[LABEL_FONT_TYPE]);
47     fontComboBox->setCurrentFont(curFont);
48     sizeSpinBox->setValue(qvariant_cast<int>(settings[LABEL_FONT_SIZE]));
49     boldToolButton->setChecked(qvariant_cast<bool>(settings[LABEL_FONT_BOLD]));
50     italicToolButton->setChecked(qvariant_cast<bool>(settings[LABEL_FONT_ITALIC]));
51     underlineToolButton->setChecked(qvariant_cast<bool>(settings[LABEL_FONT_UNDERLINE]));
52     overlineToolButton->setChecked(curFont.overline());
53 
54     overlineToolButton->setVisible(false);
55 
56     connect(colorButton, SIGNAL(clicked()), SLOT(sl_colorButton()));
57 }
58 
updateColorButton()59 void TextSettingsDialog::updateColorButton() {
60     QPalette palette = colorButton->palette();
61     palette.setColor(colorButton->backgroundRole(), curColor);
62     colorButton->setPalette(palette);
63 }
64 
sl_colorButton()65 void TextSettingsDialog::sl_colorButton() {
66     curColor = QColorDialog::getColor(curColor, this);
67     if (curColor.isValid()) {
68         updatedSettings[LABEL_COLOR] = curColor;
69         updateColorButton();
70     }
71 }
72 
accept()73 void TextSettingsDialog::accept() {
74     QFont curFont = fontComboBox->currentFont();
75     curFont.setPointSize(sizeSpinBox->value());
76 
77     curFont.setBold(boldToolButton->isChecked());
78     curFont.setItalic(italicToolButton->isChecked());
79     curFont.setUnderline(underlineToolButton->isChecked());
80     curFont.setOverline(overlineToolButton->isChecked());
81 
82     updatedSettings[LABEL_FONT_TYPE] = curFont;
83     updatedSettings[LABEL_FONT_SIZE] = curFont.pointSize();
84     updatedSettings[LABEL_FONT_BOLD] = curFont.bold();
85     updatedSettings[LABEL_FONT_ITALIC] = curFont.italic();
86     updatedSettings[LABEL_FONT_UNDERLINE] = curFont.underline();
87 
88     QDialog::accept();
89 }
90 
91 }  // namespace U2
92