aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-04-03 21:23:35 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-04-03 21:23:35 +0300
commit6e1d411f9218645851f0dde54688739390b62736 (patch)
tree7cc4af0155a3ce9dc5a0fb4014975b0aa9d2d165
parentFix various compiler warnings (diff)
downloadsmolbote-6e1d411f9218645851f0dde54688739390b62736.tar.xz
Remove QMdiArea in MainWindow
Kconfig: Change About Dialog shortcut default to F1 (was Ctrl+H) Change close current tab shortcut to Ctrl+W (was Ctrl+X) MainWindow: automatically close window when last subwindow is closed MenuBar: remove Tile/Cascade subwindows actions add show/hide/close subwindow actions SubWindow: remove Subwindow menu shortcut (was F1 by default) add close shortcut (default Ctrl+Shift+W) Minor fixes: Fix PKGBUILD sources
-rw-r--r--Kconfig16
-rw-r--r--linux/makepkg/PKGBUILD6
-rw-r--r--src/mainwindow/addressbar.cpp31
-rw-r--r--src/mainwindow/addressbar.h12
-rw-r--r--src/mainwindow/mainwindow.cpp190
-rw-r--r--src/mainwindow/mainwindow.h32
-rw-r--r--src/mainwindow/menubar.cpp106
-rw-r--r--src/mainwindow/menubar.h1
-rw-r--r--src/mainwindow/widgets/urllineedit.cpp2
-rw-r--r--src/subwindow/subwindow.cpp79
-rw-r--r--src/subwindow/subwindow.h73
11 files changed, 229 insertions, 319 deletions
diff --git a/Kconfig b/Kconfig
index a7daf09..37d3d9c 100644
--- a/Kconfig
+++ b/Kconfig
@@ -26,7 +26,7 @@ menu "Keyboard shortcuts"
default "Ctrl+N"
config shortcuts.window.about
string "Show About Dialog"
- default "Ctrl+H"
+ default "F1"
config shortcuts.window.quit
string "Quit shortcut"
default "Ctrl+Q"
@@ -72,15 +72,9 @@ menu "Keyboard shortcuts"
default "F2"
comment "Subwindow shortcuts"
- config shortcuts.subwindow.menu
- string "Subwindow context menu"
- default "F1"
- config shortcuts.subwindow.tile
- string "Tile subwindows"
- default "F9"
- config shortcuts.subwindow.cascade
- string "Cascade subwindow"
- default "F10"
+ config shortcuts.subwindow.close
+ string "Close Subwindow shortcut"
+ default "Ctrl+Shift+W"
config shortcuts.subwindow.fullscreen
string "Make current subwindow fullscreen"
default "F11"
@@ -89,7 +83,7 @@ menu "Keyboard shortcuts"
default "Ctrl+T"
config shortcuts.subwindow.closetab
string "Close current tab"
- default "Ctrl+X"
+ default "Ctrl+W"
config shortcuts.subwindow.restoretab
string "Restore last closed tab"
default "Ctrl+Shift+T"
diff --git a/linux/makepkg/PKGBUILD b/linux/makepkg/PKGBUILD
index 18f9ebe..3f10589 100644
--- a/linux/makepkg/PKGBUILD
+++ b/linux/makepkg/PKGBUILD
@@ -1,17 +1,13 @@
# Maintainer: Aqua-sama <aqua at iserlohn-fortress dot net>
-
## not-use flags
# Enable plugin signing:
_signPlugins=0
# Enable breakpad integraton:
_enableBreakpad=0
-# test
-_test=1
# install prefix
_prefix='/usr/local'
-
pkgname=smolbote-git
pkgdesc='Yet another no-frills browser'
pkgver=0
@@ -37,7 +33,7 @@ options=(!buildflags)
# use git+file:///path/to/your/repo to build from a local repo
source=("git+https://library.iserlohn-fortress.net/aqua/smolbote.git"
- "git+https://github.com/itay-grudev/SingleApplication.git"
+ "git+https://library.iserlohn-fortress.net/aqua/SingleApplication.git"
"git+https://github.com/Taywee/args")
sha512sums=('SKIP'
diff --git a/src/mainwindow/addressbar.cpp b/src/mainwindow/addressbar.cpp
index b1d005a..d37a6a7 100644
--- a/src/mainwindow/addressbar.cpp
+++ b/src/mainwindow/addressbar.cpp
@@ -10,6 +10,7 @@
#include "ui_addressbar.h"
#include <QShortcut>
#include "configuration.h"
+#include "webengine/webview.h"
AddressBar::AddressBar(QWidget *parent)
: QWidget(parent)
@@ -42,22 +43,30 @@ AddressBar::AddressBar(QWidget *parent)
} else {
emit search(ui->urlBar->text());
}
+ ui->urlBar->clearFocus();
});
}
-AddressBar::~AddressBar()
+void AddressBar::connectView(WebView *view)
{
- disconnect(this);
-}
+ disconnect(url_connection);
+ disconnect(progress_connection);
+ disconnect(search_connection);
+ disconnect(load_connection);
+ disconnect(focus_connection);
-void AddressBar::setUrl(const QUrl &url)
-{
- if(url.isEmpty())
+ if(view == nullptr) {
ui->urlBar->clear();
- else
- ui->urlBar->setUrl(url);
-}
+ ui->loadingBar->setValue(100);
+ } else {
+ ui->urlBar->setUrl(view->url());
+ ui->loadingBar->setValue(100);
+ url_connection = connect(view, &WebView::urlChanged, ui->urlBar, &UrlLineEdit::setUrl);
+ progress_connection = connect(view, &WebView::loadProgress, ui->loadingBar, &QProgressBar::setValue);
-void AddressBar::setProgress(int value) {
- ui->loadingBar->setValue(std::min(value, 100));
+ search_connection = connect(this, &AddressBar::search, view, &WebView::search);
+ load_connection = connect(this, &AddressBar::load, view, qOverload<const QUrl &>(&WebView::load));
+ focus_connection = connect(this, &AddressBar::giveFocus, view, qOverload<>(&WebView::setFocus));
+ }
}
+
diff --git a/src/mainwindow/addressbar.h b/src/mainwindow/addressbar.h
index 61d00e9..874aaa6 100644
--- a/src/mainwindow/addressbar.h
+++ b/src/mainwindow/addressbar.h
@@ -16,13 +16,14 @@ namespace Ui {
class AddressBar;
}
+class WebView;
class AddressBar : public QWidget
{
Q_OBJECT
public:
AddressBar(QWidget *parent = nullptr);
- ~AddressBar() override;
+ ~AddressBar() = default;
signals:
void complete(const QString &term, std::function<void(QStringList &)> callback);
@@ -32,11 +33,16 @@ signals:
void giveFocus();
public slots:
- void setUrl(const QUrl &url);
- void setProgress(int value);
+ void connectView(WebView *view);
private:
Ui::AddressBar *ui;
+
+ QMetaObject::Connection url_connection;
+ QMetaObject::Connection progress_connection;
+ QMetaObject::Connection search_connection;
+ QMetaObject::Connection focus_connection;
+ QMetaObject::Connection load_connection;
};
#endif // SMOLBOTE_ADDRESSBAR_H
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 36f2759..b607a63 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -13,61 +13,31 @@
#include "browser.h"
#include "configuration.h"
#include "menubar.h"
-#include "session/session.h"
-#include "session/sessiondialog.h"
-#include "subwindow/subwindow.h"
#include "webengine/webprofile.h"
-#include "webengine/webprofilemanager.h"
#include "webengine/webview.h"
#include "widgets/dockwidget.h"
#include "widgets/navigationbar.h"
#include "widgets/searchform.h"
#include <QApplication>
#include <QCloseEvent>
-#include <QFileDialog>
-#include <QJsonArray>
-#include <QJsonObject>
-#include <QLineEdit>
-#include <QMdiArea>
-#include <QMdiSubWindow>
-#include <QMenuBar>
#include <QMessageBox>
-#include <QShortcut>
#include <QStatusBar>
-#include <QToolBar>
-#include <QUrl>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
- , mdiArea(new QMdiArea(this))
{
Configuration config;
// create UI
- setWindowTitle(config.value<QString>("mainwindow.title").value());
+ defaultWindowTitle = config.value<QString>("mainwindow.title").value();
+ setWindowTitle(defaultWindowTitle);
resize(config.value<int>("mainwindow.width").value(), config.value<int>("mainwindow.height").value());
if(config.value<bool>("mainwindow.maximized").value_or(false)) {
setWindowState(Qt::WindowMaximized);
}
show();
- // current subwindow shortcut
- {
- QAction *subwindowMenuAction = new QAction(this);
- QMainWindow::addAction(subwindowMenuAction);
- config.shortcut<QAction>(*subwindowMenuAction, "shortcuts.subwindow.menu");
- connect(subwindowMenuAction, &QAction::triggered, this, [this]() {
- QMdiSubWindow *window = mdiArea->currentSubWindow();
- if(window != nullptr) {
- // show the menu at the subwindow position
- // position has to be global, and mapped by the mdiArea (parentWidget() of the subwindow)
- const auto position = mdiArea->mapToGlobal(window->pos());
- window->systemMenu()->exec(position);
- }
- });
- }
-
navigationToolBar = new NavigationBar(this);
navigationToolBar->setMovable(config.value<bool>("navigation.movable").value_or(false));
addToolBar(Qt::TopToolBarArea, navigationToolBar);
@@ -83,80 +53,20 @@ MainWindow::MainWindow(QWidget *parent)
m_menuBar = new MenuBar(this);
this->setMenuBar(m_menuBar);
- mdiArea->setBackground(Qt::NoBrush);
- setCentralWidget(mdiArea);
- mdiArea->setFocus();
-
// status bar
searchBox = new SearchForm(this);
statusBar()->addPermanentWidget(searchBox);
searchBox->setVisible(false);
- // connect signlas
- connect(mdiArea, &QMdiArea::subWindowActivated, this, [this](QMdiSubWindow *window) {
- disconnect(viewChangedConnection);
- disconnect(searchBoxConnection);
- disconnect(statusBarConnection);
-
- auto *w = qobject_cast<SubWindow *>(window);
- if(w == nullptr) {
- // no current subwindow, clear everything
- setView(nullptr);
- } else {
- setView(w->currentView());
- viewChangedConnection = connect(w, &SubWindow::currentViewChanged, this, &MainWindow::setView);
- statusBarConnection = connect(w, &SubWindow::showStatusMessage, statusBar(), &QStatusBar::showMessage);
- }
- });
-
- // address bar
- connect(addressBar, &AddressBar::search, this, [this](const QString &term) {
- if(this->currentView != nullptr) {
- currentView->search(term);
- currentView->setFocus();
- }
- });
- connect(addressBar, &AddressBar::load, this, [this](const QUrl &url) {
- if(this->currentView != nullptr) {
- currentView->load(url);
- currentView->setFocus();
- }
- });
-
- connect(addressBar, &AddressBar::giveFocus, this, [this]() {
- if(this->currentView != nullptr) {
- currentView->setFocus();
- }
- });
-
// search box
auto *searchAction = new QAction(this);
config.shortcut<QAction>(*searchAction, "shortcuts.window.search");
connect(searchAction, &QAction::triggered, this, [this]() {
- /* QTBUG-18665
- * When focusing out of the search box and hiding it, the first
- * (or earlier?) subwindow gets activated for some reason.
- */
- if(searchBox->isVisible()) {
- auto *w = mdiArea->currentSubWindow();
- searchBox->hide();
- mdiArea->setActiveSubWindow(w);
- } else {
- searchBox->show();
- }
+ searchBox->setVisible(!searchBox->isVisible());
});
QMainWindow::addAction(searchAction);
}
-MainWindow::~MainWindow()
-{
- disconnect(viewChangedConnection);
- disconnect(searchBoxConnection);
- disconnect(statusBarConnection);
-
- disconnect(addressBar);
-}
-
void MainWindow::addDockWidget(Qt::DockWidgetArea area, QWidget *widget)
{
QDockWidget *lastDock = nullptr;
@@ -189,49 +99,34 @@ void MainWindow::removeDockWidget(QWidget *widget)
void MainWindow::createTab(const QUrl &url)
{
- auto *w = qobject_cast<SubWindow *>(mdiArea->currentSubWindow());
+ auto *w = qobject_cast<SubWindow *>(centralWidget());
if(w != nullptr) {
w->addTab(url);
}
}
-const QVector<SubWindow *> MainWindow::subWindows() const
-{
- QVector<SubWindow *> list;
- const auto subwindows = mdiArea->subWindowList();
- for(auto *w : subwindows) {
- auto *subwindow = qobject_cast<SubWindow *>(w);
- if(subwindow != nullptr)
- list.append(subwindow);
- }
-
- return list;
-}
-
-SubWindow *MainWindow::currentSubWindow() const
-{
- return qobject_cast<SubWindow *>(mdiArea->currentSubWindow());
-}
-
SubWindow *MainWindow::createSubWindow(WebProfile *profile, bool openProfileNewtab)
{
- bool shouldMaximize = true;
- // if there is a current window, use its maximize state
- if(auto *currentWindow = qobject_cast<SubWindow *>(mdiArea->currentSubWindow()); currentWindow != nullptr) {
- shouldMaximize = currentWindow->isMaximized();
- }
-
auto *w = new SubWindow(this);
+ w->setProfile(profile);
+ m_subwindows.append(w);
+ setCurrentSubWindow(w);
m_menuBar->insertSubWindow(w);
- w->setProfile(profile);
- mdiArea->addSubWindow(w);
- if(shouldMaximize)
- w->showMaximized();
- else
- w->show();
+ connect(w, &SubWindow::windowTitleChanged, this, [this, w](const QString &title) {
+ if(w == currentSubWindow())
+ setWindowTitle(QString("[%1] - %2").arg(title, defaultWindowTitle));
+ });
- w->setFocus();
+ connect(w, &SubWindow::aboutToClose, this, [this, w]() {
+ m_subwindows.removeAll(w);
+ if(m_subwindows.isEmpty()) {
+ close();
+ } else {
+ setCurrentSubWindow(m_subwindows.last());
+ w->deleteLater();
+ }
+ });
if(openProfileNewtab)
w->addTab(w->profile()->newtab());
@@ -239,43 +134,42 @@ SubWindow *MainWindow::createSubWindow(WebProfile *profile, bool openProfileNewt
return w;
}
-void MainWindow::setView(WebView *view)
+void MainWindow::setCurrentSubWindow(SubWindow *subwindow)
{
- if(currentView != nullptr) {
- // disconnect old view
- disconnect(currentView, nullptr, addressBar, nullptr);
+ auto *previous = centralWidget();
+ if(previous != nullptr) {
+ previous->setParent(nullptr);
+ previous->hide();
}
- currentView = view;
-
- if(view != nullptr) {
- connect(view, &WebView::urlChanged, addressBar, &AddressBar::setUrl);
- addressBar->setUrl(view->url());
+ setCentralWidget(subwindow);
+ subwindow->show();
+ subwindow->setFocus();
+ setWindowTitle(QString("[%1] - %2").arg(subwindow->windowTitle(), defaultWindowTitle));
- connect(view, &WebView::loadProgress, addressBar, &AddressBar::setProgress);
- addressBar->setProgress(100);
+ // connect signlas
+ disconnect(viewChangedConnection);
+ disconnect(statusBarConnection);
- } else {
- addressBar->setUrl(QUrl());
- addressBar->setProgress(100);
- }
+ setView(subwindow->currentView());
+ viewChangedConnection = connect(subwindow, &SubWindow::currentViewChanged, this, &MainWindow::setView);
+ statusBarConnection = connect(subwindow, &SubWindow::showStatusMessage, statusBar(), &QStatusBar::showMessage);
+}
+void MainWindow::setView(WebView *view)
+{
+ addressBar->connectView(view);
navigationToolBar->connectWebView(view);
searchBox->setView(view);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
- if(mdiArea->subWindowList().count() > 1) {
- int choice = QMessageBox::question(this, tr("Close multiple subwindows?"), tr("Do you want to close all subwindows?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ if(m_subwindows.count() > 1) {
+ const int choice = QMessageBox::question(this, tr("Close multiple subwindows?"), tr("Do you want to close all subwindows?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if(choice == QMessageBox::No) {
event->ignore();
return;
}
}
-
- mdiArea->closeAllSubWindows();
- if(mdiArea->currentSubWindow() != nullptr)
- event->ignore();
- else
- event->accept();
+ event->accept();
}
diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h
index dc185da..98bd6ee 100644
--- a/src/mainwindow/mainwindow.h
+++ b/src/mainwindow/mainwindow.h
@@ -9,24 +9,20 @@
#ifndef SMOLBOTE_MAINWINDOW_H
#define SMOLBOTE_MAINWINDOW_H
+#include "subwindow/subwindow.h"
#include <QMainWindow>
#include <QUrl>
-#include <memory>
class Browser;
-class QMdiArea;
-class Configuration;
-class SubWindow;
class AddressBar;
class SearchForm;
class WebView;
class NavigationBar;
class WebProfile;
class MenuBar;
-class MainWindow : public QMainWindow
+class MainWindow final : public QMainWindow
{
friend class Browser;
- friend class MenuBar;
Q_OBJECT
@@ -36,18 +32,29 @@ public:
};
explicit MainWindow(QWidget *parent = nullptr);
- Q_DISABLE_COPY(MainWindow)
- ~MainWindow() override;
+ MainWindow(const MainWindow &) = delete;
+ ~MainWindow() = default;
void addDockWidget(Qt::DockWidgetArea area, QWidget *widget);
void removeDockWidget(QWidget *widget);
- const QVector<SubWindow *> subWindows() const;
- SubWindow *currentSubWindow() const;
+ [[nodiscard]] const QVector<SubWindow *> subWindows() const
+ {
+ return m_subwindows;
+ }
+ [[nodiscard]] SubWindow *currentSubWindow() const
+ {
+ return qobject_cast<SubWindow *>(centralWidget());
+ }
+ [[nodiscard]] WebView *currentView() const
+ {
+ return currentSubWindow()->currentView();
+ }
public slots:
void createTab(const QUrl &url);
SubWindow *createSubWindow(WebProfile *profile = nullptr, bool openProfileNewtab = false);
+ void setCurrentSubWindow(SubWindow *subwindow);
private slots:
void setView(WebView *view);
@@ -56,6 +63,7 @@ protected:
void closeEvent(QCloseEvent *event) override;
private:
+ QString defaultWindowTitle;
MenuBar *m_menuBar = nullptr;
QMenu *toolsMenu = nullptr;
QMenu *pageLoadProfileMenu = nullptr;
@@ -64,11 +72,9 @@ private:
AddressBar *addressBar = nullptr;
SearchForm *searchBox = nullptr;
- QMdiArea *mdiArea;
- WebView *currentView = nullptr;
+ QVector<SubWindow *> m_subwindows;
QMetaObject::Connection viewChangedConnection;
- QMetaObject::Connection searchBoxConnection;
QMetaObject::Connection statusBarConnection;
};
diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp
index 7a2bedc..c0bda61 100644
--- a/src/mainwindow/menubar.cpp
+++ b/src/mainwindow/menubar.cpp
@@ -71,6 +71,7 @@ inline QDialog *createDevToolsDialog(QWebEnginePage *page)
MenuBar::MenuBar(MainWindow *parent)
: QMenuBar(parent)
{
+ m_parent = parent;
auto *browser = qobject_cast<Browser *>(qApp);
Q_CHECK_PTR(browser);
Configuration conf;
@@ -162,11 +163,10 @@ MenuBar::MenuBar(MainWindow *parent)
});
conf.shortcut<QAction>(*actionNewSubwindow, "shortcuts.window.newgroup");
- auto *actionTileSubwindows = window->addAction(tr("Tile Subwindows"), parent->mdiArea, &QMdiArea::tileSubWindows);
- conf.shortcut<QAction>(*actionTileSubwindows, "shortcuts.subwindow.tile");
-
- auto *actionCascadeSubwindows = window->addAction(tr("Cascade Subwindows"), parent->mdiArea, &QMdiArea::cascadeSubWindows);
- conf.shortcut<QAction>(*actionCascadeSubwindows, "shortcuts.subwindow.cascade");
+ auto *actionCloseSubwindow = window->addAction(tr("Close Subwindow"), parent, [parent]() {
+ parent->currentSubWindow()->close();
+ });
+ conf.shortcut<QAction>(*actionCloseSubwindow, "shortcuts.subwindow.close");
window->addSeparator()->setText(tr("Toolbars"));
@@ -378,22 +378,22 @@ MenuBar::MenuBar(MainWindow *parent)
auto *page = this->addMenu(tr("&Page"));
{
page->addAction(tr("Create Bookmark"), parent, [browser, parent]() {
- if(parent->currentView != nullptr)
- browser->bookmarks()->addBookmark(parent->currentView->title(), parent->currentView->url().toString());
+ if(parent->currentView() != nullptr)
+ browser->bookmarks()->addBookmark(parent->currentView()->title(), parent->currentView()->url().toString());
});
page->addSeparator();
page->addAction(tr("Save"), parent, [parent]() {
- if(parent->currentView != nullptr)
- parent->currentView->triggerPageAction(QWebEnginePage::SavePage);
+ if(parent->currentView() != nullptr)
+ parent->currentView()->triggerPageAction(QWebEnginePage::SavePage);
});
page->addAction(tr("Print"), parent, [parent]() {
- if(parent->currentView != nullptr) {
+ if(parent->currentView() != nullptr) {
auto *printer = new QPrinter(QPrinterInfo::defaultPrinter());
QPrintDialog dlg(printer, parent);
if(dlg.exec() == QDialog::Accepted) {
- parent->currentView->page()->print(printer, [printer](bool success) {
+ parent->currentView()->page()->print(printer, [printer](bool success) {
Q_UNUSED(success);
delete printer;
});
@@ -402,9 +402,9 @@ MenuBar::MenuBar(MainWindow *parent)
});
page->addAction(tr("Print to PDF"), parent, [parent]() {
- if(parent->currentView != nullptr) {
+ if(parent->currentView() != nullptr) {
const QString path = QFileDialog::getSaveFileName(parent, tr("Print to PDF"), QDir::homePath(), tr("PDF files (*.pdf)"));
- parent->currentView->page()->printToPdf(path);
+ parent->currentView()->page()->printToPdf(path);
}
});
@@ -414,32 +414,32 @@ MenuBar::MenuBar(MainWindow *parent)
connect(pageProfile, &QMenu::aboutToShow, pageProfile, [=]() {
pageProfile->clear();
- if(parent->currentView != nullptr) {
+ if(parent->currentView() != nullptr) {
profileMenu(
pageProfile, [parent](WebProfile *profile) {
- parent->currentView->setProfile(profile);
+ parent->currentView()->setProfile(profile);
},
- parent->currentView->profile(), true);
+ parent->currentView()->profile(), true);
}
});
page->addSeparator();
page->addAction(tr("Developer Tools"), parent, [parent]() {
- if(parent->currentView != nullptr) {
- auto *dlg = createDevToolsDialog(parent->currentView->page());
+ if(parent->currentView() != nullptr) {
+ auto *dlg = createDevToolsDialog(parent->currentView()->page());
dlg->show();
}
});
page->addAction(tr("View Source"), parent, [parent]() {
- if(parent->currentView != nullptr) {
- parent->currentView->triggerPageAction(QWebEnginePage::ViewSource);
+ if(parent->currentView() != nullptr) {
+ parent->currentView()->triggerPageAction(QWebEnginePage::ViewSource);
}
});
#ifdef QT_DEBUG
// doesn't seem to do anything?
page->addAction(tr("Inspect Element"), parent, [parent]() {
- if(parent->currentView != nullptr) {
- parent->currentView->triggerPageAction(QWebEnginePage::InspectElement);
+ if(parent->currentView() != nullptr) {
+ parent->currentView()->triggerPageAction(QWebEnginePage::InspectElement);
}
});
#endif
@@ -450,77 +450,77 @@ MenuBar::MenuBar(MainWindow *parent)
auto *edit = this->addMenu(tr("Edit"));
{
edit->addAction(tr("Undo"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::Undo);
+ trigger_if(parent->currentView(), QWebEnginePage::Undo);
});
edit->addAction(tr("Redo"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::Redo);
+ trigger_if(parent->currentView(), QWebEnginePage::Redo);
});
edit->addSeparator();
edit->addAction(tr("Cut"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::Cut);
+ trigger_if(parent->currentView(), QWebEnginePage::Cut);
});
edit->addAction(tr("Copy"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::Copy);
+ trigger_if(parent->currentView(), QWebEnginePage::Copy);
});
edit->addAction(tr("Paste"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::Paste);
+ trigger_if(parent->currentView(), QWebEnginePage::Paste);
});
edit->addAction(tr("Paste and match Style"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::PasteAndMatchStyle);
+ trigger_if(parent->currentView(), QWebEnginePage::PasteAndMatchStyle);
});
edit->addSeparator();
edit->addAction(tr("Select all"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::SelectAll);
+ trigger_if(parent->currentView(), QWebEnginePage::SelectAll);
});
edit->addAction(tr("Clear selection"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::Unselect);
+ trigger_if(parent->currentView(), QWebEnginePage::Unselect);
});
edit->addSeparator()->setText(tr("Editing"));
edit->addAction(tr("Make editable"), parent, [parent]() {
- if(parent->currentView != nullptr)
- parent->currentView->page()->runJavaScript("document.documentElement.contentEditable = true");
+ if(parent->currentView() != nullptr)
+ parent->currentView()->page()->runJavaScript("document.documentElement.contentEditable = true");
});
edit->addAction(tr("Bold"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::ToggleBold);
+ trigger_if(parent->currentView(), QWebEnginePage::ToggleBold);
});
edit->addAction(tr("Italic"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::ToggleItalic);
+ trigger_if(parent->currentView(), QWebEnginePage::ToggleItalic);
});
edit->addAction(tr("Underline"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::ToggleUnderline);
+ trigger_if(parent->currentView(), QWebEnginePage::ToggleUnderline);
});
edit->addAction(tr("Strikethrough"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::ToggleStrikethrough);
+ trigger_if(parent->currentView(), QWebEnginePage::ToggleStrikethrough);
});
edit->addAction(tr("Align left"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::AlignLeft);
+ trigger_if(parent->currentView(), QWebEnginePage::AlignLeft);
});
edit->addAction(tr("Align right"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::AlignRight);
+ trigger_if(parent->currentView(), QWebEnginePage::AlignRight);
});
edit->addAction(tr("Align center"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::AlignCenter);
+ trigger_if(parent->currentView(), QWebEnginePage::AlignCenter);
});
edit->addAction(tr("Align justified"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::AlignJustified);
+ trigger_if(parent->currentView(), QWebEnginePage::AlignJustified);
});
edit->addAction(tr("Indent"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::Indent);
+ trigger_if(parent->currentView(), QWebEnginePage::Indent);
});
edit->addAction(tr("Outdent"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::Outdent);
+ trigger_if(parent->currentView(), QWebEnginePage::Outdent);
});
edit->addAction(tr("Insert ordered list"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::InsertOrderedList);
+ trigger_if(parent->currentView(), QWebEnginePage::InsertOrderedList);
});
edit->addAction(tr("Insert unordered list"), parent, [parent]() {
- trigger_if(parent->currentView, QWebEnginePage::InsertUnorderedList);
+ trigger_if(parent->currentView(), QWebEnginePage::InsertUnorderedList);
});
}
}
@@ -535,22 +535,18 @@ void MenuBar::insertSubWindow(SubWindow *subwindow)
auto *action = window->addAction(subwindow->windowTitle());
action->setCheckable(true);
- connect(subwindow, &SubWindow::windowStateChanged, action, [action](Qt::WindowStates, Qt::WindowStates state) {
- action->setChecked(state.testFlag(Qt::WindowMaximized) | state.testFlag(Qt::WindowActive));
- });
+ action->setChecked(subwindow->isVisible());
+ connect(subwindow, &SubWindow::visibilityChanged, action, &QAction::setChecked);
connect(subwindow, &SubWindow::windowTitleChanged, action, &QAction::setText);
connect(subwindow, &SubWindow::destroyed, action, &QAction::deleteLater);
auto *optionsMenu = new QMenu;
- optionsMenu->addAction(tr("Switch to"), subwindow, [subwindow]() {
- if(!subwindow->windowState().testFlag(Qt::WindowMaximized))
- subwindow->showMaximized();
- else
- subwindow->showNormal();
- });
- optionsMenu->addAction(tr("Close"), subwindow, [subwindow]() {
- subwindow->close();
+ optionsMenu->addAction(tr("Switch to"), subwindow, [this, subwindow]() {
+ m_parent->setCurrentSubWindow(subwindow);
});
+ optionsMenu->addAction(tr("Show"), subwindow, &SubWindow::show);
+ optionsMenu->addAction(tr("Hide"), subwindow, &SubWindow::hide);
+ optionsMenu->addAction(tr("Close"), subwindow, &SubWindow::close);
action->setMenu(optionsMenu);
}
diff --git a/src/mainwindow/menubar.h b/src/mainwindow/menubar.h
index f4d39c5..f369bef 100644
--- a/src/mainwindow/menubar.h
+++ b/src/mainwindow/menubar.h
@@ -24,6 +24,7 @@ public:
void insertSubWindow(SubWindow *subwindow);
private:
+ MainWindow *m_parent = nullptr;
QMenu *smolbote = nullptr;
QMenu *window = nullptr;
QAction *pluginInsertLocation = nullptr;
diff --git a/src/mainwindow/widgets/urllineedit.cpp b/src/mainwindow/widgets/urllineedit.cpp
index 5216f31..7eeafa6 100644
--- a/src/mainwindow/widgets/urllineedit.cpp
+++ b/src/mainwindow/widgets/urllineedit.cpp
@@ -42,12 +42,14 @@ UrlLineEdit::UrlLineEdit(QWidget *parent)
auto *loadAction = new QAction(tr("Paste and load"), this);
connect(loadAction, &QAction::triggered, this, [this]() {
emit addressbar->load(QUrl::fromUserInput(qApp->clipboard()->text()));
+ clearFocus();
});
actions.append(loadAction);
auto *searchAction = new QAction(tr("Paste and search"), this);
connect(searchAction, &QAction::triggered, this, [this]() {
emit addressbar->search(qApp->clipboard()->text());
+ clearFocus();
});
actions.append(searchAction);
diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp
index c6e156e..58acee6 100644
--- a/src/subwindow/subwindow.cpp
+++ b/src/subwindow/subwindow.cpp
@@ -8,29 +8,31 @@
#include "subwindow.h"
#include "browser.h"
-#include "tabwidget.h"
+#include "configuration.h"
+#include "webengine/webprofile.h"
#include "webengine/webview.h"
#include <QAction>
-#include <QJsonArray>
-#include <QJsonDocument>
-#include <QJsonObject>
+#include <QCloseEvent>
+#include <QHideEvent>
#include <QMenu>
#include <QShortcut>
-#include <QStyle>
+#include <QShowEvent>
#include <QTabBar>
#include <QToolButton>
-#include "configuration.h"
-#include "webengine/webprofile.h"
+#include <QVBoxLayout>
SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags flags)
- : QMdiSubWindow(parent, flags)
+ : QWidget(parent, flags)
, tabWidget(new TabWidget(this))
{
// delete this window when it closes
- setAttribute(Qt::WA_DeleteOnClose, true);
+ //setAttribute(Qt::WA_DeleteOnClose, true);
- resize(800, 600);
- setWidget(tabWidget);
+ auto *layout = new QVBoxLayout;
+ layout->setSpacing(0);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addWidget(tabWidget);
+ setLayout(layout);
m_profile = WebProfile::defaultProfile();
@@ -74,31 +76,6 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags flags)
});
}
-SubWindow::~SubWindow()
-{
- delete tabWidget;
-}
-
-int SubWindow::currentTabIndex() const
-{
- return tabWidget->currentIndex();
-}
-
-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)
{
if(profile == nullptr) {
@@ -113,11 +90,6 @@ void SubWindow::setProfile(WebProfile *profile)
}
}
-WebProfile *SubWindow::profile() const
-{
- return m_profile;
-}
-
void SubWindow::setTabData(TabData &data, int index)
{
tabWidget->tabBar()->setTabData(index, QVariant::fromValue<TabData>(data));
@@ -143,28 +115,25 @@ int SubWindow::addTab(const QUrl &url, WebProfile *profile)
return tabWidget->addTab(view);
}
-void SubWindow::closeTab(int index)
-{
- tabWidget->removeTab(index);
-}
-
-void SubWindow::setCurrentTab(int index)
+void SubWindow::moveTab(int from, int to)
{
- if(index >= 0)
- tabWidget->setCurrentIndex(index);
+ tabWidget->tabBar()->moveTab(from, to);
}
-void SubWindow::moveTab(int from, int to)
+void SubWindow::closeEvent(QCloseEvent *event)
{
- tabWidget->tabBar()->moveTab(from, to);
+ emit aboutToClose();
+ event->accept();
}
-int SubWindow::restoreLastTab()
+void SubWindow::hideEvent(QHideEvent *event)
{
- return tabWidget->restoreLastTab();
+ emit visibilityChanged(false);
+ event->accept();
}
-void SubWindow::restoreTabMenu(QMenu *menu)
+void SubWindow::showEvent(QShowEvent *event)
{
- tabWidget->restoreTabMenu(menu);
+ emit visibilityChanged(true);
+ event->accept();
}
diff --git a/src/subwindow/subwindow.h b/src/subwindow/subwindow.h
index c4f96c0..8343a9b 100644
--- a/src/subwindow/subwindow.h
+++ b/src/subwindow/subwindow.h
@@ -9,51 +9,88 @@
#ifndef SMOLBOTE_SUBWINDOW_H
#define SMOLBOTE_SUBWINDOW_H
-#include <QMdiSubWindow>
+#include "tabwidget.h"
+#include "webengine/webview.h"
+#include <QMenu>
#include <QUrl>
-#include <memory>
+#include <QWidget>
-class TabWidget;
-class WebView;
class WebProfile;
-class SubWindow : public QMdiSubWindow
+class SubWindow : public QWidget
{
Q_OBJECT
public:
- struct TabData
- {
+ struct TabData {
bool closeLocked = false;
bool refreshLocked = false;
};
explicit SubWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
- ~SubWindow() override;
+ ~SubWindow() = default;
+
+ [[nodiscard]] int currentTabIndex() const
+ {
+ return tabWidget->currentIndex();
+ }
+
+ [[nodiscard]] WebView *currentView()
+ {
+ return qobject_cast<WebView *>(tabWidget->currentWidget());
+ }
+
+ [[nodiscard]] WebView *view(int index) const
+ {
+ return qobject_cast<WebView *>(tabWidget->widget(index));
+ }
- int currentTabIndex() const;
- WebView *currentView();
- WebView *view(int index) const;
- int tabCount() const;
+ [[nodiscard]] int tabCount() const
+ {
+ return tabWidget->count();
+ }
void setProfile(WebProfile *profile);
- WebProfile *profile() const;
+ [[nodiscard]] WebProfile *profile() const
+ {
+ return m_profile;
+ }
void setTabData(TabData &data, int index);
- TabData tabData(int index) const;
+ [[nodiscard]] TabData tabData(int index) const;
signals:
void currentViewChanged(WebView *view);
void showStatusMessage(const QString &message, int timeout = 0);
+ void visibilityChanged(bool isVisible);
+ void aboutToClose();
public slots:
int addTab(const QUrl &url = QUrl(), WebProfile *profile = nullptr);
- void closeTab(int index);
+ void closeTab(int index)
+ {
+ tabWidget->removeTab(index);
+ }
- void setCurrentTab(int index);
+ void setCurrentTab(int index)
+ {
+ if(index >= 0)
+ tabWidget->setCurrentIndex(index);
+ }
void moveTab(int from, int to);
- int restoreLastTab();
- void restoreTabMenu(QMenu *menu);
+ int restoreLastTab()
+ {
+ return tabWidget->restoreLastTab();
+ }
+ void restoreTabMenu(QMenu *menu)
+ {
+ tabWidget->restoreTabMenu(menu);
+ }
+
+protected:
+ void closeEvent(QCloseEvent *event);
+ void hideEvent(QHideEvent *event);
+ void showEvent(QShowEvent *event);
private:
WebProfile *m_profile;