diff mbox series

[2/3] kernel-shark-qt: Better positioning of the Quick Context menu.

Message ID 20181217175516.2944-2-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Commit b4b1673423c5eae0e3da917f98aa89322ee502e8
Headers show
Series [1/3] kernel-shark-qt: Improve the KsQuickContextMenu | expand

Commit Message

Yordan Karadzhov Dec. 17, 2018, 5:56 p.m. UTC
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) <rostedt@goodmis.org>
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark-qt/src/KsTraceGraph.cpp  | 13 ++++++++-----
 kernel-shark-qt/src/KsTraceViewer.cpp | 13 +++++++++++--
 2 files changed, 19 insertions(+), 7 deletions(-)
diff mbox series

Patch

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);
 	}
 }