Add a method to position the dialog just with the QGV

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=754467
This commit is contained in:
Alexis Ménard 2007-12-29 21:38:00 +00:00
parent 87429288bc
commit b7e978d04c
2 changed files with 28 additions and 17 deletions

View File

@ -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<QGraphicsView*>(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;
}
}

View File

@ -24,6 +24,7 @@
#include <QtGui/QWidget>
#include <QtGui/QGraphicsSceneEvent>
#include <QtGui/QGraphicsView>
#include <plasma/plasma_export.h>
@ -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:
/**