~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to kdevdesigner/designer/paletteeditorimpl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************
2
 
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
3
 
**
4
 
** This file is part of Qt Designer.
5
 
**
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.
10
 
**
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.
14
 
**
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.
17
 
**
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.
21
 
**
22
 
** Contact info@trolltech.com if any conditions of this licensing are
23
 
** not clear to you.
24
 
**
25
 
**********************************************************************/
26
 
 
27
 
#include "paletteeditorimpl.h"
28
 
#include "paletteeditoradvancedimpl.h"
29
 
#include "previewframe.h"
30
 
#include "styledbutton.h"
31
 
#include "mainwindow.h"
32
 
#include "formwindow.h"
33
 
 
34
 
#include <qcheckbox.h>
35
 
#include <qcombobox.h>
36
 
#include <qapplication.h>
37
 
#include <qpushbutton.h>
38
 
 
39
 
PaletteEditor::PaletteEditor( FormWindow *fw, QWidget * parent, const char * name, bool modal, WFlags f )
40
 
    : PaletteEditorBase( parent, name, modal, f ), formWindow( fw )
41
 
{
42
 
    connect( buttonHelp, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) );
43
 
 
44
 
    editPalette =  QApplication::palette();
45
 
    setPreviewPalette( editPalette );
46
 
 
47
 
    buttonMainColor->setColor( editPalette.active().color( QColorGroup::Button ) );
48
 
    buttonMainColor2->setColor( editPalette.active().color( QColorGroup::Background ) );
49
 
}
50
 
 
51
 
PaletteEditor::~PaletteEditor()
52
 
{
53
 
}
54
 
 
55
 
void PaletteEditor::onTune()
56
 
{
57
 
    bool ok;
58
 
    QPalette pal = PaletteEditorAdvanced::getPalette( &ok, editPalette, backgroundMode, this, "tune_palette", formWindow);
59
 
    if (!ok) return;
60
 
 
61
 
    editPalette = pal;
62
 
    setPreviewPalette( editPalette );
63
 
}
64
 
 
65
 
void PaletteEditor::onChooseMainColor()
66
 
{
67
 
    buildPalette();
68
 
}
69
 
 
70
 
void PaletteEditor::onChoose2ndMainColor()
71
 
{
72
 
    buildPalette();
73
 
}
74
 
 
75
 
void PaletteEditor::paletteSelected(int)
76
 
{
77
 
    setPreviewPalette(editPalette);
78
 
}
79
 
 
80
 
QColorGroup::ColorRole PaletteEditor::centralFromItem( int item )
81
 
{
82
 
    switch( item )
83
 
        {
84
 
        case 0:
85
 
            return QColorGroup::Background;
86
 
        case 1:
87
 
            return QColorGroup::Foreground;
88
 
        case 2:
89
 
            return QColorGroup::Button;
90
 
        case 3:
91
 
            return QColorGroup::Base;
92
 
        case 4:
93
 
            return QColorGroup::Text;
94
 
        case 5:
95
 
            return QColorGroup::BrightText;
96
 
        case 6:
97
 
            return QColorGroup::ButtonText;
98
 
        case 7:
99
 
            return QColorGroup::Highlight;
100
 
        case 8:
101
 
            return QColorGroup::HighlightedText;
102
 
        default:
103
 
            return QColorGroup::NColorRoles;
104
 
        }
105
 
}
106
 
 
107
 
QColorGroup::ColorRole PaletteEditor::effectFromItem( int item )
108
 
{
109
 
    switch( item )
110
 
        {
111
 
        case 0:
112
 
            return QColorGroup::Light;
113
 
        case 1:
114
 
            return QColorGroup::Midlight;
115
 
        case 2:
116
 
            return QColorGroup::Mid;
117
 
        case 3:
118
 
            return QColorGroup::Dark;
119
 
        case 4:
120
 
            return QColorGroup::Shadow;
121
 
        default:
122
 
            return QColorGroup::NColorRoles;
123
 
        }
124
 
}
125
 
 
126
 
void PaletteEditor::buildPalette()
127
 
{
128
 
    int i;
129
 
    QColorGroup cg;
130
 
    QColor btn = buttonMainColor->color();
131
 
    QColor back = buttonMainColor2->color();
132
 
    QPalette automake( btn, back );
133
 
 
134
 
    for (i = 0; i<9; i++)
135
 
        cg.setColor( centralFromItem(i), automake.active().color( centralFromItem(i) ) );
136
 
 
137
 
    editPalette.setActive( cg );
138
 
    buildActiveEffect();
139
 
 
140
 
    cg = editPalette.inactive();
141
 
 
142
 
    QPalette temp( editPalette.active().color( QColorGroup::Button ),
143
 
                   editPalette.active().color( QColorGroup::Background ) );
144
 
 
145
 
    for (i = 0; i<9; i++)
146
 
        cg.setColor( centralFromItem(i), temp.inactive().color( centralFromItem(i) ) );
147
 
 
148
 
    editPalette.setInactive( cg );
149
 
    buildInactiveEffect();
150
 
 
151
 
    cg = editPalette.disabled();
152
 
 
153
 
    for (i = 0; i<9; i++)
154
 
        cg.setColor( centralFromItem(i), temp.disabled().color( centralFromItem(i) ) );
155
 
 
156
 
    editPalette.setDisabled( cg );
157
 
    buildDisabledEffect();
158
 
 
159
 
    updateStyledButtons();
160
 
}
161
 
 
162
 
