add more spacing
[personal-kdebase.git] / workspace / kcontrol / colors / previewwidget.cpp
blob63ed7bb1d995797fb4600f8dcd959c20ed5080a1
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)
28 setupUi(this);
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)
66 switch (ev->type())
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;
82 return false;
85 inline void copyPaletteBrush(QPalette &palette, QPalette::ColorGroup state,
86 QPalette::ColorRole role)
88 palette.setBrush(QPalette::Active, role, palette.brush(state, role));
89 if (state == QPalette::Disabled)
90 // ### hack, while Qt has no inactive+disabled state
91 // TODO copy from Inactive+Disabled to Inactive instead
92 palette.setBrush(QPalette::Inactive, role,
93 palette.brush(QPalette::Disabled, role));
96 void PreviewWidget::setPaletteRecursive(QWidget *widget,
97 const QPalette &palette)
99 widget->setPalette(palette);
101 const QObjectList children = widget->children();
102 foreach (QObject *child, children) {
103 if (child->isWidgetType())
104 setPaletteRecursive((QWidget*)child, palette);
108 inline void adjustWidgetForeground(QWidget *widget, QPalette::ColorGroup state,
109 const KSharedConfigPtr &config,
110 QPalette::ColorRole color,
111 KColorScheme::ColorSet set,
112 KColorScheme::ForegroundRole role)
114 QPalette palette = widget->palette();
115 KColorScheme::adjustForeground(palette, role, color, set, config);
116 copyPaletteBrush(palette, state, color);
117 widget->setPalette(palette);
120 void PreviewWidget::setPalette(const KSharedConfigPtr &config,
121 QPalette::ColorGroup state)
123 QPalette palette = KGlobalSettings::createApplicationPalette(config);
125 if (state != QPalette::Active) {
126 copyPaletteBrush(palette, state, QPalette::Base);
127 copyPaletteBrush(palette, state, QPalette::Text);
128 copyPaletteBrush(palette, state, QPalette::Window);
129 copyPaletteBrush(palette, state, QPalette::WindowText);
130 copyPaletteBrush(palette, state, QPalette::Button);
131 copyPaletteBrush(palette, state, QPalette::ButtonText);
132 copyPaletteBrush(palette, state, QPalette::Highlight);
133 copyPaletteBrush(palette, state, QPalette::HighlightedText);
134 copyPaletteBrush(palette, state, QPalette::AlternateBase);
135 copyPaletteBrush(palette, state, QPalette::Link);
136 copyPaletteBrush(palette, state, QPalette::LinkVisited);
137 copyPaletteBrush(palette, state, QPalette::Light);
138 copyPaletteBrush(palette, state, QPalette::Midlight);
139 copyPaletteBrush(palette, state, QPalette::Mid);
140 copyPaletteBrush(palette, state, QPalette::Dark);
141 copyPaletteBrush(palette, state, QPalette::Shadow);
144 setPaletteRecursive(this, palette);
146 #define ADJUST_WIDGET_FOREGROUND(w,c,s,r) \
147 adjustWidgetForeground(w, state, config, QPalette::c, KColorScheme::s, KColorScheme::r);
149 ADJUST_WIDGET_FOREGROUND(labelView1, Text, View, InactiveText);
150 ADJUST_WIDGET_FOREGROUND(labelView2, Text, View, ActiveText);
151 ADJUST_WIDGET_FOREGROUND(labelView3, Text, View, LinkText);
152 ADJUST_WIDGET_FOREGROUND(labelView4, Text, View, VisitedText);
153 ADJUST_WIDGET_FOREGROUND(labelView5, Text, View, NegativeText);
154 ADJUST_WIDGET_FOREGROUND(labelView6, Text, View, NeutralText);
155 ADJUST_WIDGET_FOREGROUND(labelView7, Text, View, PositiveText);
157 ADJUST_WIDGET_FOREGROUND(labelSelection1, HighlightedText, Selection, InactiveText);
158 ADJUST_WIDGET_FOREGROUND(labelSelection2, HighlightedText, Selection, ActiveText);
159 ADJUST_WIDGET_FOREGROUND(labelSelection3, HighlightedText, Selection, LinkText);
160 ADJUST_WIDGET_FOREGROUND(labelSelection4, HighlightedText, Selection, VisitedText);
161 ADJUST_WIDGET_FOREGROUND(labelSelection5, HighlightedText, Selection, NegativeText);
162 ADJUST_WIDGET_FOREGROUND(labelSelection6, HighlightedText, Selection, NeutralText);
163 ADJUST_WIDGET_FOREGROUND(labelSelection7, HighlightedText, Selection, PositiveText);
166 #include "previewwidget.moc"