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+
521557void 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}
0 commit comments