2016-06-15 17:44:38 +08:00
|
|
|
#include "datetimeplugin.h"
|
|
|
|
|
2016-07-13 10:08:38 +08:00
|
|
|
#include <QLabel>
|
|
|
|
|
2016-06-15 17:44:38 +08:00
|
|
|
DatetimePlugin::DatetimePlugin(QObject *parent)
|
2016-06-16 17:48:19 +08:00
|
|
|
: QObject(parent),
|
2016-07-01 11:07:20 +08:00
|
|
|
|
2016-07-13 10:08:38 +08:00
|
|
|
m_dateTipsLabel(new QLabel),
|
2016-07-01 11:07:20 +08:00
|
|
|
|
2016-06-16 17:48:19 +08:00
|
|
|
m_refershTimer(new QTimer(this))
|
2016-06-15 17:44:38 +08:00
|
|
|
{
|
2016-07-28 10:59:21 +08:00
|
|
|
m_dateTipsLabel->setObjectName("datetime");
|
2016-07-13 10:08:38 +08:00
|
|
|
m_dateTipsLabel->setStyleSheet("color:white;"
|
|
|
|
"padding:6px 10px;");
|
2016-07-01 11:07:20 +08:00
|
|
|
|
2016-06-16 17:48:19 +08:00
|
|
|
m_refershTimer->setInterval(1000);
|
|
|
|
m_refershTimer->start();
|
|
|
|
|
2016-06-27 14:33:21 +08:00
|
|
|
m_centeralWidget = new DatetimeWidget;
|
2016-06-23 10:24:51 +08:00
|
|
|
|
2016-06-27 15:34:54 +08:00
|
|
|
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::updateCurrentTimeString);
|
2016-06-16 17:48:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DatetimePlugin::~DatetimePlugin()
|
|
|
|
{
|
2016-06-27 14:33:21 +08:00
|
|
|
delete m_centeralWidget;
|
2016-07-13 10:08:38 +08:00
|
|
|
delete m_dateTipsLabel;
|
2016-06-15 17:44:38 +08:00
|
|
|
}
|
|
|
|
|
2016-06-28 14:23:30 +08:00
|
|
|
const QString DatetimePlugin::pluginName() const
|
2016-06-15 17:44:38 +08:00
|
|
|
{
|
2016-06-16 16:56:21 +08:00
|
|
|
return "datetime";
|
2016-07-01 11:07:20 +08:00
|
|
|
}
|
|
|
|
|
2016-06-24 11:32:25 +08:00
|
|
|
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
|
|
|
{
|
|
|
|
m_proxyInter = proxyInter;
|
|
|
|
m_proxyInter->itemAdded(this, QString());
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:14:45 +08:00
|
|
|
int DatetimePlugin::itemSortKey(const QString &itemKey)
|
2016-06-28 10:06:04 +08:00
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-24 11:32:25 +08:00
|
|
|
QWidget *DatetimePlugin::itemWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2016-06-27 14:33:21 +08:00
|
|
|
return m_centeralWidget;
|
2016-06-16 17:48:19 +08:00
|
|
|
}
|
2016-06-27 15:34:54 +08:00
|
|
|
|
2016-07-01 11:07:20 +08:00
|
|
|
QWidget *DatetimePlugin::itemTipsWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2016-07-13 10:08:38 +08:00
|
|
|
return m_dateTipsLabel;
|
|
|
|
}
|
2016-07-01 11:20:26 +08:00
|
|
|
|
2016-07-13 10:08:38 +08:00
|
|
|
const QString DatetimePlugin::itemCommand(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
return "dde-calendar";
|
2016-07-01 11:07:20 +08:00
|
|
|
}
|
|
|
|
|
2016-06-27 15:34:54 +08:00
|
|
|
void DatetimePlugin::updateCurrentTimeString()
|
|
|
|
{
|
2016-07-13 10:08:38 +08:00
|
|
|
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
|
|
|
2016-08-26 10:17:51 +08:00
|
|
|
m_dateTipsLabel->setText(currentDateTime.date().toString(Qt::SystemLocaleLongDate) + currentDateTime.toString(tr(" HH:mm:ss")));
|
2016-07-13 10:08:38 +08:00
|
|
|
|
|
|
|
const QString currentString = currentDateTime.toString("mm");
|
2016-06-27 15:34:54 +08:00
|
|
|
|
|
|
|
if (currentString == m_currentTimeString)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_currentTimeString = currentString;
|
|
|
|
m_centeralWidget->update();
|
|
|
|
}
|