--- a/src/mainwindow.cpp Thu Jan 04 19:40:52 2018 +0200 +++ b/src/mainwindow.cpp Thu Jan 04 19:44:26 2018 +0200 @@ -57,56 +57,56 @@ #include "documentmanager.h" #include "ldobjectiterator.h" -ConfigOption (bool ColorizeObjectsList = true) -ConfigOption (QString QuickColorToolbar = "4:25:14:27:2:3:11:1:22:|:0:72:71:15") -ConfigOption (bool ListImplicitFiles = false) -ConfigOption (QStringList HiddenToolbars) +ConfigOption(bool ColorizeObjectsList = true) +ConfigOption(QString QuickColorToolbar = "4:25:14:27:2:3:11:1:22:|:0:72:71:15") +ConfigOption(bool ListImplicitFiles = false) +ConfigOption(QStringList HiddenToolbars) // --------------------------------------------------------------------------------------------------------------------- // -MainWindow::MainWindow (QWidget* parent, Qt::WindowFlags flags) : - QMainWindow (parent, flags), - m_guiUtilities (new GuiUtilities (this)), - ui (*new Ui_MainWindow), - m_externalPrograms (nullptr), - m_settings (makeSettings (this)), - m_documents (new DocumentManager (this)), - m_currentDocument (nullptr), - m_isSelectionLocked (false) +MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) : + QMainWindow(parent, flags), + m_guiUtilities(new GuiUtilities(this)), + ui(*new Ui_MainWindow), + m_externalPrograms(nullptr), + m_settings(makeSettings(this)), + m_documents(new DocumentManager(this)), + m_currentDocument(nullptr), + m_isSelectionLocked(false) { g_win = this; - ui.setupUi (this); + ui.setupUi(this); m_updatingTabs = false; - m_renderer = new GLRenderer (this); + m_renderer = new GLRenderer(this); m_tabs = new QTabBar; - m_tabs->setTabsClosable (true); - ui.verticalLayout->insertWidget (0, m_tabs); + m_tabs->setTabsClosable(true); + ui.verticalLayout->insertWidget(0, m_tabs); createBlankDocument(); - m_renderer->setDocument (m_currentDocument); + m_renderer->setDocument(m_currentDocument); // Stuff the renderer into its frame - QVBoxLayout* rendererLayout = new QVBoxLayout (ui.rendererFrame); - rendererLayout->addWidget (renderer()); + QVBoxLayout* rendererLayout = new QVBoxLayout(ui.rendererFrame); + rendererLayout->addWidget(renderer()); - connect (ui.objectList, SIGNAL (itemSelectionChanged()), this, SLOT (selectionChanged())); - connect (ui.objectList, SIGNAL (itemDoubleClicked (QListWidgetItem*)), this, SLOT (objectListDoubleClicked (QListWidgetItem*))); - connect (m_tabs, SIGNAL (currentChanged(int)), this, SLOT (tabSelected())); - connect (m_tabs, SIGNAL (tabCloseRequested (int)), this, SLOT (closeTab (int))); + connect(ui.objectList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged())); + connect(ui.objectList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(objectListDoubleClicked(QListWidgetItem*))); + connect(m_tabs, SIGNAL(currentChanged(int)), this, SLOT(tabSelected())); + connect(m_tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); if (ActivePrimitiveScanner()) - connect (ActivePrimitiveScanner(), SIGNAL (workDone()), this, SLOT (updatePrimitives())); + connect(ActivePrimitiveScanner(), SIGNAL(workDone()), this, SLOT(updatePrimitives())); else updatePrimitives(); m_quickColors = LoadQuickColorList(); - setStatusBar (new QStatusBar); + setStatusBar(new QStatusBar); updateActions(); // Connect all actions and save default sequences - applyToActions ([&](QAction* act) + applyToActions([&](QAction* act) { - connect (act, SIGNAL (triggered()), this, SLOT (actionTriggered())); + connect(act, SIGNAL(triggered()), this, SLOT(actionTriggered())); m_defaultShortcuts[act] = act->shortcut(); }); @@ -116,45 +116,45 @@ updateColorToolbar(); updateTitle(); loadShortcuts(); - setMinimumSize (300, 200); - connect (qApp, SIGNAL (aboutToQuit()), this, SLOT (doLastSecondCleanup())); - connect (ui.ringToolHiRes, SIGNAL (clicked (bool)), this, SLOT (ringToolHiResClicked (bool))); - connect (ui.ringToolSegments, SIGNAL (valueChanged (int)), - this, SLOT (circleToolSegmentsChanged())); + setMinimumSize(300, 200); + connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(doLastSecondCleanup())); + connect(ui.ringToolHiRes, SIGNAL(clicked(bool)), this, SLOT(ringToolHiResClicked(bool))); + connect(ui.ringToolSegments, SIGNAL(valueChanged(int)), + this, SLOT(circleToolSegmentsChanged())); circleToolSegmentsChanged(); // invoke it manually for initial label text // Examine the toolsets and make a dictionary of tools - m_toolsets = Toolset::createToolsets (this); + m_toolsets = Toolset::createToolsets(this); QStringList ignore; for (int i = 0; i < Toolset::staticMetaObject.methodCount(); ++i) { - QMetaMethod method = Toolset::staticMetaObject.method (i); - ignore.append (QString::fromUtf8 (method.name())); + QMetaMethod method = Toolset::staticMetaObject.method(i); + ignore.append(QString::fromUtf8(method.name())); } for (Toolset* toolset : m_toolsets) { const QMetaObject* meta = toolset->metaObject(); - if (qobject_cast<ExtProgramToolset*> (toolset)) - m_externalPrograms = static_cast<ExtProgramToolset*> (toolset); + if (qobject_cast<ExtProgramToolset*>(toolset)) + m_externalPrograms = static_cast<ExtProgramToolset*>(toolset); for (int i = 0; i < meta->methodCount(); ++i) { ToolInfo info; - info.method = meta->method (i); + info.method = meta->method(i); info.object = toolset; - QString methodName = QString::fromUtf8 (info.method.name()); + QString methodName = QString::fromUtf8(info.method.name()); - if (ignore.contains (methodName)) + if (ignore.contains(methodName)) continue; // The method was inherited from base classes - QString actionName = "action" + methodName.left (1).toUpper() + methodName.mid (1); - QAction* action = findChild<QAction*> (actionName); + QString actionName = "action" + methodName.left(1).toUpper() + methodName.mid(1); + QAction* action = findChild<QAction*>(actionName); if (action == nullptr) - print ("No action for %1::%2 (looked for %3)\n", meta->className(), methodName, actionName); + print("No action for %1::%2(looked for %3)\n", meta->className(), methodName, actionName); else m_toolmap[action] = info; } @@ -162,7 +162,7 @@ for (QVariant const& toolbarname : config.hiddenToolbars()) { - QToolBar* toolbar = findChild<QToolBar*> (toolbarname.toString()); + QToolBar* toolbar = findChild<QToolBar*>(toolbarname.toString()); if (toolbar) toolbar->hide(); @@ -172,9 +172,9 @@ // them to the profile tab, it's the most important form to fill in. if (config.firstStart()) { - ConfigDialog* dialog = new ConfigDialog (this, ConfigDialog::ProfileTab); + ConfigDialog* dialog = new ConfigDialog(this, ConfigDialog::ProfileTab); dialog->show(); - config.setFirstStart (false); + config.setFirstStart(false); } } @@ -189,17 +189,17 @@ { // Get the name of the sender object and use it to compose the slot name, // then invoke this slot to call the action. - QAction* action = qobject_cast<QAction*> (sender()); + QAction* action = qobject_cast<QAction*>(sender()); if (action) { - if (m_toolmap.contains (action)) + if (m_toolmap.contains(action)) { const ToolInfo& info = m_toolmap[action]; - info.method.invoke (info.object, Qt::DirectConnection); + info.method.invoke(info.object, Qt::DirectConnection); } else - print ("No tool info for %1!\n", action->objectName()); + print("No tool info for %1!\n", action->objectName()); } endAction(); @@ -210,7 +210,7 @@ void MainWindow::endAction() { m_currentDocument->addHistoryStep(); - updateDocumentListItem (m_currentDocument); + updateDocumentListItem(m_currentDocument); refresh(); } @@ -237,10 +237,10 @@ for (const QVariant& it : config.recentFiles()) { QString file = it.toString(); - QAction* recent = new QAction (GetIcon ("open-recent"), file, this); + QAction* recent = new QAction(GetIcon("open-recent"), file, this); - connect (recent, SIGNAL (triggered()), this, SLOT (recentFileClicked())); - ui.menuOpenRecent->insertAction (first, recent); + connect(recent, SIGNAL(triggered()), this, SLOT(recentFileClicked())); + ui.menuOpenRecent->insertAction(first, recent); m_recentFiles << recent; first = recent; } @@ -252,7 +252,7 @@ { QList<ColorToolbarItem> colors; - for (QString colorname : config.quickColorToolbar().split (":")) + for (QString colorname : config.quickColorToolbar().split(":")) { if (colorname == "|") colors << ColorToolbarItem::makeSeparator(); @@ -261,7 +261,7 @@ LDColor color = colorname.toInt(); if (color.isValid()) - colors << ColorToolbarItem (color, nullptr); + colors << ColorToolbarItem(color, nullptr); } } @@ -274,7 +274,7 @@ { m_colorButtons.clear(); ui.toolBarColors->clear(); - ui.toolBarColors->addAction (ui.actionUncolor); + ui.toolBarColors->addAction(ui.actionUncolor); ui.toolBarColors->addSeparator(); for (ColorToolbarItem& entry : m_quickColors) @@ -286,15 +286,15 @@ else { QToolButton* colorButton = new QToolButton; - colorButton->setIcon (m_guiUtilities->makeColorIcon (entry.color(), 16)); - colorButton->setIconSize (QSize (16, 16)); - colorButton->setToolTip (entry.color().name()); + colorButton->setIcon(m_guiUtilities->makeColorIcon(entry.color(), 16)); + colorButton->setIconSize(QSize(16, 16)); + colorButton->setToolTip(entry.color().name()); - connect (colorButton, SIGNAL (clicked()), this, SLOT (quickColorClicked())); - ui.toolBarColors->addWidget (colorButton); + connect(colorButton, SIGNAL(clicked()), this, SLOT(quickColorClicked())); + ui.toolBarColors->addWidget(colorButton); m_colorButtons << colorButton; - entry.setToolButton (colorButton); + entry.setToolButton(colorButton); } } @@ -307,20 +307,20 @@ { // Ensure that the current grid - and only the current grid - is selected. int grid = config.grid(); - ui.actionGridCoarse->setChecked (grid == Grid::Coarse); - ui.actionGridMedium->setChecked (grid == Grid::Medium); - ui.actionGridFine->setChecked (grid == Grid::Fine); + ui.actionGridCoarse->setChecked(grid == Grid::Coarse); + ui.actionGridMedium->setChecked(grid == Grid::Medium); + ui.actionGridFine->setChecked(grid == Grid::Fine); // Recompile all Bézier curves, the changing grid affects their precision. - for (LDObjectIterator<LDBezierCurve> it (m_currentDocument); it.isValid(); ++it) - renderer()->compileObject (it); + for (LDObjectIterator<LDBezierCurve> it(m_currentDocument); it.isValid(); ++it) + renderer()->compileObject(it); } // --------------------------------------------------------------------------------------------------------------------- // void MainWindow::updateTitle() { - QString title = format (APPNAME " " VERSION_STRING); + QString title = format(APPNAME " " VERSION_STRING); // Append our current file if we have one if (m_currentDocument) @@ -329,11 +329,11 @@ title += m_currentDocument->getDisplayName(); if (m_currentDocument->getObjectCount() > 0 and - m_currentDocument->getObject (0)->type() == OBJ_Comment) + m_currentDocument->getObject(0)->type() == OBJ_Comment) { // Append title - LDComment* comm = static_cast <LDComment*> (m_currentDocument->getObject (0)); - title += format (": %1", comm->text()); + LDComment* comm = static_cast <LDComment*>(m_currentDocument->getObject(0)); + title += format(": %1", comm->text()); } if (m_currentDocument->hasUnsavedChanges()) @@ -346,10 +346,10 @@ title += " [pre-release build]"; #endif // DEBUG - if (strlen (commitTimeString())) - title += format (" (%1)", QString::fromUtf8 (commitTimeString())); + if (strlen(commitTimeString())) + title += format("(%1)", QString::fromUtf8(commitTimeString())); - setWindowTitle (title); + setWindowTitle(title); } // --------------------------------------------------------------------------------------------------------------------- @@ -383,7 +383,7 @@ m_objectsInList.clear(); for (int i = 0; i < ui.objectList->count(); ++i) - delete ui.objectList->item (i); + delete ui.objectList->item(i); ui.objectList->clear(); @@ -391,15 +391,15 @@ { QString descr; - switch (obj->type()) + switch(obj->type()) { case OBJ_Comment: { - descr = static_cast<LDComment*> (obj)->text(); + descr = static_cast<LDComment*>(obj)->text(); // Remove leading whitespace while (descr[0] == ' ') - descr.remove (0, 1); + descr.remove(0, 1); break; } @@ -418,25 +418,25 @@ if (i != 0) descr += ", "; - descr += obj->vertex (i).toString (true); + descr += obj->vertex(i).toString(true); } break; } case OBJ_Error: { - descr = format ("ERROR: %1", obj->asText()); + descr = format("ERROR: %1", obj->asText()); break; } case OBJ_SubfileReference: { - LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj); + LDSubfileReference* ref = static_cast<LDSubfileReference*>(obj); - descr = format ("%1 %2, (", ref->fileInfo()->getDisplayName(), ref->position().toString (true)); + descr = format("%1 %2,(", ref->fileInfo()->getDisplayName(), ref->position().toString(true)); for (int i = 0; i < 9; ++i) - descr += format ("%1%2", ref->transform()[i], (i != 8) ? " " : ""); + descr += format("%1%2", ref->transform()[i],(i != 8) ? " " : ""); descr += ')'; break; @@ -444,15 +444,15 @@ case OBJ_Bfc: { - descr = static_cast<LDBfc*> (obj)->statementToString(); + descr = static_cast<LDBfc*>(obj)->statementToString(); break; } case OBJ_Overlay: { - LDOverlay* ovl = static_cast<LDOverlay*> (obj); - descr = format ("[%1] %2 (%3, %4), %5 x %6", renderer()->cameraName ((ECamera) ovl->camera()), - Basename (ovl->fileName()), ovl->x(), ovl->y(), + LDOverlay* ovl = static_cast<LDOverlay*>(obj); + descr = format("[%1] %2(%3, %4), %5 x %6", renderer()->cameraName((ECamera) ovl->camera()), + Basename(ovl->fileName()), ovl->x(), ovl->y(), ovl->width(), ovl->height()); break; } @@ -464,22 +464,22 @@ } } - QListWidgetItem* item = new QListWidgetItem (descr); - item->setIcon (GetIcon (obj->typeName())); + QListWidgetItem* item = new QListWidgetItem(descr); + item->setIcon(GetIcon(obj->typeName())); // Use italic font if hidden if (obj->isHidden()) { QFont font = item->font(); - font.setItalic (true); - item->setFont (font); + font.setItalic(true); + item->setFont(font); } // Color gibberish orange on red so it stands out. if (obj->type() == OBJ_Error) { - item->setBackground (QColor ("#AA0000")); - item->setForeground (QColor ("#FFAA00")); + item->setBackground(QColor("#AA0000")); + item->setForeground(QColor("#FFAA00")); } else if (config.colorizeObjectsList() and obj->isColored() @@ -488,11 +488,11 @@ and obj->color() != EdgeColor) { // If the object isn't in the main or edge color, draw this list entry in that color. - item->setForeground (obj->color().faceColor()); + item->setForeground(obj->color().faceColor()); } - m_objectsInList.insert (obj, item); - ui.objectList->insertItem (ui.objectList->count(), item); + m_objectsInList.insert(obj, item); + ui.objectList->insertItem(ui.objectList->count(), item); } m_isSelectionLocked = false; @@ -510,7 +510,7 @@ return; LDObject* obj = selectedObjects().first(); - ui.objectList->scrollToItem (m_objectsInList[obj]); + ui.objectList->scrollToItem(m_objectsInList[obj]); } // --------------------------------------------------------------------------------------------------------------------- @@ -538,16 +538,16 @@ } } - // The select() method calls may have selected additional items (i.e. invertnexts) + // The select() method calls may have selected additional items(i.e. invertnexts) // Update it all now. updateSelection(); // Update the GL renderer LDObjectList compound = priorSelection + selectedObjects(); - removeDuplicates (compound); + removeDuplicates(compound); for (LDObject* obj : compound) - renderer()->compileObject (obj); + renderer()->compileObject(obj); renderer()->update(); } @@ -556,15 +556,15 @@ // void MainWindow::recentFileClicked() { - QAction* qAct = static_cast<QAction*> (sender()); - documents()->openMainModel (qAct->text()); + QAction* qAct = static_cast<QAction*>(sender()); + documents()->openMainModel(qAct->text()); } // --------------------------------------------------------------------------------------------------------------------- // void MainWindow::quickColorClicked() { - QToolButton* button = static_cast<QToolButton*> (sender()); + QToolButton* button = static_cast<QToolButton*>(sender()); LDColor color = LDColor::nullColor(); for (const ColorToolbarItem& entry : m_quickColors) @@ -584,8 +584,8 @@ if (not obj->isColored()) continue; // uncolored object - obj->setColor (color); - renderer()->compileObject (obj); + obj->setColor(color); + renderer()->compileObject(obj); } endAction(); @@ -635,12 +635,12 @@ for (LDObject* obj : selectedObjects()) { - QListWidgetItem** itempointer = m_objectsInList.find (obj); + QListWidgetItem** itempointer = m_objectsInList.find(obj); if (not itempointer) continue; - int row = ui.objectList->row (*itempointer); + int row = ui.objectList->row(*itempointer); if (top == -1) { @@ -650,8 +650,8 @@ { if (row != bottom + 1) { - itemselect.select (ui.objectList->model()->index (top, 0), - ui.objectList->model()->index (bottom, 0)); + itemselect.select(ui.objectList->model()->index(top, 0), + ui.objectList->model()->index(bottom, 0)); top = -1; } @@ -661,18 +661,18 @@ if (top != -1) { - itemselect.select (ui.objectList->model()->index (top, 0), - ui.objectList->model()->index (bottom, 0)); + itemselect.select(ui.objectList->model()->index(top, 0), + ui.objectList->model()->index(bottom, 0)); } // Select multiple objects at once for performance reasons - ui.objectList->selectionModel()->select (itemselect, QItemSelectionModel::ClearAndSelect); + ui.objectList->selectionModel()->select(itemselect, QItemSelectionModel::ClearAndSelect); m_isSelectionLocked = false; } // --------------------------------------------------------------------------------------------------------------------- // -// Returns the uniform selected color (i.e. 4 if everything selected is red), -1 if there is no such consensus. +// Returns the uniform selected color(i.e. 4 if everything selected is red), -1 if there is no such consensus. // LDColor MainWindow::getUniformSelectedColor() { @@ -695,7 +695,7 @@ // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::closeEvent (QCloseEvent* ev) +void MainWindow::closeEvent(QCloseEvent* ev) { // Check whether it's safe to close all files. if (not m_documents->isSafeToCloseAll()) @@ -714,14 +714,14 @@ } // Save the configuration before leaving. - config.setHiddenToolbars (hiddenToolbars); + config.setHiddenToolbars(hiddenToolbars); syncSettings(); ev->accept(); } // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::spawnContextMenu (const QPoint pos) +void MainWindow::spawnContextMenu(const QPoint pos) { const bool single = (selectedObjects().size() == 1); LDObject* singleObj = single ? selectedObjects().first() : nullptr; @@ -741,53 +741,53 @@ if (single and singleObj->type() != OBJ_Empty) { - contextMenu->addAction (ui.actionEdit); + contextMenu->addAction(ui.actionEdit); contextMenu->addSeparator(); } - contextMenu->addAction (ui.actionCut); - contextMenu->addAction (ui.actionCopy); - contextMenu->addAction (ui.actionPaste); - contextMenu->addAction (ui.actionRemove); + contextMenu->addAction(ui.actionCut); + contextMenu->addAction(ui.actionCopy); + contextMenu->addAction(ui.actionPaste); + contextMenu->addAction(ui.actionRemove); contextMenu->addSeparator(); - contextMenu->addAction (ui.actionSetColor); + contextMenu->addAction(ui.actionSetColor); if (single) - contextMenu->addAction (ui.actionEditRaw); + contextMenu->addAction(ui.actionEditRaw); - contextMenu->addAction (ui.actionMakeBorders); - contextMenu->addAction (ui.actionSetOverlay); - contextMenu->addAction (ui.actionClearOverlay); + contextMenu->addAction(ui.actionMakeBorders); + contextMenu->addAction(ui.actionSetOverlay); + contextMenu->addAction(ui.actionClearOverlay); if (hasSubfiles) { contextMenu->addSeparator(); - contextMenu->addAction (ui.actionOpenSubfiles); + contextMenu->addAction(ui.actionOpenSubfiles); } contextMenu->addSeparator(); - contextMenu->addAction (ui.actionModeSelect); - contextMenu->addAction (ui.actionModeDraw); - contextMenu->addAction (ui.actionModeCircle); + contextMenu->addAction(ui.actionModeSelect); + contextMenu->addAction(ui.actionModeDraw); + contextMenu->addAction(ui.actionModeCircle); if (not selectedObjects().isEmpty()) { contextMenu->addSeparator(); - contextMenu->addAction (ui.actionSubfileSelection); + contextMenu->addAction(ui.actionSubfileSelection); } if (renderer()->camera() != EFreeCamera) { contextMenu->addSeparator(); - contextMenu->addAction (ui.actionSetDrawDepth); + contextMenu->addAction(ui.actionSetDrawDepth); } - contextMenu->exec (pos); + contextMenu->exec(pos); } // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::deleteByColor (LDColor color) +void MainWindow::deleteByColor(LDColor color) { LDObjectList objs; @@ -808,26 +808,26 @@ void MainWindow::updateEditModeActions() { const EditModeType mode = renderer()->currentEditModeType(); - ui.actionModeSelect->setChecked (mode == EditModeType::Select); - ui.actionModeDraw->setChecked (mode == EditModeType::Draw); - ui.actionModeRectangle->setChecked (mode == EditModeType::Rectangle); - ui.actionModeCircle->setChecked (mode == EditModeType::Circle); - ui.actionModeMagicWand->setChecked (mode == EditModeType::MagicWand); - ui.actionModeLinePath->setChecked (mode == EditModeType::LinePath); - ui.actionModeCurve->setChecked (mode == EditModeType::Curve); + ui.actionModeSelect->setChecked(mode == EditModeType::Select); + ui.actionModeDraw->setChecked(mode == EditModeType::Draw); + ui.actionModeRectangle->setChecked(mode == EditModeType::Rectangle); + ui.actionModeCircle->setChecked(mode == EditModeType::Circle); + ui.actionModeMagicWand->setChecked(mode == EditModeType::MagicWand); + ui.actionModeLinePath->setChecked(mode == EditModeType::LinePath); + ui.actionModeCurve->setChecked(mode == EditModeType::Curve); } // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::objectListDoubleClicked (QListWidgetItem* listitem) +void MainWindow::objectListDoubleClicked(QListWidgetItem* listitem) { - LDObject* object = m_objectsInList.reverseLookup (listitem); - AddObjectDialog::staticDialog (object->type(), object); + LDObject* object = m_objectsInList.reverseLookup(listitem); + AddObjectDialog::staticDialog(object->type(), object); } // --------------------------------------------------------------------------------------------------------------------- // -bool MainWindow::save (LDDocument* doc, bool saveAs) +bool MainWindow::save(LDDocument* doc, bool saveAs) { if (doc->isCache()) return false; @@ -844,9 +844,9 @@ else if (not doc->name().isEmpty()) name = doc->name(); - name.replace ("\\", "/"); - path = QFileDialog::getSaveFileName (this, tr ("Save As"), - name, tr ("LDraw files (*.dat *.ldr)")); + name.replace("\\", "/"); + path = QFileDialog::getSaveFileName(this, tr("Save As"), + name, tr("LDraw files(*.dat *.ldr)")); if (path.isEmpty()) { @@ -855,75 +855,75 @@ } } - if (doc->save (path, &savesize)) + if (doc->save(path, &savesize)) { if (doc == m_currentDocument) updateTitle(); - print ("Saved to %1 (%2)", path, MakePrettyFileSize (savesize)); + print("Saved to %1(%2)", path, MakePrettyFileSize(savesize)); // Add it to recent files - m_documents->addRecentFile (path); + m_documents->addRecentFile(path); return true; } - QString message = format (tr ("Failed to save to %1: %2"), path, strerror (errno)); + QString message = format(tr("Failed to save to %1: %2"), path, strerror(errno)); // Tell the user the save failed, and give the option for saving as with it. - QMessageBox dlg (QMessageBox::Critical, tr ("Save Failure"), message, QMessageBox::Close, this); + QMessageBox dlg(QMessageBox::Critical, tr("Save Failure"), message, QMessageBox::Close, this); // Add a save-as button - QPushButton* saveAsBtn = new QPushButton (tr ("Save As")); - saveAsBtn->setIcon (GetIcon ("file-save-as")); - dlg.addButton (saveAsBtn, QMessageBox::ActionRole); - dlg.setDefaultButton (QMessageBox::Close); + QPushButton* saveAsBtn = new QPushButton(tr("Save As")); + saveAsBtn->setIcon(GetIcon("file-save-as")); + dlg.addButton(saveAsBtn, QMessageBox::ActionRole); + dlg.setDefaultButton(QMessageBox::Close); dlg.exec(); if (dlg.clickedButton() == saveAsBtn) - return save (doc, true); // yay recursion! + return save(doc, true); // yay recursion! return false; } // Adds a message to the renderer's message manager. -void MainWindow::addMessage (QString msg) +void MainWindow::addMessage(QString msg) { - m_renderer->messageLog()->addLine (msg); + m_renderer->messageLog()->addLine(msg); } // ============================================================================ -void ObjectList::contextMenuEvent (QContextMenuEvent* ev) +void ObjectList::contextMenuEvent(QContextMenuEvent* ev) { - g_win->spawnContextMenu (ev->globalPos()); + g_win->spawnContextMenu(ev->globalPos()); } // --------------------------------------------------------------------------------------------------------------------- // -QPixmap GetIcon (QString iconName) +QPixmap GetIcon(QString iconName) { - return (QPixmap (format (":/icons/%1.png", iconName))); + return (QPixmap(format(":/icons/%1.png", iconName))); } // --------------------------------------------------------------------------------------------------------------------- // -bool Confirm (const QString& message) +bool Confirm(const QString& message) { - return Confirm (MainWindow::tr ("Confirm"), message); + return Confirm(MainWindow::tr("Confirm"), message); } // --------------------------------------------------------------------------------------------------------------------- // -bool Confirm (const QString& title, const QString& message) +bool Confirm(const QString& title, const QString& message) { - return QMessageBox::question (g_win, title, message, + return QMessageBox::question(g_win, title, message, (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::Yes; } // --------------------------------------------------------------------------------------------------------------------- // -void Critical (const QString& message) +void Critical(const QString& message) { - QMessageBox::critical (g_win, MainWindow::tr ("Error"), message, + QMessageBox::critical(g_win, MainWindow::tr("Error"), message, (QMessageBox::Close), QMessageBox::Close); } @@ -934,7 +934,7 @@ m_updatingTabs = true; while (m_tabs->count() > 0) - m_tabs->removeTab (0); + m_tabs->removeTab(0); for (LDDocument* document : m_documents->allDocuments()) { @@ -942,8 +942,8 @@ { // Add an item to the list for this file and store the tab index // in the document so we can find documents by tab index. - document->setTabIndex (m_tabs->addTab ("")); - updateDocumentListItem (document); + document->setTabIndex(m_tabs->addTab("")); + updateDocumentListItem(document); } } @@ -954,7 +954,7 @@ // // Update the given document's tab. If no such tab exists, the document list is rebuilt. // -void MainWindow::updateDocumentListItem (LDDocument* doc) +void MainWindow::updateDocumentListItem(LDDocument* doc) { bool oldUpdatingTabs = m_updatingTabs; m_updatingTabs = true; @@ -970,13 +970,13 @@ // If this is the current file, it also needs to be the selected item on // the list. if (doc == m_currentDocument) - m_tabs->setCurrentIndex (doc->tabIndex()); + m_tabs->setCurrentIndex(doc->tabIndex()); - m_tabs->setTabText (doc->tabIndex(), doc->getDisplayName()); + m_tabs->setTabText(doc->tabIndex(), doc->getDisplayName()); // If the document.has unsaved changes, draw a little icon next to it to mark that. - m_tabs->setTabIcon (doc->tabIndex(), doc->hasUnsavedChanges() ? GetIcon ("file-save") : QIcon()); - m_tabs->setTabData (doc->tabIndex(), doc->name()); + m_tabs->setTabIcon(doc->tabIndex(), doc->hasUnsavedChanges() ? GetIcon("file-save") : QIcon()); + m_tabs->setTabData(doc->tabIndex(), doc->name()); m_updatingTabs = oldUpdatingTabs; } @@ -1004,7 +1004,7 @@ } if (switchee and switchee != m_currentDocument) - changeDocument (switchee); + changeDocument(switchee); } // --------------------------------------------------------------------------------------------------------------------- @@ -1018,7 +1018,7 @@ LDDocument* f = getm_currentDocument; for (LDObject* obj : *f) - ui.objectList->addItem (obj->qObjListEntry); + ui.objectList->addItem(obj->qObjListEntry); #endif @@ -1036,18 +1036,18 @@ { EditHistory* his = m_currentDocument->history(); int pos = his->position(); - ui.actionUndo->setEnabled (pos != -1); - ui.actionRedo->setEnabled (pos < (long) his->size() - 1); + ui.actionUndo->setEnabled(pos != -1); + ui.actionRedo->setEnabled(pos <(long) his->size() - 1); } - ui.actionWireframe->setChecked (config.drawWireframe()); - ui.actionAxes->setChecked (config.drawAxes()); - ui.actionBfcView->setChecked (config.bfcRedGreenView()); - ui.actionRandomColors->setChecked (config.randomColors()); - ui.actionDrawAngles->setChecked (config.drawAngles()); - ui.actionDrawSurfaces->setChecked (config.drawSurfaces()); - ui.actionDrawEdgeLines->setChecked (config.drawEdgeLines()); - ui.actionDrawConditionalLines->setChecked (config.drawConditionalLines()); + ui.actionWireframe->setChecked(config.drawWireframe()); + ui.actionAxes->setChecked(config.drawAxes()); + ui.actionBfcView->setChecked(config.bfcRedGreenView()); + ui.actionRandomColors->setChecked(config.randomColors()); + ui.actionDrawAngles->setChecked(config.drawAngles()); + ui.actionDrawSurfaces->setChecked(config.drawSurfaces()); + ui.actionDrawEdgeLines->setChecked(config.drawEdgeLines()); + ui.actionDrawConditionalLines->setChecked(config.drawConditionalLines()); } // --------------------------------------------------------------------------------------------------------------------- @@ -1059,7 +1059,7 @@ // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::setQuickColors (const QList<ColorToolbarItem>& colors) +void MainWindow::setQuickColors(const QList<ColorToolbarItem>& colors) { m_quickColors = colors; updateColorToolbar(); @@ -1069,14 +1069,14 @@ // void MainWindow::updatePrimitives() { - populatePrimitivesTree (ui.primitives); + populatePrimitivesTree(ui.primitives); } // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::closeTab (int tabindex) +void MainWindow::closeTab(int tabindex) { - LDDocument* doc = m_documents->findDocumentByName (m_tabs->tabData (tabindex).toString()); + LDDocument* doc = m_documents->findDocumentByName(m_tabs->tabData(tabindex).toString()); if (doc) doc->close(); @@ -1096,8 +1096,8 @@ { for (QAction* act : findChildren<QAction*>()) { - QKeySequence seq = m_settings->value ("shortcut_" + act->objectName(), act->shortcut()).value<QKeySequence>(); - act->setShortcut (seq); + QKeySequence seq = m_settings->value("shortcut_" + act->objectName(), act->shortcut()).value<QKeySequence>(); + act->setShortcut(seq); } } @@ -1105,25 +1105,25 @@ // void MainWindow::saveShortcuts() { - applyToActions ([&](QAction* act) + applyToActions([&](QAction* act) { QString const key = "shortcut_" + act->objectName(); if (m_defaultShortcuts[act] != act->shortcut()) - m_settings->setValue (key, act->shortcut()); + m_settings->setValue(key, act->shortcut()); else - m_settings->remove (key); + m_settings->remove(key); }); } // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::applyToActions (std::function<void(QAction*)> function) +void MainWindow::applyToActions(std::function<void(QAction*)> function) { for (QAction* act : findChildren<QAction*>()) { if (not act->objectName().isEmpty()) - function (act); + function(act); } } @@ -1136,7 +1136,7 @@ // --------------------------------------------------------------------------------------------------------------------- // -QKeySequence MainWindow::defaultShortcut (QAction* act) +QKeySequence MainWindow::defaultShortcut(QAction* act) { return m_defaultShortcuts[act]; } @@ -1157,17 +1157,17 @@ // --------------------------------------------------------------------------------------------------------------------- // -void MainWindow::ringToolHiResClicked (bool checked) +void MainWindow::ringToolHiResClicked(bool checked) { if (checked) { - ui.ringToolSegments->setMaximum (HighResolution); - ui.ringToolSegments->setValue (ui.ringToolSegments->value() * 3); + ui.ringToolSegments->setMaximum(HighResolution); + ui.ringToolSegments->setValue(ui.ringToolSegments->value() * 3); } else { - ui.ringToolSegments->setValue (ui.ringToolSegments->value() / 3); - ui.ringToolSegments->setMaximum (LowResolution); + ui.ringToolSegments->setValue(ui.ringToolSegments->value() / 3); + ui.ringToolSegments->setMaximum(LowResolution); } } @@ -1175,20 +1175,20 @@ // void MainWindow::circleToolSegmentsChanged() { - int numerator (ui.ringToolSegments->value()); - int denominator (ui.ringToolHiRes->isChecked() ? HighResolution : LowResolution); - Simplify (numerator, denominator); - ui.ringToolSegmentsLabel->setText (format ("%1 / %2", numerator, denominator)); + int numerator(ui.ringToolSegments->value()); + int denominator(ui.ringToolHiRes->isChecked() ? HighResolution : LowResolution); + Simplify(numerator, denominator); + ui.ringToolSegmentsLabel->setText(format("%1 / %2", numerator, denominator)); } // --------------------------------------------------------------------------------------------------------------------- // // Accessor to the settings object // -QSettings* makeSettings (QObject* parent) +QSettings* makeSettings(QObject* parent) { QString path = qApp->applicationDirPath() + "/" UNIXNAME ".ini"; - return new QSettings (path, QSettings::IniFormat, parent); + return new QSettings(path, QSettings::IniFormat, parent); } // --------------------------------------------------------------------------------------------------------------------- @@ -1200,9 +1200,9 @@ // --------------------------------------------------------------------------------------------------------------------- // -QVariant MainWindow::getConfigValue (QString name) +QVariant MainWindow::getConfigValue(QString name) { - QVariant value = m_settings->value (name, config.defaultValueByName (name)); + QVariant value = m_settings->value(name, config.defaultValueByName(name)); return value; } @@ -1212,8 +1212,8 @@ { // Create a new anonymous file and set it to our current LDDocument* f = newDocument(); - f->setName (""); - changeDocument (f); + f->setName(""); + changeDocument(f); closeInitialDocument(); doFullRefresh(); updateActions(); @@ -1221,12 +1221,12 @@ // --------------------------------------------------------------------------------------------------------------------- // -LDDocument* MainWindow::newDocument (bool cache) +LDDocument* MainWindow::newDocument(bool cache) { LDDocument* document = m_documents->createNew(); - connect (document->history(), SIGNAL (undone()), this, SLOT (historyTraversed())); - connect (document->history(), SIGNAL (redone()), this, SLOT (historyTraversed())); - connect (document->history(), SIGNAL (stepAdded()), this, SLOT (updateActions())); + connect(document->history(), SIGNAL(undone()), this, SLOT(historyTraversed())); + connect(document->history(), SIGNAL(redone()), this, SLOT(historyTraversed())); + connect(document->history(), SIGNAL(stepAdded()), this, SLOT(updateActions())); if (not cache) document->openForEditing(); @@ -1245,7 +1245,7 @@ // // TODO: document may be null, this shouldn't be the case // -void MainWindow::changeDocument (LDDocument* document) +void MainWindow::changeDocument(LDDocument* document) { // Implicit files were loaded for caching purposes and may never be switched to. if (document and document->isCache()) @@ -1256,12 +1256,12 @@ if (document) { // A ton of stuff needs to be updated - updateDocumentListItem (document); + updateDocumentListItem(document); buildObjectList(); updateTitle(); - m_renderer->setDocument (document); + m_renderer->setDocument(document); m_renderer->compiler()->needMerge(); - print ("Changed document to %1", document->getDisplayName()); + print("Changed document to %1", document->getDisplayName()); } } @@ -1300,7 +1300,7 @@ { if (doc != old and not doc->isCache()) { - changeDocument (doc); + changeDocument(doc); break; } } @@ -1324,13 +1324,13 @@ // --------------------------------------------------------------------------------------------------------------------- // -ColorToolbarItem::ColorToolbarItem (LDColor color, QToolButton* toolButton) : - m_color (color), - m_toolButton (toolButton) {} +ColorToolbarItem::ColorToolbarItem(LDColor color, QToolButton* toolButton) : + m_color(color), + m_toolButton(toolButton) {} ColorToolbarItem ColorToolbarItem::makeSeparator() { - return ColorToolbarItem (LDColor::nullColor(), nullptr); + return ColorToolbarItem(LDColor::nullColor(), nullptr); } bool ColorToolbarItem::isSeparator() const @@ -1343,7 +1343,7 @@ return m_color; } -void ColorToolbarItem::setColor (LDColor color) +void ColorToolbarItem::setColor(LDColor color) { m_color = color; } @@ -1353,46 +1353,46 @@ return m_toolButton; } -void ColorToolbarItem::setToolButton (QToolButton* value) +void ColorToolbarItem::setToolButton(QToolButton* value) { m_toolButton = value; } // --------------------------------------------------------------------------------------------------------------------- // -void populatePrimitivesTree (QTreeWidget* tw, QString const& selectByDefault) +void populatePrimitivesTree(QTreeWidget* tw, QString const& selectByDefault) { tw->clear(); for (PrimitiveCategory* cat : g_PrimitiveCategories) { - PrimitiveTreeItem* parentItem = new PrimitiveTreeItem (tw, nullptr); - parentItem->setText (0, cat->name()); + PrimitiveTreeItem* parentItem = new PrimitiveTreeItem(tw, nullptr); + parentItem->setText(0, cat->name()); QList<QTreeWidgetItem*> subfileItems; for (Primitive& prim : cat->prims) { - PrimitiveTreeItem* item = new PrimitiveTreeItem (parentItem, &prim); - item->setText (0, format ("%1 - %2", prim.name, prim.title)); + PrimitiveTreeItem* item = new PrimitiveTreeItem(parentItem, &prim); + item->setText(0, format("%1 - %2", prim.name, prim.title)); subfileItems << item; // If this primitive is the one the current object points to, // select it by default if (selectByDefault == prim.name) - tw->setCurrentItem (item); + tw->setCurrentItem(item); } - tw->addTopLevelItem (parentItem); + tw->addTopLevelItem(parentItem); } } -PrimitiveTreeItem::PrimitiveTreeItem (QTreeWidgetItem* parent, Primitive* info) : - QTreeWidgetItem (parent), - m_primitive (info) {} +PrimitiveTreeItem::PrimitiveTreeItem(QTreeWidgetItem* parent, Primitive* info) : + QTreeWidgetItem(parent), + m_primitive(info) {} -PrimitiveTreeItem::PrimitiveTreeItem (QTreeWidget* parent, Primitive* info) : - QTreeWidgetItem (parent), - m_primitive (info) {} +PrimitiveTreeItem::PrimitiveTreeItem(QTreeWidget* parent, Primitive* info) : + QTreeWidgetItem(parent), + m_primitive(info) {} Primitive* PrimitiveTreeItem::primitive() const {