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),
|
2016-07-01 11:07:20 +08:00
|
|
|
|
|
|
|
m_calendar(new DCalendar(nullptr)),
|
|
|
|
|
2016-06-16 17:48:19 +08:00
|
|
|
m_refershTimer(new QTimer(this))
|
2016-06-15 17:44:38 +08:00
|
|
|
{
|
2016-07-01 11:07:20 +08:00
|
|
|
m_calendar->setFixedSize(300, 300);
|
2016-07-01 11:20:26 +08:00
|
|
|
m_calendar->setDateInfoVisible(true);
|
|
|
|
m_calendar->setControlPanelVisible(false);
|
|
|
|
m_calendar->setSolarDisplayFormat(tr("MM/dd/yyyy"));
|
|
|
|
m_calendar->setLunarVisible(QLocale::system().name().startsWith("zh_"));
|
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-01 11:20:26 +08:00
|
|
|
delete m_calendar;
|
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-06-15 17:44:38 +08:00
|
|
|
}
|
2016-06-16 17:48:19 +08:00
|
|
|
|
2016-06-28 10:56:28 +08:00
|
|
|
PluginsItemInterface::ItemType DatetimePlugin::pluginType(const QString &itemKey)
|
2016-06-16 17:48:19 +08:00
|
|
|
{
|
2016-06-24 11:32:25 +08:00
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
return Complex;
|
|
|
|
}
|
|
|
|
|
2016-07-01 11:07:20 +08:00
|
|
|
PluginsItemInterface::ItemType DatetimePlugin::tipsType(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
return Complex;
|
|
|
|
}
|
|
|
|
|
2016-06-24 11:32:25 +08:00
|
|
|
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
|
|
|
{
|
|
|
|
m_proxyInter = proxyInter;
|
|
|
|
m_proxyInter->itemAdded(this, QString());
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:06:04 +08:00
|
|
|
int DatetimePlugin::itemSortKey(const QString &itemKey) const
|
|
|
|
{
|
|
|
|
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-01 11:20:26 +08:00
|
|
|
m_calendar->setCurrentDate(QDate::currentDate());
|
|
|
|
|
2016-07-01 11:07:20 +08:00
|
|
|
return m_calendar;
|
|
|
|
}
|
|
|
|
|
2016-06-27 15:34:54 +08:00
|
|
|
void DatetimePlugin::updateCurrentTimeString()
|
|
|
|
{
|
|
|
|
const QString currentString = QTime::currentTime().toString("mm");
|
|
|
|
|
|
|
|
if (currentString == m_currentTimeString)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_currentTimeString = currentString;
|
|
|
|
m_centeralWidget->update();
|
|
|
|
}
|