void PaletteEditor::buildActiveEffect()
163
 
{
164
 
    QColorGroup cg = editPalette.active();
165
 
    QColor btn = cg.color( QColorGroup::Button );
166
 
 
167
 
    QPalette temp( btn, btn );
168
 
 
169
 
    for (int i = 0; i<5; i++)
170
 
        cg.setColor( effectFromItem(i), temp.active().color( effectFromItem(i) ) );
171
 
 
172
 
    editPalette.setActive( cg );
173
 
    setPreviewPalette( editPalette );
174
 
 
175
 
    updateStyledButtons();
176
 
}
177
 
 
178
 
void PaletteEditor::buildInactive()
179
 
{
180
 
    editPalette.setInactive( editPalette.active() );
181
 
    buildInactiveEffect();
182
 
}
183
 
 
184
 
void PaletteEditor::buildInactiveEffect()
185
 
{
186
 
    QColorGroup cg = editPalette.inactive();
187
 
 
188
 
    QColor light, midlight, mid, dark, shadow;
189
 
    QColor btn = cg.color( QColorGroup::Button );
190
 
 
191
 
    light = btn.light(150);
192
 
    midlight = btn.light(115);
193
 
    mid = btn.dark(150);
194
 
    dark = btn.dark();
195
 
    shadow = black;
196
 
 
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 );
202
 
 
203
 
    editPalette.setInactive( cg );
204
 
    setPreviewPalette( editPalette );
205
 
    updateStyledButtons();
206
 
}
207
 
 
208
 
void PaletteEditor::buildDisabled()
209
 
{
210
 
    QColorGroup cg = editPalette.active();
211
 
    cg.setColor( QColorGroup::ButtonText, darkGray );
212
 
    cg.setColor( QColorGroup::Foreground, darkGray );
213
 
    editPalette.setDisabled( cg );
214
 
 
215
 
    buildDisabledEffect();
216
 
}
217
 
 
218
 
void PaletteEditor::buildDisabledEffect()
219
 
{
220
 
    QColorGroup cg = editPalette.disabled();
221
 
 
222
 
    QColor light, midlight, mid, dark, shadow;
223
 
    QColor btn = cg.color( QColorGroup::Button );
224
 
 
225
 
    light = btn.light(150);
226
 
    midlight = btn.light(115);
227
 
    mid = btn.dark(150);
228
 
    dark = btn.dark();
229
 
    shadow = black;
230
 
 
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 );
236
 
 
237
 
    editPalette.setDisabled( cg );
238
 
    setPreviewPalette( editPalette );
239
 
    updateStyledButtons();
240
 
}
241
 
 
242
 
void PaletteEditor::setPreviewPalette( const QPalette& pal )
243
 
{
244
 
    QColorGroup cg;
245
 
 
246
 
    switch (paletteCombo->currentItem()) {
247
 
    case 0:
248
 
    default:
249
 
        cg = pal.active();
250
 
        break;
251
 
    case 1:
252
 
        cg = pal.inactive();
253
 
        break;
254
 
    case 2:
255
 
        cg = pal.disabled();
256
 
        break;
257
 
    }
258
 
    previewPalette.setActive( cg );
259
 
    previewPalette.setInactive( cg );
260
 
    previewPalette.setDisabled( cg );
261
 
 
262
 
    previewFrame->setPreviewPalette(previewPalette);
263
 
}
264
 
 
265
 
void PaletteEditor::updateStyledButtons()
266
 
{
267
 
    buttonMainColor->setColor( editPalette.active().color( QColorGroup::Button ));
268
 
    buttonMainColor2->setColor( editPalette.active().color( QColorGroup::Background ));
269
 
}
270
 
 
271
 
void PaletteEditor::setPal( const QPalette& pal )
272
 
{
273
 
    editPalette = pal;
274
 
    setPreviewPalette( pal );
275
 
    updateStyledButtons();
276
 
}
277
 
 
278
 
QPalette PaletteEditor::pal() const
279
 
{
280
 
    return editPalette;
281
 
}
282
 
 
283
 
QPalette PaletteEditor::getPalette( bool *ok, const QPalette &init, BackgroundMode mode,
284
 
                                    QWidget* parent, const char* name, FormWindow *fw )
285
 
{
286
 
    PaletteEditor* dlg = new PaletteEditor( fw, parent, name, TRUE );
287
 
    dlg->setupBackgroundMode( mode );
288
 
 
289
 
    if ( init != QPalette() )
290
 
        dlg->setPal( init );
291
 
    int resultCode = dlg->exec();
292
 
 
293
 
    QPalette result = init;
294
 
    if ( resultCode == QDialog::Accepted ) {
295
 
        if ( ok )
296
 
            *ok = TRUE;
297
 
        result = dlg->pal();
298
 
    } else {
299
 
        if ( ok )
300
 
            *ok = FALSE;
301
 
    }
302
 
    delete dlg;
303
 
    return result;
304
 
}