make sure animation is disabled the first time

make sure the animation is disabled when the tooltip appears
for the first time.
since the correct implicitsizes can be calculated only when the
tooltip window is visible, we need to show the tooltip window
then calculate the final size and position, and last move it
*without animations*

Change-Id: I2d0f653e860104f17a62203565d5002a16d0dfae
reviewed-by: David Edmundson <kde@davidedmundson.co.uk>
BUG:341933
This commit is contained in:
Marco Martin 2015-01-16 18:01:17 +01:00
parent 99128b73eb
commit 05cea81fdd
3 changed files with 21 additions and 4 deletions

View File

@ -143,11 +143,13 @@ void ToolTip::showToolTip()
mainItem()->setVisible(true); mainItem()->setVisible(true);
} }
//if the dialog is not currently visible, disable the animated repositioning
dlg->setAnimationsEnabled(dlg->isVisible());
dlg->show();
dlg->setLocation(location); dlg->setLocation(location);
dlg->setMainItem(mainItem()); dlg->setMainItem(mainItem());
dlg->setVisualParent(this); dlg->setVisualParent(this);
dlg->setInteractive(m_interactive); dlg->setInteractive(m_interactive);
QMetaObject::invokeMethod(dlg, "show", Qt::QueuedConnection);
} }
QString ToolTip::mainText() const QString ToolTip::mainText() const

View File

@ -31,7 +31,8 @@ ToolTipDialog::ToolTipDialog(QQuickItem *parent)
m_qmlObject(0), m_qmlObject(0),
m_animation(0), m_animation(0),
m_hideTimeout(4000), m_hideTimeout(4000),
m_interactive(false) m_interactive(false),
m_animationsEnabled(true)
{ {
setFlags(Qt::ToolTip | Qt::BypassWindowManagerHint); setFlags(Qt::ToolTip | Qt::BypassWindowManagerHint);
setLocation(Plasma::Types::Floating); setLocation(Plasma::Types::Floating);
@ -77,9 +78,9 @@ void ToolTipDialog::showEvent(QShowEvent *event)
{ {
m_showTimer->start(m_hideTimeout); m_showTimer->start(m_hideTimeout);
setPosition(m_animation->endValue().toPoint());
m_animation->stop(); m_animation->stop();
Dialog::showEvent(event); Dialog::showEvent(event);
setPosition(m_animation->endValue().toPoint());
} }
void ToolTipDialog::hideEvent(QHideEvent *event) void ToolTipDialog::hideEvent(QHideEvent *event)
@ -112,7 +113,7 @@ bool ToolTipDialog::event(QEvent *e)
void ToolTipDialog::adjustGeometry(const QRect &geom) void ToolTipDialog::adjustGeometry(const QRect &geom)
{ {
if (isVisible()) { if (m_animationsEnabled) {
QRect startGeom(geometry()); QRect startGeom(geometry());
switch (location()) { switch (location()) {
@ -137,6 +138,16 @@ void ToolTipDialog::adjustGeometry(const QRect &geom)
} }
} }
bool ToolTipDialog::animationsEnabled() const
{
return m_animationsEnabled;
}
void ToolTipDialog::setAnimationsEnabled(bool enabled)
{
m_animationsEnabled = enabled;
}
void ToolTipDialog::dismiss() void ToolTipDialog::dismiss()
{ {
m_showTimer->start(m_hideTimeout / 20); // pretty short: 200ms m_showTimer->start(m_hideTimeout / 20); // pretty short: 200ms

View File

@ -63,6 +63,9 @@ public:
bool interactive(); bool interactive();
void setInteractive(bool interactive); void setInteractive(bool interactive);
bool animationsEnabled() const;
void setAnimationsEnabled(bool enabled);
protected: protected:
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event); void hideEvent(QHideEvent *event);
@ -78,6 +81,7 @@ private:
QPropertyAnimation *m_animation; QPropertyAnimation *m_animation;
int m_hideTimeout; int m_hideTimeout;
bool m_interactive; bool m_interactive;
bool m_animationsEnabled;
}; };
#endif #endif