mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
optimize datetime plugin
Change-Id: I43404063fa1053cfbbd14f8a71bef207cb624185
This commit is contained in:
parent
464057344c
commit
af16b0c136
@ -23,6 +23,11 @@ void DockPluginsController::itemAdded(PluginsItemInterface * const itemInter, co
|
||||
emit pluginItemInserted(item);
|
||||
}
|
||||
|
||||
DisplayMode DockPluginsController::displayMode() const
|
||||
{
|
||||
return Fashion;
|
||||
}
|
||||
|
||||
void DockPluginsController::loadPlugins()
|
||||
{
|
||||
// Q_ASSERT(m_pluginLoaderList.isEmpty());
|
||||
|
@ -17,8 +17,11 @@ public:
|
||||
explicit DockPluginsController(DockItemController *itemControllerInter = 0);
|
||||
~DockPluginsController();
|
||||
|
||||
// implements PluginProxyInterface
|
||||
void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey);
|
||||
|
||||
Dock::DisplayMode displayMode() const;
|
||||
|
||||
signals:
|
||||
void pluginItemInserted(PluginsItem *pluginsItem) const;
|
||||
|
||||
|
@ -178,6 +178,7 @@ void DockSettings::positionChanged()
|
||||
{
|
||||
m_position = Dock::Position(m_dockInter->position());
|
||||
DockItem::setDockPosition(m_position);
|
||||
qApp->setProperty(PROP_POSITION, QVariant::fromValue(m_position));
|
||||
|
||||
calculateWindowConfig();
|
||||
|
||||
@ -198,6 +199,7 @@ void DockSettings::displayModeChanged()
|
||||
{
|
||||
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
||||
DockItem::setDockDisplayMode(m_displayMode);
|
||||
qApp->setProperty(PROP_DISPLAY_MODE, QVariant::fromValue(m_displayMode));
|
||||
|
||||
calculateWindowConfig();
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
namespace Dock {
|
||||
|
||||
#define PROP_DISPLAY_MODE "DisplayMode"
|
||||
enum DisplayMode
|
||||
{
|
||||
Fashion = 0,
|
||||
@ -11,6 +14,7 @@ enum DisplayMode
|
||||
// Classic = 2,
|
||||
};
|
||||
|
||||
#define PROP_HIDE_MODE "HideMode"
|
||||
enum HideMode
|
||||
{
|
||||
KeepShowing = 0,
|
||||
@ -18,6 +22,7 @@ enum HideMode
|
||||
SmartHide = 3,
|
||||
};
|
||||
|
||||
#define PROP_POSITION "Position"
|
||||
enum Position
|
||||
{
|
||||
Top = 0,
|
||||
@ -26,6 +31,7 @@ enum Position
|
||||
Left = 3,
|
||||
};
|
||||
|
||||
#define PROP_HIDE_STATE "HideState"
|
||||
enum HideState
|
||||
{
|
||||
Unknown = 0,
|
||||
@ -35,4 +41,7 @@ enum HideState
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Dock::DisplayMode)
|
||||
Q_DECLARE_METATYPE(Dock::Position)
|
||||
|
||||
#endif // CONSTANTS_H
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef PLUGINPROXYINTERFACE_H
|
||||
#define PLUGINPROXYINTERFACE_H
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class PluginsItemInterface;
|
||||
@ -9,6 +11,7 @@ class PluginProxyInterface
|
||||
public:
|
||||
virtual void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey) = 0;
|
||||
|
||||
virtual Dock::DisplayMode displayMode() const = 0;
|
||||
};
|
||||
|
||||
#endif // PLUGINPROXYINTERFACE_H
|
||||
|
@ -10,10 +10,12 @@ TARGET = $$qtLibraryTarget(datetime)
|
||||
DESTDIR = $$_PRO_FILE_PWD_/../
|
||||
|
||||
HEADERS += \
|
||||
datetimeplugin.h
|
||||
datetimeplugin.h \
|
||||
datetimewidget.h
|
||||
|
||||
SOURCES += \
|
||||
datetimeplugin.cpp
|
||||
datetimeplugin.cpp \
|
||||
datetimewidget.cpp
|
||||
|
||||
target.path = $${PREFIX}/lib/dde-dock/plugins/
|
||||
INSTALLS += target
|
||||
|
@ -2,26 +2,19 @@
|
||||
|
||||
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);
|
||||
m_centeralWidget = new DatetimeWidget;
|
||||
|
||||
refershTime();
|
||||
connect(m_refershTimer, &QTimer::timeout, m_centeralWidget, static_cast<void (DatetimeWidget::*)()>(&DatetimeWidget::update));
|
||||
}
|
||||
|
||||
DatetimePlugin::~DatetimePlugin()
|
||||
{
|
||||
delete m_timeLabel;
|
||||
delete m_centeralWidget;
|
||||
}
|
||||
|
||||
const QString DatetimePlugin::pluginName()
|
||||
@ -46,13 +39,5 @@ 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);
|
||||
return m_centeralWidget;
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
#define DATETIMEPLUGIN_H
|
||||
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "datetimewidget.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
|
||||
class DatetimePlugin : public QObject, PluginsItemInterface
|
||||
@ -22,12 +22,8 @@ public:
|
||||
|
||||
QWidget *itemWidget(const QString &itemKey);
|
||||
|
||||
|
||||
private slots:
|
||||
void refershTime();
|
||||
|
||||
private:
|
||||
QLabel *m_timeLabel;
|
||||
DatetimeWidget *m_centeralWidget;
|
||||
QTimer *m_refershTimer;
|
||||
};
|
||||
|
||||
|
38
plugins/datetime/datetimewidget.cpp
Normal file
38
plugins/datetime/datetimewidget.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "datetimewidget.h"
|
||||
#include "constants.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
DatetimeWidget::DatetimeWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QSize DatetimeWidget::sizeHint() const
|
||||
{
|
||||
QFontMetrics fm(qApp->font());
|
||||
|
||||
return fm.boundingRect("88:88").size() + QSize(20, 10);
|
||||
}
|
||||
|
||||
void DatetimeWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
|
||||
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
if (displayMode == Dock::Efficient)
|
||||
{
|
||||
painter.setPen(Qt::white);
|
||||
painter.drawText(rect(), Qt::AlignCenter, "88:88");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
18
plugins/datetime/datetimewidget.h
Normal file
18
plugins/datetime/datetimewidget.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef DATETIMEWIDGET_H
|
||||
#define DATETIMEWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class DatetimeWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DatetimeWidget(QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
QSize sizeHint() const;
|
||||
void paintEvent(QPaintEvent *e);
|
||||
};
|
||||
|
||||
#endif // DATETIMEWIDGET_H
|
Loading…
x
Reference in New Issue
Block a user