mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
optimize datetime plugin
Change-Id: Id188ab920cd66ee2c91215c9877cc3edabd0fa1e
This commit is contained in:
parent
2ceeccec1d
commit
d501d3903b
@ -9,16 +9,10 @@ PluginsItem::PluginsItem(PluginsItemInterface* const inter, QWidget *parent)
|
||||
: DockItem(Plugins, parent),
|
||||
m_inter(inter)
|
||||
{
|
||||
// QBoxLayout *layout = new QBoxLayout;
|
||||
// layout->addWidget(m_inter->);
|
||||
}
|
||||
QBoxLayout *layout = new QHBoxLayout;
|
||||
layout->addWidget(m_inter->centeralWidget());
|
||||
layout->setSpacing(0);
|
||||
layout->setMargin(0);
|
||||
|
||||
void PluginsItem::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
DockItem::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect().marginsRemoved(QMargins(3, 3, 3, 3)), Qt::cyan);
|
||||
painter.setPen(Qt::red);
|
||||
painter.drawText(rect(), m_inter->name());
|
||||
setLayout(layout);
|
||||
}
|
||||
|
@ -11,9 +11,6 @@ class PluginsItem : public DockItem
|
||||
public:
|
||||
explicit PluginsItem(PluginsItemInterface* const inter, QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
private:
|
||||
PluginsItemInterface* const m_inter;
|
||||
};
|
||||
|
@ -1,13 +1,15 @@
|
||||
#ifndef PLUGINSITEMINTERFACE_H
|
||||
#define PLUGINSITEMINTERFACE_H
|
||||
|
||||
class QString;
|
||||
#include <QtCore>
|
||||
|
||||
class PluginsItemInterface
|
||||
{
|
||||
public:
|
||||
virtual ~PluginsItemInterface() {}
|
||||
|
||||
virtual const QString name() = 0;
|
||||
virtual QWidget *centeralWidget() = 0;
|
||||
};
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -1,12 +1,37 @@
|
||||
#include "datetimeplugin.h"
|
||||
|
||||
DatetimePlugin::DatetimePlugin(QObject *parent)
|
||||
: QObject(parent)
|
||||
: QObject(parent),
|
||||
m_timeLabel(new QLabel),
|
||||
m_refershTimer(new QTimer(this))
|
||||
{
|
||||
m_timeLabel->setStyleSheet("color:red;");
|
||||
|
||||
m_refershTimer->setInterval(1000);
|
||||
m_refershTimer->start();
|
||||
|
||||
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::refershTime);
|
||||
}
|
||||
|
||||
DatetimePlugin::~DatetimePlugin()
|
||||
{
|
||||
delete m_timeLabel;
|
||||
}
|
||||
|
||||
const QString DatetimePlugin::name()
|
||||
{
|
||||
return "datetime";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef DATETIMEPLUGIN_H
|
||||
#define DATETIMEPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "pluginsiteminterface.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
|
||||
class DatetimePlugin : public QObject, PluginsItemInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -13,8 +14,17 @@ class DatetimePlugin : public QObject, PluginsItemInterface
|
||||
|
||||
public:
|
||||
explicit DatetimePlugin(QObject *parent = 0);
|
||||
~DatetimePlugin();
|
||||
|
||||
const QString name();
|
||||
QWidget *centeralWidget();
|
||||
|
||||
private slots:
|
||||
void refershTime();
|
||||
|
||||
private:
|
||||
QLabel *m_timeLabel;
|
||||
QTimer *m_refershTimer;
|
||||
};
|
||||
|
||||
#endif // DATETIMEPLUGIN_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user