From 757671b97ff88f86fdf36a22ba1cb6d49996793e Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 15 May 2018 11:27:34 +0100 Subject: [PATCH] Add custom right-click menu to texture tabs in texture viewer --- qrenderdoc/Windows/TextureViewer.cpp | 52 ++++++++++++++++++++++++++++ qrenderdoc/Windows/TextureViewer.h | 1 + 2 files changed, 53 insertions(+) diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index 29620158d..79b13923f 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -1591,6 +1591,58 @@ void TextureViewer::SetupTextureTabs() &TextureViewer::textureTab_Closing); textureTabs->disableUserDrop(); + + textureTabs->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); + + QObject::connect(textureTabs->tabBar(), &QTabBar::customContextMenuRequested, this, + &TextureViewer::textureTab_Menu); +} + +void TextureViewer::textureTab_Menu(const QPoint &pos) +{ + ToolWindowManagerArea *textureTabs = ui->dockarea->areaOf(ui->renderContainer); + + int tabIndex = textureTabs->tabBar()->tabAt(pos); + + if(tabIndex == -1) + return; + + QAction closeTab(tr("Close tab"), this); + QAction closeOtherTabs(tr("Close other tabs"), this); + QAction closeRightTabs(tr("Close tabs to the right"), this); + + if(textureTabs->widget(tabIndex) == ui->renderContainer) + closeTab.setEnabled(false); + + QMenu contextMenu(this); + + contextMenu.addAction(&closeTab); + contextMenu.addAction(&closeOtherTabs); + contextMenu.addAction(&closeRightTabs); + + QObject::connect(&closeTab, &QAction::triggered, [this, textureTabs, tabIndex]() { + // remove the tab at this index + textureTabs->removeTab(tabIndex); + }); + + QObject::connect(&closeRightTabs, &QAction::triggered, [this, textureTabs, tabIndex]() { + // remove all tabs with a greater index + while(textureTabs->count() > tabIndex + 1) + textureTabs->removeTab(tabIndex + 1); + }); + + QObject::connect(&closeOtherTabs, &QAction::triggered, [this, textureTabs, tabIndex]() { + // remove all tabs with a greater index + while(textureTabs->count() > tabIndex + 1) + textureTabs->removeTab(tabIndex + 1); + + // remove all tabs at index 1 until there's only two, these are the ones between the locked tab + // 0 and the tabIndex + while(textureTabs->count() > 2) + textureTabs->removeTab(1); + }); + + RDDialog::show(&contextMenu, QCursor::pos()); } void TextureViewer::textureTab_Changed(int index) diff --git a/qrenderdoc/Windows/TextureViewer.h b/qrenderdoc/Windows/TextureViewer.h index 93ab74ecb..d079af679 100644 --- a/qrenderdoc/Windows/TextureViewer.h +++ b/qrenderdoc/Windows/TextureViewer.h @@ -185,6 +185,7 @@ private slots: void render_resize(QResizeEvent *e); void render_keyPress(QKeyEvent *e); + void textureTab_Menu(const QPoint &pos); void textureTab_Changed(int index); void textureTab_Closing(int index);