]> cloud.milkyroute.net Git - dolphin.git/blob - src/sidebar.cpp
commited initial version of Dolphin
[dolphin.git] / src / sidebar.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "sidebar.h"
21
22 #include <qlayout.h>
23 #include <qpixmap.h>
24 //Added by qt3to4:
25 #include <Q3VBoxLayout>
26 #include <kiconloader.h>
27 #include <klocale.h>
28 #include <qcombobox.h>
29
30 #include "dolphinsettings.h"
31 #include "sidebarsettings.h"
32 #include "bookmarkssidebarpage.h"
33 #include "infosidebarpage.h"
34
35 #include <assert.h>
36
37 Sidebar::Sidebar(QWidget* parent) :
38 QWidget(parent),
39 m_pagesSelector(0),
40 m_page(0),
41 m_layout(0)
42 {
43 m_layout = new Q3VBoxLayout(this);
44
45 m_pagesSelector = new QComboBox(this);
46 m_pagesSelector->insertItem(i18n("Information"));
47 m_pagesSelector->insertItem(i18n("Bookmarks"));
48
49 // Assure that the combo box has the same height as the URL navigator for
50 // a clean layout.
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);
55
56 SidebarSettings* settings = DolphinSettings::instance().sidebarSettings();
57 const int selectedIndex = indexForName(settings->selectedPage());
58 m_pagesSelector->setCurrentItem(selectedIndex);
59 m_layout->addWidget(m_pagesSelector);
60
61 createPage(selectedIndex);
62
63 connect(m_pagesSelector, SIGNAL(activated(int)),
64 this, SLOT(createPage(int)));
65 }
66
67 Sidebar::~Sidebar()
68 {
69 }
70
71 QSize Sidebar::sizeHint() const
72 {
73 QSize size(QWidget::sizeHint());
74
75 SidebarSettings* settings = DolphinSettings::instance().sidebarSettings();
76 size.setWidth(settings->width());
77 return size;
78 }
79
80 void Sidebar::createPage(int index)
81 {
82 if (m_page != 0) {
83 m_page->deleteLater();
84 m_page = 0;
85 }
86
87 switch (index) {
88 case 0: m_page = new InfoSidebarPage(this); break;
89 case 1: m_page = new BookmarksSidebarPage(this); break;
90 default: break;
91 }
92
93 m_layout->addWidget(m_page);
94 m_page->show();
95
96 SidebarSettings* settings = DolphinSettings::instance().sidebarSettings();
97 settings->setSelectedPage(m_pagesSelector->text(index));
98 }
99
100 int Sidebar::indexForName(const QString& name) const
101 {
102 const int count = m_pagesSelector->count();
103 for (int i = 0; i < count; ++i) {
104 if (m_pagesSelector->text(i) == name) {
105 return i;
106 }
107 }
108
109 return 0;
110 }