~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to kcontrol/colors/previewwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-11 14:04:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071011140448-v0eb7lxbb24zagca
Tags: 3.94.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Preview widget for KDE Display color scheme setup module
 
2
 * Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
 
3
 * eventFilter code Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; see the file COPYING.  If not, write to
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#include "previewwidget.h"
 
22
 
 
23
#include <KGlobalSettings>
 
24
#include <KColorScheme>
 
25
 
 
26
PreviewWidget::PreviewWidget(QWidget *parent) : QFrame(parent)
 
27
{
 
28
    setupUi(this);
 
29
 
 
30
    // set correct colors on... lots of things
 
31
    setAutoFillBackground(true);
 
32
    frame->setBackgroundRole(QPalette::Base);
 
33
    viewWidget->setBackgroundRole(QPalette::Base);
 
34
    labelView0->setBackgroundRole(QPalette::Base);
 
35
    labelView3->setBackgroundRole(QPalette::Base);
 
36
    labelView4->setBackgroundRole(QPalette::Base);
 
37
    labelView2->setBackgroundRole(QPalette::Base);
 
38
    labelView1->setBackgroundRole(QPalette::Base);
 
39
    labelView5->setBackgroundRole(QPalette::Base);
 
40
    labelView6->setBackgroundRole(QPalette::Base);
 
41
    labelView7->setBackgroundRole(QPalette::Base);
 
42
    selectionWidget->setBackgroundRole(QPalette::Highlight);
 
43
    labelSelection0->setBackgroundRole(QPalette::Highlight);
 
44
    labelSelection3->setBackgroundRole(QPalette::Highlight);
 
45
    labelSelection4->setBackgroundRole(QPalette::Highlight);
 
46
    labelSelection2->setBackgroundRole(QPalette::Highlight);
 
47
    labelSelection1->setBackgroundRole(QPalette::Highlight);
 
48
    labelSelection5->setBackgroundRole(QPalette::Highlight);
 
49
    labelSelection6->setBackgroundRole(QPalette::Highlight);
 
50
    labelSelection7->setBackgroundRole(QPalette::Highlight);
 
51
 
 
52
    QList<QWidget*> widgets = findChildren<QWidget*>();
 
53
    foreach (QWidget* widget, widgets)
 
54
    {
 
55
        widget->installEventFilter(this);
 
56
        widget->setFocusPolicy(Qt::NoFocus);
 
57
    }
 
58
}
 
59
 
 
60
PreviewWidget::~PreviewWidget()
 
61
{
 
62
}
 
63
 
 
64
bool PreviewWidget::eventFilter(QObject *, QEvent *ev)
 
65
{
 
66
    switch (ev->type())
 
67
    {
 
68
        case QEvent::MouseButtonPress:
 
69
        case QEvent::MouseButtonRelease:
 
70
        case QEvent::MouseButtonDblClick:
 
71
        case QEvent::MouseMove:
 
72
        case QEvent::KeyPress:
 
73
        case QEvent::KeyRelease:
 
74
        case QEvent::Enter:
 
75
        case QEvent::Leave:
 
76
        case QEvent::Wheel:
 
77
        case QEvent::ContextMenu:
 
78
            return true; // ignore
 
79
        default:
 
80
            break;
 
81
    }
 
82
    return false;
 
83
}
 
84
 
 
85
inline void copyPaletteBrush(QPalette &palette, QPalette::ColorGroup state,
 
86
                             QPalette::ColorRole role)
 
87
{
 
88
    palette.setBrush(QPalette::Active, role, palette.brush(state, role));
 
89
}
 
90
 
 
91
void PreviewWidget::setPaletteRecursive(QWidget *widget,
 
92
                                        const QPalette &palette)
 
93
{
 
94
    widget->setPalette(palette);
 
95
 
 
96
    const QObjectList children = widget->children();
 
97
    foreach (QObject *child, children) {
 
98
        if (child->isWidgetType())
 
99
            setPaletteRecursive((QWidget*)child, palette);
 
100
    }
 
101
}
 
