Detaching ExtenderItems from a Plasma::Dialog works now, but resizing the dialog isn't

always done correctly yet. I'm still looking into that.


svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=852535
This commit is contained in:
Rob Scheepmaker 2008-08-25 23:16:18 +00:00
parent dd7f1d815c
commit 56fc76d150
5 changed files with 43 additions and 11 deletions

View File

@ -1464,7 +1464,6 @@ QRect Applet::screenRect() const
QPoint tL = v->mapToGlobal(v->mapFromScene(pos()));
QPoint bR = v->mapToGlobal(v->mapFromScene(bottomRight));
kDebug() << "screenRect = " << QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y());
return QRect(QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y()));
}
}

View File

@ -90,7 +90,8 @@ void DialogPrivate::adjustView()
{
if (view && widget) {
view->setSceneRect(widget->mapToScene(widget->boundingRect()).boundingRect());
view->resize(widget->size().toSize());
view->resize(widget->minimumSize().toSize());
view->centerOn(widget);
}
}
@ -170,6 +171,12 @@ QGraphicsWidget *Dialog::graphicsWidget()
return d->widget;
}
void Dialog::adjustView()
{
d->adjustView();
adjustSize();
}
bool Dialog::eventFilter(QObject *watched, QEvent *event)
{
if (watched == d->widget && (event->type() == QEvent::GraphicsSceneResize ||

View File

@ -61,6 +61,13 @@ class PLASMA_EXPORT Dialog : public QWidget
void setGraphicsWidget(QGraphicsWidget *widget);
QGraphicsWidget *graphicsWidget();
public Q_SLOTS:
/**
* Call when the size of the graphicsWidget changes, to adjust the view and resize the
* dialog.
*/
void adjustView();
protected:
/**
* Reimplemented from QWidget

View File

@ -91,8 +91,15 @@ class ExtenderItemPrivate
//returns true if the applet overlaps with a different view then the current one.
bool leaveCurrentView(const QRect &rect)
{
if ((q->sceneBoundingRect().left() < 0)) {
//always leaveCurrentView when the item is in a Plasma::Dialog which can easy be
//seen by checking if it is in topleft quadrant and it's not just there because it's
//being viewed by the toplevel view.
return true;
}
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
if (widget->geometry().intersects(rect)) {
if (widget->geometry().intersects(rect) && widget->isVisible() && widget != toplevel) {
//is this widget a plasma view, a different view then our current one,
//AND not a dashboardview?
QGraphicsView *v = qobject_cast<QGraphicsView*>(widget);
@ -639,10 +646,7 @@ void ExtenderItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
Applet *parentApplet = d->hostApplet();
QGraphicsView *v = parentApplet->view();
QPoint localpos = v->mapFromScene(scenePos());
d->mousePos = event->screenPos() - v->mapToGlobal(localpos);
QPointF mousePos = v->mapToScene(v->mapFromGlobal(event->screenPos()));
d->mousePos = event->pos().toPoint();
parentApplet->raise();
setZValue(parentApplet->zValue());
@ -651,7 +655,7 @@ void ExtenderItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (d->extender) {
d->extender->itemHoverEnterEvent(this);
d->extender->itemHoverMoveEvent(this, d->extender->mapFromScene(mousePos));
d->extender->itemHoverMoveEvent(this, d->extender->mapFromScene(event->scenePos()));
}
//call the move event, since that spawns a toplevel view when this extender item is in a
@ -690,8 +694,11 @@ void ExtenderItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Corona *corona = d->hostApplet()->containment()->corona();
d->toplevel = new QGraphicsView(corona, 0);
//TODO: use addOffscreenWidget
setParentItem(0);
setPos(-12000, -12000);
if (sceneBoundingRect().left() > 0) {
setParentItem(0);
//only move to topleft quadrant if it isn't there allready.
setPos(-12000, -12000);
}
d->toplevel->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint);
@ -711,6 +718,7 @@ void ExtenderItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
//move the toplevel view.
d->toplevel->setSceneRect(sceneBoundingRect());
d->toplevel->setGeometry(screenRect);
} else {
setParentItem(d->hostApplet());

View File

@ -30,6 +30,7 @@
#include <plasma/dialog.h>
#include <plasma/corona.h>
#include <plasma/containment.h>
#include <plasma/extender.h>
#include <plasma/widgets/icon.h>
namespace Plasma
@ -240,7 +241,8 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
void PopupApplet::showPopup(uint popupDuration)
{
if (d->dialog && (formFactor() == Horizontal || formFactor() == Vertical)) {
d->dialog->move(popupPosition(d->dialog->sizeHint()));
d->dialog->adjustView();
d->dialog->move(popupPosition(d->dialog->size()));
d->dialog->show();
if (d->timer) {
@ -275,6 +277,15 @@ void PopupApplet::widgetGeometryChanged()
//resize vertically if necesarry.
if (formFactor() == Plasma::MediaCenter || formFactor() == Plasma::Planar) {
resize(QSizeF(size().width(), minimumHeight()));
} else {
if (graphicsWidget()) {
graphicsWidget()->resize(graphicsWidget()->minimumSize());
graphicsWidget()->update();
}
if (d->dialog) {
d->dialog->adjustView();
d->dialog->move(popupPosition(d->dialog->size()));
}
}
}
}