summaryrefslogtreecommitdiff
path: root/src/history
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-01-24 19:17:58 +0100
committerAndrea Diamantini <adjam7@gmail.com>2010-01-24 19:17:58 +0100
commitb87a805af7b066159ff4f10ff9c30fd7428ea706 (patch)
treeebce1dea818a54bd51fbcff0074df793e4f09904 /src/history
parentHere we are, with this commit I removed a lot of direct calls to (diff)
downloadrekonq-b87a805af7b066159ff4f10ff9c30fd7428ea706.tar.xz
Fixing panels
With this commit I fixed panel behaviour && saved some bytes in their definition. This will help hacking there (they are pretty the same now, I just have no time to let them inherit from a parent "rekonq panel" class) and will save some bytes in rekonq footprint :)
Diffstat (limited to 'src/history')
-rw-r--r--src/history/historypanel.cpp82
-rw-r--r--src/history/historypanel.h21
-rw-r--r--src/history/sidepanel.cpp60
-rw-r--r--src/history/sidepanel.h58
4 files changed, 59 insertions, 162 deletions
diff --git a/src/history/historypanel.cpp b/src/history/historypanel.cpp
index 42497f9e..08dc3800 100644
--- a/src/history/historypanel.cpp
+++ b/src/history/historypanel.cpp
@@ -29,25 +29,52 @@
#include "historypanel.h"
#include "historypanel.moc"
+// Auto Includes
+#include "rekonq.h"
+
+// Local Includes
+#include "application.h"
+#include "historymodels.h"
+
// Qt Includes
#include <QtGui/QLabel>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
+#include <QtGui/QTreeView>
+
// KDE Includes
#include <KLineEdit>
#include <KLocalizedString>
-HistoryPanel::HistoryPanel(QWidget *parent)
- : QWidget(parent)
- , m_historyTreeView(new QTreeView)
- , m_treeProxyModel(new TreeProxyModel(this))
+HistoryPanel::HistoryPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags)
+ : QDockWidget(title, parent, flags)
+{
+ setup();
+ setShown(ReKonfig::showHistoryPanel());
+}
+
+
+HistoryPanel::~HistoryPanel()
+{
+ // Save side panel's state
+ ReKonfig::setShowHistoryPanel(!isHidden());
+}
+
+
+void HistoryPanel::setup()
{
- m_historyTreeView->setUniformRowHeights(true);
- m_historyTreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
- m_historyTreeView->setTextElideMode(Qt::ElideMiddle);
- m_historyTreeView->setAlternatingRowColors(true);
+ setObjectName("historyPanel");
+ setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+
+ QWidget *ui = new QWidget(this);
+
+ QTreeView *historyTreeView = new QTreeView(this);
+ historyTreeView->setUniformRowHeights(true);
+ historyTreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ historyTreeView->setTextElideMode(Qt::ElideMiddle);
+ historyTreeView->setAlternatingRowColors(true);
// add search bar
QHBoxLayout *hBoxLayout = new QHBoxLayout;
@@ -60,42 +87,35 @@ HistoryPanel::HistoryPanel(QWidget *parent)
QWidget *searchBar = new QWidget;
searchBar->setLayout(hBoxLayout);
- // setup view
+ // setup layout
QVBoxLayout *vBoxLayout = new QVBoxLayout;
vBoxLayout->setContentsMargins(0, 0, 0, 0);
vBoxLayout->addWidget(searchBar);
- vBoxLayout->addWidget(m_historyTreeView);
- setLayout(vBoxLayout);
+ vBoxLayout->addWidget(historyTreeView);
+
+ // add it to the UI
+ ui->setLayout(vBoxLayout);
+ setWidget(ui);
//-
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);
+ TreeProxyModel *treeProxyModel = new TreeProxyModel(this);
+ treeProxyModel->setSourceModel(model);
+ historyTreeView->setModel(treeProxyModel);
+ historyTreeView->setExpanded(treeProxyModel->index(0, 0), true);
+ 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()));
-}
-
+ historyTreeView->header()->resizeSection(0, header);
-HistoryPanel::~HistoryPanel()
-{
- delete m_treeProxyModel;
- delete m_historyTreeView;
+ connect(search, SIGNAL(textChanged(QString)), treeProxyModel, SLOT(setFilterFixedString(QString)));
+ connect(historyTreeView, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &)));
}
-void HistoryPanel::open()
+void HistoryPanel::itemActivated(const QModelIndex &item)
{
- QModelIndex index = m_historyTreeView->currentIndex();
- if (!index.parent().isValid())
- return;
- emit openUrl(index.data(HistoryModel::UrlRole).toUrl());
+ emit openUrl( item.data(HistoryModel::UrlRole).toUrl() );
}
-
diff --git a/src/history/historypanel.h b/src/history/historypanel.h
index 083b2741..e07e2190 100644
--- a/src/history/historypanel.h
+++ b/src/history/historypanel.h
@@ -29,36 +29,31 @@
#define HISTORYPANEL_H
-// Local Includes
-#include "application.h"
-#include "historymodels.h"
-
// Qt Includes
-#include <QtGui/QWidget>
-#include <QtGui/QTreeView>
+#include <QDockWidget>
// Forward Declarations
class KUrl;
+class QWidget;
+class QModelIndex;
-class HistoryPanel : public QWidget
+class HistoryPanel : public QDockWidget
{
Q_OBJECT
public:
- explicit HistoryPanel(QWidget *parent = 0);
- virtual ~HistoryPanel();
+ explicit HistoryPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0);
+ ~HistoryPanel();
signals:
void openUrl(const KUrl &);
private slots:
- void open();
+ void itemActivated(const QModelIndex &);
private:
- QTreeView *m_historyTreeView;
- TreeProxyModel *m_treeProxyModel;
-
+ void setup();
};
#endif // HISTORYPANEL_H
diff --git a/src/history/sidepanel.cpp b/src/history/sidepanel.cpp
deleted file mode 100644
index 7c42301c..00000000
--- a/src/history/sidepanel.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
-* Copyright (C) 2009 by Paweł Prażak <pawelprazak 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 "sidepanel.h"
-#include "sidepanel.moc"
-
-// Auto Includes
-#include "rekonq.h"
-
-// Local Includes
-#include "historypanel.h"
-
-
-SidePanel::SidePanel(const QString &title, QWidget *parent, Qt::WindowFlags flags)
- : QDockWidget(title, parent, flags)
- , m_historyPanel(new HistoryPanel(this))
-{
- setObjectName("sidePanel");
- setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
-
- setShown(ReKonfig::showSideBar());
-
- connect(m_historyPanel, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&)));
-
- setWidget(m_historyPanel);
-}
-
-
-SidePanel::~SidePanel()
-{
- // Save side panel's state
- ReKonfig::setShowSideBar(!isHidden());
-
- delete m_historyPanel;
-}
diff --git a/src/history/sidepanel.h b/src/history/sidepanel.h
deleted file mode 100644
index 6aca3587..00000000
--- a/src/history/sidepanel.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
-* Copyright (C) 2009 by Paweł Prażak <pawelprazak 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 SIDEPANEL_H
-#define SIDEPANEL_H
-
-// Local Includes
-#include "application.h"
-
-// Qt Includes
-#include <QDockWidget>
-
-// Forward Declarations
-class KUrl;
-class HistoryPanel;
-
-
-class SidePanel : public QDockWidget
-{
- Q_OBJECT
-
-public:
- explicit SidePanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0);
- ~SidePanel();
-
-signals:
- void openUrl(const KUrl &);
-
-private:
- HistoryPanel *m_historyPanel;
-
-};
-
-#endif // SIDEPANEL_H