Skip to content

Commit 78f68ae

Browse files
add-uosdeepin-bot[bot]
authored andcommitted
fix(views): adaptive width layout for remote management
Remove hardcoded width values and use dynamic width calculation to support adaptive layout in remote management panel. 移除硬编码宽度值,使用动态宽度计算,支持远程管理面板自适应布局。 Log: 修复远程管理面板布局自适应问题 PMS: BUG-361273 Influence: 修复后界面元素能够根据容器大小自适应宽度,提升不同分辨率下的显示效果。
1 parent 6f79347 commit 78f68ae

2 files changed

Lines changed: 23 additions & 33 deletions

File tree

src/views/focusframe.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd
2-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
33
//
44
// SPDX-License-Identifier: GPL-3.0-or-later
55

@@ -49,11 +49,8 @@ void FocusFrame::paintEvent(QPaintEvent *event)
4949
// qCDebug(views) << "Branch: Focus is active";
5050
// 边框
5151
QPainterPath FramePath;
52-
// 效果和以下代码类似,兼容紧凑模式
53-
// 类似: paintRoundedRect(FramePath, QRect(2, 2, 218, 58));
54-
// TODO master
55-
// paintRoundedRect(FramePath, rect().adjusted(2, 2, 0, 0));
56-
paintRoundedRect(FramePath, QRect(2, 2, m_isWideFrame ? 358 : 218, 58));
52+
// 使用动态宽度绘制边框
53+
paintRoundedRect(FramePath, QRect(2, 2, qMax(0, rect().width() - 4), qMax(0, rect().height() - 4)));
5754
// 获取活动色
5855
QPen pen(pa.color(DPalette::Highlight), 2);
5956
painter.setPen(pen);
@@ -62,10 +59,8 @@ void FocusFrame::paintEvent(QPaintEvent *event)
6259

6360
// 绘制背景
6461
QPainterPath itemBackgroudPath;
65-
// 类似: paintRoundedRect(itemBackgroudPath, QRect(4, 4, 214, 54));
66-
// TODO master
67-
// paintRoundedRect(FramePath, rect().adjusted(4, 4, -2, -2));
68-
paintRoundedRect(itemBackgroudPath, QRect(4, 4, m_isWideFrame ? 354 : 214, 54));
62+
// 使用动态宽度绘制背景
63+
paintRoundedRect(itemBackgroudPath, QRect(4, 4, qMax(0, rect().width() - 8), qMax(0, rect().height() - 8)));
6964
// 产品要有悬浮效果的
7065
// painter.fillPath(itemBackgroudPath, QBrush(pa.color(DPalette::ObviousBackground)));
7166
// ui要有框,背景不变
@@ -75,10 +70,8 @@ void FocusFrame::paintEvent(QPaintEvent *event)
7570
// 焦点不在,不绘制
7671
// 绘制背景
7772
QPainterPath itemBackgroudPath;
78-
// 类似: paintRoundedRect(itemBackgroudPath, QRect(0, 0, 220, 60));
79-
// TODO master
80-
// paintRoundedRect(itemBackgroudPath, rect().adjusted(0, 0, 1, 1));
81-
paintRoundedRect(itemBackgroudPath, QRect(0, 0, m_isWideFrame ? 360 : 220, 60));
73+
// 使用动态宽度绘制背景
74+
paintRoundedRect(itemBackgroudPath, QRect(0, 0, rect().width(), rect().height()));
8275
// 产品要有悬浮效果的
8376
// painter.fillPath(itemBackgroudPath, QBrush(pa.color(DPalette::ObviousBackground)));
8477
// ui要有框,背景不变

src/views/itemwidget.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd
2-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
33
//
44
// SPDX-License-Identifier: GPL-3.0-or-later
55

