2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "navigationwidget.h"
|
2022-07-05 13:56:04 +02:00
|
|
|
#include "actionmanager/actionmanager.h"
|
|
|
|
|
#include "actionmanager/command.h"
|
|
|
|
|
#include "coreplugintr.h"
|
2010-06-25 12:56:16 +02:00
|
|
|
#include "icontext.h"
|
2013-05-07 11:39:45 +02:00
|
|
|
#include "icore.h"
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
#include "imode.h"
|
2009-01-23 13:03:36 +01:00
|
|
|
#include "inavigationwidgetfactory.h"
|
|
|
|
|
#include "modemanager.h"
|
2022-07-05 13:56:04 +02:00
|
|
|
#include "navigationsubwidget.h"
|
2009-01-23 13:03:36 +01:00
|
|
|
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/fancymainwindow.h>
|
2016-09-17 18:31:56 +03:00
|
|
|
#include <utils/qtcassert.h>
|
2016-08-03 17:55:54 +02:00
|
|
|
#include <utils/utilsicons.h>
|
|
|
|
|
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
#include <aggregation/aggregate.h>
|
|
|
|
|
|
2023-09-27 15:41:10 +02:00
|
|
|
#include <QAction>
|
2015-04-23 23:57:48 +03:00
|
|
|
#include <QCoreApplication>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
#include <QDockWidget>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QResizeEvent>
|
|
|
|
|
#include <QStandardItemModel>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::INavigationWidgetFactory *)
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
namespace Core {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2024-01-10 23:51:10 +01:00
|
|
|
struct ActivationInfo {
|
|
|
|
|
Side side;
|
|
|
|
|
int position;
|
|
|
|
|
};
|
|
|
|
|
using ActivationsMap = QHash<Id, ActivationInfo>;
|
|
|
|
|
|
|
|
|
|
static NavigationWidget *s_instanceLeft = nullptr;
|
|
|
|
|
static NavigationWidget *s_instanceRight = nullptr;
|
|
|
|
|
static ActivationsMap s_activationsMap = {};
|
|
|
|
|
|
|
|
|
|
static void addActivationInfo(Id activatedId, const ActivationInfo &activationInfo)
|
|
|
|
|
{
|
|
|
|
|
s_activationsMap.insert(activatedId, activationInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget *instance(Side side)
|
|
|
|
|
{
|
|
|
|
|
return side == Side::Left ? s_instanceLeft : s_instanceRight;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPlaceHolder *NavigationWidgetPlaceHolder::s_currentLeft = nullptr;
|
|
|
|
|
NavigationWidgetPlaceHolder *NavigationWidgetPlaceHolder::s_currentRight = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPlaceHolder *NavigationWidgetPlaceHolder::current(Side side)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
return side == Side::Left ? s_currentLeft : s_currentRight;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
void NavigationWidgetPlaceHolder::setCurrent(Side side, NavigationWidgetPlaceHolder *navWidget)
|
|
|
|
|
{
|
|
|
|
|
if (side == Side::Left)
|
|
|
|
|
s_currentLeft = navWidget;
|
|
|
|
|
else
|
|
|
|
|
s_currentRight = navWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidgetPlaceHolder::NavigationWidgetPlaceHolder(Id mode, Side side, QWidget *parent)
|
|
|
|
|
:QWidget(parent), m_mode(mode), m_side(side)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setLayout(new QVBoxLayout);
|
2019-08-29 10:36:01 +02:00
|
|
|
layout()->setContentsMargins(0, 0, 0, 0);
|
2014-11-16 10:52:41 +02:00
|
|
|
connect(ModeManager::instance(), &ModeManager::currentModeAboutToChange,
|
|
|
|
|
this, &NavigationWidgetPlaceHolder::currentModeAboutToChange);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidgetPlaceHolder::~NavigationWidgetPlaceHolder()
|
|
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
if (NavigationWidgetPlaceHolder::current(m_side) == this) {
|
2024-01-10 23:51:10 +01:00
|
|
|
if (NavigationWidget *nw = instance(m_side)) {
|
2016-09-17 18:31:56 +03:00
|
|
|
nw->setParent(nullptr);
|
2011-03-15 14:52:35 +01:00
|
|
|
nw->hide();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
void NavigationWidgetPlaceHolder::applyStoredSize()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-07-21 21:11:46 +02:00
|
|
|
auto splitter = qobject_cast<QSplitter *>(parentWidget());
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
if (splitter) {
|
|
|
|
|
// A splitter we need to resize the splitter sizes
|
|
|
|
|
QList<int> sizes = splitter->sizes();
|
|
|
|
|
int diff = 0;
|
|
|
|
|
int count = sizes.count();
|
|
|
|
|
for (int i = 0; i < sizes.count(); ++i) {
|
|
|
|
|
if (auto ph = qobject_cast<NavigationWidgetPlaceHolder *>(splitter->widget(i))) {
|
|
|
|
|
--count;
|
|
|
|
|
int width = ph->storedWidth();
|
|
|
|
|
diff += width - sizes.at(i);
|
|
|
|
|
sizes[i] = width;
|
2016-09-17 18:31:56 +03:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
int adjust = count > 1 ? (diff / (count - 1)) : 0;
|
|
|
|
|
for (int i = 0; i < sizes.count(); ++i) {
|
|
|
|
|
if (!qobject_cast<NavigationWidgetPlaceHolder *>(splitter->widget(i)))
|
|
|
|
|
sizes[i] += adjust;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
splitter->setSizes(sizes);
|
|
|
|
|
} else {
|
|
|
|
|
QSize s = size();
|
|
|
|
|
s.setWidth(storedWidth());
|
|
|
|
|
resize(s);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This function does work even though the order in which
|
|
|
|
|
// the placeHolder get the signal is undefined.
|
|
|
|
|
// It does ensure that after all PlaceHolders got the signal
|
|
|
|
|
// m_current points to the current PlaceHolder, or zero if there
|
|
|
|
|
// is no PlaceHolder in this mode
|
|
|
|
|
// And that the parent of the NavigationWidget gets the correct parent
|
2016-03-25 20:00:19 +01:00
|
|
|
void NavigationWidgetPlaceHolder::currentModeAboutToChange(Id mode)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2024-01-10 23:51:10 +01:00
|
|
|
NavigationWidget *navigationWidget = instance(m_side);
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPlaceHolder *current = NavigationWidgetPlaceHolder::current(m_side);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
if (current == this) {
|
|
|
|
|
setCurrent(m_side, nullptr);
|
|
|
|
|
navigationWidget->setParent(nullptr);
|
2008-12-02 12:01:29 +01:00
|
|
|
navigationWidget->hide();
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
navigationWidget->placeHolderChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2016-09-17 18:31:56 +03:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_mode == mode) {
|
2016-09-17 18:31:56 +03:00
|
|
|
setCurrent(m_side, this);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
layout()->addWidget(navigationWidget);
|
|
|
|
|
navigationWidget->show();
|
|
|
|
|
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
applyStoredSize();
|
2008-12-02 12:01:29 +01:00
|
|
|
setVisible(navigationWidget->isShown());
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
navigationWidget->placeHolderChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
int NavigationWidgetPlaceHolder::storedWidth() const
|
|
|
|
|
{
|
2024-01-10 23:51:10 +01:00
|
|
|
return instance(m_side)->storedWidth();
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-09 12:07:41 +01:00
|
|
|
struct NavigationWidgetPrivate
|
|
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
explicit NavigationWidgetPrivate(QAction *toggleSideBarAction, Side side);
|
2013-11-13 13:34:23 +01:00
|
|
|
~NavigationWidgetPrivate() { delete m_factoryModel; }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
QList<Internal::NavigationSubWidget *> m_subWidgets;
|
2014-11-16 10:52:41 +02:00
|
|
|
QHash<QAction *, Id> m_actionMap;
|
|
|
|
|
QHash<Id, Command *> m_commandMap;
|
2010-09-16 12:26:28 +02:00
|
|
|
QStandardItemModel *m_factoryModel;
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
FancyMainWindow *m_mainWindow = nullptr;
|
2010-09-16 12:26:28 +02:00
|
|
|
|
|
|
|
|
bool m_shown;
|
|
|
|
|
int m_width;
|
2013-11-13 13:34:23 +01:00
|
|
|
QAction *m_toggleSideBarAction; // does not take ownership
|
2016-09-17 18:31:56 +03:00
|
|
|
Side m_side;
|
2010-09-16 12:26:28 +02:00
|
|
|
};
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPrivate::NavigationWidgetPrivate(QAction *toggleSideBarAction, Side side) :
|
2010-07-15 12:24:03 +02:00
|
|
|
m_factoryModel(new QStandardItemModel),
|
|
|
|
|
m_shown(true),
|
|
|
|
|
m_width(0),
|
2016-09-17 18:31:56 +03:00
|
|
|
m_toggleSideBarAction(toggleSideBarAction),
|
|
|
|
|
m_side(side)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget::NavigationWidget(QAction *toggleSideBarAction, Side side) :
|
|
|
|
|
d(new NavigationWidgetPrivate(toggleSideBarAction, side))
|
2010-09-16 12:26:28 +02:00
|
|
|
{
|
|
|
|
|
d->m_factoryModel->setSortRole(FactoryPriorityRole);
|
2008-12-02 12:01:29 +01:00
|
|
|
setOrientation(Qt::Vertical);
|
2016-09-17 18:31:56 +03:00
|
|
|
|
|
|
|
|
if (side == Side::Left)
|
2024-01-10 23:51:10 +01:00
|
|
|
s_instanceLeft = this;
|
2016-09-17 18:31:56 +03:00
|
|
|
else
|
2024-01-10 23:51:10 +01:00
|
|
|
s_instanceRight = this;
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
|
|
|
|
|
connect(ModeManager::instance(),
|
2023-11-28 16:30:17 +01:00
|
|
|
&ModeManager::currentMainWindowChanged,
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
this,
|
|
|
|
|
&NavigationWidget::updateMode);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationWidget::~NavigationWidget()
|
|
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
if (d->m_side == Side::Left)
|
2024-01-10 23:51:10 +01:00
|
|
|
s_instanceLeft = nullptr;
|
2016-09-17 18:31:56 +03:00
|
|
|
else
|
2024-01-10 23:51:10 +01:00
|
|
|
s_instanceRight = nullptr;
|
2011-09-16 15:00:41 +02:00
|
|
|
delete d;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
QWidget *NavigationWidget::activateSubWidget(Id factoryId, Side fallbackSide)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2024-01-10 23:51:10 +01:00
|
|
|
NavigationWidget *navigationWidget = instance(fallbackSide);
|
2016-09-17 18:31:56 +03:00
|
|
|
int preferredPosition = -1;
|
|
|
|
|
|
2024-01-10 23:51:10 +01:00
|
|
|
// TODO: Use find
|
|
|
|
|
if (s_activationsMap.contains(factoryId)) {
|
|
|
|
|
const ActivationInfo info = s_activationsMap.value(factoryId);
|
|
|
|
|
navigationWidget = instance(info.side);
|
2016-09-17 18:31:56 +03:00
|
|
|
preferredPosition = info.position;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-17 17:33:47 +02:00
|
|
|
return navigationWidget->activateSubWidget(factoryId, preferredPosition);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-13 13:34:47 +01:00
|
|
|
void NavigationWidget::setFactories(const QList<INavigationWidgetFactory *> &factories)
|
2010-07-15 12:24:03 +02:00
|
|
|
{
|
2014-11-16 10:52:41 +02:00
|
|
|
Context navicontext(Constants::C_NAVIGATION_PANE);
|
2022-10-07 14:46:06 +02:00
|
|
|
for (INavigationWidgetFactory *factory : std::as_const(factories)) {
|
2011-11-09 12:07:41 +01:00
|
|
|
const Id id = factory->id();
|
2016-09-17 18:31:56 +03:00
|
|
|
const Id actionId = id.withPrefix("QtCreator.Sidebar.");
|
|
|
|
|
|
|
|
|
|
if (!ActionManager::command(actionId)) {
|
2023-01-16 17:20:07 +01:00
|
|
|
QAction *action = new QAction(Tr::tr("Activate %1 View").arg(factory->displayName()), this);
|
2016-09-17 18:31:56 +03:00
|
|
|
d->m_actionMap.insert(action, id);
|
2022-12-07 16:25:11 +01:00
|
|
|
connect(action, &QAction::triggered, this, [this, action] {
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidget::activateSubWidget(d->m_actionMap[action], Side::Left);
|
|
|
|
|
});
|
|
|
|
|
Command *cmd = ActionManager::registerAction(action, actionId, navicontext);
|
|
|
|
|
cmd->setDefaultKeySequence(factory->activationSequence());
|
|
|
|
|
d->m_commandMap.insert(id, cmd);
|
|
|
|
|
}
|
2010-07-15 12:24:03 +02:00
|
|
|
|
|
|
|
|
QStandardItem *newRow = new QStandardItem(factory->displayName());
|
2019-05-27 13:32:20 +02:00
|
|
|
newRow->setData(QVariant::fromValue(factory), FactoryObjectRole);
|
2011-11-09 12:07:41 +01:00
|
|
|
newRow->setData(QVariant::fromValue(factory->id()), FactoryIdRole);
|
2021-09-21 16:21:33 +02:00
|
|
|
newRow->setData(QVariant::fromValue(actionId), FactoryActionIdRole);
|
2010-09-09 14:35:26 +02:00
|
|
|
newRow->setData(factory->priority(), FactoryPriorityRole);
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_factoryModel->appendRow(newRow);
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_factoryModel->sort(0);
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
updateToggleAction();
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-23 17:51:05 +02:00
|
|
|
Key NavigationWidget::settingsGroup() const
|
2016-09-17 18:31:56 +03:00
|
|
|
{
|
2023-08-23 17:51:05 +02:00
|
|
|
return d->m_side == Side::Left ? Key("NavigationLeft") : Key("NavigationRight");
|
2016-09-17 18:31:56 +03:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int NavigationWidget::storedWidth()
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_width;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 12:24:03 +02:00
|
|
|
QAbstractItemModel *NavigationWidget::factoryModel() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_factoryModel;
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
void NavigationWidget::updateMode()
|
2009-12-08 18:29:44 +01:00
|
|
|
{
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
IMode *currentMode = ModeManager::currentMode();
|
|
|
|
|
FancyMainWindow *mainWindow = currentMode ? currentMode->mainWindow() : nullptr;
|
|
|
|
|
if (d->m_mainWindow == mainWindow)
|
|
|
|
|
return;
|
|
|
|
|
if (d->m_mainWindow)
|
|
|
|
|
disconnect(d->m_mainWindow, nullptr, this, nullptr);
|
|
|
|
|
d->m_mainWindow = mainWindow;
|
|
|
|
|
if (d->m_mainWindow)
|
|
|
|
|
connect(d->m_mainWindow,
|
|
|
|
|
&FancyMainWindow::dockWidgetsChanged,
|
|
|
|
|
this,
|
|
|
|
|
&NavigationWidget::updateToggleAction);
|
|
|
|
|
updateToggleAction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::updateToggleAction()
|
|
|
|
|
{
|
|
|
|
|
d->m_toggleSideBarAction->setVisible(toggleActionVisible());
|
|
|
|
|
d->m_toggleSideBarAction->setEnabled(toggleActionEnabled());
|
|
|
|
|
d->m_toggleSideBarAction->setChecked(toggleActionChecked());
|
|
|
|
|
const char *trToolTip = d->m_side == Side::Left ? (d->m_toggleSideBarAction->isChecked()
|
|
|
|
|
? Constants::TR_HIDE_LEFT_SIDEBAR
|
|
|
|
|
: Constants::TR_SHOW_LEFT_SIDEBAR)
|
|
|
|
|
: (d->m_toggleSideBarAction->isChecked()
|
|
|
|
|
? Constants::TR_HIDE_RIGHT_SIDEBAR
|
|
|
|
|
: Constants::TR_SHOW_RIGHT_SIDEBAR);
|
2016-09-17 18:31:56 +03:00
|
|
|
|
2022-07-05 13:56:04 +02:00
|
|
|
d->m_toggleSideBarAction->setToolTip(Tr::tr(trToolTip));
|
2009-12-08 18:29:44 +01:00
|
|
|
}
|
|
|
|
|
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
void NavigationWidget::placeHolderChanged()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
updateToggleAction();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::resizeEvent(QResizeEvent *re)
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_width && re->size().width())
|
|
|
|
|
d->m_width = re->size().width();
|
2008-12-02 12:01:29 +01:00
|
|
|
MiniSplitter::resizeEvent(re);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-25 15:05:56 +02:00
|
|
|
static QIcon closeIconForSide(Side side, int itemCount)
|
|
|
|
|
{
|
|
|
|
|
if (itemCount > 1)
|
|
|
|
|
return Utils::Icons::CLOSE_SPLIT_TOP.icon();
|
|
|
|
|
return side == Side::Left
|
|
|
|
|
? Utils::Icons::CLOSE_SPLIT_LEFT.icon()
|
|
|
|
|
: Utils::Icons::CLOSE_SPLIT_RIGHT.icon();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-25 09:18:49 +02:00
|
|
|
Internal::NavigationSubWidget *NavigationWidget::insertSubItem(int position,
|
|
|
|
|
int factoryIndex,
|
|
|
|
|
bool updateActivationsMap)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int pos = position + 1; pos < d->m_subWidgets.size(); ++pos) {
|
2016-09-17 18:31:56 +03:00
|
|
|
Internal::NavigationSubWidget *nsw = d->m_subWidgets.at(pos);
|
|
|
|
|
nsw->setPosition(pos + 1);
|
2024-01-10 23:51:10 +01:00
|
|
|
addActivationInfo(nsw->factory()->id(), {d->m_side, pos + 1});
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-19 17:07:49 +01:00
|
|
|
if (!d->m_subWidgets.isEmpty()) // Make all icons the bottom icon
|
2016-08-03 17:55:54 +02:00
|
|
|
d->m_subWidgets.at(0)->setCloseIcon(Utils::Icons::CLOSE_SPLIT_BOTTOM.icon());
|
2015-01-19 17:07:49 +01:00
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
auto nsw = new Internal::NavigationSubWidget(this, position, factoryIndex);
|
2022-07-20 12:05:49 +02:00
|
|
|
connect(nsw, &Internal::NavigationSubWidget::splitMe, this, [this, nsw](int factoryIndex) {
|
|
|
|
|
insertSubItem(indexOf(nsw) + 1, factoryIndex);
|
|
|
|
|
});
|
|
|
|
|
connect(nsw, &Internal::NavigationSubWidget::closeMe, this, [this, nsw] {
|
|
|
|
|
closeSubWidget(nsw);
|
|
|
|
|
});
|
|
|
|
|
connect(nsw, &Internal::NavigationSubWidget::factoryIndexChanged, this, [this, nsw] {
|
|
|
|
|
const Id factoryId = nsw->factory()->id();
|
2024-01-10 23:51:10 +01:00
|
|
|
addActivationInfo(factoryId, {d->m_side, nsw->position()});
|
2022-07-20 12:05:49 +02:00
|
|
|
});
|
2008-12-02 12:01:29 +01:00
|
|
|
insertWidget(position, nsw);
|
2016-09-17 18:31:56 +03:00
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.insert(position, nsw);
|
2017-07-25 15:05:56 +02:00
|
|
|
d->m_subWidgets.at(0)->setCloseIcon(closeIconForSide(d->m_side, d->m_subWidgets.size()));
|
2023-10-25 09:18:49 +02:00
|
|
|
if (updateActivationsMap)
|
2024-01-10 23:51:10 +01:00
|
|
|
addActivationInfo(nsw->factory()->id(), {d->m_side, position});
|
2008-12-02 12:01:29 +01:00
|
|
|
return nsw;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
QWidget *NavigationWidget::activateSubWidget(Id factoryId, int preferredPosition)
|
2010-08-13 10:10:43 +02:00
|
|
|
{
|
|
|
|
|
setShown(true);
|
2022-10-07 14:46:06 +02:00
|
|
|
for (Internal::NavigationSubWidget *subWidget : std::as_const(d->m_subWidgets)) {
|
2010-08-13 10:10:43 +02:00
|
|
|
if (subWidget->factory()->id() == factoryId) {
|
2008-12-02 12:01:29 +01:00
|
|
|
subWidget->setFocusWidget();
|
2013-05-07 11:39:45 +02:00
|
|
|
ICore::raiseWindow(this);
|
2015-08-20 14:47:02 +02:00
|
|
|
return subWidget->widget();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-08-13 10:10:43 +02:00
|
|
|
int index = factoryIndex(factoryId);
|
2010-07-15 12:24:03 +02:00
|
|
|
if (index >= 0) {
|
2016-09-17 18:31:56 +03:00
|
|
|
bool preferredIndexValid = 0 <= preferredPosition && preferredPosition < d->m_subWidgets.count();
|
|
|
|
|
const int activationIndex = preferredIndexValid ? preferredPosition : 0;
|
|
|
|
|
Internal::NavigationSubWidget *subWidget = d->m_subWidgets.at(activationIndex);
|
|
|
|
|
subWidget->setFactoryIndex(index);
|
|
|
|
|
subWidget->setFocusWidget();
|
2013-05-07 11:39:45 +02:00
|
|
|
ICore::raiseWindow(this);
|
2016-09-17 18:31:56 +03:00
|
|
|
return subWidget->widget();
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2015-08-25 11:43:29 +02:00
|
|
|
return nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-20 12:05:49 +02:00
|
|
|
void NavigationWidget::closeSubWidget(Internal::NavigationSubWidget *subWidget)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
if (d->m_subWidgets.count() != 1) {
|
2010-07-15 12:24:03 +02:00
|
|
|
subWidget->saveSettings();
|
2016-09-17 18:31:56 +03:00
|
|
|
|
|
|
|
|
int position = d->m_subWidgets.indexOf(subWidget);
|
|
|
|
|
for (int pos = position + 1; pos < d->m_subWidgets.size(); ++pos) {
|
|
|
|
|
Internal::NavigationSubWidget *nsw = d->m_subWidgets.at(pos);
|
|
|
|
|
nsw->setPosition(pos - 1);
|
2024-01-10 23:51:10 +01:00
|
|
|
addActivationInfo(nsw->factory()->id(), {d->m_side, pos - 1});
|
2016-09-17 18:31:56 +03:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.removeOne(subWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
subWidget->hide();
|
|
|
|
|
subWidget->deleteLater();
|
2015-01-19 17:07:49 +01:00
|
|
|
// update close button of top item
|
2017-07-25 15:05:56 +02:00
|
|
|
if (!d->m_subWidgets.isEmpty())
|
|
|
|
|
d->m_subWidgets.at(0)->setCloseIcon(closeIconForSide(d->m_side, d->m_subWidgets.size()));
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
|
|
|
|
setShown(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
bool NavigationWidget::toggleActionVisible() const
|
|
|
|
|
{
|
|
|
|
|
const bool haveData = d->m_factoryModel->rowCount();
|
|
|
|
|
return haveData || d->m_mainWindow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Qt::DockWidgetArea dockAreaForSide(Side side)
|
|
|
|
|
{
|
|
|
|
|
return side == Side::Left ? Qt::LeftDockWidgetArea : Qt::RightDockWidgetArea;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavigationWidget::toggleActionEnabled() const
|
|
|
|
|
{
|
|
|
|
|
const bool haveData = d->m_factoryModel->rowCount();
|
|
|
|
|
if (haveData && NavigationWidgetPlaceHolder::current(d->m_side))
|
|
|
|
|
return true;
|
|
|
|
|
if (!d->m_mainWindow)
|
|
|
|
|
return false;
|
|
|
|
|
return d->m_mainWindow->isDockAreaAvailable(dockAreaForSide(d->m_side));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavigationWidget::toggleActionChecked() const
|
|
|
|
|
{
|
|
|
|
|
const bool haveData = d->m_factoryModel->rowCount();
|
|
|
|
|
if (haveData && NavigationWidgetPlaceHolder::current(d->m_side))
|
|
|
|
|
return d->m_shown;
|
|
|
|
|
if (!d->m_mainWindow)
|
|
|
|
|
return false;
|
|
|
|
|
return d->m_mainWindow->isDockAreaVisible(dockAreaForSide(d->m_side));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 11:24:27 +01:00
|
|
|
static QString defaultFirstView(Side side)
|
|
|
|
|
{
|
|
|
|
|
return side == Side::Left ? QString("Projects") : QString("Outline");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool defaultVisible(Side side)
|
|
|
|
|
{
|
|
|
|
|
return side == Side::Left;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NavigationWidget::saveSettings(QtcSettings *settings)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-15 12:24:03 +02:00
|
|
|
QStringList viewIds;
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int i=0; i<d->m_subWidgets.count(); ++i) {
|
|
|
|
|
d->m_subWidgets.at(i)->saveSettings();
|
2011-11-09 12:07:41 +01:00
|
|
|
viewIds.append(d->m_subWidgets.at(i)->factory()->id().toString());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2020-12-10 11:24:27 +01:00
|
|
|
settings->setValueWithDefault(settingsKey("Views"), viewIds, {defaultFirstView(d->m_side)});
|
|
|
|
|
settings->setValueWithDefault(settingsKey("Visible"), isShown(), defaultVisible(d->m_side));
|
2016-09-17 18:31:56 +03:00
|
|
|
settings->setValue(settingsKey("VerticalPosition"), saveState());
|
|
|
|
|
settings->setValue(settingsKey("Width"), d->m_width);
|
|
|
|
|
|
2023-08-23 17:51:05 +02:00
|
|
|
const Key activationKey = "ActivationPosition.";
|
2024-01-10 23:51:10 +01:00
|
|
|
const auto keys = s_activationsMap.keys();
|
2016-09-17 18:31:56 +03:00
|
|
|
for (const auto &factoryId : keys) {
|
2024-01-10 23:51:10 +01:00
|
|
|
const auto &info = s_activationsMap[factoryId];
|
2023-10-25 09:18:49 +02:00
|
|
|
const Utils::Key key = settingsKey(activationKey + factoryId.name());
|
2016-09-17 18:31:56 +03:00
|
|
|
if (info.side == d->m_side)
|
2023-10-25 09:18:49 +02:00
|
|
|
settings->setValue(key, info.position);
|
|
|
|
|
else
|
|
|
|
|
settings->remove(key);
|
2016-09-17 18:31:56 +03:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-05 09:20:31 +02:00
|
|
|
void NavigationWidget::restoreSettings(QtcSettings *settings)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-10-21 17:49:19 +02:00
|
|
|
if (!d->m_factoryModel->rowCount()) {
|
|
|
|
|
// We have no widgets to show!
|
|
|
|
|
setShown(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
const bool isLeftSide = d->m_side == Side::Left;
|
2020-12-10 11:24:27 +01:00
|
|
|
QStringList viewIds = settings
|
|
|
|
|
->value(settingsKey("Views"), QStringList(defaultFirstView(d->m_side)))
|
|
|
|
|
.toStringList();
|
2009-03-26 15:54:05 +01:00
|
|
|
|
|
|
|
|
bool restoreSplitterState = true;
|
2016-09-17 18:31:56 +03:00
|
|
|
int version = settings->value(settingsKey("Version"), 1).toInt();
|
2009-03-26 15:54:05 +01:00
|
|
|
if (version == 1) {
|
2016-09-17 18:31:56 +03:00
|
|
|
QLatin1String defaultSecondView = isLeftSide ? QLatin1String("Open Documents") : QLatin1String("Bookmarks");
|
|
|
|
|
if (!viewIds.contains(defaultSecondView)) {
|
|
|
|
|
viewIds += defaultSecondView;
|
2009-03-26 15:54:05 +01:00
|
|
|
restoreSplitterState = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2016-09-17 18:31:56 +03:00
|
|
|
settings->setValue(settingsKey("Version"), 2);
|
2009-03-26 15:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-21 11:54:11 +02:00
|
|
|
int position = 0;
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const QString &id : std::as_const(viewIds)) {
|
2013-01-16 14:18:35 +01:00
|
|
|
int index = factoryIndex(Id::fromString(id));
|
2010-10-21 11:54:11 +02:00
|
|
|
if (index >= 0) {
|
|
|
|
|
// Only add if the id was actually found!
|
2023-10-25 09:18:49 +02:00
|
|
|
insertSubItem(position, index, /*updateActivationsMap=*/false);
|
2010-10-21 11:54:11 +02:00
|
|
|
++position;
|
2010-07-15 12:24:03 +02:00
|
|
|
} else {
|
2010-10-21 11:54:11 +02:00
|
|
|
restoreSplitterState = false;
|
2010-07-15 12:24:03 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-21 11:54:11 +02:00
|
|
|
if (d->m_subWidgets.isEmpty())
|
2016-09-17 18:31:56 +03:00
|
|
|
// Make sure we have at least the projects widget or outline widget
|
2023-10-25 09:18:49 +02:00
|
|
|
insertSubItem(0,
|
|
|
|
|
qMax(0, factoryIndex(Id::fromString(defaultFirstView(d->m_side)))),
|
|
|
|
|
/*updateActivationsMap=*/false);
|
2010-10-21 11:54:11 +02:00
|
|
|
|
2020-12-10 11:24:27 +01:00
|
|
|
setShown(settings->value(settingsKey("Visible"), defaultVisible(d->m_side)).toBool());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
if (restoreSplitterState && settings->contains(settingsKey("VerticalPosition"))) {
|
|
|
|
|
restoreState(settings->value(settingsKey("VerticalPosition")).toByteArray());
|
2009-03-26 15:54:05 +01:00
|
|
|
} else {
|
|
|
|
|
QList<int> sizes;
|
|
|
|
|
sizes += 256;
|
2010-07-15 12:24:03 +02:00
|
|
|
for (int i = viewIds.size()-1; i > 0; --i)
|
2009-03-26 15:54:05 +01:00
|
|
|
sizes.prepend(512);
|
|
|
|
|
setSizes(sizes);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
d->m_width = settings->value(settingsKey("Width"), 240).toInt();
|
2010-10-25 12:06:14 +02:00
|
|
|
if (d->m_width < 40)
|
|
|
|
|
d->m_width = 40;
|
2010-10-21 11:56:25 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Apply
|
2016-09-17 18:31:56 +03:00
|
|
|
if (NavigationWidgetPlaceHolder::current(d->m_side))
|
Fix left sidebar width after switching modes
After switching to debug mode, hiding left sidebar, switching back to
edit, and showing left sidebar, the sidebar had very small width.
We may not calculate the splitter sizes for each placeholder
individually, because setting them on the splitter might distribute them
in a weird way when widgets are hidden. In the above example switching
back to edit mode while both sidebars are hidden triggered something
similar to the following updates:
Left side bar update:
- calculated: (300, 1000, 0)
- actual resulting: (0, 1000, 0)
Right side bar update:
- calculated: (0, 1000, 300)
- actual resulting: (100, 900, 0)
In the longer run it would probably be better handle the resizing in a
more centralized way, since now it sets the same sizes twice (once for
each side bar update).
Task-number: QTCREATORBUG-18009
Change-Id: Ife5d6f1caded55f444245f4c3c98ae05371363b8
Reviewed-by: Serhii Moroz <frost.asm@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-04-20 16:17:18 +02:00
|
|
|
NavigationWidgetPlaceHolder::current(d->m_side)->applyStoredSize();
|
2016-09-17 18:31:56 +03:00
|
|
|
|
|
|
|
|
// Restore last activation positions
|
|
|
|
|
settings->beginGroup(settingsGroup());
|
|
|
|
|
const QString activationKey = QStringLiteral("ActivationPosition.");
|
|
|
|
|
const auto keys = settings->allKeys();
|
|
|
|
|
for (const QString &key : keys) {
|
|
|
|
|
if (!key.startsWith(activationKey))
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-09-05 09:20:31 +02:00
|
|
|
int position = settings->value(keyFromString(key)).toInt();
|
2016-09-17 18:31:56 +03:00
|
|
|
Id factoryId = Id::fromString(key.mid(activationKey.length()));
|
2024-01-10 23:51:10 +01:00
|
|
|
addActivationInfo(factoryId, {d->m_side, position});
|
2016-09-17 18:31:56 +03:00
|
|
|
}
|
|
|
|
|
settings->endGroup();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:59:04 +02:00
|
|
|
void NavigationWidget::closeSubWidgets()
|
|
|
|
|
{
|
2022-10-07 14:46:06 +02:00
|
|
|
for (Internal::NavigationSubWidget *subWidget : std::as_const(d->m_subWidgets)) {
|
2010-08-11 14:59:04 +02:00
|
|
|
subWidget->saveSettings();
|
|
|
|
|
delete subWidget;
|
|
|
|
|
}
|
2010-09-16 12:26:28 +02:00
|
|
|
d->m_subWidgets.clear();
|
2010-08-11 14:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void NavigationWidget::setShown(bool b)
|
|
|
|
|
{
|
2016-09-17 18:31:56 +03:00
|
|
|
NavigationWidgetPlaceHolder *current = NavigationWidgetPlaceHolder::current(d->m_side);
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
if (!current && d->m_mainWindow) {
|
|
|
|
|
// mode without placeholder but with main window
|
|
|
|
|
d->m_mainWindow->setDockAreaVisible(dockAreaForSide(d->m_side), b);
|
2009-01-06 17:03:08 +01:00
|
|
|
} else {
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
// mode with navigation widget placeholder or e.g. during startup/settings restore
|
|
|
|
|
if (d->m_shown == b)
|
|
|
|
|
return;
|
|
|
|
|
const bool haveData = d->m_factoryModel->rowCount();
|
|
|
|
|
d->m_shown = b;
|
|
|
|
|
if (current) {
|
|
|
|
|
const bool visible = d->m_shown && haveData;
|
|
|
|
|
current->setVisible(visible);
|
|
|
|
|
}
|
2009-01-06 17:03:08 +01:00
|
|
|
}
|
Use sidebar buttons for hiding/showing dock areas
So far, if a mode includes navigation widget placeholders, these are
used for the sidebar toggle buttons, otherwise the buttons are disabled.
Now, if a mode does not include navigation widget placeholders, but the
mode has a FancyMainWindow attached, use the buttons to hide or show the
corresponding dock widget area (left or right).
Since QMainWindow does not really support "hiding a dock widget area",
the FancyMainWindow needs to track that state manually, by tracking the
dock widgets that were visible before "hiding the dock widget area".
Also, if a dock widget is dragged into a "hidden" area, or a widget is
made visible or "unfloated" into that area, show the other widgets in the
area again as well, "unhiding" the area.
Since the mode widgets that have a mainwindow somewhere usually wrap
that into a splitter for the output panes, and the Design mode is
actually a stack widget, IMode needs another method that returns the
appropriate FancyMainWindow if available.
The patch implements this for Widget Designer.
Change-Id: I03531f4d5130c846ff5d65831b1c9be210e1c561
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 09:26:31 +01:00
|
|
|
updateToggleAction();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NavigationWidget::isShown() const
|
|
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_shown;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
int NavigationWidget::factoryIndex(Id id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
for (int row = 0; row < d->m_factoryModel->rowCount(); ++row) {
|
2014-11-16 10:52:41 +02:00
|
|
|
if (d->m_factoryModel->data(d->m_factoryModel->index(row, 0), FactoryIdRole).value<Id>() == id)
|
2010-07-15 12:24:03 +02:00
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-23 17:51:05 +02:00
|
|
|
Key NavigationWidget::settingsKey(const Key &key) const
|
2016-09-17 18:31:56 +03:00
|
|
|
{
|
2023-08-23 17:51:05 +02:00
|
|
|
return settingsGroup() + '/' + key;
|
2016-09-17 18:31:56 +03:00
|
|
|
}
|
|
|
|
|
|
2011-11-09 12:07:41 +01:00
|
|
|
QHash<Id, Command *> NavigationWidget::commandMap() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-16 12:26:28 +02:00
|
|
|
return d->m_commandMap;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-16 12:26:28 +02:00
|
|
|
} // namespace Core
|