]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/private/kitemlistviewanimation.cpp
KFileItemListWidget: wrong selection when renamed file ends with a dot
[dolphin.git] / src / kitemviews / private / kitemlistviewanimation.cpp
index 336ba38adb702f4caaa8c46a24633e285c2df76c..763f770ff54630ae66c3b55226ad4a6def2843de 100644 (file)
@@ -1,42 +1,20 @@
-/***************************************************************************
- *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   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>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "kitemlistviewanimation.h"
+#include "kitemviews/kitemlistview.h"
 
-#include <kitemviews/kitemlistview.h>
-
-#include <KDebug>
-#include <KGlobalSettings>
-
-#include <QGraphicsWidget>
 #include <QPropertyAnimation>
 
-KItemListViewAnimation::KItemListViewAnimation(QObject* parent) :
-    QObject(parent),
-    m_animationDuration(200),
-    m_scrollOrientation(Qt::Vertical),
-    m_scrollOffset(0),
-    m_animation()
+KItemListViewAnimation::KItemListViewAnimation(QObject *parent)
+    : QObject(parent)
+    , m_scrollOrientation(Qt::Vertical)
+    , m_scrollOffset(0)
+    , m_animation()
 {
-    if (KGlobalSettings::graphicEffectsLevel() == KGlobalSettings::NoEffects) {
-        m_animationDuration = 1;
-    }
 }
 
 KItemListViewAnimation::~KItemListViewAnimation()
@@ -70,12 +48,12 @@ void KItemListViewAnimation::setScrollOffset(qreal offset)
             continue;
         }
 
-        QHashIterator<QGraphicsWidget*, QPropertyAnimation*>  it(m_animation[type]);
+        QHashIterator<QGraphicsWidget *, QPropertyAnimation *> it(m_animation[type]);
         while (it.hasNext()) {
             it.next();
 
-            QGraphicsWidgetwidget = it.key();
-            QPropertyAnimationpropertyAnim = it.value();
+            QGraphicsWidget *widget = it.key();
+            QPropertyAnimation *propertyAnim = it.value();
 
             QPointF currentPos = widget->pos();
             if (m_scrollOrientation == Qt::Vertical) {
@@ -87,8 +65,7 @@ void KItemListViewAnimation::setScrollOffset(qreal offset)
             if (type == MovingAnimation) {
                 // Stop the animation, calculate the moved start- and end-value
                 // and restart the animation for the remaining duration.
-                const int remainingDuration = propertyAnim->duration()
-                                              - propertyAnim->currentTime();
+                const int remainingDuration = propertyAnim->duration() - propertyAnim->currentTime();
 
                 const bool block = propertyAnim->signalsBlocked();
                 propertyAnim->blockSignals(true);
@@ -118,11 +95,12 @@ qreal KItemListViewAnimation::scrollOffset() const
     return m_scrollOffset;
 }
 
-void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue)
+void KItemListViewAnimation::start(QGraphicsWidget *widget, AnimationType type, const QVariant &endValue)
 {
     stop(widget, type);
 
-    QPropertyAnimation* propertyAnim = 0;
+    QPropertyAnimation *propertyAnim = nullptr;
+    const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animate) ? 200 : 1;
 
     switch (type) {
     case MovingAnimation: {
@@ -132,7 +110,7 @@ void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type,
         }
 
         propertyAnim = new QPropertyAnimation(widget, "pos");
-        propertyAnim->setDuration(m_animationDuration);
+        propertyAnim->setDuration(animationDuration);
         propertyAnim->setEndValue(newPos);
         break;
     }
@@ -140,7 +118,7 @@ void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type,
     case CreateAnimation: {
         propertyAnim = new QPropertyAnimation(widget, "opacity");
         propertyAnim->setEasingCurve(QEasingCurve::InQuart);
-        propertyAnim->setDuration(m_animationDuration);
+        propertyAnim->setDuration(animationDuration);
         propertyAnim->setStartValue(0.0);
         propertyAnim->setEndValue(1.0);
         break;
@@ -149,7 +127,7 @@ void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type,
     case DeleteAnimation: {
         propertyAnim = new QPropertyAnimation(widget, "opacity");
         propertyAnim->setEasingCurve(QEasingCurve::OutQuart);
-        propertyAnim->setDuration(m_animationDuration);
+        propertyAnim->setDuration(animationDuration);
         propertyAnim->setStartValue(1.0);
         propertyAnim->setEndValue(0.0);
         break;
@@ -162,12 +140,20 @@ void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type,
         }
 
         propertyAnim = new QPropertyAnimation(widget, "size");
-        propertyAnim->setDuration(m_animationDuration);
+        propertyAnim->setDuration(animationDuration);
         propertyAnim->setEndValue(newSize);
         break;
     }
 
+    case IconResizeAnimation: {
+        propertyAnim = new QPropertyAnimation(widget, QByteArrayLiteral("iconSize"));
+        propertyAnim->setDuration(animationDuration);
+        propertyAnim->setEndValue(endValue);
+        break;
+    }
+
     default:
+        Q_UNREACHABLE();
         break;
     }
 
@@ -178,28 +164,35 @@ void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type,
     propertyAnim->start();
 }
 
-void KItemListViewAnimation::stop(QGraphicsWidgetwidget, AnimationType type)
+void KItemListViewAnimation::stop(QGraphicsWidget *widget, AnimationType type)
 {
-    QPropertyAnimationpropertyAnim = m_animation[type].value(widget);
+    QPropertyAnimation *propertyAnim = m_animation[type].value(widget);
     if (propertyAnim) {
         propertyAnim->stop();
 
         switch (type) {
-        case MovingAnimation: break;
-        case CreateAnimation: widget->setOpacity(1.0); break;
-        case DeleteAnimation: widget->setOpacity(0.0); break;
-        case ResizeAnimation: break;
-        default: break;
+        case MovingAnimation:
+            break;
+        case CreateAnimation:
+            widget->setOpacity(1.0);
+            break;
+        case DeleteAnimation:
+            widget->setOpacity(0.0);
+            break;
+        case ResizeAnimation:
+            break;
+        default:
+            break;
         }
 
         m_animation[type].remove(widget);
         delete propertyAnim;
 
-        emit finished(widget, type);
+        Q_EMIT finished(widget, type);
     }
 }
 
-void KItemListViewAnimation::stop(QGraphicsWidgetwidget)
+void KItemListViewAnimation::stop(QGraphicsWidget *widget)
 {
     for (int type = 0; type < AnimationTypeCount; ++type) {
         stop(widget, static_cast<AnimationType>(type));
@@ -211,7 +204,7 @@ bool KItemListViewAnimation::isStarted(QGraphicsWidget *widget, AnimationType ty
     return m_animation[type].value(widget);
 }
 
-bool KItemListViewAnimation::isStarted(QGraphicsWidgetwidget) const
+bool KItemListViewAnimation::isStarted(QGraphicsWidget *widget) const
 {
     for (int type = 0; type < AnimationTypeCount; ++type) {
         if (isStarted(widget, static_cast<AnimationType>(type))) {
@@ -223,18 +216,18 @@ bool KItemListViewAnimation::isStarted(QGraphicsWidget* widget) const
 
 void KItemListViewAnimation::slotFinished()
 {
-    QPropertyAnimation* finishedAnim = qobject_cast<QPropertyAnimation*>(sender());
+    QPropertyAnimation *finishedAnim = qobject_cast<QPropertyAnimation *>(sender());
     for (int type = 0; type < AnimationTypeCount; ++type) {
-        QMutableHashIterator<QGraphicsWidget*, QPropertyAnimation*> it(m_animation[type]);
+        QMutableHashIterator<QGraphicsWidget *, QPropertyAnimation *> it(m_animation[type]);
         while (it.hasNext()) {
             it.next();
-            QPropertyAnimationpropertyAnim = it.value();
+            QPropertyAnimation *propertyAnim = it.value();
             if (propertyAnim == finishedAnim) {
-                QGraphicsWidgetwidget = it.key();
+                QGraphicsWidget *widget = it.key();
                 it.remove();
                 finishedAnim->deleteLater();
 
-                emit finished(widget, static_cast<AnimationType>(type));
+                Q_EMIT finished(widget, static_cast<AnimationType>(type));
                 return;
             }
         }
@@ -242,3 +235,4 @@ void KItemListViewAnimation::slotFinished()
     Q_ASSERT(false);
 }
 
+#include "moc_kitemlistviewanimation.cpp"