Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: When there are multiple lines of files in the document management system, only the last line will be displayed. When selected, a slider will be displayed, and other lines will not be displayed #2042

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ int FileViewHelper::verticalOffset() const
return parent()->verticalOffset();
}

bool FileViewHelper::isLastIndex(const QModelIndex &index)
{
int rowCount = parent()->model()->rowCount(parent()->rootIndex());
return index.row() + 1 == rowCount;
}

int FileViewHelper::caculateListItemIndex(const QSize &itemSize, const QPoint &pos)
{
if (pos.y() % (itemSize.height() + kListViewSpacing * 2) < kListViewSpacing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FileViewHelper : public QObject
bool isEmptyArea(const QPoint &pos);
QSize viewContentSize() const;
int verticalOffset() const;
bool isLastIndex(const QModelIndex &index);

static int caculateListItemIndex(const QSize &itemSize, const QPoint &pos);
static int caculateIconItemIndex(const FileView *view, const QSize &itemSize, const QPoint &pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,13 @@ QRectF ExpandedItem::iconGeometry() const

return iconRect;
}

void ExpandedItem::setDifferenceOfLastRow(const int diff)
{
this->diff = diff < 0 ? 0 : diff;
}

int ExpandedItem::getDifferenceOfLastRow() const
{
return diff;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class ExpandedItem : public QWidget
void setOption(QStyleOptionViewItem opt);
QRectF textGeometry(int width = -1) const;
QRectF iconGeometry() const;
void setDifferenceOfLastRow(const int diff);
int getDifferenceOfLastRow() const;

private:
QPixmap iconPixmap;
Expand All @@ -52,6 +54,7 @@ class ExpandedItem : public QWidget
qreal opacity { 1 };
bool canDeferredDelete { true };
IconItemDelegate *delegate { nullptr };
int diff { 0 };
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ void IconItemDelegate::paintItemFileName(QPainter *painter, QRectF iconRect, QPa

// if has selected show all file name else show elide file name.
bool isSelected = !isDragMode && isSelectedOpt && opt.showDecorationSelected;
if (!singleSelected)
d->expandedItem->setDifferenceOfLastRow(0);

if (isSelected && singleSelected) {
const_cast<IconItemDelegate *>(this)->hideNotEditingIndexWidget();
Expand All @@ -582,17 +584,15 @@ void IconItemDelegate::paintItemFileName(QPainter *painter, QRectF iconRect, QPa
d->expandedItem->setOption(opt);
d->expandedItem->setTextBounding(QRectF());
d->expandedItem->setFixedWidth(0);

if (parent()->parent()->indexOfRow(index) == parent()->parent()->rowCount() - 1) {
d->lastAndExpandedIndex = index;
}
d->expandedItem->setDifferenceOfLastRow(parent()->parent()->rowCount() - parent()->parent()->indexOfRow(index) - 1);

updateEditorGeometry(d->expandedItem, opt, index);

return;
} else {
if (!singleSelected) {
const_cast<IconItemDelegate *>(this)->hideNotEditingIndexWidget();
d->lastAndExpandedIndex = QModelIndex();
}
}

Expand Down Expand Up @@ -630,9 +630,13 @@ QSize IconItemDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex

const QSize &size = d->itemSizeHint;

if (index.isValid() && index == d->lastAndExpandedIndex) {
// 如果有一个选中,名称显示很长时,最后一个index时设置item的高度为最多,右边才会出现滑动块
if(index.isValid() && parent()->isLastIndex(index) && d->expandedItem
&& d->expandedIndex.isValid() && d->expandedItem->isVisible()) {
d->expandedItem->setIconHeight(parent()->parent()->iconSize().height());
return QSize(size.width(), d->expandedItem->heightForWidth(size.width()));
auto hight = qMax(size.height(), d->expandedItem->heightForWidth(size.width()) -
d->expandedItem->getDifferenceOfLastRow() * size.height());
return QSize(size.width(), hight);
}

return size;
Expand Down Expand Up @@ -700,7 +704,6 @@ void IconItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionV
editor->setFixedWidth(option.rect.width());
d->expandedItem->setIconHeight(iconSize.height());
editor->adjustSize();

return;
}

Expand Down
Loading