diff --git a/dialog.cpp b/dialog.cpp index 1f540e194..c6f0c6d89 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -171,24 +171,27 @@ void Dialog::position(QGraphicsSceneEvent *event, const QRectF boundingRect, QPo QWidget *viewWidget = event->widget() ? event->widget()->parentWidget() : 0; //QPointF scenePos = mapToScene(boundingRect.topLeft()); QGraphicsView *view = qobject_cast(viewWidget); - if (view) { - QPoint viewPos = view->mapFromScene(scenePos); - QPoint globalPos = view->mapToGlobal(viewPos); - if ((globalPos.ry()-height())< 0) { + position(view,boundingRect,scenePos); +} - //scenePos = mapToScene(boundingRect.bottomLeft()); - scenePos = QPointF(scenePos.x() + boundingRect.width(), scenePos.y() + boundingRect.height()); - viewPos = view->mapFromScene(scenePos); - globalPos = view->mapToGlobal(viewPos)+QPoint(0,10); - } - else { - globalPos.ry() -= (height()+10); - } - if ((globalPos.rx() + width()) > view->width()) { - globalPos.rx()-=((globalPos.rx() + width())-view->width()); - } - move(globalPos); - kDebug() << globalPos; +void Dialog::position(QGraphicsView * view,const QRectF boundingRect,QPointF scenePos) +{ + if (view) { + QPoint viewPos = view->mapFromScene(scenePos); + QPoint globalPos = view->mapToGlobal(viewPos); + if ((globalPos.ry()-height())< 0) { + scenePos = QPointF(scenePos.x() + boundingRect.width(), scenePos.y() + boundingRect.height()); + viewPos = view->mapFromScene(scenePos); + globalPos = view->mapToGlobal(viewPos)+QPoint(0,10); + } + else { + globalPos.ry() -= (height()+10); + } + if ((globalPos.rx() + width()) > view->width()) { + globalPos.rx()-=((globalPos.rx() + width())-view->width()); + } + move(globalPos); + kDebug() << globalPos; } } diff --git a/dialog.h b/dialog.h index dd91e64a5..7512d037c 100644 --- a/dialog.h +++ b/dialog.h @@ -24,6 +24,7 @@ #include #include +#include #include @@ -62,6 +63,13 @@ class PLASMA_EXPORT Dialog : public QWidget * @arg scenePos the absolute position on the scene. */ void position(QGraphicsSceneEvent *event, const QRectF boundingRect, QPointF scenePos); + + /** + * @arg view The QGV where is displayed the applet + * @arg scenePos the absolute position on the scene. + * @arg boundingRect the boundingRect() from the applet. + */ + void position(QGraphicsView * view,const QRectF boundingRect,QPointF scenePos); protected: /**