plasma-framework/private/themedwidgetinterface.cpp
Aaron Seigo 27531a3173 the palette gets updated by all sorts of events on the scene now (incl. reparenting!), so make sure the palette is _really_ changing before marking it as custom
this fixes widget colours not updating with theme changes -> if, for instance, an offscreen widget is created, this results in a reparenting (to null)
and that in turn creates a palette changed event ... which was being intepretted as a custom palette being set and that would disable future updates
due to theme changes.

this also introduces a small helper which computes the palettes once for use by all widgets as a small performance improvement.

BUG:261967
2011-12-04 14:00:32 +01:00

86 lines
3.4 KiB
C++

/******************************************************************************
* Copyright 2011 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. *
*******************************************************************************/
#include "themedwidgetinterface_p.h"
#include "theme.h"
namespace Plasma
{
PaletteHelper *PaletteHelper::s_paletteHelper = 0;
PaletteHelper::PaletteHelper()
: QObject()
{
generatePalettes();
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(generatePalettes()));
connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(generatePalettes()));
}
PaletteHelper *PaletteHelper::self()
{
if (!s_paletteHelper) {
s_paletteHelper = new PaletteHelper;
}
return s_paletteHelper;
}
void PaletteHelper::generatePalettes()
{
Theme *theme = Theme::defaultTheme();
QColor color = theme->color(Theme::TextColor);
palette = qApp->palette();
palette.setColor(QPalette::Normal, QPalette::WindowText, color);
palette.setColor(QPalette::Inactive, QPalette::WindowText, color);
palette.setColor(QPalette::Normal, QPalette::Link, theme->color(Theme::LinkColor));
palette.setColor(QPalette::Normal, QPalette::LinkVisited, theme->color(Theme::VisitedLinkColor));
qreal alpha = color.alphaF();
color.setAlphaF(0.6);
palette.setColor(QPalette::Disabled, QPalette::WindowText, color);
color.setAlphaF(alpha);
palette.setColor(QPalette::Normal, QPalette::Text, color);
palette.setColor(QPalette::Inactive, QPalette::Text, color);
const QColor buttonColor = Theme::defaultTheme()->color(Theme::ButtonTextColor);
palette.setColor(QPalette::Normal, QPalette::ButtonText, buttonColor);
palette.setColor(QPalette::Inactive, QPalette::ButtonText, buttonColor);
//FIXME: hardcoded colors .. looks incorrect
palette.setColor(QPalette::Normal, QPalette::Base, QColor(0,0,0,0));
palette.setColor(QPalette::Inactive, QPalette::Base, QColor(0,0,0,0));
buttonPalette = palette;
buttonPalette.setColor(QPalette::Normal, QPalette::Text, buttonColor);
buttonPalette.setColor(QPalette::Inactive, QPalette::Text, buttonColor);
emit palettesUpdated();
}
} // namespace Plasma
#include "themedwidgetinterface_p.moc"