mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
feat: 更改任务栏界面的时间显示格式
任务栏界面时间格式根据控制中心设置来显示 Log: 更改任务栏界面的时间显示格式 Task: https://pms.uniontech.com/zentao/task-view-30918.html Change-Id: I35c47685c2efbe8f12afdc9a2bb5bb59f4b5324e Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/932 Reviewed-by: <mailman@uniontech.com> Reviewed-by: niecheng <niecheng@uniontech.com> Reviewed-by: wangwei <wangwei@uniontech.com> Tested-by: <mailman@uniontech.com>
This commit is contained in:
parent
9fd43e1c4d
commit
77eae531b7
@ -1 +0,0 @@
|
|||||||
deb [trusted=yes] http://shuttle.corp.deepin.com/cache/repos/eagle-sp3/release-candidate/RERF5byA5Y-R5rWL6K-VMTE5OQ unstable main contrib
|
|
@ -11,16 +11,22 @@ find_package(Qt5Widgets REQUIRED)
|
|||||||
find_package(Qt5Svg REQUIRED)
|
find_package(Qt5Svg REQUIRED)
|
||||||
find_package(Qt5DBus REQUIRED)
|
find_package(Qt5DBus REQUIRED)
|
||||||
find_package(DtkWidget REQUIRED)
|
find_package(DtkWidget REQUIRED)
|
||||||
|
pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
|
||||||
|
|
||||||
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
|
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
|
||||||
add_library(${PLUGIN_NAME} SHARED ${SRCS} datetime.qrc)
|
add_library(${PLUGIN_NAME} SHARED ${SRCS} datetime.qrc)
|
||||||
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../)
|
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../)
|
||||||
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces)
|
target_include_directories(${PLUGIN_NAME} PUBLIC
|
||||||
|
${DtkWidget_INCLUDE_DIRS}
|
||||||
|
${DFrameworkDBus_INCLUDE_DIRS}
|
||||||
|
../../interfaces ${Qt5DBus_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
target_link_libraries(${PLUGIN_NAME} PRIVATE
|
target_link_libraries(${PLUGIN_NAME} PRIVATE
|
||||||
${Qt5DBus_LIBRARIES}
|
${Qt5DBus_LIBRARIES}
|
||||||
${DtkWidget_LIBRARIES}
|
${DtkWidget_LIBRARIES}
|
||||||
${Qt5Widgets_LIBRARIES}
|
${Qt5Widgets_LIBRARIES}
|
||||||
${Qt5Svg_LIBRARIES}
|
${Qt5Svg_LIBRARIES}
|
||||||
|
${DFrameworkDBus_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins)
|
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins)
|
||||||
|
@ -40,8 +40,16 @@ DatetimeWidget::DatetimeWidget(QWidget *parent)
|
|||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_24HourFormat(false)
|
, m_24HourFormat(false)
|
||||||
, m_timeOffset(false)
|
, m_timeOffset(false)
|
||||||
|
, m_timedateInter(new Timedate("com.deepin.daemon.Timedate", "/com/deepin/daemon/Timedate", QDBusConnection::sessionBus(), this))
|
||||||
|
, m_shortDateFormat("yyyy-MM-dd")
|
||||||
|
, m_shortTimeFormat("hh:mm")
|
||||||
{
|
{
|
||||||
setMinimumSize(PLUGIN_BACKGROUND_MIN_SIZE, PLUGIN_BACKGROUND_MIN_SIZE);
|
setMinimumSize(PLUGIN_BACKGROUND_MIN_SIZE, PLUGIN_BACKGROUND_MIN_SIZE);
|
||||||
|
setShortDateFormat(m_timedateInter->shortDateFormat());
|
||||||
|
setShortTimeFormat(m_timedateInter->shortTimeFormat());
|
||||||
|
|
||||||
|
connect(m_timedateInter, &Timedate::ShortDateFormatChanged, this, &DatetimeWidget::setShortDateFormat);
|
||||||
|
connect(m_timedateInter, &Timedate::ShortTimeFormatChanged, this, &DatetimeWidget::setShortTimeFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatetimeWidget::set24HourFormat(const bool value)
|
void DatetimeWidget::set24HourFormat(const bool value)
|
||||||
@ -59,6 +67,43 @@ void DatetimeWidget::set24HourFormat(const bool value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DatetimeWidget::setShortDateFormat 根据类型设置时间显示格式
|
||||||
|
* @param type 自定义类型
|
||||||
|
*/
|
||||||
|
void DatetimeWidget::setShortDateFormat(int type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case 0: m_shortDateFormat = "yyyy/M/d"; break;
|
||||||
|
case 1: m_shortDateFormat = "yyyy-M-d"; break;
|
||||||
|
case 2: m_shortDateFormat = "yyyy.M.d"; break;
|
||||||
|
case 3: m_shortDateFormat = "yyyy/MM/dd"; break;
|
||||||
|
case 4: m_shortDateFormat = "yyyy-MM-dd"; break;
|
||||||
|
case 5: m_shortDateFormat = "yyyy.MM.dd"; break;
|
||||||
|
case 6: m_shortDateFormat = "yy/M/d"; break;
|
||||||
|
case 7: m_shortDateFormat = "yy-M-d"; break;
|
||||||
|
case 8: m_shortDateFormat = "yy.M.d"; break;
|
||||||
|
default: m_shortDateFormat = "yyyy-MM-dd"; break;
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DatetimeWidget::setShortTimeFormat 根据类型设置短时间显示格式
|
||||||
|
* @param type 自定义类型
|
||||||
|
*/
|
||||||
|
void DatetimeWidget::setShortTimeFormat(int type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case 0: m_shortTimeFormat = "h:m"; break;
|
||||||
|
case 1: m_shortTimeFormat = "hh:mm"; break;
|
||||||
|
case 2: m_shortTimeFormat = "h:m"; break;
|
||||||
|
case 3: m_shortTimeFormat = "hh:mm"; break;
|
||||||
|
default: m_shortTimeFormat = "hh:mm"; break;
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
QSize DatetimeWidget::curTimeSize() const
|
QSize DatetimeWidget::curTimeSize() const
|
||||||
{
|
{
|
||||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||||
@ -66,21 +111,19 @@ QSize DatetimeWidget::curTimeSize() const
|
|||||||
m_timeFont = TIME_FONT;
|
m_timeFont = TIME_FONT;
|
||||||
m_dateFont = DATE_FONT;
|
m_dateFont = DATE_FONT;
|
||||||
QFontMetrics fm(m_timeFont);
|
QFontMetrics fm(m_timeFont);
|
||||||
QString format;
|
QString format = m_shortTimeFormat;
|
||||||
if (m_24HourFormat)
|
if (!m_24HourFormat) {
|
||||||
format = "hh:mm";
|
|
||||||
else {
|
|
||||||
if (position == Dock::Top || position == Dock::Bottom)
|
if (position == Dock::Top || position == Dock::Bottom)
|
||||||
format = "hh:mm AP";
|
format = format.append(" AP");
|
||||||
else
|
else
|
||||||
format = "hh:mm\nAP";
|
format = format.append("\nAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString timeString = QDateTime::currentDateTime().toString(format);
|
QString timeString = QDateTime::currentDateTime().toString(format);
|
||||||
QSize timeSize = fm.boundingRect(timeString).size();
|
QSize timeSize = fm.boundingRect(timeString).size();
|
||||||
if (timeString.contains("\n")) {
|
if (timeString.contains("\n")) {
|
||||||
QStringList SL = timeString.split("\n");
|
QStringList SL = timeString.split("\n");
|
||||||
timeSize = QSize(fm.boundingRect(SL.at(0)).width(), fm.boundingRect(SL.at(0)).height() + fm.boundingRect(SL.at(1)).height());
|
timeSize = QSize(fm.boundingRect(SL.at(0)).width(), fm.boundingRect(SL.at(0)).height() + fm.boundingRect(SL.at(1)).height());
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize dateSize = QFontMetrics(m_dateFont).boundingRect("0000/00/00").size();
|
QSize dateSize = QFontMetrics(m_dateFont).boundingRect("0000/00/00").size();
|
||||||
@ -89,7 +132,7 @@ QSize DatetimeWidget::curTimeSize() const
|
|||||||
while (QFontMetrics(m_timeFont).boundingRect(timeString).size().height() + QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().height() > height()) {
|
while (QFontMetrics(m_timeFont).boundingRect(timeString).size().height() + QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().height() > height()) {
|
||||||
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
m_timeFont.setPixelSize(m_timeFont.pixelSize() - 1);
|
||||||
timeSize.setWidth(QFontMetrics(m_timeFont).boundingRect(timeString).size().width());
|
timeSize.setWidth(QFontMetrics(m_timeFont).boundingRect(timeString).size().width());
|
||||||
if (m_timeFont.pixelSize() - m_dateFont.pixelSize() == 1){
|
if (m_timeFont.pixelSize() - m_dateFont.pixelSize() == 1) {
|
||||||
m_dateFont.setPixelSize(m_dateFont.pixelSize() - 1);
|
m_dateFont.setPixelSize(m_dateFont.pixelSize() - 1);
|
||||||
dateSize.setWidth(QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().width());
|
dateSize.setWidth(QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().width());
|
||||||
}
|
}
|
||||||
@ -103,7 +146,7 @@ QSize DatetimeWidget::curTimeSize() const
|
|||||||
} else {
|
} else {
|
||||||
timeSize.setHeight(QFontMetrics(m_timeFont).boundingRect(timeString).size().height() * 2);
|
timeSize.setHeight(QFontMetrics(m_timeFont).boundingRect(timeString).size().height() * 2);
|
||||||
}
|
}
|
||||||
if (m_timeFont.pixelSize() - m_dateFont.pixelSize() == 1){
|
if (m_timeFont.pixelSize() - m_dateFont.pixelSize() == 1) {
|
||||||
m_dateFont.setPixelSize(m_dateFont.pixelSize() - 1);
|
m_dateFont.setPixelSize(m_dateFont.pixelSize() - 1);
|
||||||
dateSize.setWidth(QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().height());
|
dateSize.setWidth(QFontMetrics(m_dateFont).boundingRect("0000/00/00").size().height());
|
||||||
}
|
}
|
||||||
@ -128,14 +171,12 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
|||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
QString format;
|
QString format = m_shortTimeFormat;
|
||||||
if (m_24HourFormat)
|
if (!m_24HourFormat) {
|
||||||
format = "hh:mm";
|
|
||||||
else {
|
|
||||||
if (position == Dock::Top || position == Dock::Bottom)
|
if (position == Dock::Top || position == Dock::Bottom)
|
||||||
format = "hh:mm AP";
|
format = format.append(" AP");
|
||||||
else
|
else
|
||||||
format = "hh:mm\nAP";
|
format = format.append("\nAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.setFont(m_timeFont);
|
painter.setFont(m_timeFont);
|
||||||
@ -144,15 +185,15 @@ void DatetimeWidget::paintEvent(QPaintEvent *e)
|
|||||||
QRect timeRect = rect();
|
QRect timeRect = rect();
|
||||||
QRect dateRect = rect();
|
QRect dateRect = rect();
|
||||||
|
|
||||||
if (position == Dock::Top || position == Dock::Bottom){
|
if (position == Dock::Top || position == Dock::Bottom) {
|
||||||
timeRect.setBottom(rect().center().y() + 6);
|
timeRect.setBottom(rect().center().y() + 6);
|
||||||
dateRect.setTop(timeRect.bottom() - 4);
|
dateRect.setTop(timeRect.bottom() - 4);
|
||||||
} else {
|
} else {
|
||||||
timeRect.setBottom(rect().center().y() + m_timeOffset);
|
timeRect.setBottom(rect().center().y() + m_timeOffset);
|
||||||
dateRect.setTop(timeRect.bottom());
|
dateRect.setTop(timeRect.bottom());
|
||||||
}
|
}
|
||||||
painter.drawText(timeRect, Qt::AlignBottom | Qt::AlignHCenter, current.toString(format));
|
painter.drawText(timeRect, Qt::AlignBottom | Qt::AlignHCenter, current.toString(format));
|
||||||
format = "yyyy/MM/dd";
|
format = m_shortDateFormat;
|
||||||
painter.setFont(m_dateFont);
|
painter.setFont(m_dateFont);
|
||||||
painter.drawText(dateRect, Qt::AlignTop | Qt::AlignHCenter, current.toString(format));
|
painter.drawText(dateRect, Qt::AlignTop | Qt::AlignHCenter, current.toString(format));
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,12 @@
|
|||||||
#ifndef DATETIMEWIDGET_H
|
#ifndef DATETIMEWIDGET_H
|
||||||
#define DATETIMEWIDGET_H
|
#define DATETIMEWIDGET_H
|
||||||
|
|
||||||
|
#include <com_deepin_daemon_timedate.h>
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
using Timedate = com::deepin::daemon::Timedate;
|
||||||
|
|
||||||
class DatetimeWidget : public QWidget
|
class DatetimeWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -40,6 +44,10 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void set24HourFormat(const bool value);
|
void set24HourFormat(const bool value);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void setShortDateFormat(int type);
|
||||||
|
void setShortTimeFormat(int type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
QSize curTimeSize() const;
|
QSize curTimeSize() const;
|
||||||
@ -49,6 +57,9 @@ private:
|
|||||||
mutable QFont m_timeFont;
|
mutable QFont m_timeFont;
|
||||||
mutable QFont m_dateFont;
|
mutable QFont m_dateFont;
|
||||||
mutable int m_timeOffset;
|
mutable int m_timeOffset;
|
||||||
|
Timedate *m_timedateInter;
|
||||||
|
QString m_shortDateFormat;
|
||||||
|
QString m_shortTimeFormat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user