/src/libtomahawk/widgets/AnimatedSplitter.h

http://github.com/tomahawk-player/tomahawk · C Header · 130 lines · 81 code · 32 blank · 17 comment · 0 complexity · 63ddcb5540adbed05657d7f53c9646b4 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. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ANIMATEDSPLITTER_H
  19. #define ANIMATEDSPLITTER_H
  20. #include <QSplitter>
  21. #include <QTimeLine>
  22. #include "DllMacro.h"
  23. class AnimatedWidget;
  24. class DLLEXPORT AnimatedSplitter : public QSplitter
  25. {
  26. Q_OBJECT
  27. public:
  28. explicit AnimatedSplitter( QWidget* parent = 0 );
  29. void show( int index, bool animate = true );
  30. void hide( int index, bool animate = true );
  31. void setGreedyWidget( int index );
  32. void addWidget( QWidget* widget );
  33. void addWidget( AnimatedWidget* widget );
  34. signals:
  35. void shown( QWidget*, bool animated );
  36. void hidden( QWidget*, bool animated );
  37. protected:
  38. virtual QSplitterHandle* createHandle();
  39. private slots:
  40. void changeSize( QWidget* child, const QSize& size );
  41. void onShowRequest();
  42. void onHideRequest();
  43. void onSizeChanged( const QSize& size );
  44. void onResizeRequest( const QPoint& delta );
  45. private:
  46. int m_greedyIndex;
  47. };
  48. class DLLEXPORT AnimatedSplitterHandle : public QSplitterHandle
  49. {
  50. Q_OBJECT
  51. public:
  52. explicit AnimatedSplitterHandle( Qt::Orientation orientation, QSplitter* parent )
  53. : QSplitterHandle( orientation, parent )
  54. , m_indexInSplitter( -1 )
  55. , m_lastCount( -1 )
  56. {
  57. setCursor( Qt::ArrowCursor );
  58. }
  59. virtual QSize sizeHint() const;
  60. private:
  61. mutable int m_indexInSplitter;
  62. mutable int m_lastCount;
  63. };
  64. class DLLEXPORT AnimatedWidget : public QWidget
  65. {
  66. Q_OBJECT
  67. public:
  68. explicit AnimatedWidget( AnimatedSplitter* parent );
  69. virtual ~AnimatedWidget();
  70. QSize hiddenSize() const { return m_hiddenSize; }
  71. void setHiddenSize( const QSize& size ) { m_hiddenSize = size; emit hiddenSizeChanged(); }
  72. bool isHidden() const { return m_isHidden; }
  73. public slots:
  74. virtual void onShown( QWidget*, bool animated );
  75. virtual void onHidden( QWidget*, bool animated );
  76. virtual void hide() { emit hideWidget(); }
  77. virtual void show() { emit showWidget(); }
  78. signals:
  79. void showWidget();
  80. void hideWidget();
  81. void animationFinished();
  82. void resizeBy( const QPoint& delta );
  83. void sizeChanged( const QSize& size );
  84. void sizeHintChanged( const QSize& size );
  85. void hiddenSizeChanged();
  86. private slots:
  87. void onAnimationStep( int frame );
  88. void onAnimationFinished();
  89. protected:
  90. AnimatedSplitter* splitter() { return m_parent; }
  91. private:
  92. AnimatedSplitter* m_parent;
  93. bool m_animateForward;
  94. QSize m_hiddenSize;
  95. bool m_isHidden;
  96. QTimeLine* m_timeLine;
  97. };
  98. #endif //ANIMATEDSPLITTER_H