@@ -86,7 +86,7 @@ void ItemWidget::setFuncIcon(ItemFuncType iconType)
8686
{
8787
qCDebug(views) << "Enter ItemWidget::setFuncIcon";
8888
// 统一设置大小
89-
m_funcButton->setIconSize(QSize(20, 20));
89+
m_funcButton->setIconSize(QSize(16, 16));
9090
m_deleteButton->setIconSize(QSize(20, 20));
9191
m_deleteButton->hide();
9292
switch (iconType) {
@@ -341,16 +341,18 @@ void ItemWidget::updateSizeMode()
341341
{
342342
qCDebug(views) << "Enter ItemWidget::updateSizeMode";
343343
#ifdef DTKWIDGET_CLASS_DSizeMode
344+
// 设置最小宽度,防止挤压,允许宽度自适应
345+
setMinimumWidth(220);
344346
if (DGuiApplicationHelper::isCompactMode()) {
345347
qCDebug(views) << "Branch: compact mode";
346348
m_iconLayout->setContentsMargins(s_ItemIconContentMarginsCompact);
347-
setFixedSize(220, s_ItemHeightCompact);
349+
setFixedHeight(s_ItemHeightCompact);
348350
setFont(m_firstline, DFontSizeManager::T6, ItemTextColor_Text);
349351
setFont(m_secondline, DFontSizeManager::T7, ItemTextColor_TextTips);
350352
} else {
351353
qCDebug(views) << "Branch: normal mode";
352354
m_iconLayout->setContentsMargins(s_ItemIconContentMargins);
353-
setFixedSize(220, s_ItemHeight);
355+
setFixedHeight(s_ItemHeight);
354356
setFont(m_firstline, DFontSizeManager::T7, ItemTextColor_Text);
355357
setFont(m_secondline, DFontSizeManager::T8, ItemTextColor_TextTips);
356358
}
@@ -362,14 +364,9 @@ void ItemWidget::initUI()
362364
{
363365
if (m_functType != ItemFuncType_GroupLabel && m_functType != ItemFuncType_ItemLabel)
364366
{
365-
// 初始化控件大小
366-
if (m_functType == ItemFuncType_UngroupedItem) {
367-
setGeometry(0, 0, 360, 60);
368-
setFixedSize(360, 60);
369-
} else {
370-
setGeometry(0, 0, 220, 60);
371-
setFixedSize(220, 60);
372-
}
367+
// 设置最小宽度,防止挤压,允许宽度自适应
368+
setMinimumWidth(220);
369+
setFixedHeight(60);
373370
}
374371
else
375372
{
@@ -396,12 +393,13 @@ void ItemWidget::initUI()
396393
setFont(m_secondline, DFontSizeManager::T8, ItemTextColor_TextTips);
397394
m_firstline->setContentsMargins(0, 0, 0, 0);
398395
m_secondline->setContentsMargins(0, 0, 0, 0);
399-
m_firstline->setFixedWidth(138);
400-
m_secondline->setFixedWidth(138);
396+
m_firstline->setMaximumWidth(138);
397+
m_secondline->setMaximumWidth(138);
401398
m_textLayout->setContentsMargins(0, 0, 0, 0);
402399
m_textLayout->setSpacing(0);
403400
m_textLayout->addStretch(13);
404401
m_textLayout->addWidget(m_firstline, 13);
402+
m_textLayout->setAlignment(m_firstline, Qt::AlignLeft);
405403
m_textLayout->addStretch(9);
406404
if (m_functType != ItemFuncType_GroupLabel && m_functType != ItemFuncType_ItemLabel)
407405
{
@@ -418,10 +416,10 @@ void ItemWidget::initUI()
418416
m_funcButton->setFlat(true);
419417
m_funcButton->setFocusPolicy(Qt::NoFocus);
420418
m_funcLayout->addStretch();
421-
m_funcLayout->setContentsMargins(5, 0, 5, 0);
419+
m_funcLayout->setContentsMargins(5, 0, 10, 0);
422420
m_funcLayout->addWidget(m_deleteButton);
423421
m_funcLayout->addWidget(m_funcButton);
424-
m_funcLayout->addStretch();
422+
m_funcLayout->setSpacing(5);
425423

426424
// 整体布局
427425
m_mainLayout->setContentsMargins(0, 0, 0, 0);
@@ -433,16 +431,15 @@ void ItemWidget::initUI()
433431
m_checkBox->hide();
434432
}
435433
m_mainLayout->addLayout(m_iconLayout);
436-
m_mainLayout->addLayout(m_textLayout);
434+
m_mainLayout->addLayout(m_textLayout, 1);
437435
m_mainLayout->addLayout(m_funcLayout);
438436
} else {
439437
m_checkBox->hide();
440438
m_iconButton->hide();
441-
m_mainLayout->addLayout(m_textLayout);
439+
m_mainLayout->addLayout(m_textLayout, 1);
442440
m_deleteButton->hide();
443441
m_funcButton->hide();
444442
}
445-
m_mainLayout->addStretch();
446443
setLayout(m_mainLayout);
447444

448445
// 根据不同布局初始化界面

0 commit comments

Comments
 (0)