feat: 添加ElaWidgetTool库

This commit is contained in:
sleepwithoutbz
2025-09-19 22:40:52 +08:00
parent 5f93e8caf6
commit 4eef5c7fd5
407 changed files with 36325 additions and 7 deletions

View File

@@ -0,0 +1,79 @@
#include "ElaToolTipPrivate.h"
#include <QEvent>
#include <QPropertyAnimation>
#include <QTimer>
#include "ElaToolTip.h"
ElaToolTipPrivate::ElaToolTipPrivate(QObject* parent)
: QObject{parent}
{
_pOpacity = 1;
}
ElaToolTipPrivate::~ElaToolTipPrivate()
{
}
bool ElaToolTipPrivate::eventFilter(QObject* watched, QEvent* event)
{
Q_Q(ElaToolTip);
switch (event->type())
{
case QEvent::Enter:
{
QTimer::singleShot(_pShowDelayMsec, this, [=]() {
_doShowAnimation();
});
if (_pDisplayMsec > -1)
{
QTimer::singleShot(_pDisplayMsec, this, [=]() {
q->hide();
});
}
break;
}
case QEvent::Leave:
{
QTimer::singleShot(_pHideDelayMsec, this, [=]() {
q->hide();
});
break;
}
case QEvent::HoverMove:
case QEvent::MouseMove:
{
_updatePos();
break;
}
default:
{
break;
}
}
return QObject::eventFilter(watched, event);
}
void ElaToolTipPrivate::_doShowAnimation()
{
Q_Q(ElaToolTip);
QPoint cursorPoint = QCursor::pos();
q->move(cursorPoint.x() + 10, cursorPoint.y());
q->show();
QPropertyAnimation* showAnimation = new QPropertyAnimation(q, "windowOpacity");
showAnimation->setEasingCurve(QEasingCurve::InOutSine);
showAnimation->setDuration(250);
showAnimation->setStartValue(0);
showAnimation->setEndValue(1);
showAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void ElaToolTipPrivate::_updatePos()
{
Q_Q(ElaToolTip);
if (q->isVisible())
{
QPoint cursorPoint = QCursor::pos();
q->move(cursorPoint.x() + 10, cursorPoint.y());
}
}