From 0081a4fff5e3de0dedfa74134fc7ee221b106a5e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 2 Jun 2009 01:50:28 +0200 Subject: Porting history Ui to KDE.. --- src/CMakeLists.txt | 2 + src/history.cpp | 140 +------------------------------------------------- src/history.h | 57 -------------------- src/history.ui | 90 ++++++++++++-------------------- src/historydialog.cpp | 116 +++++++++++++++++++++++++++++++++++++++++ src/historydialog.h | 56 ++++++++++++++++++++ src/historymenu.cpp | 95 ++++++++++++++++++++++++++++++++++ src/historymenu.h | 65 +++++++++++++++++++++++ src/mainwindow.cpp | 2 +- src/panelhistory.cpp | 6 ++- src/panelhistory.h | 6 +-- 11 files changed, 376 insertions(+), 259 deletions(-) create mode 100644 src/historydialog.cpp create mode 100644 src/historydialog.h create mode 100644 src/historymenu.cpp create mode 100644 src/historymenu.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 064fc0e6..4a3f5fed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,8 @@ SET( rekonq_SRCS edittableview.cpp edittreeview.cpp history.cpp + historydialog.cpp + historymenu.cpp download.cpp bookmarks.cpp modelmenu.cpp diff --git a/src/history.cpp b/src/history.cpp index fac13b48..795bc14e 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -669,74 +669,6 @@ QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const } -// ------------------------------------------------------------------------------------------------------------- - - -HistoryMenu::HistoryMenu(QWidget *parent) - : ModelMenu(parent) - , m_history(0) -{ - connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &))); - setHoverRole(HistoryModel::UrlStringRole); -} - - -void HistoryMenu::activated(const QModelIndex &index) -{ - emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); -} - - -bool HistoryMenu::prePopulated() -{ - if (!m_history) - { - m_history = Application::historyManager(); - m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); - setModel(m_historyMenuModel); - } - // initial actions - for (int i = 0; i < m_initialActions.count(); ++i) - addAction(m_initialActions.at(i)); - if (!m_initialActions.isEmpty()) - addSeparator(); - setFirstSeparator(m_historyMenuModel->bumpedRows()); - - return false; -} - - -void HistoryMenu::postPopulated() -{ - if (m_history->history().count() > 0) - addSeparator(); - - KAction *showAllAction = new KAction(i18n("Show All History"), this); - connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); - addAction(showAllAction); - - KAction *clearAction = new KAction(i18n("Clear History"), this); - connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear())); - addAction(clearAction); -} - - -void HistoryMenu::showHistoryDialog() -{ - HistoryDialog *dialog = new HistoryDialog(this); - connect(dialog, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); - dialog->show(); -} - - -void HistoryMenu::setInitialActions(QList actions) -{ - m_initialActions = actions; - for (int i = 0; i < m_initialActions.count(); ++i) - addAction(m_initialActions.at(i)); -} - - // -------------------------------------------------------------------------------------------------------------- @@ -755,78 +687,8 @@ bool TreeProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_ } -// ----------------------------------------------------------------------------------------------------- - - -HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) : QDialog(parent) -{ - HistoryManager *history = setHistory; - if (!history) - history = Application::historyManager(); - setupUi(this); - tree->setUniformRowHeights(true); - tree->setSelectionBehavior(QAbstractItemView::SelectRows); - tree->setTextElideMode(Qt::ElideMiddle); - QAbstractItemModel *model = history->historyTreeModel(); - TreeProxyModel *proxyModel = new TreeProxyModel(this); - connect(search, SIGNAL(textChanged(QString)), - proxyModel, SLOT(setFilterFixedString(QString))); - connect(removeButton, SIGNAL(clicked()), tree, SLOT(removeOne())); - connect(removeAllButton, SIGNAL(clicked()), history, SLOT(clear())); - proxyModel->setSourceModel(model); - tree->setModel(proxyModel); - tree->setExpanded(proxyModel->index(0, 0), true); - tree->setAlternatingRowColors(true); - QFontMetrics fm(font()); - int header = fm.width(QLatin1Char('m')) * 40; - tree->header()->resizeSection(0, header); - tree->header()->setStretchLastSection(true); - connect(tree, SIGNAL(activated(const QModelIndex&)), - this, SLOT(open())); - tree->setContextMenuPolicy(Qt::CustomContextMenu); - connect(tree, SIGNAL(customContextMenuRequested(const QPoint &)), - this, SLOT(customContextMenuRequested(const QPoint &))); -} - - -void HistoryDialog::customContextMenuRequested(const QPoint &pos) -{ - QMenu menu; - QModelIndex index = tree->indexAt(pos); - index = index.sibling(index.row(), 0); - if (index.isValid() && !tree->model()->hasChildren(index)) - { - menu.addAction(i18n("Open"), this, SLOT(open())); - menu.addSeparator(); - menu.addAction(i18n("Copy"), this, SLOT(copy())); - } - menu.addAction(i18n("Delete"), tree, SLOT(removeOne())); - menu.exec(QCursor::pos()); -} - - -void HistoryDialog::open() -{ - QModelIndex index = tree->currentIndex(); - if (!index.parent().isValid()) - return; - emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); -} - - -void HistoryDialog::copy() -{ - QModelIndex index = tree->currentIndex(); - if (!index.parent().isValid()) - return; - QString url = index.data(HistoryModel::UrlStringRole).toString(); - - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(url); -} - +// ------------------------------------------------------------------------------------------------------------- -// --------------------------------------------------------------------------------------------------------------- HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent) : QAbstractProxyModel(parent), diff --git a/src/history.h b/src/history.h index 7b3cbec9..7586ff9d 100644 --- a/src/history.h +++ b/src/history.h @@ -27,7 +27,6 @@ #include "modelmenu.h" // KDE Includes -#include #include // Qt Includes @@ -256,39 +255,6 @@ private: }; -// --------------------------------------------------------------------------------------------- - -/** - * Menu that is dynamically populated from the history - * - */ - -class HistoryMenu : public ModelMenu -{ - Q_OBJECT - -signals: - void openUrl(const KUrl &url); - -public: - HistoryMenu(QWidget *parent = 0); - void setInitialActions(QList actions); - -protected: - bool prePopulated(); - void postPopulated(); - -private slots: - void activated(const QModelIndex &index); - void showHistoryDialog(); - -private: - HistoryManager *m_history; - HistoryMenuModel *m_historyMenuModel; - QList m_initialActions; -}; - - // ---------------------------------------------------------------------------------------- /** @@ -383,27 +349,4 @@ protected: }; -// ------------------------------------------------------------------------------------------ - - -// Ui includes -#include "ui_history.h" - -class HistoryDialog : public QDialog, public Ui_HistoryDialog -{ - Q_OBJECT - -signals: - void openUrl(const KUrl &url); - -public: - explicit HistoryDialog(QWidget *parent = 0, HistoryManager *history = 0); - -private slots: - void customContextMenuRequested(const QPoint &pos); - void open(); - void copy(); - -}; - #endif // HISTORY_H diff --git a/src/history.ui b/src/history.ui index 806bc9ad..fb694f8f 100644 --- a/src/history.ui +++ b/src/history.ui @@ -1,59 +1,41 @@ - - HistoryDialog - - + + + historyWidget + + 0 0 - 758 - 450 + 584 + 381 - - History + + Form - - - - - Qt::Horizontal - - - - 252 - 20 - - - - - - - - - - - - + + + - - + + &Remove - - + + Remove &All - + Qt::Horizontal - + 40 20 @@ -62,17 +44,28 @@ - - - QDialogButtonBox::Ok + + + Search: + + + + + + + + KLineEdit + QLineEdit +
klineedit.h
+
EditTreeView QTreeView @@ -80,22 +73,5 @@
- - - buttonBox - accepted() - HistoryDialog - accept() - - - 472 - 329 - - - 461 - 356 - - - - +
diff --git a/src/historydialog.cpp b/src/historydialog.cpp new file mode 100644 index 00000000..da1c5858 --- /dev/null +++ b/src/historydialog.cpp @@ -0,0 +1,116 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* 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. +* +* ============================================================ */ + + +// Auto Includes +#include "historydialog.h" +#include "historydialog.moc" + +// Local Includes +#include "history.h" +#include "application.h" + +// KDE Includes +#include +#include + +// Qt Includes +#include + +#include +#include + + +HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory) + : KDialog(parent) + , m_historyWidg(new Ui::historyWidget) +{ + HistoryManager *history = setHistory; + if (!history) + history = Application::historyManager(); + + setCaption( i18n("History") ); + setButtons( KDialog::Close ); + + QWidget *widget = new QWidget; + m_historyWidg->setupUi(widget); + setMainWidget(widget); + + m_historyWidg->tree->setUniformRowHeights(true); + m_historyWidg->tree->setSelectionBehavior(QAbstractItemView::SelectRows); + m_historyWidg->tree->setTextElideMode(Qt::ElideMiddle); + + QAbstractItemModel *model = history->historyTreeModel(); + TreeProxyModel *proxyModel = new TreeProxyModel(this); + + connect(m_historyWidg->search, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString))); + connect(m_historyWidg->removeButton, SIGNAL(clicked()), m_historyWidg->tree, SLOT(removeOne())); + connect(m_historyWidg->removeAllButton, SIGNAL(clicked()), history, SLOT(clear())); + + proxyModel->setSourceModel(model); + m_historyWidg->tree->setModel(proxyModel); + m_historyWidg->tree->setExpanded(proxyModel->index(0, 0), true); + m_historyWidg->tree->setAlternatingRowColors(true); + + QFontMetrics fm(font()); + int header = fm.width(QLatin1Char('m')) * 40; + m_historyWidg->tree->header()->resizeSection(0, header); + m_historyWidg->tree->header()->setStretchLastSection(true); + connect(m_historyWidg->tree, SIGNAL(activated(const QModelIndex&)), this, SLOT(open())); + m_historyWidg->tree->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_historyWidg->tree, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(customContextMenuRequested(const QPoint &))); +} + + +void HistoryDialog::customContextMenuRequested(const QPoint &pos) +{ + KMenu menu; + QModelIndex index = m_historyWidg->tree->indexAt(pos); + index = index.sibling(index.row(), 0); + if (index.isValid() && !m_historyWidg->tree->model()->hasChildren(index)) + { + menu.addAction(i18n("Open"), this, SLOT(open())); + menu.addSeparator(); + menu.addAction(i18n("Copy"), this, SLOT(copy())); + } + menu.addAction(i18n("Delete"), m_historyWidg->tree, SLOT(removeOne())); + menu.exec(QCursor::pos()); +} + + +void HistoryDialog::open() +{ + QModelIndex index = m_historyWidg->tree->currentIndex(); + if (!index.parent().isValid()) + return; + emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); +} + + +void HistoryDialog::copy() +{ + QModelIndex index = m_historyWidg->tree->currentIndex(); + if (!index.parent().isValid()) + return; + QString url = index.data(HistoryModel::UrlStringRole).toString(); + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(url); +} diff --git a/src/historydialog.h b/src/historydialog.h new file mode 100644 index 00000000..1f592cdd --- /dev/null +++ b/src/historydialog.h @@ -0,0 +1,56 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* 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 HISTORYDIALOG_H +#define HISTORYDIALOG_H + + +// Ui includes +#include "ui_history.h" + +// KDE Includes +#include + +class KUrl; +class QPoint; +class QWidget; +class HistoryManager; + +class HistoryDialog : public KDialog +{ + Q_OBJECT + +signals: + void openUrl(const KUrl &url); + +public: + explicit HistoryDialog(QWidget *parent = 0, HistoryManager *history = 0); + +private slots: + void customContextMenuRequested(const QPoint &pos); + void open(); + void copy(); + +private: + Ui::historyWidget *m_historyWidg; +}; + +#endif diff --git a/src/historymenu.cpp b/src/historymenu.cpp new file mode 100644 index 00000000..74b37db0 --- /dev/null +++ b/src/historymenu.cpp @@ -0,0 +1,95 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-2009 by Andrea Diamantini +* +* +* 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. +* +* ============================================================ */ + + +#include "historymenu.h" +#include "historymenu.moc" + +#include "application.h" +#include "historydialog.h" + +#include +#include + +#include + +HistoryMenu::HistoryMenu(QWidget *parent) + : ModelMenu(parent) + , m_history(0) +{ + connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &))); + setHoverRole(HistoryModel::UrlStringRole); +} + + +void HistoryMenu::activated(const QModelIndex &index) +{ + emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); +} + + +bool HistoryMenu::prePopulated() +{ + if (!m_history) + { + m_history = Application::historyManager(); + m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); + setModel(m_historyMenuModel); + } + // initial actions + for (int i = 0; i < m_initialActions.count(); ++i) + addAction(m_initialActions.at(i)); + if (!m_initialActions.isEmpty()) + addSeparator(); + setFirstSeparator(m_historyMenuModel->bumpedRows()); + + return false; +} + + +void HistoryMenu::postPopulated() +{ + if (m_history->history().count() > 0) + addSeparator(); + + KAction *showAllAction = new KAction(i18n("Show All History"), this); + connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); + addAction(showAllAction); + + KAction *clearAction = new KAction(i18n("Clear History"), this); + connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear())); + addAction(clearAction); +} + + +void HistoryMenu::showHistoryDialog() +{ + HistoryDialog *dialog = new HistoryDialog(this); + connect(dialog, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); + dialog->show(); +} + + +void HistoryMenu::setInitialActions(QList actions) +{ + m_initialActions = actions; + for (int i = 0; i < m_initialActions.count(); ++i) + addAction(m_initialActions.at(i)); +} diff --git a/src/historymenu.h b/src/historymenu.h new file mode 100644 index 00000000..06d85ffa --- /dev/null +++ b/src/historymenu.h @@ -0,0 +1,65 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-2009 by Andrea Diamantini +* +* +* 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 HISTORYMENU_H +#define HISTORYMENU_H + +#include "history.h" + +#include +#include + +class ModelMenu; +class QWidget; +class QModelIndex; +class KUrl; + +/** + * Menu that is dynamically populated from the history + * + */ + +class HistoryMenu : public ModelMenu +{ + Q_OBJECT + +signals: + void openUrl(const KUrl &url); + +public: + HistoryMenu(QWidget *parent = 0); + void setInitialActions(QList actions); + +protected: + bool prePopulated(); + void postPopulated(); + +private slots: + void activated(const QModelIndex &index); + void showHistoryDialog(); + +private: + HistoryManager *m_history; + HistoryMenuModel *m_historyMenuModel; + QList m_initialActions; +}; + +#endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 73ec3d6d..0c7a0984 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -30,7 +30,7 @@ // Local Includes #include "application.h" #include "settings.h" -#include "history.h" +#include "historymenu.h" #include "cookiejar.h" #include "networkaccessmanager.h" #include "bookmarks.h" diff --git a/src/panelhistory.cpp b/src/panelhistory.cpp index 72507663..8b736074 100644 --- a/src/panelhistory.cpp +++ b/src/panelhistory.cpp @@ -22,8 +22,10 @@ #include "panelhistory.h" #include "panelhistory.moc" -// QT Includes -#include +// Qt Includes +#include +#include +#include // KDE Includes #include diff --git a/src/panelhistory.h b/src/panelhistory.h index c6fe1380..20152c64 100644 --- a/src/panelhistory.h +++ b/src/panelhistory.h @@ -22,14 +22,14 @@ // Local Includes #include "application.h" +#include "history.h" // Qt Includes -#include +#include +#include // Forward Declarations -class QTreeView; class KUrl; -class TreeProxyModel; class PanelHistory : public QWidget -- cgit v1.2.1