X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8ffc72e87f4cffa8dce32da06e9a1d51a595765e..d7b33b76a18b14e9f286e4d8326b00910b9ea02a:/src/kitemviews/kitemlistview.cpp diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 5dd21615e..f14369cbd 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -1,23 +1,10 @@ -/*************************************************************************** - * Copyright (C) 2011 by Peter Penz * - * * - * Based on the Itemviews NG project from Trolltech Labs * - * * - * 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 + * + * Based on the Itemviews NG project from Trolltech Labs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "kitemlistview.h" @@ -37,6 +24,7 @@ #include #include #include +#include #include #include @@ -93,11 +81,13 @@ KItemListView::KItemListView(QGraphicsWidget* parent) : 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); @@ -118,6 +108,23 @@ KItemListView::KItemListView(QGraphicsWidget* parent) : 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); @@ -334,11 +341,6 @@ QSizeF KItemListView::itemSize() const return m_itemSize; } -QSizeF KItemListView::itemSizeHint() const -{ - return m_sizeHintResolver->minSizeHint(); -} - const KItemListStyleOption& KItemListView::styleOption() const { return m_styleOption; @@ -676,10 +678,22 @@ void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt 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(); + style()->drawControl(QStyle::CE_RubberBand, &opt, painter); + } + 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