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
This commit is contained in:
Aaron J. Seigo 2008-12-23 19:38:52 +00:00
parent 4edaeb129d
commit 4d38cc53b6
3 changed files with 42 additions and 4 deletions

View File

@ -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);

View File

@ -41,6 +41,7 @@ public:
void prepareShowing(bool cueUpdate);
void moveTo(const QPoint &to);
bool autohide() const;
void setOrientation(Qt::Orientation);
protected:
void checkSize();

View File

@ -314,7 +314,12 @@ void ToolTipManagerPrivate::showToolTip()
justCreated = true;
}
//kDebug() << "about to show" << justCreated;
Containment *c = dynamic_cast<Containment *>(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()));