diff --git a/debian/dde-dock.install b/debian/dde-dock.install index a6744ffca..a5406de26 100644 --- a/debian/dde-dock.install +++ b/debian/dde-dock.install @@ -9,6 +9,5 @@ usr/lib/dde-dock/plugins/liboverlay-warning.so usr/lib/dde-dock/plugins/system-trays usr/lib/dde-dock/plugins/libmultitasking.so usr/lib/dde-dock/plugins/libshow-desktop.so -usr/lib/dde-dock/plugins/libnotifications.so usr/share etc/dde-dock diff --git a/plugins/notifications/CMakeLists.txt b/plugins/notifications/CMakeLists.txt index b10c36329..954b8b814 100644 --- a/plugins/notifications/CMakeLists.txt +++ b/plugins/notifications/CMakeLists.txt @@ -18,7 +18,7 @@ endif() add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN") add_library(${PLUGIN_NAME} SHARED ${SRCS} resources.qrc) -set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../) +set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../system-trays) target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ../../interfaces) @@ -29,4 +29,4 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE ${Qt5DBus_LIBRARIES} ) -install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins) +install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins/system-trays) diff --git a/plugins/notifications/notificationswidget.cpp b/plugins/notifications/notificationswidget.cpp index 0e963bb5d..64c3a64f2 100644 --- a/plugins/notifications/notificationswidget.cpp +++ b/plugins/notifications/notificationswidget.cpp @@ -34,8 +34,6 @@ DWIDGET_USE_NAMESPACE; NotificationsWidget::NotificationsWidget(QWidget *parent) : QWidget(parent) - , m_hover(false) - , m_pressed(false) { setMouseTracking(true); setMinimumSize(PLUGIN_BACKGROUND_MIN_SIZE, PLUGIN_BACKGROUND_MIN_SIZE); @@ -43,7 +41,6 @@ NotificationsWidget::NotificationsWidget(QWidget *parent) connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [ = ] { update(); }); - m_icon = QIcon::fromTheme(":/icons/resources/icons/notification.svg"); } QSize NotificationsWidget::sizeHint() const @@ -55,109 +52,21 @@ void NotificationsWidget::paintEvent(QPaintEvent *e) { Q_UNUSED(e); - QPixmap pixmap; QString iconName = "notification"; int iconSize = PLUGIN_ICON_MAX_SIZE; + if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) + iconName.append(PLUGIN_MIN_ICON_NAME); QPainter painter(this); + const auto ratio = devicePixelRatioF(); - if (rect().height() > PLUGIN_BACKGROUND_MIN_SIZE) { - - QColor color; - if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { - color = Qt::black; - painter.setOpacity(0.5); - - if (m_hover) { - painter.setOpacity(0.6); - } - - if (m_pressed) { - painter.setOpacity(0.3); - } - } else { - color = Qt::white; - painter.setOpacity(0.1); - - if (m_hover) { - painter.setOpacity(0.2); - } - - if (m_pressed) { - painter.setOpacity(0.05); - } - } - - painter.setRenderHint(QPainter::Antialiasing, true); - - DStyleHelper dstyle(style()); - const int radius = dstyle.pixelMetric(DStyle::PM_FrameRadius); - - QPainterPath path; - - int minSize = std::min(width(), height()); - QRect rc(0, 0, minSize, minSize); - rc.moveTo(rect().center() - rc.center()); - - path.addRoundedRect(rc, radius, radius); - painter.fillPath(path, color); - } else if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) { - // 最小尺寸时,不画背景,采用深色图标 - iconName.append(PLUGIN_MIN_ICON_NAME); - } - - painter.setOpacity(1); - - pixmap = loadSvg(iconName, QSize(iconSize, iconSize)); + QPixmap pixmap = QIcon::fromTheme(iconName, QIcon::fromTheme(QString(":/icons/resources/icons/%1").arg(iconName))).pixmap(QSize(iconSize, iconSize) * ratio); + pixmap.setDevicePixelRatio(ratio); const QRectF &rf = QRectF(rect()); const QRectF &rfp = QRectF(pixmap.rect()); - painter.drawPixmap(rf.center() - rfp.center() / pixmap.devicePixelRatioF(), pixmap); -} -const QPixmap NotificationsWidget::loadSvg(const QString &fileName, const QSize &size) const -{ - const auto ratio = devicePixelRatioF(); - - QPixmap pixmap; - pixmap = QIcon::fromTheme(fileName, m_icon).pixmap(size * ratio); - pixmap.setDevicePixelRatio(ratio); - - return pixmap; -} - -void NotificationsWidget::mousePressEvent(QMouseEvent *event) -{ - m_pressed = true; - update(); - - QWidget::mousePressEvent(event); -} - -void NotificationsWidget::mouseReleaseEvent(QMouseEvent *event) -{ - m_pressed = false; - m_hover = false; - update(); - - QWidget::mouseReleaseEvent(event); -} - -void NotificationsWidget::mouseMoveEvent(QMouseEvent *event) -{ - m_hover = true; - QWidget::mouseMoveEvent(event); -} - -void NotificationsWidget::leaveEvent(QEvent *event) -{ - if (!rect().contains(mapFromGlobal(QCursor::pos()))) { - m_hover = false; - m_pressed = false; - update(); - } - - QWidget::leaveEvent(event); + painter.drawPixmap(rf.center() - rfp.center() / ratio, pixmap); } void NotificationsWidget::resizeEvent(QResizeEvent *event) diff --git a/plugins/notifications/notificationswidget.h b/plugins/notifications/notificationswidget.h index fc9dbe671..2bc7f4908 100644 --- a/plugins/notifications/notificationswidget.h +++ b/plugins/notifications/notificationswidget.h @@ -37,20 +37,7 @@ public: protected: QSize sizeHint() const override; void paintEvent(QPaintEvent *e) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void leaveEvent(QEvent *event) override; void resizeEvent(QResizeEvent *event) override; - -private: - const QPixmap loadSvg(const QString &fileName, const QSize &size) const; - -private: - Dock::DisplayMode m_displayMode; - bool m_hover; - bool m_pressed; - QIcon m_icon; }; #endif // NOTIFICATIONSWIDGET_H