X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/40f9cfd519a3244929190146a3215ae12b98270b..0c44dfe2b1c143fae323b9ff4bd415cdd69c1086:/src/kitemviews/kitemlistwidget.cpp diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index 28b374620..69a38432a 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -1,30 +1,19 @@ -/*************************************************************************** - * Copyright (C) 2011 by Peter Penz * - * * - * 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 + * + * Based on the Itemviews NG project from Trolltech Labs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "kitemlistwidget.h" #include "kitemlistview.h" #include "private/kitemlistselectiontoggle.h" +#include +#include + #include #include #include @@ -39,7 +28,7 @@ KItemListWidgetInformant::~KItemListWidgetInformant() } KItemListWidget::KItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) : - QGraphicsWidget(parent, nullptr), + QGraphicsWidget(parent), m_informant(informant), m_index(-1), m_selected(false), @@ -55,9 +44,11 @@ KItemListWidget::KItemListWidget(KItemListWidgetInformant* informant, QGraphicsI m_hoverOpacity(0), m_hoverCache(nullptr), m_hoverAnimation(nullptr), + m_hoverSequenceIndex(0), m_selectionToggle(nullptr), m_editedRole() { + connect(&m_hoverSequenceTimer, &QTimer::timeout, this, &KItemListWidget::slotHoverSequenceTimerTimeout); } KItemListWidget::~KItemListWidget() @@ -94,7 +85,7 @@ void KItemListWidget::setData(const QHash& data, m_data = data; dataChanged(m_data); } else { - foreach (const QByteArray& role, roles) { + for (const QByteArray& role : roles) { m_data[role] = data[role]; } dataChanged(m_data, roles); @@ -109,7 +100,7 @@ QHash KItemListWidget::data() const void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - Q_UNUSED(option); + Q_UNUSED(option) if (m_alternateBackground) { const QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase); @@ -127,7 +118,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o if (m_current && m_editedRole.isEmpty()) { QStyleOptionFocusRect focusRectOption; - focusRectOption.initFrom(widget); + initStyleOption(&focusRectOption); focusRectOption.rect = textFocusRect().toRect(); focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange; if (m_selected) { @@ -254,6 +245,8 @@ void KItemListWidget::setHovered(bool hovered) } m_hoverAnimation->stop(); + m_hoverSequenceIndex = 0; + if (hovered) { const qreal startValue = qMax(hoverOpacity(), qreal(0.1)); m_hoverAnimation->setStartValue(startValue); @@ -261,9 +254,19 @@ void KItemListWidget::setHovered(bool hovered) if (m_enabledSelectionToggle && !(QApplication::mouseButtons() & Qt::LeftButton)) { initializeSelectionToggle(); } + + hoverSequenceStarted(); + + const KConfigGroup globalConfig(KSharedConfig::openConfig(), "PreviewSettings"); + const int interval = globalConfig.readEntry("HoverSequenceInterval", 700); + + m_hoverSequenceTimer.start(interval); } else { m_hoverAnimation->setStartValue(hoverOpacity()); m_hoverAnimation->setEndValue(0.0); + + hoverSequenceEnded(); + m_hoverSequenceTimer.stop(); } m_hoverAnimation->start(); @@ -379,7 +382,6 @@ QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option const bool wasHovered = m_hovered; setAlternateBackground(false); - setSelected(false); setHovered(false); paint(&painter, option, widget); @@ -394,63 +396,63 @@ QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option void KItemListWidget::dataChanged(const QHash& current, const QSet& roles) { - Q_UNUSED(current); - Q_UNUSED(roles); + Q_UNUSED(current) + Q_UNUSED(roles) } void KItemListWidget::visibleRolesChanged(const QList& current, const QList& previous) { - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(current) + Q_UNUSED(previous) } void KItemListWidget::columnWidthChanged(const QByteArray& role, qreal current, qreal previous) { - Q_UNUSED(role); - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(role) + Q_UNUSED(current) + Q_UNUSED(previous) } void KItemListWidget::styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) { - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(current) + Q_UNUSED(previous) } void KItemListWidget::currentChanged(bool current) { - Q_UNUSED(current); + Q_UNUSED(current) } void KItemListWidget::selectedChanged(bool selected) { - Q_UNUSED(selected); + Q_UNUSED(selected) } void KItemListWidget::hoveredChanged(bool hovered) { - Q_UNUSED(hovered); + Q_UNUSED(hovered) } void KItemListWidget::alternateBackgroundChanged(bool enabled) { - Q_UNUSED(enabled); + Q_UNUSED(enabled) } void KItemListWidget::siblingsInformationChanged(const QBitArray& current, const QBitArray& previous) { - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(current) + Q_UNUSED(previous) } void KItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous) { - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(current) + Q_UNUSED(previous) } void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) @@ -465,11 +467,29 @@ void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) } } +void KItemListWidget::hoverSequenceStarted() +{ +} + +void KItemListWidget::hoverSequenceIndexChanged(int sequenceIndex) +{ + Q_UNUSED(sequenceIndex); +} + +void KItemListWidget::hoverSequenceEnded() +{ +} + qreal KItemListWidget::hoverOpacity() const { return m_hoverOpacity; } +int KItemListWidget::hoverSequenceIndex() const +{ + return m_hoverSequenceIndex; +} + void KItemListWidget::slotHoverAnimationFinished() { if (!m_hovered && m_selectionToggle) { @@ -478,6 +498,12 @@ void KItemListWidget::slotHoverAnimationFinished() } } +void KItemListWidget::slotHoverSequenceTimerTimeout() +{ + m_hoverSequenceIndex++; + hoverSequenceIndexChanged(m_hoverSequenceIndex); +} + void KItemListWidget::initializeSelectionToggle() { Q_ASSERT(m_enabledSelectionToggle); @@ -517,11 +543,11 @@ void KItemListWidget::clearHoverCache() void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QStyle::State styleState) { QStyleOptionViewItem viewItemOption; - viewItemOption.initFrom(widget); + initStyleOption(&viewItemOption); viewItemOption.state = styleState; viewItemOption.viewItemPosition = QStyleOptionViewItem::OnlyOne; viewItemOption.showDecorationSelected = true; viewItemOption.rect = selectionRect().toRect(); - widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); + style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); }