src/main.cpp

changeset 289
a0ddbc9a4e77
parent 286
04478da357d0
child 292
f071ec94c022
equal deleted inserted replaced
288:169b30f282bd 289:a0ddbc9a4e77
26 class ModelSubWindow : public QMdiSubWindow 26 class ModelSubWindow : public QMdiSubWindow
27 { 27 {
28 Q_OBJECT 28 Q_OBJECT
29 public: 29 public:
30 const ModelId modelId; 30 const ModelId modelId;
31 ModelSubWindow(ModelId modelId, QWidget* widget) : 31 explicit ModelSubWindow(ModelId modelId, QWidget* widget = nullptr) :
32 QMdiSubWindow{widget}, 32 QMdiSubWindow{widget},
33 modelId{modelId} 33 modelId{modelId}
34 { 34 {
35 } 35 }
36 protected: 36 protected:
396 .replace("%COMPILER_SYSTEM%", CMAKE_SYSTEM) 396 .replace("%COMPILER_SYSTEM%", CMAKE_SYSTEM)
397 ); 397 );
398 } 398 }
399 dialog.setWindowTitle(QObject::tr("About %1").arg(CMAKE_PROJECT_NAME)); 399 dialog.setWindowTitle(QObject::tr("About %1").arg(CMAKE_PROJECT_NAME));
400 dialog.exec(); 400 dialog.exec();
401 }
402
403 template<class SubWindow, class... Args>
404 SubWindow* createSubWindow(QMdiArea* mdiArea, Args&&... args)
405 {
406 // Qt seems to have a bug where the first created sub window does not render
407 // properly until it is minimized and maximized again. This only happens
408 // if we give the mdi area as a parent argument. As a work-around, we create
409 // the sub window with parent=nullptr, and add it manually.
410 // c.f. https://bugreports.qt.io/browse/QTBUG-69495
411 SubWindow* subWindow = new SubWindow{args..., nullptr};
412 mdiArea->addSubWindow(subWindow);
413 return subWindow;
401 } 414 }
402 415
403 int main(int argc, char *argv[]) 416 int main(int argc, char *argv[])
404 { 417 {
405 doQtRegistrations(); 418 doQtRegistrations();
566 data->gridLayer->settingsChanged(); 579 data->gridLayer->settingsChanged();
567 } 580 }
568 }); 581 });
569 QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage); 582 QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage);
570 const QFileInfo fileInfo{*documents.modelPath(modelId)}; 583 const QFileInfo fileInfo{*documents.modelPath(modelId)};
571 ModelSubWindow* subWindow = new ModelSubWindow{modelId, ui.mdiArea}; 584 auto* const subWindow = createSubWindow<ModelSubWindow>(ui.mdiArea, modelId);
572 subWindow->setMinimumSize({96, 96}); 585 subWindow->setMinimumSize({96, 96});
586 subWindow->resize({320, 200});
573 subWindow->setWidget(data->canvas.get()); 587 subWindow->setWidget(data->canvas.get());
574 subWindow->setWindowTitle(tabName(fileInfo)); 588 subWindow->setWindowTitle(tabName(fileInfo));
575 subWindow->show(); 589 subWindow->show();
576 } 590 }
577 }; 591 };
589 } 603 }
590 } 604 }
591 }); 605 });
592 QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{ 606 QObject::connect(ui.actionSettingsEditor, &QAction::triggered, [&]{
593 if (ui.mdiArea->findChildren<SettingsEditor*>().isEmpty()) { 607 if (ui.mdiArea->findChildren<SettingsEditor*>().isEmpty()) {
594 SettingsEditor* settingsEditor = new SettingsEditor{defaultKeyboardShortcuts, ui.mdiArea}; 608 auto* const settingsEditor = createSubWindow<SettingsEditor>(ui.mdiArea, defaultKeyboardShortcuts);
595 QObject::connect(&settingsChanged, &Signal::triggered, settingsEditor, &SettingsEditor::loadSettings); 609 QObject::connect(&settingsChanged, &Signal::triggered, settingsEditor, &SettingsEditor::loadSettings);
596 QObject::connect(settingsEditor, &SettingsEditor::settingsChanged, restoreSettings); 610 QObject::connect(settingsEditor, &SettingsEditor::settingsChanged, restoreSettings);
597 settingsEditor->setAttribute(Qt::WA_DeleteOnClose); 611 settingsEditor->setAttribute(Qt::WA_DeleteOnClose);
598 settingsEditor->show(); 612 settingsEditor->show();
599 } 613 }

mercurial