~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/components/propertyeditor/paletteeditor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the designer application of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "paletteeditor.h"
 
30
 
 
31
#include <QtCore/qdebug.h>
 
32
#include <QtGui/QMessageBox>
 
33
 
 
34
using namespace qdesigner_internal;
 
35
 
 
36
PaletteEditor::PaletteEditor(QWidget *parent)
 
37
    : QDialog(parent)
 
38
{
 
39
    ui.setupUi(this);
 
40
    ui.btnAdvanced->hide(); // ### not implemented yet
 
41
}
 
42
 
 
43
PaletteEditor::~PaletteEditor()
 
44
{
 
45
}
 
46
 
 
47
void PaletteEditor::on_btnAdvanced_clicked()
 
48
{
 
49
    QMessageBox::information(this, tr("Palette Editor..."), tr("Feature not yet implemented!"));
 
50
 
 
51
#if 0 // ###
 
52
    bool ok;
 
53
    QPalette pal = PaletteEditorAdvanced::getPalette(&ok, m_editPalette, backgroundMode, this, "tune_palette", formWindow);
 
54
    if (!ok) return;
 
55
    m_editPalette = pal;
 
56
#endif
 
57
 
 
58
    updatePreviewPalette();
 
59
}
 
60
 
 
61
void PaletteEditor::on_buttonMainColor_clicked()
 
62
{
 
63
    buildPalette();
 
64
}
 
65
 
 
66
void PaletteEditor::on_buttonMainColor2_clicked()
 
67
{
 
68
    buildPalette();
 
69
}
 
70
 
 
71
void PaletteEditor::on_paletteCombo_activated(int)
 
72
{
 
73
    updatePreviewPalette();
 
74
}
 
75
 
 
76
void PaletteEditor::buildPalette()
 
77
{
 
78
    QColor btn = ui.buttonMainColor->brush().color();
 
79
    QColor back = ui.buttonMainColor2->brush().color();
 
80
 
 
81
    setEditPalette(QPalette(btn, back));
 
82
}
 
83
 
 
84
void PaletteEditor::buildActiveEffect()
 
85
{
 
86
    QColor btn = m_editPalette.color(QPalette::Button);
 
87
 
 
88
    QPalette temp(btn, btn);
 
89
    temp.setCurrentColorGroup(QPalette::Active);
 
90
 
 
91
    m_editPalette.setCurrentColorGroup(QPalette::Active);
 
92
 
 
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());
 
98
}
 
99
 
 
100
void PaletteEditor::updatePaletteEffect(QPalette::ColorGroup g)
 
101
{
 
102
    QColor btn = m_editPalette.color(g, QPalette::Button);
 
103
 
 
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;
 
109
 
 
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);
 
115
}
 
116
 
 
117
QPalette::ColorGroup PaletteEditor::selectedColorGroup() const
 
118
{
 
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;
 
124
    }
 
125
}
 
126
 
 
127
void PaletteEditor::updatePreviewPalette()
 
128
{
 
129
    QPalette::ColorGroup g = selectedColorGroup();
 
130
 
 
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));
 
137
    }
 
138
 
 
139
    ui.previewFrame->setPreviewPalette(previewPalette);
 
140
}
 
141
 
 
142
void PaletteEditor::updateStyledButtons()
 
143
{
 
144
    ui.buttonMainColor->setBrush(m_editPalette.color(QPalette::Active, QPalette::Button));
 
145
    ui.buttonMainColor2->setBrush(m_editPalette.color(QPalette::Active, QPalette::Background));
 
146
}
 
147
 
 
148
void PaletteEditor::setEditPalette(const QPalette& pal)
 
149
{
 
150
    m_editPalette = pal;
 
151
    buildActiveEffect();
 
152
    updatePaletteEffect(QPalette::Inactive);
 
153
    updatePaletteEffect(QPalette::Disabled);
 
154
    updatePreviewPalette();
 
155
    updateStyledButtons();
 
156
}
 
157
 
 
158
QPalette PaletteEditor::editPalette() const
 
159
{
 
160
    return m_editPalette;
 
161
}
 
162
 
 
163
QPalette PaletteEditor::getPalette(QWidget* parent, const QPalette &init, int *ok)
 
164
{
 
165
    PaletteEditor dlg(parent);
 
166
    dlg.setEditPalette(init);
 
167
 
 
168
    int result = dlg.exec();
 
169
    if (ok) *ok = result;
 
170
 
 
171
    return result == QDialog::Accepted ? dlg.editPalette() : init;
 
172
}
 
173