mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-24 02:42:50 +00:00
plasma: catch visibility and position changes for hover animation in launcher applet
because the widgets are child of Plasma::ScrollWidget it is tricky to get it done properly but Plasma::ToolButton also checks for visibility change just for the "under mouse" state Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
e2b193e780
commit
2cf8a5b37a
1 changed files with 21 additions and 8 deletions
|
@ -193,6 +193,7 @@ protected:
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) final;
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) final;
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) final;
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) final;
|
||||||
bool sceneEventFilter(QGraphicsItem *item, QEvent *event) final;
|
bool sceneEventFilter(QGraphicsItem *item, QEvent *event) final;
|
||||||
|
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPropertyAnimation* animateHover(QPropertyAnimation *animation, const bool fadeout);
|
QPropertyAnimation* animateHover(QPropertyAnimation *animation, const bool fadeout);
|
||||||
|
@ -440,20 +441,16 @@ void LauncherWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
Q_UNUSED(widget);
|
Q_UNUSED(widget);
|
||||||
|
if (m_hover > 0.0) {
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
const QRectF brect = boundingRect();
|
const QRectF brect = boundingRect();
|
||||||
const QSizeF brectsize = brect.size();
|
const QSizeF brectsize = brect.size();
|
||||||
if (m_hover > 0.0) {
|
|
||||||
const qreal oldopacity = painter->opacity();
|
const qreal oldopacity = painter->opacity();
|
||||||
m_framesvg->setElementPrefix("hover");
|
m_framesvg->setElementPrefix("hover");
|
||||||
m_framesvg->resizeFrame(brectsize);
|
m_framesvg->resizeFrame(brectsize);
|
||||||
painter->setOpacity(m_hover);
|
painter->setOpacity(m_hover);
|
||||||
m_framesvg->paintFrame(painter, brect);
|
m_framesvg->paintFrame(painter, brect);
|
||||||
painter->setOpacity(oldopacity);
|
painter->setOpacity(oldopacity);
|
||||||
} else if (hasFocus()) {
|
|
||||||
m_framesvg->setElementPrefix("selected");
|
|
||||||
m_framesvg->resizeFrame(brectsize);
|
|
||||||
m_framesvg->paintFrame(painter, brect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +479,7 @@ void LauncherWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
if (m_mimedata && handleMouseEvent(event)) {
|
if (m_mimedata && handleMouseEvent(event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QGraphicsWidget::mouseMoveEvent(event);
|
Plasma::SvgWidget::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LauncherWidget::sceneEventFilter(QGraphicsItem *item, QEvent *event)
|
bool LauncherWidget::sceneEventFilter(QGraphicsItem *item, QEvent *event)
|
||||||
|
@ -496,6 +493,22 @@ bool LauncherWidget::sceneEventFilter(QGraphicsItem *item, QEvent *event)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant LauncherWidget::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||||
|
{
|
||||||
|
const QVariant result = Plasma::SvgWidget::itemChange(change, value);
|
||||||
|
switch (change) {
|
||||||
|
case QGraphicsItem::ItemPositionHasChanged:
|
||||||
|
case QGraphicsItem::ItemVisibleHasChanged: {
|
||||||
|
m_hoveranimation = animateHover(m_hoveranimation, !isUnderMouse());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
Plasma::Animation* LauncherWidget::animateButton(Plasma::Animation *animation,
|
Plasma::Animation* LauncherWidget::animateButton(Plasma::Animation *animation,
|
||||||
Plasma::ToolButton *toolbutton,
|
Plasma::ToolButton *toolbutton,
|
||||||
const bool fadeout)
|
const bool fadeout)
|
||||||
|
|
Loading…
Add table
Reference in a new issue