mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Allow disabling a specific tab from being dragged
* Also cancels any re-arrangements that involve that tab (mostly useful for a fixed tab at the start of the tab list).
This commit is contained in:
@@ -109,6 +109,8 @@ public:
|
||||
DisallowUserDocking = 0x1,
|
||||
//! Hides the close button on the tab for this tool window
|
||||
HideCloseButton = 0x2,
|
||||
//! Disable the user being able to drag this tab in the tab bar, to rearrange
|
||||
DisableDraggableTab = 0x4,
|
||||
};
|
||||
|
||||
//! Type of AreaReference.
|
||||
|
||||
@@ -34,11 +34,14 @@ ToolWindowManagerArea::ToolWindowManagerArea(ToolWindowManager *manager, QWidget
|
||||
{
|
||||
m_dragCanStart = false;
|
||||
m_tabDragCanStart = false;
|
||||
m_inTabMoved = false;
|
||||
setMovable(true);
|
||||
setTabsClosable(true);
|
||||
setDocumentMode(true);
|
||||
tabBar()->installEventFilter(this);
|
||||
m_manager->m_areas << this;
|
||||
|
||||
QObject::connect(tabBar(), &QTabBar::tabMoved, this, &ToolWindowManagerArea::tabMoved);
|
||||
}
|
||||
|
||||
ToolWindowManagerArea::~ToolWindowManagerArea() {
|
||||
@@ -100,9 +103,18 @@ bool ToolWindowManagerArea::eventFilter(QObject *object, QEvent *event) {
|
||||
if (object == tabBar()) {
|
||||
if (event->type() == QEvent::MouseButtonPress &&
|
||||
qApp->mouseButtons() == Qt::LeftButton) {
|
||||
|
||||
int tabIndex = tabBar()->tabAt(static_cast<QMouseEvent*>(event)->pos());
|
||||
|
||||
// can start tab drag only if mouse is at some tab, not at empty tabbar space
|
||||
if (tabBar()->tabAt(static_cast<QMouseEvent*>(event)->pos()) >= 0 ) {
|
||||
if (tabIndex >= 0) {
|
||||
m_tabDragCanStart = true;
|
||||
|
||||
if (m_manager->toolWindowProperties(widget(tabIndex)) & ToolWindowManager::DisableDraggableTab) {
|
||||
setMovable(false);
|
||||
} else {
|
||||
setMovable(true);
|
||||
}
|
||||
} else {
|
||||
m_dragCanStart = true;
|
||||
}
|
||||
@@ -193,3 +205,20 @@ void ToolWindowManagerArea::check_mouse_move() {
|
||||
m_manager->startDrag(toolWindows);
|
||||
}
|
||||
}
|
||||
|
||||
void ToolWindowManagerArea::tabMoved(int from, int to) {
|
||||
if(m_inTabMoved) return;
|
||||
|
||||
QWidget *a = widget(from);
|
||||
QWidget *b = widget(to);
|
||||
|
||||
if(!a || !b) return;
|
||||
|
||||
if(m_manager->toolWindowProperties(a) & ToolWindowManager::DisableDraggableTab ||
|
||||
m_manager->toolWindowProperties(b) & ToolWindowManager::DisableDraggableTab)
|
||||
{
|
||||
m_inTabMoved = true;
|
||||
tabBar()->moveTab(to, from);
|
||||
m_inTabMoved = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,9 @@ private:
|
||||
// that can be considered as dragging current tab
|
||||
// if the cursor will leave the tab bar area
|
||||
|
||||
bool m_inTabMoved; // if we're in the tabMoved() function (so if we call tabMove to cancel
|
||||
// the movement, we shouldn't re-check the tabMoved behaviour)
|
||||
|
||||
QVariantMap saveState(); // dump contents to variable
|
||||
void restoreState(const QVariantMap& data); //restore contents from given variable
|
||||
|
||||
@@ -91,6 +94,8 @@ private:
|
||||
friend class ToolWindowManager;
|
||||
friend class ToolWindowManagerWrapper;
|
||||
|
||||
private slots:
|
||||
void tabMoved(int from, int to);
|
||||
};
|
||||
|
||||
#endif // TOOLWINDOWMANAGERAREA_H
|
||||
|
||||
Reference in New Issue
Block a user