summaryrefslogtreecommitdiff
path: root/src/history
diff options
context:
space:
mode:
Diffstat (limited to 'src/history')
-rw-r--r--src/history/historymodels.cpp8
-rw-r--r--src/history/historypanel.cpp89
-rw-r--r--src/history/historypanel.h10
3 files changed, 92 insertions, 15 deletions
diff --git a/src/history/historymodels.cpp b/src/history/historymodels.cpp
index 709d0523..736dbcd7 100644
--- a/src/history/historymodels.cpp
+++ b/src/history/historymodels.cpp
@@ -118,6 +118,8 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const
return item.dateTime.date();
case UrlRole:
return QUrl(item.url);
+ case Qt::UserRole:
+ return KUrl(item.url);
case UrlStringRole:
return item.url;
case Qt::DisplayRole:
@@ -144,6 +146,12 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const
{
return Application::icon(item.url);
}
+ case Qt::ToolTipRole:
+ QString tooltip = "";
+ if(!item.title.isEmpty())
+ tooltip = item.title + "\n";
+ tooltip += item.dateTime.toString(Qt::SystemLocaleShortDate) + "\n" + item.url;
+ return tooltip;
}
return QVariant();
}
diff --git a/src/history/historypanel.cpp b/src/history/historypanel.cpp
index 8c8eae75..c67594ff 100644
--- a/src/history/historypanel.cpp
+++ b/src/history/historypanel.cpp
@@ -46,6 +46,9 @@
// KDE Includes
#include <KLineEdit>
#include <KLocalizedString>
+#include <KMenu>
+#include <KAction>
+#include <KMessageBox>
HistoryPanel::HistoryPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags)
@@ -70,11 +73,12 @@ void HistoryPanel::setup()
QWidget *ui = new QWidget(this);
- QTreeView *historyTreeView = new QTreeView(this);
- historyTreeView->setUniformRowHeights(true);
- historyTreeView->setSelectionBehavior(QAbstractItemView::SelectRows);
- historyTreeView->setTextElideMode(Qt::ElideMiddle);
- historyTreeView->setAlternatingRowColors(true);
+ m_treeView = new UrlTreeView(this);
+ m_treeView->setUniformRowHeights(true);
+ m_treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ m_treeView->setTextElideMode(Qt::ElideMiddle);
+ m_treeView->setAlternatingRowColors(true);
+ m_treeView->header()->hide();
// add search bar
QHBoxLayout *hBoxLayout = new QHBoxLayout;
@@ -91,7 +95,7 @@ void HistoryPanel::setup()
QVBoxLayout *vBoxLayout = new QVBoxLayout;
vBoxLayout->setContentsMargins(0, 0, 0, 0);
vBoxLayout->addWidget(searchBar);
- vBoxLayout->addWidget(historyTreeView);
+ vBoxLayout->addWidget(m_treeView);
// add it to the UI
ui->setLayout(vBoxLayout);
@@ -103,19 +107,78 @@ void HistoryPanel::setup()
TreeProxyModel *treeProxyModel = new TreeProxyModel(this);
treeProxyModel->setSourceModel(model);
- historyTreeView->setModel(treeProxyModel);
- historyTreeView->setExpanded(treeProxyModel->index(0, 0), true);
- historyTreeView->header()->hideSection(1);
+ m_treeView->setModel(treeProxyModel);
+ m_treeView->setExpanded(treeProxyModel->index(0, 0), true);
+ m_treeView->header()->hideSection(1);
QFontMetrics fm(font());
int header = fm.width(QLatin1Char('m')) * 40;
- historyTreeView->header()->resizeSection(0, header);
+ m_treeView->header()->resizeSection(0, header);
connect(search, SIGNAL(textChanged(QString)), treeProxyModel, SLOT(setFilterFixedString(QString)));
- connect(historyTreeView, SIGNAL(activated(const QModelIndex &)), this, SLOT(itemActivated(const QModelIndex &)));
+ connect(m_treeView, SIGNAL(contextMenuItemRequested(const QPoint &)), this, SLOT(contextMenuItem(const QPoint &)));
+ connect(m_treeView, SIGNAL(contextMenuGroupRequested(const QPoint &)), this, SLOT(contextMenuGroup(const QPoint &)));
}
+void HistoryPanel::contextMenuItem(const QPoint &pos)
+{
+ QPoint position = m_treeView->mapToGlobal(pos);
+ KMenu *menu = new KMenu(this);
+ KAction* action;
+
+ action = new KAction(KIcon("tab-new"), i18n("Open"), this);
+ connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInCurrentTab()));
+ menu->addAction(action);
+
+ action = new KAction(KIcon("tab-new"), i18n("Open in new tab"), this);
+ connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInNewTab()));
+ menu->addAction(action);
+
+ action = new KAction(KIcon("window-new"), i18n("Open in new window"), this);
+ connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInNewWindow()));
+ menu->addAction(action);
+
+ action = new KAction(KIcon("edit-copy"), i18n("Copy link"), this);
+ connect(action, SIGNAL(triggered()), m_treeView, SLOT(copyToClipboard()));
+ menu->addAction(action);
-void HistoryPanel::itemActivated(const QModelIndex &item)
+ if (!menu)
+ return;
+ menu->popup(position);
+}
+
+void HistoryPanel::contextMenuGroup(const QPoint &pos)
{
- emit openUrl( item.data(HistoryModel::UrlRole).toUrl() );
+ QPoint position = m_treeView->mapToGlobal(pos);
+ KMenu *menu = new KMenu(this);
+ KAction* action;
+
+ action = new KAction(KIcon("tab-new"), i18n("Open all Bookmarks"), this);
+ connect(action, SIGNAL(triggered()), this, SLOT(openAll()));
+
+ menu->addAction(action);
+
+ if (!menu)
+ return;
+ menu->popup(position);
+}
+
+void HistoryPanel::openAll()
+{
+ QModelIndex index = m_treeView->currentIndex();
+ if(!index.isValid())
+ return;
+
+ QList<KUrl> allChild;
+
+ for(int i = 0; i < index.model()->rowCount(index); i++)
+ allChild << qVariantValue<KUrl>(index.child(i, 0).data(Qt::UserRole));
+
+ if(allChild.length() > 8) // 8, a good choice ?
+ {
+ if(!(KMessageBox::warningContinueCancel(this, i18n("You are about to open a lot of tabs : %1\nAre you sure ?", QString::number(allChild.length()))) == KMessageBox::Continue))
+ return;
+ }
+
+ for(int i = 0; i < allChild.length(); i++)
+ emit openUrl(allChild.at(i).url(), Rekonq::SettingOpenTab);
}
diff --git a/src/history/historypanel.h b/src/history/historypanel.h
index 6e6a9162..0c01189c 100644
--- a/src/history/historypanel.h
+++ b/src/history/historypanel.h
@@ -31,6 +31,8 @@
// Local Includes
#include "rekonqprivate_export.h"
+#include "application.h"
+#include "urltreeview.h"
// Qt Includes
#include <QDockWidget>
@@ -50,13 +52,17 @@ public:
~HistoryPanel();
signals:
- void openUrl(const KUrl &);
+ void openUrl(const KUrl &, const Rekonq::OpenType &);
+ void itemHovered(const QString &);
private slots:
- void itemActivated(const QModelIndex &);
+ void contextMenuItem(const QPoint &pos);
+ void contextMenuGroup(const QPoint &pos);
+ void openAll();
private:
void setup();
+ UrlTreeView *m_treeView;
};
#endif // HISTORYPANEL_H