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
This commit is contained in:
Rob Scheepmaker 2008-08-29 19:00:10 +00:00
parent 7c817fd06c
commit c066ea7027
5 changed files with 46 additions and 33 deletions

View File

@ -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<QGraphicsWidget*>(d->offscreenLayout->itemAt(i));
if (foundWidget == widget) {
d->offscreenLayout->removeAt(i);
d->offscreenLayout->invalidate();
}
}
}

View File

@ -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();

View File

@ -24,6 +24,7 @@
#include <QGraphicsSceneResizeEvent>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsLinearLayout>
#include <QLayout>
#include <QPainter>
#include <QTimer>
@ -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<QGraphicsView *>(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<Dialog*>(w);
if (dialog) {
if (dialog->isVisible() && dialog->geometry().contains(pos)) {
v = qobject_cast<QGraphicsView*>(dialog->layout()->itemAt(0)->widget());
if (v) {
return v->mapToScene(v->mapFromGlobal(pos));
}
}
} else {
v = qobject_cast<QGraphicsView *>(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);
}

View File

@ -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) {

View File

@ -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())