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>
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.
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.
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.
21
#include "previewwidget.h"
23
#include <KGlobalSettings>
24
#include <KColorScheme>
26
PreviewWidget::PreviewWidget(QWidget *parent) : QFrame(parent)
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);
52
QList<QWidget*> widgets = findChildren<QWidget*>();
53
foreach (QWidget* widget, widgets)
55
widget->installEventFilter(this);
56
widget->setFocusPolicy(Qt::NoFocus);
60
PreviewWidget::~PreviewWidget()
64
bool PreviewWidget::eventFilter(QObject *, QEvent *ev)
68
case QEvent::MouseButtonPress:
69
case QEvent::MouseButtonRelease:
70
case QEvent::MouseButtonDblClick:
71
case QEvent::MouseMove:
72
case QEvent::KeyPress:
73
case QEvent::KeyRelease:
77
case QEvent::ContextMenu:
78
return true; // ignore
85
inline void copyPaletteBrush(QPalette &palette, QPalette::ColorGroup state,
86
QPalette::ColorRole role)
88
palette.setBrush(QPalette::Active, role, palette.brush(state, role));
91
void PreviewWidget::setPaletteRecursive(QWidget *widget,
92
const QPalette &palette)
94
widget->setPalette(palette);
96
const QObjectList children = widget->children();
97
foreach (QObject *child, children) {
98
if (child->isWidgetType())
99
setPaletteRecursive((QWidget*)child, palette);
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)
109
QPalette palette = widget->palette();
110
KColorScheme::adjustForeground(palette, role, color, set, config);
111
copyPaletteBrush(palette, state, color);
112
widget->setPalette(palette);
115
void PreviewWidget::setPalette(const KSharedConfigPtr &config,
116
QPalette::ColorGroup state)
118
QPalette palette = KGlobalSettings::createApplicationPalette(config);
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);
139
setPaletteRecursive(this, palette);
141
#define ADJUST_WIDGET_FOREGROUND(w,c,s,r) \
142
adjustWidgetForeground(w, state, config, QPalette::c, KColorScheme::s, KColorScheme::r);
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);
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);
161
#include "previewwidget.moc"