Added option to import/export mouse shortcuts. Fixes #490.

This commit is contained in:
Leonardo Zide 2020-08-22 18:47:03 -07:00
parent 0828fd1e2c
commit 8958e822a0
5 changed files with 90 additions and 0 deletions

View file

@ -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));

View file

@ -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

View file

@ -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)

View file

@ -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);

View file

@ -1168,6 +1168,20 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QPushButton" name="MouseImportButton">
<property name="text">
<string>Import...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="MouseExportButton">
<property name="text">
<string>Export...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mouseReset">
<property name="text">
@ -1390,6 +1404,8 @@
<tabstop>shortcutAssign</tabstop>
<tabstop>shortcutRemove</tabstop>
<tabstop>mouseTree</tabstop>
<tabstop>MouseImportButton</tabstop>
<tabstop>MouseExportButton</tabstop>
<tabstop>mouseReset</tabstop>
<tabstop>mouseButton</tabstop>
<tabstop>mouseControl</tabstop>