From 892daad6789d440f60521197ae0a3f47def59256 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 19 Apr 2018 13:21:48 +0200 Subject: Add Window menu - add new tab button to tab widget - tab shortcuts are read from configuration again - updated manpage some --- src/mainwindow/window.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/mainwindow/window.cpp') 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 +#include +#include +#include -Window::Window(QWidget *parent, Qt::WindowFlags flags) +Window::Window(const QHash &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 -- cgit v1.2.1