You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.4 KiB
101 lines
3.4 KiB
#include "album.h"
|
|
#include "ui_album.h"
|
|
|
|
album::album(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::album)
|
|
{
|
|
ui->setupUi(this);
|
|
this->installEventFilter(this);
|
|
|
|
}
|
|
|
|
album::~album()
|
|
{
|
|
delete ui;
|
|
}
|
|
void album::album_init()
|
|
{
|
|
}
|
|
bool album::eventFilter(QObject *watch, QEvent *evn)
|
|
{
|
|
static int press_x;//摁下的x坐标
|
|
static int press_y;
|
|
static int relea_x;
|
|
static int relea_y;
|
|
|
|
QMouseEvent *event = static_cast<QMouseEvent *>(evn);
|
|
|
|
if(event->type()==QEvent::MouseButtonPress)//鼠标摁下
|
|
{
|
|
press_x = event->globalX();
|
|
press_y = event->globalY();
|
|
}
|
|
qDebug()<<press_x;
|
|
if(event->type()==QEvent::MouseButtonRelease)//鼠标释放
|
|
{
|
|
relea_x = event->globalX();
|
|
relea_y = event->globalY();
|
|
}
|
|
|
|
//判断滑动方向(右滑)
|
|
if((relea_x - press_x)>20 && event->type()==QEvent::MouseButtonRelease && qAbs(relea_y-press_y)<50)
|
|
{
|
|
int current_page = ui->stackedWidget->currentIndex();// 获取当前页面的索引
|
|
|
|
if(current_page<=2)
|
|
{
|
|
ui->label->setPixmap(ui->stackedWidget->currentWidget()->grab());//获取当前页面
|
|
|
|
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->label,"geometry");
|
|
animation1->setDuration(1000);
|
|
animation1->setStartValue(QRect(0,0,this->width(),this->height()));
|
|
animation1->setEndValue(QRect(this->width()*2,0,this->width(),this->height()));
|
|
//animation1->start();
|
|
|
|
ui->stackedWidget->setCurrentIndex(current_page+1);
|
|
|
|
QPropertyAnimation *animation2 = new QPropertyAnimation(ui->stackedWidget->currentWidget(),"geometry");
|
|
animation2->setDuration(1000);
|
|
animation2->setStartValue(QRect(-this->width()*2,0,this->width(),this->height()));
|
|
animation2->setEndValue(QRect(0,0,this->width(),this->height()));
|
|
|
|
QParallelAnimationGroup *group = new QParallelAnimationGroup;
|
|
group->addAnimation(animation1);
|
|
group->addAnimation(animation2);
|
|
group->start();
|
|
}
|
|
}
|
|
|
|
//判断滑动方向(左滑)
|
|
if((press_x - relea_x)>20 && event->type()==QEvent::MouseButtonRelease && qAbs(relea_y-press_y)<50)
|
|
{
|
|
int current_page = ui->stackedWidget->currentIndex();
|
|
ui->page->setStyleSheet(image_path);
|
|
if(current_page>=0)
|
|
{
|
|
ui->label->setPixmap(ui->stackedWidget->currentWidget()->grab());
|
|
|
|
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->label,"geometry");
|
|
animation1->setDuration(1000);
|
|
animation1->setStartValue(QRect(0,0,this->width(),this->height()));
|
|
animation1->setEndValue(QRect(-this->width(),0,this->width(),this->height()));
|
|
//animation1->start();
|
|
|
|
ui->stackedWidget->setCurrentIndex(current_page-1);
|
|
|
|
QPropertyAnimation *animation2 = new QPropertyAnimation(ui->stackedWidget->currentWidget(),"geometry");
|
|
animation2->setDuration(1000);
|
|
animation2->setStartValue(QRect(this->width()*2,0,this->width(),this->height()));
|
|
animation2->setEndValue(QRect(0,0,this->width(),this->height()));
|
|
|
|
QParallelAnimationGroup *group = new QParallelAnimationGroup;
|
|
group->addAnimation(animation1);
|
|
group->addAnimation(animation2);
|
|
group->start();
|
|
}
|
|
}
|
|
|
|
return QWidget::eventFilter(watch,evn);
|
|
}
|