+ if (m_styleOption == option) {
+ return;
+ }
+
+ const KItemListStyleOption previousOption = m_styleOption;
+ m_styleOption = option;
+
+ bool animate = true;
+ const QSizeF margin(option.horizontalMargin, option.verticalMargin);
+ if (margin != m_layouter->itemMargin()) {
+ // Skip animations when the number of rows or columns
+ // are changed in the grid layout. Although the animation
+ // engine can handle this usecase, it looks obtrusive.
+ animate = !changesItemGridLayout(m_layouter->size(), m_layouter->itemSize(), margin);
+ m_layouter->setItemMargin(margin);
+ }
+
+ if (m_grouped) {
+ updateGroupHeaderHeight();
+ }
+
+ if (animate && (previousOption.maxTextLines != option.maxTextLines || previousOption.maxTextWidth != option.maxTextWidth)) {
+ // Animating a change of the maximum text size just results in expensive
+ // temporary eliding and clipping operations and does not look good visually.
+ animate = false;
+ }
+
+ QHashIterator<int, KItemListWidget *> it(m_visibleItems);
+ while (it.hasNext()) {
+ it.next();
+ it.value()->setStyleOption(option);
+ }
+
+ m_sizeHintResolver->clearCache();
+ m_layouter->markAsDirty();
+ doLayout(animate ? Animation : NoAnimation);
+
+ if (m_itemSize.isEmpty()) {
+ updatePreferredColumnWidths();
+ }
+
+ onStyleOptionChanged(option, previousOption);
+}
+
+void KItemListView::setScrollOrientation(Qt::Orientation orientation)
+{
+ const Qt::Orientation previousOrientation = m_layouter->scrollOrientation();
+ if (orientation == previousOrientation) {
+ return;
+ }
+
+ m_layouter->setScrollOrientation(orientation);
+ m_animation->setScrollOrientation(orientation);
+ m_sizeHintResolver->clearCache();
+
+ if (m_grouped) {
+ QMutableHashIterator<KItemListWidget *, KItemListGroupHeader *> it(m_visibleGroups);
+ while (it.hasNext()) {
+ it.next();
+ it.value()->setScrollOrientation(orientation);
+ }
+ updateGroupHeaderHeight();
+ }
+
+ doLayout(NoAnimation);
+
+ onScrollOrientationChanged(orientation, previousOrientation);
+ Q_EMIT scrollOrientationChanged(orientation, previousOrientation);
+}
+
+Qt::Orientation KItemListView::scrollOrientation() const
+{
+ return m_layouter->scrollOrientation();
+}
+
+KItemListWidgetCreatorBase *KItemListView::defaultWidgetCreator() const
+{
+ return nullptr;
+}
+
+KItemListGroupHeaderCreatorBase *KItemListView::defaultGroupHeaderCreator() const
+{
+ return nullptr;
+}
+
+void KItemListView::initializeItemListWidget(KItemListWidget *item)
+{
+ Q_UNUSED(item)
+}
+
+bool KItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray> &changedRoles) const
+{
+ Q_UNUSED(changedRoles)
+ return true;
+}
+
+void KItemListView::onControllerChanged(KItemListController *current, KItemListController *previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+}
+
+void KItemListView::onModelChanged(KItemModelBase *current, KItemModelBase *previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+}
+
+void KItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+}
+
+void KItemListView::onItemSizeChanged(const QSizeF ¤t, const QSizeF &previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+}
+
+void KItemListView::onScrollOffsetChanged(qreal current, qreal previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+}
+
+void KItemListView::onVisibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+}
+
+void KItemListView::onStyleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous)
+{
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
+}
+
+void KItemListView::onHighlightEntireRowChanged(bool highlightEntireRow)
+{
+ Q_UNUSED(highlightEntireRow)
+}
+
+void KItemListView::onSupportsItemExpandingChanged(bool supportsExpanding)
+{
+ Q_UNUSED(supportsExpanding)
+}
+
+void KItemListView::onTransactionBegin()
+{
+}
+
+void KItemListView::onTransactionEnd()
+{
+}
+
+bool KItemListView::event(QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::PaletteChange:
+ updatePalette();
+ break;
+
+ case QEvent::FontChange:
+ 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())) {
+ event->accept();
+ return true;
+ }
+ }
+
+ return QGraphicsWidget::event(event);
+}
+
+void KItemListView::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ m_mousePos = transform().map(event->pos());
+ event->accept();
+}
+
+void KItemListView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ QGraphicsWidget::mouseMoveEvent(event);
+
+ m_mousePos = transform().map(event->pos());
+ if (m_autoScrollTimer && !m_autoScrollTimer->isActive()) {
+ m_autoScrollTimer->start(InitialAutoScrollDelay);
+ }
+}
+
+void KItemListView::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
+{
+ event->setAccepted(true);
+ setAutoScroll(true);
+}
+
+void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
+{
+ QGraphicsWidget::dragMoveEvent(event);