2016-06-15 17:44:38 +08:00
|
|
|
#include "datetimeplugin.h"
|
|
|
|
|
|
|
|
DatetimePlugin::DatetimePlugin(QObject *parent)
|
2016-06-16 17:48:19 +08:00
|
|
|
: QObject(parent),
|
|
|
|
m_timeLabel(new QLabel),
|
|
|
|
m_refershTimer(new QTimer(this))
|
2016-06-15 17:44:38 +08:00
|
|
|
{
|
2016-06-17 09:42:06 +08:00
|
|
|
m_timeLabel->setAlignment(Qt::AlignCenter);
|
|
|
|
m_timeLabel->setStyleSheet("color:white;"
|
2016-06-23 10:50:26 +08:00
|
|
|
// "background-color:black;"
|
2016-06-23 10:24:51 +08:00
|
|
|
"padding:5px;"
|
2016-06-17 09:42:06 +08:00
|
|
|
"font-size:12px;");
|
2016-06-15 17:44:38 +08:00
|
|
|
|
2016-06-16 17:48:19 +08:00
|
|
|
m_refershTimer->setInterval(1000);
|
|
|
|
m_refershTimer->start();
|
|
|
|
|
|
|
|
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::refershTime);
|
2016-06-23 10:24:51 +08:00
|
|
|
|
|
|
|
refershTime();
|
2016-06-16 17:48:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DatetimePlugin::~DatetimePlugin()
|
|
|
|
{
|
|
|
|
delete m_timeLabel;
|
2016-06-15 17:44:38 +08:00
|
|
|
}
|
|
|
|
|
2016-06-16 16:56:21 +08:00
|
|
|
const QString DatetimePlugin::name()
|
2016-06-15 17:44:38 +08:00
|
|
|
{
|
2016-06-16 16:56:21 +08:00
|
|
|
return "datetime";
|
2016-06-15 17:44:38 +08:00
|
|
|
}
|
2016-06-16 17:48:19 +08:00
|
|
|
|
|
|
|
QWidget *DatetimePlugin::centeralWidget()
|
|
|
|
{
|
|
|
|
return m_timeLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DatetimePlugin::refershTime()
|
|
|
|
{
|
|
|
|
const QString text = QTime::currentTime().toString(tr("HH:mm"));
|
|
|
|
|
|
|
|
if (m_timeLabel->text() != text)
|
|
|
|
m_timeLabel->setText(text);
|
|
|
|
}
|