From 4b4d3034ee731a7308f39f0d8269871578f9142f Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Sun, 14 Aug 2022 13:06:19 -0500 Subject: [PATCH] Change 'detachtab' to RMB context menu. --- notes/README.variables | 130 +++++++++++++++++++++++++++++++++++++++ src/QDetachTabWidget.cpp | 14 ++++- src/QDetachTabWidget.h | 2 +- 3 files changed, 143 insertions(+), 3 deletions(-) diff --git a/notes/README.variables b/notes/README.variables index 91e469d..d14ea5c 100644 --- a/notes/README.variables +++ b/notes/README.variables @@ -33,3 +33,133 @@ "-data-delete-expression id1 id2 ..." "-data-list-expressions" +# +# var examples. +# using 'hellostruct' as the example with a 'Person' struct that contains a 'Location' struct. +# +# 'me' +# + + "-var-create x2112 "*" me" + + ^done,name="x2112",numchild="1",value="{...}",type="Person",thread-id="1",has_more="0" + + "-var-info-type x2112" + + ^done,type="Person" + + "-var-info-num-children x2112" + + ^done,numchild="1" + + "-var-list-children --no-values x2112" + + ^done,numchild="1", + children=[ + child={name="x2112.public",exp="public",numchild="4",thread-id="1"} + ], + has_more="0" + + "-var-list-children --no-values x2112.public" + + ^done,numchild="4", + children=[ + child={name="x2112.public.name", exp="name", numchild="2", type="std::string", thread-id="1"}, + child={name="x2112.public.age", exp="age", numchild="0", type="int", thread-id="1"}, + child={name="x2112.public.salary", exp="salary", numchild="0", type="float", thread-id="1"}, + child={name="x2112.public.location", exp="location", numchild="1", type="Location", thread-id="1"} + ], + has_more="0" + + "-var-list-children --all-values x2112.public" + + ^done,numchild="4", + children=[ + child={name="x2112.public.name", exp="name", numchild="2", value="{...}", type="std::string", thread-id="1"}, + child={name="x2112.public.age", exp="age", numchild="0", value="60", type="int", thread-id="1"}, + child={name="x2112.public.salary", exp="salary", numchild="0", value="0.25", type="float", thread-id="1"}, + child={name="x2112.public.location", exp="location", numchild="1", value="{...}", type="Location", thread-id="1"} + ], + has_more="0" + + "-var-list-children --simple-values x2112.public" + + ^done,numchild="4", + children=[ + child={name="x2112.public.name", exp="name", numchild="2", type="std::string", thread-id="1"}, + child={name="x2112.public.age", exp="age", numchild="0", value="60", type="int", thread-id="1"}, + child={name="x2112.public.salary", exp="salary", numchild="0", value="0.25", type="float", thread-id="1"}, + child={name="x2112.public.location", exp="location", numchild="1", type="Location", thread-id="1"} + ], + has_more="0" + + "-var-evaluate-expression x2112" + + ^done,value="{...}" + + "-var-evaluate-expression x2112.name" + "-var-evaluate-expression x2112.age" + "-var-evaluate-expression x2112.salary" + "-var-evaluate-expression x2112.location" + + ^done,value="{...}" + ^done,value="60" + ^done,value="0.25" + ^done,value="{...}" + + "-var-delete x2112" + + ^done,ndeleted="1" + + +# +# 'me.name' +# + + "-var-create x2112 "*" me.name" + + ^done,name="x2112",numchild="2",value="{...}",type="std::string",thread-id="1",has_more="0" + + "-var-info-type x2112" + + ^done,type="std::string" + + "-var-info-num-children x2112" + + ^done,numchild="2" + + "-var-evaluate-expression x2112" + + ^done,value="{...}" + + "-var-list-children --no-values x2112" + + ^done,numchild="2", + children=[ + child={name="x2112.public", exp="public", numchild="1", thread-id="1"}, + child={name="x2112.private", exp="private", numchild="3", thread-id="1"} + ], + has_more="0" + + "-var-list-children --no-values x2112.public" + + ^done,numchild="1", + children=[ + child={name="x2112.public.npos",exp="npos",numchild="0",type="const std::__cxx11::basic_string, std::allocator >::size_type",thread-id="1"} + ], + has_more="0" + + "-var-list-children --no-values x2112.private" + + ^done,numchild="3", + children=[ + child={name="x2112.private._M_dataplus",exp="_M_dataplus",numchild="2",type="std::__cxx11::basic_string, std::allocator >::_Alloc_hider",thread-id="1"}, + child={name="x2112.private._M_string_length",exp="_M_string_length",numchild="0",type="std::__cxx11::basic_string, std::allocator >::size_type",thread-id="1"}, + child={name="x2112.private.2_anonymous",exp="",numchild="1",type="union {...}",thread-id="1"} + ], + has_more="0" + + "-var-list-children --no-values x2112.public.npos" + + ^done,numchild="0",has_more="0" + diff --git a/src/QDetachTabWidget.cpp b/src/QDetachTabWidget.cpp index bbca515..af73e96 100644 --- a/src/QDetachTabWidget.cpp +++ b/src/QDetachTabWidget.cpp @@ -7,7 +7,9 @@ QDetachTabWidget::QDetachTabWidget(QWidget* parent) : QTabWidget(parent) { - QObject::connect(tabBar(), &QTabBar::tabBarDoubleClicked, this, &QDetachTabWidget::handleShowContextMenu); + tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); + + QObject::connect(tabBar(), &QTabBar::customContextMenuRequested, this, &QDetachTabWidget::handleShowContextMenu); QObject::connect(this, &QTabWidget::tabCloseRequested, this, &QDetachTabWidget::handleTabClosedRequested); } @@ -25,7 +27,15 @@ void QDetachTabWidget::closeEvent (QCloseEvent* e) { QTabWidget::closeEvent(e); } -void QDetachTabWidget::handleShowContextMenu(int tabIndex) { +void QDetachTabWidget::handleShowContextMenu (const QPoint& point) { + + // Don't do anything. + if (point.isNull()) { + return; + } + + // Get the tab index at the RMB click point. + int tabIndex = tabBar()->tabAt(point); // Create the menu. QMenu menu("Window Action", this); diff --git a/src/QDetachTabWidget.h b/src/QDetachTabWidget.h index ba8f30f..65c7404 100644 --- a/src/QDetachTabWidget.h +++ b/src/QDetachTabWidget.h @@ -24,7 +24,7 @@ class QDetachTabWidget : public QTabWidget { void closeEvent (QCloseEvent* e); protected slots: - void handleShowContextMenu (int tabIndex); + void handleShowContextMenu (const QPoint& point); void handleTabClosedRequested (int tabIndex); private: