2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-07-16 15:00:29 +02:00
|
|
|
#include <coreplugin/minisplitter.h>
|
2020-06-26 13:59:38 +02:00
|
|
|
|
|
|
|
|
#include <utils/id.h>
|
2009-07-16 15:00:29 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHash>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QSettings;
|
2010-09-16 12:26:28 +02:00
|
|
|
class QAbstractItemModel;
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2020-12-10 11:24:27 +01:00
|
|
|
namespace Utils {
|
|
|
|
|
class QtcSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
namespace Core {
|
2008-12-02 12:01:29 +01:00
|
|
|
class INavigationWidgetFactory;
|
2009-01-14 13:17:53 +01:00
|
|
|
class Command;
|
2008-12-02 12:01:29 +01:00
|
|
|
class NavigationWidget;
|
2010-09-16 12:26:28 +02:00
|
|
|
struct NavigationWidgetPrivate;
|
2014-02-11 21:55:42 +02:00
|
|
|
namespace Internal { class NavigationSubWidget; }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
enum class Side {
|
|
|
|
|
Left,
|
|
|
|
|
Right
|
|
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
class CORE_EXPORT NavigationWidgetPlaceHolder : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2011-09-16 15:00:41 +02:00
|
|
|
friend class Core::NavigationWidget;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2020-06-26 13:59:38 +02:00
|
|
|
explicit NavigationWidgetPlaceHolder(Utils::Id mode, Side side, QWidget *parent = nullptr);
|
2018-05-07 15:00:03 +02:00
|
|
|
~NavigationWidgetPlaceHolder() override;
|
2016-09-17 18:31:56 +03:00
|
|
|
static NavigationWidgetPlaceHolder *current(Side side);
|
|
|
|
|
static void setCurrent(Side side, NavigationWidgetPlaceHolder *navWidget);
|
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 applyStoredSize();
|
2010-09-16 12:26:28 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
2020-06-26 13:59:38 +02:00
|
|
|
void currentModeAboutToChange(Utils::Id mode);
|
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 storedWidth() const;
|
2014-11-16 10:52:41 +02:00
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id m_mode;
|
2016-09-17 18:31:56 +03:00
|
|
|
Side m_side;
|
|
|
|
|
static NavigationWidgetPlaceHolder *s_currentLeft;
|
|
|
|
|
static NavigationWidgetPlaceHolder *s_currentRight;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2010-08-13 10:10:43 +02:00
|
|
|
class CORE_EXPORT NavigationWidget : public MiniSplitter
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2011-09-16 15:00:41 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2010-07-15 12:24:03 +02:00
|
|
|
enum FactoryModelRoles {
|
|
|
|
|
FactoryObjectRole = Qt::UserRole,
|
2010-09-09 14:35:26 +02:00
|
|
|
FactoryIdRole,
|
2021-09-21 16:21:33 +02:00
|
|
|
FactoryActionIdRole,
|
2010-09-09 14:35:26 +02:00
|
|
|
FactoryPriorityRole
|
2010-07-15 12:24:03 +02:00
|
|
|
};
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
explicit NavigationWidget(QAction *toggleSideBarAction, Side side);
|
2018-05-07 15:00:03 +02:00
|
|
|
~NavigationWidget() override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-11-13 13:34:47 +01:00
|
|
|
void setFactories(const QList<INavigationWidgetFactory*> &factories);
|
2010-07-15 12:24:03 +02:00
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
QString settingsGroup() const;
|
2020-12-10 11:24:27 +01:00
|
|
|
void saveSettings(Utils::QtcSettings *settings);
|
2008-12-11 14:35:14 +01:00
|
|
|
void restoreSettings(QSettings *settings);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QWidget *activateSubWidget(Utils::Id factoryId, int preferredPosition);
|
2010-08-11 14:59:04 +02:00
|
|
|
void closeSubWidgets();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool isShown() const;
|
|
|
|
|
void setShown(bool b);
|
|
|
|
|
|
2016-09-17 18:31:56 +03:00
|
|
|
static NavigationWidget *instance(Side side);
|
2020-06-26 13:59:38 +02:00
|
|
|
static QWidget *activateSubWidget(Utils::Id factoryId, Side fallbackSide);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int storedWidth();
|
|
|
|
|
|
|
|
|
|
// Called from the place holders
|
|
|
|
|
void placeHolderChanged(NavigationWidgetPlaceHolder *holder);
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QHash<Utils::Id, Command *> commandMap() const;
|
2010-07-15 12:24:03 +02:00
|
|
|
QAbstractItemModel *factoryModel() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
protected:
|
2018-05-07 15:00:03 +02:00
|
|
|
void resizeEvent(QResizeEvent *) override;
|
2010-07-15 12:24:03 +02:00
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
private:
|
2022-07-20 12:05:49 +02:00
|
|
|
void closeSubWidget(Internal::NavigationSubWidget *subWidget);
|
2009-12-08 18:29:44 +01:00
|
|
|
void updateToggleText();
|
2016-09-17 18:31:56 +03:00
|
|
|
Internal::NavigationSubWidget *insertSubItem(int position, int factoryIndex);
|
2020-06-26 13:59:38 +02:00
|
|
|
int factoryIndex(Utils::Id id);
|
2016-09-17 18:31:56 +03:00
|
|
|
QString settingsKey(const QString &key) const;
|
2010-07-15 12:24:03 +02:00
|
|
|
|
2011-09-16 15:00:41 +02:00
|
|
|
NavigationWidgetPrivate *d;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Core
|