diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-13 12:49:28 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-12-13 13:41:50 +0100 |
commit | 4eedf60d76a047f63b0991eee0b623e9be854c76 (patch) | |
tree | c8b335c8909a309c2bc2765e823bec5da74aa5aa /src/subwindow/tabwidget.cpp | |
parent | Fix crash creating ConfigurationEditorPlugin widget (diff) | |
download | smolbote-4eedf60d76a047f63b0991eee0b623e9be854c76.tar.xz |
MainWindow: rework menu bar
Split off menu bar into its own class out of MainWindow
Menu bar now has a 'Find in menus' function
Diffstat (limited to 'src/subwindow/tabwidget.cpp')
-rw-r--r-- | src/subwindow/tabwidget.cpp | 78 |
1 files changed, 32 insertions, 46 deletions
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 |