From 7c9d6554e1cff47d8be2824097392b80cf3463b6 Mon Sep 17 00:00:00 2001 From: liyigang Date: Fri, 11 Oct 2024 15:31:46 +0800 Subject: [PATCH] fix: After adjusting the width of the dde-file-manager, other applications such as file editors open dde-file-dailog field display Adjust the adaptive width strategy, and when the window width is less than the width of all columns, adjust the columns larger than the minimum width. When the window width is greater than the width of all columns, adjust the width of the filename column Log: After adjusting the width of the dde-file-manager, other applications such as file editors open dde-file-dailog field display Bug: https://pms.uniontech.com/bug-view-273831.html --- .../dfmplugin-workspace/views/headerview.cpp | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/plugins/filemanager/core/dfmplugin-workspace/views/headerview.cpp b/src/plugins/filemanager/core/dfmplugin-workspace/views/headerview.cpp index a206d1869a..acaf37fbf7 100644 --- a/src/plugins/filemanager/core/dfmplugin-workspace/views/headerview.cpp +++ b/src/plugins/filemanager/core/dfmplugin-workspace/views/headerview.cpp @@ -94,18 +94,35 @@ void HeaderView::doFileNameColumnResize(const int totalWidth) int fileNameColumn = viewModel()->getColumnByRole(kItemFileDisplayNameRole); int columnCount = count(); int columnWidthSumOmitFileName = 0; + QMap moreThanMin = {}; + bool isMoreThanMin = false; for (int i = 0; i < columnCount; ++i) { - if (i == fileNameColumn || isSectionHidden(i)) + if (isSectionHidden(i)) continue; - columnWidthSumOmitFileName += view->getColumnWidth(i); + auto itemColWidth = view->getColumnWidth(i); + moreThanMin.insert(i, itemColWidth - minimumSectionSize()); + if (!isMoreThanMin && itemColWidth - minimumSectionSize() > 0) + isMoreThanMin = true; + columnWidthSumOmitFileName += itemColWidth; + } + // 所有列的宽度大于当前窗口的宽度,并且有一列宽度大于最小值,调整这一列的宽度 + if (columnWidthSumOmitFileName > totalWidth && isMoreThanMin) { + int moreThanTotal = columnWidthSumOmitFileName - totalWidth; + for (const int logicCol : moreThanMin.keys()) { + auto itemMoreThan = moreThanMin.value(logicCol); + if (moreThanTotal > 0 && moreThanMin.value(logicCol) > 0) { + resizeSection(logicCol, view->getColumnWidth(logicCol) - qMin(moreThanTotal, itemMoreThan)); + moreThanTotal -= qMin(moreThanTotal, itemMoreThan); + } + if (moreThanTotal <= 0) + break; + } + } else if (totalWidth > columnWidthSumOmitFileName) { + // 所有列的宽度小于当前窗口的宽度,调整名称这一行的宽度 + resizeSection(fileNameColumn, view->getColumnWidth(fileNameColumn) + + totalWidth - columnWidthSumOmitFileName); } - - int targetWidth = totalWidth - columnWidthSumOmitFileName; - const QVariantMap &state = Application::appObtuselySetting()->value("WindowManager", "ViewColumnState").toMap(); - int colWidth = state.value(QString::number(kItemFileDisplayNameRole), -1).toInt(); - - resizeSection(fileNameColumn, qMax(targetWidth, colWidth)); } void HeaderView::onActionClicked(const int column, QAction *action)