dde-dock/plugins/datetime/datetimeplugin.cpp
石博文 2037457bf7 change plugin interface
Change-Id: Ie2e3fd67559cd1af77deec2377c7978ad00364f1
2016-08-02 09:28:06 +08:00

59 lines
1.3 KiB
C++

#include "datetimeplugin.h"
DatetimePlugin::DatetimePlugin(QObject *parent)
: QObject(parent),
m_timeLabel(new QLabel),
m_refershTimer(new QTimer(this))
{
m_timeLabel->setAlignment(Qt::AlignCenter);
m_timeLabel->setStyleSheet("color:white;"
// "background-color:black;"
"padding:5px;"
"font-size:12px;");
m_refershTimer->setInterval(1000);
m_refershTimer->start();
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::refershTime);
refershTime();
}
DatetimePlugin::~DatetimePlugin()
{
delete m_timeLabel;
}
const QString DatetimePlugin::pluginName()
{
return "datetime";
}
PluginsItemInterface::PluginType DatetimePlugin::pluginType(const QString &itemKey)
{
Q_UNUSED(itemKey);
return Complex;
}
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
{
m_proxyInter = proxyInter;
m_proxyInter->itemAdded(this, QString());
}
QWidget *DatetimePlugin::itemWidget(const QString &itemKey)
{
Q_UNUSED(itemKey);
return m_timeLabel;
}
void DatetimePlugin::refershTime()
{
const QString text = QTime::currentTime().toString(tr("HH:mm"));
if (m_timeLabel->text() != text)
m_timeLabel->setText(text);
}