From 27cdeadb0390a7b69815a7e10692b31643f816e0 Mon Sep 17 00:00:00 2001 From: Rob Scheepmaker Date: Mon, 25 Aug 2008 13:55:26 +0000 Subject: [PATCH] Some changes to PopupApplet to make it a useful base class for extender using applets, and some changes to libplasmaclock to make it's dialog get the correct size. Works quite well, but for some reason dragging extender items from the dialog doesn't work correctly right now, I'm working on that. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=852189 --- extenderitem.cpp | 16 ++++++++++------ popupapplet.cpp | 27 +++++++++++++++++++++++++++ popupapplet.h | 1 + 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/extenderitem.cpp b/extenderitem.cpp index 78f6fd962..d1b2ef63b 100644 --- a/extenderitem.cpp +++ b/extenderitem.cpp @@ -95,14 +95,14 @@ class ExtenderItemPrivate if (widget->geometry().intersects(rect)) { //is this widget a plasma view, a different view then our current one, //AND not a dashboardview? - Plasma::View *v = qobject_cast(widget); - Plasma::View *currentV = 0; + QGraphicsView *v = qobject_cast(widget); + QGraphicsView *currentV = 0; if (hostApplet()) { - currentV = qobject_cast(hostApplet()->containment()->view()); + currentV = qobject_cast(hostApplet()->containment()->view()); } - if (v && v != currentV - && v->containment() != hostApplet()->containment()) { + + if (v && v != currentV) { return true; } } @@ -474,7 +474,6 @@ bool ExtenderItem::isDetached() const void ExtenderItem::addAction(const QString &name, QAction *action) { - Q_ASSERT(action); d->actions[name] = action; @@ -653,6 +652,11 @@ void ExtenderItem::mousePressEvent(QGraphicsSceneMouseEvent *event) d->extender->itemHoverMoveEvent(this, d->extender->mapFromScene(mousePos)); } + //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); + QApplication::setOverrideCursor(Qt::ClosedHandCursor); } diff --git a/popupapplet.cpp b/popupapplet.cpp index 15faf38ce..7638fd268 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -29,6 +29,7 @@ #include #include +#include #include namespace Plasma @@ -136,6 +137,12 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints) connect(d->icon, SIGNAL(clicked()), this, SLOT(togglePopup())); } + //since we call this function when an extender's geometry gets updated, we want to avoid doing + //anything if the StartupCompletedConstraint hasn't been called yet. + if (!d->layout) { + return; + } + if (constraints & Plasma::FormFactorConstraint) { d->layout->removeAt(0); @@ -220,6 +227,11 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints) d->dialog->adjustSize(); d->layout->addItem(d->icon); + + setMinimumSize(QSizeF(0, 0)); + setMaximumWidth(containment()->size().height()); + setMaximumHeight(containment()->size().height()); + break; } } @@ -253,6 +265,21 @@ void PopupApplet::hidePopup() } } +void PopupApplet::widgetGeometryChanged() +{ + if (graphicsWidget()) { + //sizes are recalculated in the constraintsevent so let's just call that. + if (layout()) { + 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 751213484..0bc1429bd 100644 --- a/popupapplet.h +++ b/popupapplet.h @@ -51,6 +51,7 @@ public: public Q_SLOTS: void hidePopup(); + void widgetGeometryChanged(); protected: void constraintsEvent(Plasma::Constraints constraints);