src/main.cpp

changeset 355
e81f4ad53efd
parent 354
91053052bb28
child 356
65b4741b302d
equal deleted inserted replaced
354:91053052bb28 355:e81f4ad53efd
5 #include <QMdiSubWindow> 5 #include <QMdiSubWindow>
6 #include <QMessageBox> 6 #include <QMessageBox>
7 #include <QScrollBar> 7 #include <QScrollBar>
8 #include <QStackedWidget> 8 #include <QStackedWidget>
9 #include <QTranslator> 9 #include <QTranslator>
10 #include <ui_about.h>
11 #include "src/gl/partrenderer.h" 10 #include "src/gl/partrenderer.h"
12 #include "src/layers/axeslayer.h" 11 #include "src/layers/axeslayer.h"
13 #include "src/layers/edittools.h" 12 #include "src/layers/edittools.h"
14 #include "src/layers/gridlayer.h" 13 #include "src/layers/gridlayer.h"
15 #include "src/ldrawalgorithm.h" 14 #include "src/ldrawalgorithm.h"
16 #include "src/mainwindow.h" 15 #include "src/mainwindow.h"
17 #include "src/messagelog.h" 16 #include "src/messagelog.h"
17 #include "src/modelsubwindow.h"
18 #include "src/settings.h" 18 #include "src/settings.h"
19 #include "src/settingseditor/settingseditor.h" 19 #include "src/settingseditor/settingseditor.h"
20 #include "src/ui/circletooloptionswidget.h" 20 #include "src/ui/circletooloptionswidget.h"
21 #include "src/version.h" 21 #include "src/version.h"
22 #include "src/widgets/colorselectdialog.h" 22 #include "src/widgets/colorselectdialog.h"
23 #include "src/parser.h" 23 #include "src/parser.h"
24 #include "src/ldrawsyntaxhighlighter.h" 24 #include "src/ldrawsyntaxhighlighter.h"
25 #include <GL/glew.h> 25 #include <GL/glew.h>
26 26
27 static const QDir LOCALE_DIR {":/locale"}; 27 static const QDir LOCALE_DIR {":/locale"};
28
29 class ModelSubWindow : public QMdiSubWindow
30 {
31 Q_OBJECT
32 public:
33 const ModelId modelId;
34 explicit ModelSubWindow(ModelId modelId, QWidget* widget = nullptr) :
35 QMdiSubWindow{widget},
36 modelId{modelId}
37 {
38 }
39 protected:
40 void closeEvent(QCloseEvent* event) override
41 {
42 event->ignore();
43 }
44 };
45 28
46 class ModelData : public QObject 29 class ModelData : public QObject
47 { 30 {
48 Q_OBJECT 31 Q_OBJECT
49 public: 32 public:
297 ui->toolWidgetStack->addWidget(widget); 280 ui->toolWidgetStack->addWidget(widget);
298 QObject::connect(action, &QAction::triggered, [ui, i]{ 281 QObject::connect(action, &QAction::triggered, [ui, i]{
299 ui->toolWidgetStack->setCurrentIndex(i); 282 ui->toolWidgetStack->setCurrentIndex(i);
300 }); 283 });
301 } 284 }
302 }
303
304 static void about(QWidget* parent)
305 {
306 QDialog dialog{parent};
307 Ui_About ui;
308 ui.setupUi(&dialog);
309 const char* glVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION));
310 const QString extensions = []{
311 GLint numExtensions;
312 glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
313 QStringList extensionsList;
314 for (GLint i = 0; i < numExtensions; i++) {
315 const GLubyte* ext = glGetStringi(GL_EXTENSIONS, i);
316 extensionsList.push_back(reinterpret_cast<const char*>(ext));
317 }
318 return extensionsList.join(" ");
319 }();
320 for (QTextBrowser* browser : dialog.findChildren<QTextBrowser*>()) {
321 browser->setHtml(
322 browser->toHtml()
323 .replace("%APPNAME%", CMAKE_PROJECT_NAME)
324 .replace("%COPYRIGHT%", COPYRIGHT)
325 .replace("%QTVERSION%", qVersion())
326 .replace("%VERSION%", detailedVersionString(QLocale::LongFormat))
327 .replace("%REVDATE%", revisionDateString(QLocale::LongFormat))
328 .replace("%BUILDTYPE%", CMAKE_BUILD_TYPE)
329 .replace("%COMPILER_ID%", CMAKE_CXX_COMPILER_ID)
330 .replace("%COMPILER_VERSION%", CMAKE_CXX_COMPILER_VERSION)
331 .replace("%COMPILER_FLAGS%", CMAKE_CXX_FLAGS)
332 .replace("%COMPILER_CPU%", CMAKE_SYSTEM_PROCESSOR)
333 .replace("%COMPILER_SYSTEM%", CMAKE_SYSTEM)
334 .replace("%GLMVERSIONSTRING%", GLM_VERSION_MESSAGE)
335 .replace("%GL_VERSION%", glVersion)
336 .replace("%GL_EXTENSIONS%", extensions)
337 );
338 }
339 dialog.setWindowTitle(QObject::tr("About %1").arg(CMAKE_PROJECT_NAME));
340 dialog.exec();
341 } 285 }
342 286
343 template<class SubWindow, class... Args> 287 template<class SubWindow, class... Args>
344 SubWindow* createSubWindow(QMdiArea* mdiArea, Args&&... args) 288 SubWindow* createSubWindow(QMdiArea* mdiArea, Args&&... args)
345 { 289 {
732 } 676 }
733 mainWindow.modelEdit->setEnabled(modelSubWindow != nullptr); 677 mainWindow.modelEdit->setEnabled(modelSubWindow != nullptr);
734 updateTitle(); 678 updateTitle();
735 }); 679 });
736 mainWindow.messageLog->setModel(&messageLog); 680 mainWindow.messageLog->setModel(&messageLog);
737 QObject::connect(mainWindow.actionAboutQt, &QAction::triggered, &app, &QApplication::aboutQt);
738 QObject::connect(&documents, &DocumentManager::message, &messageLog, &MessageLog::addMessage); 681 QObject::connect(&documents, &DocumentManager::message, &messageLog, &MessageLog::addMessage);
739 QObject::connect(&messageLog, &MessageLog::rowsAboutToBeInserted, [&mainWindow]{ 682 QObject::connect(&messageLog, &MessageLog::rowsAboutToBeInserted, [&mainWindow]{
740 const auto bar = mainWindow.messageLog->verticalScrollBar(); 683 const auto bar = mainWindow.messageLog->verticalScrollBar();
741 mainWindow.messageLog->setProperty("shouldAutoScroll", bar->value() == bar->maximum()); 684 mainWindow.messageLog->setProperty("shouldAutoScroll", bar->value() == bar->maximum());
742 }); 685 });
763 for (const ModelAction& action : ldraw::makeUnofficial(model)) { 706 for (const ModelAction& action : ldraw::makeUnofficial(model)) {
764 executeAction(model, action); 707 executeAction(model, action);
765 } 708 }
766 } 709 }
767 }); 710 });
768 QObject::connect( 711 QObject::connect(mainWindow.actionAboutQt, &QAction::triggered, &app, &QApplication::aboutQt);
769 mainWindow.actionAbout,
770 &QAction::triggered,
771 [&mainWindow]{
772 // Make sure that there's an OpenGL context active, otherwise
773 // we cannot obtain OpenGL information
774 if (mainWindow.mdiArea->findChildren<ModelSubWindow*>().empty()) {
775 mainWindow.actionNew->trigger();
776 }
777 about(&mainWindow);
778 }
779 );
780 QObject::connect( 712 QObject::connect(
781 mainWindow.modelEdit, 713 mainWindow.modelEdit,
782 &QPlainTextEdit::textChanged, 714 &QPlainTextEdit::textChanged,
783 [&documents, &libraries, &mainWindow]{ 715 [&documents, &libraries, &mainWindow]{
784 if (ModelData* data = currentModelData(&mainWindow, &documents)) { 716 if (ModelData* data = currentModelData(&mainWindow, &documents)) {

mercurial