diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-04-19 13:21:48 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-04-19 13:21:48 +0200 |
commit | 892daad6789d440f60521197ae0a3f47def59256 (patch) | |
tree | dfc32d336b75a5524605f7392e4256db960dfe1b /src | |
parent | Removed MainWindow::titleChangedConnection (diff) | |
download | smolbote-892daad6789d440f60521197ae0a3f47def59256.tar.xz |
Add Window menu
- add new tab button to tab widget
- tab shortcuts are read from configuration again
- updated manpage some
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow/mainwindow.cpp | 10 | ||||
-rw-r--r-- | src/mainwindow/mainwindow.h | 1 | ||||
-rw-r--r-- | src/mainwindow/widgets/tabwidget.cpp | 22 | ||||
-rw-r--r-- | src/mainwindow/widgets/tabwidget.h | 4 | ||||
-rw-r--r-- | src/mainwindow/window.cpp | 37 | ||||
-rw-r--r-- | src/mainwindow/window.h | 2 |
6 files changed, 42 insertions, 34 deletions
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 0052d13..23bc7da 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -66,6 +66,7 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) disconnect(navigationBarConnection); disconnect(searchBoxConnection); disconnect(statusBarConnection); + windowMenu->setMenu(nullptr); auto *w = qobject_cast<Window *>(window); if(w == nullptr) { @@ -75,6 +76,7 @@ MainWindow::MainWindow(std::shared_ptr<Configuration> &config, QWidget *parent) navigationToolBar->connectWebView(nullptr); searchBox->setView(nullptr); } else { + windowMenu->setMenu(w->systemMenu()); addressBar->connectWebView(w->currentView()); addressBarConnection = connect(w, &Window::currentViewChanged, addressBar, &AddressBar::connectWebView); navigationToolBar->connectWebView(w->currentView()); @@ -107,11 +109,6 @@ MainWindow::~MainWindow() void MainWindow::createMenuBar() { auto *smolboteMenu = menuBar()->addMenu(qApp->applicationDisplayName()); - smolboteMenu->addAction(tr("New tab"), this, [this]() { - createTab(QUrl::fromUserInput("about:blank")); - }, - QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.newTab").value().c_str())); - smolboteMenu->addAction(tr("New tab group"), this, [this]() { createSubWindow(QUrl::fromUserInput("about:blank")); }, @@ -132,6 +129,7 @@ void MainWindow::createMenuBar() smolboteMenu->addAction(tr("Quit"), qApp, &QApplication::quit, QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.quit").value().c_str())); + windowMenu = menuBar()->addAction(tr("Window")); toolsMenu = menuBar()->addMenu(tr("Tools")); } @@ -174,7 +172,7 @@ void MainWindow::createTab(const QUrl &url) Window *MainWindow::createSubWindow(const QUrl &url) { - auto *w = new Window(this); + auto *w = new Window(m_config->section("window"), this); mdiArea->addSubWindow(w); w->showMaximized(); w->setFocus(); diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 0d7939c..6ed9e5b 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -46,6 +46,7 @@ protected: void closeEvent(QCloseEvent *event) override; private: + QAction *windowMenu = nullptr; QMenu *toolsMenu = nullptr; AddressBar *addressBar = nullptr; SearchForm *searchBox = nullptr; diff --git a/src/mainwindow/widgets/tabwidget.cpp b/src/mainwindow/widgets/tabwidget.cpp index 21476cd..66182c3 100644 --- a/src/mainwindow/widgets/tabwidget.cpp +++ b/src/mainwindow/widgets/tabwidget.cpp @@ -25,28 +25,6 @@ TabWidget::TabWidget(QWidget *parent) connect(this, &TabWidget::tabCloseRequested, this, &TabWidget::deleteTab); - // general actions - closeTab_action = new QAction(this); - closeTab_action->setShortcut(QKeySequence("Ctrl+X")); - connect(closeTab_action, &QAction::triggered, this, [this]() { - this->deleteTab(this->currentIndex()); - }); - addAction(closeTab_action); - - leftTab_action = new QAction(this); - leftTab_action->setShortcut(QKeySequence("Ctrl+O")); - connect(leftTab_action, &QAction::triggered, this, [this]() { - this->setCurrentIndex(qMax(0, this->currentIndex() - 1)); - }); - addAction(leftTab_action); - - rightTab_action = new QAction(this); - rightTab_action->setShortcut(QKeySequence("Ctrl+P")); - connect(rightTab_action, &QAction::triggered, this, [this]() { - this->setCurrentIndex(qMin(this->currentIndex() + 1, this->count() - 1)); - }); - addAction(rightTab_action); - // context menu tabContextMenu = new QMenu(this); auto *closeTab = tabContextMenu->addAction(tr("Close Tab")); diff --git a/src/mainwindow/widgets/tabwidget.h b/src/mainwindow/widgets/tabwidget.h index b7aad63..06fa79b 100644 --- a/src/mainwindow/widgets/tabwidget.h +++ b/src/mainwindow/widgets/tabwidget.h @@ -30,10 +30,6 @@ protected: void contextMenuEvent(QContextMenuEvent *event) override; private: - QAction *closeTab_action; - QAction *leftTab_action; - QAction *rightTab_action; - QMenu *tabContextMenu; }; diff --git a/src/mainwindow/window.cpp b/src/mainwindow/window.cpp index 0c52076..735df4a 100644 --- a/src/mainwindow/window.cpp +++ b/src/mainwindow/window.cpp @@ -11,8 +11,11 @@ #include "webengine/webview.h" #include "widgets/tabwidget.h" #include <QUrl> +#include <QToolButton> +#include <QStyle> +#include <QAction> -Window::Window(QWidget *parent, Qt::WindowFlags flags) +Window::Window(const QHash<QString, QString> &config, QWidget *parent, Qt::WindowFlags flags) : QMdiSubWindow(parent, flags) , tabWidget(new TabWidget(this)) { @@ -22,6 +25,38 @@ Window::Window(QWidget *parent, Qt::WindowFlags flags) resize(800, 600); setWidget(tabWidget); + // 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("window.shortcuts.new"))); + connect(newTab_button, &QToolButton::clicked, this, [=]() { + addTab(WebProfile::defaultProfile()->newtab()); + }); + tabWidget->setCornerWidget(newTab_button, Qt::TopRightCorner); + + // general actions + auto *closeTab_action = new QAction(this); + closeTab_action->setShortcut(QKeySequence(config.value("window.shortcuts.close"))); + connect(closeTab_action, &QAction::triggered, this, [=]() { + tabWidget->deleteTab(tabWidget->currentIndex()); + }); + addAction(closeTab_action); + + auto *leftTab_action = new QAction(this); + leftTab_action->setShortcut(QKeySequence(config.value("window.shortcuts.left"))); + connect(leftTab_action, &QAction::triggered, this, [=]() { + tabWidget->setCurrentIndex(qMax(0, tabWidget->currentIndex() - 1)); + }); + addAction(leftTab_action); + + auto *rightTab_action = new QAction(this); + rightTab_action->setShortcut(QKeySequence(config.value("window.shortcuts.right"))); + connect(rightTab_action, &QAction::triggered, this, [=]() { + tabWidget->setCurrentIndex(qMin(tabWidget->currentIndex() + 1, tabWidget->count() - 1)); + }); + addAction(rightTab_action); + connect(tabWidget, &TabWidget::currentChanged, [this](int index) { if(index < 0) { // last tab has been closed diff --git a/src/mainwindow/window.h b/src/mainwindow/window.h index ee9a11d..cdc504c 100644 --- a/src/mainwindow/window.h +++ b/src/mainwindow/window.h @@ -19,7 +19,7 @@ class Window : public QMdiSubWindow Q_OBJECT public: - explicit Window(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); + explicit Window(const QHash<QString, QString> &config, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); ~Window() override; WebView *currentView(); |