add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / Sidebar.h
blobcd1dce4b42a9f026420aea6a0e227019653eb1a7
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 int count = m_widgets->count();
63 QWidget * widget = m_widgets->widget( 0 );
64 while( widget )
66 m_widgets->removeWidget( widget );
67 delete widget;
68 widget = m_widgets->widget( 0 );
72 void setContentsWidget( QWidget *w )
74 m_contentsWidget = w;
75 if( w )
76 w->setParent( this );
78 SideBarWidget *sideBarWidget() const { return m_bar; }
80 QWidget *contentsWidget() const { return m_contentsWidget; }
82 int addWidget( const QIcon &icon, const QString &name, QWidget *widget )
84 m_widgets->addWidget( widget );
85 m_bar->addSideBar( icon, name );
86 return m_widgets->count() - 1;
89 void removeWidget( QWidget *widget )
91 m_widgets->removeWidget( widget );
95 QWidget *at( int index ) const { return m_widgets->widget( index ); }
97 int currentIndex() const { return m_current; }
99 QWidget *currentWidget() const
101 if( m_current >= 0 )
102 return at( m_current );
103 else
104 return 0;
107 public slots:
108 void showWidget( int index ) { m_bar->open( index ); }
110 private slots:
111 void openWidget( int index )
113 m_contentsWidget->setParent( m_frame );
114 m_frame->show();
115 m_widgets->setCurrentIndex( index );
116 m_current = index;
117 emit widgetActivated( currentIndex() );
118 emit widgetActivated( currentWidget() );
121 void closeWidgets()
123 m_contentsWidget->setParent( this );
124 m_frame->hide();
125 resize( m_bar->sizeHint() );
126 m_current = -1;
127 emit widgetActivated( currentIndex() );
128 emit widgetActivated( currentWidget() );
131 private:
132 SideBarWidget *m_bar;
133 KHBox *m_frame;
134 QStackedWidget *m_widgets;
135 QWidget *m_contentsWidget;
136 int m_current;
139 #endif