make PlaylistModel observe albums for changes to the cover image (needed for services...
[amarok.git] / src / sidebar.h
blob9e1d7b88dfa5120587f05092c333edc2022bc5bc
1 /*
2 Copyright (c) 2006 Gábor Lehel <illissius@gmail.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef AMAROK_SIDEBAR_H
21 #define AMAROK_SIDEBAR_H
23 #include "sidebarwidget.h"
25 #include <KHBox>
27 #include <QIcon>
28 #include <QFrame>
29 #include <QStackedWidget>
32 class SideBar: public KHBox
34 typedef KHBox super;
35 Q_OBJECT
37 signals:
38 void widgetActivated( int index );
39 void widgetActivated( QWidget* );
41 public:
42 explicit SideBar( QWidget *parent, QWidget *contentsWidget = 0 )
43 : super( parent )
44 , m_bar( new SideBarWidget( this ) )
45 , m_frame( new KHBox( this ) )
46 , m_widgets( new QStackedWidget( m_frame ) )
47 , m_current( -1 )
49 connect( m_bar, SIGNAL( opened( int ) ), SLOT( openWidget( int ) ) );
50 connect( m_bar, SIGNAL( closed() ), SLOT( closeWidgets() ) );
51 m_frame->hide();
52 m_widgets->setParent( m_frame );
53 setContentsWidget( contentsWidget );
54 layout()->setContentsMargins( 0, 0, 0, 0 );
57 void setContentsWidget( QWidget *w )
59 m_contentsWidget = w;
60 if( w )
61 w->setParent( this );
63 SideBarWidget *sideBarWidget() const { return m_bar; }
65 QWidget *contentsWidget() const { return m_contentsWidget; }
67 int addWidget( const QIcon &icon, const QString &name, QWidget *widget )
69 m_widgets->addWidget( widget );
70 m_bar->addSideBar( icon, name );
71 return m_widgets->count() - 1;
74 void removeWidget( QWidget *widget )
76 m_widgets->removeWidget( widget );
80 QWidget *at( int index ) const { return m_widgets->widget( index ); }
82 int currentIndex() const { return m_current; }
84 QWidget *currentWidget() const
86 if( m_current >= 0 )
87 return at( m_current );
88 else
89 return 0;
92 public slots:
93 void showWidget( int index ) { m_bar->open( index ); }
95 private slots:
96 void openWidget( int index )
98 m_contentsWidget->setParent( m_frame );
99 m_frame->show();
100 m_widgets->setCurrentIndex( index );
101 m_current = index;
102 emit widgetActivated( currentIndex() );
103 emit widgetActivated( currentWidget() );
106 void closeWidgets()
108 m_contentsWidget->setParent( this );
109 m_frame->hide();
110 resize( m_bar->sizeHint() );
111 m_current = -1;
112 emit widgetActivated( currentIndex() );
113 emit widgetActivated( currentWidget() );
116 private:
117 SideBarWidget *m_bar;
118 KHBox *m_frame;
119 QStackedWidget *m_widgets;
120 QWidget *m_contentsWidget;
121 int m_current;
124 #endif