Introduce main window affinity

By default a dock widget can dock into any main window.
With affinities, we can now have a dock widget "belong" to a main window
and only be able to dock into it (or into other floating dock widgets
with the same affinity).

See DockWidgetBase::setAffinity() and MainWindowBase::setAffinity().
This commit is contained in:
Sergio Martins
2020-02-09 21:02:21 +00:00
parent 59bb0d8e71
commit d6997eaf7f
13 changed files with 234 additions and 10 deletions

View File

@@ -58,6 +58,12 @@ int main(int argc, char **argv)
QCommandLineOption lazyResizeOption("l", QCoreApplication::translate("main", "Use lazy resize"));
parser.addOption(lazyResizeOption);
QCommandLineOption multipleMainWindows("m", QCoreApplication::translate("main", "Shows two multiple main windows"));
parser.addOption(multipleMainWindows);
QCommandLineOption incompatibleMainWindows("i", QCoreApplication::translate("main", "Only usable with -m. Make the two main windows incompatible with each other. (Illustrates (MainWindowBase::setAffinityName))"));
parser.addOption(incompatibleMainWindows);
#if defined(DOCKS_DEVELOPER_MODE)
QCommandLineOption noCentralFrame("c", QCoreApplication::translate("main", "No central frame"));
parser.addOption(noCentralFrame);
@@ -88,11 +94,33 @@ int main(int argc, char **argv)
if (parser.isSet(lazyResizeOption))
flags |= KDDockWidgets::Config::Flag_LazyResize;
if (parser.isSet(incompatibleMainWindows) && !parser.isSet(multipleMainWindows)) {
qWarning() << "Error: Argument -i requires -m";
return 1;
}
KDDockWidgets::Config::self().setFlags(flags);
MyMainWindow mainWindow(options);
MyMainWindow mainWindow(QStringLiteral("MyMainWindow"), options);
mainWindow.setWindowTitle("Main Window 1");
mainWindow.resize(1200, 1200);
mainWindow.show();
if (parser.isSet(multipleMainWindows)) {
// By default a dock widget can dock into any main window.
// By setting an affinity name we can prevent that. Dock widgets of different affinities are incompatible.
const QString affinity = parser.isSet(incompatibleMainWindows) ? QStringLiteral("affinity1")
: QString();
auto mainWindow2 = new MyMainWindow(QStringLiteral("MyMainWindow-2"), options, affinity);
if (affinity.isEmpty())
mainWindow2->setWindowTitle("Main Window 2");
else
mainWindow2->setWindowTitle("Main Window 2 (different affinity)");
mainWindow2->resize(1200, 1200);
mainWindow2->show();
}
return app.exec();
}