2010-10-22 02:25:17 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright 2009 by Aaron Seigo <aseigo@kde.org> *
|
|
|
|
* *
|
|
|
|
* This library is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Library General Public *
|
|
|
|
* License as published by the Free Software Foundation; either *
|
|
|
|
* version 2 of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This library is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
|
|
* Library General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Library General Public License *
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to *
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
|
|
|
* Boston, MA 02110-1301, USA. *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2010-10-22 14:29:35 +02:00
|
|
|
#ifndef THEMEDWIDGETINTERFACE_P_H
|
|
|
|
#define THEMEDWIDGETINTERFACE_P_H
|
2010-10-22 02:25:17 +02:00
|
|
|
|
|
|
|
#include "kglobalsettings.h"
|
2010-10-22 12:59:45 +02:00
|
|
|
#include <QApplication>
|
2010-10-22 02:25:17 +02:00
|
|
|
|
|
|
|
#include "theme.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class ThemedWidgetInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ThemedWidgetInterface(T *publicClass)
|
|
|
|
: q(publicClass),
|
|
|
|
customPalette(false),
|
2010-10-29 19:25:00 +02:00
|
|
|
customFont(false),
|
|
|
|
buttonColorForText(false)
|
2010-10-22 02:25:17 +02:00
|
|
|
{
|
|
|
|
QObject::connect(Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(setPalette()));
|
|
|
|
QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), q, SLOT(setPalette()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void initTheming()
|
|
|
|
{
|
|
|
|
customPalette = false;
|
|
|
|
customFont = false;
|
|
|
|
setPalette();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPalette()
|
|
|
|
{
|
|
|
|
if (!customPalette) {
|
|
|
|
QColor color = Theme::defaultTheme()->color(Theme::TextColor);
|
|
|
|
QPalette p = q->palette();
|
|
|
|
p.setColor(QPalette::Normal, QPalette::WindowText, color);
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
|
|
|
|
|
|
|
|
p.setColor(QPalette::Normal, QPalette::Link, Theme::defaultTheme()->color(Theme::LinkColor));
|
|
|
|
p.setColor(QPalette::Normal, QPalette::LinkVisited, Theme::defaultTheme()->color(Theme::VisitedLinkColor));
|
|
|
|
|
2010-10-29 19:25:00 +02:00
|
|
|
|
|
|
|
qreal alpha = color.alpha();
|
|
|
|
color.setAlphaF(0.6);
|
|
|
|
p.setColor(QPalette::Disabled, QPalette::WindowText, color);
|
|
|
|
color.setAlphaF(alpha);
|
|
|
|
|
|
|
|
const QColor buttonColor = Theme::defaultTheme()->color(Theme::ButtonTextColor);
|
|
|
|
p.setColor(QPalette::Normal, QPalette::Text, buttonColorForText ? buttonColor : color);
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::Text, buttonColorForText ? buttonColor : color);
|
|
|
|
|
|
|
|
p.setColor(QPalette::Normal, QPalette::ButtonText, buttonColor);
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::ButtonText, buttonColor);
|
2010-10-22 02:25:17 +02:00
|
|
|
|
|
|
|
//FIXME: hardcoded colors .. looks incorrect
|
|
|
|
p.setColor(QPalette::Normal, QPalette::Base, QColor(0,0,0,0));
|
|
|
|
p.setColor(QPalette::Inactive, QPalette::Base, QColor(0,0,0,0));
|
|
|
|
|
|
|
|
q->setPalette(p);
|
|
|
|
customPalette = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!customFont) {
|
|
|
|
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
|
|
|
|
customFont = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::FontChange:
|
|
|
|
customFont = q->font() != QApplication::font();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::PaletteChange:
|
2010-10-25 22:02:13 +02:00
|
|
|
customPalette = true;
|
2010-10-22 02:25:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void event(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Show) {
|
|
|
|
customFont = q->font() != QApplication::font();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
T *q;
|
|
|
|
bool customPalette : 1;
|
|
|
|
bool customFont : 1;
|
2010-10-29 19:25:00 +02:00
|
|
|
bool buttonColorForText : 1;
|
2010-10-22 02:25:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
#endif
|
|
|
|
|