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"
30 #include <QStackedWidget>
33 class SideBar
: public KHBox
39 void widgetActivated( int index
);
40 void widgetActivated( QWidget
* );
43 explicit SideBar( QWidget
*parent
, QWidget
*contentsWidget
= 0 )
45 , m_bar( new SideBarWidget( this ) )
46 , m_frame( new KHBox( this ) )
47 , m_widgets( new QStackedWidget( m_frame
) )
50 connect( m_bar
, SIGNAL( opened( int ) ), SLOT( openWidget( int ) ) );
51 connect( m_bar
, SIGNAL( closed() ), SLOT( closeWidgets() ) );
53 m_widgets
->setParent( m_frame
);
54 setContentsWidget( contentsWidget
);
55 layout()->setContentsMargins( 0, 0, 0, 0 );
62 int count
= m_widgets
->count();
63 QWidget
* widget
= m_widgets
->widget( 0 );
66 m_widgets
->removeWidget( widget
);
68 widget
= m_widgets
->widget( 0 );
72 void setContentsWidget( QWidget
*w
)
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
102 return at( m_current
);
108 void showWidget( int index
) { m_bar
->open( index
); }
111 void openWidget( int index
)
113 m_contentsWidget
->setParent( m_frame
);
115 m_widgets
->setCurrentIndex( index
);
117 emit
widgetActivated( currentIndex() );
118 emit
widgetActivated( currentWidget() );
123 m_contentsWidget
->setParent( this );
125 resize( m_bar
->sizeHint() );
127 emit
widgetActivated( currentIndex() );
128 emit
widgetActivated( currentWidget() );
132 SideBarWidget
*m_bar
;
134 QStackedWidget
*m_widgets
;
135 QWidget
*m_contentsWidget
;