* loading and saving of applets; allows one to define which config file,

which keeps us on the path to being able to snapshot and share layouts
* extend addApplet with optional params for applet id and starting geometry

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=696631
This commit is contained in:
Aaron J. Seigo 2007-08-05 13:03:54 +00:00
parent d10dba893e
commit b41bd5f532
2 changed files with 73 additions and 12 deletions

View File

@ -71,10 +71,11 @@ public:
QString mimetype;
};
Corona::Corona(QObject * parent)
Corona::Corona(QObject *parent)
: QGraphicsScene(parent),
d(new Private)
{
loadApplets("plasma-appletsrc");
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
}
@ -82,6 +83,7 @@ Corona::Corona(const QRectF & sceneRect, QObject * parent )
: QGraphicsScene(sceneRect, parent),
d(new Private)
{
loadApplets("plasma-appletsrc");
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
}
@ -89,6 +91,7 @@ Corona::Corona(qreal x, qreal y, qreal width, qreal height, QObject * parent)
: QGraphicsScene(x, y, width, height, parent),
d(new Private)
{
loadApplets("plasma-appletsrc");
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
}
@ -169,9 +172,38 @@ QString Corona::appletMimeType()
return d->mimetype;
}
Applet* Corona::addApplet(const QString& name, const QStringList& args)
void Corona::saveApplets(const QString &config) const
{
Applet* applet = Applet::loadApplet(name, 0, args);
KConfig appletConfig(config);
foreach (Applet *applet, d->applets) {
KConfigGroup cg(&appletConfig, QString::number(applet->id()));
kDebug() << "saving applet " << applet->name();
cg.writeEntry("plugin", applet->pluginName());
cg.writeEntry("geometry", QRect(applet->pos().toPoint(), applet->boundingRect().size().toSize()));
}
}
void Corona::saveApplets() const
{
saveApplets("plasma-appletsrc");
}
void Corona::loadApplets(const QString& config)
{
qDeleteAll(d->applets);
d->applets.clear();
KConfig appletConfig(config, KConfig::OnlyLocal);
foreach (const QString& group, appletConfig.groupList()) {
KConfigGroup cg(&appletConfig, group);
addApplet(cg.readEntry("plugin", QString()), QStringList(),
group.toUInt(), cg.readEntry("geometry", QRectF()));
}
}
Applet* Corona::addApplet(const QString& name, const QStringList& args, uint id, const QRectF& geometry)
{
Applet* applet = Applet::loadApplet(name, id, args);
if (!applet) {
kDebug() << "Applet " << name << " could not be loaded.";
applet = new Applet;
@ -180,9 +212,13 @@ Applet* Corona::addApplet(const QString& name, const QStringList& args)
qreal appWidth = applet->boundingRect().width();
qreal appHeight = applet->boundingRect().height();
//TODO: Make sure new applets don't overlap with existing ones
// Center exactly:
applet->setPos((width() / 2) - (appWidth / 2),(height() / 2) - (appHeight / 2));
if (geometry.isValid()) {
applet->setGeometry(geometry);
} else {
//TODO: Make sure new applets don't overlap with existing ones
// Center exactly:
applet->setPos((width() / 2) - (appWidth / 2),(height() / 2) - (appHeight / 2));
}
addItem(applet);
applet->updateConstraints();

View File

@ -68,15 +68,34 @@ public:
/**
* Sets the mimetype of Drag/Drop items. Default is
* text/x-plasmoidservicename
**/
void setAppletMimeType(const QString& mimetype);
*/
void setAppletMimeType(const QString &mimetype);
/**
* The current mime type of Drag/Drop items.
**/
QString appletMimeType();
*/
QString appletMimeType();
/**
* Save applets to a config file
*
* @param config the name of the config file to save to
*/
void saveApplets(const QString &config) const;
/**
* Load applet layout from a config file
*
* @param config the name of the config file to load from
*/
void loadApplets(const QString &config);
public Q_SLOTS:
/**
* Save applets to the default config file
*/
void saveApplets() const;
/**
* Informs the Corona as to what position it is in. This is informational
* only, as the Corona doesn't change it's actual location. This is,
@ -99,8 +118,14 @@ public Q_SLOTS:
* @param name the plugin name for the applet, as given by
* KPluginInfo::pluginName()
* @param args argument list to pass to the plasmoid
* @param id to assign to this applet, or 0 to auto-assign it a new id
* @param geometry where to place the applet, or to auto-place it if an invalid
* is provided
*
* @return a pointer to the applet on success, or 0 on failure
*/
Applet* addApplet(const QString& name, const QStringList& args = QStringList());
Applet* addApplet(const QString& name, const QStringList& args = QStringList(),
uint id = 0, const QRectF &geometry = QRectF());
/**
* Adds a SuperKaramba theme to the scene