-
Notifications
You must be signed in to change notification settings - Fork 0
/
menubutton.cpp
49 lines (40 loc) · 1.63 KB
/
menubutton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "menubutton.h"
#include <QTimer>
MenuButton::MenuButton(int r, int x, int y, int width, int height, QString path, QString path2, QWidget *parent) : QLabel(parent)
{
pushLabel->setParent(parent);
textButton->setParent(parent);
pushLabel->setGeometry(x - r, y - r, 2*r, 2*r);
buttonGif->setScaledSize(QSize(pushLabel->width(), pushLabel->height()));
pushLabel->setMovie(buttonGif);
buttonGif->start();
textButton->setGeometry(x - r, y - r, 2*r, 2*r);
textButton->setStyleSheet("QPushButton{border:0px;}");
textButton->setImage(path, path2, 2*r, 2*r);
setSound(":/sound/button_mouseover.wav", ":/sound/button_mouseleave.wav", ":/sound/button_press.wav", ":/sound/button_release.wav"); //默认音效
animation->setParent(parent);
animation->setTargetObject(pushLabel);
animation->setDuration(2000);
animation->setPropertyName("geometry");
animation->setStartValue(QRect(x - r, height, 2*r, 2*r));
animation->setEndValue(QRect(x - r, y - r, 2*r, 2*r));
animation->setEasingCurve(QEasingCurve::InOutCubic);
connect(textButton, &QPushButton::clicked, [=](){
emit clicked();
});
}
void MenuButton::show(){
pushLabel->setVisible(true);
animation->start();
QTimer::singleShot(2000, textButton, [=](){
textButton->setVisible(true);
});
}
void MenuButton::setVisible(bool flag){
pushLabel->setVisible(flag);
textButton->setVisible(flag);
QLabel::setVisible(flag);
}
void MenuButton::setSound(QString pathHover, QString pathLeave, QString pathPress, QString pathRelease){
textButton->setSound(pathHover, pathLeave, pathPress, pathRelease);
}