@@ -401,6 +401,7 @@ X11WindowPreviewContainer::X11WindowPreviewContainer(X11WindowMonitor* monitor,
401401 , m_isDockPreviewCount (0 )
402402 , m_model (new AppItemWindowModel (this ))
403403 , m_titleWidget (new QWidget ())
404+ , m_systemOpacity (0.2 )
404405{
405406 m_hideTimer = new QTimer (this );
406407 m_hideTimer->setSingleShot (true );
@@ -518,6 +519,33 @@ void X11WindowPreviewContainer::resizeEvent(QResizeEvent *event)
518519 updatePosition ();
519520}
520521
522+ void X11WindowPreviewContainer::paintEvent (QPaintEvent *event)
523+ {
524+ Q_UNUSED (event)
525+
526+ QPainter painter (this );
527+ painter.setRenderHint (QPainter::Antialiasing);
528+
529+ QColor backgroundColor;
530+
531+ auto themeType = DGuiApplicationHelper::instance ()->themeType ();
532+ if (themeType == DGuiApplicationHelper::DarkType) {
533+ backgroundColor = QColor (0 , 0 , 0 , static_cast <int >(255 * m_systemOpacity));
534+ } else {
535+ backgroundColor = QColor (255 , 255 , 255 , static_cast <int >(255 * m_systemOpacity));
536+ }
537+
538+ painter.setBrush (backgroundColor);
539+ painter.setPen (Qt::NoPen);
540+
541+ // 获取圆角半径
542+ DStyleHelper dstyle (style ());
543+ const int radius = dstyle.pixelMetric (DStyle::PM_FrameRadius);
544+
545+ // 绘制带圆角的背景
546+ painter.drawRoundedRect (rect (), radius, radius);
547+ }
548+
521549void X11WindowPreviewContainer::updatePosition ()
522550{
523551 auto screenRect = m_baseWindow->screen ()->geometry ();
@@ -754,4 +782,16 @@ void X11WindowPreviewContainer::updatePreviewIconFromBase64(const QString &base6
754782 m_previewIcon->setPixmap (QIcon::fromTheme (m_previewItem->icon ()).pixmap (PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT));
755783 }
756784}
785+
786+ double X11WindowPreviewContainer::getOpacity () const
787+ {
788+ return m_systemOpacity;
789+ }
790+
791+ void X11WindowPreviewContainer::setOpacity (double opacity)
792+ {
793+ m_systemOpacity = opacity;
794+ update ();
795+ }
796+
757797}
0 commit comments