diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2009-06-02 01:50:28 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2009-06-02 01:50:28 +0200 |
commit | 0081a4fff5e3de0dedfa74134fc7ee221b106a5e (patch) | |
tree | e082599890e2adfde0167396d468b750b2a84dc5 /src | |
parent | Merge branch 'review/master' (diff) | |
download | rekonq-0081a4fff5e3de0dedfa74134fc7ee221b106a5e.tar.xz |
Porting history Ui to KDE..
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/history.cpp | 140 | ||||
-rw-r--r-- | src/history.h | 57 | ||||
-rw-r--r-- | src/history.ui | 90 | ||||
-rw-r--r-- | src/historydialog.cpp | 116 | ||||
-rw-r--r-- | src/historydialog.h | 56 | ||||
-rw-r--r-- | src/historymenu.cpp | 95 | ||||
-rw-r--r-- | src/historymenu.h | 65 | ||||
-rw-r--r-- | src/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/panelhistory.cpp | 6 | ||||
-rw-r--r-- | src/panelhistory.h | 6 |
11 files changed, 376 insertions, 259 deletions
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<QAction*> 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 <KAction> #include <KUrl> // 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<QAction*> actions); - -protected: - bool prePopulated(); - void postPopulated(); - -private slots: - void activated(const QModelIndex &index); - void showHistoryDialog(); - -private: - HistoryManager *m_history; - HistoryMenuModel *m_historyMenuModel; - QList<QAction*> 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 @@ -<ui version="4.0" > - <class>HistoryDialog</class> - <widget class="QDialog" name="HistoryDialog" > - <property name="geometry" > +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>historyWidget</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>758</width> - <height>450</height> + <width>584</width> + <height>381</height> </rect> </property> - <property name="windowTitle" > - <string>History</string> + <property name="windowTitle"> + <string>Form</string> </property> - <layout class="QGridLayout" name="gridLayout" > - <item row="0" column="0" > - <spacer> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0" > - <size> - <width>252</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="1" > - <widget class="KLineEdit" name="search" /> - </item> - <item row="1" column="0" colspan="2" > - <widget class="EditTreeView" name="tree" /> - </item> - <item row="2" column="0" colspan="2" > - <layout class="QHBoxLayout" > + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout"> <item> - <widget class="QPushButton" name="removeButton" > - <property name="text" > + <widget class="QPushButton" name="removeButton"> + <property name="text"> <string>&Remove</string> </property> </widget> </item> <item> - <widget class="QPushButton" name="removeAllButton" > - <property name="text" > + <widget class="QPushButton" name="removeAllButton"> + <property name="text"> <string>Remove &All</string> </property> </widget> </item> <item> <spacer> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> @@ -62,40 +44,34 @@ </spacer> </item> <item> - <widget class="QDialogButtonBox" name="buttonBox" > - <property name="standardButtons" > - <set>QDialogButtonBox::Ok</set> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Search:</string> </property> </widget> </item> + <item> + <widget class="KLineEdit" name="search"/> + </item> </layout> </item> + <item> + <widget class="EditTreeView" name="tree"/> + </item> </layout> </widget> <customwidgets> <customwidget> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header>klineedit.h</header> + </customwidget> + <customwidget> <class>EditTreeView</class> <extends>QTreeView</extends> <header>edittreeview.h</header> </customwidget> </customwidgets> <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>HistoryDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel" > - <x>472</x> - <y>329</y> - </hint> - <hint type="destinationlabel" > - <x>461</x> - <y>356</y> - </hint> - </hints> - </connection> - </connections> + <connections/> </ui> 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 <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, 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 <KAction> +#include <KUrl> + +// Qt Includes +#include <QtCore/QPoint> + +#include <QtGui/QWidget> +#include <QtGui/QClipboard> + + +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 <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, 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 <KDialog> + +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 <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, 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 <QtGui/QWidget> +#include <QtCore/QModelIndex> + +#include <KUrl> + +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<QAction*> 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 <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, 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 <QtCore/QList> +#include <QtGui/QAction> + +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<QAction*> actions); + +protected: + bool prePopulated(); + void postPopulated(); + +private slots: + void activated(const QModelIndex &index); + void showHistoryDialog(); + +private: + HistoryManager *m_history; + HistoryMenuModel *m_historyMenuModel; + QList<QAction*> 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 <QLabel> +// Qt Includes +#include <QtGui/QLabel> +#include <QtGui/QHBoxLayout> +#include <QtGui/QHeaderView> // KDE Includes #include <KLocalizedString> 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 <QWidget> +#include <QtGui/QWidget> +#include <QtGui/QTreeView> // Forward Declarations -class QTreeView; class KUrl; -class TreeProxyModel; class PanelHistory : public QWidget |