1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "paletteeditor.h"
31
#include <QtCore/qdebug.h>
32
#include <QtGui/QMessageBox>
34
using namespace qdesigner_internal;
36
PaletteEditor::PaletteEditor(QWidget *parent)
40
ui.btnAdvanced->hide(); // ### not implemented yet
43
PaletteEditor::~PaletteEditor()
47
void PaletteEditor::on_btnAdvanced_clicked()
49
QMessageBox::information(this, tr("Palette Editor..."), tr("Feature not yet implemented!"));
53
QPalette pal = PaletteEditorAdvanced::getPalette(&ok, m_editPalette, backgroundMode, this, "tune_palette", formWindow);
58
updatePreviewPalette();
61
void PaletteEditor::on_buttonMainColor_clicked()
66
void PaletteEditor::on_buttonMainColor2_clicked()
71
void PaletteEditor::on_paletteCombo_activated(int)
73
updatePreviewPalette();
76
void PaletteEditor::buildPalette()
78
QColor btn = ui.buttonMainColor->brush().color();
79
QColor back = ui.buttonMainColor2->brush().color();
81
setEditPalette(QPalette(btn, back));
84
void PaletteEditor::buildActiveEffect()
86
QColor btn = m_editPalette.color(QPalette::Button);
88
QPalette temp(btn, btn);
89
temp.setCurrentColorGroup(QPalette::Active);
91
m_editPalette.setCurrentColorGroup(QPalette::Active);
93
m_editPalette.setBrush(QPalette::Light, temp.light());
94
m_editPalette.setBrush(QPalette::Midlight, temp.midlight());
95
m_editPalette.setBrush(QPalette::Mid, temp.mid());
96
m_editPalette.setBrush(QPalette::Dark, temp.dark());
97
m_editPalette.setBrush(QPalette::Shadow, temp.shadow());
100
void PaletteEditor::updatePaletteEffect(QPalette::ColorGroup g)
102
QColor btn = m_editPalette.color(g, QPalette::Button);
104
QColor light = btn.light(150);
105
QColor midlight = btn.light(115);
106
QColor mid = btn.dark(150);
107
QColor dark = btn.dark();
108
QColor shadow = Qt::black;
110
m_editPalette.setColor(g, QPalette::Light, light);
111
m_editPalette.setColor(g, QPalette::Midlight, midlight);
112
m_editPalette.setColor(g, QPalette::Mid, mid);
113
m_editPalette.setColor(g, QPalette::Dark, dark);
114
m_editPalette.setColor(g, QPalette::Shadow, shadow);
117
QPalette::ColorGroup PaletteEditor::selectedColorGroup() const
119
switch (ui.paletteCombo->currentIndex()) {
120
default: return QPalette::Active;
121
case 0: return QPalette::Active;
122
case 1: return QPalette::Inactive;
123
case 2: return QPalette::Disabled;
127
void PaletteEditor::updatePreviewPalette()
129
QPalette::ColorGroup g = selectedColorGroup();
131
// build the preview palette
132
QPalette previewPalette = m_editPalette;
133
for (QPalette::ColorRole r = QPalette::Foreground; r < QPalette::NColorRoles; reinterpret_cast<int&>(r)++) {
134
previewPalette.setColor(QPalette::Active, r, m_editPalette.color(g, r));
135
previewPalette.setColor(QPalette::Inactive, r, m_editPalette.color(g, r));
136
previewPalette.setColor(QPalette::Disabled, r, m_editPalette.color(g, r));
139
ui.previewFrame->setPreviewPalette(previewPalette);
142
void PaletteEditor::updateStyledButtons()
144
ui.buttonMainColor->setBrush(m_editPalette.color(QPalette::Active, QPalette::Button));
145
ui.buttonMainColor2->setBrush(m_editPalette.color(QPalette::Active, QPalette::Background));
148
void PaletteEditor::setEditPalette(const QPalette& pal)
152
updatePaletteEffect(QPalette::Inactive);
153
updatePaletteEffect(QPalette::Disabled);
154
updatePreviewPalette();
155
updateStyledButtons();
158
QPalette PaletteEditor::editPalette() const
160
return m_editPalette;
163
QPalette PaletteEditor::getPalette(QWidget* parent, const QPalette &init, int *ok)
165
PaletteEditor dlg(parent);
166
dlg.setEditPalette(init);
168
int result = dlg.exec();
169
if (ok) *ok = result;
171
return result == QDialog::Accepted ? dlg.editPalette() : init;