22#include "ViewWrapper_p.h"
23#include "core/DockRegistry_p.h"
26#include "core/MainWindow_p.h"
29#include "core/Window_p.h"
32#include "core/Logging_p.h"
49class MyCentralWidget :
public QWidget
58 ~MyCentralWidget()
override;
62class MainWindow::Private
67 , m_controller(qq->mainWindow())
68 , m_supportsAutoHide(
Config::self().flags() &
Config::Flag_AutoHideSupport)
69 , m_centralWidget(new MyCentralWidget(qq))
82 m_layout->setContentsMargins(m_centerWidgetMargins * factor);
85 void setupCentralLayout()
87 m_layout->setSpacing(0);
90 if (m_supportsAutoHide) {
94 innerVLayout->setSpacing(0);
95 innerVLayout->setContentsMargins(0, 0, 0, 0);
96 innerVLayout->addWidget(
98 innerVLayout->addWidget(View_qt::asQWidget(m_controller->layout()));
99 innerVLayout->addWidget(
101 m_layout->addLayout(innerVLayout);
104 m_layout->addWidget(View_qt::asQWidget(m_controller->layout()->view()));
107 q->QMainWindow::setCentralWidget(m_centralWidget);
110 bool onlySupportsQDockWidgets()
const
115 bool needsManualInit()
const
121 void sanityCheckCentralWidget()
const
123 if (
auto cw = q->centralWidget()) {
125 qWarning() <<
"MainWindow: Expected our own central widget, not " << cw->objectName();
132 const bool m_supportsAutoHide;
133 MyCentralWidget *
const m_centralWidget;
135 QMargins m_centerWidgetMargins = { 1, 5, 1, 1 };
140MyCentralWidget::~MyCentralWidget() =
default;
146 , MainWindowViewInterface(static_cast<Core::
MainWindow *>(controller()))
147 , d(new Private(this))
156 m_mainWindow->init(uniqueName);
159 if (!requiresManualInit)
160 d->setupCentralLayout();
162 const bool isWindow = !parentWidget() || (flags &
Qt::Window);
174 window()->onScreenChanged(
this, [](
QObject *context,
auto window) {
175 if (
auto mw = qobject_cast<MainWindow *>(context))
182 d->sanityCheckCentralWidget();
185 d->groupCountChangedConnection = m_mainWindow->d->groupCountChanged.connect([
this](
int count) {
186 Q_EMIT groupCountChanged(count);
192 d->sanityCheckCentralWidget();
196void MainWindow::setCentralWidget(
QWidget *w)
203 return d->m_centerWidgetMargins;
208 if (d->m_centerWidgetMargins == margins)
210 d->m_centerWidgetMargins = margins;
232 return View_qt::asQWidget(view.get());
247 if (d->onlySupportsQDockWidgets()) {
250 qFatal(
"MainWindow::setCentralWidget_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
256 if (d->onlySupportsQDockWidgets()) {
259 qFatal(
"MainWindow::addDockWidget_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
266 if (d->onlySupportsQDockWidgets()) {
269 qFatal(
"MainWindow::addDockWidget_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
275 if (d->onlySupportsQDockWidgets()) {
278 qFatal(
"MainWindow::restoreDockWidget_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
285 if (d->onlySupportsQDockWidgets()) {
288 qFatal(
"MainWindow::removeDockWidget_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
294 if (d->onlySupportsQDockWidgets()) {
297 qFatal(
"MainWindow::dockWidgetArea_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
305 if (d->onlySupportsQDockWidgets()) {
308 qFatal(
"MainWindow::resizeDocks_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
314 if (d->onlySupportsQDockWidgets()) {
317 qFatal(
"MainWindow::tabifyDockWidget_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
323 if (d->onlySupportsQDockWidgets()) {
326 qFatal(
"MainWindow::tabifiedDockWidgets_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
334 if (d->onlySupportsQDockWidgets()) {
337 qFatal(
"MainWindow::splitDockWidget_split_legacy: Legacy QDockWidgets are not supported without MainWindowOption_QDockWidgets");
343 if (d->needsManualInit()) {
345 d->setupCentralLayout();
347 qFatal(
"MainWindow::manualInit requires MainWindowOption_ManualInit");
Application-wide config to tune certain behaviours of the framework.
A ScopedConnection is a RAII-style way to make sure a Connection is disconnected.
MainWindow *const m_mainWindow
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
std::shared_ptr< View > persistentCentralView() const
void setPersistentCentralView(std::shared_ptr< View > widget)
Sets a persistent central widget. It can't be detached.
The QMainwindow sub-class that the application should use to be able to dock KDDockWidget DockWidget ...
Qt::DockWidgetArea dockWidgetArea_legacy(QDockWidget *dockwidget) const
bool restoreDockWidget_legacy(QDockWidget *dockwidget)
void addDockWidget_legacy(Qt::DockWidgetArea area, QDockWidget *dockwidget)
void tabifyDockWidget_legacy(QDockWidget *first, QDockWidget *second)
void setCentralWidget_legacy(QWidget *)
These *_legacy overloads provide QDockWidget compatibility, during porting. See MainWindowOption_QDoc...
void setPersistentCentralWidget(QWidget *widget)
QHBoxLayout * internalLayout() const
returns the internal layout this is rarely needed unless you want to layout other widgets next to the...
void setContentsMargins(int left, int top, int right, int bottom) override
Sets the main window's content margins.
~MainWindow() override
Destructor.
void resizeDocks_legacy(const QList< QDockWidget * > &docks, const QList< int > &sizes, Qt::Orientation orientation)
QWidget * persistentCentralWidget() const
friend class Core::MainWindow
void removeDockWidget_legacy(QDockWidget *dockwidget)
void setCenterWidgetMargins(QMargins)
sets the margins for the contents widget
QMargins centerWidgetMargins() const override
returns the margins for the contents widget
void updateMargins()
for internal use only
void splitDockWidget_split_legacy(QDockWidget *after, QDockWidget *dockwidget, Qt::Orientation orientation)
QRect centralAreaGeometry() const override
QList< QDockWidget * > tabifiedDockWidgets_legacy(QDockWidget *dockwidget) const
A MultiSplitter with support for drop indicators when hovering over.
The MainWindow base-class that's shared between QtWidgets and QtQuick stack.
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget)
QWidget * centralWidget() const const
void setDockOptions(QMainWindow::DockOptions options)
Qt::DockWidgetArea dockWidgetArea(QDockWidget *dockwidget) const const
void removeDockWidget(QDockWidget *dockwidget)
void resizeDocks(const QList< QDockWidget * > &docks, const QList< int > &sizes, Qt::Orientation orientation)
bool restoreDockWidget(QDockWidget *dockwidget)
void setCentralWidget(QWidget *widget)
void splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation)
QList< QDockWidget * > tabifiedDockWidgets(QDockWidget *dockwidget) const const
void tabifyDockWidget(QDockWidget *first, QDockWidget *second)
void setObjectName(const QString &name)
QObject * parent() const const
QMainWindow sub-class to enable KDDockWidgets support.
void setContentsMargins(int left, int top, int right, int bottom)