GUI: added options for detach/delete tabs in MHTabWidget
This commit is contained in:
parent
a134c11426
commit
13eaa8a7ae
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue