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/tabwidget.cpp | 78 +++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 46 deletions(-) (limited to 'src/subwindow/tabwidget.cpp') diff --git a/src/subwindow/tabwidget.cpp b/src/subwindow/tabwidget.cpp index 942a364..c635aee 100644 --- a/src/subwindow/tabwidget.cpp +++ b/src/subwindow/tabwidget.cpp @@ -31,7 +31,7 @@ TabWidget::TabWidget(QWidget *parent) setStyleSheet("QTabBar::tab { width: 200px; }"); setTabsClosable(true); - //setTabBarAutoHide(true); + setTabBarAutoHide(true); setElideMode(Qt::ElideRight); setMovable(true); @@ -75,51 +75,6 @@ TabWidget::~TabWidget() } } -QMenu *TabWidget::createTabMenu(QWidget *parent) -{ - auto *menu = new QMenu(parent); - - auto *reopenTabAction = menu->addAction(tr("Reopen last tab")); - connect(reopenTabAction, &QAction::triggered, this, [this]() { - if(!m_closedTabs.isEmpty()) { - TabInformation tab = m_closedTabs.takeLast(); - addTab(createViewFromInfo(tab, this)); - } - }); - - auto *tabHistoryMenu = menu->addMenu(tr("Tab History")); - connect(tabHistoryMenu, &QMenu::aboutToShow, this, [this, tabHistoryMenu]() { - tabHistoryMenu->clear(); - for(int i = 0; i < m_closedTabs.count(); ++i) { - auto *openAction = tabHistoryMenu->addAction(m_closedTabs.at(i).title); - - connect(openAction, &QAction::triggered, this, [this, i]() { - TabInformation tab = m_closedTabs.takeAt(i); - addTab(createViewFromInfo(tab, this)); - }); - } - - tabHistoryMenu->addSeparator(); - - auto *clearTabHistory = tabHistoryMenu->addAction(tr("Clear")); - connect(clearTabHistory, &QAction::triggered, this, [this]() { - m_closedTabs.clear(); - }); - }); - - connect(menu, &QMenu::aboutToShow, this, [this, reopenTabAction, tabHistoryMenu]() { - if(m_closedTabs.isEmpty()) { - reopenTabAction->setEnabled(false); - tabHistoryMenu->setEnabled(false); - } else { - reopenTabAction->setEnabled(true); - tabHistoryMenu->setEnabled(true); - } - }); - - return menu; -} - int TabWidget::addTab(WebView *view) { Q_ASSERT_X(view != nullptr, "TabWidget::addTab", "Tried to add null view"); @@ -165,6 +120,37 @@ void TabWidget::deleteTab(int index) parentWidget()->close(); } +int TabWidget::restoreLastTab() +{ + if(!m_closedTabs.isEmpty()) { + TabInformation tab = m_closedTabs.takeLast(); + return addTab(createViewFromInfo(tab, this)); + } + return -1; +} + +void TabWidget::restoreTabMenu(QMenu *menu) +{ + if(m_closedTabs.isEmpty()) + return; + + for(int i = 0; i < m_closedTabs.count(); ++i) { + auto *openAction = menu->addAction(m_closedTabs.at(i).title); + + connect(openAction, &QAction::triggered, this, [this, i]() { + TabInformation tab = m_closedTabs.takeAt(i); + addTab(createViewFromInfo(tab, this)); + }); + } + + menu->addSeparator(); + + auto *clearTabHistory = menu->addAction(tr("Clear")); + connect(clearTabHistory, &QAction::triggered, this, [this]() { + m_closedTabs.clear(); + }); +} + void TabWidget::contextMenuEvent(QContextMenuEvent *event) { // check if the context menu was called on a tab -- cgit v1.2.1