From 4d38cc53b6560c0c5f57c696c8eb5e65d1507f45 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 23 Dec 2008 19:38:52 +0000 Subject: [PATCH] make tooltips orientation aware; fixes problems with panel autohiding as well as avoids some unecessary painting in vertical panels BUG:178552 svn path=/trunk/KDE/kdelibs/; revision=900840 --- private/tooltip.cpp | 38 +++++++++++++++++++++++++++++++++++--- private/tooltip_p.h | 1 + tooltipmanager.cpp | 7 ++++++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/private/tooltip.cpp b/private/tooltip.cpp index b94a039b7..c1d8f4651 100644 --- a/private/tooltip.cpp +++ b/private/tooltip.cpp @@ -75,7 +75,7 @@ public: { return document->size().toSize(); } - + QSize maximumSizeHint() const { return minimumSizeHint(); @@ -100,6 +100,7 @@ class ToolTipPrivate preview(0), source(0), timeline(0), + orientation(Qt::Horizontal), autohide(true) { } @@ -111,6 +112,7 @@ class ToolTipPrivate QTimeLine *timeline; QPoint to; QPoint from; + Qt::Orientation orientation; bool autohide; }; @@ -185,14 +187,39 @@ void ToolTip::checkSize() resize(hint); #endif */ + int deltaX = 0; + int deltaY = 0; + if (d->orientation == Qt::Horizontal) { /* kDebug() << "resizing from" << current << "to" << hint << "and moving from" << pos() << "to" << x() << y() + (current.height() - hint.height()) << current.height() - hint.height(); */ - resize(hint); - move(x(), y() + (current.height() - size().height())); + deltaY = current.height() - hint.height(); + } else { + /* + kDebug() << "vertical resizing from" << current << "to" << hint + << "and moving from" << pos() << "to" + << x() + (current.width() - hint.width()) << y() + << current.width() - hint.width(); */ + deltaX = current.width() - hint.width(); + } + + // resize then move if we're getting smaller, vice versa when getting bigger + // this prevents overlap with the item in the smaller case, and a repaint of + // the tipped item when getting bigger + bool resizeFirst = deltaY > 0 || deltaX > 0; + + if (resizeFirst) { + resize(hint); + } + + move(x() + deltaX, y() + deltaY); + + if (!resizeFirst) { + resize(hint); + } } } @@ -292,6 +319,11 @@ bool ToolTip::autohide() const return d->autohide; } +void ToolTip::setOrientation(Qt::Orientation orientation) +{ + d->orientation = orientation; +} + void ToolTip::updateTheme() { const int topHeight = d->background->marginSize(Plasma::TopMargin); diff --git a/private/tooltip_p.h b/private/tooltip_p.h index c6f304130..6b44be693 100644 --- a/private/tooltip_p.h +++ b/private/tooltip_p.h @@ -41,6 +41,7 @@ public: void prepareShowing(bool cueUpdate); void moveTo(const QPoint &to); bool autohide() const; + void setOrientation(Qt::Orientation); protected: void checkSize(); diff --git a/tooltipmanager.cpp b/tooltipmanager.cpp index c2b4a88ed..b148ba7bb 100644 --- a/tooltipmanager.cpp +++ b/tooltipmanager.cpp @@ -314,7 +314,12 @@ void ToolTipManagerPrivate::showToolTip() justCreated = true; } - //kDebug() << "about to show" << justCreated; + Containment *c = dynamic_cast(currentWidget->topLevelItem()); + kDebug() << "about to show" << justCreated << (QObject*)c; + if (c) { + tipWidget->setOrientation(c->formFactor() == Vertical ? Qt::Vertical : Qt::Horizontal); + } + tipWidget->setContent(currentWidget, tooltip.value()); tipWidget->prepareShowing(!justCreated); tipWidget->moveTo(ToolTipManager::self()->m_corona->popupPosition(currentWidget, tipWidget->size()));