-/***************************************************************************
- * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
- * *
- * Based on the Itemviews NG project from Trolltech Labs: *
- * http://qt.gitorious.org/qt-labs/itemviews-ng *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ *
+ * Based on the Itemviews NG project from Trolltech Labs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#include "kitemlistview.h"
#include <QElapsedTimer>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
+#include <QPropertyAnimation>
#include <QStyleOptionRubberBand>
#include <QTimer>
m_oldMaximumItemOffset(0),
m_skipAutoScrollForRubberBand(false),
m_rubberBand(nullptr),
+ m_tapAndHoldIndicator(nullptr),
m_mousePos(),
m_autoScrollIncrement(0),
m_autoScrollTimer(nullptr),
m_header(nullptr),
m_headerWidget(nullptr),
+ m_indicatorAnimation(nullptr),
m_dropIndicator()
{
setAcceptHoverEvents(true);
+ setAcceptTouchEvents(true);
m_sizeHintResolver = new KItemListSizeHintResolver(this);
m_rubberBand = new KItemListRubberBand(this);
connect(m_rubberBand, &KItemListRubberBand::activationChanged, this, &KItemListView::slotRubberBandActivationChanged);
+ m_tapAndHoldIndicator = new KItemListRubberBand(this);
+ m_indicatorAnimation = new QPropertyAnimation(m_tapAndHoldIndicator, "endPosition", this);
+ connect(m_tapAndHoldIndicator, &KItemListRubberBand::activationChanged, this, [this](bool active) {
+ if (active) {
+ m_indicatorAnimation->setDuration(150);
+ m_indicatorAnimation->setStartValue(QPointF(1, 1));
+ m_indicatorAnimation->setEndValue(QPointF(40, 40));
+ m_indicatorAnimation->start();
+ }
+ update();
+ });
+ connect(m_tapAndHoldIndicator, &KItemListRubberBand::endPositionChanged, this, [this]() {
+ if (m_tapAndHoldIndicator->isActive()) {
+ update();
+ }
+ });
+
m_headerWidget = new KItemListHeaderWidget(this);
m_headerWidget->setVisible(false);
return m_itemSize;
}
-QSizeF KItemListView::itemSizeHint() const
-{
- return m_sizeHintResolver->minSizeHint();
-}
-
const KItemListStyleOption& KItemListView::styleOption() const
{
return m_styleOption;
}
QStyleOptionRubberBand opt;
- opt.initFrom(widget);
+ initStyleOption(&opt);
+ opt.shape = QRubberBand::Rectangle;
+ opt.opaque = false;
+ opt.rect = rubberBandRect.toRect();
+ style()->drawControl(QStyle::CE_RubberBand, &opt, painter);
+ }
+
+ if (m_tapAndHoldIndicator->isActive()) {
+ const QPointF indicatorSize = m_tapAndHoldIndicator->endPosition();
+ const QRectF rubberBandRect = QRectF(m_tapAndHoldIndicator->startPosition() - indicatorSize,
+ (m_tapAndHoldIndicator->startPosition()) + indicatorSize).normalized();
+ QStyleOptionRubberBand opt;
+ initStyleOption(&opt);
opt.shape = QRubberBand::Rectangle;
opt.opaque = false;
opt.rect = rubberBandRect.toRect();
if (!m_dropIndicator.isEmpty()) {
const QRectF r = m_dropIndicator.toRect();
- QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
+ QColor color = palette().brush(QPalette::Normal, QPalette::Text).color();
painter->setPen(color);
// TODO: The following implementation works only for a vertical scroll-orientation
void KItemListView::initializeItemListWidget(KItemListWidget* item)
{
- Q_UNUSED(item);
+ Q_UNUSED(item)
}
bool KItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const
{
- Q_UNUSED(changedRoles);
+ Q_UNUSED(changedRoles)
return true;
}
void KItemListView::onControllerChanged(KItemListController* current, KItemListController* previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
}
void KItemListView::onModelChanged(KItemModelBase* current, KItemModelBase* previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
}
void KItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
}
void KItemListView::onItemSizeChanged(const QSizeF& current, const QSizeF& previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
}
void KItemListView::onScrollOffsetChanged(qreal current, qreal previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
}
void KItemListView::onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
}
void KItemListView::onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
}
void KItemListView::onSupportsItemExpandingChanged(bool supportsExpanding)
{
- Q_UNUSED(supportsExpanding);
+ Q_UNUSED(supportsExpanding)
}
void KItemListView::onTransactionBegin()
// Update the indexes of all KItemListWidget instances that are located
// after the inserted items. It is important to adjust the indexes in the order
// from the highest index to the lowest index to prevent overlaps when setting the new index.
- qSort(itemsToMove);
+ std::sort(itemsToMove.begin(), itemsToMove.end());
for (int i = itemsToMove.count() - 1; i >= 0; --i) {
KItemListWidget* widget = m_visibleItems.value(itemsToMove[i]);
Q_ASSERT(widget);
void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
if (m_grouped) {
updateVisibleGroupHeaders();
doLayout(NoAnimation);
void KItemListView::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous)
{
- Q_UNUSED(current);
- Q_UNUSED(previous);
+ Q_UNUSED(current)
+ Q_UNUSED(previous)
if (m_grouped) {
updateVisibleGroupHeaders();
doLayout(NoAnimation);
void KItemListView::slotCurrentChanged(int current, int previous)
{
- Q_UNUSED(previous);
+ Q_UNUSED(previous)
// In SingleSelection mode (e.g., in the Places Panel), the current item is
// always the selected item. It is not necessary to highlight the current item then.
if (m_controller->selectionBehavior() != KItemListController::SingleSelection) {
- KItemListWidget* previousWidget = m_visibleItems.value(previous, 0);
+ KItemListWidget* previousWidget = m_visibleItems.value(previous, nullptr);
if (previousWidget) {
previousWidget->setCurrent(false);
}
- KItemListWidget* currentWidget = m_visibleItems.value(current, 0);
+ KItemListWidget* currentWidget = m_visibleItems.value(current, nullptr);
if (currentWidget) {
currentWidget->setCurrent(true);
}
void KItemListView::slotSelectionChanged(const KItemSet& current, const KItemSet& previous)
{
- Q_UNUSED(previous);
+ Q_UNUSED(previous)
QHashIterator<int, KItemListWidget*> it(m_visibleItems);
while (it.hasNext()) {
qreal currentWidth,
qreal previousWidth)
{
- Q_UNUSED(role);
- Q_UNUSED(currentWidth);
- Q_UNUSED(previousWidth);
+ Q_UNUSED(role)
+ Q_UNUSED(currentWidth)
+ Q_UNUSED(previousWidth)
m_headerWidget->setAutomaticColumnResizing(false);
applyColumnWidthsFromHeader();