Debian Codegraph @

src/Gui/PreferencePages/DlgSettingsViewColor.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2009 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library 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 Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #include <QPushButton>
24
25
26 #include "DlgSettingsViewColor.h"
27 #include "ui_DlgSettingsViewColor.h"
28
29
30 using namespace Gui::Dialog;
31
32 /* TRANSLATOR Gui::Dialog::DlgSettingsViewColor */
33
34 /**
35 * Constructs a DlgSettingsViewColor which is a child of 'parent', with the
36 * name 'name' and widget flags set to 'f'
37 */
38 DlgSettingsViewColor::DlgSettingsViewColor(QWidget* parent)
39 : PreferencePage(parent)
40 , ui(new Ui_DlgSettingsViewColor)
41 {
42 // clang-format off
43 ui->setupUi(this);
44 connect(ui->SwitchGradientColors, &QPushButton::pressed, this,
45 &DlgSettingsViewColor::onSwitchGradientColorsPressed);
46
47 connect(ui->radioButtonSimple, &QRadioButton::toggled, this,
48 &DlgSettingsViewColor::onRadioButtonSimpleToggled);
49
50 connect(ui->radioButtonGradient, &QRadioButton::toggled, this,
51 &DlgSettingsViewColor::onRadioButtonGradientToggled);
52
53 connect(ui->rbRadialGradient, &QRadioButton::toggled, this,
54 &DlgSettingsViewColor::onRadioButtonRadialGradientToggled);
55
56 connect(ui->checkMidColor, &QCheckBox::toggled, this,
57 &DlgSettingsViewColor::onCheckMidColorToggled);
58 // clang-format on
59 }
60
61 /**
62 * Destroys the object and frees any allocated resources
63 */
64 DlgSettingsViewColor::~DlgSettingsViewColor() = default;
65
66 void DlgSettingsViewColor::saveSettings()
67 {
68 ui->SelectionColor_Background->onSave();
69 ui->backgroundColorFrom->onSave();
70 ui->backgroundColorTo->onSave();
71 ui->backgroundColorMid->onSave();
72 ui->radioButtonSimple->onSave();
73 ui->radioButtonGradient->onSave();
74 ui->rbRadialGradient->onSave();
75 ui->checkMidColor->onSave();
76 ui->TreeEditColor->onSave();
77 ui->TreeActiveColor->onSave();
78 ui->CbLabelColor->onSave();
79 ui->CbLabelTextSize->onSave();
80 }
81
82 void DlgSettingsViewColor::loadSettings()
83 {
84 ui->SelectionColor_Background->onRestore();
85 ui->backgroundColorFrom->onRestore();
86 ui->backgroundColorTo->onRestore();
87 ui->backgroundColorMid->onRestore();
88 ui->radioButtonSimple->onRestore();
89 ui->radioButtonGradient->onRestore();
90 ui->rbRadialGradient->onRestore();
91 ui->checkMidColor->onRestore();
92 ui->TreeEditColor->onRestore();
93 ui->TreeActiveColor->onRestore();
94 ui->CbLabelColor->onRestore();
95 ui->CbLabelTextSize->onRestore();
96
97 if (ui->radioButtonSimple->isChecked()) {
98 onRadioButtonSimpleToggled(true);
99 }
100 else if (ui->radioButtonGradient->isChecked()) {
101 onRadioButtonGradientToggled(true);
102 }
103 else {
104 onRadioButtonRadialGradientToggled(true);
105 }
106 }
107
108 /**
109 * Sets the strings of the subwidgets using the current language.
110 */
111 void DlgSettingsViewColor::changeEvent(QEvent* e)
112 {
113 if (e->type() == QEvent::LanguageChange) {
114 ui->retranslateUi(this);
115 }
116 else {
117 QWidget::changeEvent(e);
118 }
119 }
120
121 void DlgSettingsViewColor::onSwitchGradientColorsPressed()
122 {
123 QColor tempColor = ui->backgroundColorFrom->color();
124 ui->backgroundColorFrom->setColor(ui->backgroundColorTo->color());
125 ui->backgroundColorTo->setColor(tempColor);
126 }
127
128 void DlgSettingsViewColor::onCheckMidColorToggled(bool val)
129 {
130 ui->color2Label->setEnabled(val);
131 ui->backgroundColorMid->setEnabled(val);
132 }
133
134 void DlgSettingsViewColor::onRadioButtonSimpleToggled(bool val)
135 {
136 setGradientColorVisibility(!val);
137 }
138
139 void DlgSettingsViewColor::onRadioButtonGradientToggled(bool val)
140 {
141 setGradientColorVisibility(val);
142 ui->color1Label->setText(tr("Top:"));
143 ui->color2Label->setText(tr("Middle:"));
144 ui->color3Label->setText(tr("Bottom:"));
145 }
146
147 void DlgSettingsViewColor::onRadioButtonRadialGradientToggled(bool val)
148 {
149 setGradientColorVisibility(val);
150 ui->color1Label->setText(tr("Central:"));
151 ui->color2Label->setText(tr("Midway:"));
152 ui->color3Label->setText(tr("End:"));
153 }
154
155 void DlgSettingsViewColor::setGradientColorVisibility(bool val)
156 {
157 ui->SelectionColor_Background->setVisible(!val);
158 ui->color1Label->setVisible(val);
159 ui->backgroundColorFrom->setVisible(val);
160 ui->color2Label->setVisible(val);
161 ui->backgroundColorMid->setVisible(val);
162 ui->color3Label->setVisible(val);
163 ui->backgroundColorTo->setVisible(val);
164 ui->checkMidColor->setVisible(val);
165 ui->SwitchGradientColors->setVisible(val);
166
167 if (val) {
168 onCheckMidColorToggled(ui->checkMidColor->isChecked());
169 }
170 }
171
172 #include "moc_DlgSettingsViewColor.cpp"