#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDateTime>
#include <QTimer>

MainWindow::MainWindow(QWidget* parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);

    calendarLoopPlay();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_close_clicked()
{
    this->close();
}

void MainWindow::on_pushButton_max_clicked()
{
    if (isFullScreen()) {
        this->showMaximized();
    } else {
        this->showFullScreen();
    }
}

void MainWindow::on_pushButton_min_clicked()
{
    this->showMinimized();
}

void MainWindow::calendarLoopPlay()
{
    ui->label_calendar->clear();
    QTimer* timer_calendar = new QTimer(this);
    connect(timer_calendar, &QTimer::timeout, this, [this]() {
        QDateTime time = QDateTime::currentDateTime();
        QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd");
        ui->label_calendar->setText(str);
    });
    timer_calendar->start(1000); //每一秒溢出一次进入槽函数
}
