Make plasma libs build.
[amarok.git] / src / Sidebar.h
blob0ade734280716f1dd38744f0cf87ffe1aa5edeef
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 "widgets/SidebarWidget.h"
25 #include <KHBox>
27 #include <QIcon>
28 #include <QFrame>
29 #include <QLayout>
30 #include <QStackedWidget>
33 class SideBar: public KHBox
35 typedef KHBox super;
36 Q_OBJECT
38 signals:
39 void widgetActivated( int index );
40 void widgetActivated( QWidget* );
42 public:
43 explicit SideBar( QWidget *parent, QWidget *contentsWidget = 0 )
44 : super( parent )
45 , m_bar( new SideBarWidget( this ) )
46 , m_frame( new KHBox( this ) )
47 , m_widgets( new QStackedWidget( m_frame ) )
48 , m_current( -1 )
50 connect( m_bar, SIGNAL( opened( int ) ), SLOT( openWidget( int ) ) );
51 connect( m_bar, SIGNAL( closed() ), SLOT( closeWidgets() ) );
52 m_frame->hide();
53 m_widgets->setParent( m_frame );
54 setContentsWidget( contentsWidget );
55 layout()->setContentsMargins( 0, 0, 0, 0 );
58 ~SideBar() {}
60 void deleteBrowsers()
62 QWidget * widget = m_widgets->widget( 0 );
63 while( widget )
65 m_widgets->removeWidget( widget );
66 delete widget;
67 widget = m_widgets->widget( 0 );
71 void setContentsWidget( QWidget *w )
73 m_contentsWidget = w;
74 if( w )
75 w->setParent( this );
77 SideBarWidget *sideBarWidget() const { return m_bar; }
79 QWidget *contentsWidget() const { return m_contentsWidget; }
81 int addWidget( const QIcon &icon, const QString &name, QWidget *widget )
83 m_widgets->addWidget( widget );
84 m_bar->addSideBar( icon, name );
85 return m_widgets->count() - 1;
88 void removeWidget( QWidget *widget )
90 m_widgets->removeWidget( widget );
94 QWidget *at( int index ) const { return m_widgets->widget( index ); }
96 int currentIndex() const { return m_current; }
98 QWidget *currentWidget() const
100 if( m_current >= 0 )
101 return at( m_current );
102 else
103 return 0;
106 public slots:
107 void showWidget( int index ) { m_bar->open( index ); }
109 private slots:
110 void openWidget( int index )
112 m_contentsWidget->setParent( m_frame );
113 m_frame->show();
114 m_widgets->setCurrentIndex( index );
115 m_current = index;
116 emit widgetActivated( currentIndex() );
117 emit widgetActivated( currentWidget() );
120 void closeWidgets()
122 m_contentsWidget->setParent( this );
123 m_frame->hide();
124 resize( m_bar->sizeHint() );
125 m_current = -1;
126 emit widgetActivated( currentIndex() );
127 emit widgetActivated( currentWidget() );
130 private:
131 SideBarWidget *m_bar;
132 KHBox *m_frame;
133 QStackedWidget *m_widgets;
134 QWidget *m_contentsWidget;
135 int m_current;
138 #endif