From cd34f12ac32b8077fa1b42fd1cb8a8b99dc18e28 Mon Sep 17 00:00:00 2001 From: chenjun Date: Thu, 13 Jan 2022 09:15:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(appitem):=20=E8=B0=83=E6=95=B4=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E7=95=8C=E9=9D=A2=E5=A4=A7=E5=B0=8F=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整预览界面大小计算规则.先根据屏幕宽高计算出能预览的最大数量,然后根据数量计算界面宽高,再将计算出相对数量的预览界面添加到布局并显示,其他的暂 时不添加,减少界面刷新次数 Log: 调整预览界面大小计算规则,调整预览界面布局 Bug: https://pms.uniontech.com/zentao/bug-view-110624.html Influence: 正常显示预览界面布局 Change-Id: I5342099b05d19eae7d019b6540bc69b98867b02e --- frame/item/components/appsnapshot.cpp | 2 +- frame/item/components/previewcontainer.cpp | 38 ++++++++++++++-------- frame/item/components/previewcontainer.h | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 9587b6803..f2349be25 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -83,7 +83,7 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) setLayout(centralLayout); setAcceptDrops(true); - resize(SNAP_WIDTH, SNAP_HEIGHT); + resize(SNAP_WIDTH / 2, SNAP_HEIGHT / 2); connect(m_closeBtn2D, &DIconButton::clicked, this, &AppSnapshot::closeWindow, Qt::QueuedConnection); connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &AppSnapshot::compositeChanged, Qt::QueuedConnection); diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index 2c070faf0..494fe14a6 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -152,31 +152,37 @@ void PreviewContainer::prepareHide() m_mouseLeaveTimer->start(); } -void PreviewContainer::adjustSize(const bool composite) +void PreviewContainer::adjustSize(bool composite) { - const int count = m_snapshots.size(); + int count = m_snapshots.size(); + const int screenWidth = QDesktopWidget().screenGeometry(this).width(); + const int screenHeight = QDesktopWidget().screenGeometry(this).height(); + //先根据屏幕宽高计算出能预览的最大数量,然后根据数量计算界面宽高 if (composite) { // 3D - const QRect r = qApp->primaryScreen() ? qApp->primaryScreen()->geometry() : QRect(); const int padding = 20; - const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight; if (horizontal) { + count = qMin(count, screenWidth *2 / SNAP_WIDTH); + const int h = SNAP_HEIGHT + MARGIN * 2; const int w = SNAP_WIDTH * count + MARGIN * 2 + SPACING * (count - 1); setFixedHeight(h); - setFixedWidth(std::min(w, r.width() - padding)); + setFixedWidth(qMin(w, screenWidth - padding)); } else { + count = qMin(count, screenWidth *2 / SNAP_HEIGHT); + const int w = SNAP_WIDTH + MARGIN * 2; const int h = SNAP_HEIGHT * count + MARGIN * 2 + SPACING * (count - 1); setFixedWidth(w); - setFixedHeight(std::min(h, r.height() - padding)); + setFixedHeight(qMin(h, screenHeight - padding)); } } else if (m_windowListLayout->count()) { // 2D + count = qMin(count, screenWidth / SNAP_HEIGHT_WITHOUT_COMPOSITE); const int h = SNAP_HEIGHT_WITHOUT_COMPOSITE * count + MARGIN * 2 + SPACING * (count - 1); // 根据appitem title 设置自适应宽度 @@ -193,26 +199,30 @@ void PreviewContainer::adjustSize(const bool composite) setFixedSize(SNAP_WIDTH, h); } } + + //根据计算的数量,将相应的预览界面添加到布局并显示,其他的暂时不添加,减少界面刷新次数 + int i = 0; + for (AppSnapshot *snap : m_snapshots) { + if (i < count && m_windowListLayout->indexOf(snap) < 0 ) { + m_windowListLayout->addWidget(snap); + } + snap->setVisible(i < count); + i++; + } } void PreviewContainer::appendSnapWidget(const WId wid) { + //创建预览界面,默认不显示,等计算出显示数量后再加入布局并显示 AppSnapshot *snap = new AppSnapshot(wid); + snap->setVisible(false); connect(snap, &AppSnapshot::clicked, this, &PreviewContainer::onSnapshotClicked, Qt::QueuedConnection); connect(snap, &AppSnapshot::entered, this, &PreviewContainer::previewEntered, Qt::QueuedConnection); connect(snap, &AppSnapshot::requestCheckWindow, this, &PreviewContainer::requestCheckWindows, Qt::QueuedConnection); connect(snap, &AppSnapshot::requestCloseAppSnapshot, this, &PreviewContainer::onRequestCloseAppSnapshot); - m_windowListLayout->addWidget(snap); - if (m_snapshots.size() >= (QDesktopWidget().screenGeometry(this).width() / (SNAP_WIDTH / 2))) - snap->setVisible(false); - m_snapshots.insert(wid, snap); - - // refresh if visible - if (isVisible()) - snap->fetchSnapshot(); } void PreviewContainer::enterEvent(QEvent *e) diff --git a/frame/item/components/previewcontainer.h b/frame/item/components/previewcontainer.h index 1ecd50c60..6aebb1700 100644 --- a/frame/item/components/previewcontainer.h +++ b/frame/item/components/previewcontainer.h @@ -67,7 +67,7 @@ public slots: void prepareHide(); private: - void adjustSize(const bool composite); + void adjustSize(bool composite); void appendSnapWidget(const WId wid); void enterEvent(QEvent *e);