From 182a330e250008177d05a5ef4ed0bd87226ee954 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 22 Apr 2009 01:18:22 +0200 Subject: Side Panel --- src/CMakeLists.txt | 2 ++ src/application.cpp | 41 ++++++++++++++------- src/application.h | 20 ++++++++--- src/bookmarks.cpp | 24 +++---------- src/mainwindow.cpp | 42 +++++++++++++++++++--- src/mainwindow.h | 19 +++++++--- src/panelhistory.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ src/panelhistory.h | 55 +++++++++++++++++++++++++++++ src/rekonq.kcfg | 3 ++ src/rekonqui.rc | 6 +++- src/settings_general.ui | 7 ++++ src/sidepanel.cpp | 54 ++++++++++++++++++++++++++++ src/sidepanel.h | 52 +++++++++++++++++++++++++++ 13 files changed, 371 insertions(+), 48 deletions(-) create mode 100644 src/panelhistory.cpp create mode 100644 src/panelhistory.h create mode 100644 src/sidepanel.cpp create mode 100644 src/sidepanel.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9f67c749..486a3992 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,8 @@ SET( rekonq_SRCS settings.cpp webview.cpp main.cpp + sidepanel.cpp + panelhistory.cpp ) KDE4_ADD_UI_FILES( rekonq_SRCS diff --git a/src/application.cpp b/src/application.cpp index 45641ea8..5b296333 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -48,28 +48,24 @@ #include -HistoryManager *Application::s_historyManager = 0; -NetworkAccessManager *Application::s_networkAccessManager = 0; -DownloadManager *Application::s_downloadManager = 0; -BookmarkProvider *Application::s_bookmarkProvider = 0; +QPointer Application::s_historyManager; +QPointer Application::s_networkAccessManager; +QPointer Application::s_downloadManager; +QPointer Application::s_bookmarkProvider; + Application::Application() - : KUniqueApplication() + : KUniqueApplication() + , m_mainWindow(0) { - m_mainWindow = new MainWindow(); - m_mainWindow->setObjectName("MainWindow"); - setWindowIcon(KIcon("rekonq")); - - m_mainWindow->show(); - - QTimer::singleShot(0, this, SLOT(postLaunch())); } Application::~Application() { - delete s_downloadManager; + delete m_mainWindow; + delete s_bookmarkProvider; delete s_networkAccessManager; delete s_historyManager; } @@ -80,6 +76,18 @@ int Application::newInstance() KCmdLineArgs::setCwd(QDir::currentPath().toUtf8()); KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); + if (!m_mainWindow) + { + m_mainWindow = new MainWindow(); + + m_mainWindow->setObjectName("MainWindow"); + setWindowIcon(KIcon("rekonq")); + + m_mainWindow->show(); + + QTimer::singleShot(0, this, SLOT(postLaunch())); + } + if (args->count() > 0) { for (int i = 0; i < args->count(); ++i) @@ -120,6 +128,13 @@ void Application::postLaunch() } + +void Application::slotSaveConfiguration() const +{ + ReKonfig::self()->writeConfig(); +} + + void Application::openUrl(const KUrl &url) { mainWindow()->loadUrl(url); diff --git a/src/application.h b/src/application.h index ee3d3112..5c0ee3cb 100644 --- a/src/application.h +++ b/src/application.h @@ -22,6 +22,8 @@ #ifndef APPLICATION_H #define APPLICATION_H +// Qt Includes +#include // KDE Includes #include @@ -69,6 +71,14 @@ public: static DownloadManager *downloadManager(); static BookmarkProvider *bookmarkProvider(); +public slots: + /** + * Save application's configuration + * @see ReKonfig::self()->writeConfig(); + */ + void slotSaveConfiguration() const; + + private slots: /** @@ -78,12 +88,12 @@ private slots: void openUrl(const KUrl &url); private: - static HistoryManager *s_historyManager; - static NetworkAccessManager *s_networkAccessManager; - static DownloadManager *s_downloadManager; - static BookmarkProvider *s_bookmarkProvider; + static QPointer s_historyManager; + static QPointer s_networkAccessManager; + static QPointer s_downloadManager; + static QPointer s_bookmarkProvider; - MainWindow* m_mainWindow; + QPointer m_mainWindow; }; #endif // APPLICATION_H diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp index fc69b88f..e6dbf1df 100644 --- a/src/bookmarks.cpp +++ b/src/bookmarks.cpp @@ -87,20 +87,6 @@ QString BookmarkOwner::currentTitle() const } -// QList< QPair > BookmarkOwner::currentBookmarkList() const -// { -// QList< QPair > list; -// QList tabs = Application::instance()->mainWindow()->mainView()->tabs(); -// foreach(WebView *tab, tabs) -// { -// QString url = tab->url().url(); -// QString title = tab->title(); -// list.append(QPair(url, title)); -// } -// return list; -// } - - // ------------------------------------------------------------------------------------------------------ @@ -149,12 +135,12 @@ void BookmarkMenu::slotAddBookmark() BookmarkProvider::BookmarkProvider(QWidget *parent) : QWidget(parent) - , m_manager(NULL) - , m_owner(NULL) + , m_manager(0) + , m_owner(0) , m_menu(new KMenu(this)) , m_actionCollection(new KActionCollection(this)) - , m_bookmarkMenu(NULL) - , m_bookmarkToolBar(NULL) + , m_bookmarkMenu(0) + , m_bookmarkToolBar(0) { KUrl bookfile = KUrl("~/.kde/share/apps/konqueror/bookmarks.xml"); // share konqueror bookmarks @@ -184,9 +170,9 @@ BookmarkProvider::BookmarkProvider(QWidget *parent) // setup toolbar setupToolBar(); - } + BookmarkProvider::~BookmarkProvider() { delete m_bookmarkToolBar; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7b9139cc..82b15ebf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -37,6 +37,8 @@ #include "mainview.h" #include "bookmarks.h" #include "download.h" +#include "findbar.h" +#include "sidepanel.h" // KDE Includes #include @@ -66,6 +68,7 @@ MainWindow::MainWindow() , m_view(new MainView(this)) , m_findBar(new FindBar(this)) , m_searchBar(new SearchBar(this)) + , m_sidePanel(0) { // accept dnd setAcceptDrops(true); @@ -73,19 +76,23 @@ MainWindow::MainWindow() // updating rekonq configuration slotUpdateConfiguration(); - // creating a centralWidget containing m_view and the hidden findbar + // creating a centralWidget containing panel, m_view and the hidden findbar QWidget *centralWidget = new QWidget; + centralWidget->setContentsMargins(0, 0, 0, 0); + + // setting layout QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(m_view); - - // Adding Find Bar - connect(m_findBar, SIGNAL(searchString(const QString &)), this, SLOT(slotFind(const QString &))); layout->addWidget(m_findBar); - centralWidget->setLayout(layout); + + // central widget setCentralWidget(centralWidget); + // Adding Find Bar + connect(m_findBar, SIGNAL(searchString(const QString &)), this, SLOT(slotFind(const QString &))); + // setting size policies setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -127,6 +134,7 @@ MainWindow::MainWindow() KActionMenu *bmMenu = Application::bookmarkProvider()->bookmarkActionMenu(); actionCollection()->addAction(QLatin1String("bookmarks"), bmMenu); + setupSidePanel(); // a call to KXmlGuiWindow::setupGUI() populates the GUI // with actions, using KXMLGUI. // It also applies the saved mainwindow settings, if any, and ask the @@ -143,6 +151,8 @@ MainWindow::MainWindow() // setting up toolbars to NOT have context menu enabled setContextMenuPolicy(Qt::DefaultContextMenu); + + } @@ -304,6 +314,28 @@ void MainWindow::setupActions() } +void MainWindow::setupSidePanel() +{ + // Setup history side panel + m_sidePanel = new SidePanel(i18n("History"), this); + connect(m_sidePanel, SIGNAL(openUrl(const KUrl&)), this, SLOT(loadUrl(const KUrl&))); + connect(m_sidePanel, SIGNAL(destroyed()), Application::instance(), SLOT(slotSaveConfiguration())); + + addDockWidget(Qt::LeftDockWidgetArea, m_sidePanel); + + // setup side panel actions + KAction* a = new KAction(this); + a->setText(i18n("History")); + a->setCheckable(true); + a->setChecked(ReKonfig::showSideBar()); + a->setShortcut(KShortcut(Qt::CTRL + Qt::Key_H)); + actionCollection()->addAction(QLatin1String("show_history_panel"), a); + + // connect to toogle action + connect(a, SIGNAL(triggered(bool)), m_sidePanel->toggleViewAction(), SLOT(trigger())); +} + + void MainWindow::setupHistoryMenu() { HistoryMenu *historyMenu = new HistoryMenu(this); diff --git a/src/mainwindow.h b/src/mainwindow.h index 76f5431b..74fee529 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -24,21 +24,27 @@ #define MAINWINDOW_H // Local Includes -#include "findbar.h" #include "searchbar.h" #include "bookmarks.h" #include "mainview.h" +#include "webview.h" // KDE Includes #include -#include -#include #include -#include // Forward Declarations -class KUrl; class QWebFrame; + +class KUrl; +class KAction; +class KActionMenu; +class KIcon; +class KMenu; + +class FindBar; +class HistoryMenu; +class SidePanel; class WebView; @@ -65,6 +71,8 @@ private: void setupActions(); void setupHistoryMenu(); void setupToolBars(); + void setupSidePanel(); + SidePanel *sidePanel() { return m_sidePanel; } public slots: void slotHome(); @@ -134,6 +142,7 @@ private: MainView *m_view; FindBar *m_findBar; SearchBar *m_searchBar; + SidePanel *m_sidePanel; }; #endif // MAINWINDOW_H diff --git a/src/panelhistory.cpp b/src/panelhistory.cpp new file mode 100644 index 00000000..4b71cefa --- /dev/null +++ b/src/panelhistory.cpp @@ -0,0 +1,94 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Domrachev Alexandr +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + + +// Self Includes +#include "panelhistory.h" + +// QT Includes +#include + +// KDE Includes +#include +#include +#include + +// Local Includes +#include "history.h" + + +PanelHistory::PanelHistory(QWidget *parent) + : QWidget(parent) + , m_historyTreeView(new QTreeView) + , m_treeProxyModel(new TreeProxyModel(this)) +{ + m_historyTreeView->setUniformRowHeights(true); + m_historyTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); + m_historyTreeView->setTextElideMode(Qt::ElideMiddle); + m_historyTreeView->setAlternatingRowColors(true); + + // add search bar + QHBoxLayout *hBoxLayout = new QHBoxLayout; + hBoxLayout->setContentsMargins(5, 0, 0, 0); + QLabel *searchLabel = new QLabel(i18n("Search: ")); + hBoxLayout->addWidget(searchLabel); + KLineEdit *search = new KLineEdit; + hBoxLayout->addWidget(search); + QWidget *searchBar = new QWidget; + searchBar->setLayout(hBoxLayout); + + // setup view + QVBoxLayout *vBoxLayout = new QVBoxLayout; + vBoxLayout->setContentsMargins(0, 0, 0, 0); + vBoxLayout->addWidget(searchBar); + vBoxLayout->addWidget(m_historyTreeView); + setLayout(vBoxLayout); + + //- + HistoryManager *historyManager = Application::historyManager(); + QAbstractItemModel *model = historyManager->historyTreeModel(); + + m_treeProxyModel->setSourceModel(model); + m_historyTreeView->setModel(m_treeProxyModel); + m_historyTreeView->setExpanded(m_treeProxyModel->index(0, 0), true); + m_historyTreeView->header()->hideSection(1); + QFontMetrics fm(font()); + int header = fm.width(QLatin1Char('m')) * 40; + m_historyTreeView->header()->resizeSection(0, header); + + connect(search, SIGNAL(textChanged(QString)), m_treeProxyModel, SLOT(setFilterFixedString(QString))); + connect(m_historyTreeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(open())); +} + + +PanelHistory::~PanelHistory() +{ + delete m_treeProxyModel; + delete m_historyTreeView; +} + + +void PanelHistory::open() +{ + QModelIndex index = m_historyTreeView->currentIndex(); + if (!index.parent().isValid()) + return; + emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); +} + diff --git a/src/panelhistory.h b/src/panelhistory.h new file mode 100644 index 00000000..45847565 --- /dev/null +++ b/src/panelhistory.h @@ -0,0 +1,55 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Domrachev Alexandr +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + +#ifndef PANELHISTORY_H +#define PANELHISTORY_H + +// Qt Includes +#include + +// Local Includes +#include "application.h" + +class QTreeView; +class KUrl; +class TreeProxyModel; + + +class PanelHistory : public QWidget +{ + Q_OBJECT + Q_DISABLE_COPY(PanelHistory) + +public: + explicit PanelHistory(QWidget *parent = 0); + virtual ~PanelHistory(); + +signals: + void openUrl(const KUrl&); + +private slots: + void open(); + +private: + QTreeView *m_historyTreeView; + TreeProxyModel *m_treeProxyModel; + +}; + +#endif // PANELHISTORY_H diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index a02f10ad..c6d5b0ff 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -23,6 +23,9 @@ true + + false + diff --git a/src/rekonqui.rc b/src/rekonqui.rc index 6de55eb5..e7b8d292 100644 --- a/src/rekonqui.rc +++ b/src/rekonqui.rc @@ -1,6 +1,6 @@ - + @@ -63,6 +63,10 @@ &Settings + + Side &Panels + + diff --git a/src/settings_general.ui b/src/settings_general.ui index 3b117854..580c6bb2 100644 --- a/src/settings_general.ui +++ b/src/settings_general.ui @@ -100,6 +100,13 @@ + + + + Show side panel + + + diff --git a/src/sidepanel.cpp b/src/sidepanel.cpp new file mode 100644 index 00000000..2197a603 --- /dev/null +++ b/src/sidepanel.cpp @@ -0,0 +1,54 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Paweł Prażak +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + +// Self Includes +#include "sidepanel.h" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "panelhistory.h" + + +SidePanel::SidePanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) + : QDockWidget(title, parent, flags) + , m_panelHistory(new PanelHistory(this)) +{ + setObjectName("sidePanel"); + setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + setShown(ReKonfig::showSideBar()); + + connect(m_panelHistory, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); + + setWidget(m_panelHistory); +} + + +SidePanel::~SidePanel() +{ + // Save side panel's state + ReKonfig::setShowSideBar(!isHidden()); + + delete m_panelHistory; +} + + + diff --git a/src/sidepanel.h b/src/sidepanel.h new file mode 100644 index 00000000..636eb363 --- /dev/null +++ b/src/sidepanel.h @@ -0,0 +1,52 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Paweł Prażak +* +* +* This program is free software; you can redistribute it +* and/or modify it under the terms of the GNU General +* Public License as published by the Free Software Foundation; +* either version 2, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* ============================================================ */ + + +#ifndef SIDEPANEL_H +#define SIDEPANEL_H + + +// Qt Includes +#include + +// Local Includes +#include "application.h" + +class KUrl; +class PanelHistory; + + +class SidePanel : public QDockWidget +{ + Q_OBJECT + Q_DISABLE_COPY(SidePanel) + +public: + explicit SidePanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~SidePanel(); + +signals: + void openUrl(const KUrl&); + +private: + PanelHistory *m_panelHistory; + +}; + +#endif // SIDEPANEL_H -- cgit v1.2.1