summaryrefslogtreecommitdiff
path: root/src/bookmarks
diff options
context:
space:
mode:
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/bookmarkspanel.cpp112
-rw-r--r--src/bookmarks/bookmarkspanel.h20
-rw-r--r--src/bookmarks/bookmarksproxy.cpp58
-rw-r--r--src/bookmarks/bookmarksproxy.h58
4 files changed, 48 insertions, 200 deletions
diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp
index 08f99155..e88d3060 100644
--- a/src/bookmarks/bookmarkspanel.cpp
+++ b/src/bookmarks/bookmarkspanel.cpp
@@ -28,51 +28,31 @@
// Self Includes
#include "bookmarkspanel.h"
+// Auto Includes
+#include "rekonq.h"
+
// Local Includes
#include "application.h"
#include "bookmarkprovider.h"
#include "bookmarkstreemodel.h"
-#include "bookmarksproxy.h"
#include "bookmarkscontextmenu.h"
#include "bookmarkowner.h"
#include "paneltreeview.h"
+#include "urlfilterproxymodel.h"
-// Auto Includes
-#include "rekonq.h"
-
-// Qt includes
-#include <QtGui/QHBoxLayout>
-#include <QtGui/QLabel>
-#include <QtGui/QHeaderView>
-
-// KDE includes
-#include <KLineEdit>
BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags)
- : QDockWidget(title, parent, flags)
- , m_treeView(new PanelTreeView(this))
+ : UrlPanel(title, parent, flags)
, m_loadingState(false)
- , m_loaded(false)
{
setObjectName("bookmarksPanel");
- setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
-
- connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(showing(bool)));
-
setVisible(ReKonfig::showBookmarksPanel());
}
BookmarksPanel::~BookmarksPanel()
{
- ReKonfig::setShowBookmarksPanel(false);
-}
-
-
-void BookmarksPanel::showing(bool b)
-{
- if(b && !m_loaded)
- setup();
+ ReKonfig::setShowBookmarksPanel(!isHidden());
}
@@ -99,6 +79,24 @@ void BookmarksPanel::contextMenu(const QPoint &pos)
}
+void BookmarksPanel::contextMenuItem(const QPoint &pos)
+{
+ contextMenu(pos);
+}
+
+
+void BookmarksPanel::contextMenuGroup(const QPoint &pos)
+{
+ contextMenu(pos);
+}
+
+
+void BookmarksPanel::contextMenuEmpty(const QPoint &pos)
+{
+ contextMenu(pos);
+}
+
+
void BookmarksPanel::deleteBookmark()
{
QModelIndex index = m_treeView->currentIndex();
@@ -131,12 +129,13 @@ void BookmarksPanel::onExpand(const QModelIndex &index)
void BookmarksPanel::loadFoldedState(const QModelIndex &root)
{
- int count = m_treeView->model()->rowCount(root);
+ QAbstractItemModel *model = m_treeView->model();
+ int count = model->rowCount(root);
QModelIndex index;
for (int i = 0; i < count; ++i)
{
- index = m_treeView->model()->index(i, 0, root);
+ index = model->index(i, 0, root);
if (index.isValid())
{
KBookmark bm = bookmarkForIndex(index);
@@ -152,57 +151,14 @@ void BookmarksPanel::loadFoldedState(const QModelIndex &root)
void BookmarksPanel::setup()
{
- kDebug() << "Loading bookmarks panel setup...";
-
- QWidget *ui = new QWidget(this);
-
- // setup search bar
- QHBoxLayout *searchLayout = new QHBoxLayout;
- searchLayout->setContentsMargins(5, 0, 0, 0);
- QLabel *searchLabel = new QLabel(i18n("&Search:"));
- searchLayout->addWidget(searchLabel);
- KLineEdit *search = new KLineEdit;
- search->setClearButtonShown(true);
- searchLayout->addWidget(search);
- searchLabel->setBuddy(search);
-
- // setup tree view
- m_treeView->setUniformRowHeights(true);
- m_treeView->header()->hide();
- m_treeView->setDragEnabled(true);
- m_treeView->setAutoExpandDelay(750);
- m_treeView->setDefaultDropAction(Qt::MoveAction);
- m_treeView->viewport()->setAcceptDrops(true);
-
- // put everything together
- QVBoxLayout *vBoxLayout = new QVBoxLayout;
- vBoxLayout->setContentsMargins(0, 0, 0, 0);
- vBoxLayout->addLayout(searchLayout);
- vBoxLayout->addWidget(m_treeView);
-
- // add it to the UI
- ui->setLayout(vBoxLayout);
- setWidget(ui);
-
- BookmarksTreeModel *model = new BookmarksTreeModel(this);
- BookmarksProxy *proxy = new BookmarksProxy(ui);
- proxy->setSourceModel(model);
- m_treeView->setModel(proxy);
-
- connect(search, SIGNAL(textChanged(const QString &)), proxy, SLOT(setFilterFixedString(const QString &)));
+ UrlPanel::setup();
+ kDebug() << "Bookmarks panel...";
- connect(model, SIGNAL(bookmarksUpdated()), this, SLOT(startLoadFoldedState()));
-
- connect(m_treeView, SIGNAL(contextMenuItemRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &)));
- connect(m_treeView, SIGNAL(contextMenuGroupRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &)));
- connect(m_treeView, SIGNAL(contextMenuEmptyRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &)));
connect(m_treeView, SIGNAL(delKeyPressed()), this, SLOT(deleteBookmark()));
connect(m_treeView, SIGNAL(collapsed(const QModelIndex &)), this, SLOT(onCollapse(const QModelIndex &)));
connect(m_treeView, SIGNAL(expanded(const QModelIndex &)), this, SLOT(onExpand(const QModelIndex &)));
startLoadFoldedState();
-
- m_loaded = true;
}
@@ -211,9 +167,17 @@ KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index)
if (!index.isValid())
return KBookmark();
- const BookmarksProxy *proxyModel = static_cast<const BookmarksProxy*>(index.model());
+ const UrlFilterProxyModel *proxyModel = static_cast<const UrlFilterProxyModel*>(index.model());
QModelIndex originalIndex = proxyModel->mapToSource(index);
BtmItem *node = static_cast<BtmItem*>(originalIndex.internalPointer());
return node->getBkm();
}
+
+
+QAbstractItemModel* BookmarksPanel::getModel()
+{
+ BookmarksTreeModel *model = new BookmarksTreeModel(this);
+ connect(model, SIGNAL(bookmarksUpdated()), this, SLOT(startLoadFoldedState()));
+ return model;
+}
diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h
index 4afa953b..2418ae81 100644
--- a/src/bookmarks/bookmarkspanel.h
+++ b/src/bookmarks/bookmarkspanel.h
@@ -33,15 +33,14 @@
// Rekonq Includes
#include "rekonq_defines.h"
-// Qt Includes
-#include <QDockWidget>
+// Local Includes
+#include "urlpanel.h"
// Forward Declarations
-class PanelTreeView;
class KBookmark;
class QModelIndex;
-class REKONQ_TESTS_EXPORT BookmarksPanel : public QDockWidget
+class REKONQ_TESTS_EXPORT BookmarksPanel : public UrlPanel
{
Q_OBJECT
@@ -50,16 +49,16 @@ public:
virtual ~BookmarksPanel();
signals:
- void openUrl(const KUrl &, const Rekonq::OpenType &);
- void itemHovered(const QString &);
void expansionChanged();
public slots:
- void showing(bool);
void startLoadFoldedState();
private slots:
void contextMenu(const QPoint &pos);
+ virtual void contextMenuItem(const QPoint &pos);
+ virtual void contextMenuGroup(const QPoint &pos);
+ virtual void contextMenuEmpty(const QPoint &pos);
void deleteBookmark();
void onCollapse(const QModelIndex &index);
@@ -67,11 +66,12 @@ private slots:
void loadFoldedState(const QModelIndex &root);
private:
- void setup();
+ virtual void setup();
KBookmark bookmarkForIndex(const QModelIndex &index);
- PanelTreeView *m_treeView;
- bool m_loadingState, m_loaded;
+ virtual QAbstractItemModel* getModel();
+
+ bool m_loadingState;
};
#endif // BOOKMARKSPANEL_H
diff --git a/src/bookmarks/bookmarksproxy.cpp b/src/bookmarks/bookmarksproxy.cpp
deleted file mode 100644
index 1e4da877..00000000
--- a/src/bookmarks/bookmarksproxy.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2009 by Nils Weigel <nehlsen at gmail dot com>
-* Copyright (C) 2010 by Andrea Diamantini <adjam7 at gmail dot com>
-*
-*
-* 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 of
-* the License or (at your option) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* 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.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* ============================================================ */
-
-
-// Self Includes
-#include "bookmarksproxy.h"
-
-
-BookmarksProxy::BookmarksProxy(QObject *parent)
- : QSortFilterProxyModel(parent)
-{
- setFilterCaseSensitivity(Qt::CaseInsensitive);
-}
-
-
-bool BookmarksProxy::filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const
-{
- return recursiveMatch( sourceModel()->index(source_row, 0, source_parent) );
-}
-
-
-bool BookmarksProxy::recursiveMatch(const QModelIndex &index) const
-{
- if (index.data().toString().contains(filterRegExp()))
- return true;
-
- int numChildren = sourceModel()->rowCount(index);
- for (int childRow = 0; childRow < numChildren; ++childRow)
- {
- if (recursiveMatch(sourceModel()->index(childRow, 0, index)))
- return true;
- }
-
- return false;
-}
diff --git a/src/bookmarks/bookmarksproxy.h b/src/bookmarks/bookmarksproxy.h
deleted file mode 100644
index b4554d2b..00000000
--- a/src/bookmarks/bookmarksproxy.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2009 by Nils Weigel <nehlsen at gmail dot com>
-* Copyright (C) 2010 by Andrea Diamantini <adjam7 at gmail dot com>
-*
-*
-* 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 of
-* the License or (at your option) version 3 or any later version
-* accepted by the membership of KDE e.V. (or its successor approved
-* by the membership of KDE e.V.), which shall act as a proxy
-* defined in Section 14 of version 3 of the license.
-*
-* 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.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* ============================================================ */
-
-
-#ifndef BOOKMARKSPROXY_H
-#define BOOKMARKSPROXY_H
-
-
-// Rekonq Includes
-#include "rekonq_defines.h"
-
-// Qt Includes
-#include <QtGui/QSortFilterProxyModel>
-
-/**
- * QSortFilterProxyModel hides all children which parent doesn't
- * match the filter. This class is used to change this behavior.
- * If a bookmark matches the filter it'll be shown, even if it's parent doesn't match it.
- */
-class REKONQ_TESTS_EXPORT BookmarksProxy : public QSortFilterProxyModel
-{
- Q_OBJECT
- Q_DISABLE_COPY(BookmarksProxy)
-
-public:
- BookmarksProxy(QObject *parent = 0);
-
-protected:
- virtual bool filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const;
-
- // returns true if index or any of his children match the filter
- bool recursiveMatch(const QModelIndex &index) const;
-};
-
-#endif // BOOKMARKSPROXY_H