102
 
 
103
inline void adjustWidgetForeground(QWidget *widget, QPalette::ColorGroup state,
 
104
                                   const KSharedConfigPtr &config,
 
105
                                   QPalette::ColorRole color,
 
106
                                   KColorScheme::ColorSet set,
 
107
                                   KColorScheme::ForegroundRole role)
 
108
{
 
109
    QPalette palette = widget->palette();
 
110
    KColorScheme::adjustForeground(palette, role, color, set, config);
 
111
    copyPaletteBrush(palette, state, color);
 
112
    widget->setPalette(palette);
 
113
}
 
114
 
 
115
void PreviewWidget::setPalette(const KSharedConfigPtr &config,
 
116
                               QPalette::ColorGroup state)
 
117
{
 
118
    QPalette palette = KGlobalSettings::createApplicationPalette(config);
 
119
 
 
120
    if (state != QPalette::Active) {
 
121
        copyPaletteBrush(palette, state, QPalette::Base);
 
122
        copyPaletteBrush(palette, state, QPalette::Text);
 
123
        copyPaletteBrush(palette, state, QPalette::Window);
 
124
        copyPaletteBrush(palette, state, QPalette::WindowText);
 
125
        copyPaletteBrush(palette, state, QPalette::Button);
 
126
        copyPaletteBrush(palette, state, QPalette::ButtonText);
 
127
        copyPaletteBrush(palette, state, QPalette::Highlight);
 
128
        copyPaletteBrush(palette, state, QPalette::HighlightedText);
 
129
        copyPaletteBrush(palette, state, QPalette::AlternateBase);
 
130
        copyPaletteBrush(palette, state, QPalette::Link);
 
131
        copyPaletteBrush(palette, state, QPalette::LinkVisited);
 
132
        copyPaletteBrush(palette, state, QPalette::Light);
 
133
        copyPaletteBrush(palette, state, QPalette::Midlight);
 
134
        copyPaletteBrush(palette, state, QPalette::Mid);
 
135
        copyPaletteBrush(palette, state, QPalette::Dark);
 
136
        copyPaletteBrush(palette, state, QPalette::Shadow);
 
137
    }
 
138
 
 
139
    setPaletteRecursive(this, palette);
 
140
 
 
141
#define ADJUST_WIDGET_FOREGROUND(w,c,s,r) \
 
142
    adjustWidgetForeground(w, state, config, QPalette::c, KColorScheme::s, KColorScheme::r);
 
143
 
 
144
    ADJUST_WIDGET_FOREGROUND(labelView1, Text, View, InactiveText);
 
145
    ADJUST_WIDGET_FOREGROUND(labelView2, Text, View, ActiveText);
 
146
    ADJUST_WIDGET_FOREGROUND(labelView3, Text, View, LinkText);
 
147
    ADJUST_WIDGET_FOREGROUND(labelView4, Text, View, VisitedText);
 
148
    ADJUST_WIDGET_FOREGROUND(labelView5, Text, View, NegativeText);
 
149
    ADJUST_WIDGET_FOREGROUND(labelView6, Text, View, NeutralText);
 
150
    ADJUST_WIDGET_FOREGROUND(labelView7, Text, View, PositiveText);
 
151
 
 
152
    ADJUST_WIDGET_FOREGROUND(labelSelection1, HighlightedText, Selection, InactiveText);
 
153
    ADJUST_WIDGET_FOREGROUND(labelSelection2, HighlightedText, Selection, ActiveText);
 
154
    ADJUST_WIDGET_FOREGROUND(labelSelection3, HighlightedText, Selection, LinkText);
 
155
    ADJUST_WIDGET_FOREGROUND(labelSelection4, HighlightedText, Selection, VisitedText);
 
156
    ADJUST_WIDGET_FOREGROUND(labelSelection5, HighlightedText, Selection, NegativeText);
 
157
    ADJUST_WIDGET_FOREGROUND(labelSelection6, HighlightedText, Selection, NeutralText);
 
158
    ADJUST_WIDGET_FOREGROUND(labelSelection7, HighlightedText, Selection, PositiveText);
 
159
}
 
160
 
 
161
#include "previewwidget.moc"