]>
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 ***************************************************************************/
22 #include <QVBoxLayout>
25 #include <kiconloader.h>
28 #include "dolphinsettings.h"
29 #include "sidebarsettings.h"
30 #include "bookmarkssidebarpage.h"
31 #include "infosidebarpage.h"
33 Sidebar::Sidebar(DolphinMainWindow
* mainWindow
, QWidget
* parent
) :
35 m_mainWindow(mainWindow
),
40 m_layout
= new QVBoxLayout(this);
41 m_layout
->setMargin(0);
42 m_layout
->setSpacing(0);
44 m_pagesSelector
= new QComboBox(this);
45 m_pagesSelector
->insertItem(i18n("Information"));
46 m_pagesSelector
->insertItem(i18n("Bookmarks"));
48 // Assure that the combo box has the same height as the Url navigator for
50 // TODO: the following 2 lines have been copied from the UrlNavigator
51 // constructor (-> provide a shared height setting?)
52 QFontMetrics
fontMetrics(font());
53 m_pagesSelector
->setMinimumHeight(fontMetrics
.height() + 8);
55 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
56 const int selectedIndex
= indexForName(settings
->selectedPage());
57 m_pagesSelector
->setCurrentItem(selectedIndex
);
58 m_layout
->addWidget(m_pagesSelector
);
60 createPage(selectedIndex
);
62 connect(m_pagesSelector
, SIGNAL(activated(int)),
63 this, SLOT(createPage(int)));
70 QSize
Sidebar::sizeHint() const
72 QSize
size(QWidget::sizeHint());
74 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
75 size
.setWidth(settings
->width());
79 void Sidebar::createPage(int index
)
82 m_page
->deleteLater();
87 case 0: m_page
= new InfoSidebarPage(m_mainWindow
, this); break;
88 case 1: m_page
= new BookmarksSidebarPage(m_mainWindow
, this); break;
92 m_layout
->addWidget(m_page
);
95 SidebarSettings
* settings
= DolphinSettings::instance().sidebarSettings();
96 settings
->setSelectedPage(m_pagesSelector
->text(index
));
99 int Sidebar::indexForName(const QString
& name
) const
101 const int count
= m_pagesSelector
->count();
102 for (int i
= 0; i
< count
; ++i
) {
103 if (m_pagesSelector
->text(i
) == name
) {
111 #include "sidebar.moc"