* share the package structures by using a single shared ptr

* use the script's contentSizeHint if we are a script

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=779417
This commit is contained in:
Aaron J. Seigo 2008-02-26 04:08:51 +00:00
parent 12cea8acf1
commit bed3c1d927
4 changed files with 30 additions and 10 deletions

View File

@ -143,7 +143,7 @@ public:
QString packageFormat = appletDescription.property("X-Plasma-PackageFormat").toString();
if (packageFormat.isEmpty()) {
package = new Package(path, PlasmoidPackage());
package = new Package(path, PackageStructure::Ptr(new PlasmoidPackage()));
} else {
package = new Package(path, PackageStructure::load(packageFormat));
}
@ -288,6 +288,7 @@ public:
// number of members at this point.
static uint s_maxAppletId;
static uint s_maxZValue;
static PackageStructure::Ptr packageStructure;
uint appletId;
KPluginInfo appletDescription;
Package* package;
@ -314,6 +315,7 @@ public:
uint Applet::Private::s_maxAppletId = 0;
uint Applet::Private::s_maxZValue = 0;
PackageStructure::Ptr Applet::Private::packageStructure(0);
Applet::Applet(QGraphicsItem *parent,
const QString& serviceID,
@ -344,9 +346,13 @@ Applet::~Applet()
delete d;
}
PackageStructure Applet::packageStructure()
PackageStructure::Ptr Applet::packageStructure()
{
return PlasmoidPackage();
if (!Private::packageStructure) {
Private::packageStructure = new PlasmoidPackage();
}
return Private::packageStructure;
}
void Applet::init()
@ -1001,6 +1007,14 @@ void Applet::setContentSize(int width, int height)
QSizeF Applet::contentSizeHint() const
{
static bool checkingScript = false;
if (!checkingScript && d->script) {
checkingScript = true;
return d->script->contentSizeHint();
}
checkingScript = false;
QSizeF size;
if (layout()) {
size = layout()->sizeHint();

View File

@ -24,9 +24,9 @@
#include <QtGui/QGraphicsItem>
#include <QtGui/QWidget>
#include <kplugininfo.h>
#include <ksharedconfig.h>
#include <kgenericfactory.h>
#include <KPluginInfo>
#include <KSharedConfig>
#include <KGenericFactory>
#include <plasma/configxml.h>
#include <plasma/packagestructure.h>
@ -104,7 +104,7 @@ class PLASMA_EXPORT Applet : public Widget
/**
* @return a package structure representing a Theme
*/
static PackageStructure packageStructure();
static PackageStructure::Ptr packageStructure();
/**
* This method is called once the applet is loaded and added to a Corona.

View File

@ -60,6 +60,7 @@ public:
QString findInTheme(const QString &image, const QString &theme) const;
static const char *defaultTheme;
static PackageStructure::Ptr packageStructure;
QString themeName;
QString app;
KSharedConfigPtr colors;
@ -71,6 +72,7 @@ public:
#endif
};
PackageStructure::Ptr Theme::Private::packageStructure(0);
const char *Theme::Private::defaultTheme = "default";
class ThemeSingleton
@ -113,9 +115,13 @@ Theme::~Theme()
delete d;
}
PackageStructure Theme::packageStructure()
PackageStructure::Ptr Theme::packageStructure()
{
return ThemePackage();
if (!Private::packageStructure) {
Private::packageStructure = new ThemePackage();
}
return Private::packageStructure;
}
void Theme::setApplication(const QString &appname)

View File

@ -67,7 +67,7 @@ class PLASMA_EXPORT Theme : public QObject
/**
* @return a package structure representing a Theme
*/
static PackageStructure packageStructure();
static PackageStructure::Ptr packageStructure();
/**
* Sets the application the theme setting is associated with. This