Refactoring the background painting code into DefaultBackground.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=729889
This commit is contained in:
parent
733a6071a2
commit
fb1fe06b79
@ -55,8 +55,6 @@ public:
|
|||||||
: formFactor(Planar),
|
: formFactor(Planar),
|
||||||
location(Floating),
|
location(Floating),
|
||||||
layout(0),
|
layout(0),
|
||||||
background(0),
|
|
||||||
bitmapBackground(0),
|
|
||||||
screen(0),
|
screen(0),
|
||||||
immutable(false)
|
immutable(false)
|
||||||
{
|
{
|
||||||
@ -67,16 +65,12 @@ public:
|
|||||||
qDeleteAll(applets);
|
qDeleteAll(applets);
|
||||||
applets.clear();
|
applets.clear();
|
||||||
delete layout;
|
delete layout;
|
||||||
delete bitmapBackground;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FormFactor formFactor;
|
FormFactor formFactor;
|
||||||
Location location;
|
Location location;
|
||||||
Layout* layout;
|
Layout* layout;
|
||||||
Applet::List applets;
|
Applet::List applets;
|
||||||
Plasma::Svg *background;
|
|
||||||
QPixmap* bitmapBackground;
|
|
||||||
QString wallpaperPath;
|
|
||||||
QSize size;
|
QSize size;
|
||||||
int screen;
|
int screen;
|
||||||
bool immutable;
|
bool immutable;
|
||||||
@ -108,18 +102,6 @@ void Containment::init()
|
|||||||
setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
|
setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
||||||
if (type() == DesktopContainment) {
|
|
||||||
KConfigGroup config(KGlobal::config(), "General");
|
|
||||||
d->wallpaperPath = config.readEntry("wallpaper", KStandardDirs::locate("wallpaper", "plasma-default.png"));
|
|
||||||
|
|
||||||
kDebug() << "wallpaperPath is" << d->wallpaperPath << QFile::exists(d->wallpaperPath);
|
|
||||||
if (d->wallpaperPath.isEmpty() ||
|
|
||||||
!QFile::exists(d->wallpaperPath)) {
|
|
||||||
kDebug() << "SVG wallpaper!";
|
|
||||||
d->background = new Plasma::Svg("widgets/wallpaper", this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: would be nice to not do this on init, as it causes Phase to init
|
//TODO: would be nice to not do this on init, as it causes Phase to init
|
||||||
connect(Phase::self(), SIGNAL(animationComplete(QGraphicsItem*,Plasma::Phase::Animation)),
|
connect(Phase::self(), SIGNAL(animationComplete(QGraphicsItem*,Plasma::Phase::Animation)),
|
||||||
this, SLOT(appletDisappearComplete(QGraphicsItem*,Plasma::Phase::Animation)));
|
this, SLOT(appletDisappearComplete(QGraphicsItem*,Plasma::Phase::Animation)));
|
||||||
@ -150,50 +132,8 @@ void Containment::paintInterface(QPainter *painter,
|
|||||||
const QStyleOptionGraphicsItem *option,
|
const QStyleOptionGraphicsItem *option,
|
||||||
const QRect& contentsRect)
|
const QRect& contentsRect)
|
||||||
{
|
{
|
||||||
//FIXME: this should probably ALL move to the Desktop containment, save for drawing a rect
|
// If the derived class can't be bothered - just draw a plane old rectangle
|
||||||
// in case there is no other drawing going on
|
painter->drawRect(contentsRect.adjusted(1, 1, -1, -1));
|
||||||
if (type() != DesktopContainment) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//kDebug() << "paintInterface of background";
|
|
||||||
//TODO: we should have a way to do this outside of the paint event!
|
|
||||||
if (d->background) {
|
|
||||||
d->background->resize(contentsRect.size());
|
|
||||||
} else if (!d->wallpaperPath.isEmpty()) {
|
|
||||||
if (!d->bitmapBackground || !(d->bitmapBackground->size() == contentsRect.size())) {
|
|
||||||
delete d->bitmapBackground;
|
|
||||||
d->bitmapBackground = new QPixmap(d->wallpaperPath);
|
|
||||||
(*d->bitmapBackground) = d->bitmapBackground->scaled(contentsRect.size());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// got nothing to paint!
|
|
||||||
//kDebug() << "got nothing?";
|
|
||||||
painter->drawRect(contentsRect.adjusted(1, 1, -1, -1));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw the background untransformed (saves lots of per-pixel-math)
|
|
||||||
painter->save();
|
|
||||||
painter->resetTransform();
|
|
||||||
|
|
||||||
// blit the background (saves all the per-pixel-products that blending does)
|
|
||||||
painter->setCompositionMode(QPainter::CompositionMode_Source);
|
|
||||||
|
|
||||||
if (d->background) {
|
|
||||||
// Plasma::Svg doesn't support drawing only part of the image (it only
|
|
||||||
// supports drawing the whole image to a rect), so we blit to 0,0-w,h
|
|
||||||
d->background->paint(painter, contentsRect);
|
|
||||||
//kDebug() << "draw svg of background";
|
|
||||||
} else if (d->bitmapBackground) {
|
|
||||||
// for pixmaps we draw only the exposed part (untransformed since the
|
|
||||||
// bitmapBackground already has the size of the viewport)
|
|
||||||
painter->drawPixmap(option->exposedRect, *d->bitmapBackground, option->exposedRect);
|
|
||||||
//kDebug() << "draw pixmap of background";
|
|
||||||
}
|
|
||||||
|
|
||||||
// restore transformation and composition mode
|
|
||||||
painter->restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSizeF Containment::contentSizeHint() const
|
QSizeF Containment::contentSizeHint() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user