introduce wallpaper image rendering into libplasma so it can be shared amongst all wallpaper plugins; most of the plugins are duplicating this code which can't be good. :)
next up is to port the Image wallpaper plugin to this and make sure it all still works and then look at bringing the wallpaper listing model/view somewhere all the plugins can share it for their configuration needs svn path=/trunk/KDE/kdelibs/; revision=948064
This commit is contained in:
parent
e309bf2da3
commit
1c62ca5b79
@ -84,6 +84,7 @@ set(plasma_LIB_SRCS
|
|||||||
private/style.cpp
|
private/style.cpp
|
||||||
private/toolbox.cpp
|
private/toolbox.cpp
|
||||||
private/tooltip.cpp
|
private/tooltip.cpp
|
||||||
|
private/wallpaperrenderthread.cpp
|
||||||
private/windowpreview.cpp
|
private/windowpreview.cpp
|
||||||
querymatch.cpp
|
querymatch.cpp
|
||||||
runnercontext.cpp
|
runnercontext.cpp
|
||||||
|
@ -1,28 +1,43 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
|
* Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
|
||||||
|
* Copyright (c) 2009 Aaron Seigo <aseigo@kde.org>
|
||||||
|
*
|
||||||
|
* This program 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, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this program; if not, write to the
|
||||||
|
* Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
#include "plasma/private/wallpaperrenderthread_p.h"
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "renderthread.h"
|
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <KDebug>
|
#include <QSvgRenderer>
|
||||||
#include <KSvgRenderer>
|
|
||||||
|
|
||||||
RenderThread::RenderThread()
|
#include <kdebug.h>
|
||||||
: m_current_token(-1)
|
|
||||||
, m_size(0, 0)
|
namespace Plasma
|
||||||
|
{
|
||||||
|
|
||||||
|
WallpaperRenderThread::WallpaperRenderThread(QObject *parent)
|
||||||
|
: QThread(parent),
|
||||||
|
m_currentToken(-1)
|
||||||
{
|
{
|
||||||
m_abort = false;
|
m_abort = false;
|
||||||
m_restart = false;
|
m_restart = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderThread::~RenderThread()
|
WallpaperRenderThread::~WallpaperRenderThread()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// abort computation
|
// abort computation
|
||||||
@ -34,15 +49,16 @@ RenderThread::~RenderThread()
|
|||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderThread::setSize(const QSize& size)
|
void WallpaperRenderThread::setSize(const QSize& size)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_mutex);
|
QMutexLocker lock(&m_mutex);
|
||||||
m_size = size;
|
m_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RenderThread::render(const QString &file,
|
int WallpaperRenderThread::render(const QString &file,
|
||||||
const QColor &color,
|
const QSize &size,
|
||||||
Background::ResizeMethod method)
|
Wallpaper::ResizeMethod method,
|
||||||
|
const QColor &color)
|
||||||
{
|
{
|
||||||
int token;
|
int token;
|
||||||
{
|
{
|
||||||
@ -50,8 +66,9 @@ int RenderThread::render(const QString &file,
|
|||||||
m_file = file;
|
m_file = file;
|
||||||
m_color = color;
|
m_color = color;
|
||||||
m_method = method;
|
m_method = method;
|
||||||
|
m_size = size;
|
||||||
m_restart = true;
|
m_restart = true;
|
||||||
token = ++m_current_token;
|
token = ++m_currentToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRunning()) {
|
if (!isRunning()) {
|
||||||
@ -63,13 +80,13 @@ int RenderThread::render(const QString &file,
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderThread::run()
|
void WallpaperRenderThread::run()
|
||||||
{
|
{
|
||||||
QString file;
|
QString file;
|
||||||
QColor color;
|
QColor color;
|
||||||
QSize size;
|
QSize size;
|
||||||
qreal ratio;
|
qreal ratio;
|
||||||
Background::ResizeMethod method;
|
Wallpaper::ResizeMethod method;
|
||||||
int token;
|
int token;
|
||||||
|
|
||||||
forever {
|
forever {
|
||||||
@ -87,7 +104,7 @@ void RenderThread::run()
|
|||||||
m_restart = false;
|
m_restart = false;
|
||||||
|
|
||||||
// load all parameters in nonshared variables
|
// load all parameters in nonshared variables
|
||||||
token = m_current_token;
|
token = m_currentToken;
|
||||||
file = m_file;
|
file = m_file;
|
||||||
color = m_color;
|
color = m_color;
|
||||||
size = m_size;
|
size = m_size;
|
||||||
@ -99,7 +116,7 @@ void RenderThread::run()
|
|||||||
result.fill(color.rgba());
|
result.fill(color.rgba());
|
||||||
|
|
||||||
if (file.isEmpty() || !QFile::exists(file)) {
|
if (file.isEmpty() || !QFile::exists(file)) {
|
||||||
emit done(token, result);
|
emit done(token, result, file, size, method, color);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,11 +154,11 @@ void RenderThread::run()
|
|||||||
// set render parameters according to resize mode
|
// set render parameters according to resize mode
|
||||||
switch (method)
|
switch (method)
|
||||||
{
|
{
|
||||||
case Background::Scale:
|
case Wallpaper::ScaledResize:
|
||||||
imgSize *= ratio;
|
imgSize *= ratio;
|
||||||
scaledSize = size;
|
scaledSize = size;
|
||||||
break;
|
break;
|
||||||
case Background::Center:
|
case Wallpaper::CenteredResize:
|
||||||
scaledSize = imgSize;
|
scaledSize = imgSize;
|
||||||
pos = QPoint((size.width() - scaledSize.width()) / 2,
|
pos = QPoint((size.width() - scaledSize.width()) / 2,
|
||||||
(size.height() - scaledSize.height()) / 2);
|
(size.height() - scaledSize.height()) / 2);
|
||||||
@ -162,7 +179,7 @@ void RenderThread::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Background::Maxpect: {
|
case Wallpaper::MaxpectResize: {
|
||||||
imgSize *= ratio;
|
imgSize *= ratio;
|
||||||
float xratio = (float) size.width() / imgSize.width();
|
float xratio = (float) size.width() / imgSize.width();
|
||||||
float yratio = (float) size.height() / imgSize.height();
|
float yratio = (float) size.height() / imgSize.height();
|
||||||
@ -179,7 +196,7 @@ void RenderThread::run()
|
|||||||
(size.height() - scaledSize.height()) / 2);
|
(size.height() - scaledSize.height()) / 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Background::ScaleCrop: {
|
case Wallpaper::ScaledAndCroppedResize: {
|
||||||
imgSize *= ratio;
|
imgSize *= ratio;
|
||||||
float xratio = (float) size.width() / imgSize.width();
|
float xratio = (float) size.width() / imgSize.width();
|
||||||
float yratio = (float) size.height() / imgSize.height();
|
float yratio = (float) size.height() / imgSize.height();
|
||||||
@ -196,11 +213,11 @@ void RenderThread::run()
|
|||||||
(size.height() - scaledSize.height()) / 2);
|
(size.height() - scaledSize.height()) / 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Background::Tiled:
|
case Wallpaper::TiledResize:
|
||||||
scaledSize = imgSize;
|
scaledSize = imgSize;
|
||||||
tiled = true;
|
tiled = true;
|
||||||
break;
|
break;
|
||||||
case Background::CenterTiled:
|
case Wallpaper::CenterTiledResize:
|
||||||
scaledSize = imgSize;
|
scaledSize = imgSize;
|
||||||
pos = QPoint(
|
pos = QPoint(
|
||||||
-scaledSize.width() +
|
-scaledSize.width() +
|
||||||
@ -215,7 +232,7 @@ void RenderThread::run()
|
|||||||
kDebug() << token << scalable << scaledSize << imgSize;
|
kDebug() << token << scalable << scaledSize << imgSize;
|
||||||
if (scalable) {
|
if (scalable) {
|
||||||
// tiling is ignored for scalable wallpapers
|
// tiling is ignored for scalable wallpapers
|
||||||
KSvgRenderer svg(file);
|
QSvgRenderer svg(file);
|
||||||
if (m_restart) {
|
if (m_restart) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -244,7 +261,12 @@ void RenderThread::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// signal we're done
|
// signal we're done
|
||||||
emit done(token, result);
|
emit done(token, result, file, size, method, color);
|
||||||
endLoop: continue;
|
endLoop: continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Plasma
|
||||||
|
|
||||||
|
#include "wallpaperrenderthread_p.moc"
|
||||||
|
|
||||||
|
@ -1,36 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
|
* Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
|
||||||
|
* Copyright (c) 2009 Aaron Seigo <aseigo@kde.org>
|
||||||
|
*
|
||||||
|
* This program 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, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program 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 General Public License for more details
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this program; if not, write to the
|
||||||
|
* Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
#ifndef PLASMA_WALLPAPERRENDERTHREAD_H
|
||||||
it under the terms of the GNU General Public License as published by
|
#define PLASMA_WALLPAPERRENDERTHREAD_H
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RENDERTHREAD_H
|
|
||||||
#define RENDERTHREAD_H
|
|
||||||
|
|
||||||
#include "backgroundpackage.h"
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
|
|
||||||
class RenderThread : public QThread
|
#include "plasma/wallpaper.h"
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
RenderThread();
|
|
||||||
virtual ~RenderThread();
|
|
||||||
|
|
||||||
int render(const QString &file,
|
namespace Plasma
|
||||||
const QColor &color,
|
{
|
||||||
Background::ResizeMethod method);
|
|
||||||
|
class WallpaperRenderThread : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
WallpaperRenderThread(QObject *parent = 0);
|
||||||
|
virtual ~WallpaperRenderThread();
|
||||||
|
|
||||||
|
int render(const QString &file, const QSize &size,
|
||||||
|
Wallpaper::ResizeMethod, const QColor &color);
|
||||||
|
|
||||||
void setSize(const QSize &size);
|
void setSize(const QSize &size);
|
||||||
void setRatio(float ratio);
|
void setRatio(float ratio);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void done(int token, const QImage &pixmap,
|
||||||
|
const QString &sourceImagePath, const QSize &size,
|
||||||
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color);
|
||||||
protected:
|
protected:
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
@ -39,18 +58,16 @@ private:
|
|||||||
QWaitCondition m_condition;
|
QWaitCondition m_condition;
|
||||||
|
|
||||||
// protected by mutex
|
// protected by mutex
|
||||||
int m_current_token;
|
int m_currentToken;
|
||||||
QString m_file;
|
QString m_file;
|
||||||
QColor m_color;
|
QColor m_color;
|
||||||
QSize m_size;
|
QSize m_size;
|
||||||
float m_ratio;
|
float m_ratio;
|
||||||
Background::ResizeMethod m_method;
|
Wallpaper::ResizeMethod m_method;
|
||||||
|
|
||||||
bool m_abort;
|
bool m_abort;
|
||||||
bool m_restart;
|
bool m_restart;
|
||||||
|
|
||||||
signals:
|
|
||||||
void done(int token, const QImage &pixmap);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Plasma
|
||||||
#endif // RENDERTHREAD_H
|
#endif // RENDERTHREAD_H
|
||||||
|
101
wallpaper.cpp
101
wallpaper.cpp
@ -20,12 +20,20 @@
|
|||||||
|
|
||||||
#include "wallpaper.h"
|
#include "wallpaper.h"
|
||||||
|
|
||||||
#include <kservicetypetrader.h>
|
#include <QColor>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
#include <kglobal.h>
|
||||||
|
#include <kservicetypetrader.h>
|
||||||
|
#include <kstandarddirs.h>
|
||||||
|
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
#include "plasma/private/dataengineconsumer_p.h"
|
#include "plasma/private/dataengineconsumer_p.h"
|
||||||
|
#include "plasma/private/packages_p.h"
|
||||||
|
#include "plasma/private/wallpaperrenderthread_p.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
@ -36,23 +44,41 @@ public:
|
|||||||
WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) :
|
WallpaperPrivate(KService::Ptr service, Wallpaper *wallpaper) :
|
||||||
q(wallpaper),
|
q(wallpaper),
|
||||||
wallpaperDescription(service),
|
wallpaperDescription(service),
|
||||||
|
renderColor(0, 0, 0),
|
||||||
|
renderToken(-1),
|
||||||
|
renderResizeMethod(Wallpaper::ScaledResize),
|
||||||
|
cacheRendering(false),
|
||||||
initialized(false),
|
initialized(false),
|
||||||
needsConfig(false)
|
needsConfig(false)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
~WallpaperPrivate()
|
QString cachePath(const QString &sourceImagePath, const QSize &size,
|
||||||
{
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color) const;
|
||||||
};
|
|
||||||
|
|
||||||
|
void renderComplete(int token, const QImage &image,
|
||||||
|
const QString &sourceImagePath, const QSize &size,
|
||||||
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color);
|
||||||
|
|
||||||
|
static WallpaperRenderThread s_renderer;
|
||||||
|
static PackageStructure::Ptr packageStructure;
|
||||||
|
|
||||||
Wallpaper *q;
|
Wallpaper *q;
|
||||||
KPluginInfo wallpaperDescription;
|
KPluginInfo wallpaperDescription;
|
||||||
QRectF boundingRect;
|
QRectF boundingRect;
|
||||||
KServiceAction mode;
|
KServiceAction mode;
|
||||||
|
QColor renderColor;
|
||||||
|
int renderToken;
|
||||||
|
Wallpaper::ResizeMethod renderResizeMethod;
|
||||||
|
bool cacheRendering : 1;
|
||||||
bool initialized : 1;
|
bool initialized : 1;
|
||||||
bool needsConfig : 1;
|
bool needsConfig : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
WallpaperRenderThread WallpaperPrivate::s_renderer;
|
||||||
|
PackageStructure::Ptr WallpaperPrivate::packageStructure(0);
|
||||||
|
|
||||||
Wallpaper::Wallpaper(QObject *parentObject, const QVariantList &args)
|
Wallpaper::Wallpaper(QObject *parentObject, const QVariantList &args)
|
||||||
: d(new WallpaperPrivate(KService::serviceByStorageId(args.count() > 0 ?
|
: d(new WallpaperPrivate(KService::serviceByStorageId(args.count() > 0 ?
|
||||||
args[0].toString() : QString()), this))
|
args[0].toString() : QString()), this))
|
||||||
@ -65,6 +91,9 @@ Wallpaper::Wallpaper(QObject *parentObject, const QVariantList &args)
|
|||||||
mutableArgs.removeFirst();
|
mutableArgs.removeFirst();
|
||||||
}
|
}
|
||||||
setParent(parentObject);
|
setParent(parentObject);
|
||||||
|
|
||||||
|
connect(&WallpaperPrivate::s_renderer, SIGNAL(done(int,QImage,QString,QSize,Wallpaper::ResizeMethod,QColor)),
|
||||||
|
this, SLOT(renderComplete(int,QImage,QString,QSize,Wallpaper::ResizeMethod,QColor)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallpaper::~Wallpaper()
|
Wallpaper::~Wallpaper()
|
||||||
@ -125,6 +154,16 @@ Wallpaper *Wallpaper::load(const KPluginInfo &info, const QVariantList &args)
|
|||||||
return load(info.pluginName(), args);
|
return load(info.pluginName(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PackageStructure::Ptr Wallpaper::packageStructure()
|
||||||
|
{
|
||||||
|
if (!WallpaperPrivate::packageStructure) {
|
||||||
|
WallpaperPrivate::packageStructure = new WallpaperPackage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return WallpaperPrivate::packageStructure;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString Wallpaper::name() const
|
QString Wallpaper::name() const
|
||||||
{
|
{
|
||||||
if (!d->wallpaperDescription.isValid()) {
|
if (!d->wallpaperDescription.isValid()) {
|
||||||
@ -266,6 +305,60 @@ void Wallpaper::setConfigurationRequired(bool needsConfig, const QString &reason
|
|||||||
emit configurationRequired(needsConfig);
|
emit configurationRequired(needsConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Wallpaper::setUseDiskCache() const
|
||||||
|
{
|
||||||
|
return d->cacheRendering;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wallpaper::setUseDiskCache(bool useCache)
|
||||||
|
{
|
||||||
|
d->cacheRendering = useCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wallpaper::render(const QString &sourceImagePath, const QSize &size,
|
||||||
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color)
|
||||||
|
{
|
||||||
|
if (sourceImagePath.isEmpty() || !QFile::exists(sourceImagePath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d->cacheRendering) {
|
||||||
|
QString cache = d->cachePath(sourceImagePath, size, resizeMethod, color);
|
||||||
|
if (QFile::exists(cache)) {
|
||||||
|
kDebug() << "loading cached wallpaper from" << cache;
|
||||||
|
QImage img(cache);
|
||||||
|
emit renderComplete(img);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d->renderToken = WallpaperPrivate::s_renderer.render(sourceImagePath, size, resizeMethod, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString WallpaperPrivate::cachePath(const QString &sourceImagePath, const QSize &size,
|
||||||
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color) const
|
||||||
|
{
|
||||||
|
const QString id = QString("plasma-wallpapers/%5_%3_%4_%1x%2.png")
|
||||||
|
.arg(size.width()).arg(size.height()).arg(color.name())
|
||||||
|
.arg(resizeMethod).arg(sourceImagePath);
|
||||||
|
return KGlobal::dirs()->locateLocal("cache", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WallpaperPrivate::renderComplete(int token, const QImage &image,
|
||||||
|
const QString &sourceImagePath, const QSize &size,
|
||||||
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color)
|
||||||
|
{
|
||||||
|
if (token != renderToken) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cacheRendering) {
|
||||||
|
image.save(cachePath(sourceImagePath, size, resizeMethod, color));
|
||||||
|
}
|
||||||
|
|
||||||
|
emit q->renderComplete(image);
|
||||||
|
}
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
|
||||||
#include "wallpaper.moc"
|
#include "wallpaper.moc"
|
||||||
|
70
wallpaper.h
70
wallpaper.h
@ -24,6 +24,7 @@
|
|||||||
#include <kplugininfo.h>
|
#include <kplugininfo.h>
|
||||||
|
|
||||||
#include <plasma/plasma.h>
|
#include <plasma/plasma.h>
|
||||||
|
#include <plasma/packagestructure.h>
|
||||||
#include <plasma/version.h>
|
#include <plasma/version.h>
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
@ -61,6 +62,19 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
|||||||
Q_PROPERTY(QList<KServiceAction> listRenderingModes READ listRenderingModes)
|
Q_PROPERTY(QList<KServiceAction> listRenderingModes READ listRenderingModes)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Various resize modes supported by the built in image renderer
|
||||||
|
*/
|
||||||
|
enum ResizeMethod {
|
||||||
|
ScaledResize /**< Scales the image to fit the full area*/,
|
||||||
|
CenteredResize /**< Centers the image within the area */,
|
||||||
|
ScaledAndCroppedResize /**< Scales and crops the image, preserving the aspect ratio */,
|
||||||
|
TiledResize /**< Tiles the image to fill the area */,
|
||||||
|
CenterTiledResize /**< Tiles the image to fill the area, starting with a centered tile */,
|
||||||
|
MaxpectResize /**< Best fit resize */
|
||||||
|
};
|
||||||
|
Q_ENUMS(ResizeMethod)
|
||||||
|
|
||||||
~Wallpaper();
|
~Wallpaper();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,6 +110,11 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
|||||||
**/
|
**/
|
||||||
static Wallpaper *load(const KPluginInfo &info, const QVariantList &args = QVariantList());
|
static Wallpaper *load(const KPluginInfo &info, const QVariantList &args = QVariantList());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Package specialization for wallpapers
|
||||||
|
*/
|
||||||
|
static PackageStructure::Ptr packageStructure();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the user-visible name for the wallpaper, as specified in the
|
* Returns the user-visible name for the wallpaper, as specified in the
|
||||||
* .desktop file.
|
* .desktop file.
|
||||||
@ -230,9 +249,16 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
|||||||
/**
|
/**
|
||||||
* @return true if the wallpaper currently needs to be configured,
|
* @return true if the wallpaper currently needs to be configured,
|
||||||
* otherwise, false
|
* otherwise, false
|
||||||
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
bool configurationRequired() const;
|
bool configurationRequired() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if disk caching is turned on.
|
||||||
|
* @since 4.3
|
||||||
|
*/
|
||||||
|
bool setUseDiskCache() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* This signal indicates that wallpaper needs to be repainted.
|
* This signal indicates that wallpaper needs to be repainted.
|
||||||
@ -241,21 +267,30 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when the user wants to configure/change the wallpaper.
|
* Emitted when the user wants to configure/change the wallpaper.
|
||||||
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
void configureRequested();
|
void configureRequested();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when the state of the wallpaper requiring configuration
|
* Emitted when the state of the wallpaper requiring configuration
|
||||||
* changes.
|
* changes.
|
||||||
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
void configurationRequired(bool needsConfig);
|
void configurationRequired(bool needsConfig);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when the configuration of the wallpaper needs to be saved
|
* Emitted when the configuration of the wallpaper needs to be saved
|
||||||
* to disk.
|
* to disk.
|
||||||
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
void configNeedsSaving();
|
void configNeedsSaving();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when a wallpaper image render is completed.
|
||||||
|
* @since 4.3
|
||||||
|
*/
|
||||||
|
void renderComplete(const QImage &image);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* This constructor is to be used with the plugin loading systems
|
* This constructor is to be used with the plugin loading systems
|
||||||
@ -285,10 +320,45 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
|||||||
* @param reason a translated message for the user explaining that the
|
* @param reason a translated message for the user explaining that the
|
||||||
* applet needs configuring; this should note what needs
|
* applet needs configuring; this should note what needs
|
||||||
* to be configured
|
* to be configured
|
||||||
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
|
void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the wallpaper asyncronously with the given parameters. When the rendering is
|
||||||
|
* complete, the renderComplete signal is emitted.
|
||||||
|
*
|
||||||
|
* @param sourceImagePath the path to the image file on disk. Common image formats such as
|
||||||
|
* PNG, JPEG and SVG are supported
|
||||||
|
* @param size the size to render the image as
|
||||||
|
* @param resizeMethod the method to use when resizing the image to fit size, @see
|
||||||
|
* ResizeMethod
|
||||||
|
* @param color the color to use to pad the rendered image if it doesn't take up the
|
||||||
|
* entire size with the given ResizeMethod
|
||||||
|
* @since 4.3
|
||||||
|
*/
|
||||||
|
void render(const QString &sourceImagePath, const QSize &size,
|
||||||
|
Wallpaper::ResizeMethod resizeMethod = ScaledResize,
|
||||||
|
const QColor &color = QColor(0, 0, 0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether or not to cache on disk the results of calls to render. If the wallpaper
|
||||||
|
* changes often or is innexpensive to render, then it's probably best not to cache them.
|
||||||
|
*
|
||||||
|
* The default is not to cache.
|
||||||
|
*
|
||||||
|
* @see render
|
||||||
|
* @param useCache true to cache rendered papers on disk, false not to cache
|
||||||
|
* @since 4.3
|
||||||
|
*/
|
||||||
|
void setUseDiskCache(bool useCache);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Q_PRIVATE_SLOT(d, void renderComplete(int token, const QImage &image,
|
||||||
|
const QString &sourceImagePath, const QSize &size,
|
||||||
|
Wallpaper::ResizeMethod resizeMethod, const QColor &color))
|
||||||
|
|
||||||
|
friend class WallpaperPrivate;
|
||||||
WallpaperPrivate *const d;
|
WallpaperPrivate *const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user