diff --git a/common/lc_shortcuts.cpp b/common/lc_shortcuts.cpp index f5889a73..20e91d9b 100644 --- a/common/lc_shortcuts.cpp +++ b/common/lc_shortcuts.cpp @@ -151,6 +151,27 @@ void lcMouseShortcuts::Reset() mShortcuts[LC_TOOL_ZOOM].Button1 = Qt::RightButton; } +bool lcMouseShortcuts::Save(const QString& FileName) +{ + QStringList Shortcuts; + + if (!Save(Shortcuts)) + return false; + + QFile File(FileName); + + if (!File.open(QIODevice::WriteOnly)) + return false; + + QTextStream Stream(&File); + + for (const QString& Shortcut : Shortcuts) + Stream << Shortcut << QLatin1String("\n"); + + Stream.flush(); + + return true; +} bool lcMouseShortcuts::Save(QStringList& Shortcuts) { Shortcuts.clear(); @@ -179,6 +200,22 @@ bool lcMouseShortcuts::Save(QStringList& Shortcuts) return true; } +bool lcMouseShortcuts::Load(const QString& FileName) +{ + QFile File(FileName); + + if (!File.open(QIODevice::ReadOnly)) + return false; + + QTextStream Stream(&File); + QStringList Lines; + + while (!Stream.atEnd()) + Lines += Stream.readLine(); + + return Load(Lines); +} + bool lcMouseShortcuts::Load(const QStringList& FullShortcuts) { memset(mShortcuts, 0, sizeof(mShortcuts)); diff --git a/common/lc_shortcuts.h b/common/lc_shortcuts.h index 1022ac19..a0e159cf 100644 --- a/common/lc_shortcuts.h +++ b/common/lc_shortcuts.h @@ -24,8 +24,11 @@ class lcMouseShortcuts { public: void Reset(); + bool Save(const QString& FileName); bool Save(QStringList& Shortcuts); + bool Load(const QString& FileName); bool Load(const QStringList& Shortcuts); + lcTool GetTool(Qt::MouseButton Button, Qt::KeyboardModifiers Modifiers) const; struct diff --git a/qt/lc_qpreferencesdialog.cpp b/qt/lc_qpreferencesdialog.cpp index ad295585..bcc18006 100644 --- a/qt/lc_qpreferencesdialog.cpp +++ b/qt/lc_qpreferencesdialog.cpp @@ -1054,6 +1054,38 @@ void lcQPreferencesDialog::on_mouseRemove_clicked() MouseTreeItemChanged(Current); } +void lcQPreferencesDialog::on_MouseImportButton_clicked() +{ + QString FileName = QFileDialog::getOpenFileName(this, tr("Import Shortcuts"), "", tr("Text Files (*.txt);;All Files (*.*)")); + + if (FileName.isEmpty()) + return; + + lcMouseShortcuts Shortcuts; + if (!Shortcuts.Load(FileName)) + { + QMessageBox::warning(this, "LeoCAD", tr("Error loading mouse shortcuts file.")); + return; + } + + mOptions->MouseShortcuts = Shortcuts; + UpdateMouseTree(); + + mOptions->MouseShortcutsModified = true; + mOptions->MouseShortcutsDefault = false; +} + +void lcQPreferencesDialog::on_MouseExportButton_clicked() +{ + QString FileName = QFileDialog::getSaveFileName(this, tr("Export Shortcuts"), "", tr("Text Files (*.txt);;All Files (*.*)")); + + if (FileName.isEmpty()) + return; + + if (!mOptions->MouseShortcuts.Save(FileName)) + QMessageBox::warning(this, "LeoCAD", tr("Error saving mouse shortcuts file.")); +} + void lcQPreferencesDialog::on_mouseReset_clicked() { if (QMessageBox::question(this, "LeoCAD", tr("Are you sure you want to load the default mouse shortcuts?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) diff --git a/qt/lc_qpreferencesdialog.h b/qt/lc_qpreferencesdialog.h index 6e786e5d..922dbd48 100644 --- a/qt/lc_qpreferencesdialog.h +++ b/qt/lc_qpreferencesdialog.h @@ -59,6 +59,8 @@ public slots: void on_KeyboardFilterEdit_textEdited(const QString& Text); void on_mouseAssign_clicked(); void on_mouseRemove_clicked(); + void on_MouseImportButton_clicked(); + void on_MouseExportButton_clicked(); void on_mouseReset_clicked(); void on_studLogo_toggled(); void MouseTreeItemChanged(QTreeWidgetItem* Current); diff --git a/qt/lc_qpreferencesdialog.ui b/qt/lc_qpreferencesdialog.ui index 1025483d..4b36eb84 100644 --- a/qt/lc_qpreferencesdialog.ui +++ b/qt/lc_qpreferencesdialog.ui @@ -1168,6 +1168,20 @@ + + + + Import... + + + + + + + Export... + + + @@ -1390,6 +1404,8 @@ shortcutAssign shortcutRemove mouseTree + MouseImportButton + MouseExportButton mouseReset mouseButton mouseControl