Skip to content

Commit b1b3d77

Browse files
committed
feat: add preview follows the system opacity.
as title. PMS-BUG-314371
1 parent 50edcae commit b1b3d77

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

panels/dock/taskmanager/x11preview.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
#include <QTimer>
2929
#include <QWindow>
3030
#include <QtConcurrent>
31+
#include <QtGlobal>
3132

3233
#include <DStyle>
3334
#include <DPlatformHandle>
35+
#include <QDBusReply>
3436

3537
#include <DWindowManagerHelper>
3638
#include <DGuiApplicationHelper>
@@ -401,6 +403,7 @@ X11WindowPreviewContainer::X11WindowPreviewContainer(X11WindowMonitor* monitor,
401403
, m_isDockPreviewCount(0)
402404
, m_model(new AppItemWindowModel(this))
403405
, m_titleWidget(new QWidget())
406+
, m_systemOpacity(0.2)
404407
{
405408
m_hideTimer = new QTimer(this);
406409
m_hideTimer->setSingleShot(true);
@@ -410,6 +413,12 @@ X11WindowPreviewContainer::X11WindowPreviewContainer(X11WindowMonitor* monitor,
410413
setMouseTracking(true);
411414
initUI();
412415

416+
m_appearanceInterface = new QDBusInterface("org.deepin.dde.Appearance1",
417+
"/org/deepin/dde/Appearance1",
418+
"org.deepin.dde.Appearance1",
419+
QDBusConnection::sessionBus(), this);
420+
connect(m_appearanceInterface, SIGNAL(Changed(QString,QString)), this, SLOT(onSystemOpacityChanged(QString,QString)));
421+
m_systemOpacity = getSystemOpacity();
413422
connect(m_hideTimer, &QTimer::timeout, this, &X11WindowPreviewContainer::callHide);
414423

415424
connect(m_closeAllButton, &DIconButton::clicked, this, [this](){
@@ -518,6 +527,33 @@ void X11WindowPreviewContainer::resizeEvent(QResizeEvent *event)
518527
updatePosition();
519528
}
520529

530+
void X11WindowPreviewContainer::paintEvent(QPaintEvent *event)
531+
{
532+
Q_UNUSED(event)
533+
534+
QPainter painter(this);
535+
painter.setRenderHint(QPainter::Antialiasing);
536+
537+
QColor backgroundColor;
538+
539+
auto themeType = DGuiApplicationHelper::instance()->themeType();
540+
if (themeType == DGuiApplicationHelper::DarkType) {
541+
backgroundColor = QColor(0, 0, 0, static_cast<int>(255 * m_systemOpacity));
542+
} else {
543+
backgroundColor = QColor(255, 255, 255, static_cast<int>(255 * m_systemOpacity));
544+
}
545+
546+
painter.setBrush(backgroundColor);
547+
painter.setPen(Qt::NoPen);
548+
549+
// 获取圆角半径
550+
DStyleHelper dstyle(style());
551+
const int radius = dstyle.pixelMetric(DStyle::PM_FrameRadius);
552+
553+
// 绘制带圆角的背景
554+
painter.drawRoundedRect(rect(), radius, radius);
555+
}
556+
521557
void X11WindowPreviewContainer::updatePosition()
522558
{
523559
auto screenRect = m_baseWindow->screen()->geometry();
@@ -754,4 +790,31 @@ void X11WindowPreviewContainer::updatePreviewIconFromBase64(const QString &base6
754790
m_previewIcon->setPixmap(QIcon::fromTheme(m_previewItem->icon()).pixmap(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT));
755791
}
756792
}
793+
794+
795+
double X11WindowPreviewContainer::getSystemOpacity()
796+
{
797+
if (m_appearanceInterface && m_appearanceInterface->isValid()) {
798+
QVariant opacityVariant = m_appearanceInterface->property("Opacity");
799+
if (opacityVariant.isValid()) {
800+
double opacity = opacityVariant.toReal();
801+
opacity = qBound(0.0, opacity, 1.0);
802+
return opacity;
803+
}
804+
}
805+
return 0.2;
806+
}
807+
808+
void X11WindowPreviewContainer::onSystemOpacityChanged(const QString &propertyName, const QString &value)
809+
{
810+
//value传过来没有值
811+
Q_UNUSED(value);
812+
813+
// 只处理窗口透明度属性
814+
if (propertyName == "windowopacity") {
815+
m_systemOpacity = getSystemOpacity();
816+
update();
817+
}
818+
}
819+
757820
}

panels/dock/taskmanager/x11preview.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <DBlurEffectWidget>
1818
#include <DGuiApplicationHelper>
1919
#include <DIconButton>
20+
#include <QDBusInterface>
2021

2122
DWIDGET_USE_NAMESPACE
2223

@@ -76,19 +77,22 @@ class X11WindowPreviewContainer: public DBlurEffectWidget
7677
void showEvent(QShowEvent *event) override;
7778
void hideEvent(QHideEvent *event) override;
7879
void resizeEvent(QResizeEvent *event) override;
80+
void paintEvent(QPaintEvent *event) override;
7981

8082
private:
8183
inline void updatePreviewTitle(const QString& title);
8284
inline void initUI();
8385
inline void updateSize();
8486
void updatePreviewIconFromBase64(const QString &base64Data);
87+
double getSystemOpacity();
8588

8689
public Q_SLOTS:
8790
void updatePosition();
8891

8992
private Q_SLOTS:
9093
void updateOrientation();
9194
void callHide();
95+
void onSystemOpacityChanged(const QString &propertyName, const QString &value);
9296

9397
private:
9498
bool m_isPreviewEntered;
@@ -114,6 +118,10 @@ private Q_SLOTS:
114118
QPointer<AppItem> m_previewItem;
115119

116120
QString m_previewTitleStr;
121+
122+
// 透明度相关
123+
QDBusInterface* m_appearanceInterface;
124+
double m_systemOpacity;
117125
};
118126

119127
}

0 commit comments

Comments
 (0)