mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-24 02:42:50 +00:00
plasma: check if visible widgets are under the mouse every 1 second
slightly better than Plasma::ToolButton when it comes to the widget being in a scroll area/widget of some sort Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
0896ce8d91
commit
630ed969da
1 changed files with 26 additions and 7 deletions
|
@ -188,6 +188,7 @@ Q_SIGNALS:
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void slotClicked(const Qt::MouseButton button);
|
void slotClicked(const Qt::MouseButton button);
|
||||||
void slotUpdateFonts();
|
void slotUpdateFonts();
|
||||||
|
void slotTimeout();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) final;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) final;
|
||||||
|
@ -201,7 +202,7 @@ private:
|
||||||
QPropertyAnimation* animateHover(QPropertyAnimation *animation, const bool fadeout);
|
QPropertyAnimation* animateHover(QPropertyAnimation *animation, const bool fadeout);
|
||||||
Plasma::Animation* animateButton(Plasma::Animation *animation, Plasma::ToolButton *toolbutton,
|
Plasma::Animation* animateButton(Plasma::Animation *animation, Plasma::ToolButton *toolbutton,
|
||||||
const bool fadeout);
|
const bool fadeout);
|
||||||
bool handleMouseEvent(QGraphicsSceneMouseEvent *event) const;
|
bool handleMouseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
QGraphicsLinearLayout* m_layout;
|
QGraphicsLinearLayout* m_layout;
|
||||||
Plasma::FrameSvg* m_framesvg;
|
Plasma::FrameSvg* m_framesvg;
|
||||||
|
@ -223,6 +224,7 @@ private:
|
||||||
QString m_data;
|
QString m_data;
|
||||||
int m_actioncounter;
|
int m_actioncounter;
|
||||||
QPointer<QMimeData> m_mimedata;
|
QPointer<QMimeData> m_mimedata;
|
||||||
|
QTimer* m_undermousetimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
LauncherWidget::LauncherWidget(QGraphicsWidget *parent)
|
LauncherWidget::LauncherWidget(QGraphicsWidget *parent)
|
||||||
|
@ -245,7 +247,8 @@ LauncherWidget::LauncherWidget(QGraphicsWidget *parent)
|
||||||
m_action3animation(nullptr),
|
m_action3animation(nullptr),
|
||||||
m_action4animation(nullptr),
|
m_action4animation(nullptr),
|
||||||
m_actioncounter(0),
|
m_actioncounter(0),
|
||||||
m_mimedata(nullptr)
|
m_mimedata(nullptr),
|
||||||
|
m_undermousetimer(nullptr)
|
||||||
{
|
{
|
||||||
m_layout = new QGraphicsLinearLayout(Qt::Horizontal, this);
|
m_layout = new QGraphicsLinearLayout(Qt::Horizontal, this);
|
||||||
setLayout(m_layout);
|
setLayout(m_layout);
|
||||||
|
@ -301,6 +304,15 @@ LauncherWidget::LauncherWidget(QGraphicsWidget *parent)
|
||||||
KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
|
KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
|
||||||
this, SLOT(slotUpdateFonts())
|
this, SLOT(slotUpdateFonts())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
m_undermousetimer = new QTimer(this);
|
||||||
|
// this could be done on scroll event (Plasma::ScrollWidget::scrollStateChanged()) but that
|
||||||
|
// means locking for thread-safety
|
||||||
|
m_undermousetimer->setInterval(s_animationduration * 4);
|
||||||
|
connect(
|
||||||
|
m_undermousetimer, SIGNAL(timeout()),
|
||||||
|
this, SLOT(slotTimeout())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
LauncherWidget::~LauncherWidget()
|
LauncherWidget::~LauncherWidget()
|
||||||
|
@ -448,9 +460,8 @@ void LauncherWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
||||||
if (m_hover > 0.0) {
|
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 qreal oldopacity = painter->opacity();
|
const qreal oldopacity = painter->opacity();
|
||||||
m_framesvg->resizeFrame(brectsize);
|
m_framesvg->resizeFrame(brect.size());
|
||||||
painter->setOpacity(m_hover);
|
painter->setOpacity(m_hover);
|
||||||
m_framesvg->paintFrame(painter, brect);
|
m_framesvg->paintFrame(painter, brect);
|
||||||
painter->setOpacity(oldopacity);
|
painter->setOpacity(oldopacity);
|
||||||
|
@ -500,9 +511,12 @@ QVariant LauncherWidget::itemChange(QGraphicsItem::GraphicsItemChange change, co
|
||||||
{
|
{
|
||||||
const QVariant result = Plasma::SvgWidget::itemChange(change, value);
|
const QVariant result = Plasma::SvgWidget::itemChange(change, value);
|
||||||
switch (change) {
|
switch (change) {
|
||||||
case QGraphicsItem::ItemPositionHasChanged:
|
|
||||||
case QGraphicsItem::ItemVisibleHasChanged: {
|
case QGraphicsItem::ItemVisibleHasChanged: {
|
||||||
m_hoveranimation = animateHover(m_hoveranimation, !isUnderMouse());
|
if (value.toBool()) {
|
||||||
|
m_undermousetimer->start();
|
||||||
|
} else {
|
||||||
|
m_undermousetimer->stop();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -546,7 +560,7 @@ QPropertyAnimation* LauncherWidget::animateHover(QPropertyAnimation *animation,
|
||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LauncherWidget::handleMouseEvent(QGraphicsSceneMouseEvent *event) const
|
bool LauncherWidget::handleMouseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->buttons() & Qt::LeftButton &&
|
if (event->buttons() & Qt::LeftButton &&
|
||||||
(event->pos() - event->buttonDownPos(Qt::LeftButton)).manhattanLength() > KGlobalSettings::dndEventDelay())
|
(event->pos() - event->buttonDownPos(Qt::LeftButton)).manhattanLength() > KGlobalSettings::dndEventDelay())
|
||||||
|
@ -590,6 +604,11 @@ void LauncherWidget::slotUpdateFonts()
|
||||||
m_subtextwidget->setFont(subtextfont);
|
m_subtextwidget->setFont(subtextfont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LauncherWidget::slotTimeout()
|
||||||
|
{
|
||||||
|
m_hoveranimation = animateHover(m_hoveranimation, !isUnderMouse());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class LauncherSearch : public QGraphicsWidget
|
class LauncherSearch : public QGraphicsWidget
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue