Skip to content

Commit

Permalink
fix: [dock] show elided name if too long.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
itsXuSt committed Sep 23, 2024
1 parent 4d89a6e commit 7d62ae3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
62 changes: 28 additions & 34 deletions src/plugins/filemanager/core/dfmplugin-workspace/views/fileview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,13 @@ void FileView::setViewMode(Global::ViewMode mode)
// itemDelegate 未设置时为未初始化状态,此时调用setViewMode需要执行设置流程
// itemDelegate 已设置时,若view不可见,则暂不执行viewMode设置逻辑
if (!isVisible() && itemDelegate()
&& d->delegates[static_cast<int>(mode)] == itemDelegate())
&& d->delegates[static_cast<int>(mode)] == itemDelegate())
return;

if (itemDelegate())
itemDelegate()->hideAllIIndexWidget();

int delegateModeIndex = mode == Global::ViewMode::kTreeMode ?
static_cast<int>(Global::ViewMode::kListMode) : static_cast<int>(mode);
int delegateModeIndex = mode == Global::ViewMode::kTreeMode ? static_cast<int>(Global::ViewMode::kListMode) : static_cast<int>(mode);
if (d->delegates.keys().contains(delegateModeIndex)) {
d->currentViewMode = mode;
} else {
Expand Down Expand Up @@ -147,14 +146,14 @@ void FileView::setViewMode(Global::ViewMode mode)
case Global::ViewMode::kListMode:
d->delegates[static_cast<int>(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());
Expand Down Expand Up @@ -538,9 +537,7 @@ void FileView::delayUpdateStatusBar()
void FileView::viewModeChanged(quint64 windowId, int viewMode)
{
Global::ViewMode mode = static_cast<Global::ViewMode>(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);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()))

Check warning on line 779 in src/plugins/filemanager/core/dfmplugin-workspace/views/fileview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::any_of algorithm instead of a raw loop.
return true;
}

Expand All @@ -800,20 +797,19 @@ QList<QUrl> 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();
Expand Down Expand Up @@ -843,21 +839,20 @@ void FileView::selectedTreeViewUrlList(QList<QUrl> &selectedUrls, QList<QUrl> &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;
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) {
treeSelectedUrls << model()->data(index, ItemRoles::kItemUrlRole).toUrl();
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

});
}

Expand All @@ -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();
});
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 7d62ae3

Please sign in to comment.