Merge woc branch to trunk, say good bye to old plasma, there is a lot of stuff to port

applets, 
please update to another revision to use the version that works

green flag from aaron


svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=796368
This commit is contained in:
Alexis Ménard 2008-04-13 13:23:39 +00:00
parent a76cce7919
commit 4467261c95
30 changed files with 184 additions and 766 deletions

View File

@ -4,7 +4,7 @@ include (KDE4Defaults)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${KDEBASE_WORKSPACE_SOURCE_DIR}/libs ${CMAKE_CURRENT_SOURCE_DIR}/.. ${KDE4_INCLUDES} ${OPENGL_INCLUDE_DIR})
add_subdirectory(widgets)
add_subdirectory(tests)
#add_subdirectory(tests)
add_definitions(-DKDE_DEFAULT_DEBUG_AREA=1209)
########### next target ###############

View File

@ -25,10 +25,8 @@
#include <KDebug>
#include <KPluginInfo>
#include <KServiceTypeTrader>
#include <KStandardDirs>
#include <QTimer>
#include "package.h"
#include "scripting/runnerscript.h"
#include "searchcontext.h"
@ -37,31 +35,33 @@ namespace Plasma
class AbstractRunner::Private
{
public:
public:
bool hasMatchOptions;
bool hasConfig;
Priority priority;
Speed speed;
RunnerScript* script;
KPluginInfo runnerDescription;
AbstractRunner* runner;
QTime runtime;
int fastRuns;
Private(AbstractRunner* r, KService::Ptr service)
: priority(NormalPriority),
speed(NormalSpeed),
script(0),
runnerDescription(service),
runner(r),
fastRuns(0),
package(0)
fastRuns(0)
{
if (runnerDescription.isValid()) {
const QString language = runnerDescription.property("X-Plasma-Language").toString();
if (!language.isEmpty()) {
const QString path = KStandardDirs::locate("data",
"plasma/runners/" + runnerDescription.pluginName() + "/");
PackageStructure::Ptr structure = Plasma::packageStructure(language, Plasma::RunnerComponent);
structure->setPath(path);
package = new Package(path, structure);
QString language = runnerDescription.property("X-Plasma-Language").toString();
if (!language.isEmpty()) {
script = Plasma::loadScriptEngine(language, runner);
if (!script) {
kDebug() << "Could not create a" << language << "ScriptEngine for the"
<< runnerDescription.name() << "Runner.";
delete package;
package = 0;
} else {
QTimer::singleShot(0, runner, SLOT(init()));
}
@ -69,25 +69,14 @@ public:
}
}
bool hasMatchOptions;
bool hasConfig;
Priority priority;
Speed speed;
RunnerScript* script;
KPluginInfo runnerDescription;
AbstractRunner* runner;
QTime runtime;
int fastRuns;
Package *package;
static QMutex bigLock;
};
QMutex AbstractRunner::Private::bigLock;
AbstractRunner::AbstractRunner(QObject* parent, const QString& serviceId)
: QObject(parent),
d(new Private(this, KService::serviceByStorageId(serviceId)))
AbstractRunner::AbstractRunner(QObject* parent, const QString& serviceId)
: QObject(parent),
d(new Private(this, KService::serviceByStorageId(serviceId)))
{
}
@ -232,11 +221,6 @@ QString AbstractRunner::runnerName() const
return d->runnerDescription.property("X-Plasma-RunnerName").toString();
}
const Package* AbstractRunner::package() const
{
return d->package;
}
void AbstractRunner::init()
{
if (d->script) {

View File

@ -36,7 +36,6 @@ class KCompletion;
namespace Plasma
{
class Package;
class RunnerScript;
/**
@ -169,14 +168,6 @@ class PLASMA_EXPORT AbstractRunner : public QObject
*/
QString runnerName() const;
/**
* Accessor for the associated Package object if any.
* Generally, only Plasmoids come in a Package.
*
* @return the Package object, or 0 if none
**/
const Package* package() const;
protected:
/**
* Sets whether or not the the runner has options for matches

View File

@ -33,7 +33,10 @@
#include <QTextDocument>
#include <QTimer>
#include <QUiLoader>
#include <QLabel>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsLinearLayout>
#include <QGraphicsProxyWidget>
#include <KIcon>
#include <KColorScheme>
@ -103,7 +106,6 @@ public:
package(0),
needsConfigOverlay(0),
background(0),
overlay(0),
failureText(0),
script(0),
configXml(0),
@ -133,7 +135,6 @@ public:
DataEngineManager::self()->unload( engine );
}
delete background;
delete overlay;
delete package;
delete configXml;
delete shadow;
@ -217,16 +218,6 @@ public:
applet->setHasConfigurationInterface(true);
}
}
QSizeF contentSize(const Applet* q)
{
if (failureText) {
return failureText->geometry().size();
}
return q->contentSize();
}
QString instanceName()
{
if (!appletDescription.isValid()) {
@ -320,7 +311,6 @@ public:
QList<QGraphicsItem*> watchedForMouseMove;
QStringList loadedEngines;
Plasma::SvgPanel *background;
Plasma::SvgPanel *overlay;
Plasma::LineEdit *failureText;
AppletScript *script;
ConfigXml* configXml;
@ -640,26 +630,29 @@ bool Applet::drawStandardBackground() const
void Applet::setDrawStandardBackground(bool drawBackground)
{
if
(drawBackground)
{
setWindowFlags(Qt::Window);
}
else
{
setWindowFlags(0);
}
if (drawBackground) {
if (!d->background) {
d->background = new Plasma::SvgPanel("widgets/background");
if (!Plasma::Theme::self()->image("widgets/overlay").isEmpty()) {
d->overlay = new Plasma::SvgPanel("widgets/overlay");
}
int left, top, right, bottom;
d->getBorderSize(left, top, right, bottom);
setMargins(0, 0, right, bottom);
setContentsMargins(0, 0, right, bottom);
updateGeometry();
update();
}
} else if (d->background) {
delete d->background;
delete d->overlay;
d->background = 0;
d->overlay = 0;
setMargins(0, 0, 0, 0);
setContentsMargins(0, 0, 0, 0);
updateGeometry();
update();
}
@ -683,6 +676,15 @@ QString visibleFailureText(const QString& reason)
return text;
}
void Applet::paintWindowFrame ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
//Plasma::SvgPanel *background = new Plasma::SvgPanel("widgets/background");
//background->paint(painter,geometry());
setWindowFrameMargins(1,1,1,1);
painter->setPen(QPen(Qt::red));
painter->drawRoundedRect(geometry(),5,5);
}
void Applet::setFailedToLaunch(bool failed, const QString& reason)
{
if (d->failed == failed) {
@ -702,8 +704,9 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
if (failed) {
setDrawStandardBackground(true);
Layout* failureLayout = new BoxLayout(BoxLayout::TopToBottom, this);
failureLayout->setMargins(0, 0, 0, 0);
#ifdef TOPORT
Layout* failureLayout = new BoxLayout(BoxLayout::TopToBottom, this);
d->failureText = new LineEdit(this);
d->failureText->setTextInteractionFlags( Qt::TextSelectableByMouse );
d->failureText->setStyled(false);
@ -715,8 +718,18 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
Theme::self()->colors())
.brush(QPalette::Normal).color());
failureLayout->addItem(d->failureText);
setGeometry(QRectF(geometry().topLeft(), d->failureText->sizeHint()));
}
#endif
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout();
failureLayout->setContentsMargins(0, 0, 0, 0);
QGraphicsProxyWidget * failureWidget = new QGraphicsProxyWidget(this);
QLabel * label = new QLabel(visibleFailureText(reason));
label->setWordWrap(true);
failureWidget->setWidget(label);
failureLayout->addItem(failureWidget);
setLayout(failureLayout);
}
update();
}
@ -739,7 +752,7 @@ void Applet::setNeedsConfiguring(bool needsConfig)
}
d->needsConfigOverlay = new OverlayWidget(this);
d->needsConfigOverlay->resize(contentSize());
d->needsConfigOverlay->resize(boundingRect().size());
int zValue = 100;
foreach (QGraphicsItem *child, QGraphicsItem::children()) {
@ -753,7 +766,7 @@ void Applet::setNeedsConfiguring(bool needsConfig)
PushButton* button = new PushButton(d->needsConfigOverlay);
button->setText(i18n("Configure..."));
connect(button, SIGNAL(clicked()), this, SLOT(showConfigurationInterface()));
QSizeF s = button->sizeHint();
QSizeF s = button->geometry().size();
button->resize(s);
button->setPos(d->needsConfigOverlay->boundingRect().width() / 2 - s.width() / 2,
d->needsConfigOverlay->boundingRect().height() / 2 - s.height() / 2);
@ -783,7 +796,7 @@ void Applet::flushUpdatedConstraints()
d->pendingConstraints = NoConstraint;
if (c & Plasma::SizeConstraint && d->needsConfigOverlay) {
d->needsConfigOverlay->setGeometry(QRectF(QPointF(0, 0), contentSize()));
d->needsConfigOverlay->setGeometry(QRectF(QPointF(0, 0), boundingRect().size()));
// FIXME:: rather horrible hack to work around the fact we don't have spacers
// for layouts, and with WoC coming i'd rather not expend effort there
QGraphicsItem * button = d->needsConfigOverlay->QGraphicsItem::children().first();
@ -852,20 +865,6 @@ int Applet::type() const
return Type;
}
QRectF Applet::boundingRect() const
{
QRectF rect = QRectF(QPointF(0,0), d->contentSize(this));
int left;
int right;
int top;
int bottom;
d->getBorderSize(left, top, right, bottom);
//kDebug() << "Background , Border size" << d->background << left << top << right << bottom;
return rect.adjusted(-left, -top, right, bottom);
}
QPainterPath Applet::shape() const
{
if (isContainment()) {
@ -875,21 +874,6 @@ QPainterPath Applet::shape() const
return Plasma::roundedRectangle(boundingRect().adjusted(-2, -2, 2, 2), 10);
}
QSizeF Applet::sizeHint() const
{
int left = 0;
int right = 0;
int top = 0;
int bottom = 0;
d->getBorderSize(left, top, right, bottom);
QSizeF borderSize = QSizeF(left + right, top + bottom);
//kDebug() << "Applet content size hint: " << contentSizeHint() << "plus our borders" << left << right << top << bottom;
return contentSizeHint() + QSizeF(left + right, top + bottom);
}
Qt::Orientations Applet::expandingDirections() const
{
if (d->square) {
@ -975,7 +959,7 @@ void Applet::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *opti
coption.view = v;
}
paintInterface(painter, &coption, QRect(QPoint(0,0), d->contentSize(this).toSize()));
paintInterface(painter, &coption, QRect(QPoint(0,0), boundingRect().size().toSize()));
}
painter->restore();
@ -983,14 +967,7 @@ void Applet::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *opti
}
//kDebug() << "paint interface of" << (QObject*) this;
paintInterface(painter, option, QRect(QPoint(0,0), d->contentSize(this).toSize()));
}
if (d->overlay &&
formFactor() != Plasma::Vertical &&
formFactor() != Plasma::Horizontal) {
//kDebug() << "option rect is" << option->rect;
d->overlay->paint(painter, option->rect);
paintInterface(painter, option, QRect(QPoint(0,0), boundingRect().size().toSize()));
}
painter->restore();
@ -1048,124 +1025,6 @@ Location Applet::location() const
return c->location();
}
QRectF Applet::contentRect() const
{
return QRectF(QPointF(0, 0), contentSize());
}
QSizeF Applet::contentSize() const
{
int top, left, right, bottom;
d->getBorderSize(left, top, right, bottom);
// kDebug() << "Geometry size: " << geometry().size();
// kDebug() << "Borders: " << left << top << right << bottom;
return (geometry().size() - QSizeF(left + right, top + bottom)).expandedTo(QSizeF(0, 0));
}
void Applet::setContentSize(const QSizeF &size)
{
int top, left, right, bottom;
d->getBorderSize(left, top, right, bottom);
resize(size + QSizeF(left + right, top + bottom));
}
void Applet::setContentSize(int width, int height)
{
setContentSize(QSizeF(width, 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();
} else {
size = contentSize();
}
QSizeF max = maximumContentSize();
size = size.boundedTo(max);
if (d->square) {
//kDebug() << "SizeHintIn: " << (QObject*)this << size;
switch (formFactor()) {
case Plasma::Vertical:
if (size.width() > max.height()) {
size.setWidth(max.height());
}
size.setHeight(size.width());
case Plasma::Horizontal:
case Plasma::Planar:
case Plasma::MediaCenter:
if (size.height() > max.width()) {
size.setHeight(max.width());
}
size.setWidth(size.height());
default:
break;
}
//kDebug() << "SizeHintOut: " << size;
return size;
}
return size;
}
void Applet::setMinimumContentSize(const QSizeF &minSize)
{
int top, left, right, bottom;
d->getBorderSize(left, top, right, bottom);
setMinimumSize(minSize + QSizeF(left + right, top + bottom));
}
void Applet::setMinimumContentSize(int minWidth, int minHeight)
{
setMinimumContentSize(QSizeF(minWidth, minHeight));
}
QSizeF Applet::minimumContentSize() const
{
int top, left, right, bottom;
d->getBorderSize(left, top, right, bottom);
return minimumSize() - QSizeF(left + right, top + bottom);
}
void Applet::setMaximumContentSize(const QSizeF &maxSize)
{
int top, left, right, bottom;
d->getBorderSize(left, top, right, bottom);
setMaximumSize(maxSize + QSizeF(left + right, top + bottom));
}
void Applet::setMaximumContentSize(int maxWidth, int maxHeight)
{
setMaximumContentSize(QSizeF(maxWidth, maxHeight));
}
QSizeF Applet::maximumContentSize() const
{
int top, left, right, bottom;
d->getBorderSize(left, top, right, bottom);
return maximumSize() - QSizeF(left + right, top + bottom);
}
Qt::AspectRatioMode Applet::aspectRatioMode() const
{
return d->aspectRatioMode;
@ -1583,27 +1442,10 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
void Applet::setGeometry(const QRectF& geometry)
{
QSizeF s = size();
QPointF p = pos();
Widget::setGeometry(geometry);
//kDebug() << s << size();
if (s != size()) {
if (d->background) {
//kDebug() << "setting background to" << size();
d->background->resize(size());
}
if (d->overlay) {
//kDebug() << "setting overlay to" << size();
d->overlay->resize(size());
}
updateConstraints(Plasma::SizeConstraint);
emit geometryChanged();
} else if (p != pos()) {
emit geometryChanged();
}
updateConstraints(Plasma::SizeConstraint);
//FIXME see for who is connect to this???
//emit geometryChanged();
}
void Applet::raise()

102
applet.h
View File

@ -229,89 +229,7 @@ class PLASMA_EXPORT Applet : public Widget
*/
virtual Location location() const;
/**
* Returns the rect that the contents are positioned within in local coordinates
*/
QRectF contentRect() const;
/**
* Returns the area within which contents can be painted.
**/
QSizeF contentSize() const;
/**
* Sets the content size.
*
* @note Normally an applet should never
* call this directly except in the constructor to provide a default
* size
*
* @param size the new size of the contents area
*/
void setContentSize(const QSizeF &size);
/**
* Sets the content size.
*
* @note Normally an applet should never
* call this directly except in the constructor to provide a default
* size
*
* @param width the new width of the contents area
* @param height the new height of the contents area
*/
void setContentSize(int width, int height);
/**
* Returns an ideal size for the applet's content.
* Applets can re-implement this to provide a suitable size based
* on their contents.
*
* Unlike sizeHint() , contentSizeHint() does not include the
* size of any borders surrounding the content area.
*
* The default implementation returns the sizeHint() of the applet's
* layout if it has one, or a null size otherwise.
*/
virtual QSizeF contentSizeHint() const;
/**
* Sets the minimum size for the content of this applet
*/
void setMinimumContentSize(const QSizeF &minSize);
/**
* Sets the minimum size for the content of this applet
*
* @param minWidth the new minimum width of the contents area
* @param minHeight the new minimum height of the contents area
*/
void setMinimumContentSize(int minWidth, int minHeight);
/**
* Get the minimum size for the content of this applet
*/
QSizeF minimumContentSize() const;
/**
* Sets the maximum size for the content of this applet.
*/
void setMaximumContentSize(const QSizeF &maxSize);
/**
* Sets the maximum size for the content of this applet
*
* @param maxWidth the new maximum width of the contents area
* @param maxHeight the new maximum height of the contents area
*/
void setMaximumContentSize(int maxWidth, int maxHeight);
/**
* Get the maximum size for the content of this applet
*/
QSizeF maximumContentSize() const;
/**
/**
* @return the prefered aspect ratio mode for placement and resizing
*/
Qt::AspectRatioMode aspectRatioMode() const;
@ -492,6 +410,8 @@ class PLASMA_EXPORT Applet : public Widget
**/
void setDrawStandardBackground(bool drawBackground);
void paintWindowFrame ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget);
/**
* If for some reason, the applet fails to get up on its feet (the
* library couldn't be loaded, necessary hardware support wasn't found,
@ -573,14 +493,14 @@ class PLASMA_EXPORT Applet : public Widget
/**
* Sets whether or not this Applet is acting as a Containment
*/
virtual void setIsContainment(bool isContainment);
void setIsContainment(bool isContainment);
/**
* @return true if this Applet is currently being used as a Containment, false otherwise
*/
bool isContainment() const;
/**
/**
* Sets the geometry of this Plasma::Applet. Should not be used directly by
* applet subclasses.
* @param geometry the geometry to apply to this Plasma::Applet.
@ -592,11 +512,6 @@ class PLASMA_EXPORT Applet : public Widget
*/
void raise();
/**
* Reimplemented from LayoutItem
*/
QSizeF sizeHint() const;
/**
* Reimplemented from Plasma::Widget
*/
@ -608,12 +523,7 @@ class PLASMA_EXPORT Applet : public Widget
int type() const;
enum { Type = Plasma::AppletType };
/**
* Reimplemented from QGraphicsItem
**/
QRectF boundingRect() const;
/**
/**
* Reimplemented from QGraphicsItem
*/
QPainterPath shape() const;

View File

@ -63,7 +63,7 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet)
m_gradientColor = colors.background(KColorScheme::NormalBackground).color();
QTransform originalMatrix = m_applet->transform();
QRectF rect(m_applet->boundingRect());
QRectF rect(m_applet->contentsRect());
QPointF center = rect.center();
originalMatrix.translate(center.x(), center.y());
@ -440,7 +440,7 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
// If the applet doesn't have a minimum size, calculate based on a
// minimum content area size of 16x16
if (min.isEmpty()) {
min = m_applet->boundingRect().size() - m_applet->contentRect().size();
min = m_applet->boundingRect().size() - m_applet->boundingRect().size();
min += QSizeF(16, 16);
}

View File

@ -27,6 +27,8 @@
#include <QMimeData>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsLayout>
#include <QGraphicsLinearLayout>
#include <KApplication>
#include <KAuthorized>
@ -83,33 +85,6 @@ public:
return toolbox;
}
void initToolBox()
{
if (toolbox) {
return;
}
if (type == DesktopContainment) {
Plasma::Widget *addWidgetTool = q->addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets"));
connect(addWidgetTool, SIGNAL(clicked()), q, SIGNAL(showAddWidgets()));
Plasma::Widget *zoomInTool = q->addToolBoxTool("zoomIn", "zoom-in", i18n("Zoom In"));
connect(zoomInTool, SIGNAL(clicked()), q, SLOT(zoomIn()));
Plasma::Widget *zoomOutTool = q->addToolBoxTool("zoomOut", "zoom-out", i18n("Zoom Out"));
connect(zoomOutTool, SIGNAL(clicked()), q, SIGNAL(zoomOut()));
if (!q->isKioskImmutable()) {
Plasma::Widget *lockTool = q->addToolBoxTool("lockWidgets", "object-locked",
q->isImmutable() ? i18n("Unlock Widgets") :
i18n("Lock Widgets"));
connect(lockTool, SIGNAL(clicked()), q, SLOT(toggleDesktopImmutability()));
}
} else if (type == PanelContainment) {
createToolbox();
}
}
void positionToolbox()
{
QRectF r;
@ -147,10 +122,8 @@ void Containment::Private::setLockToolText()
QSizeF iconSize = icon->sizeFromIconSize(22);
icon->setMinimumSize(iconSize);
icon->setMaximumSize(iconSize);
icon->resize(icon->sizeHint());
icon->resize(icon->size());
}
toolbox->enableTool("addwidgets", !q->isImmutable());
}
}
@ -269,6 +242,7 @@ void Containment::containmentConstraintsUpdated(Plasma::Constraints constraints)
if (constraints & Plasma::ScreenConstraint && d->toolbox) {
d->toolbox->setPos(geometry().width() - d->toolbox->boundingRect().width(), 0);
d->toolbox->enableTool("addwidgets", !isImmutable());
}
if (constraints & Plasma::SizeConstraint) {
@ -292,26 +266,30 @@ void Containment::setContainmentType(Containment::Type type)
{
d->type = type;
// reset the toolbox!
delete d->toolbox;
d->toolbox = 0;
if (isContainment() && type == DesktopContainment) {
if (!d->toolbox) {
Plasma::Widget *addWidgetTool = addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets"));
connect(addWidgetTool, SIGNAL(clicked()), this, SIGNAL(showAddWidgets()));
if (isContainment()) {
d->initToolBox();
Plasma::Widget *zoomInTool = addToolBoxTool("zoomIn", "zoom-in", i18n("Zoom In"));
connect(zoomInTool, SIGNAL(clicked()), this, SLOT(zoomIn()));
Plasma::Widget *zoomOutTool = addToolBoxTool("zoomOut", "zoom-out", i18n("Zoom Out"));
connect(zoomOutTool, SIGNAL(clicked()), this, SIGNAL(zoomOut()));
if (!isKioskImmutable()) {
Plasma::Widget *lockTool = addToolBoxTool("lockWidgets", "object-locked",
isImmutable() ? i18n("Unlock Widgets") :
i18n("Lock Widgets"));
connect(lockTool, SIGNAL(clicked()), this, SLOT(toggleDesktopImmutability()));
}
}
} else {
delete d->toolbox;
d->toolbox = 0;
}
}
void Containment::setIsContainment(bool isContainment)
{
Applet::setIsContainment(isContainment);
// reset the toolbox!
delete d->toolbox;
d->toolbox = 0;
d->initToolBox();
}
Corona* Containment::corona() const
{
return dynamic_cast<Corona*>(scene());
@ -460,14 +438,15 @@ void Containment::setFormFactor(FormFactor formFactor)
positionPanel(true);
}
Layout *lay = layout();
if (lay) {
QGraphicsLayout *lay = layout();
QGraphicsLinearLayout * linearLay = dynamic_cast<QGraphicsLinearLayout *>(lay);
if (linearLay) {
foreach (Applet* applet, d->applets) {
lay->addItem(applet);
linearLay->addItem(applet);
applet->updateConstraints(Plasma::FormFactorConstraint);
}
//linearLay->addStretch();
}
updateConstraints(Plasma::FormFactorConstraint);
}
@ -478,23 +457,27 @@ void Containment::createLayout(FormFactor formFactor)
switch (formFactor) {
case Planar:
case MediaCenter:
new FreeLayout(this);
//setLayout(new QGraphicsLinearLayout());
break;
case Horizontal: {
BoxLayout *lay = new BoxLayout(BoxLayout::LeftToRight, this);
lay->setMargins(0, 0, 0, 0);
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout();
lay->setOrientation(Qt::Horizontal);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(4);
setLayout(lay);
break;
}
case Vertical: {
BoxLayout *lay = new BoxLayout(BoxLayout::TopToBottom, this);
lay->setMargins(0, 0, 0, 0);
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout();
lay->setOrientation(Qt::Vertical);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(4);
setLayout(lay);
break;
}
default:
kDebug() << "This can't be happening! Or... can it? ;)" << d->formFactor;
setLayout(0); //auto-delete
//setLayout(0); //auto-delete
break;
}
}
@ -595,19 +578,23 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui
if (containmentType() != PanelContainment) {
//kDebug() << "adding applet" << applet->name() << "with a default geometry of" << appletGeometry << appletGeometry.isValid();
if (appletGeometry.isValid()) {
applet->setGeometry(appletGeometry);
//applet->setGeometry(appletGeometry);
} else if (appletGeometry.x() != -1 && appletGeometry.y() != -1) {
// yes, this means we can't have items start -1, -1
applet->setGeometry(QRectF(appletGeometry.topLeft(),
applet->sizeHint()));
//applet->setGeometry(QRectF(appletGeometry.topLeft(),
// applet->sizeHint()));
} else if (geometry().isValid()) {
applet->setGeometry(geometryForApplet(applet));
//applet->setGeometry(geometryForApplet(applet));
}
}
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
connect(applet, SIGNAL(configNeedsSaving()), this, SIGNAL(configNeedsSaving()));
Corona *c = corona();
if (c) {
connect(applet, SIGNAL(configNeedsSaving()), corona(), SLOT(scheduleConfigSync()));
}
emit appletAdded(applet);
return applet;
}
@ -637,7 +624,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
// Calculate where the user wants the applet to go before adding it
//so long as this isn't a new applet with a delayed init
if (! delayInit || (currentContainment && currentContainment != this)) {
index = indexAt(pos);
index = indexAt(pos);
}
}
@ -660,13 +647,14 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
connect(applet, SIGNAL(destroyed(QObject*)),
this, SLOT(appletDestroyed(QObject*)));
Layout *lay = layout();
QGraphicsLayout *lay = layout();
// Reposition the applet after adding has been done
//FIXME adding position incorrect
if (index != -1) {
BoxLayout *l = dynamic_cast<BoxLayout *>(lay);
QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(lay);
if (l) {
l->insertItem(index, l->takeAt(l->indexOf(applet)));
l->insertItem(index, applet);
d->applets.removeAll(applet);
d->applets.insert(index, applet);
} else {
@ -679,21 +667,24 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
applet->setPos(pos);
}
if (lay) {
lay->addItem(applet);
QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(lay);
if (l) {
l->addItem(applet);
}
//l->addStretch();
}
prepareApplet(applet, delayInit); //must at least flush constraints
}
//containment-relative pos... right?
int Containment::indexAt(const QPointF &pos) const
{
if (pos == QPointF(-1, -1)) {
/* if (pos == QPointF(-1, -1)) {
return -1;
}
BoxLayout *l = dynamic_cast<BoxLayout *>(layout());
QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(layout());
if (l) {
foreach (Applet *existingApplet, d->applets) {
if (formFactor() == Horizontal) {
@ -718,7 +709,7 @@ int Containment::indexAt(const QPointF &pos) const
}
}
}
}
}*/
return -1;
}
@ -740,44 +731,6 @@ void Containment::prepareApplet(Applet *applet, bool delayInit)
}
}
QRectF Containment::geometryForApplet(Applet *applet) const
{
// The value part of these maps isn't used. Only sorted keys are needed.
QMap<qreal, bool> xPositions;
QMap<qreal, bool> yPositions;
// Add the top-left corner offset by the applet's border
QPointF offset = applet->boundingRect().topLeft();
xPositions[-offset.x()] = true;
yPositions[-offset.y()] = true;
QRectF placement(QPointF(0, 0), applet->sizeHint());
foreach (Applet *existingApplet, d->applets) {
QPointF bottomRight = existingApplet->geometry().bottomRight();
if (bottomRight.x() + placement.width() < geometry().width()) {
xPositions[bottomRight.x() + 1] = true;
}
if (bottomRight.y() + placement.height() < geometry().height()) {
yPositions[bottomRight.y() + 1] = true;
}
}
// Try to fit it in an empty space
foreach (qreal x, xPositions.keys()) {
foreach (qreal y, yPositions.keys()) {
placement.moveTo(x, y);
if (regionIsEmpty(placement, applet)) {
return placement;
}
}
}
// Otherwise place it in the centre of the screen
placement.moveLeft(geometry().width() / 2 - placement.width() / 2);
placement.moveTop(geometry().height() / 2 - placement.height() / 2);
return placement;
}
bool Containment::regionIsEmpty(const QRectF &region, Applet *ignoredApplet) const
{
foreach (Applet *applet, d->applets) {
@ -1272,7 +1225,7 @@ Plasma::Widget * Containment::addToolBoxTool(const QString& toolName, const QStr
QSizeF iconSize = tool->sizeFromIconSize(22);
tool->setMinimumSize(iconSize);
tool->setMaximumSize(iconSize);
tool->resize(tool->sizeHint());
tool->resize(tool->size());
d->createToolbox()->addTool(tool, toolName);

View File

@ -142,11 +142,6 @@ class PLASMA_EXPORT Containment : public Applet
*/
void setContainmentType(Containment::Type type);
/**
* Reimplemented from Applet
*/
void setIsContainment(bool isContainment);
/**
* Returns the Corona (if any) that this Containment is hosted by
*/
@ -228,7 +223,7 @@ class PLASMA_EXPORT Containment : public Applet
*/
void addApplet(Applet *applet, const QPointF &pos = QPointF(-1, -1), bool dontInit = true);
/**
/**
* @return the index to insert an applet at if you want it near the point pos.
* @param pos the containment-relative position
*/
@ -423,7 +418,6 @@ class PLASMA_EXPORT Containment : public Applet
void repositionToolbox();
private:
QRectF geometryForApplet(Applet *applet) const;
bool regionIsEmpty(const QRectF &region, Applet *ignoredApplet=0) const;
void prepareApplet(Applet *applet, bool delayInit);
void positionPanel(bool force = false);

View File

@ -362,11 +362,14 @@ Containment* Corona::addContainment(const QString& name, const QVariantList& arg
}
d->containments.append(containment);
connect(containment, SIGNAL(destroyed(QObject*)), SLOT(containmentDestroyed(QObject*)));
connect(containment, SIGNAL(launchActivated()), SIGNAL(launchActivated()));
connect(containment, SIGNAL(configNeedsSaving()), SLOT(scheduleConfigSync()));
connect(containment, SIGNAL(destroyed(QObject*)),
this, SLOT(containmentDestroyed(QObject*)));
connect(containment, SIGNAL(launchActivated()),
SIGNAL(launchActivated()));
connect(containment, SIGNAL(configNeedsSaving()),
SLOT(scheduleConfigSync()));
connect(containment, SIGNAL(screenChanged(int,int,Plasma::Containment*)),
SIGNAL(screenOwnerChanged(int,int,Plasma::Containment*)));
this, SIGNAL(screenOwnerChanged(int,int,Plasma::Containment*)));
if (!delayedInit) {
emit containmentAdded(containment);

View File

@ -186,7 +186,7 @@ void GLApplet::paintInterface(QPainter *painter,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix m = painter->worldMatrix();
QRect deviceRect = m.mapRect(QRect(QPoint(23, 25), contentSize().toSize()));
QRect deviceRect = m.mapRect(QRect(QPoint(23, 25), boundingRect().size().toSize()));
d->updateGlSize(deviceRect.size());
// redirect this widget's painting into the pbuffer

View File

@ -489,14 +489,6 @@ QPixmap Phase::animationResult(AnimId id)
return state->pixmap;
}
bool Phase::isAnimating() const
{
return (!d->animatedItems.isEmpty() ||
!d->movingItems.isEmpty() ||
!d->animatedElements.isEmpty() ||
!d->customAnims.isEmpty());
}
void Phase::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event)

View File

@ -116,12 +116,6 @@ public:
Q_INVOKABLE void setAnimationPixmap(AnimId id, const QPixmap &pixmap);
Q_INVOKABLE QPixmap animationResult(AnimId id);
/**
* @return true if there are animations happening
* @since 4.1
*/
Q_INVOKABLE bool isAnimating() const;
Q_SIGNALS:
void animationComplete(QGraphicsItem *item, Plasma::Phase::Animation anim);
void movementComplete(QGraphicsItem *item);

View File

@ -63,13 +63,13 @@ void AppletScript::paintInterface(QPainter* painter, const QStyleOptionGraphicsI
QSizeF AppletScript::contentSizeHint() const
{
return applet()->contentSizeHint();
return applet()->boundingRect().size();
}
QSizeF AppletScript::size() const
{
if (applet()) {
return applet()->contentSize();
return applet()->boundingRect().size();
}
return QSizeF();

View File

@ -17,10 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "plasma/scripting/runnerscript.h"
#include "runnerscript.h"
#include "plasma/abstractrunner.h"
#include "plasma/package.h"
#include "abstractrunner.h"
namespace Plasma
{
@ -63,20 +62,6 @@ void RunnerScript::exec(const Plasma::SearchContext *search, const Plasma::Searc
Q_UNUSED(action)
}
const Package* RunnerScript::package() const
{
return 0;
}
QString RunnerScript::mainScript() const
{
if (!package()) {
return QString();
} else {
return package()->filePath("mainscript");
}
}
} // Plasma namespace
#include "runnerscript.moc"

View File

@ -70,19 +70,6 @@ public:
*/
virtual void exec(const Plasma::SearchContext *search, const Plasma::SearchMatch *action);
protected Q_SLOTS:
/**
* @return absolute path to the main script file for this plasmoid
*/
QString mainScript() const;
/**
* @return the Package associated with this plasmoid which can
* be used to request resources, such as images and
* interface files.
*/
const Package* package() const;
private:
class Private;
Private * const d;

View File

@ -51,16 +51,6 @@ bool ScriptEngine::init()
return true;
}
const Package* ScriptEngine::package() const
{
return 0;
}
QString ScriptEngine::mainScript() const
{
return QString();
}
QStringList knownLanguages(ComponentTypes types)
{
QString constraintTemplate = "'%1' in [X-Plasma-ComponentTypes]";

View File

@ -70,21 +70,8 @@ public:
*/
virtual bool init();
protected Q_SLOTS:
/**
* @return absolute path to the main script file for this plasmoid
*/
virtual QString mainScript() const;
/**
* @return the Package associated with this plasmoid which can
* be used to request resources, such as images and
* interface files.
*/
virtual const Package* package() const;
private:
class Private;
class Private;
Private * const d;
};

View File

@ -134,7 +134,7 @@ void SearchMatch::setEnabled( bool enabled )
bool SearchMatch::isEnabled() const
{
return d->enabled;
return d->enabled;
}
bool SearchMatch::operator<(const SearchMatch& other) const

View File

@ -93,8 +93,7 @@ class PLASMA_EXPORT Theme : public QObject
*
* @arg name the name of the file in the theme directory (without the
* ".svg" part or a leading slash)
* @return the full path to the requested file for the current theme,
* or an empty string if the image is not available
* @return the full path to the requested file for the current theme
*/
Q_INVOKABLE QString image( const QString& name ) const;

View File

@ -44,8 +44,7 @@ public:
};
UiLoader::UiLoader( QObject *parent )
: QObject(parent),
d(new Private())
: d( new Private() )
{
d->widgets
<< "CheckBox"

View File

@ -157,7 +157,7 @@ void View::setContainment(Containment *containment)
}
d->containment = containment;
if (!containment) {
if (! containment) {
return;
}
@ -172,7 +172,7 @@ void View::setContainment(Containment *containment)
}
updateSceneRect();
connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
//connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
}
Containment* View::containment() const

View File

@ -1 +1 @@
add_subdirectory( tests )
#add_subdirectory( tests )

View File

@ -72,13 +72,14 @@ qreal Label::heightForWidth(qreal w) const
//return m.boundingRect(QRectF(0, 0, w, 9999), d->alignment | Qt::TextWordWrap, d->text).height();
return 0;
}
#ifdef REMOVE
QSizeF Label::sizeHint() const
{
QFontMetricsF m(d->textFont);
return m.boundingRect(QRectF(0,0,9999,9999), d->alignment | Qt::TextWordWrap, d->text).size();
//return m.boundingRect(QRectF(0, 0, d->maximumWidth, 9999), d->alignment | Qt::TextWordWrap, d->text).size();
}
#endif
void Label::setText(const QString& text)
{

View File

@ -72,11 +72,12 @@ class PLASMA_EXPORT Label : public Plasma::Widget
*/
qreal heightForWidth(qreal w) const;
/**
#ifdef REMOVE
/**
* Reimplemented from Plasma::Widget.
*/
QSizeF sizeHint() const;
#endif
/**
* Sets the text to be displayed.
*/

View File

@ -46,9 +46,9 @@ class LineEdit::Private
QString defaultText;
QString oldText;
bool showingDefaultText : 1;
bool styled : 1;
bool multiline : 1;
bool showingDefaultText;
bool styled;
bool multiline;
};

