From 13eaa8a7aeb00bc6bd892b0fcc9b528c4a41b8fb Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Tue, 30 Dec 2014 00:54:13 +0100 Subject: [PATCH] GUI: added options for detach/delete tabs in MHTabWidget --- x64_dbg_gui/Project/Src/Gui/TabBar.cpp | 19 ++++++++++++++++--- x64_dbg_gui/Project/Src/Gui/TabBar.h | 6 +++++- x64_dbg_gui/Project/Src/Gui/TabWidget.cpp | 11 +++++++++-- x64_dbg_gui/Project/Src/Gui/TabWidget.h | 5 ++++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/x64_dbg_gui/Project/Src/Gui/TabBar.cpp b/x64_dbg_gui/Project/Src/Gui/TabBar.cpp index 69be9960..2fef8e37 100644 --- a/x64_dbg_gui/Project/Src/Gui/TabBar.cpp +++ b/x64_dbg_gui/Project/Src/Gui/TabBar.cpp @@ -14,8 +14,10 @@ ////////////////////////////////////////////////////////////// // Default Constructor ////////////////////////////////////////////////////////////// -MHTabBar::MHTabBar(QWidget* parent) : QTabBar(parent) +MHTabBar::MHTabBar(QWidget* parent, bool allowDetach, bool allowDelete) : QTabBar(parent) { + mAllowDetach = allowDetach; + mAllowDelete = allowDelete; setAcceptDrops(true); setElideMode(Qt::ElideRight); setSelectionBehaviorOnRemove(QTabBar::SelectLeftTab); @@ -31,14 +33,25 @@ MHTabBar::~MHTabBar(void) void MHTabBar::contextMenuEvent(QContextMenuEvent* event) { + if(!mAllowDetach && !mAllowDelete) + return; QMenu wMenu(this); QAction wDetach("&Detach", this); - wMenu.addAction(&wDetach); - if(wMenu.exec(event->globalPos()) == &wDetach) + if(mAllowDetach) + wMenu.addAction(&wDetach); + QAction wDelete("&Delete", this); + if(mAllowDelete) + wMenu.addAction(&wDelete); + QAction* executed = wMenu.exec(event->globalPos()); + if(executed == &wDetach) { QPoint p(0, 0); OnDetachTab((int)tabAt(event->pos()), p); } + else if(executed == &wDelete) + { + OnDeleteTab((int)tabAt(event->pos())); + } } diff --git a/x64_dbg_gui/Project/Src/Gui/TabBar.h b/x64_dbg_gui/Project/Src/Gui/TabBar.h index 3e456247..affb236d 100644 --- a/x64_dbg_gui/Project/Src/Gui/TabBar.h +++ b/x64_dbg_gui/Project/Src/Gui/TabBar.h @@ -18,7 +18,7 @@ class MHTabBar: public QTabBar { Q_OBJECT public: - MHTabBar(QWidget* parent); + MHTabBar(QWidget* parent, bool allowDetach, bool allowDelete); ~MHTabBar(void); protected: @@ -36,8 +36,12 @@ signals: void OnDetachTab(int index, QPoint & dropPoint); // Move Tab void OnMoveTab(int fromIndex, int toIndex); + // Delete Tab + void OnDeleteTab(int index); private: + bool mAllowDetach; + bool mAllowDelete; /* QPoint m_dragStartPos; QPoint m_dragMovedPos; diff --git a/x64_dbg_gui/Project/Src/Gui/TabWidget.cpp b/x64_dbg_gui/Project/Src/Gui/TabWidget.cpp index 46317380..f7e0ef6d 100644 --- a/x64_dbg_gui/Project/Src/Gui/TabWidget.cpp +++ b/x64_dbg_gui/Project/Src/Gui/TabWidget.cpp @@ -5,11 +5,12 @@ ////////////////////////////////////////////////////////////// // Default Constructor ////////////////////////////////////////////////////////////// -MHTabWidget::MHTabWidget(QWidget* parent) : QTabWidget(parent) +MHTabWidget::MHTabWidget(QWidget* parent, bool allowDetach, bool allowDelete) : QTabWidget(parent) { - m_tabBar = new MHTabBar(this); + m_tabBar = new MHTabBar(this, allowDetach, allowDelete); connect(m_tabBar, SIGNAL(OnDetachTab(int, QPoint &)), this, SLOT(DetachTab(int, QPoint &))); connect(m_tabBar, SIGNAL(OnMoveTab(int, int)), this, SLOT(MoveTab(int, int))); + connect(m_tabBar, SIGNAL(OnDeleteTab(int)), this, SLOT(DeleteTab(int))); setTabBar(m_tabBar); setMovable(true); @@ -29,6 +30,7 @@ MHTabWidget::~MHTabWidget(void) { disconnect(m_tabBar, SIGNAL(OnMoveTab(int, int)), this, SLOT(MoveTab(int, int))); disconnect(m_tabBar, SIGNAL(OnDetachTab(int, QPoint &)), this, SLOT(DetachTab(int, QPoint &))); + disconnect(m_tabBar, SIGNAL(OnDeleteTab(int)), this, SLOT(DeleteTab(int))); delete m_tabBar; } @@ -120,6 +122,11 @@ void MHTabWidget::DetachTab(int index, QPoint & dropPoint) detachedWidget->showNormal(); } +void MHTabWidget::DeleteTab(int index) +{ + removeTab(index); +} + ////////////////////////////////////////////////////////////////////////////// void MHTabWidget::AttachTab(QWidget* parent) { diff --git a/x64_dbg_gui/Project/Src/Gui/TabWidget.h b/x64_dbg_gui/Project/Src/Gui/TabWidget.h index 2c4411d2..762d98a6 100644 --- a/x64_dbg_gui/Project/Src/Gui/TabWidget.h +++ b/x64_dbg_gui/Project/Src/Gui/TabWidget.h @@ -22,7 +22,7 @@ class MHTabWidget: public QTabWidget Q_OBJECT public: - MHTabWidget(QWidget* parent); + MHTabWidget(QWidget* parent, bool allowDetach = true, bool allowDelete = false); virtual ~MHTabWidget(void); QTabBar* tabBar(); @@ -39,6 +39,9 @@ public slots: // Attach Tab void AttachTab(QWidget* parent); + // Delete Tab + void DeleteTab(int index); + public Q_SLOTS: void setCurrentIndex(int index); void setCurrentWidget(QWidget* widget);