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:
parent
e77d0a39a9
commit
ee37d19811
@ -82,7 +82,9 @@ void ToolTip::show(const QPoint &location, Plasma::Widget *widget)
|
||||
{
|
||||
d->currentWidget = widget;
|
||||
setData(widget->toolTip());
|
||||
move(location.x(), location.y() - sizeHint().height());
|
||||
|
||||
move(location.x(), location.y());
|
||||
|
||||
if (d->isShown) {
|
||||
// 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
|
||||
|
@ -38,6 +38,8 @@
|
||||
|
||||
#include "layouts/freelayout.h"
|
||||
#include "plasma/plasma.h"
|
||||
#include "plasma/view.h"
|
||||
#include "plasma/containment.h"
|
||||
#include "tooltip_p.h"
|
||||
|
||||
namespace Plasma
|
||||
@ -504,9 +506,7 @@ void Widget::setToolTip(const ToolTipData &tip)
|
||||
{
|
||||
d->toolTip = tip;
|
||||
if (ToolTip::self()->currentWidget() == this) {
|
||||
QPoint viewPos = view()->mapFromScene(scenePos());
|
||||
QPoint globalPos = view()->mapToGlobal(viewPos);
|
||||
ToolTip::self()->show(globalPos, this);
|
||||
ToolTip::self()->show(popupPosition(ToolTip::self()->sizeHint()), 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)
|
||||
{
|
||||
// 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.
|
||||
QGraphicsView *parentView = view();
|
||||
if (parentView) {
|
||||
QPoint viewPos = parentView->mapFromScene(scenePos());
|
||||
QPoint globalPos = parentView->mapToGlobal(viewPos);
|
||||
ToolTip::self()->show(globalPos, this);
|
||||
ToolTip *tip = ToolTip::self();
|
||||
tip->adjustSize();
|
||||
tip->show(popupPosition(tip->size()), this);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -288,6 +288,14 @@ TODO: implement once we decide how to handle the font system
|
||||
*/
|
||||
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:
|
||||
/**
|
||||
* Paints the widget
|
||||
|
Loading…
Reference in New Issue
Block a user