src/main.cpp

changeset 236
1fa0e1de9f0a
parent 235
7ef03c2b46ab
child 237
10a6298f636f
equal deleted inserted replaced
235:7ef03c2b46ab 236:1fa0e1de9f0a
13 #include "document.h" 13 #include "document.h"
14 #include "settingseditor/settingseditor.h" 14 #include "settingseditor/settingseditor.h"
15 #include "widgets/colorselectdialog.h" 15 #include "widgets/colorselectdialog.h"
16 #include "settings.h" 16 #include "settings.h"
17 #include "ui/circletooloptionswidget.h" 17 #include "ui/circletooloptionswidget.h"
18 #include "messagelog.h"
18 19
19 static const QDir LOCALE_DIR {":/locale"}; 20 static const QDir LOCALE_DIR {":/locale"};
20 21
21 class ModelSubWindow : public QMdiSubWindow 22 class ModelSubWindow : public QMdiSubWindow
22 { 23 {
340 result.push_back(index.row()); 341 result.push_back(index.row());
341 } 342 }
342 return result; 343 return result;
343 } 344 }
344 345
346 #include <QScrollBar>
345 int main(int argc, char *argv[]) 347 int main(int argc, char *argv[])
346 { 348 {
347 doQtRegistrations(); 349 doQtRegistrations();
348 QApplication app{argc, argv}; 350 QApplication app{argc, argv};
349 QMainWindow mainWindow; 351 QMainWindow mainWindow;
353 QTranslator translator{&mainWindow}; 355 QTranslator translator{&mainWindow};
354 LibrariesModel libraries{&mainWindow}; 356 LibrariesModel libraries{&mainWindow};
355 QStringList recentlyOpenedFiles; 357 QStringList recentlyOpenedFiles;
356 ColorTable colorTable; 358 ColorTable colorTable;
357 gl::RenderPreferences renderPreferences; 359 gl::RenderPreferences renderPreferences;
360 MessageLog messageLog;
358 ui.setupUi(&mainWindow); 361 ui.setupUi(&mainWindow);
359 const uiutilities::KeySequenceMap defaultKeyboardShortcuts = 362 const uiutilities::KeySequenceMap defaultKeyboardShortcuts =
360 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow)); 363 uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow));
361 const auto saveSettings = [&]{ 364 const auto saveSettings = [&]{
362 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry()); 365 setSetting<Setting::MainWindowGeometry>(mainWindow.saveGeometry());
410 { 413 {
411 recentlyOpenedFiles.removeLast(); 414 recentlyOpenedFiles.removeLast();
412 } 415 }
413 saveSettings(); 416 saveSettings();
414 updateRecentlyOpenedDocumentsMenu(); 417 updateRecentlyOpenedDocumentsMenu();
415 };
416 const auto logMessage = [&ui](const Message& message){
417 QString messagetext = message.time.toString(QObject::tr("[hh:mm:ss]"));
418 switch(message.type) {
419 case Message::Info:
420 messagetext += QObject::tr(" [INFO] ");
421 break;
422 case Message::Warning:
423 messagetext += QObject::tr(" [WARN] ");
424 break;
425 case Message::Error:
426 messagetext += QObject::tr(" [ERR!] ");
427 break;
428 }
429 messagetext += message.text;
430 ui.messageLog->append(messagetext);
431 }; 418 };
432 const auto openModelForEditing = [&](const ModelId modelId){ 419 const auto openModelForEditing = [&](const ModelId modelId){
433 Model* model = documents.getModelById(modelId); 420 Model* model = documents.getModelById(modelId);
434 if (model != nullptr) { 421 if (model != nullptr) {
435 ModelData* data = new ModelData(&documents); 422 ModelData* data = new ModelData(&documents);
639 ui.modelListView->setSelectionModel(data->itemSelectionModel.get()); 626 ui.modelListView->setSelectionModel(data->itemSelectionModel.get());
640 } 627 }
641 } 628 }
642 } 629 }
643 }); 630 });
631 ui.messageLog->setModel(&messageLog);
644 QObject::connect(ui.actionAboutQt, &QAction::triggered, &app, &QApplication::aboutQt); 632 QObject::connect(ui.actionAboutQt, &QAction::triggered, &app, &QApplication::aboutQt);
645 QObject::connect(&documents, &DocumentManager::message, logMessage); 633 QObject::connect(&documents, &DocumentManager::message, &messageLog, &MessageLog::addMessage);
634 QObject::connect(&messageLog, &MessageLog::rowsAboutToBeInserted, [&]{
635 const auto bar = ui.messageLog->verticalScrollBar();
636 ui.messageLog->setProperty("shouldAutoScroll", bar->value() == bar->maximum());
637 });
638 QObject::connect(&messageLog, &MessageLog::rowsInserted, [&]{
639 if (ui.messageLog->property("shouldAutoScroll").toBool()) {
640 ui.messageLog->scrollToBottom();
641 }
642 });
646 mainWindow.setWindowTitle(title()); 643 mainWindow.setWindowTitle(title());
647 mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>()); 644 mainWindow.restoreGeometry(setting<Setting::MainWindowGeometry>());
648 restoreSettings(); 645 restoreSettings();
649 updateRenderPreferences(&ui, &renderPreferences, &documents); 646 updateRenderPreferences(&ui, &renderPreferences, &documents);
650 mainWindow.show(); 647 mainWindow.show();

mercurial