diff --git a/frame/window/components/datetimedisplayer.cpp b/frame/window/components/datetimedisplayer.cpp index 0f6b07e63..5ece823d3 100644 --- a/frame/window/components/datetimedisplayer.cpp +++ b/frame/window/components/datetimedisplayer.cpp @@ -40,7 +40,6 @@ DateTimeDisplayer::DateTimeDisplayer(bool showMultiRow, QWidget *parent) , m_currentSize(0) , m_oneRow(false) , m_showMultiRow(showMultiRow) - , m_isEnter(false) { m_tipPopupWindow.reset(new DockPopupWindow); // 日期格式变化的时候,需要重绘 @@ -271,14 +270,6 @@ void DateTimeDisplayer::paintEvent(QPaintEvent *e) painter.setRenderHint(QPainter::Antialiasing); painter.setPen(QPen(palette().brightText(), 1)); - // 绘制背景色 - if (m_isEnter) { - QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white; - backColor.setAlphaF(0.2); - // 鼠标进入的时候,绘制底色 - painter.fillRect(rect(), backColor); - } - int timeAlignFlag = Qt::AlignCenter; int dateAlignFlag = Qt::AlignCenter; @@ -395,7 +386,7 @@ QRect DateTimeDisplayer::textRect(const QRect &sourceRect) const void DateTimeDisplayer::enterEvent(QEvent *event) { Q_UNUSED(event); - m_isEnter = true; + Q_EMIT requestDrawBackground(rect()); update(); m_tipPopupWindow->show(tipsPoint()); } @@ -403,7 +394,7 @@ void DateTimeDisplayer::enterEvent(QEvent *event) void DateTimeDisplayer::leaveEvent(QEvent *event) { Q_UNUSED(event); - m_isEnter = false; + Q_EMIT requestDrawBackground(QRect()); update(); m_tipPopupWindow->hide(); } diff --git a/frame/window/components/datetimedisplayer.h b/frame/window/components/datetimedisplayer.h index 421099422..f1bb0d62a 100644 --- a/frame/window/components/datetimedisplayer.h +++ b/frame/window/components/datetimedisplayer.h @@ -42,6 +42,7 @@ class DateTimeDisplayer : public QWidget Q_SIGNALS: void requestUpdate(); // 当日期时间格式发生变化的时候,需要通知外面来更新窗口尺寸 + void requestDrawBackground(const QRect &rect); protected: void mousePressEvent(QMouseEvent *event) override; @@ -83,7 +84,6 @@ private Q_SLOTS: int m_currentSize; bool m_oneRow; bool m_showMultiRow; - bool m_isEnter; }; #endif // DATETIMEDISPLAYER_H diff --git a/frame/window/systempluginwindow.cpp b/frame/window/systempluginwindow.cpp index c7abc89b7..ea292e16c 100644 --- a/frame/window/systempluginwindow.cpp +++ b/frame/window/systempluginwindow.cpp @@ -208,7 +208,6 @@ StretchPluginsItem::StretchPluginsItem(DockInter *dockInter, PluginsItemInterfac , m_itemKey(itemKey) , m_displayMode(Dock::DisplayMode::Efficient) , m_dockInter(dockInter) - , m_isEnter(false) { } @@ -266,12 +265,6 @@ void StretchPluginsItem::paintEvent(QPaintEvent *event) rctPixmap.setHeight(ICONSIZE); } - if (m_isEnter) { - QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white; - backColor.setAlphaF(0.2); - // 鼠标进入的时候,绘制底色 - painter.fillRect(rect(), backColor); - } // 绘制图标 int iconSize = static_cast(ICONSIZE * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio())); painter.drawPixmap(rctPixmap, icon.pixmap(iconSize, iconSize)); @@ -393,14 +386,17 @@ void StretchPluginsItem::mouseReleaseEvent(QMouseEvent *e) void StretchPluginsItem::enterEvent(QEvent *event) { - m_isEnter = true; + if (auto view = qobject_cast(parentWidget())) + view->requestDrawBackground(rect()); + update(); DockItem::enterEvent(event); } void StretchPluginsItem::leaveEvent(QEvent *event) { - m_isEnter = false; + if (auto view = qobject_cast(parentWidget())) + view->requestDrawBackground(QRect()); update(); DockItem::leaveEvent(event); } diff --git a/frame/window/systempluginwindow.h b/frame/window/systempluginwindow.h index 7da835d1b..8e29b4004 100644 --- a/frame/window/systempluginwindow.h +++ b/frame/window/systempluginwindow.h @@ -35,6 +35,7 @@ class SystemPluginWindow : public QWidget Q_SIGNALS: void itemChanged(); void requestDrop(QDropEvent *dropEvent); + void requestDrawBackground(const QRect &rect); protected: bool eventFilter(QObject *watched, QEvent *event) override; @@ -99,7 +100,6 @@ class StretchPluginsItem : public DockItem static Dock::Position m_position; QPoint m_mousePressPoint; DockInter *m_dockInter; - bool m_isEnter; }; #endif // SYSTEMPLUGINWINDOW_H diff --git a/frame/window/traymanagerwindow.cpp b/frame/window/traymanagerwindow.cpp index f8ec7a17b..84bdc307b 100644 --- a/frame/window/traymanagerwindow.cpp +++ b/frame/window/traymanagerwindow.cpp @@ -241,6 +241,37 @@ void TrayManagerWindow::onTrayCountChanged() Q_EMIT requestUpdate(); } +void TrayManagerWindow::updateHighlightArea(const QRect &rect) +{ + do { + m_highlightArea.clear(); + if (!rect.isValid()) + break; + + auto widget = qobject_cast(sender()); + Q_ASSERT(widget); + + QRect tmp = rect; + tmp.moveTopLeft(widget->mapTo(this, rect.topLeft())); + + const auto radius = pathRadius(); + m_highlightArea.addRoundedRect(tmp, radius, radius); + if (widget == m_dateTimeWidget) { + if (!m_singleShow) { + QPainterPath path; + if(m_position == Dock::Position::Top) + path.addRect(tmp.adjusted(0, radius, 0, 0)); + else + path.addRect(tmp.adjusted(0, 0, 0, -radius)); + + m_highlightArea += path; + } + } + } while (false); + + update(); +} + void TrayManagerWindow::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); @@ -302,6 +333,7 @@ void TrayManagerWindow::initConnection() Q_EMIT requestUpdate(); }); + connect(m_systemPluginWidget, &SystemPluginWindow::requestDrawBackground, this, &TrayManagerWindow::updateHighlightArea); connect(m_trayView, &TrayGridView::dragLeaved, m_delegate, [ this ]{ Q_EMIT m_delegate->requestDrag(true); @@ -313,6 +345,7 @@ void TrayManagerWindow::initConnection() connect(m_model, &TrayModel::rowCountChanged, m_trayView, &TrayGridView::onUpdateEditorView); connect(m_dateTimeWidget, &DateTimeDisplayer::requestUpdate, this, &TrayManagerWindow::requestUpdate); + connect(m_dateTimeWidget, &DateTimeDisplayer::requestDrawBackground, this, &TrayManagerWindow::updateHighlightArea); m_trayView->installEventFilter(this); m_quickIconWidget->installEventFilter(this); @@ -508,6 +541,17 @@ void TrayManagerWindow::paintEvent(QPaintEvent *event) painter.setPen(maskColor(110)); painter.drawPath(path); painter.restore(); + + // draw highlight background for special path. + if (!m_highlightArea.isEmpty()) { + painter.save(); + QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white; + backColor.setAlphaF(0.2); + painter.setPen(Qt::NoPen); + painter.setBrush(backColor); + painter.drawPath(m_highlightArea); + painter.restore(); + } } QColor TrayManagerWindow::maskColor(uint8_t alpha) const diff --git a/frame/window/traymanagerwindow.h b/frame/window/traymanagerwindow.h index c624d9e82..f0528398f 100644 --- a/frame/window/traymanagerwindow.h +++ b/frame/window/traymanagerwindow.h @@ -11,6 +11,7 @@ #include "org_deepin_dde_timedate1.h" +#include #include namespace Dtk { namespace Widget { class DBlurEffectWidget; } } @@ -72,6 +73,7 @@ class TrayManagerWindow : public QWidget private Q_SLOTS: void onTrayCountChanged(); + void updateHighlightArea(const QRect &rect); private: QWidget *m_appPluginDatetimeWidget; @@ -90,6 +92,7 @@ private Q_SLOTS: QLabel *m_splitLine; bool m_singleShow; // 用于记录当前日期时间和插件区域是显示一行还是显示多行 int m_borderRadius; // 圆角的值 + QPainterPath m_highlightArea; }; #endif // PLUGINWINDOW_H