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/historydialog.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/historydialog.cpp (limited to 'src/historydialog.cpp') 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); +} -- cgit v1.2.1