]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistwidget.cpp
Fix paste on row while in details view mode
[dolphin.git] / src / kitemviews / kitemlistwidget.cpp
index c33335ae635412994f3aab44af3dbfc8c985222e..5541aa9f89f811658004c67d9a4f48c97730d9d5 100644 (file)
@@ -1,30 +1,19 @@
-/***************************************************************************
- *   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 "kitemlistwidget.h"
 
 #include "kitemlistview.h"
 #include "private/kitemlistselectiontoggle.h"
 
+#include <KConfigGroup>
+#include <KSharedConfig>
+
 #include <QApplication>
 #include <QPainter>
 #include <QPropertyAnimation>
@@ -39,12 +28,13 @@ KItemListWidgetInformant::~KItemListWidgetInformant()
 }
 
 KItemListWidget::KItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
-    QGraphicsWidget(parent, nullptr),
+    QGraphicsWidget(parent),
     m_informant(informant),
     m_index(-1),
     m_selected(false),
     m_current(false),
     m_hovered(false),
+    m_expansionAreaHovered(false),
     m_alternateBackground(false),
     m_enabledSelectionToggle(false),
     m_data(),
@@ -55,9 +45,12 @@ KItemListWidget::KItemListWidget(KItemListWidgetInformant* informant, QGraphicsI
     m_hoverOpacity(0),
     m_hoverCache(nullptr),
     m_hoverAnimation(nullptr),
+    m_hoverSequenceIndex(0),
     m_selectionToggle(nullptr),
-    m_editedRole()
+    m_editedRole(),
+    m_iconSize(-1)
 {
+    connect(&m_hoverSequenceTimer, &QTimer::timeout, this, &KItemListWidget::slotHoverSequenceTimerTimeout);
 }
 
 KItemListWidget::~KItemListWidget()
@@ -94,7 +87,7 @@ void KItemListWidget::setData(const QHash<QByteArray, QVariant>& 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);
@@ -189,6 +182,18 @@ qreal KItemListWidget::columnWidth(const QByteArray& role) const
     return m_columnWidths.value(role);
 }
 
+qreal KItemListWidget::sidePadding() const {
+    return m_sidePadding;
+}
+
+void KItemListWidget::setSidePadding(qreal width) {
+    if (m_sidePadding != width){
+        m_sidePadding = width;
+        sidePaddingChanged(width);
+        update();
+    }
+}
+
 void KItemListWidget::setStyleOption(const KItemListStyleOption& option)
 {
     if (m_styleOption == option) {
@@ -254,6 +259,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 +268,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();
@@ -277,6 +294,20 @@ bool KItemListWidget::isHovered() const
     return m_hovered;
 }
 
+void KItemListWidget::setExpansionAreaHovered(bool hovered)
+{
+    if (hovered == m_expansionAreaHovered) {
+        return;
+    }
+    m_expansionAreaHovered = hovered;
+    update();
+}
+
+bool KItemListWidget::expansionAreaHovered() const
+{
+    return m_expansionAreaHovered;
+}
+
 void KItemListWidget::setHoverPosition(const QPointF& pos)
 {
     if (m_selectionToggle) {
@@ -338,6 +369,20 @@ QByteArray KItemListWidget::editedRole() const
     return m_editedRole;
 }
 
+void KItemListWidget::setIconSize(int iconSize)
+{
+    if (m_iconSize != iconSize) {
+        const int previousIconSize = m_iconSize;
+        m_iconSize = iconSize;
+        iconSizeChanged(iconSize, previousIconSize);
+    }
+}
+
+int KItemListWidget::iconSize() const
+{
+    return m_iconSize;
+}
+
 bool KItemListWidget::contains(const QPointF& point) const
 {
     if (!QGraphicsWidget::contains(point)) {
@@ -379,7 +424,6 @@ QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option
     const bool wasHovered = m_hovered;
 
     setAlternateBackground(false);
-    setSelected(false);
     setHovered(false);
 
     paint(&painter, option, widget);
@@ -414,11 +458,20 @@ void KItemListWidget::columnWidthChanged(const QByteArray& role,
     Q_UNUSED(previous)
 }
 
+void KItemListWidget::sidePaddingChanged(qreal width)
+{
+    Q_UNUSED(width)
+}
+
 void KItemListWidget::styleOptionChanged(const KItemListStyleOption& current,
                                          const KItemListStyleOption& previous)
 {
-    Q_UNUSED(current)
     Q_UNUSED(previous)
+
+    // set the initial value of m_iconSize if not set
+    if (m_iconSize == -1) {
+        m_iconSize = current.iconSize;
+    }
 }
 
 void KItemListWidget::currentChanged(bool current)
@@ -453,6 +506,12 @@ void KItemListWidget::editedRoleChanged(const QByteArray& current, const QByteAr
     Q_UNUSED(previous)
 }
 
+void KItemListWidget::iconSizeChanged(int current, int previous)
+{
+    Q_UNUSED(current)
+    Q_UNUSED(previous)
+}
+
 void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
 {
     QGraphicsWidget::resizeEvent(event);
@@ -465,11 +524,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 +555,12 @@ void KItemListWidget::slotHoverAnimationFinished()
     }
 }
 
+void KItemListWidget::slotHoverSequenceTimerTimeout()
+{
+    m_hoverSequenceIndex++;
+    hoverSequenceIndexChanged(m_hoverSequenceIndex);
+}
+
 void KItemListWidget::initializeSelectionToggle()
 {
     Q_ASSERT(m_enabledSelectionToggle);