aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-01-12 11:11:34 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-01-12 11:11:34 +0100
commit835d23f1f3b8cc3ada5005ac87bdcfe7029c8732 (patch)
treedae8b4045bb9ac991a2cd8bb124b5f60e4171d24 /src
parentMinor changes (diff)
downloadsmolbote-835d23f1f3b8cc3ada5005ac87bdcfe7029c8732.tar.xz
New Window action now works
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp6
-rw-r--r--src/browser.h2
-rw-r--r--src/main.cpp6
-rw-r--r--src/mainwindow.cpp11
-rw-r--r--src/mainwindow.h5
5 files changed, 16 insertions, 14 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index cc68174..2b35e21 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -21,12 +21,6 @@ Browser::~Browser()
m_windows.clear();
}
-
-QVector<MainWindow*> Browser::windows()
-{
- return m_windows;
-}
-
void Browser::addWindow(MainWindow *window)
{
if(m_windows.contains(window)) {
diff --git a/src/browser.h b/src/browser.h
index 938acda..38826f0 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -13,8 +13,6 @@ public:
explicit Browser(QString configPath, QObject *parent = 0);
~Browser();
- // what is windows() useful for?
- QVector<MainWindow*> windows();
void addWindow(MainWindow* window);
public slots:
diff --git a/src/main.cpp b/src/main.cpp
index f8c9c7d..a0ec78f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -26,12 +26,12 @@ int main(int argc, char *argv[])
if(parser.positionalArguments().length() > 0) {
QUrl url = QUrl::fromUserInput(parser.positionalArguments().at(0));
if(url.isValid()) {
- instance.addWindow(new MainWindow(url));
+ instance.addWindow(new MainWindow(&instance, url));
} else {
- instance.addWindow(new MainWindow());
+ instance.addWindow(new MainWindow(&instance));
}
} else {
- instance.addWindow(new MainWindow());
+ instance.addWindow(new MainWindow(&instance));
}
return app.exec();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 763d192..dea9f79 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -4,8 +4,9 @@
#include <QMenu>
#include <QCloseEvent>
#include <QMessageBox>
+#include "browser.h"
-MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) :
+MainWindow::MainWindow(Browser *instance, QUrl defaultUrl, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
navigationToolBar(new QToolBar(this)),
@@ -13,6 +14,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) :
tabBar(new WebViewTabBar(this)),
urlLineEdit(new QLineEdit(navigationToolBar))
{
+ browserInstance = instance;
Settings settings;
ui->setupUi(this);
@@ -21,8 +23,8 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) :
// Populate the menu bar
// Browser menu - with new window, new tab, open and quit
QMenu *browserMenu = new QMenu(qApp->applicationName(), ui->menuBar);
+ browserMenu->addAction(tr("New Window"), this, SLOT(handleNewWindow()), QKeySequence(tr("Ctrl+N")));
browserMenu->addAction(tr("New Tab"), this, SLOT(createNewTab()), QKeySequence(tr("Ctrl+T")));
- browserMenu->addAction(tr("New Window"));
browserMenu->addSeparator();
browserMenu->addAction(tr("Quit"), qApp, SLOT(quit()), QKeySequence(tr("Ctrl+Q")));
ui->menuBar->addMenu(browserMenu);
@@ -70,6 +72,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
QMainWindow::closeEvent(event);
}
+void MainWindow::handleNewWindow(const QUrl &url)
+{
+ browserInstance->addWindow(new MainWindow(browserInstance, url));
+}
+
void MainWindow::handleTabChanged(QWebEngineView *view)
{
centralWidget()->setParent(0);
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 48ce43f..7371759 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -12,12 +12,13 @@ namespace Ui {
class MainWindow;
}
+class Browser;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
- explicit MainWindow(QUrl defaultUrl = QUrl(""), QWidget *parent = 0);
+ explicit MainWindow(Browser *instance, QUrl defaultUrl = QUrl(""), QWidget *parent = 0);
~MainWindow();
public slots:
@@ -27,12 +28,14 @@ protected:
void closeEvent(QCloseEvent *event) override;
private slots:
+ void handleNewWindow(const QUrl &url = QUrl(""));
void handleTabChanged(QWebEngineView *view);
void handleUrlChanged();
void handleUrlUpdated(const QUrl &url);
void handleTitleUpdated(const QString &title);
private:
+ Browser *browserInstance;
Ui::MainWindow *ui;
QToolBar *navigationToolBar, *tabToolBar;
WebViewTabBar *tabBar;