FEATURE: allow themes to state that they should use the native widgets

svn path=/trunk/KDE/kdelibs/; revision=931193
This commit is contained in:
Aaron J. Seigo 2009-02-24 22:42:06 +00:00
parent 01e4d0916a
commit a88f2d8247
6 changed files with 52 additions and 21 deletions

View File

@ -29,6 +29,7 @@
#include <kdebug.h>
#include <plasma/framesvg.h>
#include <plasma/theme.h>
namespace Plasma {
@ -104,6 +105,11 @@ void Style::drawComplexControl(ComplexControl control,
QPainter *painter,
const QWidget *widget) const
{
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
qApp->style()->drawComplexControl(control, option, painter, widget);
return;
}
switch (control) {
case CC_ScrollBar: {
d->createScrollbar();
@ -251,7 +257,10 @@ void Style::drawComplexControl(ComplexControl control,
void Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
Q_UNUSED(widget)
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
qApp->style()->drawPrimitive(element, option, painter, widget);
return;
}
switch (element) {
case PE_PanelLineEdit:
@ -271,6 +280,10 @@ void Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
int Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
{
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
return qApp->style()->pixelMetric(metric, option, widget);
}
switch (metric) {
case PM_ScrollBarExtent: {
d->createScrollbar();

View File

@ -65,7 +65,8 @@ public:
compositingActive(KWindowSystem::compositingActive()),
isDefault(false),
useGlobal(true),
hasWallpapers(false)
hasWallpapers(false),
useNativeWidgetStyle(false)
{
generalFont = QApplication::font();
cacheTheme = cacheConfig().readEntry("CacheTheme", true);
@ -138,6 +139,7 @@ public:
bool useGlobal : 1;
bool hasWallpapers : 1;
bool cacheTheme : 1;
bool useNativeWidgetStyle :1;
};
PackageStructure::Ptr ThemePrivate::packageStructure(0);
@ -362,6 +364,9 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
defaultWallpaperWidth = cg.readEntry("defaultWidth", DEFAULT_WALLPAPER_WIDTH);
defaultWallpaperHeight = cg.readEntry("defaultHeight", DEFAULT_WALLPAPER_HEIGHT);
cg = KConfigGroup(&metadata, "Settings");
useNativeWidgetStyle = cg.readEntry("UseNativeWidgetStyle", false);
QObject::disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
q, SLOT(colorsChanged()));
@ -584,6 +589,11 @@ bool Theme::useGlobalSettings() const
return d->useGlobal;
}
bool Theme::useNativeWidgetStyle() const
{
return d->useNativeWidgetStyle;
}
bool Theme::findInCache(const QString &key, QPixmap &pix)
{
return d->useCache() && d->pixmapCache->find(key, pix);

View File

@ -179,6 +179,12 @@ class PLASMA_EXPORT Theme : public QObject
*/
bool useGlobalSettings() const;
/**
* @return true if the native widget styles should be used instead of themed
* widgets. Defaults is false.
*/
bool useNativeWidgetStyle() const;
/**
* Tries to load pixmap with the specified key from cache.
* @return true when pixmap was found and loaded from cache, false otherwise

View File

@ -60,7 +60,7 @@ public:
bool fadeIn;
qreal opacity;
QRectF activeRect;
Plasma::Style::Ptr style;
Style::Ptr style;
};
void ComboBoxPrivate::syncActiveRect()
@ -100,7 +100,7 @@ void ComboBoxPrivate::syncBorders()
p.setColor(QPalette::Normal, QPalette::Text, color);
p.setColor(QPalette::Inactive, QPalette::Text, color);
native->setPalette(p);
native->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
native->setFont(Theme::defaultTheme()->font(Theme::DefaultFont));
}
void ComboBoxPrivate::animationUpdate(qreal progress)
@ -132,15 +132,15 @@ ComboBox::ComboBox(QGraphicsWidget *parent)
d->syncBorders();
setAcceptHoverEvents(true);
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders()));
d->style = Plasma::Style::sharedStyle();
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncBorders()));
d->style = Style::sharedStyle();
native->setStyle(d->style.data());
}
ComboBox::~ComboBox()
{
delete d;
Plasma::Style::doneWithSharedStyle();
Style::doneWithSharedStyle();
}
QString ComboBox::text() const
@ -196,7 +196,9 @@ void ComboBox::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
if (!styleSheet().isNull() || nativeWidget()->isEditable()) {
if (!styleSheet().isNull() ||
nativeWidget()->isEditable() ||
Theme::defaultTheme()->useNativeWidgetStyle()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}
@ -243,14 +245,14 @@ void ComboBox::paint(QPainter *painter,
d->background->paintFrame(painter);
}
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::ButtonTextColor));
painter->setPen(Theme::defaultTheme()->color(Theme::ButtonTextColor));
QStyleOptionComboBox comboOpt;
comboOpt.initFrom(nativeWidget());
comboOpt.palette.setColor(
QPalette::ButtonText, Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor));
QPalette::ButtonText, Theme::defaultTheme()->color(Theme::ButtonTextColor));
comboOpt.currentIcon = nativeWidget()->itemIcon(
nativeWidget()->currentIndex());
comboOpt.currentText = nativeWidget()->itemText(
@ -270,11 +272,11 @@ void ComboBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
const int FadeInDuration = 75;
if (d->animId != -1) {
Plasma::Animator::self()->stopCustomAnimation(d->animId);
Animator::self()->stopCustomAnimation(d->animId);
}
d->animId = Plasma::Animator::self()->customAnimation(
d->animId = Animator::self()->customAnimation(
40 / (1000 / FadeInDuration), FadeInDuration,
Plasma::Animator::LinearCurve, this, "animationUpdate");
Animator::LinearCurve, this, "animationUpdate");
d->background->setElementPrefix("active");
@ -286,13 +288,13 @@ void ComboBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
const int FadeOutDuration = 150;
if (d->animId != -1) {
Plasma::Animator::self()->stopCustomAnimation(d->animId != -1);
Animator::self()->stopCustomAnimation(d->animId != -1);
}
d->fadeIn = false;
d->animId = Plasma::Animator::self()->customAnimation(
d->animId = Animator::self()->customAnimation(
40 / (1000 / FadeOutDuration),
FadeOutDuration, Plasma::Animator::LinearCurve, this, "animationUpdate");
FadeOutDuration, Animator::LinearCurve, this, "animationUpdate");
d->background->setElementPrefix("active");

View File

@ -247,7 +247,7 @@ void PushButton::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
if (!styleSheet().isNull()) {
if (!styleSheet().isNull() || Theme::defaultTheme()->useNativeWidgetStyle()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}

View File

@ -74,10 +74,10 @@ Slider::~Slider()
}
void Slider::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
if (!styleSheet().isNull()) {
if (!styleSheet().isNull() || Theme::defaultTheme()->useNativeWidgetStyle()) {
QGraphicsProxyWidget::paint(painter, option, widget);
return;
}
@ -112,7 +112,7 @@ void Slider::paint(QPainter *painter,
d->background->resizeFrame(backgroundRect.size());
d->background->paintFrame(painter, backgroundRect.topLeft());
//Thickmarks
//Tickmarks
if (sliderOpt.tickPosition != QSlider::NoTicks) {
sliderOpt.subControls = QStyle::SC_SliderTickmarks;
sliderOpt.palette.setColor(