#include <QPropertyAnimation>
#include <QStyleOptionRubberBand>
#include <QTimer>
+#include <QVariantAnimation>
namespace {
// Delay in ms for triggering the next autoscroll
const int RepeatingAutoScrollDelay = 1000 / 60;
+
+ // Copied from the Kirigami.Units.shortDuration
+ const int RubberFadeSpeed = 150;
+
+ const char* RubberPropertyName = "_kitemviews_rubberBandPosition";
}
#ifndef QT_NO_ACCESSIBILITY
}
if (newOffset != scrollOffset()) {
- emit scrollTo(newOffset);
+ Q_EMIT scrollTo(newOffset);
}
}
}
{
QGraphicsWidget::paint(painter, option, widget);
+ for (auto animation : qAsConst(m_rubberBandAnimations)) {
+ QRectF rubberBandRect = animation->property(RubberPropertyName).toRectF();
+
+ const QPointF topLeft = rubberBandRect.topLeft();
+ if (scrollOrientation() == Qt::Vertical) {
+ rubberBandRect.moveTo(topLeft.x(), topLeft.y() - scrollOffset());
+ } else {
+ rubberBandRect.moveTo(topLeft.x() - scrollOffset(), topLeft.y());
+ }
+
+ QStyleOptionRubberBand opt;
+ initStyleOption(&opt);
+ opt.shape = QRubberBand::Rectangle;
+ opt.opaque = false;
+ opt.rect = rubberBandRect.toRect();
+
+ painter->save();
+
+ painter->setOpacity(animation->currentValue().toReal());
+ style()->drawControl(QStyle::CE_RubberBand, &opt, painter);
+
+ painter->restore();
+ }
+
if (m_rubberBand->isActive()) {
QRectF rubberBandRect = QRectF(m_rubberBand->startPosition(),
m_rubberBand->endPosition()).normalized();
doLayout(NoAnimation);
onScrollOrientationChanged(orientation, previousOrientation);
- emit scrollOrientationChanged(orientation, previousOrientation);
+ Q_EMIT scrollOrientationChanged(orientation, previousOrientation);
}
Qt::Orientation KItemListView::scrollOrientation() const
QVector<int> itemsToMove;
// Remove all KItemListWidget instances that got deleted
- for (KItemListWidget* widget : qAsConst(m_visibleItems)) {
+ // Iterate over a const copy because the container is mutated within the loop
+ // directly and in `recycleWidget()` (https://bugs.kde.org/show_bug.cgi?id=428374)
+ const auto visibleItems = m_visibleItems;
+ for (KItemListWidget* widget : visibleItems) {
const int i = widget->index();
if (i < firstRemovedIndex) {
continue;
connect(m_rubberBand, &KItemListRubberBand::endPositionChanged, this, &KItemListView::slotRubberBandPosChanged);
m_skipAutoScrollForRubberBand = true;
} else {
+ QRectF rubberBandRect = QRectF(m_rubberBand->startPosition(),
+ m_rubberBand->endPosition()).normalized();
+
+ auto animation = new QVariantAnimation(this);
+ animation->setStartValue(1.0);
+ animation->setEndValue(0.0);
+ animation->setDuration(RubberFadeSpeed);
+ animation->setProperty(RubberPropertyName, rubberBandRect);
+
+ QEasingCurve curve;
+ curve.setType(QEasingCurve::BezierSpline);
+ curve.addCubicBezierSegment(QPointF(0.4, 0.0), QPointF(1.0, 1.0), QPointF(1.0, 1.0));
+ animation->setEasingCurve(curve);
+
+ connect(animation, &QVariantAnimation::valueChanged, this, [=](const QVariant&) {
+ update();
+ });
+ connect(animation, &QVariantAnimation::finished, this, [=]() {
+ m_rubberBandAnimations.removeAll(animation);
+ delete animation;
+ });
+ animation->start();
+ m_rubberBandAnimations << animation;
+
disconnect(m_rubberBand, &KItemListRubberBand::startPositionChanged, this, &KItemListView::slotRubberBandPosChanged);
disconnect(m_rubberBand, &KItemListRubberBand::endPositionChanged, this, &KItemListView::slotRubberBandPosChanged);
m_skipAutoScrollForRubberBand = false;
setVisibleRoles(current);
- emit visibleRolesChanged(current, previous);
+ Q_EMIT visibleRolesChanged(current, previous);
}
void KItemListView::triggerAutoScrolling()
{
disconnectRoleEditingSignals(index);
- emit roleEditingCanceled(index, role, value);
+ Q_EMIT roleEditingCanceled(index, role, value);
m_editingRole = false;
}
{
disconnectRoleEditingSignals(index);
- emit roleEditingFinished(index, role, value);
+ Q_EMIT roleEditingFinished(index, role, value);
m_editingRole = false;
}
{
const qreal newScrollOffset = m_layouter->scrollOffset();
if (m_oldScrollOffset != newScrollOffset) {
- emit scrollOffsetChanged(newScrollOffset, m_oldScrollOffset);
+ Q_EMIT scrollOffsetChanged(newScrollOffset, m_oldScrollOffset);
m_oldScrollOffset = newScrollOffset;
}
const qreal newMaximumScrollOffset = m_layouter->maximumScrollOffset();
if (m_oldMaximumScrollOffset != newMaximumScrollOffset) {
- emit maximumScrollOffsetChanged(newMaximumScrollOffset, m_oldMaximumScrollOffset);
+ Q_EMIT maximumScrollOffsetChanged(newMaximumScrollOffset, m_oldMaximumScrollOffset);
m_oldMaximumScrollOffset = newMaximumScrollOffset;
}
const qreal newItemOffset = m_layouter->itemOffset();
if (m_oldItemOffset != newItemOffset) {
- emit itemOffsetChanged(newItemOffset, m_oldItemOffset);
+ Q_EMIT itemOffsetChanged(newItemOffset, m_oldItemOffset);
m_oldItemOffset = newItemOffset;
}
const qreal newMaximumItemOffset = m_layouter->maximumItemOffset();
if (m_oldMaximumItemOffset != newMaximumItemOffset) {
- emit maximumItemOffsetChanged(newMaximumItemOffset, m_oldMaximumItemOffset);
+ Q_EMIT maximumItemOffsetChanged(newMaximumItemOffset, m_oldMaximumItemOffset);
m_oldMaximumItemOffset = newMaximumItemOffset;
}
}
groupHeaderHeight += 2 * m_styleOption.horizontalMargin;
groupHeaderMargin = m_styleOption.horizontalMargin;
} else if (m_itemSize.isEmpty()){
- groupHeaderHeight += 4 * m_styleOption.padding;
+ groupHeaderHeight += 2 * m_styleOption.padding;
groupHeaderMargin = m_styleOption.iconSize / 2;
} else {
groupHeaderHeight += 2 * m_styleOption.padding + m_styleOption.verticalMargin;