first crude direction support for tooltips

it still needs support for diagonal movements
This commit is contained in:
Marco Martin 2014-01-09 15:09:53 +01:00
parent 3f094d59a5
commit c53a00ce4b
3 changed files with 51 additions and 1 deletions

View File

@ -78,6 +78,27 @@ void ToolTip::showToolTip()
}
dlg->setMainItem(mainItem());
//heuristics for knowing the diration
Plasma::Types::Direction dir = Plasma::Types::Up;
QPoint pos = mapToScene(QPoint(0, 0)).toPoint();
if (window() && window()->screen()) {
pos = window()->mapToGlobal(pos);
}
QPoint popupPos = dlg->popupPosition(this, Qt::AlignCenter);
if (pos.y() + height() <= popupPos.y()) {
dir = Plasma::Types::Down;
} else if (pos.x() + width() <= popupPos.x()) {
dir = Plasma::Types::Right;
} else if (pos.y() >= popupPos.y() + dlg->height()) {
dir = Plasma::Types::Up;
} else if (pos.x() >= popupPos.x() + dlg->width()) {
dir = Plasma::Types::Left;
}
dlg->setDirection(dir);
dlg->setVisible(true);
dlg->setVisualParent(this);
}

View File

@ -34,10 +34,12 @@ ToolTipDialog::ToolTipDialog(QQuickItem *parent)
: DialogProxy(parent),
m_qmlObject(0),
m_animation(0),
m_hideTimeout(4000)
m_hideTimeout(4000),
m_direction(Plasma::Types::Up)
{
setFlags(Qt::ToolTip);
setLocation(Plasma::Types::Floating);
setDirection(Plasma::Types::Up);
m_frameSvgItem->setImagePath("widgets/tooltip");
m_showTimer = new QTimer(this);
@ -70,6 +72,16 @@ QQuickItem *ToolTipDialog::loadDefaultItem()
return qobject_cast<QQuickItem *>(m_qmlObject->rootObject());
}
Plasma::Types::Direction ToolTipDialog::direction() const
{
return m_direction;
}
void ToolTipDialog::setDirection(Plasma::Types::Direction loc)
{
m_direction = loc;
}
void ToolTipDialog::showEvent(QShowEvent *event)
{
m_showTimer->start(m_hideTimeout);
@ -89,6 +101,19 @@ void ToolTipDialog::adjustPosition(const QPoint &point)
m_animation->setDuration(250);
}
switch (m_direction) {
case Plasma::Types::Left:
case Plasma::Types::Right:
setX(point.x());
break;
case Plasma::Types::Up:
case Plasma::Types::Down:
setY(point.y());
break;
default:
break;
}
m_animation->setStartValue(position());
m_animation->setEndValue(point);
m_animation->start();

View File

@ -47,6 +47,9 @@ public:
QQuickItem *loadDefaultItem();
Plasma::Types::Direction direction() const;
void setDirection(Plasma::Types::Direction loc);
/**
* animate the position change if visible
*/
@ -68,6 +71,7 @@ private:
QTimer *m_showTimer;
QPropertyAnimation *m_animation;
int m_hideTimeout;
Plasma::Types::Direction m_direction;
};
#endif