+bye bye paintwidget method

+remove tooltip that will be replaced by the tooltip manager
+port some used stuff in applet class

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=796924
This commit is contained in:
Alexis Ménard 2008-04-14 14:50:02 +00:00
parent da49777a70
commit 1b7a9a14e0
5 changed files with 125 additions and 160 deletions

View File

@ -59,7 +59,6 @@ set(plasma_LIB_SRCS
scripting/runnerscript.cpp
scripting/scriptengine.cpp
widgets/icon.cpp
widgets/tooltip.cpp
widgets/widget.cpp
widgets/webcontent.cpp
)

View File

@ -38,6 +38,7 @@
#include <QPushButton>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsLinearLayout>
#include <QDesktopWidget>
#include <QGraphicsProxyWidget>
#include <KIcon>
@ -521,6 +522,91 @@ const Package* Applet::package() const
return d->package;
}
QGraphicsView *Applet::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()) ||
view->sceneRect().contains(scenePos())) {
return view;
}
}
return 0;
}
QRectF Applet::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 Applet::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);
}
QPoint Applet::popupPosition(const QSize &s) const
{
QGraphicsView *v = view();
Q_ASSERT(v);
QPoint pos = v->mapFromScene(scenePos());
pos = v->mapToGlobal(pos);
kDebug() << "==> position is" << scenePos() << v->mapFromScene(scenePos()) << pos;
Plasma::View *pv = dynamic_cast<Plasma::View *>(v);
Plasma::Location loc = Floating;
if (pv) {
loc = pv->containment()->location();
}
switch (loc) {
case BottomEdge:
pos = QPoint(pos.x(), pos.y() - s.height());
break;
case TopEdge:
pos = QPoint(pos.x(), pos.y() + (int)size().height());
break;
case LeftEdge:
pos = QPoint(pos.x() + (int)size().width(), pos.y());
break;
case RightEdge:
pos = QPoint(pos.x() - s.width(), pos.y());
break;
default:
if (pos.y() - s.height() > 0) {
pos = QPoint(pos.x(), pos.y() - s.height());
} else {
pos = QPoint(pos.x(), pos.y() + (int)size().height());
}
}
//are we out of screen?
QRect screenRect = QApplication::desktop()->screenGeometry(pv ? pv->containment()->screen() : -1);
kDebug() << "==> rect for" << (pv ? pv->containment()->screen() : -1) << "is" << screenRect;
if (pos.rx() + s.width() > screenRect.right()) {
pos.rx() -= ((pos.rx() + s.width()) - screenRect.right());
}
if (pos.ry() + s.height() > screenRect.bottom()) {
pos.ry() -= ((pos.ry() + s.height()) - screenRect.bottom());
}
pos.rx() = qMax(0, pos.rx());
return pos;
}
void Applet::updateConstraints(Plasma::Constraints constraints)
{
d->scheduleConstraintsUpdate(constraints, this);
@ -905,7 +991,7 @@ QColor Applet::color() const
}
}
void Applet::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if (d->shadow && d->shadow->shadowedSize() != boundingRect().size()) {
//kDebug() << "sizes are " << d->shadow->shadowedSize() << boundingRect().size();

View File

@ -193,6 +193,33 @@ class PLASMA_EXPORT Applet : public Widget
**/
const Package* package() const;
/**
* 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;
/**
* Recomended position for a popup window like a menu or a tooltip
* given its size
* @param s size of the popup
* @returns recomended position
*/
QPoint popupPosition(const QSize &s) const;
/**
* Called when any of the geometry constraints have been updated.
* This method calls constraintsUpdated, which may be reimplemented,
@ -713,7 +740,7 @@ class PLASMA_EXPORT Applet : public Widget
/**
* Reimplemented from QGraphicsItem
**/
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
class Private;
Private* const d;

View File

@ -32,7 +32,6 @@
#include <QList>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QDesktopWidget>
#include <QGraphicsLayout>
#include <QGraphicsLinearLayout>
@ -78,38 +77,6 @@ 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()) ||
view->sceneRect().contains(scenePos())) {
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)
@ -134,9 +101,11 @@ Widget::Widget(QGraphicsItem *parent, QObject* parentObject)
Widget::~Widget()
{
#ifdef TOOLTIPMANAGER
if (ToolTip::self()->currentWidget() == this) {
ToolTip::self()->hide();
}
#endif
delete d;
}
@ -226,16 +195,9 @@ void Widget::addChild(Widget *w)
void Widget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
/*
NOTE: put this back if we end up needing to control when things paint due to, e.g. zooming.
if (!d->shouldPaint(painter, transform())) {
return;
}
*/
paintWidget(painter, option, widget);
}
#ifdef TOOLTIPMANAGER
const ToolTipData* Widget::toolTip() const
{
return d->toolTip;
@ -266,79 +228,6 @@ void Widget::updateToolTip(bool update)
Q_UNUSED(update)
}
void Widget::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(painter);
Q_UNUSED(option);
Q_UNUSED(widget);
// Replaced by widget's own function
}
QPoint Widget::popupPosition(const QSize &s) const
{
QGraphicsView *v = view();
Q_ASSERT(v);
QPoint pos = v->mapFromScene(scenePos());
pos = v->mapToGlobal(pos);
kDebug() << "==> position is" << scenePos() << v->mapFromScene(scenePos()) << pos;
Plasma::View *pv = dynamic_cast<Plasma::View *>(v);
Plasma::Location loc = Floating;
if (pv) {
loc = pv->containment()->location();
}
switch (loc) {
case BottomEdge:
pos = QPoint(pos.x(), pos.y() - s.height());
break;
case TopEdge:
pos = QPoint(pos.x(), pos.y() + (int)size().height());
break;
case LeftEdge:
pos = QPoint(pos.x() + (int)size().width(), pos.y());
break;
case RightEdge:
pos = QPoint(pos.x() - s.width(), pos.y());
break;
default:
if (pos.y() - s.height() > 0) {
pos = QPoint(pos.x(), pos.y() - s.height());
} else {
pos = QPoint(pos.x(), pos.y() + (int)size().height());
}
}
//are we out of screen?
QRect screenRect = QApplication::desktop()->screenGeometry(pv ? pv->containment()->screen() : -1);
kDebug() << "==> rect for" << (pv ? pv->containment()->screen() : -1) << "is" << screenRect;
if (pos.rx() + s.width() > screenRect.right()) {
pos.rx() -= ((pos.rx() + s.width()) - screenRect.right());
}
if (pos.ry() + s.height() > screenRect.bottom()) {
pos.ry() -= ((pos.ry() + s.height()) - screenRect.bottom());
}
pos.rx() = qMax(0, pos.rx());
return pos;
}
void Widget::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
// HACK: QGraphicsItem's documentation says that the event will be passed
// to the parent if it's not handled, but it isn't passed. This can be
// removed when Qt4.4 becomes a requirement. See Qt bug #176902.
Widget *parentWidget = parent();
if (parentWidget) {
parentWidget->contextMenuEvent(event);
}
}
bool Widget::sceneEvent(QEvent *event)
{
switch (event->type()) {
@ -381,6 +270,6 @@ bool Widget::sceneEvent(QEvent *event)
return QGraphicsItem::sceneEvent(event);
}
#endif
} // Plasma namespace

View File

@ -146,25 +146,7 @@ public:
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;
#ifdef TOOLTIPMANAGER
/**
* The Data from the tooltip
* @returns A ToolTip::Data object with current information
@ -187,30 +169,12 @@ public:
*/
virtual void updateToolTip(bool update);
/**
* Recomended position for a popup window like a menu or a tooltip
* given its size
* @param s size of the popup
* @returns recomended position
*/
QPoint popupPosition(const QSize &s) const;
/**
* Reimplemented from QGraphicsItem
*/
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
#endif
protected:
/**
* Paints the widget
* @param painter the QPainter to use to paint.
* @param option the style option used to give specific info on the item being dawn.
* @param widget the parent QWidget (most likely the Corona)
*/
virtual void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
virtual bool sceneEvent(QEvent *event);
#ifdef TOOLTIPMANAGER
virtual bool sceneEvent(QEvent *event);
#endif
private:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void setSize(const QSizeF &);