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"
29 #include <QStackedWidget>
32 class SideBar
: public KHBox
38 void widgetActivated( int index
);
39 void widgetActivated( QWidget
* );
42 explicit SideBar( QWidget
*parent
, QWidget
*contentsWidget
= 0 )
44 , m_bar( new SideBarWidget( this ) )
45 , m_frame( new KHBox( this ) )
46 , m_widgets( new QStackedWidget( m_frame
) )
49 connect( m_bar
, SIGNAL( opened( int ) ), SLOT( openWidget( int ) ) );
50 connect( m_bar
, SIGNAL( closed() ), SLOT( closeWidgets() ) );
52 m_widgets
->setParent( m_frame
);
53 setContentsWidget( contentsWidget
);
54 layout()->setContentsMargins( 0, 0, 0, 0 );
57 void setContentsWidget( QWidget
*w
)
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
87 return at( m_current
);
93 void showWidget( int index
) { m_bar
->open( index
); }
96 void openWidget( int index
)
98 m_contentsWidget
->setParent( m_frame
);
100 m_widgets
->setCurrentIndex( index
);
102 emit
widgetActivated( currentIndex() );
103 emit
widgetActivated( currentWidget() );
108 m_contentsWidget
->setParent( this );
110 resize( m_bar
->sizeHint() );
112 emit
widgetActivated( currentIndex() );
113 emit
widgetActivated( currentWidget() );
117 SideBarWidget
*m_bar
;
119 QStackedWidget
*m_widgets
;
120 QWidget
*m_contentsWidget
;