• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

delegateanimationhandler_p.h

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE project
00003 
00004    Copyright © 2007 Fredrik Höglund <fredrik@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef DELEGATEANIMATIONHANDLER_P_H
00023 #define DELEGATEANIMATIONHANDLER_P_H
00024 
00025 #include <QBasicTimer>
00026 #include <QMap>
00027 #include <QLinkedList>
00028 #include <QPersistentModelIndex>
00029 #include <QStyle>
00030 #include <QTimeLine>
00031 #include <QTime>
00032 #include <QTimer>
00033 
00034 
00035 class QAbstractItemView;
00036 
00037 namespace KIO
00038 {
00039 
00040 class CachedRendering : public QObject
00041 {
00042     Q_OBJECT
00043 public:
00044     
00045     CachedRendering(QStyle::State state, const QSize &size, QModelIndex validityIndex);
00046     bool checkValidity(QStyle::State current) const { return state == current && valid; }
00047 
00048     QStyle::State state;
00049     QPixmap regular;
00050     QPixmap hover;
00051     
00052     bool valid;
00053     QPersistentModelIndex validityIndex;
00054 private Q_SLOTS:
00055     void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
00056     void modelReset();
00057 };
00058 
00059 
00060 class AnimationState
00061 {
00062 public:
00063     ~AnimationState();
00064     //Progress of the mouse hovering animation
00065     qreal hoverProgress() const;
00066     //Progress of the icon fading animation
00067     qreal fadeProgress() const;
00068     //Angle of the painter, to paint the animation for a file job on an item
00069     qreal jobAnimationAngle() const;
00070 
00071     void setJobAnimation(bool value);
00072     bool hasJobAnimation() const;
00073 
00074     CachedRendering *cachedRendering() const { return renderCache; }
00075     //The previous render-cache is deleted, if there was one
00076     void setCachedRendering(CachedRendering *rendering) { delete renderCache; renderCache = rendering; }
00077 
00078     //Returns current cached rendering, and removes it from this state.
00079     //The caller has the ownership.
00080     CachedRendering *takeCachedRendering() { CachedRendering* ret = renderCache; renderCache = 0; return ret; }
00081 
00082     CachedRendering* cachedRenderingFadeFrom() const { return fadeFromRenderCache; }
00083     //The previous render-cache is deleted, if there was one
00084     void setCachedRenderingFadeFrom(CachedRendering* rendering) { delete fadeFromRenderCache; fadeFromRenderCache = rendering; if(rendering) m_fadeProgress = 0; else m_fadeProgress = 1; }
00085 
00086 private:
00087     AnimationState(const QModelIndex &index);
00088     bool update();
00089 
00090     QPersistentModelIndex index;
00091     QTimeLine::Direction direction;
00092     bool animating;
00093     bool jobAnimation;
00094     qreal progress;
00095     qreal m_fadeProgress;
00096     qreal m_jobAnimationAngle;
00097     QTime time;
00098     QTime creationTime;
00099     CachedRendering *renderCache;
00100     CachedRendering *fadeFromRenderCache;
00101 
00102     friend class DelegateAnimationHandler;
00103 };
00104 
00105 
00106 class DelegateAnimationHandler : public QObject
00107 {
00108     Q_OBJECT
00109 
00110     typedef QLinkedList<AnimationState*> AnimationList;
00111     typedef QMapIterator<const QAbstractItemView *, AnimationList*> AnimationListsIterator;
00112     typedef QMutableMapIterator<const QAbstractItemView *, AnimationList*> MutableAnimationListsIterator;
00113 
00114 public:
00115     DelegateAnimationHandler(QObject *parent = 0);
00116     ~DelegateAnimationHandler();
00117 
00118     AnimationState *animationState(const QStyleOption &option, const QModelIndex &index, const QAbstractItemView *view);
00119 
00120     void restartAnimation(AnimationState* state);
00121 
00122     void gotNewIcon(const QModelIndex& index);
00123 
00124 private slots:
00125     void viewDeleted(QObject *view);
00126     void sequenceTimerTimeout();
00127 
00128 private:
00129     void eventuallyStartIteration(QModelIndex index);
00130     AnimationState *findAnimationState(const QAbstractItemView *view, const QModelIndex &index) const;
00131     void addAnimationState(AnimationState *state, const QAbstractItemView *view);
00132     void startAnimation(AnimationState *state);
00133     int runAnimations(AnimationList *list, const QAbstractItemView *view);
00134     void timerEvent(QTimerEvent *event);
00135     void setSequenceIndex(int arg1);
00136 
00137 private:
00138     QMap<const QAbstractItemView*, AnimationList*> animationLists;
00139     QTime fadeInAddTime;
00140     QBasicTimer timer;
00141     //Icon sequence handling:
00142     QPersistentModelIndex sequenceModelIndex;
00143     QTimer iconSequenceTimer;
00144     int currentSequenceIndex;
00145 };
00146 
00147 }
00148 
00149 #endif

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal