* setRemainSquare(bool) to allow applets to say "yes, keep my width == height, thank you"
* use AppletScript svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=765975
This commit is contained in:
parent
0e0d1122ca
commit
f2674c9a51
64
applet.cpp
64
applet.cpp
@ -53,7 +53,7 @@
|
|||||||
#include "plasma/package.h"
|
#include "plasma/package.h"
|
||||||
#include "plasma/packages_p.h"
|
#include "plasma/packages_p.h"
|
||||||
#include "plasma/plasma.h"
|
#include "plasma/plasma.h"
|
||||||
#include "plasma/scriptengine.h"
|
#include "plasma/scripting/appletscript.h"
|
||||||
#include "plasma/shadowitem_p.h"
|
#include "plasma/shadowitem_p.h"
|
||||||
#include "plasma/svg.h"
|
#include "plasma/svg.h"
|
||||||
#include "plasma/theme.h"
|
#include "plasma/theme.h"
|
||||||
@ -77,7 +77,7 @@ public:
|
|||||||
package(0),
|
package(0),
|
||||||
background(0),
|
background(0),
|
||||||
failureText(0),
|
failureText(0),
|
||||||
scriptEngine(0),
|
script(0),
|
||||||
configXml(0),
|
configXml(0),
|
||||||
shadow(0),
|
shadow(0),
|
||||||
cachedBackground(0),
|
cachedBackground(0),
|
||||||
@ -89,7 +89,8 @@ public:
|
|||||||
hasConfigurationInterface(false),
|
hasConfigurationInterface(false),
|
||||||
failed(false),
|
failed(false),
|
||||||
needsConfig(false),
|
needsConfig(false),
|
||||||
isContainment(false)
|
isContainment(false),
|
||||||
|
square(false)
|
||||||
{
|
{
|
||||||
if (appletId == 0) {
|
if (appletId == 0) {
|
||||||
appletId = nextId();
|
appletId = nextId();
|
||||||
@ -145,8 +146,8 @@ public:
|
|||||||
// it will be parented to this applet and so will get
|
// it will be parented to this applet and so will get
|
||||||
// deleted when the applet does
|
// deleted when the applet does
|
||||||
|
|
||||||
scriptEngine = ScriptEngine::load(language, applet);
|
script = Plasma::loadScriptEngine(language, applet);
|
||||||
if (!scriptEngine) {
|
if (!script) {
|
||||||
delete package;
|
delete package;
|
||||||
package = 0;
|
package = 0;
|
||||||
applet->setFailedToLaunch(true, i18n("Could not create a %1 ScriptEngine for the %2 widget.",
|
applet->setFailedToLaunch(true, i18n("Could not create a %1 ScriptEngine for the %2 widget.",
|
||||||
@ -396,7 +397,7 @@ public:
|
|||||||
static uint s_maxAppletId;
|
static uint s_maxAppletId;
|
||||||
Plasma::Svg *background;
|
Plasma::Svg *background;
|
||||||
Plasma::LineEdit *failureText;
|
Plasma::LineEdit *failureText;
|
||||||
ScriptEngine* scriptEngine;
|
AppletScript *script;
|
||||||
ConfigXml* configXml;
|
ConfigXml* configXml;
|
||||||
ShadowItem* shadow;
|
ShadowItem* shadow;
|
||||||
QPixmap* cachedBackground;
|
QPixmap* cachedBackground;
|
||||||
@ -409,6 +410,7 @@ public:
|
|||||||
bool failed : 1;
|
bool failed : 1;
|
||||||
bool needsConfig : 1;
|
bool needsConfig : 1;
|
||||||
bool isContainment : 1;
|
bool isContainment : 1;
|
||||||
|
bool square : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint Applet::Private::s_maxAppletId = 0;
|
uint Applet::Private::s_maxAppletId = 0;
|
||||||
@ -444,6 +446,9 @@ Applet::~Applet()
|
|||||||
|
|
||||||
void Applet::init()
|
void Applet::init()
|
||||||
{
|
{
|
||||||
|
if (d->script && !d->script->init()) {
|
||||||
|
setFailedToLaunch(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint Applet::id() const
|
uint Applet::id() const
|
||||||
@ -860,6 +865,15 @@ QSizeF Applet::sizeHint() const
|
|||||||
return contentSizeHint() + QSizeF(left + right, top + bottom);
|
return contentSizeHint() + QSizeF(left + right, top + bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::Orientations Applet::expandingDirections() const
|
||||||
|
{
|
||||||
|
if (d->square) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Widget::expandingDirections();
|
||||||
|
}
|
||||||
|
|
||||||
QList<QAction*> Applet::contextActions()
|
QList<QAction*> Applet::contextActions()
|
||||||
{
|
{
|
||||||
kDebug() << "empty context actions";
|
kDebug() << "empty context actions";
|
||||||
@ -939,8 +953,8 @@ void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *o
|
|||||||
{
|
{
|
||||||
Q_UNUSED(contentsRect)
|
Q_UNUSED(contentsRect)
|
||||||
|
|
||||||
if (d->scriptEngine) {
|
if (d->script) {
|
||||||
d->scriptEngine->paintInterface(painter, option, contentsRect);
|
d->script->paintInterface(painter, option, contentsRect);
|
||||||
} else {
|
} else {
|
||||||
//kDebug() << "Applet::paintInterface() default impl";
|
//kDebug() << "Applet::paintInterface() default impl";
|
||||||
}
|
}
|
||||||
@ -1019,11 +1033,31 @@ void Applet::setContentSize(int width, int height)
|
|||||||
|
|
||||||
QSizeF Applet::contentSizeHint() const
|
QSizeF Applet::contentSizeHint() const
|
||||||
{
|
{
|
||||||
|
QSizeF size;
|
||||||
if (layout()) {
|
if (layout()) {
|
||||||
return layout()->sizeHint();
|
size = layout()->sizeHint();
|
||||||
|
} else {
|
||||||
|
size = contentSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentSize();
|
if (d->square) {
|
||||||
|
//kDebug() << "SizeHintIn: " << size;
|
||||||
|
switch (formFactor()) {
|
||||||
|
case Plasma::Vertical:
|
||||||
|
size.setHeight(size.width());
|
||||||
|
case Plasma::Horizontal:
|
||||||
|
case Plasma::Planar:
|
||||||
|
case Plasma::MediaCenter:
|
||||||
|
size.setWidth(size.height());
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//kDebug() << "SizeHintOut: " << size;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::setMinimumContentSize(const QSizeF &minSize)
|
void Applet::setMinimumContentSize(const QSizeF &minSize)
|
||||||
@ -1078,6 +1112,16 @@ void Applet::setAspectRatioMode(Qt::AspectRatioMode mode)
|
|||||||
d->aspectRatioMode = mode;
|
d->aspectRatioMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Applet::remainSquare() const
|
||||||
|
{
|
||||||
|
return d->square;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Applet::setRemainSquare(bool square)
|
||||||
|
{
|
||||||
|
d->square = square;
|
||||||
|
}
|
||||||
|
|
||||||
QString Applet::globalName() const
|
QString Applet::globalName() const
|
||||||
{
|
{
|
||||||
if (!d->appletDescription.isValid()) {
|
if (!d->appletDescription.isValid()) {
|
||||||
|
21
applet.h
21
applet.h
@ -305,10 +305,22 @@ class PLASMA_EXPORT Applet : public Widget
|
|||||||
Qt::AspectRatioMode aspectRatioMode() const;
|
Qt::AspectRatioMode aspectRatioMode() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the prefered aspect ratio mode for placement and resizing
|
* Sets the prefered aspect ratio mode for placement and resizing
|
||||||
*/
|
*/
|
||||||
void setAspectRatioMode(Qt::AspectRatioMode);
|
void setAspectRatioMode(Qt::AspectRatioMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether or not to keep this applet square.
|
||||||
|
*/
|
||||||
|
bool remainSquare() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether or not this applet should be kept square.
|
||||||
|
*
|
||||||
|
* @param square true if the applet should always be square in shape.
|
||||||
|
*/
|
||||||
|
void setRemainSquare(bool square);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all known applets.
|
* Returns a list of all known applets.
|
||||||
*
|
*
|
||||||
@ -565,7 +577,12 @@ class PLASMA_EXPORT Applet : public Widget
|
|||||||
/**
|
/**
|
||||||
* Reimplemented from LayoutItem
|
* Reimplemented from LayoutItem
|
||||||
*/
|
*/
|
||||||
virtual QSizeF sizeHint() const;
|
QSizeF sizeHint() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reimplemented from Plasma::Widget
|
||||||
|
*/
|
||||||
|
Qt::Orientations expandingDirections() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reimplemented from QGraphicsItem
|
* Reimplemented from QGraphicsItem
|
||||||
|
Loading…
x
Reference in New Issue
Block a user