1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
#include "browsertab.hpp"
#include <memory>
#include <QShortcut>
#include <QKeySequence>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
settings("xqTechnologies", "Kristall"),
ui(new Ui::MainWindow),
url_status(new QLabel())
{
ui->setupUi(this);
this->statusBar()->addWidget(this->url_status);
this->favourites.load(settings);
this->current_style.load(settings);
ui->favourites_view->setModel(&favourites);
// this->ui->history_window->setVisible(false);
this->ui->clientcert_window->setVisible(false);
this->ui->bookmarks_window->setVisible(true);
auto add_shortcut = [this](QString const & sequence, void (MainWindow::*fun)())
{
auto * shortcut = new QShortcut(QKeySequence(sequence), this);
connect(shortcut, &QShortcut::activated, this, fun);
};
add_shortcut("Ctrl+T", &MainWindow::on_new_tab);
add_shortcut("Ctrl+W", &MainWindow::on_close_tab);
add_shortcut("F5", &MainWindow::on_refresh);
}
MainWindow::~MainWindow()
{
this->favourites.save(settings);
this->current_style.save(settings);
delete ui;
}
BrowserTab * MainWindow::addEmptyTab(bool focus_new)
{
BrowserTab * tab = new BrowserTab(this);
connect(tab, &BrowserTab::titleChanged, this, &MainWindow::on_tab_titleChanged);
int index = this->ui->browser_tabs->addTab(tab, "Page");
if(focus_new) {
this->ui->browser_tabs->setCurrentIndex(index);
}
return tab;
}
BrowserTab * MainWindow::addNewTab(bool focus_new, QUrl const & url)
{
auto tab = addEmptyTab(focus_new);
tab->navigateTo(url, BrowserTab::PushImmediate);
return tab;
}
void MainWindow::setUrlPreview(const QUrl &url)
{
if(url.isValid()) {
auto str = url.toString();
if(str.length() > 300) {
str = str.mid(0, 300) + "...";
}
this->url_status->setText(str);
}
else {
this->url_status->setText("");
}
}
void MainWindow::on_browser_tabs_currentChanged(int index)
{
if(index >= 0) {
BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->widget(index));
if(tab != nullptr) {
this->ui->outline_view->setModel(&tab->outline);
this->ui->outline_view->expandAll();
this->ui->history_view->setModel(&tab->history);
} else {
this->ui->outline_view->setModel(nullptr);
this->ui->history_view->setModel(nullptr);
}
} else {
this->ui->outline_view->setModel(nullptr);
this->ui->history_view->setModel(nullptr);
}
}
void MainWindow::on_favourites_view_doubleClicked(const QModelIndex &index)
{
if(auto url = this->favourites.get(index); url.isValid()) {
this->addNewTab(true, url);
}
}
void MainWindow::on_browser_tabs_tabCloseRequested(int index)
{
delete this->ui->browser_tabs->widget(index);
}
void MainWindow::on_history_view_doubleClicked(const QModelIndex &index)
{
BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget());
if(tab != nullptr) {
tab->navigateBack(index);
}
}
void MainWindow::on_tab_titleChanged(const QString &title)
{
auto * tab = qobject_cast<BrowserTab*>(sender());
if(tab != nullptr) {
int index = this->ui->browser_tabs->indexOf(tab);
assert(index >= 0);
this->ui->browser_tabs->setTabText(index, title);
}
}
void MainWindow::on_tab_locationChanged(const QUrl &url)
{
auto * tab = qobject_cast<BrowserTab*>(sender());
if(tab != nullptr) {
int index = this->ui->browser_tabs->indexOf(tab);
assert(index >= 0);
this->ui->browser_tabs->setTabToolTip(index, url.toString());
}
}
void MainWindow::on_new_tab()
{
this->addEmptyTab(true);
}
void MainWindow::on_refresh()
{
BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget());
if(tab != nullptr) {
// tab->reloadPage();
}
}
void MainWindow::on_close_tab()
{
BrowserTab * tab = qobject_cast<BrowserTab*>(this->ui->browser_tabs->currentWidget());
if(tab != nullptr) {
delete tab;
}
}
|