View File

@ -292,7 +292,7 @@ Qt::Orientations PushButton::expandingDirections() const
{
return Qt::Horizontal;
}
#ifdef REMOVE
QSizeF PushButton::sizeHint() const
{
int width = 0;
@ -315,6 +315,7 @@ QSizeF PushButton::sizeHint() const
return QSizeF((QApplication::style()->sizeFromContents(QStyle::CT_PushButton, &option, QSize(width, height), 0).
expandedTo(QApplication::globalStrut())));
}
#endif
} // namespace Plasma

View File

@ -163,7 +163,9 @@ public:
// NOTE: bogus
QSizeF minimumSize() const;
Qt::Orientations expandingDirections() const;
#ifdef REMOVE
QSizeF sizeHint() const;
#endif
Q_SIGNALS:
/**

View File

@ -76,7 +76,7 @@ QSizeF WebContent::sizeHint() const
return d->page->mainFrame()->contentsSize();
}
return Widget::sizeHint();
return Widget::size();
}
void WebContent::setPage(QWebPage *page)

View File

@ -33,6 +33,8 @@
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QDesktopWidget>
#include <QGraphicsLayout>
#include <QGraphicsLinearLayout>
#include <KDebug>
@ -122,8 +124,7 @@ bool Widget::Private::shouldPaint(QPainter *painter, const QTransform &transform
}
Widget::Widget(QGraphicsItem *parent, QObject* parentObject)
: QObject(parentObject),
QGraphicsItem(parent),
: QGraphicsWidget(parent),
d(new Private)
{
setFlag(QGraphicsItem::ItemClipsToShape, true);
@ -166,7 +167,7 @@ Widget::CachePaintMode Widget::cachePaintMode() const
void Widget::update(const QRectF &rect)
{
QGraphicsItem::update(rect);
QGraphicsWidget::update(rect);
}
Qt::Orientations Widget::expandingDirections() const
@ -174,32 +175,9 @@ Qt::Orientations Widget::expandingDirections() const
return Qt::Horizontal | Qt::Vertical;
}
void Widget::setMinimumSize(const QSizeF& newMin)
QFont Widget::font() const
{
d->minimumSize = newMin;
QSizeF s = size();
if (s != s.expandedTo(newMin)) {
setGeometry(QRectF(pos(), s.expandedTo(newMin)));
}
}
QSizeF Widget::minimumSize() const
{
return d->minimumSize;
}
void Widget::setMaximumSize(const QSizeF& newMax)
{
d->maximumSize = newMax;
QSizeF s = size();
if (s != s.boundedTo(newMax)) {
setGeometry(QRectF(pos(), s.boundedTo(newMax)));
}
}
QSizeF Widget::maximumSize() const
{
return d->maximumSize;
return QApplication::font();
}
bool Widget::hasHeightForWidth() const
@ -233,87 +211,7 @@ QRectF Widget::geometry() const
void Widget::setSize(const QSizeF &s)
{
LayoutItem::setSize(s);
}
void Widget::setGeometry(const QRectF& geometry)
{
setPos(geometry.topLeft());
if (geometry.size().width() > 0 && geometry.size().height() > 0 && size() != geometry.size()) {
prepareGeometryChange();
qreal width = qBound(d->minimumSize.width(), geometry.size().width(), d->maximumSize.width());
qreal height = qBound(d->minimumSize.height(), geometry.size().height(), d->maximumSize.height());
setSize(QSizeF(width, height));
qreal xd = topLeft().x();
qreal yd = topLeft().y();
if (xd < 0) {
width -= xd;
xd = 0;
}
if (yd < 0) {
height -= yd;
yd = 0;
}
if (layout()) {
QRectF r(QPointF(xd, yd), QSizeF(width, height));
r = adjustToMargins(r);
layout()->setGeometry(r);
/*if (qobject_cast<Plasma::Applet*>(this)) {
kDebug() << (QObject*)this << this->geometry() << this->topLeft()
<< "layout geometry is now" << r << margin(RightMargin);
}*/
}
if (managingLayout()) {
//kDebug() << "invalidating managing layout";
managingLayout()->invalidate();
}
}
update();
}
void Widget::updateGeometry()
{
if (managingLayout()) {
managingLayout()->invalidate();
} else {
setGeometry(QRectF(pos(), sizeHint()));
}
}
QSizeF Widget::sizeHint() const
{
if (layout()) {
return layout()->sizeHint();
} else {
return size();
}
}
QFont Widget::font() const
{
return QApplication::font();
}
QRectF Widget::boundingRect() const
{
return QRectF(QPointF(0,0), size());
}
void Widget::resize(const QSizeF& size)
{
setGeometry(QRectF(pos(), size));
}
void Widget::resize(qreal w, qreal h)
{
resize(QSizeF(w, h));
resize(s);
}
Widget *Widget::parent() const
@ -347,9 +245,9 @@ void Widget::addChild(Widget *w)
w->setParentItem(this);
//kDebug() << "Added Child Widget" << (QObject*)w << "our geom is" << geometry();
if (layout()) {
layout()->addItem(w);
QGraphicsLinearLayout * lay = dynamic_cast<QGraphicsLinearLayout *>(layout());
if (lay) {
lay->addItem(w);
}
updateGeometry();
@ -411,30 +309,6 @@ void Widget::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *opti
// Replaced by widget's own function
}
QVariant Widget::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemChildRemovedChange) {
if (layout() && !isAncestorOf(value.value<QGraphicsItem*>())) {
layout()->removeItem(dynamic_cast<Plasma::LayoutItem*>(value.value<QGraphicsItem*>()));
updateGeometry();
}
}
return QGraphicsItem::itemChange(change, value);
}
void Widget::managingLayoutChanged()
{
if (managingLayout()) {
d->wasMovable = flags() & ItemIsMovable;
if (!dynamic_cast<FreeLayout*>(managingLayout())) {
setFlag(ItemIsMovable, false);
}
} else {
setFlag(ItemIsMovable, d->wasMovable);
}
}
QPoint Widget::popupPosition(const QSize &s) const
{
QGraphicsView *v = view();

View File

@ -22,7 +22,7 @@
#ifndef WIDGET_H_
#define WIDGET_H_
#include <QtGui/QGraphicsItem>
#include <QtGui/QGraphicsWidget>
#include <QtGui/QPixmap>
#include <QtCore/QRectF>
@ -63,16 +63,11 @@ class Layout;
* To implement a Widget, just subclass Plasma::Widget and implement at minimum,
* sizeHint() and paintWidget()
*/
class PLASMA_EXPORT Widget : public QObject,
public QGraphicsItem,
public LayoutItem
class PLASMA_EXPORT Widget : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY( Qt::Orientations expandingDirections READ expandingDirections )
Q_PROPERTY( QSizeF minimumSize READ minimumSize WRITE setMinimumSize )
Q_PROPERTY( QSizeF maximumSize READ maximumSize WRITE setMaximumSize )
Q_PROPERTY( QRectF geometry READ geometry WRITE setGeometry )
Q_PROPERTY( QSizeF sizeHint READ sizeHint )
Q_PROPERTY( QSizeF size READ size WRITE resize )
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
@ -102,28 +97,6 @@ public:
*/
virtual Qt::Orientations expandingDirections() const;
/**
* Sets the minimum size of the Widget.
* @param size the size to set as the minimum size.
*/
void setMinimumSize(const QSizeF& size);
/**
* @return minimum size of the Widget.
*/
QSizeF minimumSize() const;
/**
* Sets the maximum size of the Widget.
* @param size the size to set as the maximum size.
*/
void setMaximumSize(const QSizeF& size);
/**
* @return maximum size of the Widget.
*/
QSizeF maximumSize() const;
/**
* This method is used by Plasma::Layout to determine whether this widget
* can provide a height value given a width value.
@ -159,53 +132,11 @@ public:
*/
QRectF geometry() const;
/**
* Sets the geometry of this Widget.
*/
/**
* Sets the geometry of this Plasma::Widget
* @param geometry the geometry to apply to this Plasma::Widget.
*/
virtual void setGeometry(const QRectF &geometry);
/**
* This method is used to notify any containing Plasma::Layout that it should
* reset its geometry.
*/
// NOTE: this is a completely broken concept -MB
Q_INVOKABLE void updateGeometry();
/**
* Returns the recommended size for this widget. Note that this size is not
* necessarily only the size for the widget, but might also include margins etc.
* @return recommended size for this Plasma::Widget.
*/
virtual QSizeF sizeHint() const;
/**
* @return the font currently set for this widget
**/
QFont font() const;
/**
* Reimplemented from QGraphicsItem
* @return the bounding rectangle for this Plasma::Widget
*/
virtual QRectF boundingRect() const;
/**
* Resizes this Plasma::Widget.
* @param size the new size of this Plasma::Widget.
*/
Q_INVOKABLE void resize(const QSizeF &size);
/**
* Convenience method for resizing this Plasma::Widget
* @param width the new width.
* @param height the new height.
*/
Q_INVOKABLE void resize(qreal width, qreal height);
/**
* @return this Plasma::Widget's parent, returns a null pointer if
* none exist.
@ -311,8 +242,6 @@ protected:
*/
virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void managingLayoutChanged();
virtual bool sceneEvent(QEvent *event);
private: