linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yordan Karadzhov <ykaradzhov@vmware.com>
To: "rostedt@goodmis.org" <rostedt@goodmis.org>
Cc: "linux-trace-devel@vger.kernel.org" <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	[thread overview]
Message-ID: <20181217175516.2944-2-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20181217175516.2944-1-ykaradzhov@vmware.com>

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

  reply	other threads:[~2018-12-17 17:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-17 17:55 [PATCH 1/3] kernel-shark-qt: Improve the KsQuickContextMenu Yordan Karadzhov
2018-12-17 17:56 ` Yordan Karadzhov [this message]
2018-12-17 17:56 ` [PATCH 3/3] kernel-shark-qt: Make the Quick Contex menu less touchy Yordan Karadzhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181217175516.2944-2-ykaradzhov@vmware.com \
    --to=ykaradzhov@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).