Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | #include "ui_paletteeditoradvanced.h" |
42 | #include "paletteeditoradvanced.h" |
43 | #include "colorbutton.h" |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | PaletteEditorAdvanced::PaletteEditorAdvanced(QWidget *parent) |
48 | : QDialog(parent), ui(new Ui::PaletteEditorAdvanced), selectedPalette(0) |
49 | { |
50 | ui->setupUi(this); |
51 | |
52 | // create a ColorButton's |
53 | buttonCentral = new ColorButton(ui->groupCentral); |
54 | buttonCentral->setToolTip(tr("Choose a color")); |
55 | buttonCentral->setWhatsThis(tr("Choose a color for the selected central color role.")); |
56 | ui->layoutCentral->addWidget(buttonCentral); |
57 | ui->labelCentral->setBuddy(buttonCentral); |
58 | |
59 | buttonEffect = new ColorButton(ui->groupEffect); |
60 | buttonEffect->setToolTip(tr("Choose a color")); |
61 | buttonEffect->setWhatsThis(tr("Choose a color for the selected effect color role.")); |
62 | buttonEffect->setEnabled(false); |
63 | ui->layoutEffect->addWidget(buttonEffect); |
64 | ui->labelEffect->setBuddy(buttonEffect); |
65 | |
66 | // signals and slots connections |
67 | connect(ui->paletteCombo, SIGNAL(activated(int)), SLOT(paletteSelected(int))); |
68 | connect(ui->comboCentral, SIGNAL(activated(int)), SLOT(onCentral(int))); |
69 | connect(buttonCentral, SIGNAL(clicked()), SLOT(onChooseCentralColor())); |
70 | connect(buttonEffect, SIGNAL(clicked()), SLOT(onChooseEffectColor())); |
71 | connect(ui->comboEffect, SIGNAL(activated(int)), SLOT(onEffect(int))); |
72 | connect(ui->checkBuildEffect, SIGNAL(toggled(bool)), SLOT(onToggleBuildEffects(bool))); |
73 | connect(ui->checkBuildEffect, SIGNAL(toggled(bool)), buttonEffect, SLOT(setDisabled(bool))); |
74 | connect(ui->checkBuildInactive, SIGNAL(toggled(bool)), SLOT(onToggleBuildInactive(bool))); |
75 | connect(ui->checkBuildDisabled, SIGNAL(toggled(bool)), SLOT(onToggleBuildDisabled(bool))); |
76 | |
77 | onToggleBuildEffects(true); |
78 | |
79 | editPalette = QApplication::palette(); |
80 | } |
81 | |
82 | PaletteEditorAdvanced::~PaletteEditorAdvanced() |
83 | { |
84 | delete ui; |
85 | } |
86 | |
87 | void PaletteEditorAdvanced::onToggleBuildInactive(bool v) |
88 | { |
89 | if (selectedPalette == 1) { |
90 | ui->groupCentral->setDisabled(v); |
91 | ui->groupEffect->setDisabled(v); |
92 | } |
93 | |
94 | if (v) { |
95 | build(QPalette::Inactive); |
96 | updateColorButtons(); |
97 | } |
98 | } |
99 | |
100 | void PaletteEditorAdvanced::onToggleBuildDisabled(bool v) |
101 | { |
102 | if (selectedPalette == 2) { |
103 | ui->groupCentral->setDisabled(v); |
104 | ui->groupEffect->setDisabled(v); |
105 | } |
106 | |
107 | if (v) { |
108 | build(QPalette::Disabled); |
109 | updateColorButtons(); |
110 | } |
111 | } |
112 | |
113 | void PaletteEditorAdvanced::paletteSelected(int p) |
114 | { |
115 | selectedPalette = p; |
116 | |
117 | if(p == 1) { // inactive |
118 | ui->groupCentral->setDisabled(ui->checkBuildInactive->isChecked()); |
119 | ui->groupEffect->setDisabled(ui->checkBuildInactive->isChecked()); |
120 | } else if (p == 2) { // disabled |
121 | ui->groupCentral->setDisabled(ui->checkBuildDisabled->isChecked()); |
122 | ui->groupEffect->setDisabled(ui->checkBuildDisabled->isChecked()); |
123 | } else { |
124 | ui->groupCentral->setEnabled(true); |
125 | ui->groupEffect->setEnabled(true); |
126 | } |
127 | updateColorButtons(); |
128 | } |
129 | |
130 | void PaletteEditorAdvanced::onChooseCentralColor() |
131 | { |
132 | QPalette::ColorGroup group = groupFromIndex(selectedPalette); |
133 | editPalette.setColor(group, centralFromIndex(ui->comboCentral->currentIndex()), |
134 | buttonCentral->color()); |
135 | |
136 | buildEffect(group); |
137 | if (group == QPalette::Active) { |
138 | if(ui->checkBuildInactive->isChecked()) |
139 | build(QPalette::Inactive); |
140 | if(ui->checkBuildDisabled->isChecked()) |
141 | build(QPalette::Disabled); |
142 | } |
143 | |
144 | updateColorButtons(); |
145 | } |
146 | |
147 | void PaletteEditorAdvanced::onChooseEffectColor() |
148 | { |
149 | QPalette::ColorGroup group = groupFromIndex(selectedPalette); |
150 | editPalette.setColor(group, effectFromIndex(ui->comboEffect->currentIndex()), |
151 | buttonEffect->color()); |
152 | |
153 | if (group == QPalette::Active) { |
154 | if(ui->checkBuildInactive->isChecked()) |
155 | build(QPalette::Inactive); |
156 | if(ui->checkBuildDisabled->isChecked()) |
157 | build(QPalette::Disabled); |
158 | } |
159 | |
160 | updateColorButtons(); |
161 | } |
162 | |
163 | void PaletteEditorAdvanced::onToggleBuildEffects(bool on) |
164 | { |
165 | if (on) { |
166 | for (int i = 0; i < QPalette::NColorGroups; i++) |
167 | buildEffect(QPalette::ColorGroup(i)); |
168 | } |
169 | } |
170 | |
171 | QPalette::ColorGroup PaletteEditorAdvanced::groupFromIndex(int item) |
172 | { |
173 | switch (item) { |
174 | case 0: |
175 | default: |
176 | return QPalette::Active; |
177 | case 1: |
178 | return QPalette::Inactive; |
179 | case 2: |
180 | return QPalette::Disabled; |
181 | } |
182 | } |
183 | |
184 | QPalette::ColorRole PaletteEditorAdvanced::centralFromIndex(int item) |
185 | { |
186 | switch (item) { |
187 | case 0: |
188 | return QPalette::Window; |
189 | case 1: |
190 | return QPalette::WindowText; |
191 | case 2: |
192 | return QPalette::Base; |
193 | case 3: |
194 | return QPalette::AlternateBase; |
195 | case 4: |
196 | return QPalette::ToolTipBase; |
197 | case 5: |
198 | return QPalette::ToolTipText; |
199 | case 6: |
200 | return QPalette::Text; |
201 | case 7: |
202 | return QPalette::Button; |
203 | case 8: |
204 | return QPalette::ButtonText; |
205 | case 9: |
206 | return QPalette::BrightText; |
207 | case 10: |
208 | return QPalette::Highlight; |
209 | case 11: |
210 | return QPalette::HighlightedText; |
211 | case 12: |
212 | return QPalette::Link; |
213 | case 13: |
214 | return QPalette::LinkVisited; |
215 | default: |
216 | return QPalette::NoRole; |
217 | } |
218 | } |
219 | |
220 | QPalette::ColorRole PaletteEditorAdvanced::effectFromIndex(int item) |
221 | { |
222 | switch (item) { |
223 | case 0: |
224 | return QPalette::Light; |
225 | case 1: |
226 | return QPalette::Midlight; |
227 | case 2: |
228 | return QPalette::Mid; |
229 | case 3: |
230 | return QPalette::Dark; |
231 | case 4: |
232 | return QPalette::Shadow; |
233 | default: |
234 | return QPalette::NoRole; |
235 | } |
236 | } |
237 | |
238 | void PaletteEditorAdvanced::onCentral(int item) |
239 | { |
240 | QColor c = editPalette.color(groupFromIndex(selectedPalette), centralFromIndex(item)); |
241 | buttonCentral->setColor(c); |
242 | } |
243 | |
244 | void PaletteEditorAdvanced::onEffect(int item) |
245 | { |
246 | QColor c = editPalette.color(groupFromIndex(selectedPalette), effectFromIndex(item)); |
247 | buttonEffect->setColor(c); |
248 | } |
249 | |
250 | QPalette PaletteEditorAdvanced::buildEffect(QPalette::ColorGroup colorGroup, |
251 | const QPalette &basePalette) |
252 | { |
253 | QPalette result(basePalette); |
254 | |
255 | if (colorGroup == QPalette::Active) { |
256 | QPalette calculatedPalette(basePalette.color(colorGroup, QPalette::Button), |
257 | basePalette.color(colorGroup, QPalette::Window)); |
258 | |
259 | for (int i = 0; i < 5; i++) { |
260 | QPalette::ColorRole effectRole = effectFromIndex(i); |
261 | result.setColor(colorGroup, effectRole, |
262 | calculatedPalette.color(colorGroup, effectRole)); |
263 | } |
264 | } else { |
265 | QColor btn = basePalette.color(colorGroup, QPalette::Button); |
266 | |
267 | result.setColor(colorGroup, QPalette::Light, btn.lighter()); |
268 | result.setColor(colorGroup, QPalette::Midlight, btn.lighter(115)); |
269 | result.setColor(colorGroup, QPalette::Mid, btn.darker(150)); |
270 | result.setColor(colorGroup, QPalette::Dark, btn.darker()); |
271 | result.setColor(colorGroup, QPalette::Shadow, Qt::black); |
272 | } |
273 | |
274 | return result; |
275 | } |
276 | |
277 | void PaletteEditorAdvanced::buildEffect(QPalette::ColorGroup colorGroup) |
278 | { |
279 | editPalette = buildEffect(colorGroup, editPalette); |
280 | updateColorButtons(); |
281 | } |
282 | |
283 | void PaletteEditorAdvanced::build(QPalette::ColorGroup colorGroup) |
284 | { |
285 | if (colorGroup != QPalette::Active) { |
286 | for (int i = 0; i < QPalette::NColorRoles; i++) |
287 | editPalette.setColor(colorGroup, QPalette::ColorRole(i), |
288 | editPalette.color(QPalette::Active, QPalette::ColorRole(i))); |
289 | |
290 | if (colorGroup == QPalette::Disabled) { |
291 | editPalette.setColor(colorGroup, QPalette::ButtonText, Qt::darkGray); |
292 | editPalette.setColor(colorGroup, QPalette::WindowText, Qt::darkGray); |
293 | editPalette.setColor(colorGroup, QPalette::Text, Qt::darkGray); |
294 | editPalette.setColor(colorGroup, QPalette::HighlightedText, Qt::darkGray); |
295 | } |
296 | |
297 | if (ui->checkBuildEffect->isChecked()) |
298 | buildEffect(colorGroup); |
299 | else |
300 | updateColorButtons(); |
301 | } |
302 | } |
303 | |
304 | void PaletteEditorAdvanced::updateColorButtons() |
305 | { |
306 | QPalette::ColorGroup colorGroup = groupFromIndex(selectedPalette); |
307 | buttonCentral->setColor(editPalette.color(colorGroup, |
308 | centralFromIndex(ui->comboCentral->currentIndex()))); |
309 | buttonEffect->setColor(editPalette.color(colorGroup, |
310 | effectFromIndex(ui->comboEffect->currentIndex()))); |
311 | } |
312 | |
313 | void PaletteEditorAdvanced::setPal(const QPalette &pal) |
314 | { |
315 | editPalette = pal; |
316 | updateColorButtons(); |
317 | } |
318 | |
319 | QPalette PaletteEditorAdvanced::pal() const |
320 | { |
321 | return editPalette; |
322 | } |
323 | |
324 | void PaletteEditorAdvanced::setupBackgroundRole(QPalette::ColorRole role) |
325 | { |
326 | int initRole = 0; |
327 | |
328 | switch (role) { |
329 | case QPalette::Window: |
330 | initRole = 0; |
331 | break; |
332 | case QPalette::WindowText: |
333 | initRole = 1; |
334 | break; |
335 | case QPalette::Base: |
336 | initRole = 2; |
337 | break; |
338 | case QPalette::AlternateBase: |
339 | initRole = 3; |
340 | break; |
341 | case QPalette::ToolTipBase: |
342 | initRole = 4; |
343 | break; |
344 | case QPalette::ToolTipText: |
345 | initRole = 5; |
346 | break; |
347 | case QPalette::Text: |
348 | initRole = 6; |
349 | break; |
350 | case QPalette::Button: |
351 | initRole = 7; |
352 | break; |
353 | case QPalette::ButtonText: |
354 | initRole = 8; |
355 | break; |
356 | case QPalette::BrightText: |
357 | initRole = 9; |
358 | break; |
359 | case QPalette::Highlight: |
360 | initRole = 10; |
361 | break; |
362 | case QPalette::HighlightedText: |
363 | initRole = 11; |
364 | break; |
365 | case QPalette::Link: |
366 | initRole = 12; |
367 | break; |
368 | case QPalette::LinkVisited: |
369 | initRole = 13; |
370 | break; |
371 | default: |
372 | initRole = -1; |
373 | break; |
374 | } |
375 | |
376 | if (initRole != -1) |
377 | ui->comboCentral->setCurrentIndex(initRole); |
378 | } |
379 | |
380 | QPalette PaletteEditorAdvanced::getPalette(bool *ok, const QPalette &init, |
381 | QPalette::ColorRole backgroundRole, QWidget *parent) |
382 | { |
383 | PaletteEditorAdvanced *dlg = new PaletteEditorAdvanced(parent); |
384 | dlg->setupBackgroundRole(backgroundRole); |
385 | |
386 | if (init != QPalette()) |
387 | dlg->setPal(init); |
388 | int resultCode = dlg->exec(); |
389 | |
390 | QPalette result = init; |
391 | if (resultCode == QDialog::Accepted) |
392 | result = dlg->pal(); |
393 | |
394 | if (ok) |
395 | *ok = resultCode; |
396 | |
397 | delete dlg; |
398 | return result; |
399 | } |
400 | |
401 | QT_END_NAMESPACE |
402 |
Warning: That file was not part of the compilation database. It may have many parsing errors.