better positioning of tooltips in case of panels not in bottom position and a new function in widget called popupPosition(const QSize s) this will be used every time a tooltip or popup menu has to be positioned

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=764299
This commit is contained in:
Marco Martin 2008-01-21 11:42:08 +00:00
parent e77d0a39a9
commit ee37d19811
3 changed files with 46 additions and 7 deletions

View File

@ -82,7 +82,9 @@ void ToolTip::show(const QPoint &location, Plasma::Widget *widget)
{ {
d->currentWidget = widget; d->currentWidget = widget;
setData(widget->toolTip()); setData(widget->toolTip());
move(location.x(), location.y() - sizeHint().height());
move(location.x(), location.y());
if (d->isShown) { if (d->isShown) {
// Don't delay if the tooltip is already shown(i.e. moving from one task to another) // Don't delay if the tooltip is already shown(i.e. moving from one task to another)
// Qt doesn't seem to like visible tooltips moving though, so hide it and then // Qt doesn't seem to like visible tooltips moving though, so hide it and then

View File

@ -38,6 +38,8 @@
#include "layouts/freelayout.h" #include "layouts/freelayout.h"
#include "plasma/plasma.h" #include "plasma/plasma.h"
#include "plasma/view.h"
#include "plasma/containment.h"
#include "tooltip_p.h" #include "tooltip_p.h"
namespace Plasma namespace Plasma
@ -504,9 +506,7 @@ void Widget::setToolTip(const ToolTipData &tip)
{ {
d->toolTip = tip; d->toolTip = tip;
if (ToolTip::self()->currentWidget() == this) { if (ToolTip::self()->currentWidget() == this) {
QPoint viewPos = view()->mapFromScene(scenePos()); ToolTip::self()->show(popupPosition(ToolTip::self()->sizeHint()), this);
QPoint globalPos = view()->mapToGlobal(viewPos);
ToolTip::self()->show(globalPos, this);
} }
} }
@ -543,6 +543,35 @@ void Widget::managingLayoutChanged()
} }
} }
QPoint Widget::popupPosition(const QSize s) const
{
QPoint pos = view()->mapFromScene(scenePos());
pos = view()->mapToGlobal(pos);
Plasma::View *pv = dynamic_cast<Plasma::View *>(view());
Plasma::Location loc = Floating;
if (pv) {
loc = pv->containment()->location();
}
switch (loc) {
case BottomEdge:
return QPoint(pos.x(), pos.y() - s.height());
case TopEdge:
return QPoint(pos.x(), pos.y() + (int)size().height());
case LeftEdge:
return QPoint(pos.x() + (int)size().width(), pos.y());
case RightEdge:
return QPoint(pos.x() - s.width(), pos.y());
default:
if (pos.y() > 0) {
return QPoint(pos.x(), pos.y()-s.height());
} else {
return QPoint(pos.x(), pos.y()+(int)size().height());
}
}
}
void Widget::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void Widget::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{ {
// HACK: QGraphicsItem's documentation says that the event will be passed // HACK: QGraphicsItem's documentation says that the event will be passed
@ -578,9 +607,9 @@ bool Widget::sceneEvent(QEvent *event)
// initialized, in which case view() will return 0. // initialized, in which case view() will return 0.
QGraphicsView *parentView = view(); QGraphicsView *parentView = view();
if (parentView) { if (parentView) {
QPoint viewPos = parentView->mapFromScene(scenePos()); ToolTip *tip = ToolTip::self();
QPoint globalPos = parentView->mapToGlobal(viewPos); tip->adjustSize();
ToolTip::self()->show(globalPos, this); tip->show(popupPosition(tip->size()), this);
} }
break; break;

View File

@ -288,6 +288,14 @@ TODO: implement once we decide how to handle the font system
*/ */
void setToolTip( const ToolTipData &dt ); void setToolTip( const ToolTipData &dt );
/**
* 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;
protected: protected:
/** /**
* Paints the widget * Paints the widget