-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
140 lines (115 loc) · 4.74 KB
/
mainwindow.cpp
File metadata and controls
140 lines (115 loc) · 4.74 KB
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
// Copyright (C) 2025 Mohit Deoli
// SPDX-License-Identifier: GPL-3.0-only
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
/*, ui(new Ui::MainWindow)*/
{
/*
MainWindow (QMainWindow)
└── centralWidget (QWidget)
└── QVBoxLayout (centralLayout)
├── tabBar (TabBar)
├── navigationBar (NavigationBar)
└── webAreaLayout (WebAreaLayoutWidget)
└── WebAreaLayoutManager
└── multiple WebEngineView
*/
// this->setWindowFlags(Qt::Popup);
// this->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
// ui->setupUi(this);
QWidget* centralWidget = new QWidget(this);
QVBoxLayout* centralLayout = new QVBoxLayout(centralWidget);
centralWidget->setLayout(centralLayout);
tabBar = new TabBar(centralWidget);
// tabBar = new FramelessWindow<TabBar>(false, centralWidget);
navigationBar = new NavigationBar(centralWidget);
webAreaLayout = new WebAreaLayoutWidget(centralWidget);
centralLayout->setContentsMargins(0,0,0,0);
centralLayout->setSpacing(0);
centralLayout->addWidget(tabBar);
centralLayout->addWidget(navigationBar);
centralLayout->addWidget(webAreaLayout);
connect(tabBar, &TabBar::newTabAdded, this, &MainWindow::onNewTabAdded);
connect(tabBar, &TabBar::tabClosed, this, &MainWindow::onTabClosed);
connect(tabBar, &TabBar::tabSelected, this, &MainWindow::onTabSelected);
connect(navigationBar, &NavigationBar::searchRequested, this, &MainWindow::onSearchRequested);
connect(navigationBar, &NavigationBar::pageBack, this, [this](){
webAreaLayout->goBack();
});
connect(navigationBar, &NavigationBar::pageForward, this, [this](){
webAreaLayout->goForward();
});
connect(navigationBar, &NavigationBar::pageReload, this, [this](){
webAreaLayout->goBack();
});
connect(navigationBar, &NavigationBar::layoutChanged, this, &MainWindow::onWebAreaLayoutChanged);
connect(webAreaLayout, &WebAreaLayoutWidget::webViewUrlChanged, navigationBar, &NavigationBar::setSearchbarText);
connect(webAreaLayout, &WebAreaLayoutWidget::webViewTitleChanged, this, [this](int index, const QString &new_title){
tabBar->setTabTitle(index, new_title);
});
connect(webAreaLayout, &WebAreaLayoutWidget::webViewFaviconChanged, this, [this](int index, const QIcon &favicon){
tabBar->setTabFavicon(index, favicon.pixmap(12,12));
});
connect(webAreaLayout, &WebAreaLayoutWidget::backButtonState, this, [this](bool enabled){
navigationBar->setBackButtonState(enabled);
});
connect(webAreaLayout, &WebAreaLayoutWidget::forwardButtonState, this, [this](bool enabled){
navigationBar->setForwardButtonState(enabled);
});
connect(webAreaLayout, &WebAreaLayoutWidget::message, this, [this](const QString &text){
navigationBar->setMessage(text);
});
connect(webAreaLayout, &WebAreaLayoutWidget::layoutChanged, this, [this](int layout){
navigationBar->setLayoutControllerIndex(layout);
});
this->setCentralWidget(centralWidget);
this->showMaximized();
// default tab
tabBar->addNewTab();
// this->setWindowFlags(Qt::FramelessWindowHint);
// TODO : Make window frameless and add ability to make it move, resize from corners
// setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
}
MainWindow::~MainWindow()
{
// delete ui;
}
void MainWindow::onSearchRequested(const QUrl &url){
qDebug() << url ;
webAreaLayout->loadUrl(url);
}
void MainWindow::onNewTabAdded(int tabIndex){
webAreaLayout->addNewWebView(tabIndex);
}
void MainWindow::onTabSelected(int tabIndex){
if(tabIndex >= 0){
webAreaLayout->setCurrentWebView(tabIndex);
navigationBar->setSearchbarText(webAreaLayout->currentUrl().toDisplayString());
tabBar->setCurrentTab(tabIndex);
}else{
qDebug() << "select tab : tab out of index!";
}
}
void MainWindow::onTabClosed(int tabIndex){
if(tabIndex >= 0){
webAreaLayout->closeWebView(tabIndex);
if(webAreaLayout->webviewVectorSize() == 0){
tabBar->addNewTab();
// TODO : CLOSE APPLICATION INSTEAD
qDebug() << "new tab added when none left";
}
onTabSelected((tabIndex-1)>=0?(tabIndex-1):0);
}else{
qDebug() << "Delete tab: tab out of index!";
}
}
void MainWindow::onWebAreaLayoutChanged(int layout){
// 0 = single view, 1 = split view, 2 = grid view, 3 = popup view
// LayoutMode mode = static_cast<LayoutMode>(layout);
webAreaLayout->setLayoutMode(layout);
}
// TODO : remove .ui file listing from CMake
// Custom theming