diff options
author | adjam <adjam@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-06-02 22:41:57 +0000 |
---|---|---|
committer | adjam <adjam@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-06-02 22:41:57 +0000 |
commit | c9d8f10a2a361dd5dffa5d61b96bc96f0d50129d (patch) | |
tree | a2c949860fb01f2efb3dfd3b439a726a4e3ea753 /src/historydialog.cpp | |
parent | Merge branch 'master' into local-svn (diff) | |
parent | new cookie management system. That (hopefully) works well..;) (diff) | |
download | rekonq-c9d8f10a2a361dd5dffa5d61b96bc96f0d50129d.tar.xz |
Merge branch 'master' into local-svn
git-svn-id: svn+ssh://svn.kde.org/home/kde/trunk/playground/network/rekonq@976901 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/historydialog.cpp')
-rw-r--r-- | src/historydialog.cpp | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/historydialog.cpp b/src/historydialog.cpp new file mode 100644 index 00000000..7b0d6bc0 --- /dev/null +++ b/src/historydialog.cpp @@ -0,0 +1,129 @@ +/* ============================================================ +* +* 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> +#include <QtGui/QDesktopWidget> + + +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->search->setClearButtonShown(true); + + 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')) * 25; + m_historyWidg->tree->header()->resizeSection(0, header); + m_historyWidg->tree->header()->setStretchLastSection(true); + + m_historyWidg->tree->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(m_historyWidg->tree, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(customContextMenuRequested(const QPoint &))); + + connect(m_historyWidg->tree, SIGNAL(activated(const QModelIndex&)), this, SLOT(open())); +} + + +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); +} + +QSize HistoryDialog::sizeHint() const +{ + QRect desktopRect = Application::desktop()->screenGeometry(); + QSize size = desktopRect.size() * 0.7; + return size; +} |