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
|
2010-02-16 16:11:51 +01:00
|
|
|
|
|
|
|
|
#include "imode.h"
|
|
|
|
|
|
2018-01-19 15:51:23 +01:00
|
|
|
#include "modemanager.h"
|
|
|
|
|
|
2024-07-01 15:48:35 +02:00
|
|
|
#include <utils/aspects.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 <utils/fancymainwindow.h>
|
|
|
|
|
|
|
|
|
|
#include <aggregation/aggregate.h>
|
|
|
|
|
|
2024-07-01 15:48:35 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2020-06-04 12:44:25 +02:00
|
|
|
namespace Core {
|
|
|
|
|
|
2023-11-28 15:49:43 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class IModePrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QString m_displayName;
|
|
|
|
|
QIcon m_icon;
|
|
|
|
|
QMenu *m_menu = nullptr;
|
2023-11-28 16:10:37 +01:00
|
|
|
Utils::FancyMainWindow *m_mainWindow = nullptr;
|
2023-11-28 15:49:43 +01:00
|
|
|
int m_priority = -1;
|
|
|
|
|
Utils::Id m_id;
|
2024-07-03 11:02:46 +02:00
|
|
|
Context m_context;
|
|
|
|
|
QPointer<QWidget> m_widget;
|
2023-11-28 15:49:43 +01:00
|
|
|
bool m_isEnabled = true;
|
2024-07-01 15:48:35 +02:00
|
|
|
BoolAspect m_isVisible;
|
2023-11-28 15:49:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2020-06-04 12:44:25 +02:00
|
|
|
/*!
|
|
|
|
|
\class Core::IMode
|
2020-06-12 16:04:30 +02:00
|
|
|
\inheaderfile coreplugin/imode.h
|
2020-06-04 12:44:25 +02:00
|
|
|
\ingroup mainclasses
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
\brief The IMode class represents a mode in \QC.
|
|
|
|
|
|
|
|
|
|
This class defines a mode and its representation as a tool button in the
|
|
|
|
|
mode selector on the left side of \QC's main window.
|
|
|
|
|
|
|
|
|
|
Modes are used to show a different UI for different development tasks.
|
|
|
|
|
Therefore modes control the layout of most of Qt Creator's main window,
|
|
|
|
|
except for the tool bar on the left side and the status bar. For example
|
|
|
|
|
Edit mode, the most commonly used mode for coding, shows the code editor
|
|
|
|
|
and various navigation and output panes. Debug mode enhances that view with
|
|
|
|
|
a configurable layout of debugging related information. Design mode
|
|
|
|
|
reserves all the main window's space for the graphical editor.
|
|
|
|
|
|
|
|
|
|
A mode is an IContext. Set the context's \l{IContext::widget()}{widget}
|
|
|
|
|
to define the mode's layout.
|
|
|
|
|
|
|
|
|
|
Adding a mode should be done sparingly, only as a last reserve. Consider if
|
|
|
|
|
your feature can instead be implemented as a INavigationWidgetFactory,
|
|
|
|
|
IOutputPane, \c{Debugger::Utils::Perspective}, separate dialog, or
|
|
|
|
|
specialized IEditor first.
|
|
|
|
|
|
|
|
|
|
If you add a mode, consider adding a NavigationWidgetPlaceHolder
|
|
|
|
|
on the left side and a OutputPanePlaceHolder on the bottom of your
|
|
|
|
|
mode's layout.
|
|
|
|
|
|
|
|
|
|
Modes automatically register themselves with \QC when they are created and
|
|
|
|
|
unregister themselves when they are destructed.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\property IMode::enabled
|
|
|
|
|
|
|
|
|
|
This property holds whether the mode is enabled.
|
|
|
|
|
|
|
|
|
|
By default, this property is \c true.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\property IMode::displayName
|
|
|
|
|
|
|
|
|
|
This property holds the display name of the mode.
|
|
|
|
|
|
|
|
|
|
The display name is shown under the mode icon in the mode selector.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\property IMode::icon
|
|
|
|
|
|
|
|
|
|
This property holds the icon of the mode.
|
|
|
|
|
|
|
|
|
|
The icon is shown for the mode in the mode selector. Mode icons should
|
|
|
|
|
support the sizes 34x34 pixels and 68x68 pixels for HiDPI.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\property IMode::priority
|
|
|
|
|
|
|
|
|
|
This property holds the priority of the mode.
|
|
|
|
|
|
|
|
|
|
The priority defines the order in which the modes are shown in the mode
|
|
|
|
|
selector. Higher priority moves to mode towards the top. Welcome mode,
|
|
|
|
|
which should stay at the top, has the priority 100. The default priority is
|
|
|
|
|
-1.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\property IMode::id
|
|
|
|
|
|
|
|
|
|
This property holds the ID of the mode.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\property IMode::menu
|
|
|
|
|
|
|
|
|
|
This property holds the mode's menu.
|
|
|
|
|
|
|
|
|
|
By default, a mode does not have a menu. When you set a menu, it is not
|
|
|
|
|
owned by the mode unless you set the parent explicitly.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Creates an IMode with an optional \a parent.
|
|
|
|
|
|
|
|
|
|
Registers the mode in \QC.
|
|
|
|
|
*/
|
2023-11-28 15:49:43 +01:00
|
|
|
IMode::IMode(QObject *parent)
|
2024-07-03 11:02:46 +02:00
|
|
|
: QObject(parent)
|
2023-11-28 15:49:43 +01:00
|
|
|
, m_d(new Internal::IModePrivate)
|
2010-02-16 16:11:51 +01:00
|
|
|
{
|
2024-07-01 15:48:35 +02:00
|
|
|
m_d->m_isVisible.setDefaultValue(true);
|
|
|
|
|
connect(&m_d->m_isVisible, &BoolAspect::changed, this, [this] {
|
|
|
|
|
emit visibleChanged(m_d->m_isVisible.value());
|
|
|
|
|
m_d->m_isVisible.writeSettings();
|
|
|
|
|
});
|
2020-11-27 13:12:23 +01:00
|
|
|
ModeManager::addMode(this);
|
2010-02-16 16:11:51 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-28 15:49:43 +01:00
|
|
|
IMode::~IMode() = default;
|
|
|
|
|
|
|
|
|
|
QString IMode::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QIcon IMode::icon() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_icon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int IMode::priority() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_priority;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::Id IMode::id() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_id;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-16 16:11:51 +01:00
|
|
|
void IMode::setEnabled(bool enabled)
|
|
|
|
|
{
|
2023-11-28 15:49:43 +01:00
|
|
|
if (m_d->m_isEnabled == enabled)
|
2010-02-16 16:11:51 +01:00
|
|
|
return;
|
2023-11-28 15:49:43 +01:00
|
|
|
m_d->m_isEnabled = enabled;
|
|
|
|
|
emit enabledStateChanged(m_d->m_isEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 15:48:35 +02:00
|
|
|
void IMode::setVisible(bool visible)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_isVisible.setValue(visible);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-28 15:49:43 +01:00
|
|
|
void IMode::setDisplayName(const QString &displayName)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_displayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMode::setIcon(const QIcon &icon)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_icon = icon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMode::setPriority(int priority)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_priority = priority;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMode::setId(Utils::Id id)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_id = id;
|
2024-07-01 15:48:35 +02:00
|
|
|
m_d->m_isVisible
|
|
|
|
|
.setSettingsKey("MainWindow", id.withPrefix("Mode.").withSuffix(".Visible").toKey());
|
|
|
|
|
m_d->m_isVisible.readSettings();
|
2023-11-28 15:49:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMode::setMenu(QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_menu = menu;
|
2010-02-16 16:11:51 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-03 11:02:46 +02:00
|
|
|
void IMode::setContext(const Context &context)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMode::setWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_widget = widget;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
Utils::FancyMainWindow *IMode::mainWindow()
|
|
|
|
|
{
|
2023-11-28 16:10:37 +01:00
|
|
|
if (m_d->m_mainWindow)
|
|
|
|
|
return m_d->m_mainWindow;
|
|
|
|
|
return qobject_cast<Utils::FancyMainWindow *>(widget());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IMode::setMainWindow(Utils::FancyMainWindow *mw)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_mainWindow = mw;
|
2023-11-28 16:30:17 +01:00
|
|
|
emit ModeManager::instance()->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
|
|
|
}
|
|
|
|
|
|
2010-02-16 16:11:51 +01:00
|
|
|
bool IMode::isEnabled() const
|
|
|
|
|
{
|
2023-11-28 15:49:43 +01:00
|
|
|
return m_d->m_isEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 15:48:35 +02:00
|
|
|
bool IMode::isVisible() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_isVisible.value();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-28 15:49:43 +01:00
|
|
|
QMenu *IMode::menu() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_menu;
|
2010-02-16 16:11:51 +01:00
|
|
|
}
|
2020-06-04 12:44:25 +02:00
|
|
|
|
2024-07-03 11:02:46 +02:00
|
|
|
Context IMode::context() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *IMode::widget() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 12:44:25 +02:00
|
|
|
} // namespace Core
|