Thu, 23 Feb 2017 20:03:31 +0200
Moved GetIcon and makeSettings into the MainWindow namespace as static methods.
--- a/src/dialogs/configdialog.cpp Thu Feb 23 19:56:21 2017 +0200 +++ b/src/dialogs/configdialog.cpp Thu Feb 23 20:03:31 2017 +0200 @@ -74,7 +74,7 @@ QDialog (parent, f), HierarchyElement (parent), ui (*new Ui_ConfigDialog), - m_settings (makeSettings (this)) + m_settings (MainWindow::makeSettings (this)) { ui.setupUi (this); @@ -173,7 +173,7 @@ // If the action doesn't have a valid icon, use an empty one // so that the list is kept aligned. if (act->icon().isNull()) - item->setIcon (GetIcon ("empty")); + item->setIcon (MainWindow::getIcon ("empty")); ui.shortcutsList->insertItem (ui.shortcutsList->count(), item); } @@ -196,9 +196,9 @@ QLineEdit* input = new QLineEdit; QPushButton* setPathButton = new QPushButton; - icon->setPixmap (GetIcon (name.toLower())); + icon->setPixmap (MainWindow::getIcon (name.toLower())); input->setText (m_window->externalPrograms()->getPathSetting (program)); - setPathButton->setIcon (GetIcon ("folder")); + setPathButton->setIcon (MainWindow::getIcon ("folder")); widgets.input = input; widgets.setPathButton = setPathButton; widgets.wineBox = nullptr; @@ -345,7 +345,7 @@ if (entry.isSeparator()) { item->setText ("<hr />"); - item->setIcon (GetIcon ("empty")); + item->setIcon (MainWindow::getIcon ("empty")); } else { @@ -359,7 +359,7 @@ else { item->setText ("[[unknown color]]"); - item->setIcon (GetIcon ("error")); + item->setIcon (MainWindow::getIcon ("error")); } } @@ -500,7 +500,7 @@ // void ConfigDialog::setButtonBackground (QPushButton* button, QString value) { - button->setIcon (GetIcon ("colorselect")); + button->setIcon (MainWindow::getIcon ("colorselect")); button->setAutoFillBackground (true); button->setStyleSheet (format ("background-color: %1", value)); m_buttonColors[button] = QColor (value);
--- a/src/dialogs/ldrawpathdialog.cpp Thu Feb 23 19:56:21 2017 +0200 +++ b/src/dialogs/ldrawpathdialog.cpp Thu Feb 23 20:03:31 2017 +0200 @@ -36,7 +36,7 @@ else { cancelButton()->setText ("Exit"); - cancelButton()->setIcon (GetIcon ("exit")); + cancelButton()->setIcon (MainWindow::getIcon ("exit")); } okButton()->setEnabled (false);
--- a/src/glrenderer.cpp Thu Feb 23 19:56:21 2017 +0200 +++ b/src/glrenderer.cpp Thu Feb 23 20:03:31 2017 +0200 @@ -85,7 +85,7 @@ }; CameraIcon* info = &m_cameraIcons[static_cast<int>(camera)]; - info->image = GetIcon (cameraIconNames[static_cast<int>(camera)]); + info->image = MainWindow::getIcon (cameraIconNames[static_cast<int>(camera)]); info->camera = camera; }
--- a/src/guiutilities.cpp Thu Feb 23 19:56:21 2017 +0200 +++ b/src/guiutilities.cpp Thu Feb 23 20:03:31 2017 +0200 @@ -51,7 +51,7 @@ painter.fillRect(QRect {0, 0, size, size}, ldColor.edgeColor()); // Paint the checkerboard background, visible with translucent icons - painter.drawPixmap(QRect {1, 1, size - 2, size - 2}, GetIcon("checkerboard"), QRect {0, 0, 8, 8}); + painter.drawPixmap(QRect {1, 1, size - 2, size - 2}, MainWindow::getIcon("checkerboard"), QRect {0, 0, 8, 8}); // Paint the color above the checkerboard painter.fillRect (QRect {1, 1, size - 2, size - 2}, color);
--- a/src/mainwindow.cpp Thu Feb 23 19:56:21 2017 +0200 +++ b/src/mainwindow.cpp Thu Feb 23 20:03:31 2017 +0200 @@ -58,7 +58,7 @@ m_mathFunctions(new MathFunctions(this)), ui (*new Ui_MainWindow), m_externalPrograms (nullptr), - m_settings (makeSettings (this)), + m_settings (makeSettings (this)), m_documents (new DocumentManager (this)), m_currentDocument (nullptr), m_isSelectionLocked (false) @@ -228,7 +228,7 @@ for (const QVariant& it : m_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); m_recentFiles << recent; @@ -355,7 +355,7 @@ for (LDObject* obj : m_currentDocument->objects()) { QListWidgetItem* item = new QListWidgetItem {obj->objectListText()}; - item->setIcon (GetIcon (obj->typeName())); + item->setIcon (getIcon (obj->typeName())); // Use italic font if hidden if (obj->isHidden()) @@ -757,7 +757,7 @@ // Add a save-as button QPushButton* saveAsBtn = new QPushButton (tr ("Save As")); - saveAsBtn->setIcon (GetIcon ("file-save-as")); + saveAsBtn->setIcon (getIcon ("file-save-as")); dlg.addButton (saveAsBtn, QMessageBox::ActionRole); dlg.setDefaultButton (QMessageBox::Close); dlg.exec(); @@ -773,11 +773,12 @@ messageLog()->addLine (msg); } -// --------------------------------------------------------------------------------------------------------------------- -// -QPixmap GetIcon (QString iconName) +/* + * Returns an icon from built-in resources. + */ +QPixmap MainWindow::getIcon(QString iconName) { - return (QPixmap (format (":/icons/%1.png", iconName))); + return {format(":/icons/%1.png", iconName)}; } MessageManager* MainWindow::messageLog() const @@ -833,7 +834,7 @@ 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->setTabIcon (doc->tabIndex(), doc->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); m_tabs->setTabData (doc->tabIndex(), doc->name()); m_updatingTabs = oldUpdatingTabs; } @@ -1038,14 +1039,13 @@ ui.ringToolSegmentsLabel->setText (format ("%1 / %2", numerator, denominator)); } -// --------------------------------------------------------------------------------------------------------------------- -// -// Accessor to the settings object -// -QSettings* makeSettings (QObject* parent) +/* + * Returns a settings object that interfaces the ini file. + */ +QSettings* MainWindow::makeSettings(QObject* parent) { QString path = qApp->applicationDirPath() + "/" UNIXNAME ".ini"; - return new QSettings (path, QSettings::IniFormat, parent); + return new QSettings {path, QSettings::IniFormat, parent}; } // ---------------------------------------------------------------------------------------------------------------------
--- a/src/mainwindow.h Thu Feb 23 19:56:21 2017 +0200 +++ b/src/mainwindow.h Thu Feb 23 20:03:31 2017 +0200 @@ -115,6 +115,9 @@ void updateSelection(); void updateTitle(); + static QPixmap getIcon(QString iconName); + static class QSettings* makeSettings(QObject* parent = nullptr); + signals: void gridChanged(); @@ -169,7 +172,3 @@ // Pointer to the instance of MainWindow. // TODO: it's going out, slowly but surely. extern MainWindow* g_win; - -// Get an icon by name from the resources directory. -QPixmap GetIcon (QString iconName); -class QSettings* makeSettings(QObject* parent = nullptr);
--- a/tools/configcollector.py Thu Feb 23 19:56:21 2017 +0200 +++ b/tools/configcollector.py Thu Feb 23 20:03:31 2017 +0200 @@ -153,7 +153,7 @@ device.write( '\n' 'Configuration::Configuration() :\n' - '\tm_settings(makeSettings(nullptr))\n' + '\tm_settings(MainWindow::makeSettings(nullptr))\n' '{\n') for declaration in self.declarations.values(): device.write('\tm_defaults["{name}"] = QVariant::fromValue<{type}>({default});\n'.format(**declaration))