applet doesn't inherit from QGraphicsWidget
This commit is contained in:
parent
09cf013164
commit
cc21f6fcfe
116
applet.cpp
116
applet.cpp
@ -116,8 +116,8 @@
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
Applet::Applet(const KPluginInfo &info, QGraphicsItem *parent, uint appletId)
|
||||
: QGraphicsWidget(parent),
|
||||
Applet::Applet(const KPluginInfo &info, QObject *parent, uint appletId)
|
||||
: QObject(parent),
|
||||
d(new AppletPrivate(KService::Ptr(), &info, appletId, this))
|
||||
{
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
@ -125,8 +125,8 @@ Applet::Applet(const KPluginInfo &info, QGraphicsItem *parent, uint appletId)
|
||||
d->init();
|
||||
}
|
||||
|
||||
Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId)
|
||||
: QGraphicsWidget(parent),
|
||||
Applet::Applet(QObject *parent, const QString &serviceID, uint appletId)
|
||||
: QObject(parent),
|
||||
d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this))
|
||||
{
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
@ -134,8 +134,8 @@ Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId)
|
||||
d->init();
|
||||
}
|
||||
|
||||
Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId, const QVariantList &args)
|
||||
: QGraphicsWidget(parent),
|
||||
Applet::Applet(QObject *parent, const QString &serviceID, uint appletId, const QVariantList &args)
|
||||
: QObject(parent),
|
||||
d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this))
|
||||
{
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
@ -156,7 +156,7 @@ Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId, c
|
||||
}
|
||||
|
||||
Applet::Applet(QObject *parentObject, const QVariantList &args)
|
||||
: QGraphicsWidget(0),
|
||||
: QObject(0),
|
||||
d(new AppletPrivate(
|
||||
KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()), 0,
|
||||
args.count() > 1 ? args[1].toInt() : 0, this))
|
||||
@ -186,7 +186,7 @@ Applet::Applet(QObject *parentObject, const QVariantList &args)
|
||||
}
|
||||
|
||||
Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args)
|
||||
: QGraphicsWidget(0),
|
||||
: QObject(0),
|
||||
d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this))
|
||||
{
|
||||
Q_UNUSED(args) // FIXME?
|
||||
@ -625,7 +625,6 @@ void Applet::setBackgroundHints(const Plasma::BackgroundHints hints)
|
||||
if ((hints & StandardBackground) || (hints & TranslucentBackground)) {
|
||||
if (!d->background) {
|
||||
d->background = new Plasma::FrameSvg(this);
|
||||
QObject::connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(themeChanged()));
|
||||
}
|
||||
|
||||
if ((hints & TranslucentBackground) &&
|
||||
@ -976,16 +975,16 @@ void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *o
|
||||
FormFactor Applet::formFactor() const
|
||||
{
|
||||
Containment *c = containment();
|
||||
QGraphicsWidget *pw = qobject_cast<QGraphicsWidget *>(parent());
|
||||
QObject *pw = qobject_cast<QObject *>(parent());
|
||||
if (!pw) {
|
||||
pw = dynamic_cast<QGraphicsWidget *>(parentItem());
|
||||
pw = dynamic_cast<QObject *>(parentItem());
|
||||
}
|
||||
Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(pw);
|
||||
//assumption: this loop is usually is -really- short or doesn't run at all
|
||||
while (!parentApplet && pw && pw->parentWidget()) {
|
||||
QGraphicsWidget *parentWidget = qobject_cast<QGraphicsWidget *>(pw->parent());
|
||||
QObject *parentWidget = qobject_cast<QObject *>(pw->parent());
|
||||
if (!parentWidget) {
|
||||
parentWidget = dynamic_cast<QGraphicsWidget *>(pw->parentItem());
|
||||
parentWidget = dynamic_cast<QObject *>(pw->parentItem());
|
||||
}
|
||||
pw = parentWidget;
|
||||
parentApplet = qobject_cast<Plasma::Applet *>(pw);
|
||||
@ -1021,7 +1020,7 @@ Containment *Applet::containment() const
|
||||
}
|
||||
}
|
||||
|
||||
QGraphicsItem *parent = parentItem();
|
||||
QObject *parent = parentItem();
|
||||
Containment *c = 0;
|
||||
|
||||
while (parent) {
|
||||
@ -1122,7 +1121,7 @@ void Applet::setAspectRatioMode(Plasma::AspectRatioMode mode)
|
||||
d->aspectRatioMode = mode;
|
||||
}
|
||||
|
||||
void Applet::registerAsDragHandle(QGraphicsItem *item)
|
||||
void Applet::registerAsDragHandle(QObject *item)
|
||||
{
|
||||
if (!item || d->registeredAsDragHandle.contains(item)) {
|
||||
return;
|
||||
@ -1132,7 +1131,7 @@ void Applet::registerAsDragHandle(QGraphicsItem *item)
|
||||
item->installSceneEventFilter(this);
|
||||
}
|
||||
|
||||
void Applet::unregisterAsDragHandle(QGraphicsItem *item)
|
||||
void Applet::unregisterAsDragHandle(QObject *item)
|
||||
{
|
||||
if (!item) {
|
||||
return;
|
||||
@ -1145,7 +1144,7 @@ void Applet::unregisterAsDragHandle(QGraphicsItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
bool Applet::isRegisteredAsDragHandle(QGraphicsItem *item)
|
||||
bool Applet::isRegisteredAsDragHandle(QObject *item)
|
||||
{
|
||||
return d->registeredAsDragHandle.contains(item);
|
||||
}
|
||||
@ -1211,14 +1210,14 @@ void Applet::setHasConfigurationInterface(bool hasInterface)
|
||||
d->hasConfigurationInterface = hasInterface;
|
||||
}
|
||||
|
||||
bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
bool Applet::sceneEventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == this) {
|
||||
switch (event->type()) {
|
||||
case QEvent::GraphicsSceneHoverEnter:
|
||||
//kDebug() << "got hoverenterEvent" << immutability() << " " << immutability();
|
||||
if (immutability() == Mutable) {
|
||||
QGraphicsWidget *pw = this;
|
||||
QObject *pw = this;
|
||||
//This is for the rare case of applet in applet (systray)
|
||||
//if the applet is in an applet that is not a containment, don't create the handle BUG:301648
|
||||
while (pw = pw->parentWidget()) {
|
||||
@ -1235,8 +1234,7 @@ bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
} else {
|
||||
//kDebug() << "generated applet handle";
|
||||
AppletHandle *handle = new AppletHandle(containment(), this, he->pos());
|
||||
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
|
||||
this, SLOT(handleDisappeared(AppletHandle*)));
|
||||
|
||||
connect(this, SIGNAL(geometryChanged()),
|
||||
handle, SLOT(appletResized()));
|
||||
d->handle = handle;
|
||||
@ -1278,13 +1276,13 @@ bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||
break;
|
||||
}
|
||||
|
||||
return QGraphicsItem::sceneEventFilter(watched, event);
|
||||
return QObject::sceneEventFilter(watched, event);
|
||||
}
|
||||
|
||||
void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (immutability() == Mutable && formFactor() == Plasma::Planar && (flags() & ItemIsMovable)) {
|
||||
QGraphicsWidget::mouseMoveEvent(event);
|
||||
QObject::mouseMoveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1295,12 +1293,12 @@ void Applet::focusInEvent(QFocusEvent *event)
|
||||
containment()->d->focusApplet(this);
|
||||
}
|
||||
|
||||
QGraphicsWidget::focusInEvent(event);
|
||||
QObject::focusInEvent(event);
|
||||
}
|
||||
|
||||
void Applet::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
{
|
||||
QGraphicsWidget::resizeEvent(event);
|
||||
QObject::resizeEvent(event);
|
||||
|
||||
if (d->background) {
|
||||
d->background->resizeFrame(boundingRect().size());
|
||||
@ -1623,82 +1621,18 @@ Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantL
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
QVariant ret = QGraphicsWidget::itemChange(change, value);
|
||||
|
||||
//kDebug() << change;
|
||||
switch (change) {
|
||||
case ItemSceneHasChanged: {
|
||||
Corona *newCorona = qobject_cast<Corona *>(qvariant_cast<QGraphicsScene*>(value));
|
||||
if (newCorona && newCorona->immutability() != Mutable) {
|
||||
updateConstraints(ImmutableConstraint);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ItemParentChange:
|
||||
if (!d->isContainment) {
|
||||
Containment *c = containment();
|
||||
if (d->mainConfig && !c) {
|
||||
kWarning() << "Configuration object was requested prior to init(), which is too early. "
|
||||
"Please fix this item:" << parentItem() << value.value<QGraphicsItem *>()
|
||||
<< name();
|
||||
|
||||
Applet *newC = dynamic_cast<Applet*>(value.value<QGraphicsItem *>());
|
||||
if (newC) {
|
||||
// if this is an applet, and we've just been assigned to our first containment,
|
||||
// but the applet did something stupid like ask for the config() object prior to
|
||||
// this happening (e.g. inits ctor) then let's repair that situation for them.
|
||||
KConfigGroup *old = d->mainConfig;
|
||||
KConfigGroup appletConfig = newC->config();
|
||||
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
||||
d->mainConfig = new KConfigGroup(&appletConfig, QString::number(d->appletId));
|
||||
old->copyTo(d->mainConfig);
|
||||
old->deleteGroup();
|
||||
delete old;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ItemParentHasChanged:
|
||||
{
|
||||
if (isContainment()) {
|
||||
removeSceneEventFilter(this);
|
||||
} else {
|
||||
Containment *c = containment();
|
||||
if (c && c->containmentType() == Containment::DesktopContainment) {
|
||||
installSceneEventFilter(this);
|
||||
} else {
|
||||
removeSceneEventFilter(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ItemPositionHasChanged:
|
||||
emit geometryChanged();
|
||||
// fall through!
|
||||
case ItemTransformHasChanged:
|
||||
d->scheduleModificationNotification();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QPainterPath Applet::shape() const
|
||||
{
|
||||
if (d->script) {
|
||||
return d->script->shape();
|
||||
}
|
||||
|
||||
return QGraphicsWidget::shape();
|
||||
return QObject::shape();
|
||||
}
|
||||
|
||||
QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
||||
{
|
||||
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
|
||||
QSizeF hint = QObject::sizeHint(which, constraint);
|
||||
const FormFactor ff = formFactor();
|
||||
|
||||
// in panels make sure that the contents won't exit from the panel
|
||||
|
18
applet.h
18
applet.h
@ -70,7 +70,7 @@ class Package;
|
||||
*
|
||||
* See techbase.kde.org for tutorials on writing Applets using this class.
|
||||
*/
|
||||
class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
class PLASMA_EXPORT Applet : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
|
||||
@ -809,6 +809,14 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
*/
|
||||
void runAssociatedApplication();
|
||||
|
||||
bool hasFocus() const;
|
||||
void setFocus(Qt::FocusReason);
|
||||
|
||||
void resize(const QSizeF &size);
|
||||
QSizeF size() const;
|
||||
QRectF geometry() const;
|
||||
void setGeometry(const QRect &geom);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This constructor is to be used with the plugin loading systems
|
||||
@ -951,11 +959,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
*/
|
||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsItem
|
||||
*/
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsItem
|
||||
*/
|
||||
@ -993,8 +996,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
*/
|
||||
Applet(const QString &packagePath, uint appletId, const QVariantList &args);
|
||||
|
||||
Q_PRIVATE_SLOT(d, void setFocus())
|
||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||
Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
|
||||
Q_PRIVATE_SLOT(d, void selectItemToDestroy())
|
||||
Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
|
||||
@ -1003,7 +1004,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state))
|
||||
Q_PRIVATE_SLOT(d, void globalShortcutChanged())
|
||||
Q_PRIVATE_SLOT(d, void propagateConfigChanged())
|
||||
Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsItem
|
||||
|
@ -611,12 +611,6 @@ void Containment::setFormFactor(FormFactor formFactor)
|
||||
//kDebug() << "switching FF to " << formFactor;
|
||||
d->formFactor = formFactor;
|
||||
|
||||
if (isContainment() &&
|
||||
(d->type == PanelContainment || d->type == CustomPanelContainment)) {
|
||||
// we are a panel and we have chaged our orientation
|
||||
d->positionPanel(true);
|
||||
}
|
||||
|
||||
if (d->toolBox) {
|
||||
d->toolBox.data()->reposition();
|
||||
}
|
||||
@ -971,9 +965,7 @@ void Containment::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
Applet::resizeEvent(event);
|
||||
|
||||
if (isContainment()) {
|
||||
if (d->isPanelContainment()) {
|
||||
d->positionPanel();
|
||||
} else if (corona()) {
|
||||
if (corona()) {
|
||||
corona()->layoutContainments();
|
||||
}
|
||||
|
||||
@ -1027,29 +1019,6 @@ void Containment::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
QVariant Containment::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
//FIXME if the applet is moved to another containment we need to unfocus it
|
||||
|
||||
if (isContainment() &&
|
||||
(change == QGraphicsItem::ItemSceneHasChanged ||
|
||||
change == QGraphicsItem::ItemPositionHasChanged)) {
|
||||
switch (d->type) {
|
||||
case PanelContainment:
|
||||
case CustomPanelContainment:
|
||||
d->positionPanel();
|
||||
break;
|
||||
default:
|
||||
if (corona()) {
|
||||
corona()->layoutContainments();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Applet::itemChange(change, value);
|
||||
}
|
||||
|
||||
void Containment::enableAction(const QString &name, bool enable)
|
||||
{
|
||||
QAction *action = this->action(name);
|
||||
|
@ -409,6 +409,9 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
*/
|
||||
KConfigGroup containmentActionsConfig();
|
||||
|
||||
void setAcceptDrops(bool accept);
|
||||
bool acceptDrops() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* This signal is emitted when a new applet is created by the containment
|
||||
@ -548,7 +551,6 @@ Q_SIGNALS:
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
/**
|
||||
* @reimp
|
||||
|
@ -131,7 +131,6 @@ void AppletPrivate::init(const QString &packagePath)
|
||||
<< "You probably want to be passing in a Service::Ptr "
|
||||
<< "or a QVariantList with a valid storageid as arg[0].";
|
||||
#endif
|
||||
q->resize(size);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -140,7 +139,6 @@ void AppletPrivate::init(const QString &packagePath)
|
||||
size = s.toSize();
|
||||
}
|
||||
//kDebug() << "size" << size;
|
||||
q->resize(size);
|
||||
|
||||
QString api = appletDescription.property("X-Plasma-API").toString();
|
||||
|
||||
@ -205,15 +203,11 @@ void AppletPrivate::init(const QString &packagePath)
|
||||
}
|
||||
}
|
||||
|
||||
void AppletPrivate::setFocus()
|
||||
{
|
||||
//kDebug() << "setting focus";
|
||||
q->setFocus(Qt::ShortcutFocusReason);
|
||||
}
|
||||
|
||||
void AppletPrivate::selectItemToDestroy()
|
||||
{
|
||||
//FIXME: this will not work nicely with multiple screens and being zoomed out!
|
||||
//TODO: port away from QGV
|
||||
/*
|
||||
if (isContainment) {
|
||||
QGraphicsView *view = q->view();
|
||||
if (view && view->transform().isScaling() &&
|
||||
@ -229,16 +223,11 @@ void AppletPrivate::selectItemToDestroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
q->destroy();
|
||||
}
|
||||
|
||||
void AppletPrivate::updateRect(const QRectF &rect)
|
||||
{
|
||||
q->update(rect);
|
||||
}
|
||||
|
||||
void AppletPrivate::cleanUpAndDelete()
|
||||
{
|
||||
// reimplemented in the UI specific library
|
||||
@ -684,7 +673,7 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
|
||||
}
|
||||
|
||||
if (isContainment) {
|
||||
Corona *corona = qobject_cast<Corona*>(q->scene());
|
||||
Corona *corona = static_cast<Containment*>(q)->corona();
|
||||
KConfigGroup containmentConfig;
|
||||
//kDebug() << "got a corona, baby?" << (QObject*)corona << (QObject*)q;
|
||||
|
||||
@ -733,22 +722,6 @@ QString AppletPrivate::visibleFailureText(const QString &reason)
|
||||
return text;
|
||||
}
|
||||
|
||||
void AppletPrivate::themeChanged()
|
||||
{
|
||||
if (background) {
|
||||
//do again the translucent background fallback
|
||||
q->setBackgroundHints(backgroundHints);
|
||||
|
||||
qreal left;
|
||||
qreal right;
|
||||
qreal top;
|
||||
qreal bottom;
|
||||
background->getMargins(left, top, right, bottom);
|
||||
q->setContentsMargins(left, right, top, bottom);
|
||||
}
|
||||
q->update();
|
||||
}
|
||||
|
||||
void AppletPrivate::resetConfigurationObject()
|
||||
{
|
||||
// make sure mainConfigGroup exists in all cases
|
||||
@ -758,24 +731,15 @@ void AppletPrivate::resetConfigurationObject()
|
||||
delete mainConfig;
|
||||
mainConfig = 0;
|
||||
|
||||
Corona * corona = qobject_cast<Corona*>(q->scene());
|
||||
if (!q->containment()) {
|
||||
return;
|
||||
}
|
||||
Corona * corona = q->containment()->corona();
|
||||
if (corona) {
|
||||
corona->requireConfigSync();
|
||||
}
|
||||
}
|
||||
|
||||
void AppletPrivate::handleDisappeared(AppletHandle *h)
|
||||
{
|
||||
if (h == handle.data()) {
|
||||
h->detachApplet();
|
||||
QGraphicsScene *scene = q->scene();
|
||||
if (scene && h->scene() == scene) {
|
||||
scene->removeItem(h);
|
||||
}
|
||||
h->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
uint AppletPrivate::s_maxAppletId = 0;
|
||||
int AppletPrivate::s_maxZValue = 0;
|
||||
int AppletPrivate::s_minZValue = 0;
|
||||
|
@ -100,18 +100,14 @@ public:
|
||||
*/
|
||||
void setIsContainment(bool isContainment, bool forceUpdate = false);
|
||||
|
||||
void handleDisappeared(AppletHandle *handle);
|
||||
QString globalName() const;
|
||||
QString instanceName();
|
||||
void scheduleConstraintsUpdate(Plasma::Constraints c);
|
||||
void scheduleModificationNotification();
|
||||
KConfigGroup *mainConfigGroup();
|
||||
QString visibleFailureText(const QString &reason);
|
||||
void themeChanged();
|
||||
void resetConfigurationObject();
|
||||
void selectItemToDestroy();
|
||||
void updateRect(const QRectF &rect);
|
||||
void setFocus();
|
||||
void addGlobalShortcutsPage(KConfigDialog *dialog);
|
||||
void addPublishPage(KConfigDialog *dialog);
|
||||
void configDialogFinished();
|
||||
|
@ -140,7 +140,7 @@ void ContainmentPrivate::checkContainmentFurniture()
|
||||
|
||||
void ContainmentPrivate::addContainmentActions(KMenu &desktopMenu, QEvent *event)
|
||||
{
|
||||
if (static_cast<Corona*>(q->scene())->immutability() != Mutable &&
|
||||
if (q->corona()->immutability() != Mutable &&
|
||||
!KAuthorized::authorizeKAction("plasma/containment_actions")) {
|
||||
//kDebug() << "immutability";
|
||||
return;
|
||||
@ -213,6 +213,8 @@ void ContainmentPrivate::addAppletActions(KMenu &desktopMenu, Applet *applet, QE
|
||||
|
||||
Applet* ContainmentPrivate::appletAt(const QPointF &point)
|
||||
{
|
||||
return 0;
|
||||
/*TODO: port away qgv
|
||||
Applet *applet = 0;
|
||||
|
||||
QGraphicsItem *item = q->scene()->itemAt(point);
|
||||
@ -239,6 +241,7 @@ Applet* ContainmentPrivate::appletAt(const QPointF &point)
|
||||
item = item->parentItem();
|
||||
}
|
||||
return applet;
|
||||
*/
|
||||
}
|
||||
|
||||
void ContainmentPrivate::setScreen(int newScreen, int newDesktop, bool preventInvalidDesktops)
|
||||
@ -257,9 +260,11 @@ void ContainmentPrivate::setScreen(int newScreen, int newDesktop, bool preventIn
|
||||
Q_ASSERT(corona);
|
||||
|
||||
//if it's an offscreen widget, don't allow to claim a screen, after all it's *off*screen
|
||||
//TODO: port away qgv
|
||||
/* should decide in a different way if this is a dashboard containment
|
||||
if (corona->offscreenWidgets().contains(q)) {
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
int numScreens = corona->numScreens();
|
||||
if (newScreen < -1) {
|
||||
@ -360,7 +365,6 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF pos = q->mapFromScene(scenePos);
|
||||
const QMimeData *mimeData = 0;
|
||||
|
||||
if (dropEvent) {
|
||||
@ -388,7 +392,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
const QStringList appletNames = data.split('\n', QString::SkipEmptyParts);
|
||||
foreach (const QString &appletName, appletNames) {
|
||||
//kDebug() << "doing" << appletName;
|
||||
QRectF geom(pos, QSize(0, 0));
|
||||
QRectF geom(scenePos, QSize(0, 0));
|
||||
q->addApplet(appletName, QVariantList(), geom);
|
||||
}
|
||||
if (dropEvent) {
|
||||
@ -414,7 +418,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
QMimeDatabase db;
|
||||
QMimeType mime = db.mimeTypeForUrl(url);
|
||||
QString mimeName = mime.name();
|
||||
QRectF geom(pos, QSize());
|
||||
QRectF geom(scenePos, QSize());
|
||||
QVariantList args;
|
||||
args << url.toString();
|
||||
#ifndef NDEBUG
|
||||
@ -516,7 +520,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
stream.writeRawData(data, data.size());
|
||||
}
|
||||
|
||||
QRectF geom(pos, QSize());
|
||||
QRectF geom(scenePos, QSize());
|
||||
QVariantList args;
|
||||
args << tempFile.fileName();
|
||||
#ifndef NDEBUG
|
||||
@ -946,125 +950,11 @@ void ContainmentPrivate::appletAppeared(Applet *applet)
|
||||
emit q->configNeedsSaving();
|
||||
}
|
||||
|
||||
void ContainmentPrivate::positionPanel(bool force)
|
||||
{
|
||||
if (!q->scene()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "no scene yet";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// already positioning the panel - avoid infinite loops
|
||||
if (ContainmentPrivate::s_positioningPanels) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we position panels in negative coordinates, and stack all horizontal
|
||||
// and all vertical panels with each other.
|
||||
|
||||
|
||||
const QPointF p = q->pos();
|
||||
|
||||
if (!force &&
|
||||
p.y() + q->size().height() < -INTER_CONTAINMENT_MARGIN &&
|
||||
q->scene()->collidingItems(q).isEmpty()) {
|
||||
// already positioned and not running into any other panels
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QPointF newPos = preferredPanelPos(q->corona());
|
||||
if (p != newPos) {
|
||||
ContainmentPrivate::s_positioningPanels = true;
|
||||
q->setPos(newPos);
|
||||
ContainmentPrivate::s_positioningPanels = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ContainmentPrivate::isPanelContainment() const
|
||||
{
|
||||
return type == Containment::PanelContainment || type == Containment::CustomPanelContainment;
|
||||
}
|
||||
|
||||
QPointF ContainmentPrivate::preferredPos(Corona *corona) const
|
||||
{
|
||||
Q_ASSERT(corona);
|
||||
|
||||
if (isPanelContainment()) {
|
||||
//kDebug() << "is a panel, so put it at" << preferredPanelPos(corona);
|
||||
return preferredPanelPos(corona);
|
||||
}
|
||||
|
||||
QPointF pos(0, 0);
|
||||
QTransform t;
|
||||
while (QGraphicsItem *i = corona->itemAt(pos, t)) {
|
||||
pos.setX(i->scenePos().x() + i->boundingRect().width() + 10);
|
||||
}
|
||||
|
||||
//kDebug() << "not a panel, put it at" << pos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
QPointF ContainmentPrivate::preferredPanelPos(Corona *corona) const
|
||||
{
|
||||
Q_ASSERT(corona);
|
||||
|
||||
//TODO: research how non-Horizontal, non-Vertical (e.g. Planar) panels behave here
|
||||
bool horiz = formFactor == Plasma::Horizontal;
|
||||
qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET;
|
||||
qreal lastHeight = 0;
|
||||
|
||||
// this should be ok for small numbers of panels, but if we ever end
|
||||
// up managing hundreds of them, this simplistic alogrithm will
|
||||
// likely be too slow.
|
||||
foreach (const Containment *other, corona->containments()) {
|
||||
if (other == q ||
|
||||
!other->d->isPanelContainment() ||
|
||||
horiz != (other->formFactor() == Plasma::Horizontal)) {
|
||||
// only line up with panels of the same orientation
|
||||
continue;
|
||||
}
|
||||
|
||||
if (horiz) {
|
||||
qreal y = other->pos().y();
|
||||
if (y < bottom) {
|
||||
lastHeight = other->size().height();
|
||||
bottom = y;
|
||||
}
|
||||
} else {
|
||||
qreal width = other->size().width();
|
||||
qreal x = other->pos().x() + width;
|
||||
if (x > bottom) {
|
||||
lastHeight = width;
|
||||
bottom = x + lastHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// give a space equal to the height again of the last item so there is
|
||||
// room to grow.
|
||||
QPointF newPos;
|
||||
if (horiz) {
|
||||
bottom -= lastHeight + INTER_CONTAINMENT_MARGIN;
|
||||
//TODO: fix x position for non-flush-left panels
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "moved to" << QPointF(0, bottom - q->size().height());
|
||||
#endif
|
||||
newPos = QPointF(0, bottom - q->size().height());
|
||||
} else {
|
||||
bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
|
||||
//TODO: fix y position for non-flush-top panels
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "moved to" << QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
||||
#endif
|
||||
newPos = QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
||||
}
|
||||
|
||||
return newPos;
|
||||
}
|
||||
|
||||
|
||||
bool ContainmentPrivate::prepareContainmentActions(const QString &trigger, const QPoint &screenPos, KMenu *menu)
|
||||
{
|
||||
ContainmentActions *plugin = actionPlugins()->value(trigger);
|
||||
|
@ -97,10 +97,7 @@ public:
|
||||
void initApplets();
|
||||
void checkContainmentFurniture();
|
||||
bool regionIsEmpty(const QRectF ®ion, Applet *ignoredApplet=0) const;
|
||||
void positionPanel(bool force = false);
|
||||
bool isPanelContainment() const;
|
||||
QPointF preferredPos(Corona *corona) const;
|
||||
QPointF preferredPanelPos(Corona *corona) const;
|
||||
void setLockToolText();
|
||||
void appletDeleted(Applet*);
|
||||
void appletAppeared(Applet*);
|
||||
|
@ -86,17 +86,6 @@ QList<QAction*> AppletScript::contextualActions()
|
||||
return QList<QAction*>();
|
||||
}
|
||||
|
||||
QPainterPath AppletScript::shape() const
|
||||
{
|
||||
if (applet()) {
|
||||
QPainterPath path;
|
||||
path.addRect(applet()->boundingRect());
|
||||
return path;
|
||||
}
|
||||
|
||||
return QPainterPath();
|
||||
}
|
||||
|
||||
void AppletScript::setHasConfigurationInterface(bool hasInterface)
|
||||
{
|
||||
if (applet()) {
|
||||
|
@ -110,11 +110,6 @@ public:
|
||||
*/
|
||||
virtual QList<QAction*> contextualActions();
|
||||
|
||||
/**
|
||||
* Returns the shape of the widget, defaults to the bounding rect
|
||||
*/
|
||||
virtual QPainterPath shape() const;
|
||||
|
||||
/**
|
||||
* Sets whether or not this script has a configuration interface or not
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user