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
|
|
|
|
{
|
|
|
|
|
2011-12-04 13:55:05 +01:00
|
|
|
class PaletteHelper : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static PaletteHelper *self();
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void generatePalettes();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void palettesUpdated();
|
|
|
|
|
|
|
|
public:
|
|
|
|
QPalette palette;
|
|
|
|
QPalette buttonPalette;
|
|
|
|
|
|
|
|
private:
|
|
|
|
PaletteHelper();
|
|
|
|
static PaletteHelper *s_paletteHelper;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-10-22 02:25:17 +02:00
|
|
|
template <class T>
|
|
|
|
class ThemedWidgetInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ThemedWidgetInterface(T *publicClass)
|
|
|
|
: q(publicClass),
|
|
|
|
customPalette(false),
|
2010-10-29 19:25:00 +02:00
|
|
|
customFont(false),
|
2011-12-04 13:55:05 +01:00
|
|
|
buttonColorForText(false),
|
|
|
|
internalPaletteChange(false)
|
2010-10-22 02:25:17 +02:00
|
|
|
{
|
2011-12-04 13:55:05 +01:00
|
|
|
QObject::connect(PaletteHelper::self(), SIGNAL(palettesUpdated()), q, SLOT(setPalette()));
|
2010-10-22 02:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void initTheming()
|
|
|
|
{
|
|
|
|
customPalette = false;
|
|
|
|
customFont = false;
|
|
|
|
setPalette();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPalette()
|
|
|
|
{
|
|
|
|
if (!customPalette) {
|
2011-12-04 13:55:05 +01:00
|
|
|
internalPaletteChange = true;
|
|
|
|
q->setPalette((buttonColorForText ? PaletteHelper::self()->buttonPalette
|
|
|
|
: PaletteHelper::self()->palette));
|
|
|
|
internalPaletteChange = false;
|
2010-10-22 02:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2011-12-04 13:55:05 +01:00
|
|
|
if (!internalPaletteChange &&
|
|
|
|
q->palette() != (buttonColorForText ? PaletteHelper::self()->buttonPalette : PaletteHelper::self()->palette)) {
|
|
|
|
customPalette = true;
|
|
|
|
}
|
2010-10-22 02:25:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-04 13:55:05 +01:00
|
|
|
void setWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
internalPaletteChange = true;
|
|
|
|
q->setWidget(widget);
|
|
|
|
internalPaletteChange = false;
|
|
|
|
}
|
|
|
|
|
2010-10-22 02:25:17 +02:00
|
|
|
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;
|
2011-12-04 13:55:05 +01:00
|
|
|
bool internalPaletteChange : 1;
|
2010-10-22 02:25:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
#endif
|
|
|
|
|