From patchwork Mon Dec 17 17:56:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 10760197 Return-Path: Received: from mail-eopbgr700052.outbound.protection.outlook.com ([40.107.70.52]:10656 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727468AbeLQR4F (ORCPT ); Mon, 17 Dec 2018 12:56:05 -0500 From: Yordan Karadzhov To: "rostedt@goodmis.org" CC: "linux-trace-devel@vger.kernel.org" Subject: [PATCH 2/3] kernel-shark-qt: Better positioning of the Quick Context menu. Date: Mon, 17 Dec 2018 17:56:01 +0000 Message-ID: <20181217175516.2944-2-ykaradzhov@vmware.com> References: <20181217175516.2944-1-ykaradzhov@vmware.com> In-Reply-To: <20181217175516.2944-1-ykaradzhov@vmware.com> Content-Language: en-US MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org List-ID: Content-Length: 3420 So far I wrongly assumed that the coordinates of the point provided by the customContextMenuRequested signal are given in the reference frame of the parent widget (KsTraceGraph or KsTraceViewer). In fact the signal is emitted by the child widget (KsGLWidget or KsTableView) and the coordinates are given in the reference frame of the child. This patch provides a proper positioning of the menu. Reported-by: Steven Rostedt (VMware) Signed-off-by: Yordan Karadzhov --- kernel-shark-qt/src/KsTraceGraph.cpp | 13 ++++++++----- kernel-shark-qt/src/KsTraceViewer.cpp | 13 +++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/kernel-shark-qt/src/KsTraceGraph.cpp b/kernel-shark-qt/src/KsTraceGraph.cpp index 858930c..5144f61 100644 --- a/kernel-shark-qt/src/KsTraceGraph.cpp +++ b/kernel-shark-qt/src/KsTraceGraph.cpp @@ -136,7 +136,7 @@ KsTraceGraph::KsTraceGraph(QWidget *parent) this, &KsTraceGraph::_updateTimeLegends); _glWindow.setContextMenuPolicy(Qt::CustomContextMenu); - connect(&_glWindow, &QTableView::customContextMenuRequested, + connect(&_glWindow, &QWidget::customContextMenuRequested, this, &KsTraceGraph::_onCustomContextMenu); _scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -782,12 +782,15 @@ void KsTraceGraph::_onCustomContextMenu(const QPoint &point) connect(menu, &KsQuickMarkerMenu::deselect, this, &KsTraceGraph::deselect); - QPoint global = mapToGlobal(point); /* - * The global coordinates have to be corrected for the offset - * of the vertical scrollbar. + * Note that this slot was connected to the + * customContextMenuRequested signal of the OpenGL widget. + * Because of this the coordinates of the point are given with + * respect to the frame of this widget. */ - global.ry() -= _scrollArea.verticalScrollBar()->value(); + QPoint global = _glWindow.mapToGlobal(point); + global.ry() -= menu->sizeHint().height() / 2; + menu->exec(global); } } diff --git a/kernel-shark-qt/src/KsTraceViewer.cpp b/kernel-shark-qt/src/KsTraceViewer.cpp index 971793f..09f6a1e 100644 --- a/kernel-shark-qt/src/KsTraceViewer.cpp +++ b/kernel-shark-qt/src/KsTraceViewer.cpp @@ -150,7 +150,7 @@ KsTraceViewer::KsTraceViewer(QWidget *parent) this, &KsTraceViewer::_searchReset); _view.setContextMenuPolicy(Qt::CustomContextMenu); - connect(&_view, &QTableView::customContextMenuRequested, + connect(&_view, &QWidget::customContextMenuRequested, this, &KsTraceViewer::_onCustomContextMenu); connect(&_view, &QTableView::clicked, @@ -263,13 +263,22 @@ void KsTraceViewer::_onCustomContextMenu(const QPoint &point) size_t row = _proxyModel.mapRowFromSource(i.row()); KsQuickContextMenu menu(_data, row, _mState, this); + /* + * Note that this slot was connected to the + * customContextMenuRequested signal of the Table widget. + * Because of this the coordinates of the point are given with + * respect to the frame of this widget. + */ + QPoint global = _view.mapToGlobal(point); + global.ry() -= menu.sizeHint().height() / 2; + connect(&menu, &KsQuickContextMenu::addTaskPlot, this, &KsTraceViewer::addTaskPlot); connect(&menu, &KsQuickMarkerMenu::deselect, this, &KsTraceViewer::deselect); - menu.exec(mapToGlobal(point)); + menu.exec(global); } }