]>
cloud.milkyroute.net Git - dolphin.git/blob - src/sidebar.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program 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 *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
25 #include <Q3VBoxLayout>
26 #include <kiconloader.h>
28 #include <qcombobox.h>
30 #include "dolphinsettings.h"
31 #include "sidebarsettings.h"
32 #include "bookmarkssidebarpage.h"
33 #include "infosidebarpage.h"
37 Sidebar::Sidebar(QWidget
* parent
) :
43 m_layout
= new Q3VBoxLayout(this);
45 m_pagesSelector
= new QComboBox(this);
46 m_pagesSelector
->insertItem(i18n("Information"));
47 m_pagesSelector
->insertItem(i18n("Bookmarks"));
49 // Assure that the combo box has the same height as the URL navigator for
51 // TODO: the following 2 lines have been copied from the URLNavigator
52 // constructor (-> provide a shared height setting?)
53 QFontMetrics
fontMetrics(font());
54 m_pagesSelector
->setMinimumHeight(fontMetrics
.height() + 8);
56 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
57 const int selectedIndex
= indexForName(settings
->selectedPage());
58 m_pagesSelector
->setCurrentItem(selectedIndex
);
59 m_layout
->addWidget(m_pagesSelector
);
61 createPage(selectedIndex
);
63 connect(m_pagesSelector
, SIGNAL(activated(int)),
64 this, SLOT(createPage(int)));
71 QSize
Sidebar::sizeHint() const
73 QSize
size(QWidget::sizeHint());
75 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
76 size
.setWidth(settings
->width());
80 void Sidebar::createPage(int index
)
83 m_page
->deleteLater();
88 case 0: m_page
= new InfoSidebarPage(this); break;
89 case 1: m_page
= new BookmarksSidebarPage(this); break;
93 m_layout
->addWidget(m_page
);
96 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
97 settings
->setSelectedPage(m_pagesSelector
->text(index
));
100 int Sidebar::indexForName(const QString
& name
) const
102 const int count
= m_pagesSelector
->count();
103 for (int i
= 0; i
< count
; ++i
) {
104 if (m_pagesSelector
->text(i
) == name
) {