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 <kdebug.h>
#include <plasma/framesvg.h> #include <plasma/framesvg.h>
#include <plasma/theme.h>
namespace Plasma { namespace Plasma {
@ -104,6 +105,11 @@ void Style::drawComplexControl(ComplexControl control,
QPainter *painter, QPainter *painter,
const QWidget *widget) const const QWidget *widget) const
{ {
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
qApp->style()->drawComplexControl(control, option, painter, widget);
return;
}
switch (control) { switch (control) {
case CC_ScrollBar: { case CC_ScrollBar: {
d->createScrollbar(); 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 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) { switch (element) {
case PE_PanelLineEdit: 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 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) { switch (metric) {
case PM_ScrollBarExtent: { case PM_ScrollBarExtent: {
d->createScrollbar(); d->createScrollbar();

View File

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

View File

@ -179,6 +179,12 @@ class PLASMA_EXPORT Theme : public QObject
*/ */
bool useGlobalSettings() const; 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. * Tries to load pixmap with the specified key from cache.
* @return true when pixmap was found and loaded from cache, false otherwise * @return true when pixmap was found and loaded from cache, false otherwise

View File

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

View File

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

View File

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