Added methods for gaining information about the view. This is useful for
applets such as systemtray and tasks that need to know about global geometry. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=746172
This commit is contained in:
parent
059505f639
commit
10af4df668
@ -25,6 +25,8 @@
|
||||
#include <limits>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QList>
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
@ -76,6 +78,36 @@ QGraphicsItem* Widget::graphicsItem()
|
||||
return this;
|
||||
}
|
||||
|
||||
QGraphicsView *Widget::view() const
|
||||
{
|
||||
// It's assumed that we won't be visible on more than one view here.
|
||||
// Anything that actually needs view() should only really care about
|
||||
// one of them anyway though.
|
||||
if (!scene()) {
|
||||
return 0;
|
||||
}
|
||||
foreach (QGraphicsView *view, scene()->views()) {
|
||||
if (view->sceneRect().intersects(sceneBoundingRect())) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRectF Widget::mapFromView(const QGraphicsView *view, const QRect &rect) const
|
||||
{
|
||||
// TODO: Confirm that adjusted() is needed and is not covering for some
|
||||
// issue elsewhere
|
||||
return mapFromScene(view->mapToScene(rect)).boundingRect().adjusted(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
QRect Widget::mapToView(const QGraphicsView *view, const QRectF &rect) const
|
||||
{
|
||||
// TODO: Confirm that adjusted() is needed and is not covering for some
|
||||
// issue elsewhere
|
||||
return view->mapFromScene(mapToScene(rect)).boundingRect().adjusted(0, 0, -1, -1);
|
||||
}
|
||||
|
||||
bool Widget::Private::shouldPaint(QPainter *painter, const QTransform &transform)
|
||||
{
|
||||
Q_UNUSED(painter)
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include <plasma/layouts/layoutitem.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QGraphicsView;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
@ -242,6 +244,25 @@ TODO: implement once we decide how to handle the font system
|
||||
|
||||
virtual QGraphicsItem* graphicsItem();
|
||||
|
||||
/**
|
||||
* Returns the view this widget is visible on
|
||||
*/
|
||||
QGraphicsView *view() const;
|
||||
|
||||
/**
|
||||
* Maps a QRect from a view's coordinates to local coordinates.
|
||||
* @param view the view from which rect should be mapped
|
||||
* @param rect the rect to be mapped
|
||||
*/
|
||||
QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
|
||||
|
||||
/**
|
||||
* Maps a QRectF from local coordinates to a view's coordinates.
|
||||
* @param view the view to which rect should be mapped
|
||||
* @param rect the rect to be mapped
|
||||
*/
|
||||
QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Paints the widget
|
||||
|
Loading…
Reference in New Issue
Block a user