1
/**********************************************************************
2
** Copyright (C) 2000 Trolltech AS. All rights reserved.
4
** This file is part of Qt Designer.
6
** This file may be distributed and/or modified under the terms of the
7
** GNU General Public License version 2 as published by the Free Software
8
** Foundation and appearing in the file LICENSE.GPL included in the
9
** packaging of this file.
11
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12
** licenses may use this file in accordance with the Qt Commercial License
13
** Agreement provided with the Software.
15
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18
** See http://www.trolltech.com/gpl/ for GPL licensing information.
19
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20
** information about Qt Commercial License Agreements.
22
** Contact info@trolltech.com if any conditions of this licensing are
25
**********************************************************************/
27
#include "paletteeditorimpl.h"
28
#include "paletteeditoradvancedimpl.h"
29
#include "previewframe.h"
30
#include "styledbutton.h"
31
#include "mainwindow.h"
32
#include "formwindow.h"
34
#include <qcheckbox.h>
35
#include <qcombobox.h>
36
#include <qapplication.h>
37
#include <qpushbutton.h>
39
PaletteEditor::PaletteEditor( FormWindow *fw, QWidget * parent, const char * name, bool modal, WFlags f )
40
: PaletteEditorBase( parent, name, modal, f ), formWindow( fw )
42
connect( buttonHelp, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) );
44
editPalette = QApplication::palette();
45
setPreviewPalette( editPalette );
47
buttonMainColor->setColor( editPalette.active().color( QColorGroup::Button ) );
48
buttonMainColor2->setColor( editPalette.active().color( QColorGroup::Background ) );
51
PaletteEditor::~PaletteEditor()
55
void PaletteEditor::onTune()
58
QPalette pal = PaletteEditorAdvanced::getPalette( &ok, editPalette, backgroundMode, this, "tune_palette", formWindow);
62
setPreviewPalette( editPalette );
65
void PaletteEditor::onChooseMainColor()
70
void PaletteEditor::onChoose2ndMainColor()
75
void PaletteEditor::paletteSelected(int)
77
setPreviewPalette(editPalette);
80
QColorGroup::ColorRole PaletteEditor::centralFromItem( int item )
85
return QColorGroup::Background;
87
return QColorGroup::Foreground;
89
return QColorGroup::Button;
91
return QColorGroup::Base;
93
return QColorGroup::Text;
95
return QColorGroup::BrightText;
97
return QColorGroup::ButtonText;
99
return QColorGroup::Highlight;
101
return QColorGroup::HighlightedText;
103
return QColorGroup::NColorRoles;
107
QColorGroup::ColorRole PaletteEditor::effectFromItem( int item )
112
return QColorGroup::Light;
114
return QColorGroup::Midlight;
116
return QColorGroup::Mid;
118
return QColorGroup::Dark;
120
return QColorGroup::Shadow;
122
return QColorGroup::NColorRoles;
126
void PaletteEditor::buildPalette()
130
QColor btn = buttonMainColor->color();
131
QColor back = buttonMainColor2->color();
132
QPalette automake( btn, back );
134
for (i = 0; i<9; i++)
135
cg.setColor( centralFromItem(i), automake.active().color( centralFromItem(i) ) );
137
editPalette.setActive( cg );
140
cg = editPalette.inactive();
142
QPalette temp( editPalette.active().color( QColorGroup::Button ),
143
editPalette.active().color( QColorGroup::Background ) );
145
for (i = 0; i<9; i++)
146
cg.setColor( centralFromItem(i), temp.inactive().color( centralFromItem(i) ) );
148
editPalette.setInactive( cg );
149
buildInactiveEffect();
151
cg = editPalette.disabled();
153
for (i = 0; i<9; i++)
154
cg.setColor( centralFromItem(i), temp.disabled().color( centralFromItem(i) ) );
156
editPalette.setDisabled( cg );
157
buildDisabledEffect();
159
updateStyledButtons();
162
void PaletteEditor::buildActiveEffect()
164
QColorGroup cg = editPalette.active();
165
QColor btn = cg.color( QColorGroup::Button );
167
QPalette temp( btn, btn );
169
for (int i = 0; i<5; i++)
170
cg.setColor( effectFromItem(i), temp.active().color( effectFromItem(i) ) );
172
editPalette.setActive( cg );
173
setPreviewPalette( editPalette );
175
updateStyledButtons();
178
void PaletteEditor::buildInactive()
180
editPalette.setInactive( editPalette.active() );
181
buildInactiveEffect();
184
void PaletteEditor::buildInactiveEffect()
186
QColorGroup cg = editPalette.inactive();
188
QColor light, midlight, mid, dark, shadow;
189
QColor btn = cg.color( QColorGroup::Button );
191
light = btn.light(150);
192
midlight = btn.light(115);
197
cg.setColor( QColorGroup::Light, light );
198
cg.setColor( QColorGroup::Midlight, midlight );
199
cg.setColor( QColorGroup::Mid, mid );
200
cg.setColor( QColorGroup::Dark, dark );
201
cg.setColor( QColorGroup::Shadow, shadow );
203
editPalette.setInactive( cg );
204
setPreviewPalette( editPalette );
205
updateStyledButtons();
208
void PaletteEditor::buildDisabled()
210
QColorGroup cg = editPalette.active();
211
cg.setColor( QColorGroup::ButtonText, darkGray );
212
cg.setColor( QColorGroup::Foreground, darkGray );
213
editPalette.setDisabled( cg );
215
buildDisabledEffect();
218
void PaletteEditor::buildDisabledEffect()
220
QColorGroup cg = editPalette.disabled();
222
QColor light, midlight, mid, dark, shadow;
223
QColor btn = cg.color( QColorGroup::Button );
225
light = btn.light(150);
226
midlight = btn.light(115);
231
cg.setColor( QColorGroup::Light, light );
232
cg.setColor( QColorGroup::Midlight, midlight );
233
cg.setColor( QColorGroup::Mid, mid );
234
cg.setColor( QColorGroup::Dark, dark );
235
cg.setColor( QColorGroup::Shadow, shadow );
237
editPalette.setDisabled( cg );
238
setPreviewPalette( editPalette );
239
updateStyledButtons();
242
void PaletteEditor::setPreviewPalette( const QPalette& pal )
246
switch (paletteCombo->currentItem()) {
258
previewPalette.setActive( cg );
259
previewPalette.setInactive( cg );
260
previewPalette.setDisabled( cg );
262
previewFrame->setPreviewPalette(previewPalette);
265
void PaletteEditor::updateStyledButtons()
267
buttonMainColor->setColor( editPalette.active().color( QColorGroup::Button ));
268
buttonMainColor2->setColor( editPalette.active().color( QColorGroup::Background ));
271
void PaletteEditor::setPal( const QPalette& pal )
274
setPreviewPalette( pal );
275
updateStyledButtons();
278
QPalette PaletteEditor::pal() const
283
QPalette PaletteEditor::getPalette( bool *ok, const QPalette &init, BackgroundMode mode,
284
QWidget* parent, const char* name, FormWindow *fw )
286
PaletteEditor* dlg = new PaletteEditor( fw, parent, name, TRUE );
287
dlg->setupBackgroundMode( mode );
289
if ( init != QPalette() )
291
int resultCode = dlg->exec();
293
QPalette result = init;
294
if ( resultCode == QDialog::Accepted ) {