From 825ee7ea9621a3ae25942e679ea3488cb88d1f53 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 5 Feb 2018 11:50:50 +0100 Subject: [PATCH] Revert "TabContextMenu: Require only WebTab in constructor" This broke context menu on empty tab bar space. This reverts commit e791e77045b572af02d27f7a15ae082a4a13814c. --- src/lib/tabwidget/tabbar.cpp | 16 ++++++++-------- src/lib/tabwidget/tabcontextmenu.cpp | 8 ++++---- src/lib/tabwidget/tabcontextmenu.h | 5 ++--- src/plugins/TabManager/tabmanagerwidget.cpp | 10 +++++++--- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/lib/tabwidget/tabbar.cpp b/src/lib/tabwidget/tabbar.cpp index 2ef16f3ca..2e8c50b18 100644 --- a/src/lib/tabwidget/tabbar.cpp +++ b/src/lib/tabwidget/tabbar.cpp @@ -345,14 +345,14 @@ void TabBar::contextMenuEvent(QContextMenuEvent* event) return; } - WebTab* webTab = qobject_cast(m_tabWidget->widget(tabAt(event->pos()))); - if (webTab) { - TabContextMenu menu(webTab, Qt::Horizontal); - // Prevent choosing first option with double rightclick - const QPoint pos = event->globalPos(); - QPoint p(pos.x(), pos.y() + 1); - menu.exec(p); - } + int index = tabAt(event->pos()); + + TabContextMenu menu(index, Qt::Horizontal, m_window, m_tabWidget); + + // Prevent choosing first option with double rightclick + const QPoint pos = event->globalPos(); + QPoint p(pos.x(), pos.y() + 1); + menu.exec(p); m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(true); } diff --git a/src/lib/tabwidget/tabcontextmenu.cpp b/src/lib/tabwidget/tabcontextmenu.cpp index 9934ca80b..67ad5c663 100644 --- a/src/lib/tabwidget/tabcontextmenu.cpp +++ b/src/lib/tabwidget/tabcontextmenu.cpp @@ -27,12 +27,12 @@ #include "checkboxdialog.h" -TabContextMenu::TabContextMenu(WebTab *tab, Qt::Orientation orientation, bool showCloseOtherTabs) +TabContextMenu::TabContextMenu(int index, Qt::Orientation orientation, BrowserWindow* window, TabWidget* tabWidget, bool showCloseOtherTabs) : QMenu() - , m_clickedTab(tab->tabIndex()) + , m_clickedTab(index) , m_tabsOrientation(orientation) - , m_window(tab->webView()->browserWindow()) - , m_tabWidget(m_window->tabWidget()) + , m_window(window) + , m_tabWidget(tabWidget) , m_showCloseOtherTabs(showCloseOtherTabs) { setObjectName("tabcontextmenu"); diff --git a/src/lib/tabwidget/tabcontextmenu.h b/src/lib/tabwidget/tabcontextmenu.h index 0b0ad07ce..0d162623b 100644 --- a/src/lib/tabwidget/tabcontextmenu.h +++ b/src/lib/tabwidget/tabcontextmenu.h @@ -22,15 +22,14 @@ #include "qzcommon.h" -class WebTab; -class TabWidget; class BrowserWindow; +class TabWidget; class FALKON_EXPORT TabContextMenu : public QMenu { Q_OBJECT public: - explicit TabContextMenu(WebTab *tab, Qt::Orientation orientation, bool showCloseOtherTabs = true); + explicit TabContextMenu(int index, Qt::Orientation orientation, BrowserWindow* window, TabWidget* tabWidget, bool showCloseOtherTabs = true); signals: void reloadTab(int index); diff --git a/src/plugins/TabManager/tabmanagerwidget.cpp b/src/plugins/TabManager/tabmanagerwidget.cpp index c445228c8..383286194 100644 --- a/src/plugins/TabManager/tabmanagerwidget.cpp +++ b/src/plugins/TabManager/tabmanagerwidget.cpp @@ -279,12 +279,16 @@ void TabManagerWidget::customContextMenuRequested(const QPoint &pos) TabItem* item = static_cast(ui->treeWidget->itemAt(pos)); if (item) { - WebTab *tab = item->webTab(); - if (tab) { + BrowserWindow* mainWindow = item->window(); + QWidget* tabWidget = item->webTab(); + + if (mainWindow && tabWidget) { + int index = mainWindow->tabWidget()->indexOf(tabWidget); + // if items are not grouped by Window then actions "Close Other Tabs", // "Close Tabs To The Bottom" and "Close Tabs To The Top" // are ambiguous and should be hidden. - menu = new TabContextMenu(tab, Qt::Vertical, m_groupType == GroupByWindow); + menu = new TabContextMenu(index, Qt::Vertical, mainWindow, mainWindow->tabWidget(), m_groupType == GroupByWindow); menu->addSeparator(); } }