Q_UNUSED(key)
if (KItemListContainer *container = qobject_cast<KItemListContainer *>(object)) {
+ if (auto controller = container->controller(); controller) {
+ if (KItemListView *view = controller->view(); view && view->accessibleParent()) {
+ return view->accessibleParent();
+ }
+ }
return new KItemListContainerAccessible(container);
} else if (KItemListView *view = qobject_cast<KItemListView *>(object)) {
- return new KItemListViewAccessible(view);
+ return new KItemListViewAccessible(view, view->accessibleParent());
}
return nullptr;
if (!m_headerWidget->automaticColumnResizing()) {
// The column-width of new roles are still 0. Apply the preferred
// column-width as default with.
- for (const QByteArray &role : qAsConst(m_visibleRoles)) {
+ for (const QByteArray &role : std::as_const(m_visibleRoles)) {
if (m_headerWidget->columnWidth(role) == 0) {
const qreal width = m_headerWidget->preferredColumnWidth(role);
m_headerWidget->setColumnWidth(role, width);
return m_groupHeaderCreator;
}
+#ifndef QT_NO_ACCESSIBILITY
+void KItemListView::setAccessibleParentsObject(KItemListContainer *accessibleParentsObject)
+{
+ Q_ASSERT(!m_accessibleParent);
+ m_accessibleParent = new KItemListContainerAccessible(accessibleParentsObject);
+}
+KItemListContainerAccessible *KItemListView::accessibleParent()
+{
+ Q_CHECK_PTR(m_accessibleParent); // We always want the accessibility tree/hierarchy to be complete.
+ return m_accessibleParent;
+}
+#endif
+
QSizeF KItemListView::itemSize() const
{
return m_itemSize;
if (m_headerWidget->automaticColumnResizing()) {
applyAutomaticColumnWidths();
} else {
- const qreal requiredWidth = columnWidthsSum();
+ const qreal requiredWidth = columnWidthsSum() + 2 * m_headerWidget->sidePadding();
const QSizeF dynamicItemSize(qMax(newSize.width(), requiredWidth), m_itemSize.height());
m_layouter->setItemSize(dynamicItemSize);
}
std::optional<int> KItemListView::itemAt(const QPointF &pos) const
{
+ if (headerBoundaries().contains(pos)) {
+ return std::nullopt;
+ }
+
QHashIterator<int, KItemListWidget *> it(m_visibleItems);
while (it.hasNext()) {
it.next();
return m_sizeHintResolver->isElided(index);
}
-void KItemListView::scrollToItem(int index)
+void KItemListView::scrollToItem(int index, ViewItemPosition viewItemPosition)
{
QRectF viewGeometry = geometry();
if (m_headerWidget->isVisible()) {
}
QRectF currentRect = itemRect(index);
- // Fix for Bug 311099 - View the underscore when using Ctrl + PagDown
+ if (layoutDirection() == Qt::RightToLeft && scrollOrientation() == Qt::Horizontal) {
+ currentRect.moveLeft(m_layouter->size().width() - currentRect.right());
+ }
+
+ // Fix for Bug 311099 - View the underscore when using Ctrl + PageDown
currentRect.adjust(-m_styleOption.horizontalMargin, -m_styleOption.verticalMargin, m_styleOption.horizontalMargin, m_styleOption.verticalMargin);
- if (!viewGeometry.contains(currentRect)) {
- qreal newOffset = scrollOffset();
- if (scrollOrientation() == Qt::Vertical) {
- if (currentRect.top() < viewGeometry.top()) {
- newOffset += currentRect.top() - viewGeometry.top();
- } else if (currentRect.bottom() > viewGeometry.bottom()) {
- newOffset += currentRect.bottom() - viewGeometry.bottom();
+ qreal offset = 0;
+ switch (scrollOrientation()) {
+ case Qt::Vertical:
+ if (currentRect.top() < viewGeometry.top() || currentRect.bottom() > viewGeometry.bottom()) {
+ switch (viewItemPosition) {
+ case Beginning:
+ offset = currentRect.top() - viewGeometry.top();
+ break;
+ case Middle:
+ offset = 0.5 * (currentRect.top() + currentRect.bottom() - (viewGeometry.top() + viewGeometry.bottom()));
+ break;
+ case End:
+ offset = currentRect.bottom() - viewGeometry.bottom();
+ break;
+ case Nearest:
+ if (currentRect.top() < viewGeometry.top()) {
+ offset = currentRect.top() - viewGeometry.top();
+ }
+ if (currentRect.bottom() > viewGeometry.bottom() + offset) {
+ offset += currentRect.bottom() - viewGeometry.bottom() - offset;
+ }
+ break;
+ default:
+ Q_UNREACHABLE();
}
- } else {
- if (currentRect.left() < viewGeometry.left()) {
- newOffset += currentRect.left() - viewGeometry.left();
- } else if (currentRect.right() > viewGeometry.right()) {
- newOffset += currentRect.right() - viewGeometry.right();
+ }
+ break;
+ case Qt::Horizontal:
+ if (currentRect.left() < viewGeometry.left() || currentRect.right() > viewGeometry.right()) {
+ switch (viewItemPosition) {
+ case Beginning:
+ if (layoutDirection() == Qt::RightToLeft) {
+ offset = currentRect.right() - viewGeometry.right();
+ } else {
+ offset = currentRect.left() - viewGeometry.left();
+ }
+ break;
+ case Middle:
+ offset = 0.5 * (currentRect.left() + currentRect.right() - (viewGeometry.left() + viewGeometry.right()));
+ break;
+ case End:
+ if (layoutDirection() == Qt::RightToLeft) {
+ offset = currentRect.left() - viewGeometry.left();
+ } else {
+ offset = currentRect.right() - viewGeometry.right();
+ }
+ break;
+ case Nearest:
+ if (layoutDirection() == Qt::RightToLeft) {
+ if (currentRect.left() < viewGeometry.left()) {
+ offset = currentRect.left() - viewGeometry.left();
+ }
+ if (currentRect.right() > viewGeometry.right() + offset) {
+ offset += currentRect.right() - viewGeometry.right() - offset;
+ }
+ } else {
+ if (currentRect.right() > viewGeometry.right()) {
+ offset = currentRect.right() - viewGeometry.right();
+ }
+ if (currentRect.left() < viewGeometry.left() + offset) {
+ offset += currentRect.left() - viewGeometry.left() - offset;
+ }
+ }
+ break;
+ default:
+ Q_UNREACHABLE();
}
}
+ break;
+ default:
+ Q_UNREACHABLE();
+ }
- if (newOffset != scrollOffset()) {
- Q_EMIT scrollTo(newOffset);
- return;
- }
+ if (!qFuzzyIsNull(offset)) {
+ Q_EMIT scrollTo(scrollOffset() + offset);
+ return;
}
Q_EMIT scrollingStopped();
{
QGraphicsWidget::paint(painter, option, widget);
- for (auto animation : qAsConst(m_rubberBandAnimations)) {
+ for (auto animation : std::as_const(m_rubberBandAnimations)) {
QRectF rubberBandRect = animation->property(RubberPropertyName).toRectF();
const QPointF topLeft = rubberBandRect.topLeft();
updateFont();
break;
+ case QEvent::FocusIn:
+ focusInEvent(static_cast<QFocusEvent *>(event));
+ event->accept();
+ return true;
+ break;
+
+ case QEvent::FocusOut:
+ focusOutEvent(static_cast<QFocusEvent *>(event));
+ event->accept();
+ return true;
+ break;
+
default:
// Forward all other events to the controller and handle them there
if (!m_editingRole && m_controller && m_controller->processEvent(event, transform())) {
// after the deleted items. It is important to update them in ascending
// order to prevent overlaps when setting the new index.
std::sort(itemsToMove.begin(), itemsToMove.end());
- for (int i : qAsConst(itemsToMove)) {
+ for (int i : std::as_const(itemsToMove)) {
KItemListWidget *widget = m_visibleItems.value(i);
Q_ASSERT(widget);
const int newIndex = i - count;
}
}
+void KItemListView::slotGroupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+ if (m_grouped) {
+ updateVisibleGroupHeaders();
+ doLayout(NoAnimation);
+ }
+}
+
+void KItemListView::slotGroupRoleChanged(const QByteArray ¤t, const QByteArray &previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+ if (m_grouped) {
+ updateVisibleGroupHeaders();
+ doLayout(NoAnimation);
+ }
+}
+
void KItemListView::slotCurrentChanged(int current, int previous)
{
Q_UNUSED(previous)
disconnect(m_model, &KItemModelBase::groupedSortingChanged, this, &KItemListView::slotGroupedSortingChanged);
disconnect(m_model, &KItemModelBase::sortOrderChanged, this, &KItemListView::slotSortOrderChanged);
disconnect(m_model, &KItemModelBase::sortRoleChanged, this, &KItemListView::slotSortRoleChanged);
+ disconnect(m_model, &KItemModelBase::groupOrderChanged, this, &KItemListView::slotGroupOrderChanged);
+ disconnect(m_model, &KItemModelBase::groupRoleChanged, this, &KItemListView::slotGroupRoleChanged);
m_sizeHintResolver->itemsRemoved(KItemRangeList() << KItemRange(0, m_model->count()));
}
}
// Delete invisible KItemListWidget instances that have not been reused
- for (int index : qAsConst(reusableItems)) {
+ for (int index : std::as_const(reusableItems)) {
recycleWidget(m_visibleItems.value(index));
}
const int groupIndex = groupIndexForItem(index);
Q_ASSERT(groupIndex >= 0);
groupHeader->setData(groups.at(groupIndex).second);
- groupHeader->setRole(model()->sortRole());
+ groupHeader->setRole(model()->groupRole());
groupHeader->setStyleOption(m_styleOption);
groupHeader->setScrollOrientation(scrollOrientation());
groupHeader->setItemIndex(index);
const QFontMetricsF fontMetrics(m_headerWidget->font());
const int gripMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderGripMargin);
const int headerMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderMargin);
- for (const QByteArray &visibleRole : qAsConst(m_visibleRoles)) {
+ for (const QByteArray &visibleRole : std::as_const(m_visibleRoles)) {
const QString headerText = m_model->roleDescription(visibleRole);
const qreal headerWidth = fontMetrics.horizontalAdvance(headerText) + gripMargin + headerMargin * 2;
widths.insert(visibleRole, headerWidth);
const int endIndex = startIndex + itemRange.count - 1;
for (int i = startIndex; i <= endIndex; ++i) {
- for (const QByteArray &visibleRole : qAsConst(m_visibleRoles)) {
+ for (const QByteArray &visibleRole : std::as_const(m_visibleRoles)) {
qreal maxWidth = widths.value(visibleRole, 0);
const qreal width = creator->preferredRoleColumnWidth(visibleRole, i, this);
maxWidth = qMax(width, maxWidth);
void KItemListView::applyColumnWidthsFromHeader()
{
// Apply the new size to the layouter
- const qreal requiredWidth = columnWidthsSum() + m_headerWidget->sidePadding();
+ const qreal requiredWidth = columnWidthsSum() + 2 * m_headerWidget->sidePadding();
const QSizeF dynamicItemSize(qMax(size().width(), requiredWidth), m_itemSize.height());
m_layouter->setItemSize(dynamicItemSize);
void KItemListView::updateWidgetColumnWidths(KItemListWidget *widget)
{
- for (const QByteArray &role : qAsConst(m_visibleRoles)) {
+ for (const QByteArray &role : std::as_const(m_visibleRoles)) {
widget->setColumnWidth(role, m_headerWidget->columnWidth(role));
}
widget->setSidePadding(m_headerWidget->sidePadding());
if (itemCount == rangesItemCount) {
const QHash<QByteArray, qreal> preferredWidths = preferredColumnWidths(itemRanges);
- for (const QByteArray &role : qAsConst(m_visibleRoles)) {
+ for (const QByteArray &role : std::as_const(m_visibleRoles)) {
m_headerWidget->setPreferredColumnWidth(role, preferredWidths.value(role));
}
} else {
// size does not use the available view-size the size of the
// first role will get stretched.
- for (const QByteArray &role : qAsConst(m_visibleRoles)) {
+ for (const QByteArray &role : std::as_const(m_visibleRoles)) {
const qreal preferredWidth = m_headerWidget->preferredColumnWidth(role);
m_headerWidget->setColumnWidth(role, preferredWidth);
}
qreal firstColumnWidth = m_headerWidget->columnWidth(firstRole);
QSizeF dynamicItemSize = m_itemSize;
- qreal requiredWidth = columnWidthsSum() + m_headerWidget->sidePadding()
- + m_headerWidget->sidePadding(); // Adding the padding a second time so we have the same padding symmetrically on both sides of the view.
- // This improves UX, looks better and increases the chances of users figuring out that the padding area can be used for deselecting and dropping files.
+ qreal requiredWidth = columnWidthsSum() + 2 * m_headerWidget->sidePadding(); // Adding the padding a second time so we have the same padding
+ // symmetrically on both sides of the view. This improves UX, looks better and increases the chances of users figuring out that the padding
+ // area can be used for deselecting and dropping files.
const qreal availableWidth = size().width();
if (requiredWidth < availableWidth) {
// Stretch the first column to use the whole remaining width
qreal KItemListView::columnWidthsSum() const
{
qreal widthsSum = 0;
- for (const QByteArray &role : qAsConst(m_visibleRoles)) {
+ for (const QByteArray &role : std::as_const(m_visibleRoles)) {
widthsSum += m_headerWidget->columnWidth(role);
}
return widthsSum;