* try not to call view() if possible

* code clarifications, simplicity++

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=862852
This commit is contained in:
Aaron J. Seigo 2008-09-20 06:08:28 +00:00
parent f9244362a4
commit c302aa3ff4
2 changed files with 25 additions and 30 deletions

View File

@ -362,17 +362,19 @@ void AppletPrivate::appletAnimationComplete(QGraphicsItem *item, Plasma::Animato
void AppletPrivate::selectItemToDestroy() void AppletPrivate::selectItemToDestroy()
{ {
//FIXME: this will not work nicely with multiple screens and being zoomed out! //FIXME: this will not work nicely with multiple screens and being zoomed out!
if (q->isContainment() && if (q->isContainment()) {
q->view() && q->view()->transform().isScaling() && QGraphicsView *view = q->view();
q->scene()->focusItem() != q) { if (view && view->transform().isScaling() &&
QGraphicsItem *focus = q->scene()->focusItem(); q->scene()->focusItem() != q) {
QGraphicsItem *focus = q->scene()->focusItem();
if (focus) { if (focus) {
Containment *toDestroy = dynamic_cast<Containment*>(focus->topLevelItem()); Containment *toDestroy = dynamic_cast<Containment*>(focus->topLevelItem());
if (toDestroy) { if (toDestroy) {
toDestroy->destroy(); toDestroy->destroy();
return; return;
}
} }
} }
} }
@ -447,12 +449,12 @@ QGraphicsView *Applet::view() const
QGraphicsView *found = 0; QGraphicsView *found = 0;
QGraphicsView *possibleFind = 0; QGraphicsView *possibleFind = 0;
//kDebug() << "looking through" << scene()->views().count() << "views";
foreach (QGraphicsView *view, scene()->views()) { foreach (QGraphicsView *view, scene()->views()) {
kDebug() << "checking" << view->sceneRect() << "against" << sceneBoundingRect() //kDebug() << " checking" << view << view->sceneRect() << "against" << sceneBoundingRect() << scenePos();
<< scenePos();
if (view->sceneRect().intersects(sceneBoundingRect()) || if (view->sceneRect().intersects(sceneBoundingRect()) ||
view->sceneRect().contains(scenePos())) { view->sceneRect().contains(scenePos())) {
kDebug() << "found something!" << view->isActiveWindow(); //kDebug() << " found something!" << view->isActiveWindow();
if (view->isActiveWindow()) { if (view->isActiveWindow()) {
found = view; found = view;
} else { } else {
@ -460,6 +462,7 @@ QGraphicsView *Applet::view() const
} }
} }
} }
return found ? found : possibleFind; return found ? found : possibleFind;
} }
@ -1502,26 +1505,19 @@ void Applet::timerEvent(QTimerEvent *event)
QRect Applet::screenRect() const QRect Applet::screenRect() const
{ {
QPointF bottomRight = pos(); QGraphicsView *v = view();
bottomRight.setX(bottomRight.x() + size().width());
bottomRight.setY(bottomRight.y() + size().height());
Containment *c; if (v) {
c = containment(); QPointF bottomRight = pos();
bottomRight.rx() += size().width();
bottomRight.ry() += size().height();
if (c) { QPoint tL = v->mapToGlobal(v->mapFromScene(pos()));
QGraphicsView *v; QPoint bR = v->mapToGlobal(v->mapFromScene(bottomRight));
v = c->view(); return QRect(QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y()));
if (v) {
QPoint tL = v->mapToGlobal(v->mapFromScene(pos()));
QPoint bR = v->mapToGlobal(v->mapFromScene(bottomRight));
return QRect(QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y()));
}
} }
//The applet isn't in any containment, or in a containment that doesn't have a view on it. //The applet doesn't have a view on it.
//So a screenRect isn't relevant. //So a screenRect isn't relevant.
return QRect(QPoint(0, 0), QSize(0, 0)); return QRect(QPoint(0, 0), QSize(0, 0));
} }

View File

@ -623,8 +623,7 @@ void AppletHandle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
//set the screenRect correctly. the screenRect contains the bounding //set the screenRect correctly. the screenRect contains the bounding
//rect of the applet in screen coordinates. m_mousePos contains the //rect of the applet in screen coordinates. m_mousePos contains the
//position of the mouse relative to the applet, in screen coords. //position of the mouse relative to the applet, in screen coords.
QRect screenRect = QRect(event->screenPos() - m_mousePos, QRect screenRect = QRect(event->screenPos() - m_mousePos, m_applet->size().toSize());
m_applet->screenRect().size());
//kDebug() << "screenRect = " << screenRect; //kDebug() << "screenRect = " << screenRect;