summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <[email protected]>2015-09-04 15:03:38 +0200
committerAndre Heinecke <[email protected]>2015-09-04 20:29:59 +0200
commit2e2738be95b95fb7a914d5062f2b6f80f53301cf (patch)
tree2a8f9a6259aa28d3c09246a93bdcee596fdb2a7f
parentecd53085c95a7b00860c4e56e68983769671065c (diff)
Fix tabwidget contextmenu for QTabWidget
REVIEW: 125047
-rw-r--r--kleopatra/view/tabwidget.cpp21
-rw-r--r--kleopatra/view/tabwidget.h2
2 files changed, 10 insertions, 13 deletions
diff --git a/kleopatra/view/tabwidget.cpp b/kleopatra/view/tabwidget.cpp
index d5448a7..c0be432 100644
--- a/kleopatra/view/tabwidget.cpp
+++ b/kleopatra/view/tabwidget.cpp
@@ -314,11 +314,7 @@ public:
~Private() {}
private:
- void slotContextMenu(const QPoint &p)
- {
- slotContextMenu(0, p);
- }
- void slotContextMenu(QWidget *w, const QPoint &p);
+ void slotContextMenu(const QPoint &p);
void currentIndexChanged(int index);
void slotPageTitleChanged(const QString &title);
void slotPageKeyFilterChanged(const shared_ptr<KeyFilter> &filter);
@@ -440,9 +436,12 @@ TabWidget::Private::Private(TabWidget *qq)
tabWidget.tabBar()->hide();
tabWidget.setMovable(true);
+ tabWidget.tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
+
connect(&tabWidget, SIGNAL(currentChanged(int)), q, SLOT(currentIndexChanged(int)));
- connect(&tabWidget, SIGNAL(contextMenu(QPoint)), q, SLOT(slotContextMenu(QPoint)));
- connect(&tabWidget, SIGNAL(contextMenu(QWidget*,QPoint)), q, SLOT(slotContextMenu(QWidget*,QPoint)));
+ connect(tabWidget.tabBar(), &QWidget::customContextMenuRequested, q, [this](const QPoint& p) {
+ slotContextMenu(p);
+ });
const action_data actionDataNew = {
"window_new_tab", i18n("New Tab"), i18n("Open a new tab"),
@@ -504,10 +503,10 @@ TabWidget::Private::Private(TabWidget *qq)
setCornerAction(currentPageActions[Close], Qt::TopRightCorner);
}
-void TabWidget::Private::slotContextMenu(QWidget *w, const QPoint &p)
+void TabWidget::Private::slotContextMenu(const QPoint &p)
{
- assert(!w || qobject_cast<Page *>(w));
- Page *const contextMenuPage = static_cast<Page *>(w);
+ const int tabUnderPos = tabWidget.tabBar()->tabAt(p);
+ Page *const contextMenuPage = static_cast<Page *>(tabWidget.widget(tabUnderPos));
const Page *const current = currentPage();
QAction **const actions = contextMenuPage == current ? currentPageActions : otherPageActions ;
@@ -525,7 +524,7 @@ void TabWidget::Private::slotContextMenu(QWidget *w, const QPoint &p)
menu.addSeparator();
menu.addAction(actions[Close]);
- const QAction *const action = menu.exec(p);
+ const QAction *const action = menu.exec(tabWidget.tabBar()->mapToGlobal(p));
if (contextMenuPage == current || action == newAction) {
return; // performed through signal/slot connections...
diff --git a/kleopatra/view/tabwidget.h b/kleopatra/view/tabwidget.h
index 768a5dc..a60f782 100644
--- a/kleopatra/view/tabwidget.h
+++ b/kleopatra/view/tabwidget.h
@@ -102,8 +102,6 @@ private:
class Private;
kdtools::pimpl_ptr<Private> d;
- Q_PRIVATE_SLOT(d, void slotContextMenu(QWidget *, const QPoint &))
- Q_PRIVATE_SLOT(d, void slotContextMenu(const QPoint &))
Q_PRIVATE_SLOT(d, void currentIndexChanged(int))
Q_PRIVATE_SLOT(d, void slotPageTitleChanged(const QString &))
Q_PRIVATE_SLOT(d, void slotPageKeyFilterChanged(const boost::shared_ptr<Kleo::KeyFilter> &))