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}) 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(widgets)
add_subdirectory(tests) #add_subdirectory(tests)
add_definitions(-DKDE_DEFAULT_DEBUG_AREA=1209) add_definitions(-DKDE_DEFAULT_DEBUG_AREA=1209)
########### next target ############### ########### next target ###############

View File

@ -25,10 +25,8 @@
#include <KDebug> #include <KDebug>
#include <KPluginInfo> #include <KPluginInfo>
#include <KServiceTypeTrader> #include <KServiceTypeTrader>
#include <KStandardDirs>
#include <QTimer> #include <QTimer>
#include "package.h"
#include "scripting/runnerscript.h" #include "scripting/runnerscript.h"
#include "searchcontext.h" #include "searchcontext.h"
@ -37,31 +35,33 @@ namespace Plasma
class AbstractRunner::Private 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) Private(AbstractRunner* r, KService::Ptr service)
: priority(NormalPriority), : priority(NormalPriority),
speed(NormalSpeed), speed(NormalSpeed),
script(0), script(0),
runnerDescription(service), runnerDescription(service),
runner(r), runner(r),
fastRuns(0), fastRuns(0)
package(0)
{ {
if (runnerDescription.isValid()) { if (runnerDescription.isValid()) {
const QString language = runnerDescription.property("X-Plasma-Language").toString(); 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);
if (!language.isEmpty()) {
script = Plasma::loadScriptEngine(language, runner); script = Plasma::loadScriptEngine(language, runner);
if (!script) { if (!script) {
kDebug() << "Could not create a" << language << "ScriptEngine for the" kDebug() << "Could not create a" << language << "ScriptEngine for the"
<< runnerDescription.name() << "Runner."; << runnerDescription.name() << "Runner.";
delete package;
package = 0;
} else { } else {
QTimer::singleShot(0, runner, SLOT(init())); 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; static QMutex bigLock;
}; };
QMutex AbstractRunner::Private::bigLock; QMutex AbstractRunner::Private::bigLock;
AbstractRunner::AbstractRunner(QObject* parent, const QString& serviceId) AbstractRunner::AbstractRunner(QObject* parent, const QString& serviceId)
: QObject(parent), : QObject(parent),
d(new Private(this, KService::serviceByStorageId(serviceId))) d(new Private(this, KService::serviceByStorageId(serviceId)))
{ {
} }
@ -232,11 +221,6 @@ QString AbstractRunner::runnerName() const
return d->runnerDescription.property("X-Plasma-RunnerName").toString(); return d->runnerDescription.property("X-Plasma-RunnerName").toString();
} }
const Package* AbstractRunner::package() const
{
return d->package;
}
void AbstractRunner::init() void AbstractRunner::init()
{ {
if (d->script) { if (d->script) {

View File

@ -36,7 +36,6 @@ class KCompletion;
namespace Plasma namespace Plasma
{ {
class Package;
class RunnerScript; class RunnerScript;
/** /**
@ -169,14 +168,6 @@ class PLASMA_EXPORT AbstractRunner : public QObject
*/ */
QString runnerName() const; 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: protected:
/** /**
* Sets whether or not the the runner has options for matches * Sets whether or not the the runner has options for matches

View File

@ -33,7 +33,10 @@
#include <QTextDocument> #include <QTextDocument>
#include <QTimer> #include <QTimer>
#include <QUiLoader> #include <QUiLoader>
#include <QLabel>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QGraphicsLinearLayout>
#include <QGraphicsProxyWidget>
#include <KIcon> #include <KIcon>
#include <KColorScheme> #include <KColorScheme>
@ -103,7 +106,6 @@ public:
package(0), package(0),
needsConfigOverlay(0), needsConfigOverlay(0),
background(0), background(0),
overlay(0),
failureText(0), failureText(0),
script(0), script(0),
configXml(0), configXml(0),
@ -133,7 +135,6 @@ public:
DataEngineManager::self()->unload( engine ); DataEngineManager::self()->unload( engine );
} }
delete background; delete background;
delete overlay;
delete package; delete package;
delete configXml; delete configXml;
delete shadow; delete shadow;
@ -217,16 +218,6 @@ public:
applet->setHasConfigurationInterface(true); applet->setHasConfigurationInterface(true);
} }
} }
QSizeF contentSize(const Applet* q)
{
if (failureText) {
return failureText->geometry().size();
}
return q->contentSize();
}
QString instanceName() QString instanceName()
{ {
if (!appletDescription.isValid()) { if (!appletDescription.isValid()) {
@ -320,7 +311,6 @@ public:
QList<QGraphicsItem*> watchedForMouseMove; QList<QGraphicsItem*> watchedForMouseMove;
QStringList loadedEngines; QStringList loadedEngines;
Plasma::SvgPanel *background; Plasma::SvgPanel *background;
Plasma::SvgPanel *overlay;
Plasma::LineEdit *failureText; Plasma::LineEdit *failureText;
AppletScript *script; AppletScript *script;
ConfigXml* configXml; ConfigXml* configXml;
@ -640,26 +630,29 @@ bool Applet::drawStandardBackground() const
void Applet::setDrawStandardBackground(bool drawBackground) void Applet::setDrawStandardBackground(bool drawBackground)
{ {
if
(drawBackground)
{
setWindowFlags(Qt::Window);
}
else
{
setWindowFlags(0);
}
if (drawBackground) { if (drawBackground) {
if (!d->background) { if (!d->background) {
d->background = new Plasma::SvgPanel("widgets/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; int left, top, right, bottom;
d->getBorderSize(left, top, right, bottom); d->getBorderSize(left, top, right, bottom);
setMargins(0, 0, right, bottom); setContentsMargins(0, 0, right, bottom);
updateGeometry(); updateGeometry();
update(); update();
} }
} else if (d->background) { } else if (d->background) {
delete d->background; delete d->background;
delete d->overlay;
d->background = 0; d->background = 0;
d->overlay = 0; setContentsMargins(0, 0, 0, 0);
setMargins(0, 0, 0, 0);
updateGeometry(); updateGeometry();
update(); update();
} }
@ -683,6 +676,15 @@ QString visibleFailureText(const QString& reason)
return text; 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) void Applet::setFailedToLaunch(bool failed, const QString& reason)
{ {
if (d->failed == failed) { if (d->failed == failed) {
@ -702,8 +704,9 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
if (failed) { if (failed) {
setDrawStandardBackground(true); 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 = new LineEdit(this);
d->failureText->setTextInteractionFlags( Qt::TextSelectableByMouse ); d->failureText->setTextInteractionFlags( Qt::TextSelectableByMouse );
d->failureText->setStyled(false); d->failureText->setStyled(false);
@ -715,8 +718,18 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
Theme::self()->colors()) Theme::self()->colors())
.brush(QPalette::Normal).color()); .brush(QPalette::Normal).color());
failureLayout->addItem(d->failureText); 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(); update();
} }
@ -739,7 +752,7 @@ void Applet::setNeedsConfiguring(bool needsConfig)
} }
d->needsConfigOverlay = new OverlayWidget(this); d->needsConfigOverlay = new OverlayWidget(this);
d->needsConfigOverlay->resize(contentSize()); d->needsConfigOverlay->resize(boundingRect().size());
int zValue = 100; int zValue = 100;
foreach (QGraphicsItem *child, QGraphicsItem::children()) { foreach (QGraphicsItem *child, QGraphicsItem::children()) {
@ -753,7 +766,7 @@ void Applet::setNeedsConfiguring(bool needsConfig)
PushButton* button = new PushButton(d->needsConfigOverlay); PushButton* button = new PushButton(d->needsConfigOverlay);
button->setText(i18n("Configure...")); button->setText(i18n("Configure..."));
connect(button, SIGNAL(clicked()), this, SLOT(showConfigurationInterface())); connect(button, SIGNAL(clicked()), this, SLOT(showConfigurationInterface()));
QSizeF s = button->sizeHint(); QSizeF s = button->geometry().size();
button->resize(s); button->resize(s);
button->setPos(d->needsConfigOverlay->boundingRect().width() / 2 - s.width() / 2, button->setPos(d->needsConfigOverlay->boundingRect().width() / 2 - s.width() / 2,
d->needsConfigOverlay->boundingRect().height() / 2 - s.height() / 2); d->needsConfigOverlay->boundingRect().height() / 2 - s.height() / 2);
@ -783,7 +796,7 @@ void Applet::flushUpdatedConstraints()
d->pendingConstraints = NoConstraint; d->pendingConstraints = NoConstraint;
if (c & Plasma::SizeConstraint && d->needsConfigOverlay) { 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 // 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 // for layouts, and with WoC coming i'd rather not expend effort there
QGraphicsItem * button = d->needsConfigOverlay->QGraphicsItem::children().first(); QGraphicsItem * button = d->needsConfigOverlay->QGraphicsItem::children().first();
@ -852,20 +865,6 @@ int Applet::type() const
return Type; 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 QPainterPath Applet::shape() const
{ {
if (isContainment()) { if (isContainment()) {
@ -875,21 +874,6 @@ QPainterPath Applet::shape() const
return Plasma::roundedRectangle(boundingRect().adjusted(-2, -2, 2, 2), 10); 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 Qt::Orientations Applet::expandingDirections() const
{ {
if (d->square) { if (d->square) {
@ -975,7 +959,7 @@ void Applet::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *opti
coption.view = v; 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(); painter->restore();
@ -983,14 +967,7 @@ void Applet::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *opti
} }
//kDebug() << "paint interface of" << (QObject*) this; //kDebug() << "paint interface of" << (QObject*) this;
paintInterface(painter, option, QRect(QPoint(0,0), d->contentSize(this).toSize())); paintInterface(painter, option, QRect(QPoint(0,0), boundingRect().size().toSize()));
}
if (d->overlay &&
formFactor() != Plasma::Vertical &&
formFactor() != Plasma::Horizontal) {
//kDebug() << "option rect is" << option->rect;
d->overlay->paint(painter, option->rect);
} }
painter->restore(); painter->restore();
@ -1048,124 +1025,6 @@ Location Applet::location() const
return c->location(); 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 Qt::AspectRatioMode Applet::aspectRatioMode() const
{ {
return d->aspectRatioMode; return d->aspectRatioMode;
@ -1583,27 +1442,10 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
void Applet::setGeometry(const QRectF& geometry) void Applet::setGeometry(const QRectF& geometry)
{ {
QSizeF s = size();
QPointF p = pos();
Widget::setGeometry(geometry); Widget::setGeometry(geometry);
//kDebug() << s << size(); updateConstraints(Plasma::SizeConstraint);
if (s != size()) { //FIXME see for who is connect to this???
if (d->background) { //emit geometryChanged();
//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();
}
} }
void Applet::raise() void Applet::raise()

106
applet.h
View File

@ -228,90 +228,8 @@ class PLASMA_EXPORT Applet : public Widget
* @see Plasma::Location * @see Plasma::Location
*/ */
virtual Location location() const; 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 * @return the prefered aspect ratio mode for placement and resizing
*/ */
Qt::AspectRatioMode aspectRatioMode() const; Qt::AspectRatioMode aspectRatioMode() const;
@ -492,6 +410,8 @@ class PLASMA_EXPORT Applet : public Widget
**/ **/
void setDrawStandardBackground(bool drawBackground); 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 * 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, * library couldn't be loaded, necessary hardware support wasn't found,
@ -573,30 +493,25 @@ class PLASMA_EXPORT Applet : public Widget
/** /**
* Sets whether or not this Applet is acting as a Containment * 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 * @return true if this Applet is currently being used as a Containment, false otherwise
*/ */
bool isContainment() const; bool isContainment() const;
/** /**
* Sets the geometry of this Plasma::Applet. Should not be used directly by * Sets the geometry of this Plasma::Applet. Should not be used directly by
* applet subclasses. * applet subclasses.
* @param geometry the geometry to apply to this Plasma::Applet. * @param geometry the geometry to apply to this Plasma::Applet.
*/ */
void setGeometry(const QRectF &geometry); void setGeometry(const QRectF &geometry);
/** /**
* Causes this applet to raise above all other applets. * Causes this applet to raise above all other applets.
*/ */
void raise(); void raise();
/**
* Reimplemented from LayoutItem
*/
QSizeF sizeHint() const;
/** /**
* Reimplemented from Plasma::Widget * Reimplemented from Plasma::Widget
*/ */
@ -608,12 +523,7 @@ class PLASMA_EXPORT Applet : public Widget
int type() const; int type() const;
enum { Type = Plasma::AppletType }; enum { Type = Plasma::AppletType };
/** /**
* Reimplemented from QGraphicsItem
**/
QRectF boundingRect() const;
/**
* Reimplemented from QGraphicsItem * Reimplemented from QGraphicsItem
*/ */
QPainterPath shape() const; QPainterPath shape() const;

View File

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

View File

@ -27,6 +27,8 @@
#include <QMimeData> #include <QMimeData>
#include <QPainter> #include <QPainter>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QGraphicsLayout>
#include <QGraphicsLinearLayout>
#include <KApplication> #include <KApplication>
#include <KAuthorized> #include <KAuthorized>
@ -83,33 +85,6 @@ public:
return toolbox; 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() void positionToolbox()
{ {
QRectF r; QRectF r;
@ -147,10 +122,8 @@ void Containment::Private::setLockToolText()
QSizeF iconSize = icon->sizeFromIconSize(22); QSizeF iconSize = icon->sizeFromIconSize(22);
icon->setMinimumSize(iconSize); icon->setMinimumSize(iconSize);
icon->setMaximumSize(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) { if (constraints & Plasma::ScreenConstraint && d->toolbox) {
d->toolbox->setPos(geometry().width() - d->toolbox->boundingRect().width(), 0); d->toolbox->setPos(geometry().width() - d->toolbox->boundingRect().width(), 0);
d->toolbox->enableTool("addwidgets", !isImmutable());
} }
if (constraints & Plasma::SizeConstraint) { if (constraints & Plasma::SizeConstraint) {
@ -292,26 +266,30 @@ void Containment::setContainmentType(Containment::Type type)
{ {
d->type = type; d->type = type;
// reset the toolbox! if (isContainment() && type == DesktopContainment) {
delete d->toolbox; if (!d->toolbox) {
d->toolbox = 0; Plasma::Widget *addWidgetTool = addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets"));
connect(addWidgetTool, SIGNAL(clicked()), this, SIGNAL(showAddWidgets()));
if (isContainment()) { Plasma::Widget *zoomInTool = addToolBoxTool("zoomIn", "zoom-in", i18n("Zoom In"));
d->initToolBox(); 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 Corona* Containment::corona() const
{ {
return dynamic_cast<Corona*>(scene()); return dynamic_cast<Corona*>(scene());
@ -460,14 +438,15 @@ void Containment::setFormFactor(FormFactor formFactor)
positionPanel(true); positionPanel(true);
} }
Layout *lay = layout(); QGraphicsLayout *lay = layout();
if (lay) { QGraphicsLinearLayout * linearLay = dynamic_cast<QGraphicsLinearLayout *>(lay);
if (linearLay) {
foreach (Applet* applet, d->applets) { foreach (Applet* applet, d->applets) {
lay->addItem(applet); linearLay->addItem(applet);
applet->updateConstraints(Plasma::FormFactorConstraint); applet->updateConstraints(Plasma::FormFactorConstraint);
} }
//linearLay->addStretch();
} }
updateConstraints(Plasma::FormFactorConstraint); updateConstraints(Plasma::FormFactorConstraint);
} }
@ -478,23 +457,27 @@ void Containment::createLayout(FormFactor formFactor)
switch (formFactor) { switch (formFactor) {
case Planar: case Planar:
case MediaCenter: case MediaCenter:
new FreeLayout(this); //setLayout(new QGraphicsLinearLayout());
break; break;
case Horizontal: { case Horizontal: {
BoxLayout *lay = new BoxLayout(BoxLayout::LeftToRight, this); QGraphicsLinearLayout *lay = new QGraphicsLinearLayout();
lay->setMargins(0, 0, 0, 0); lay->setOrientation(Qt::Horizontal);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(4); lay->setSpacing(4);
setLayout(lay);
break; break;
} }
case Vertical: { case Vertical: {
BoxLayout *lay = new BoxLayout(BoxLayout::TopToBottom, this); QGraphicsLinearLayout *lay = new QGraphicsLinearLayout();
lay->setMargins(0, 0, 0, 0); lay->setOrientation(Qt::Vertical);
lay->setContentsMargins(0, 0, 0, 0);
lay->setSpacing(4); lay->setSpacing(4);
setLayout(lay);
break; break;
} }
default: default:
kDebug() << "This can't be happening! Or... can it? ;)" << d->formFactor; kDebug() << "This can't be happening! Or... can it? ;)" << d->formFactor;
setLayout(0); //auto-delete //setLayout(0); //auto-delete
break; break;
} }
} }
@ -595,19 +578,23 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui
if (containmentType() != PanelContainment) { if (containmentType() != PanelContainment) {
//kDebug() << "adding applet" << applet->name() << "with a default geometry of" << appletGeometry << appletGeometry.isValid(); //kDebug() << "adding applet" << applet->name() << "with a default geometry of" << appletGeometry << appletGeometry.isValid();
if (appletGeometry.isValid()) { if (appletGeometry.isValid()) {
applet->setGeometry(appletGeometry); //applet->setGeometry(appletGeometry);
} else if (appletGeometry.x() != -1 && appletGeometry.y() != -1) { } else if (appletGeometry.x() != -1 && appletGeometry.y() != -1) {
// yes, this means we can't have items start -1, -1 // yes, this means we can't have items start -1, -1
applet->setGeometry(QRectF(appletGeometry.topLeft(), //applet->setGeometry(QRectF(appletGeometry.topLeft(),
applet->sizeHint())); // applet->sizeHint()));
} else if (geometry().isValid()) { } else if (geometry().isValid()) {
applet->setGeometry(geometryForApplet(applet)); //applet->setGeometry(geometryForApplet(applet));
} }
} }
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry(); //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); emit appletAdded(applet);
return 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 // 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 //so long as this isn't a new applet with a delayed init
if (! delayInit || (currentContainment && currentContainment != this)) { 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*)), connect(applet, SIGNAL(destroyed(QObject*)),
this, SLOT(appletDestroyed(QObject*))); this, SLOT(appletDestroyed(QObject*)));
Layout *lay = layout(); QGraphicsLayout *lay = layout();
// Reposition the applet after adding has been done // Reposition the applet after adding has been done
//FIXME adding position incorrect
if (index != -1) { if (index != -1) {
BoxLayout *l = dynamic_cast<BoxLayout *>(lay); QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(lay);
if (l) { if (l) {
l->insertItem(index, l->takeAt(l->indexOf(applet))); l->insertItem(index, applet);
d->applets.removeAll(applet); d->applets.removeAll(applet);
d->applets.insert(index, applet); d->applets.insert(index, applet);
} else { } else {
@ -679,21 +667,24 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
applet->setPos(pos); applet->setPos(pos);
} }
if (lay) { QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(lay);
lay->addItem(applet); if (l) {
l->addItem(applet);
} }
//l->addStretch();
} }
prepareApplet(applet, delayInit); //must at least flush constraints prepareApplet(applet, delayInit); //must at least flush constraints
} }
//containment-relative pos... right? //containment-relative pos... right?
int Containment::indexAt(const QPointF &pos) const int Containment::indexAt(const QPointF &pos) const
{ {
if (pos == QPointF(-1, -1)) { /* if (pos == QPointF(-1, -1)) {
return -1; return -1;
} }
BoxLayout *l = dynamic_cast<BoxLayout *>(layout()); QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(layout());
if (l) { if (l) {
foreach (Applet *existingApplet, d->applets) { foreach (Applet *existingApplet, d->applets) {
if (formFactor() == Horizontal) { if (formFactor() == Horizontal) {
@ -718,7 +709,7 @@ int Containment::indexAt(const QPointF &pos) const
} }
} }
} }
} }*/
return -1; 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 bool Containment::regionIsEmpty(const QRectF &region, Applet *ignoredApplet) const
{ {
foreach (Applet *applet, d->applets) { foreach (Applet *applet, d->applets) {
@ -1272,7 +1225,7 @@ Plasma::Widget * Containment::addToolBoxTool(const QString& toolName, const QStr
QSizeF iconSize = tool->sizeFromIconSize(22); QSizeF iconSize = tool->sizeFromIconSize(22);
tool->setMinimumSize(iconSize); tool->setMinimumSize(iconSize);
tool->setMaximumSize(iconSize); tool->setMaximumSize(iconSize);
tool->resize(tool->sizeHint()); tool->resize(tool->size());
d->createToolbox()->addTool(tool, toolName); d->createToolbox()->addTool(tool, toolName);

View File

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

View File

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

View File

@ -186,7 +186,7 @@ void GLApplet::paintInterface(QPainter *painter,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix m = painter->worldMatrix(); 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()); d->updateGlSize(deviceRect.size());
// redirect this widget's painting into the pbuffer // redirect this widget's painting into the pbuffer

View File

@ -489,14 +489,6 @@ QPixmap Phase::animationResult(AnimId id)
return state->pixmap; 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) void Phase::timerEvent(QTimerEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)

View File

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

View File

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

View File

@ -17,10 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "plasma/scripting/runnerscript.h" #include "runnerscript.h"
#include "plasma/abstractrunner.h" #include "abstractrunner.h"
#include "plasma/package.h"
namespace Plasma namespace Plasma
{ {
@ -63,20 +62,6 @@ void RunnerScript::exec(const Plasma::SearchContext *search, const Plasma::Searc
Q_UNUSED(action) 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 } // Plasma namespace
#include "runnerscript.moc" #include "runnerscript.moc"

View File

@ -70,19 +70,6 @@ public:
*/ */
virtual void exec(const Plasma::SearchContext *search, const Plasma::SearchMatch *action); 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: private:
class Private; class Private;
Private * const d; Private * const d;

View File

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

View File

@ -70,21 +70,8 @@ public:
*/ */
virtual bool init(); 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: private:
class Private; class Private;
Private * const d; Private * const d;
}; };

View File

@ -134,7 +134,7 @@ void SearchMatch::setEnabled( bool enabled )
bool SearchMatch::isEnabled() const bool SearchMatch::isEnabled() const
{ {
return d->enabled; return d->enabled;
} }
bool SearchMatch::operator<(const SearchMatch& other) const 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 * @arg name the name of the file in the theme directory (without the
* ".svg" part or a leading slash) * ".svg" part or a leading slash)
* @return the full path to the requested file for the current theme, * @return the full path to the requested file for the current theme
* or an empty string if the image is not available
*/ */
Q_INVOKABLE QString image( const QString& name ) const; Q_INVOKABLE QString image( const QString& name ) const;

View File

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

View File

@ -157,10 +157,10 @@ void View::setContainment(Containment *containment)
} }
d->containment = containment; d->containment = containment;
if (!containment) { if (! containment) {
return; return;
} }
if (screen > -1) { if (screen > -1) {
containment->setScreen(screen); containment->setScreen(screen);
} }
@ -172,7 +172,7 @@ void View::setContainment(Containment *containment)
} }
updateSceneRect(); updateSceneRect();
connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect())); //connect(containment, SIGNAL(geometryChanged()), this, SLOT(updateSceneRect()));
} }
Containment* View::containment() const 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 m.boundingRect(QRectF(0, 0, w, 9999), d->alignment | Qt::TextWordWrap, d->text).height();
return 0; return 0;
} }
#ifdef REMOVE
QSizeF Label::sizeHint() const QSizeF Label::sizeHint() const
{ {
QFontMetricsF m(d->textFont); 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,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(); //return m.boundingRect(QRectF(0, 0, d->maximumWidth, 9999), d->alignment | Qt::TextWordWrap, d->text).size();
} }
#endif
void Label::setText(const QString& text) void Label::setText(const QString& text)
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,6 +33,8 @@
#include <QPainter> #include <QPainter>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QGraphicsLayout>
#include <QGraphicsLinearLayout>
#include <KDebug> #include <KDebug>
@ -122,8 +124,7 @@ bool Widget::Private::shouldPaint(QPainter *painter, const QTransform &transform
} }
Widget::Widget(QGraphicsItem *parent, QObject* parentObject) Widget::Widget(QGraphicsItem *parent, QObject* parentObject)
: QObject(parentObject), : QGraphicsWidget(parent),
QGraphicsItem(parent),
d(new Private) d(new Private)
{ {
setFlag(QGraphicsItem::ItemClipsToShape, true); setFlag(QGraphicsItem::ItemClipsToShape, true);
@ -166,7 +167,7 @@ Widget::CachePaintMode Widget::cachePaintMode() const
void Widget::update(const QRectF &rect) void Widget::update(const QRectF &rect)
{ {
QGraphicsItem::update(rect); QGraphicsWidget::update(rect);
} }
Qt::Orientations Widget::expandingDirections() const Qt::Orientations Widget::expandingDirections() const
@ -174,32 +175,9 @@ Qt::Orientations Widget::expandingDirections() const
return Qt::Horizontal | Qt::Vertical; return Qt::Horizontal | Qt::Vertical;
} }
void Widget::setMinimumSize(const QSizeF& newMin) QFont Widget::font() const
{ {
d->minimumSize = newMin; return QApplication::font();
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;
} }
bool Widget::hasHeightForWidth() const bool Widget::hasHeightForWidth() const
@ -233,87 +211,7 @@ QRectF Widget::geometry() const
void Widget::setSize(const QSizeF &s) void Widget::setSize(const QSizeF &s)
{ {
LayoutItem::setSize(s); resize(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));
} }
Widget *Widget::parent() const Widget *Widget::parent() const
@ -347,9 +245,9 @@ void Widget::addChild(Widget *w)
w->setParentItem(this); w->setParentItem(this);
//kDebug() << "Added Child Widget" << (QObject*)w << "our geom is" << geometry(); //kDebug() << "Added Child Widget" << (QObject*)w << "our geom is" << geometry();
QGraphicsLinearLayout * lay = dynamic_cast<QGraphicsLinearLayout *>(layout());
if (layout()) { if (lay) {
layout()->addItem(w); lay->addItem(w);
} }
updateGeometry(); updateGeometry();
@ -411,30 +309,6 @@ void Widget::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *opti
// Replaced by widget's own function // 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 QPoint Widget::popupPosition(const QSize &s) const
{ {
QGraphicsView *v = view(); QGraphicsView *v = view();

View File

@ -22,7 +22,7 @@
#ifndef WIDGET_H_ #ifndef WIDGET_H_
#define WIDGET_H_ #define WIDGET_H_
#include <QtGui/QGraphicsItem> #include <QtGui/QGraphicsWidget>
#include <QtGui/QPixmap> #include <QtGui/QPixmap>
#include <QtCore/QRectF> #include <QtCore/QRectF>
@ -63,16 +63,11 @@ class Layout;
* To implement a Widget, just subclass Plasma::Widget and implement at minimum, * To implement a Widget, just subclass Plasma::Widget and implement at minimum,
* sizeHint() and paintWidget() * sizeHint() and paintWidget()
*/ */
class PLASMA_EXPORT Widget : public QObject, class PLASMA_EXPORT Widget : public QGraphicsWidget
public QGraphicsItem,
public LayoutItem
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( Qt::Orientations expandingDirections READ expandingDirections ) 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( QRectF geometry READ geometry WRITE setGeometry )
Q_PROPERTY( QSizeF sizeHint READ sizeHint )
Q_PROPERTY( QSizeF size READ size WRITE resize ) Q_PROPERTY( QSizeF size READ size WRITE resize )
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
@ -102,28 +97,6 @@ public:
*/ */
virtual Qt::Orientations expandingDirections() const; 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 * This method is used by Plasma::Layout to determine whether this widget
* can provide a height value given a width value. * can provide a height value given a width value.
@ -159,53 +132,11 @@ public:
*/ */
QRectF geometry() const; 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 * @return the font currently set for this widget
**/ **/
QFont font() const; 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 * @return this Plasma::Widget's parent, returns a null pointer if
* none exist. * none exist.
@ -310,9 +241,7 @@ protected:
* @param widget the parent QWidget (most likely the Corona) * @param widget the parent QWidget (most likely the Corona)
*/ */
virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); 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); virtual bool sceneEvent(QEvent *event);
private: private: