From 7d62ae31ea9ca9dd2d25b8ffdeeb43880ea09c03 Mon Sep 17 00:00:00 2001 From: xust Date: Mon, 23 Sep 2024 16:06:30 +0800 Subject: [PATCH] fix: [dock] show elided name if too long. 1. and show tooltip when mouse hovered on name label. tooltip only shows when the popup widget get the focus. 2. add an option to disable tests. 3. center the file-empty tip in the workspace. Log: as title. Bug: https://pms.uniontech.com/bug-view-274011.html --- CMakeLists.txt | 6 +- .../disk-mount/widgets/deviceitem.cpp | 9 +++ .../dfmplugin-workspace/views/fileview.cpp | 62 +++++++++---------- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e178034d57..6332981fff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,9 +155,11 @@ if (BUILD_DOCS) endif() endif () + +option(FORCE_DISABLE_TESTS "If sets ON, disable tests" OFF) # test -message(STATUS "Enable testing: ${BUILD_TESTING}") -if(BUILD_TESTING) +message(STATUS "Enable testing: ${BUILD_TESTING}, force disable tests?: ${FORCE_DISABLE_TESTS}") +if(BUILD_TESTING AND (NOT FORCE_DISABLE_TESTS)) enable_testing() add_subdirectory(tests) endif() diff --git a/src/external/dde-dock-plugins/disk-mount/widgets/deviceitem.cpp b/src/external/dde-dock-plugins/disk-mount/widgets/deviceitem.cpp index 04b9890114..9e0ebeee95 100644 --- a/src/external/dde-dock-plugins/disk-mount/widgets/deviceitem.cpp +++ b/src/external/dde-dock-plugins/disk-mount/widgets/deviceitem.cpp @@ -67,6 +67,15 @@ void DeviceItem::initUI() setTextFont(labName, 14, QFont::Medium); setTextColor(labName, DGuiApplicationHelper::instance()->themeType(), 0.8); + QFontMetrics fm(labName->font()); + auto textPixelWidth = fm.boundingRect(data.displayName).width(); + const int kDevNameLen = 175; + if (textPixelWidth > kDevNameLen) { + auto text = fm.elidedText(data.displayName, Qt::TextElideMode::ElideRight, kDevNameLen); + labName->setText(text); + labName->setToolTip(data.displayName); + } + sizeLabel = new QLabel(this); setTextFont(sizeLabel, 12, QFont::Normal); setTextColor(sizeLabel, DGuiApplicationHelper::instance()->themeType(), 0.6); diff --git a/src/plugins/filemanager/core/dfmplugin-workspace/views/fileview.cpp b/src/plugins/filemanager/core/dfmplugin-workspace/views/fileview.cpp index a33b42d1ac..c150a5bf19 100644 --- a/src/plugins/filemanager/core/dfmplugin-workspace/views/fileview.cpp +++ b/src/plugins/filemanager/core/dfmplugin-workspace/views/fileview.cpp @@ -112,14 +112,13 @@ void FileView::setViewMode(Global::ViewMode mode) // itemDelegate 未设置时为未初始化状态,此时调用setViewMode需要执行设置流程 // itemDelegate 已设置时,若view不可见,则暂不执行viewMode设置逻辑 if (!isVisible() && itemDelegate() - && d->delegates[static_cast(mode)] == itemDelegate()) + && d->delegates[static_cast(mode)] == itemDelegate()) return; if (itemDelegate()) itemDelegate()->hideAllIIndexWidget(); - int delegateModeIndex = mode == Global::ViewMode::kTreeMode ? - static_cast(Global::ViewMode::kListMode) : static_cast(mode); + int delegateModeIndex = mode == Global::ViewMode::kTreeMode ? static_cast(Global::ViewMode::kListMode) : static_cast(mode); if (d->delegates.keys().contains(delegateModeIndex)) { d->currentViewMode = mode; } else { @@ -147,14 +146,14 @@ void FileView::setViewMode(Global::ViewMode mode) case Global::ViewMode::kListMode: d->delegates[static_cast(Global::ViewMode::kListMode)]->setPaintProxy(new ListItemPaintProxy(this)); setIconSize(QSize(kListViewIconSize, kListViewIconSize)); - viewport()->setContentsMargins(0,0,0,0); + viewport()->setContentsMargins(0, 0, 0, 0); model()->setTreeView(false); setListViewMode(); break; case Global::ViewMode::kExtendMode: break; case Global::ViewMode::kTreeMode: - viewport()->setContentsMargins(0,0,0,0); + viewport()->setContentsMargins(0, 0, 0, 0); if (d->itemsExpandable) { auto proxy = new TreeItemPaintProxy(this); proxy->setStyleProxy(style()); @@ -538,9 +537,7 @@ void FileView::delayUpdateStatusBar() void FileView::viewModeChanged(quint64 windowId, int viewMode) { Global::ViewMode mode = static_cast(viewMode); - if (mode == Global::ViewMode::kIconMode || - mode == Global::ViewMode::kListMode || - mode == Global::ViewMode::kTreeMode) { + if (mode == Global::ViewMode::kIconMode || mode == Global::ViewMode::kListMode || mode == Global::ViewMode::kTreeMode) { setViewMode(mode); } @@ -745,7 +742,7 @@ void FileView::updateViewportContentsMargins(const QSize &itemSize) int itemWidth = itemSize.width() + 2 * spacing(); int iconHorizontalMargin = kIconHorizontalMargin; #ifdef DTKWIDGET_CLASS_DSizeMode - iconHorizontalMargin = DSizeModeHelper::element(kCompactIconHorizontalMargin, kIconHorizontalMargin); + iconHorizontalMargin = DSizeModeHelper::element(kCompactIconHorizontalMargin, kIconHorizontalMargin); #endif if (itemWidth < 2 * kIconHorizontalMargin) @@ -777,9 +774,9 @@ bool FileView::indexInRect(const QRect &actualRect, const QModelIndex &index) auto rectList = itemDelegate()->itemGeomertys(opt, index); for (const auto &rect : rectList) { if (!(actualRect.left() > rect.right() - || actualRect.top() > rect.bottom() - || rect.left() > actualRect.right() - || rect.top() > actualRect.bottom())) + || actualRect.top() > rect.bottom() + || rect.left() > actualRect.right() + || rect.top() > actualRect.bottom())) return true; } @@ -800,20 +797,19 @@ QList FileView::selectedTreeViewUrlList() const return list; if (selectIndex.count() >= 2) std::sort(selectIndex.begin(), selectIndex.end(), - [](const QModelIndex &left, const QModelIndex &right){ - return left.row() < right.row(); - }); + [](const QModelIndex &left, const QModelIndex &right) { + return left.row() < right.row(); + }); for (const QModelIndex &index : selectIndex) { bool expandIsParent = false; if (expandIndex.isValid()) { auto parentUrl = expandIndex.data(Global::ItemRoles::kItemUrlRole).toUrl(); auto child = index.data(Global::ItemRoles::kItemUrlRole).toUrl(); expandIsParent = (index.data(Global::ItemRoles::kItemTreeViewDepthRole).toInt() - > expandIndex.data(Global::ItemRoles::kItemTreeViewDepthRole).toInt()) + > expandIndex.data(Global::ItemRoles::kItemTreeViewDepthRole).toInt()) && UniversalUtils::isParentUrl(child, parentUrl); } - if (index.parent() != rootIndex || - (expandIndex.isValid() && expandIsParent)) + if (index.parent() != rootIndex || (expandIndex.isValid() && expandIsParent)) continue; if (!expandIndex.isValid() || !expandIsParent) { list << model()->data(index, ItemRoles::kItemUrlRole).toUrl(); @@ -843,9 +839,9 @@ void FileView::selectedTreeViewUrlList(QList &selectedUrls, QList &t return; if (selectIndex.count() >= 2) std::sort(selectIndex.begin(), selectIndex.end(), - [](const QModelIndex &left, const QModelIndex &right){ - return left.row() < right.row(); - }); + [](const QModelIndex &left, const QModelIndex &right) { + return left.row() < right.row(); + }); for (const QModelIndex &index : selectIndex) { selectedUrls.append(index.data(Global::ItemRoles::kItemUrlRole).toUrl()); bool expandIsParent = false; @@ -853,11 +849,10 @@ void FileView::selectedTreeViewUrlList(QList &selectedUrls, QList &t auto parentUrl = expandIndex.data(Global::ItemRoles::kItemUrlRole).toUrl(); auto child = index.data(Global::ItemRoles::kItemUrlRole).toUrl(); expandIsParent = (index.data(Global::ItemRoles::kItemTreeViewDepthRole).toInt() - > expandIndex.data(Global::ItemRoles::kItemTreeViewDepthRole).toInt()) + > expandIndex.data(Global::ItemRoles::kItemTreeViewDepthRole).toInt()) && UniversalUtils::isParentUrl(child, parentUrl); } - if (index.parent() != rootIndex || - (expandIndex.isValid() && expandIsParent)) + if (index.parent() != rootIndex || (expandIndex.isValid() && expandIsParent)) continue; if (!expandIndex.isValid() || !expandIsParent) { treeSelectedUrls << model()->data(index, ItemRoles::kItemUrlRole).toUrl(); @@ -1066,7 +1061,7 @@ QModelIndex FileView::iconIndexAt(const QPoint &pos, const QSize &itemSize) cons int iconVerticalTopMargin = 0; #ifdef DTKWIDGET_CLASS_DSizeMode - iconVerticalTopMargin = DSizeModeHelper::element(kCompactIconVerticalTopMargin, kIconVerticalTopMargin); + iconVerticalTopMargin = DSizeModeHelper::element(kCompactIconVerticalTopMargin, kIconVerticalTopMargin); #endif if (itemDelegate() && itemDelegate()->itemExpanded() && itemDelegate()->expandItemRect().contains(pos)) { @@ -1185,7 +1180,7 @@ void FileView::onHeaderViewSectionChanged(const QUrl &url) bool FileView::edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event) { if (selectedIndexCount() > 1) - return false; + return false; return DListView::edit(index, trigger, event); } @@ -1416,8 +1411,7 @@ QRect FileView::visualRect(const QModelIndex &index) const #ifdef DTKWIDGET_CLASS_DSizeMode iconVerticalTopMargin = DSizeModeHelper::element(kCompactIconVerticalTopMargin, kIconVerticalTopMargin); #endif - rect.setTop(rowIndex * (itemSize.height() + 2 * iconViewSpacing) + iconVerticalTopMargin + - (rowIndex == 0 ? 1 * iconViewSpacing : 0 * iconViewSpacing)); + rect.setTop(rowIndex * (itemSize.height() + 2 * iconViewSpacing) + iconVerticalTopMargin + (rowIndex == 0 ? 1 * iconViewSpacing : 0 * iconViewSpacing)); rect.setLeft(columnIndex * itemWidth + (columnIndex == 0 ? iconViewSpacing : 0)); rect.setSize(itemSize); } @@ -1459,7 +1453,7 @@ void FileView::updateGeometries() iconVerticalTopMargin = DSizeModeHelper::element(kCompactIconVerticalTopMargin, kIconVerticalTopMargin); #endif if (!d->isResizeEvent - || (d->isResizeEvent && d->lastContentHeight > 0 && d->lastContentHeight != contentsSize().height())) + || (d->isResizeEvent && d->lastContentHeight > 0 && d->lastContentHeight != contentsSize().height())) resizeContents(contentsSize().width(), contentsSize().height() + iconVerticalTopMargin); d->lastContentHeight = contentsSize().height(); } @@ -1508,7 +1502,6 @@ void FileView::startDrag(Qt::DropActions supportedActions) data->setData(DFMGLOBAL_NAMESPACE::Mime::kDFMTreeUrlsKey, ba); } - QPixmap pixmap = d->viewDrawHelper->renderDragPixmap(currentViewMode(), indexes); QDrag *drag = new QDrag(this); drag->setPixmap(pixmap); @@ -1920,17 +1913,16 @@ void FileView::initializeConnect() }, Qt::DirectConnection); } - connect(&FileInfoHelper::instance(), &FileInfoHelper::smbSeverMayModifyPassword, this, [this](const QUrl &url){ + connect(&FileInfoHelper::instance(), &FileInfoHelper::smbSeverMayModifyPassword, this, [this](const QUrl &url) { if (DeviceUtils::isSamba(rootUrl()) && url.path().startsWith(rootUrl().path())) { fmInfo() << rootUrl() << url << "smb server may modify password"; if (d->isShowSmbMountError) - return ; + return; d->isShowSmbMountError = true; DialogManager::instance()->showErrorDialog(tr("Mount error"), tr("Server login credentials are invalid. Please uninstall and remount")); d->isShowSmbMountError = false; } - }); } @@ -1956,7 +1948,7 @@ void FileView::initializePreSelectTimer() d->preSelectTimer->setInterval(100); d->preSelectTimer->setSingleShot(true); - connect(d->preSelectTimer, &QTimer::timeout, this, [ = ] { + connect(d->preSelectTimer, &QTimer::timeout, this, [=] { if (selectFiles(d->preSelectionUrls)) d->preSelectionUrls.clear(); }); @@ -2025,6 +2017,8 @@ void FileView::updateContentLabel() if (fileInfo) { d->contentLabel->setText(fileInfo->viewOfTip(ViewInfoType::kEmptyDir)); d->contentLabel->adjustSize(); + d->contentLabel->setWordWrap(true); + d->contentLabel->setAlignment(Qt::AlignCenter); return; } }