/src/sourcetree/animationhelper.h

http://github.com/tomahawk-player/tomahawk · C Header · 76 lines · 42 code · 16 blank · 18 comment · 0 complexity · 88b5d3649ef8ad523d4c7873ec0d1ab9 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2011, Michael Zanetti <mzanetti@kde.org>
  5. *
  6. * Tomahawk is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Tomahawk is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANIMATIONHELPER_H
  20. #define ANIMATIONHELPER_H
  21. #include <QObject>
  22. #include <QModelIndex>
  23. #include <QSize>
  24. #include <QTimer>
  25. #include <QPropertyAnimation>
  26. class AnimationHelper: public QObject
  27. {
  28. Q_OBJECT
  29. Q_PROPERTY( QSize size READ size WRITE setSize NOTIFY sizeChanged )
  30. public:
  31. AnimationHelper( const QModelIndex& index, QObject *parent = 0 );
  32. QSize originalSize() const;
  33. QSize size() const;
  34. bool initialized() const;
  35. void initialize( const QSize& startValue, const QSize& endValue, int duration );
  36. void setSize( const QSize& size );
  37. void expand();
  38. void collapse( bool immediately = false );
  39. bool partlyExpanded();
  40. bool fullyExpanded();
  41. signals:
  42. void sizeChanged();
  43. void finished( const QModelIndex& index);
  44. private slots:
  45. void expandTimeout();
  46. void collapseTimeout();
  47. void expandAnimationFinished();
  48. void collapseAnimationFinished();
  49. private:
  50. QModelIndex m_index;
  51. QSize m_size;
  52. QSize m_targetSize;
  53. QSize m_startSize;
  54. QTimer m_expandTimer;
  55. QTimer m_collapseTimer;
  56. bool m_fullyExpanded;
  57. QPropertyAnimation *m_expandAnimation;
  58. QPropertyAnimation *m_collapseAnimation;
  59. };
  60. #endif // ANIMATIONHELPER_H