#include "ShowTime.h"
#include <QPainter>
#include <QDateTime>
#include <QString>

Show_Time::Show_Time(QWidget *parent) : QWidget(parent) {
    setObjectName("Show_Time");
    setAttribute(Qt::WA_OpaquePaintEvent);
    timer.start(1000);
    connect(&timer, &QTimer::timeout, this, [this](){
        update();
    });
}

void Show_Time::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
    painter.setPen(Qt::NoPen);
    painter.fillRect(rect(), QApplication::style()->standardPalette().brush(QPalette::Window));
    painter.setPen(QPen());
    QString&& dateTimeString = QDateTime::currentDateTime().toString("HH:mm:ss");
    painter.drawText(rect(), Qt::AlignCenter, dateTimeString);
    painter.end();
}
