PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 19#ifndef ANIMATEDSPLITTER_H
 20#define ANIMATEDSPLITTER_H
 21
 22#include <QSplitter>
 23#include <QTimeLine>
 24
 25#include "DllMacro.h"
 26
 27class AnimatedWidget;
 28
 29class DLLEXPORT AnimatedSplitter : public QSplitter
 30{
 31Q_OBJECT
 32
 33public:
 34    explicit AnimatedSplitter( QWidget* parent = 0 );
 35
 36    void show( int index, bool animate = true );
 37    void hide( int index, bool animate = true );
 38
 39    void setGreedyWidget( int index );
 40
 41    void addWidget( QWidget* widget );
 42    void addWidget( AnimatedWidget* widget );
 43
 44signals:
 45    void shown( QWidget*, bool animated );
 46    void hidden( QWidget*, bool animated );
 47
 48protected:
 49    virtual QSplitterHandle* createHandle();
 50
 51private slots:
 52    void changeSize( QWidget* child, const QSize& size );
 53    
 54    void onShowRequest();
 55    void onHideRequest();
 56
 57    void onSizeChanged( const QSize& size );
 58    void onResizeRequest( const QPoint& delta );
 59    
 60private:
 61    int m_greedyIndex;
 62};
 63
 64
 65class DLLEXPORT AnimatedSplitterHandle : public QSplitterHandle
 66{
 67Q_OBJECT
 68public:
 69    explicit AnimatedSplitterHandle( Qt::Orientation orientation, QSplitter* parent )
 70        : QSplitterHandle( orientation, parent )
 71        , m_indexInSplitter( -1 )
 72        , m_lastCount( -1 )
 73    {
 74        setCursor( Qt::ArrowCursor );
 75    }
 76
 77    virtual QSize sizeHint() const;
 78
 79private:
 80    mutable int m_indexInSplitter;
 81    mutable int m_lastCount;
 82};
 83
 84
 85class DLLEXPORT AnimatedWidget : public QWidget
 86{
 87Q_OBJECT
 88public:
 89    explicit AnimatedWidget( AnimatedSplitter* parent );
 90    virtual ~AnimatedWidget();
 91
 92    QSize hiddenSize() const { return m_hiddenSize; }
 93    void setHiddenSize( const QSize& size ) { m_hiddenSize = size; emit hiddenSizeChanged(); }
 94
 95    bool isHidden() const { return m_isHidden; }
 96
 97public slots:
 98    virtual void onShown( QWidget*, bool animated );
 99    virtual void onHidden( QWidget*, bool animated );
100
101    virtual void hide() { emit hideWidget(); }
102    virtual void show() { emit showWidget(); }
103
104signals:
105    void showWidget();
106    void hideWidget();
107    
108    void animationFinished();
109
110    void resizeBy( const QPoint& delta );
111    void sizeChanged( const QSize& size );
112    void sizeHintChanged( const QSize& size );
113    void hiddenSizeChanged();
114
115private slots:
116    void onAnimationStep( int frame );
117    void onAnimationFinished();
118
119protected:
120    AnimatedSplitter* splitter() { return m_parent; }
121
122private:
123    AnimatedSplitter* m_parent;
124    bool m_animateForward;
125    QSize m_hiddenSize;
126    bool m_isHidden;
127    QTimeLine* m_timeLine;
128};
129
130#endif //ANIMATEDSPLITTER_H