From c066ea70271ebe383d4a8342405fbddde82a14d7 Mon Sep 17 00:00:00 2001 From: Rob Scheepmaker Date: Fri, 29 Aug 2008 19:00:10 +0000 Subject: [PATCH] PopupApplet monitors the size of the applet now. And fixed scenePosFromScreenPos so you can now reorder extenderitems within a Dialog. Stuff still breaks when detaching the last item, I'm still working on that. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=854547 --- corona.cpp | 3 --- extender.cpp | 6 +++--- extenderitem.cpp | 34 ++++++++++++++++++++++++++-------- popupapplet.cpp | 29 ++++++++++++++++------------- popupapplet.h | 7 +------ 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/corona.cpp b/corona.cpp index 54e7ef511..a27dc5553 100644 --- a/corona.cpp +++ b/corona.cpp @@ -374,8 +374,6 @@ void Corona::addOffscreenWidget(QGraphicsWidget *widget) d->offscreenLayout->addItem(widget, d->offscreenLayout->rowCount() + 1, d->offscreenLayout->columnCount() + 1); - d->offscreenLayout->invalidate(); - kDebug() << "current scenerect = " << widget->sceneBoundingRect(); } @@ -390,7 +388,6 @@ void Corona::removeOffscreenWidget(QGraphicsWidget *widget) dynamic_cast(d->offscreenLayout->itemAt(i)); if (foundWidget == widget) { d->offscreenLayout->removeAt(i); - d->offscreenLayout->invalidate(); } } } diff --git a/extender.cpp b/extender.cpp index 0cb69e739..8b5b6bf21 100644 --- a/extender.cpp +++ b/extender.cpp @@ -46,9 +46,9 @@ Extender::Extender(Applet *applet) d->emptyExtenderLabel = new Label(this); d->emptyExtenderLabel->setText(d->emptyExtenderMessage); - d->emptyExtenderLabel->setMinimumSize(QSizeF(150, 24)); - d->emptyExtenderLabel->setPreferredSize(QSizeF(200, 48)); - d->emptyExtenderLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + d->emptyExtenderLabel->setMinimumSize(QSizeF(150, 64)); + d->emptyExtenderLabel->setPreferredSize(QSizeF(200, 64)); + d->emptyExtenderLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); d->layout->addItem(d->emptyExtenderLabel); d->loadExtenderItems(); diff --git a/extenderitem.cpp b/extenderitem.cpp index 47e9becfd..5e38f91de 100644 --- a/extenderitem.cpp +++ b/extenderitem.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,7 @@ #include "applet.h" #include "containment.h" #include "corona.h" +#include "dialog.h" #include "extender.h" #include "panelsvg.h" #include "theme.h" @@ -177,9 +179,24 @@ class ExtenderItemPrivate QGraphicsView *found = 0; foreach (QWidget *w, QApplication::topLevelWidgets()) { - QGraphicsView *v = qobject_cast(w); - if (v && v->isVisible() && v->geometry().contains(pos)) { - if (found) { + QGraphicsView *v = 0; + + //first check if we're over a Dialog. + Dialog *dialog = qobject_cast(w); + if (dialog) { + if (dialog->isVisible() && dialog->geometry().contains(pos)) { + v = qobject_cast(dialog->layout()->itemAt(0)->widget()); + if (v) { + return v->mapToScene(v->mapFromGlobal(pos)); + } + } + } else { + v = qobject_cast(w); + } + + //else check if it is a QGV: + if (v && w->isVisible() && w->geometry().contains(pos)) { + if (found && order.contains(found->winId())) { if (order.indexOf(found->winId()) < order.indexOf(v->winId())) { found = v; } @@ -405,7 +422,6 @@ void ExtenderItem::setExtender(Extender *extender, const QPointF &pos) //move the configuration. if (d->hostApplet() && (extender != d->extender)) { - kDebug() << "moving configuration"; KConfigGroup c = extender->d->applet->config("ExtenderItems"); config().reparent(&c); } @@ -636,6 +652,7 @@ void ExtenderItem::resizeEvent(QGraphicsSceneResizeEvent *event) void ExtenderItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { + kDebug() << "the mouse pressed yeah yeah yeah!"; if (!(d->dragHandleRect().contains(event->pos()))) { return; } @@ -651,16 +668,17 @@ void ExtenderItem::mousePressEvent(QGraphicsSceneMouseEvent *event) setZValue(parentApplet->zValue()); if (d->extender) { - d->extender->itemHoverEnterEvent(this); + //d->extender->itemHoverEnterEvent(this); //d->extender->itemHoverMoveEvent(this, d->extender->mapFromScene(event->scenePos())); + d->extender->itemHoverMoveEvent(this, d->extender->mapFromScene(d->scenePosFromScreenPos(event->screenPos()))); } + d->extender->d->removeExtenderItem(this); + //call the move event, since that spawns a toplevel view when this extender item is in a //Plasma::Dialog, which is very essential since else the dialog will close before having been //able to receive any move events. - mouseMoveEvent(event); - - d->extender->d->removeExtenderItem(this); + //mouseMoveEvent(event); QApplication::setOverrideCursor(Qt::ClosedHandCursor); } diff --git a/popupapplet.cpp b/popupapplet.cpp index 401680e67..fcf4ccecb 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -175,6 +175,7 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints) if (graphicsWidget()) { d->layout->addItem(graphicsWidget()); setMinimumSize(graphicsWidget()->minimumSize() + marginSize); + graphicsWidget()->installEventFilter(this); } else { if (!d->proxy) { @@ -240,6 +241,21 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints) } } +bool PopupApplet::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == graphicsWidget() && (event->type() == QEvent::GraphicsSceneResize)) { + //sizes are recalculated in the constraintsevent so let's just call that. + constraintsEvent(Plasma::FormFactorConstraint); + + //resize vertically if necesarry. + if (formFactor() == Plasma::MediaCenter || formFactor() == Plasma::Planar) { + resize(QSizeF(size().width(), minimumHeight())); + } + } + + return Applet::eventFilter(watched, event); +} + void PopupApplet::showPopup(uint popupDuration) { if (d->dialog && (formFactor() == Horizontal || formFactor() == Vertical)) { @@ -275,19 +291,6 @@ void PopupApplet::popupEvent(bool) } -void PopupApplet::widgetGeometryChanged() -{ - if (graphicsWidget() && layout()) { - //sizes are recalculated in the constraintsevent so let's just call that. - constraintsEvent(Plasma::FormFactorConstraint); - - //resize vertically if necesarry. - if (formFactor() == Plasma::MediaCenter || formFactor() == Plasma::Planar) { - resize(QSizeF(size().width(), minimumHeight())); - } - } -} - void PopupAppletPrivate::togglePopup() { if (dialog) { diff --git a/popupapplet.h b/popupapplet.h index c29eab617..58f7211e4 100644 --- a/popupapplet.h +++ b/popupapplet.h @@ -100,14 +100,9 @@ public Q_SLOTS: */ void hidePopup(); - /** - * Notify PopupApplet that the geometry of the graphicsWidget has changed. When you use an - * extender you'll want to connect the extender's geometryChanged() signal to this slot. - */ - void widgetGeometryChanged(); - protected: void constraintsEvent(Plasma::Constraints constraints); + bool eventFilter(QObject *watched, QEvent *event); private: Q_PRIVATE_SLOT(d, void togglePopup())