diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-04-16 17:07:36 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-04-16 17:07:36 +0200 |
commit | d796821f8304306dbe088701724243b39e8eb358 (patch) | |
tree | 836c85aa421db5c495e2b36f6a02cea924b6d919 /src/mainwindow/window.cpp | |
parent | Branch of Qt5.11 features (diff) | |
download | smolbote-d796821f8304306dbe088701724243b39e8eb358.tar.xz |
Multiple subwindows interface
Subwindows are similar to tab groups.
- Rewrote Browser and MainWindow, so they should be somewhat cleaner now
- Moved AboutDialog to lib/about
What's broken:
- loading bar
- search box
- address bar bookmark suggestions
- plugins
Diffstat (limited to 'src/mainwindow/window.cpp')
-rw-r--r-- | src/mainwindow/window.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/mainwindow/window.cpp b/src/mainwindow/window.cpp new file mode 100644 index 0000000..67397fe --- /dev/null +++ b/src/mainwindow/window.cpp @@ -0,0 +1,68 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/smolbote.hg + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "window.h" +#include "webengine/webprofile.h" +#include "webengine/webview.h" +#include "widgets/tabwidget.h" +#include <QUrl> + +Window::Window(QWidget *parent, Qt::WindowFlags flags) + : QMdiSubWindow(parent, flags) + , tabWidget(new TabWidget(this)) +{ + // delete this window when it closes + setAttribute(Qt::WA_DeleteOnClose, true); + + resize(800, 600); + setWidget(tabWidget); + + connect(tabWidget, &TabWidget::currentChanged, [this](int index) { + if(index < 0) { + // last tab has been closed + close(); + } else { + auto *view = dynamic_cast<WebView *>(tabWidget->widget(index)); + Q_CHECK_PTR(view); + + disconnect(titleConnection); + connect(view, &WebView::titleChanged, this, &Window::setWindowTitle); + setWindowTitle(view->title()); + + emit currentViewChanged(view); + } + }); +} + +Window::~Window() +{ + delete tabWidget; +} + +WebView *Window::currentView() +{ + return qobject_cast<WebView *>(tabWidget->currentWidget()); +} + +int Window::addTab(WebView *view) +{ + Q_CHECK_PTR(view); + return tabWidget->addTab(view); +} + +int Window::addTab(const QUrl &url) +{ + auto *view = new WebView(WebProfile::defaultProfile(), this); + view->load(url); + return tabWidget->addTab(view); +} + +void Window::swapToTab(int index) +{ + tabWidget->setCurrentIndex(index); +} |