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 "setpreviewwidget.h"
23 #include <KGlobalSettings>
24 #include <KColorUtils>
26 void setAutoFill(QWidget
* widget
)
28 widget
->setAutoFillBackground(true);
29 widget
->setBackgroundRole(QPalette::Base
);
32 SetPreviewWidget::SetPreviewWidget(QWidget
*parent
) : QFrame(parent
)
36 // set correct colors on... lots of things
37 setAutoFillBackground(true);
38 setBackgroundRole(QPalette::Base
);
39 setAutoFill(widgetBack0
);
40 setAutoFill(widgetBack1
);
41 setAutoFill(widgetBack2
);
42 setAutoFill(widgetBack3
);
43 setAutoFill(widgetBack4
);
44 setAutoFill(widgetBack5
);
45 setAutoFill(widgetBack6
);
46 setAutoFill(widgetBack7
);
47 setAutoFill(widgetBack8
);
48 setAutoFill(widgetBack9
);
49 setAutoFillBackground(true);
51 frame->setBackgroundRole(QPalette::Base);
52 viewWidget->setBackgroundRole(QPalette::Base);
53 labelView0->setBackgroundRole(QPalette::Base);
54 labelView3->setBackgroundRole(QPalette::Base);
55 labelView4->setBackgroundRole(QPalette::Base);
56 labelView2->setBackgroundRole(QPalette::Base);
57 labelView1->setBackgroundRole(QPalette::Base);
58 labelView5->setBackgroundRole(QPalette::Base);
59 labelView6->setBackgroundRole(QPalette::Base);
60 labelView7->setBackgroundRole(QPalette::Base);
61 selectionWidget->setBackgroundRole(QPalette::Highlight);
62 labelSelection0->setBackgroundRole(QPalette::Highlight);
63 labelSelection3->setBackgroundRole(QPalette::Highlight);
64 labelSelection4->setBackgroundRole(QPalette::Highlight);
65 labelSelection2->setBackgroundRole(QPalette::Highlight);
66 labelSelection1->setBackgroundRole(QPalette::Highlight);
67 labelSelection5->setBackgroundRole(QPalette::Highlight);
68 labelSelection6->setBackgroundRole(QPalette::Highlight);
69 labelSelection7->setBackgroundRole(QPalette::Highlight);
72 QList
<QWidget
*> widgets
= findChildren
<QWidget
*>();
73 foreach (QWidget
* widget
, widgets
)
75 widget
->installEventFilter(this);
76 widget
->setFocusPolicy(Qt::NoFocus
);
80 SetPreviewWidget::~SetPreviewWidget()
84 bool SetPreviewWidget::eventFilter(QObject
*, QEvent
*ev
)
88 case QEvent::MouseButtonPress
:
89 case QEvent::MouseButtonRelease
:
90 case QEvent::MouseButtonDblClick
:
91 case QEvent::MouseMove
:
92 case QEvent::KeyPress
:
93 case QEvent::KeyRelease
:
97 case QEvent::ContextMenu
:
98 return true; // ignore
105 void SetPreviewWidget::setPalette(const KSharedConfigPtr
&config
,
106 KColorScheme::ColorSet set
)
108 QPalette palette
= KGlobalSettings::createApplicationPalette(config
);
109 KColorScheme::adjustBackground(palette
, KColorScheme::NormalBackground
,
110 QPalette::Base
, set
, config
);
111 QFrame::setPalette(palette
);
113 #define SET_ROLE_PALETTE(n, f, b) \
114 KColorScheme::adjustForeground(palette, KColorScheme::f, QPalette::Text, set, config); \
115 labelFore##n->setPalette(palette); \
116 KColorScheme::adjustBackground(palette, KColorScheme::b, QPalette::Base, set, config); \
117 labelBack##n->setPalette(palette); \
118 widgetBack##n->setPalette(palette);
120 SET_ROLE_PALETTE(0, NormalText
, NormalBackground
);
121 SET_ROLE_PALETTE(1, InactiveText
, AlternateBackground
);
122 SET_ROLE_PALETTE(2, ActiveText
, ActiveBackground
);
123 SET_ROLE_PALETTE(3, LinkText
, LinkBackground
);
124 SET_ROLE_PALETTE(4, VisitedText
, VisitedBackground
);
125 SET_ROLE_PALETTE(5, NegativeText
, NegativeBackground
);
126 SET_ROLE_PALETTE(6, NeutralText
, NeutralBackground
);
127 SET_ROLE_PALETTE(7, PositiveText
, PositiveBackground
);
129 KColorScheme
kcs(QPalette::Active
, set
, config
);
132 #define SET_DECO_PALETTE(n, d) \
133 deco = kcs.decoration(KColorScheme::d); \
134 palette.setBrush(QPalette::Text, deco); \
135 labelFore##n->setPalette(palette); \
136 deco = KColorUtils::tint(kcs.background().color(), deco.color()); \
137 palette.setBrush(QPalette::Base, deco); \
138 labelBack##n->setPalette(palette); \
139 widgetBack##n->setPalette(palette);
141 SET_DECO_PALETTE(8, HoverColor
);
142 SET_DECO_PALETTE(9, FocusColor
);
145 #include "setpreviewwidget.moc"