From 1b7a9a14e0a43c48b07abc6521bc9c7a7ce7ea66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9nard?= Date: Mon, 14 Apr 2008 14:50:02 +0000 Subject: [PATCH] +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 --- CMakeLists.txt | 1 - applet.cpp | 88 ++++++++++++++++++++++++++++++++- applet.h | 29 ++++++++++- widgets/widget.cpp | 119 ++------------------------------------------- widgets/widget.h | 48 +++--------------- 5 files changed, 125 insertions(+), 160 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4566a6c1a..82d20dacd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/applet.cpp b/applet.cpp index de665b60f..69bfcb5da 100644 --- a/applet.cpp +++ b/applet.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -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(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(); diff --git a/applet.h b/applet.h index e54d758f2..fd9c15388 100644 --- a/applet.h +++ b/applet.h @@ -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; diff --git a/widgets/widget.cpp b/widgets/widget.cpp index 2544a89c9..fb2910922 100644 --- a/widgets/widget.cpp +++ b/widgets/widget.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -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(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 diff --git a/widgets/widget.h b/widgets/widget.h index 4160263cd..1401444dd 100644 --- a/widgets/widget.h +++ b/widgets/widget.h @@ -145,26 +145,8 @@ public: Q_INVOKABLE void addChild(Widget *widget); 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 &);