aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow/subwindow.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-08-07 10:18:28 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-08-07 10:18:28 +0200
commite68dbcfd937a3de352152857ef9ad146a7c89bfc (patch)
tree751b0f1d6c7a223b19b06730fabc0cca478fa57d /src/mainwindow/subwindow.cpp
parentFix fullscreen toggle (diff)
downloadsmolbote-e68dbcfd937a3de352152857ef9ad146a7c89bfc.tar.xz
Move SubWindow to src/subwindow
Diffstat (limited to 'src/mainwindow/subwindow.cpp')
-rw-r--r--src/mainwindow/subwindow.cpp171
1 files changed, 0 insertions, 171 deletions
diff --git a/src/mainwindow/subwindow.cpp b/src/mainwindow/subwindow.cpp
deleted file mode 100644
index bdb852a..0000000
--- a/src/mainwindow/subwindow.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * 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 "subwindow.h"
-#include "browser.h"
-#include "webengine/webview.h"
-#include "widgets/tabwidget.h"
-#include <QAction>
-#include <QJsonArray>
-#include <QJsonDocument>
-#include <QJsonObject>
-#include <QMenu>
-#include <QShortcut>
-#include <QStyle>
-#include <QToolButton>
-#include <webprofile.h>
-#include "profilemanager.h"
-#include <configuration.h>
-
-SubWindow::SubWindow(const std::unique_ptr<Configuration> &config, 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);
-
- m_profile = WebProfile::defaultProfile();
-
- // system menu
- {
- auto *menu = systemMenu();
- menu->addSeparator();
-
- auto *profileName_action = menu->addAction(tr("Profile: %1").arg(m_profile->name()));
- profileName_action->setEnabled(false);
- auto *loadProfile_menu = menu->addMenu(tr("Load profile"));
-
- Browser *browser = qobject_cast<Browser *>(qApp);
- Q_CHECK_PTR(browser);
-
- ProfileIterator it(ProfileManager::profileList());
- while(it.hasNext()) {
- it.next();
- auto *profile =it.value();
- auto *loadAction = loadProfile_menu->addAction(profile->name());
-
- connect(loadAction, &QAction::triggered, this, [=]() {
- this->setProfile(profile);
- profileName_action->setText(tr("Profile: %1").arg(profile->name()));
- });
- }
- }
-
- // new tab button
- auto *newTab_button = new QToolButton(this);
- newTab_button->setIcon(style()->standardIcon(QStyle::SP_FileIcon));
- newTab_button->setToolTip(tr("Add tab"));
- newTab_button->setShortcut(QKeySequence(config->value<QString>("window.shortcuts.new").value()));
- connect(newTab_button, &QToolButton::clicked, this, [=]() {
- auto index = addTab(WebProfile::defaultProfile()->newtab());
- tabWidget->setCurrentIndex(index);
- });
- tabWidget->setCornerWidget(newTab_button, Qt::TopRightCorner);
-
- // general actions
- auto *closeTab_shortcut = new QShortcut(QKeySequence(config->value<QString>("window.shortcuts.close").value()), this);
- connect(closeTab_shortcut, &QShortcut::activated, this, [=]() {
- tabWidget->deleteTab(tabWidget->currentIndex());
- });
-
- auto *leftTab_shortcut = new QShortcut(QKeySequence(config->value<QString>("window.shortcuts.left").value()), this);
- connect(leftTab_shortcut, &QShortcut::activated, this, [=]() {
- tabWidget->setCurrentIndex(qMax(0, tabWidget->currentIndex() - 1));
- });
-
- auto *rightTab_shortcut = new QShortcut(QKeySequence(config->value<QString>("window.shortcuts.right").value()), this);
- connect(rightTab_shortcut, &QShortcut::activated, this, [=]() {
- tabWidget->setCurrentIndex(qMin(tabWidget->currentIndex() + 1, tabWidget->count() - 1));
- });
-
- auto *fullScreen_shortcut = new QShortcut(QKeySequence(config->value<QString>("window.shortcuts.fullscreen").value()), this);
- connect(fullScreen_shortcut, &QShortcut::activated, this, [=]() {
- auto *w = this->window();
- if(w->isFullScreen())
- w->showNormal();
- else
- w->showFullScreen();
- });
-
- 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);
- disconnect(linkHoveredConnection);
-
- titleConnection = connect(view, &WebView::titleChanged, this, [this](const QString &title) {
- auto *v = qobject_cast<WebView *>(sender());
- this->setWindowTitle(QString("%1 :%2").arg(title, v->profile()->name()));
- });
- setWindowTitle(QString("%1 :%2").arg(view->title(), view->profile()->name()));
-
- linkHoveredConnection = connect(view->page(), &WebPage::linkHovered, this, [this](const QString &url) {
- if(!url.isEmpty())
- emit showStatusMessage(url, 3000);
- });
-
- emit currentViewChanged(view);
- }
- });
-}
-
-SubWindow::~SubWindow()
-{
- delete tabWidget;
-}
-
-WebView *SubWindow::currentView()
-{
- return qobject_cast<WebView *>(tabWidget->currentWidget());
-}
-
-WebView *SubWindow::view(int index) const
-{
- return qobject_cast<WebView *>(tabWidget->widget(index));
-}
-
-int SubWindow::tabCount() const
-{
- return tabWidget->count();
-}
-
-void SubWindow::setProfile(WebProfile *profile)
-{
- Q_CHECK_PTR(profile);
- this->m_profile = profile;
- for(int i = 0; i < tabWidget->count(); ++i) {
- auto *view = qobject_cast<WebView *>(tabWidget->widget(i));
- view->setProfile(profile);
- }
-}
-
-WebProfile *SubWindow::profile() const
-{
- return m_profile;
-}
-
-int SubWindow::addTab(const QUrl &url, WebProfile *profile)
-{
- auto *view = new WebView((profile == nullptr) ? m_profile : profile, this);
- if(!url.isEmpty())
- view->load(url);
- return tabWidget->addTab(view);
-}
-
-void SubWindow::setCurrentTab(int index)
-{
- tabWidget->setCurrentIndex(index);
-}