From 4eedf60d76a047f63b0991eee0b623e9be854c76 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 13 Dec 2018 12:49:28 +0100 Subject: MainWindow: rework menu bar Split off menu bar into its own class out of MainWindow Menu bar now has a 'Find in menus' function --- src/subwindow/subwindow.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src/subwindow/subwindow.cpp') diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp index 0844f1f..4beba49 100644 --- a/src/subwindow/subwindow.cpp +++ b/src/subwindow/subwindow.cpp @@ -61,18 +61,6 @@ SubWindow::SubWindow(const Configuration *config, QWidget *parent, Qt::WindowFla menu->insertSeparator(firstAction); } - // 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("subwindow.shortcuts.new").value())); - connect(newTab_button, &QToolButton::clicked, this, [=]() { - auto index = addTab(WebProfile::defaultProfile()->newtab()); - tabWidget->setCurrentIndex(index); - }); - newTab_button->setMenu(tabWidget->createTabMenu(newTab_button)); - tabWidget->setCornerWidget(newTab_button, Qt::TopRightCorner); - // general actions auto *closeTab_shortcut = new QShortcut(QKeySequence(config->value("subwindow.shortcuts.close").value()), this); connect(closeTab_shortcut, &QShortcut::activated, this, [=]() { @@ -159,8 +147,10 @@ int SubWindow::tabCount() const void SubWindow::setProfile(WebProfile *profile) { - if(profile == nullptr) + if(profile == nullptr) { + setProfile(WebProfile::defaultProfile()); return; + } this->m_profile = profile; for(int i = 0; i < tabWidget->count(); ++i) { @@ -178,13 +168,29 @@ int SubWindow::addTab(const QUrl &url, WebProfile *profile) { Q_CHECK_PTR(m_profile); - auto *view = new WebView((profile == nullptr) ? m_profile : profile, this); - if(!url.isEmpty()) + auto *_profile = (profile == nullptr) ? m_profile : profile; + + auto *view = new WebView(_profile, this); + if(url.isEmpty()) + view->load(_profile->newtab()); + else view->load(url); + return tabWidget->addTab(view); } void SubWindow::setCurrentTab(int index) { - tabWidget->setCurrentIndex(index); + if(index > 0) + tabWidget->setCurrentIndex(index); +} + +int SubWindow::restoreLastTab() +{ + return tabWidget->restoreLastTab(); +} + +void SubWindow::restoreTabMenu(QMenu *menu) +{ + tabWidget->restoreTabMenu(menu); } -- cgit v1.2.1