mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
datetime: add am/pm tips on 24 hour format
Change-Id: I51affb6a5a59492cfd8804b3766a29d107d20aa5
This commit is contained in:
parent
f3cc3452de
commit
0584380b20
Notes:
Deepin Code Review
2017-06-27 09:20:28 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 27 Jun 2017 09:20:19 +0800 Reviewed-on: https://cr.deepin.io/24051 Project: dde/dde-dock Branch: refs/heads/master
@ -79,6 +79,11 @@ void PluginsItem::setInContainer(const bool container)
|
||||
m_pluginInter->setItemIsInContainer(m_itemKey, container);
|
||||
}
|
||||
|
||||
QSize PluginsItem::sizeHint() const
|
||||
{
|
||||
return m_centralWidget->sizeHint();
|
||||
}
|
||||
|
||||
void PluginsItem::refershIcon()
|
||||
{
|
||||
m_pluginInter->refershIcon(m_itemKey);
|
||||
|
@ -23,20 +23,21 @@ public:
|
||||
using DockItem::showContextMenu;
|
||||
using DockItem::hidePopup;
|
||||
|
||||
inline ItemType itemType() const {return Plugins;}
|
||||
inline ItemType itemType() const override {return Plugins;}
|
||||
QSize sizeHint() const override;
|
||||
|
||||
public slots:
|
||||
void refershIcon();
|
||||
void refershIcon() override;
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
bool eventFilter(QObject *o, QEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
bool eventFilter(QObject *o, QEvent *e) override;
|
||||
|
||||
void invokedMenuItem(const QString &itemId, const bool checked);
|
||||
const QString contextMenu() const;
|
||||
QWidget *popupTips();
|
||||
void invokedMenuItem(const QString &itemId, const bool checked) override;
|
||||
const QString contextMenu() const override;
|
||||
QWidget *popupTips() override;
|
||||
|
||||
private:
|
||||
void startDrag();
|
||||
|
@ -18,7 +18,8 @@ DatetimePlugin::DatetimePlugin(QObject *parent)
|
||||
|
||||
m_centralWidget = new DatetimeWidget;
|
||||
|
||||
connect(m_centralWidget, &DatetimeWidget::requestContextMenu, [this] {m_proxyInter->requestContextMenu(this, QString());});
|
||||
connect(m_centralWidget, &DatetimeWidget::requestContextMenu, [this] { m_proxyInter->requestContextMenu(this, QString()); });
|
||||
connect(m_centralWidget, &DatetimeWidget::requestUpdateGeometry, [this] { m_proxyInter->itemUpdate(this, QString()); });
|
||||
|
||||
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::updateCurrentTimeString);
|
||||
}
|
||||
|
@ -25,13 +25,18 @@ void DatetimeWidget::toggleHourFormat()
|
||||
|
||||
m_cachedTime.clear();
|
||||
update();
|
||||
|
||||
emit requestUpdateGeometry();
|
||||
}
|
||||
|
||||
QSize DatetimeWidget::sizeHint() const
|
||||
{
|
||||
QFontMetrics fm(qApp->font());
|
||||
|
||||
return fm.boundingRect("88:88").size() + QSize(20, 10);
|
||||
if (m_24HourFormat)
|
||||
return fm.boundingRect("88:88").size() + QSize(20, 10);
|
||||
else
|
||||
return fm.boundingRect("88:88 A.A.").size() + QSize(20, 20);
|
||||
}
|
||||
|
||||
void DatetimeWidget::resizeEvent(QResizeEvent *e)
|
||||
@ -46,16 +51,26 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
||||
Q_UNUSED(e);
|
||||
|
||||
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||
const QDateTime current = QDateTime::currentDateTime();
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
if (displayMode == Dock::Efficient)
|
||||
{
|
||||
const QString text = current.toString(m_24HourFormat ? "hh:mm" : "hh:mm A");
|
||||
QString format;
|
||||
if (m_24HourFormat)
|
||||
format = "hh:mm";
|
||||
else
|
||||
{
|
||||
if (position == Dock::Top || position == Dock::Bottom)
|
||||
format = "hh:mm AP";
|
||||
else
|
||||
format = "hh:mm\nAP";
|
||||
}
|
||||
|
||||
painter.setPen(Qt::white);
|
||||
painter.drawText(rect(), Qt::AlignCenter, text.left(5));
|
||||
painter.drawText(rect(), Qt::AlignCenter, current.time().toString(format));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -97,17 +112,45 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
||||
const QPoint bigNum2Offset = bigNum1Offset + QPoint(bigNumWidth + 1, 0);
|
||||
p.drawPixmap(bigNum2Offset, bigNum2);
|
||||
|
||||
// draw small num 1
|
||||
const QString smallNum1Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[2]);
|
||||
const QPixmap smallNum1 = loadSvg(smallNum1Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum1Offset = bigNum2Offset + QPoint(bigNumWidth + 2, smallNumHeight);
|
||||
p.drawPixmap(smallNum1Offset, smallNum1);
|
||||
if (!m_24HourFormat)
|
||||
{
|
||||
// draw small num 1
|
||||
const QString smallNum1Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[2]);
|
||||
const QPixmap smallNum1 = loadSvg(smallNum1Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum1Offset = bigNum2Offset + QPoint(bigNumWidth + 2, 1);
|
||||
p.drawPixmap(smallNum1Offset, smallNum1);
|
||||
|
||||
// draw small num 2
|
||||
const QString smallNum2Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[3]);
|
||||
const QPixmap smallNum2 = loadSvg(smallNum2Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum2Offset = smallNum1Offset + QPoint(smallNumWidth + 1, 0);
|
||||
p.drawPixmap(smallNum2Offset, smallNum2);
|
||||
// draw small num 2
|
||||
const QString smallNum2Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[3]);
|
||||
const QPixmap smallNum2 = loadSvg(smallNum2Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum2Offset = smallNum1Offset + QPoint(smallNumWidth + 1, 0);
|
||||
p.drawPixmap(smallNum2Offset, smallNum2);
|
||||
|
||||
// draw am/pm tips
|
||||
const int tips_width = (smallNumWidth * 2 + 2) & ~0x1;
|
||||
const int tips_height = tips_width / 2;
|
||||
|
||||
QPixmap tips;
|
||||
if (current.time().hour() > 12)
|
||||
tips = loadSvg(":/icons/resources/icons/tips-pm.svg", QSize(tips_width, tips_height));
|
||||
else
|
||||
tips = loadSvg(":/icons/resources/icons/tips-am.svg", QSize(tips_width, tips_height));
|
||||
|
||||
const QPoint tipsOffset = bigNum2Offset + QPoint(bigNumWidth + 2, bigNumHeight - tips_height);
|
||||
p.drawPixmap(tipsOffset, tips);
|
||||
} else {
|
||||
// draw small num 1
|
||||
const QString smallNum1Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[2]);
|
||||
const QPixmap smallNum1 = loadSvg(smallNum1Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum1Offset = bigNum2Offset + QPoint(bigNumWidth + 2, smallNumHeight);
|
||||
p.drawPixmap(smallNum1Offset, smallNum1);
|
||||
|
||||
// draw small num 2
|
||||
const QString smallNum2Path = QString(":/icons/resources/icons/small%1.svg").arg(currentTimeString[3]);
|
||||
const QPixmap smallNum2 = loadSvg(smallNum2Path, QSize(smallNumWidth, smallNumHeight));
|
||||
const QPoint smallNum2Offset = smallNum1Offset + QPoint(smallNumWidth + 1, 0);
|
||||
p.drawPixmap(smallNum2Offset, smallNum2);
|
||||
}
|
||||
}
|
||||
|
||||
// draw cached fashion mode time item
|
||||
|
@ -14,6 +14,7 @@ public:
|
||||
bool is24HourFormat() const { return m_24HourFormat; }
|
||||
|
||||
signals:
|
||||
void requestUpdateGeometry() const;
|
||||
void requestContextMenu() const;
|
||||
|
||||
public slots:
|
||||
|
@ -21,5 +21,7 @@
|
||||
<file>resources/icons/small7.svg</file>
|
||||
<file>resources/icons/small8.svg</file>
|
||||
<file>resources/icons/small9.svg</file>
|
||||
<file>resources/icons/tips-am.svg</file>
|
||||
<file>resources/icons/tips-pm.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
46
plugins/datetime/resources/icons/tips-am.svg
Executable file
46
plugins/datetime/resources/icons/tips-am.svg
Executable file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 21.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 10 5" style="enable-background:new 0 0 10 5;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{opacity:0.3;fill:#2EA7E0;}
|
||||
.st1{fill:url(#SVGID_1_);}
|
||||
.st2{opacity:0.5;fill:url(#SVGID_2_);}
|
||||
.st3{fill:#FFFFFF;}
|
||||
.st4{opacity:0.4;}
|
||||
.st5{opacity:0.2;}
|
||||
.st6{fill:#0C0C0C;}
|
||||
.st7{fill:url(#SVGID_3_);}
|
||||
.st8{fill:#002422;}
|
||||
.st9{fill:url(#SVGID_4_);}
|
||||
.st10{fill:url(#SVGID_5_);}
|
||||
.st11{fill:url(#SVGID_6_);}
|
||||
.st12{fill:url(#SVGID_7_);}
|
||||
.st13{fill:#FFBC00;}
|
||||
.st14{fill:url(#SVGID_8_);}
|
||||
.st15{opacity:0.5;fill:url(#SVGID_9_);}
|
||||
.st16{fill:url(#SVGID_10_);}
|
||||
.st17{fill:url(#SVGID_11_);}
|
||||
.st18{fill:url(#SVGID_12_);}
|
||||
.st19{fill:url(#SVGID_13_);}
|
||||
.st20{fill:url(#SVGID_14_);}
|
||||
.st21{opacity:0.5;fill:#231815;}
|
||||
.st22{opacity:0.4;fill:#231815;}
|
||||
.st23{fill:#47E700;}
|
||||
.st24{fill:url(#SVGID_15_);}
|
||||
.st25{opacity:0.4;fill:#47E700;}
|
||||
.st26{opacity:0.7;fill:#2EA7E0;}
|
||||
.st27{opacity:0.48;}
|
||||
.st28{opacity:0.33;}
|
||||
.st29{opacity:0.38;}
|
||||
.st30{opacity:0.5;}
|
||||
.st31{fill:#CF9111;}
|
||||
.st32{fill:#F9AF15;}
|
||||
.st33{fill:#95A6A4;}
|
||||
.st34{opacity:0.5;fill:#00A0E9;}
|
||||
</style>
|
||||
<g>
|
||||
<path class="st33" d="M0,0v5h1V3h2v2h1V0H0z M3,2H1V1h2V2z"/>
|
||||
<polygon class="st33" points="8,0 7,0 6,0 5,0 5,1 5,5 6,5 6,1 7,1 7,5 8,5 8,1 9,1 9,5 10,5 10,1 10,0 9,0 "/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
46
plugins/datetime/resources/icons/tips-pm.svg
Executable file
46
plugins/datetime/resources/icons/tips-pm.svg
Executable file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 21.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 10 5" style="enable-background:new 0 0 10 5;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{opacity:0.3;fill:#2EA7E0;}
|
||||
.st1{fill:url(#SVGID_1_);}
|
||||
.st2{opacity:0.5;fill:url(#SVGID_2_);}
|
||||
.st3{fill:#FFFFFF;}
|
||||
.st4{opacity:0.4;}
|
||||
.st5{opacity:0.2;}
|
||||
.st6{fill:#0C0C0C;}
|
||||
.st7{fill:url(#SVGID_3_);}
|
||||
.st8{fill:#002422;}
|
||||
.st9{fill:url(#SVGID_4_);}
|
||||
.st10{fill:url(#SVGID_5_);}
|
||||
.st11{fill:url(#SVGID_6_);}
|
||||
.st12{fill:url(#SVGID_7_);}
|
||||
.st13{fill:#FFBC00;}
|
||||
.st14{fill:url(#SVGID_8_);}
|
||||
.st15{opacity:0.5;fill:url(#SVGID_9_);}
|
||||
.st16{fill:url(#SVGID_10_);}
|
||||
.st17{fill:url(#SVGID_11_);}
|
||||
.st18{fill:url(#SVGID_12_);}
|
||||
.st19{fill:url(#SVGID_13_);}
|
||||
.st20{fill:url(#SVGID_14_);}
|
||||
.st21{opacity:0.5;fill:#231815;}
|
||||
.st22{opacity:0.4;fill:#231815;}
|
||||
.st23{fill:#47E700;}
|
||||
.st24{fill:url(#SVGID_15_);}
|
||||
.st25{opacity:0.4;fill:#47E700;}
|
||||
.st26{opacity:0.7;fill:#2EA7E0;}
|
||||
.st27{opacity:0.48;}
|
||||
.st28{opacity:0.33;}
|
||||
.st29{opacity:0.38;}
|
||||
.st30{opacity:0.5;}
|
||||
.st31{fill:#CF9111;}
|
||||
.st32{fill:#F9AF15;}
|
||||
.st33{fill:#95A6A4;}
|
||||
.st34{opacity:0.5;fill:#00A0E9;}
|
||||
</style>
|
||||
<g>
|
||||
<path class="st33" d="M0,5h1V3h3V0H0V5z M1,1h2v1H1V1z"/>
|
||||
<polygon class="st33" points="9,0 8,0 7,0 6,0 5,0 5,1 5,5 6,5 6,1 7,1 7,5 8,5 8,1 9,1 9,5 10,5 10,1 10,0 "/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
Loading…
x
Reference in New Issue
Block a user