81 lines
2.1 KiB
C++
81 lines
2.1 KiB
C++
#include "mainwindow.h"
|
|
#include "./ui_mainwindow.h"
|
|
|
|
#include <QPainter>
|
|
#include <QPropertyAnimation>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
|
|
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
|
|
|
m_bgLinearGradient.setColorAt(0, QColor(255, 255, 255, 25)); // a:0
|
|
m_bgLinearGradient.setColorAt(1, QColor(255, 255, 255, 200));
|
|
m_bgLinearGradient.setStart(0, 0);
|
|
m_bgLinearGradient.setFinalStop(0, height());
|
|
|
|
m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity", this);
|
|
m_fadeOutAnimation->setDuration(400);
|
|
m_fadeOutAnimation->setStartValue(1);
|
|
m_fadeOutAnimation->setEndValue(0);
|
|
connect(m_fadeOutAnimation, &QPropertyAnimation::finished, this, &QMainWindow::close);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *)
|
|
{
|
|
qApp->exit();
|
|
}
|
|
|
|
void MainWindow::paintEvent(QPaintEvent * e)
|
|
{
|
|
QPainter painter(this);
|
|
|
|
painter.setBrush(QBrush(m_bgLinearGradient));
|
|
painter.setPen(Qt::NoPen);
|
|
painter.drawRect(0, 0, width(), height());
|
|
|
|
return QMainWindow::paintEvent(e);
|
|
}
|
|
|
|
void MainWindow::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
if (event->buttons() & Qt::LeftButton && !isMaximized()) {
|
|
m_clickedOnWindow = true;
|
|
m_oldMousePos = event->pos();
|
|
event->accept();
|
|
}
|
|
|
|
return QMainWindow::mousePressEvent(event);
|
|
}
|
|
|
|
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow) {
|
|
move(event->globalPos() - m_oldMousePos);
|
|
event->accept();
|
|
}
|
|
|
|
return QMainWindow::mouseMoveEvent(event);
|
|
}
|
|
|
|
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
|
|
{
|
|
m_clickedOnWindow = false;
|
|
|
|
return QMainWindow::mouseReleaseEvent(event);
|
|
}
|
|
|
|
void MainWindow::on_closeWindowBtn_clicked()
|
|
{
|
|
m_fadeOutAnimation->start();
|
|
}
|