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; QWidget *viewWidget = event->widget() ? event->widget()->parentWidget() : 0;
//QPointF scenePos = mapToScene(boundingRect.topLeft()); //QPointF scenePos = mapToScene(boundingRect.topLeft());
QGraphicsView *view = qobject_cast<QGraphicsView*>(viewWidget); QGraphicsView *view = qobject_cast<QGraphicsView*>(viewWidget);
if (view) { position(view,boundingRect,scenePos);
QPoint viewPos = view->mapFromScene(scenePos); }
QPoint globalPos = view->mapToGlobal(viewPos);
if ((globalPos.ry()-height())< 0) {
//scenePos = mapToScene(boundingRect.bottomLeft()); void Dialog::position(QGraphicsView * view,const QRectF boundingRect,QPointF scenePos)
scenePos = QPointF(scenePos.x() + boundingRect.width(), scenePos.y() + boundingRect.height()); {
viewPos = view->mapFromScene(scenePos); if (view) {
globalPos = view->mapToGlobal(viewPos)+QPoint(0,10); QPoint viewPos = view->mapFromScene(scenePos);
} QPoint globalPos = view->mapToGlobal(viewPos);
else { if ((globalPos.ry()-height())< 0) {
globalPos.ry() -= (height()+10); scenePos = QPointF(scenePos.x() + boundingRect.width(), scenePos.y() + boundingRect.height());
} viewPos = view->mapFromScene(scenePos);
if ((globalPos.rx() + width()) > view->width()) { globalPos = view->mapToGlobal(viewPos)+QPoint(0,10);
globalPos.rx()-=((globalPos.rx() + width())-view->width()); }
} else {
move(globalPos); globalPos.ry() -= (height()+10);
kDebug() << globalPos; }
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/QWidget>
#include <QtGui/QGraphicsSceneEvent> #include <QtGui/QGraphicsSceneEvent>
#include <QtGui/QGraphicsView>
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
@ -62,6 +63,13 @@ class PLASMA_EXPORT Dialog : public QWidget
* @arg scenePos the absolute position on the scene. * @arg scenePos the absolute position on the scene.
*/ */
void position(QGraphicsSceneEvent *event, const QRectF boundingRect, QPointF scenePos); 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: protected:
/** /**