Falkon Develop
Cross-platform Qt-based web browser
historysidebar.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "historysidebar.h"
19#include "ui_historysidebar.h"
20#include "browserwindow.h"
21#include "tabwidget.h"
22#include "tabbedwebview.h"
23#include "mainapplication.h"
24#include "qzsettings.h"
25#include "iconprovider.h"
26
28 : QWidget(parent)
29 , ui(new Ui::HistorySideBar)
30 , m_window(window)
31{
32 ui->setupUi(this);
33 ui->historyTree->setViewType(HistoryTreeView::HistorySidebarViewType);
34
35 connect(ui->historyTree, &HistoryTreeView::urlActivated, this, &HistorySideBar::urlActivated);
36 connect(ui->historyTree, &HistoryTreeView::urlCtrlActivated, this, &HistorySideBar::urlCtrlActivated);
37 connect(ui->historyTree, &HistoryTreeView::urlShiftActivated, this, &HistorySideBar::urlShiftActivated);
38 connect(ui->historyTree, &HistoryTreeView::contextMenuRequested, this, &HistorySideBar::createContextMenu);
39
40 connect(ui->search, &QLineEdit::textEdited, ui->historyTree, &HistoryTreeView::search);
41}
42
43void HistorySideBar::urlActivated(const QUrl &url)
44{
45 openUrl(url);
46}
47
48void HistorySideBar::urlCtrlActivated(const QUrl &url)
49{
50 openUrlInNewTab(url);
51}
52
53void HistorySideBar::urlShiftActivated(const QUrl &url)
54{
55 openUrlInNewWindow(url);
56}
57
58void HistorySideBar::openUrl(const QUrl &url)
59{
60 const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl();
61 m_window->weView()->load(u);
62}
63
64void HistorySideBar::openUrlInNewTab(const QUrl &url)
65{
66 const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl();
67 m_window->tabWidget()->addView(u, qzSettings->newTabPosition);
68}
69
70void HistorySideBar::openUrlInNewWindow(const QUrl &url)
71{
72 const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl();
73 mApp->createWindow(Qz::BW_NewWindow, u);
74}
75
76void HistorySideBar::openUrlInNewPrivateWindow(const QUrl &url)
77{
78 const QUrl u = !url.isEmpty() ? url : ui->historyTree->selectedUrl();
79 mApp->startPrivateBrowsing(u);
80}
81
82void HistorySideBar::createContextMenu(const QPoint &pos)
83{
84 QMenu menu;
85 QAction* actNewTab = menu.addAction(IconProvider::newTabIcon(), tr("Open in new tab"));
86 QAction* actNewWindow = menu.addAction(IconProvider::newWindowIcon(), tr("Open in new window"));
87 QAction* actNewPrivateWindow = menu.addAction(IconProvider::privateBrowsingIcon(), tr("Open in new private window"));
88
89 menu.addSeparator();
90 QAction* actDelete = menu.addAction(QIcon::fromTheme(QSL("edit-delete")), tr("Delete"));
91
92 connect(actNewTab, SIGNAL(triggered()), this, SLOT(openUrlInNewTab()));
93 connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openUrlInNewWindow()));
94 connect(actNewPrivateWindow, SIGNAL(triggered()), this, SLOT(openUrlInNewPrivateWindow()));
95 connect(actDelete, &QAction::triggered, ui->historyTree, &HistoryTreeView::removeSelectedItems);
96
97 if (ui->historyTree->selectedUrl().isEmpty()) {
98 actNewTab->setDisabled(true);
99 actNewWindow->setDisabled(true);
100 actNewPrivateWindow->setDisabled(true);
101 }
102
103 menu.exec(pos);
104}
105
106void HistorySideBar::showEvent(QShowEvent *event)
107{
108 QWidget::showEvent(event);
109 ui->search->setFocus();
110}
111
113{
114 delete ui;
115}
TabWidget * tabWidget() const
TabbedWebView * weView() const
~HistorySideBar() override
HistorySideBar(BrowserWindow *window, QWidget *parent=nullptr)
void urlCtrlActivated(const QUrl &url)
void urlShiftActivated(const QUrl &url)
void contextMenuRequested(const QPoint &point)
void urlActivated(const QUrl &url)
void search(const QString &string)
static QIcon privateBrowsingIcon()
static QIcon newWindowIcon()
static QIcon newTabIcon()
int addView(const LoadRequest &req, const Qz::NewTabPositionFlags &openFlags, bool selectLine=false, bool pinned=false)
Definition: tabwidget.cpp:314
void load(const QUrl &url)
Definition: webview.cpp:177
#define mApp
@ BW_NewWindow
Definition: qzcommon.h:67
#define QSL(x)
Definition: qzcommon.h:40
#define qzSettings
Definition: qzsettings.h:69