mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
fix(appitem): 调整预览界面大小计算规则
调整预览界面大小计算规则.先根据屏幕宽高计算出能预览的最大数量,然后根据数量计算界面宽高,再将计算出相对数量的预览界面添加到布局并显示,其他的暂 时不添加,减少界面刷新次数 Log: 调整预览界面大小计算规则,调整预览界面布局 Bug: https://pms.uniontech.com/zentao/bug-view-110624.html Influence: 正常显示预览界面布局 Change-Id: I5342099b05d19eae7d019b6540bc69b98867b02e
This commit is contained in:
parent
920f8c148e
commit
cd34f12ac3
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user