抽象出控件动画类

This commit is contained in:
2022-12-11 00:17:09 +08:00
parent 1c24079406
commit e171904a34
5 changed files with 68 additions and 33 deletions

View File

@@ -18,17 +18,7 @@ MainWindow::MainWindow(QWidget *parent)
initConfig();
moveToCenter(this); //让窗口居中显示
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity", this);
//设置动画效果
animation->setEasingCurve(QEasingCurve::Linear);
//设置动画时间(单位:毫秒)
animation->setDuration(500);
// 设置动画步长值,以及在该位置时显示的透明度
animation->setKeyValueAt(0, 0);
// m_animation->setKeyValueAt(0.5, 0);
animation->setKeyValueAt(1, 1);
// 开始动画
animation->start();
WidgetAnimation::widgetOpacity(this,true);
downloadlistwidget = new DownloadListWidget;
downloadButton = new QPushButton(ui->titlebar);
@@ -112,7 +102,7 @@ MainWindow::MainWindow(QWidget *parent)
//appintopage按下下载按钮时标题栏下载列表按钮抖动
connect(ui->appintopage, &AppIntoPage::clickedDownloadBtn, [=]() {
widgetShake(downloadButton,6);//第一个参数是抖动的控件,第二个参数是抖动范围(像素)
WidgetAnimation::widgetShake(downloadButton,6);//第一个参数是抖动的控件,第二个参数是抖动范围(像素)
});
connect(backButtom, &QPushButton::clicked, [=]() {
@@ -190,26 +180,6 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::widgetShake(QWidget *pWidget, int nRange)
{
int nX = pWidget->x();
int nY = pWidget->y();
QPropertyAnimation *pAnimation = new QPropertyAnimation(pWidget,"geometry");
pAnimation->setEasingCurve(QEasingCurve::InOutSine);
pAnimation->setDuration(400);
pAnimation->setStartValue(QRect(QPoint(nX,nY),pWidget->size()));
int nShakeCount = 8;
double nStep = 1.0/nShakeCount;
for(int i = 1; i < nShakeCount; i++){
nRange = i&1 ? -nRange : nRange;
pAnimation->setKeyValueAt(nStep*i,QRect(QPoint(nX + nRange,nY),pWidget->size()));
}
pAnimation->setEndValue(QRect(QPoint(nX,nY),pWidget->size()));
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void MainWindow::openUrl(QUrl url)
{
if (url.toString().startsWith("spk://")) {