From 028762a5b6b7e1be59d4e87c73d99786be4bba0e Mon Sep 17 00:00:00 2001 From: donghualin Date: Tue, 16 Aug 2022 09:39:43 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=B6=E5=B0=9A=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E6=97=A5=E6=9C=9F=E6=97=B6=E9=97=B4=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 时尚模式下的日期时间增加右键菜单,并且响应对应的功能 Log: Influence: 任务栏-时尚模式,右键查看日期时间是否存在时间日期菜单 Task: https://pms.uniontech.com/task-view-162235.html Change-Id: I7a7cb951647d8fcba85087e8baec54f41d9f9226 --- frame/window/components/datetimedisplayer.cpp | 67 +++++++++++++++++-- frame/window/components/datetimedisplayer.h | 9 ++- frame/window/quicksettingcontainer.cpp | 3 + frame/window/systempluginwindow.cpp | 1 - frame/window/systempluginwindow.h | 3 +- frame/window/traymanagerwindow.cpp | 2 +- 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/frame/window/components/datetimedisplayer.cpp b/frame/window/components/datetimedisplayer.cpp index e751d1ac6..dc8fe195b 100644 --- a/frame/window/components/datetimedisplayer.cpp +++ b/frame/window/components/datetimedisplayer.cpp @@ -29,6 +29,7 @@ #include #include #include +#include DWIDGET_USE_NAMESPACE DGUI_USE_NAMESPACE @@ -46,6 +47,7 @@ DateTimeDisplayer::DateTimeDisplayer(QWidget *parent) , m_position(Dock::Position::Bottom) , m_dateFont(DFontSizeManager::instance()->t10()) , m_tipsWidget(new Dock::TipsWidget(this)) + , m_menu(new QMenu(this)) , m_tipsTimer(new QTimer(this)) , m_currentSize(0) , m_oneRow(false) @@ -64,10 +66,10 @@ DateTimeDisplayer::DateTimeDisplayer(QWidget *parent) m_tipsTimer->setInterval(1000); m_tipsTimer->start(); updatePolicy(); - m_tipPopupWindow->hide(); - if (Utils::IS_WAYLAND_DISPLAY) { + createMenuItem(); + if (Utils::IS_WAYLAND_DISPLAY) m_tipPopupWindow->setWindowFlags(m_tipPopupWindow->windowFlags() | Qt::FramelessWindowHint); - } + m_tipPopupWindow->hide(); } DateTimeDisplayer::~DateTimeDisplayer() @@ -131,6 +133,14 @@ QSize DateTimeDisplayer::suitableSize() return QSize(width(), info.m_timeRect.height() + info.m_dateRect.height()); } +void DateTimeDisplayer::mousePressEvent(QMouseEvent *event) +{ + if ((event->button() != Qt::RightButton)) + return QWidget::mousePressEvent(event); + + m_menu->exec(QCursor::pos()); +} + void DateTimeDisplayer::mouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event); @@ -226,7 +236,7 @@ void DateTimeDisplayer::onDateTimeFormatChanged() repaint(); // 如果日期时间的格式发生了变化,需要通知外部来调整日期时间的尺寸 if (lastSize != m_currentSize) - Q_EMIT sizeChanged(); + Q_EMIT requestUpdate(); } void DateTimeDisplayer::paintEvent(QPaintEvent *e) @@ -302,6 +312,45 @@ QFont DateTimeDisplayer::timeFont() const return dateFontSize[index]; } +void DateTimeDisplayer::createMenuItem() +{ + QAction *timeFormatAction = new QAction(this); + if (m_timedateInter->use24HourFormat()) + timeFormatAction->setText(tr("12-hour time")); + else + timeFormatAction->setText(tr("24-hour time")); + + connect(timeFormatAction, &QAction::triggered, this, [ = ] { + m_timedateInter->setUse24HourFormat(!m_timedateInter->use24HourFormat()); + }); + m_menu->addAction(timeFormatAction); + + if (!QFile::exists(ICBC_CONF_FILE)) { + QAction *timeSettingAction = new QAction(tr("Time settings"), this); + connect(timeSettingAction, &QAction::triggered, this, [ = ] { +#ifdef USE_AM + DDBusSender() + .service("org.deepin.dde.ControlCenter1") + .interface("org.deepin.dde.ControlCenter1") + .path("/org/deepin/dde/ControlCenter1") + .method(QString("ShowPage")) + .arg(QString("datetime")) + .call(); +#else + DDBusSender() + .service("com.deepin.dde.ControlCenter") + .interface("com.deepin.dde.ControlCenter") + .path("/com/deepin/dde/ControlCenter") + .method(QString("ShowPage")) + .arg(QString("datetime")) + .call(); +#endif + }); + + m_menu->addAction(timeSettingAction); + } +} + void DateTimeDisplayer::enterEvent(QEvent *event) { Q_UNUSED(event); @@ -314,6 +363,16 @@ void DateTimeDisplayer::leaveEvent(QEvent *event) m_tipPopupWindow->hide(); } +void DateTimeDisplayer::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); + + int oldSize = m_currentSize; + m_currentSize = (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) ? width() : height(); + if (oldSize != m_currentSize) + Q_EMIT requestUpdate(); +} + void DateTimeDisplayer::updateLastData(const DateTimeInfo &info) { m_lastDateString = info.m_date; diff --git a/frame/window/components/datetimedisplayer.h b/frame/window/components/datetimedisplayer.h index 3b1a29e8e..693db0b53 100644 --- a/frame/window/components/datetimedisplayer.h +++ b/frame/window/components/datetimedisplayer.h @@ -29,7 +29,9 @@ #include namespace Dock { class TipsWidget; } + class DockPopupWindow; +class QMenu; using Timedate = com::deepin::daemon::Timedate; @@ -53,13 +55,15 @@ public: QSize suitableSize(); Q_SIGNALS: - void sizeChanged(); // 当日期时间格式发生变化的时候,需要通知外面来更新窗口尺寸 + void requestUpdate(); // 当日期时间格式发生变化的时候,需要通知外面来更新窗口尺寸 protected: + void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void paintEvent(QPaintEvent *e) override; void enterEvent(QEvent *event) override; void leaveEvent(QEvent *event) override; + void resizeEvent(QResizeEvent *event) override; private: void updatePolicy(); @@ -72,6 +76,8 @@ private: QPoint tipsPoint() const; QFont timeFont() const; + void createMenuItem(); + private Q_SLOTS: void onTimeChanged(); void onDateTimeFormatChanged(); @@ -81,6 +87,7 @@ private: Dock::Position m_position; QFont m_dateFont; Dock::TipsWidget *m_tipsWidget; + QMenu *m_menu; QSharedPointer m_tipPopupWindow; QTimer *m_tipsTimer; QString m_lastDateString; diff --git a/frame/window/quicksettingcontainer.cpp b/frame/window/quicksettingcontainer.cpp index 53c290e5a..133686b0d 100644 --- a/frame/window/quicksettingcontainer.cpp +++ b/frame/window/quicksettingcontainer.cpp @@ -31,6 +31,7 @@ #include "volumedeviceswidget.h" #include "pluginchildpage.h" #include "volumemodel.h" +#include "utils.h" #include #include @@ -120,6 +121,8 @@ DockPopupWindow *QuickSettingContainer::popWindow() m_popWindow->setArrowHeight(10); m_popWindow->setArrowDirection(getDirection(m_position)); m_popWindow->setContent(new QuickSettingContainer(m_popWindow)); + if (Utils::IS_WAYLAND_DISPLAY) + m_popWindow->setWindowFlags(m_popWindow->windowFlags() | Qt::FramelessWindowHint | Qt::Popup); return m_popWindow; } diff --git a/frame/window/systempluginwindow.cpp b/frame/window/systempluginwindow.cpp index fed159c50..478b4ccaf 100644 --- a/frame/window/systempluginwindow.cpp +++ b/frame/window/systempluginwindow.cpp @@ -21,7 +21,6 @@ #include "systempluginwindow.h" #include "systemplugincontroller.h" #include "systempluginitem.h" -#include "dockpluginscontroller.h" #include "fixedplugincontroller.h" #include diff --git a/frame/window/systempluginwindow.h b/frame/window/systempluginwindow.h index bb8e5ec13..a21ba18a4 100644 --- a/frame/window/systempluginwindow.h +++ b/frame/window/systempluginwindow.h @@ -22,13 +22,14 @@ #define SYSTEMPLUGINWINDOW_H #include "constants.h" -#include "dockpluginscontroller.h" +#include "dockitem.h" #include class FixedPluginController; class StretchPluginsItem; class QBoxLayout; +class PluginsItemInterface; namespace Dtk { namespace Widget { class DListView; } } diff --git a/frame/window/traymanagerwindow.cpp b/frame/window/traymanagerwindow.cpp index 50b03cc68..6a41748fa 100644 --- a/frame/window/traymanagerwindow.cpp +++ b/frame/window/traymanagerwindow.cpp @@ -294,7 +294,7 @@ void TrayManagerWindow::initConnection() } } }); - connect(m_dateTimeWidget, &DateTimeDisplayer::sizeChanged, this, &TrayManagerWindow::requestUpdate); + connect(m_dateTimeWidget, &DateTimeDisplayer::requestUpdate, this, &TrayManagerWindow::requestUpdate); m_trayView->installEventFilter(this); m_quickIconWidget->installEventFilter(this);