mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix: 时尚模式下日期时间增加右键菜单
时尚模式下的日期时间增加右键菜单,并且响应对应的功能 Log: Influence: 任务栏-时尚模式,右键查看日期时间是否存在时间日期菜单 Task: https://pms.uniontech.com/task-view-162235.html Change-Id: I7a7cb951647d8fcba85087e8baec54f41d9f9226
This commit is contained in:
parent
c78f101e84
commit
028762a5b6
@ -29,6 +29,7 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
DGUI_USE_NAMESPACE
|
DGUI_USE_NAMESPACE
|
||||||
@ -46,6 +47,7 @@ DateTimeDisplayer::DateTimeDisplayer(QWidget *parent)
|
|||||||
, m_position(Dock::Position::Bottom)
|
, m_position(Dock::Position::Bottom)
|
||||||
, m_dateFont(DFontSizeManager::instance()->t10())
|
, m_dateFont(DFontSizeManager::instance()->t10())
|
||||||
, m_tipsWidget(new Dock::TipsWidget(this))
|
, m_tipsWidget(new Dock::TipsWidget(this))
|
||||||
|
, m_menu(new QMenu(this))
|
||||||
, m_tipsTimer(new QTimer(this))
|
, m_tipsTimer(new QTimer(this))
|
||||||
, m_currentSize(0)
|
, m_currentSize(0)
|
||||||
, m_oneRow(false)
|
, m_oneRow(false)
|
||||||
@ -64,10 +66,10 @@ DateTimeDisplayer::DateTimeDisplayer(QWidget *parent)
|
|||||||
m_tipsTimer->setInterval(1000);
|
m_tipsTimer->setInterval(1000);
|
||||||
m_tipsTimer->start();
|
m_tipsTimer->start();
|
||||||
updatePolicy();
|
updatePolicy();
|
||||||
m_tipPopupWindow->hide();
|
createMenuItem();
|
||||||
if (Utils::IS_WAYLAND_DISPLAY) {
|
if (Utils::IS_WAYLAND_DISPLAY)
|
||||||
m_tipPopupWindow->setWindowFlags(m_tipPopupWindow->windowFlags() | Qt::FramelessWindowHint);
|
m_tipPopupWindow->setWindowFlags(m_tipPopupWindow->windowFlags() | Qt::FramelessWindowHint);
|
||||||
}
|
m_tipPopupWindow->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTimeDisplayer::~DateTimeDisplayer()
|
DateTimeDisplayer::~DateTimeDisplayer()
|
||||||
@ -131,6 +133,14 @@ QSize DateTimeDisplayer::suitableSize()
|
|||||||
return QSize(width(), info.m_timeRect.height() + info.m_dateRect.height());
|
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)
|
void DateTimeDisplayer::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
@ -226,7 +236,7 @@ void DateTimeDisplayer::onDateTimeFormatChanged()
|
|||||||
repaint();
|
repaint();
|
||||||
// 如果日期时间的格式发生了变化,需要通知外部来调整日期时间的尺寸
|
// 如果日期时间的格式发生了变化,需要通知外部来调整日期时间的尺寸
|
||||||
if (lastSize != m_currentSize)
|
if (lastSize != m_currentSize)
|
||||||
Q_EMIT sizeChanged();
|
Q_EMIT requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DateTimeDisplayer::paintEvent(QPaintEvent *e)
|
void DateTimeDisplayer::paintEvent(QPaintEvent *e)
|
||||||
@ -302,6 +312,45 @@ QFont DateTimeDisplayer::timeFont() const
|
|||||||
return dateFontSize[index];
|
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)
|
void DateTimeDisplayer::enterEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
@ -314,6 +363,16 @@ void DateTimeDisplayer::leaveEvent(QEvent *event)
|
|||||||
m_tipPopupWindow->hide();
|
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)
|
void DateTimeDisplayer::updateLastData(const DateTimeInfo &info)
|
||||||
{
|
{
|
||||||
m_lastDateString = info.m_date;
|
m_lastDateString = info.m_date;
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
#include <com_deepin_daemon_timedate.h>
|
#include <com_deepin_daemon_timedate.h>
|
||||||
|
|
||||||
namespace Dock { class TipsWidget; }
|
namespace Dock { class TipsWidget; }
|
||||||
|
|
||||||
class DockPopupWindow;
|
class DockPopupWindow;
|
||||||
|
class QMenu;
|
||||||
|
|
||||||
using Timedate = com::deepin::daemon::Timedate;
|
using Timedate = com::deepin::daemon::Timedate;
|
||||||
|
|
||||||
@ -53,13 +55,15 @@ public:
|
|||||||
QSize suitableSize();
|
QSize suitableSize();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void sizeChanged(); // 当日期时间格式发生变化的时候,需要通知外面来更新窗口尺寸
|
void requestUpdate(); // 当日期时间格式发生变化的时候,需要通知外面来更新窗口尺寸
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void enterEvent(QEvent *event) override;
|
void enterEvent(QEvent *event) override;
|
||||||
void leaveEvent(QEvent *event) override;
|
void leaveEvent(QEvent *event) override;
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updatePolicy();
|
void updatePolicy();
|
||||||
@ -72,6 +76,8 @@ private:
|
|||||||
QPoint tipsPoint() const;
|
QPoint tipsPoint() const;
|
||||||
QFont timeFont() const;
|
QFont timeFont() const;
|
||||||
|
|
||||||
|
void createMenuItem();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onTimeChanged();
|
void onTimeChanged();
|
||||||
void onDateTimeFormatChanged();
|
void onDateTimeFormatChanged();
|
||||||
@ -81,6 +87,7 @@ private:
|
|||||||
Dock::Position m_position;
|
Dock::Position m_position;
|
||||||
QFont m_dateFont;
|
QFont m_dateFont;
|
||||||
Dock::TipsWidget *m_tipsWidget;
|
Dock::TipsWidget *m_tipsWidget;
|
||||||
|
QMenu *m_menu;
|
||||||
QSharedPointer<DockPopupWindow> m_tipPopupWindow;
|
QSharedPointer<DockPopupWindow> m_tipPopupWindow;
|
||||||
QTimer *m_tipsTimer;
|
QTimer *m_tipsTimer;
|
||||||
QString m_lastDateString;
|
QString m_lastDateString;
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "volumedeviceswidget.h"
|
#include "volumedeviceswidget.h"
|
||||||
#include "pluginchildpage.h"
|
#include "pluginchildpage.h"
|
||||||
#include "volumemodel.h"
|
#include "volumemodel.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <DListView>
|
#include <DListView>
|
||||||
#include <DStyle>
|
#include <DStyle>
|
||||||
@ -120,6 +121,8 @@ DockPopupWindow *QuickSettingContainer::popWindow()
|
|||||||
m_popWindow->setArrowHeight(10);
|
m_popWindow->setArrowHeight(10);
|
||||||
m_popWindow->setArrowDirection(getDirection(m_position));
|
m_popWindow->setArrowDirection(getDirection(m_position));
|
||||||
m_popWindow->setContent(new QuickSettingContainer(m_popWindow));
|
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;
|
return m_popWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "systempluginwindow.h"
|
#include "systempluginwindow.h"
|
||||||
#include "systemplugincontroller.h"
|
#include "systemplugincontroller.h"
|
||||||
#include "systempluginitem.h"
|
#include "systempluginitem.h"
|
||||||
#include "dockpluginscontroller.h"
|
|
||||||
#include "fixedplugincontroller.h"
|
#include "fixedplugincontroller.h"
|
||||||
|
|
||||||
#include <DListView>
|
#include <DListView>
|
||||||
|
@ -22,13 +22,14 @@
|
|||||||
#define SYSTEMPLUGINWINDOW_H
|
#define SYSTEMPLUGINWINDOW_H
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "dockpluginscontroller.h"
|
#include "dockitem.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class FixedPluginController;
|
class FixedPluginController;
|
||||||
class StretchPluginsItem;
|
class StretchPluginsItem;
|
||||||
class QBoxLayout;
|
class QBoxLayout;
|
||||||
|
class PluginsItemInterface;
|
||||||
|
|
||||||
namespace Dtk { namespace Widget { class DListView; } }
|
namespace Dtk { namespace Widget { class DListView; } }
|
||||||
|
|
||||||
|
@ -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_trayView->installEventFilter(this);
|
||||||
m_quickIconWidget->installEventFilter(this);
|
m_quickIconWidget->installEventFilter(this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user