mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat(notify):move notify center to tray
This commit is contained in:
parent
8733c9bc25
commit
b09ff55c5a
1
debian/dde-dock.install
vendored
1
debian/dde-dock.install
vendored
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user