forked from qt-creator/qt-creator
Add a menu to Debug mode that switches perspectives
Set a menu for switching perspectives on the debug mode icon. When icons & text are shown for the modes, there is an additional arrow to the right of the mode that can be clicked to open the menu. This functionality was added in 4.1 for that purpose, finally use it. Do not show and arrow in "Icons Only" mode, so it stays small, but make it available on right-click as well. Change-Id: If19877b5231b7f01f0b3fd98cf65e8eaf9da1a5f Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -211,8 +211,9 @@ void FancyTabBar::mousePressEvent(QMouseEvent *event)
|
||||
if (rect.contains(event->pos())) {
|
||||
if (isTabEnabled(index)) {
|
||||
if (m_tabs.at(index)->hasMenu
|
||||
&& rect.right() - event->pos().x() <= kMenuButtonWidth) {
|
||||
// menu arrow clicked
|
||||
&& ((!m_iconsOnly && rect.right() - event->pos().x() <= kMenuButtonWidth)
|
||||
|| event->button() == Qt::RightButton)) {
|
||||
// menu arrow clicked or right-click
|
||||
emit menuTriggered(index, event);
|
||||
} else {
|
||||
if (index != m_currentIndex) {
|
||||
@@ -387,7 +388,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
paintIconAndText(painter, rect, tab->icon, tab->text, enabled, selected);
|
||||
|
||||
// menu arrow
|
||||
if (tab->hasMenu) {
|
||||
if (tab->hasMenu && !m_iconsOnly) {
|
||||
QStyleOption opt;
|
||||
opt.initFrom(this);
|
||||
opt.rect = rect.adjusted(rect.width() - kMenuButtonWidth, 0, -8, 0);
|
||||
|
@@ -158,6 +158,7 @@ public:
|
||||
DebuggerMainWindow *q = nullptr;
|
||||
QPointer<Perspective> m_currentPerspective = nullptr;
|
||||
QComboBox *m_perspectiveChooser = nullptr;
|
||||
QMenu *m_perspectiveMenu;
|
||||
QStackedWidget *m_centralWidgetStack = nullptr;
|
||||
QHBoxLayout *m_subPerspectiveSwitcherLayout = nullptr;
|
||||
QHBoxLayout *m_innerToolsLayout = nullptr;
|
||||
@@ -186,8 +187,7 @@ DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *parent)
|
||||
m_perspectiveChooser->setObjectName("PerspectiveChooser");
|
||||
m_perspectiveChooser->setProperty("panelwidget", true);
|
||||
m_perspectiveChooser->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
connect(m_perspectiveChooser, QOverload<int>::of(&QComboBox::activated),
|
||||
this, [this](int item) {
|
||||
connect(m_perspectiveChooser, QOverload<int>::of(&QComboBox::activated), this, [this](int item) {
|
||||
Perspective *perspective = Perspective::findPerspective(m_perspectiveChooser->itemData(item).toString());
|
||||
QTC_ASSERT(perspective, return);
|
||||
if (auto subPerspective = Perspective::findPerspective(perspective->d->m_lastActiveSubPerspectiveId))
|
||||
@@ -196,6 +196,20 @@ DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *parent)
|
||||
perspective->select();
|
||||
});
|
||||
|
||||
m_perspectiveMenu = new QMenu;
|
||||
connect(m_perspectiveMenu, &QMenu::aboutToShow, this, [this] {
|
||||
m_perspectiveMenu->clear();
|
||||
for (Perspective *perspective : qAsConst(m_perspectives)) {
|
||||
m_perspectiveMenu->addAction(perspective->d->m_name, perspective, [perspective] {
|
||||
if (auto subPerspective = Perspective::findPerspective(
|
||||
perspective->d->m_lastActiveSubPerspectiveId))
|
||||
subPerspective->select();
|
||||
else
|
||||
perspective->select();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
auto viewButton = new QToolButton;
|
||||
viewButton->setText(DebuggerMainWindow::tr("&Views"));
|
||||
|
||||
@@ -263,6 +277,7 @@ DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *parent)
|
||||
DebuggerMainWindowPrivate::~DebuggerMainWindowPrivate()
|
||||
{
|
||||
delete m_editorPlaceHolder;
|
||||
delete m_perspectiveMenu;
|
||||
}
|
||||
|
||||
DebuggerMainWindow::DebuggerMainWindow()
|
||||
@@ -511,6 +526,11 @@ void DebuggerMainWindow::addSubPerspectiveSwitcher(QWidget *widget)
|
||||
d->m_subPerspectiveSwitcherLayout->addWidget(widget);
|
||||
}
|
||||
|
||||
QMenu *DebuggerMainWindow::perspectiveMenu()
|
||||
{
|
||||
return theMainWindow ? theMainWindow->d->m_perspectiveMenu : nullptr;
|
||||
}
|
||||
|
||||
DebuggerMainWindow *DebuggerMainWindow::instance()
|
||||
{
|
||||
return theMainWindow;
|
||||
|
@@ -140,6 +140,7 @@ public:
|
||||
|
||||
static QWidget *centralWidgetStack();
|
||||
void addSubPerspectiveSwitcher(QWidget *widget);
|
||||
static QMenu *perspectiveMenu();
|
||||
|
||||
static Perspective *currentPerspective();
|
||||
|
||||
|
@@ -547,6 +547,8 @@ public:
|
||||
mainWindow->addSubPerspectiveSwitcher(EngineManager::engineChooser());
|
||||
|
||||
setWidget(splitter);
|
||||
|
||||
setMenu(DebuggerMainWindow::perspectiveMenu());
|
||||
}
|
||||
|
||||
~DebugMode() { delete widget(); }
|
||||
|
Reference in New Issue
Block a user