Skip to content
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
8 changes: 8 additions & 0 deletions src/widgets/dlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,14 @@ void DListView::setBackgroundType(DStyledItemDelegate::BackgroundType background
{
if (DStyledItemDelegate *d = qobject_cast<DStyledItemDelegate *>(itemDelegate())) {
d->setBackgroundType(backgroundType);

if (d->spacing() < 0) {
if (d->backgroundType() == DStyledItemDelegate::RoundedBackground) {
d->setItemSpacing(10);
} else if (d->backgroundType() == DStyledItemDelegate::ClipCornerBackground) {
d->setItemSpacing(1);
}
}
}
}

Expand Down
28 changes: 11 additions & 17 deletions src/widgets/dstyleditemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,23 +516,17 @@
}
}


inline int itemSpacing() const
inline int spacing() const

Check warning on line 519 in src/widgets/dstyleditemdelegate.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Local variable 'spacing' shadows outer function

Check warning on line 519 in src/widgets/dstyleditemdelegate.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Local variable 'spacing' shadows outer function

Check warning on line 519 in src/widgets/dstyleditemdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'spacing' shadows outer function

Check warning on line 519 in src/widgets/dstyleditemdelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'spacing' shadows outer function
{
if (spacing >= 0)
return spacing;
const auto type = backgroundType & DStyledItemDelegate::BackgroundType_Mask;
if (type == DStyledItemDelegate::RoundedBackground)
return 10;
if (type == DStyledItemDelegate::ClipCornerBackground)
return 1;
return 0;
if (itemSpacing < 0)
return 0;
return itemSpacing;
}

DStyledItemDelegate::BackgroundType backgroundType = DStyledItemDelegate::NoBackground;
QMargins margins;
QSize itemSize;
int spacing = -1;
int itemSpacing = -1;
QMap<QModelIndex, QList<QPair<QAction*, QRect>>> clickableActionMap;
QAction *pressedAction = nullptr;
QList<QPointer<QWidget>> lastWidgets;
Expand Down Expand Up @@ -1189,9 +1183,9 @@
const QListView * lv = qobject_cast<const QListView*>(option.widget);
if (lv) {
if (lv->flow() == QListView::LeftToRight) {
size.rwidth() += d->itemSpacing();
size.rwidth() += d->spacing();
} else {
size.rheight() += d->itemSpacing();
size.rheight() += d->spacing();
}
}

Expand Down Expand Up @@ -1266,7 +1260,7 @@
{
D_DC(DStyledItemDelegate);

return d->itemSpacing();
return d->itemSpacing;
}

void DStyledItemDelegate::setBackgroundType(DStyledItemDelegate::BackgroundType type)
Expand Down Expand Up @@ -1310,7 +1304,7 @@
{
D_D(DStyledItemDelegate);

d->spacing = spacing;
d->itemSpacing = spacing;
}

void DStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const
Expand Down Expand Up @@ -1366,9 +1360,9 @@
const QListView * lv = qobject_cast<const QListView*>(option->widget);
if (lv) {
if (lv->flow() == QListView::LeftToRight) {
option->rect.adjust(0, 0, 0 - d->itemSpacing(), 0);
option->rect.adjust(0, 0, 0 - d->spacing(), 0);
} else {
option->rect.adjust(0, 0, 0, 0 - d->itemSpacing());
option->rect.adjust(0, 0, 0, 0 - d->spacing());
}
if (lv->window() && lv->window()->isActiveWindow()) {
option->state |= QStyle::State_Active;
Expand Down
Loading