mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Added option to import/export mouse shortcuts. Fixes #490.
This commit is contained in:
parent
0828fd1e2c
commit
8958e822a0
5 changed files with 90 additions and 0 deletions
|
@ -151,6 +151,27 @@ void lcMouseShortcuts::Reset()
|
||||||
mShortcuts[LC_TOOL_ZOOM].Button1 = Qt::RightButton;
|
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)
|
bool lcMouseShortcuts::Save(QStringList& Shortcuts)
|
||||||
{
|
{
|
||||||
Shortcuts.clear();
|
Shortcuts.clear();
|
||||||
|
@ -179,6 +200,22 @@ bool lcMouseShortcuts::Save(QStringList& Shortcuts)
|
||||||
return true;
|
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)
|
bool lcMouseShortcuts::Load(const QStringList& FullShortcuts)
|
||||||
{
|
{
|
||||||
memset(mShortcuts, 0, sizeof(mShortcuts));
|
memset(mShortcuts, 0, sizeof(mShortcuts));
|
||||||
|
|
|
@ -24,8 +24,11 @@ class lcMouseShortcuts
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Reset();
|
void Reset();
|
||||||
|
bool Save(const QString& FileName);
|
||||||
bool Save(QStringList& Shortcuts);
|
bool Save(QStringList& Shortcuts);
|
||||||
|
bool Load(const QString& FileName);
|
||||||
bool Load(const QStringList& Shortcuts);
|
bool Load(const QStringList& Shortcuts);
|
||||||
|
|
||||||
lcTool GetTool(Qt::MouseButton Button, Qt::KeyboardModifiers Modifiers) const;
|
lcTool GetTool(Qt::MouseButton Button, Qt::KeyboardModifiers Modifiers) const;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
|
|
@ -1054,6 +1054,38 @@ void lcQPreferencesDialog::on_mouseRemove_clicked()
|
||||||
MouseTreeItemChanged(Current);
|
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()
|
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)
|
if (QMessageBox::question(this, "LeoCAD", tr("Are you sure you want to load the default mouse shortcuts?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
|
||||||
|
|
|
@ -59,6 +59,8 @@ public slots:
|
||||||
void on_KeyboardFilterEdit_textEdited(const QString& Text);
|
void on_KeyboardFilterEdit_textEdited(const QString& Text);
|
||||||
void on_mouseAssign_clicked();
|
void on_mouseAssign_clicked();
|
||||||
void on_mouseRemove_clicked();
|
void on_mouseRemove_clicked();
|
||||||
|
void on_MouseImportButton_clicked();
|
||||||
|
void on_MouseExportButton_clicked();
|
||||||
void on_mouseReset_clicked();
|
void on_mouseReset_clicked();
|
||||||
void on_studLogo_toggled();
|
void on_studLogo_toggled();
|
||||||
void MouseTreeItemChanged(QTreeWidgetItem* Current);
|
void MouseTreeItemChanged(QTreeWidgetItem* Current);
|
||||||
|
|
|
@ -1168,6 +1168,20 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
<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>
|
<item>
|
||||||
<widget class="QPushButton" name="mouseReset">
|
<widget class="QPushButton" name="mouseReset">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -1390,6 +1404,8 @@
|
||||||
<tabstop>shortcutAssign</tabstop>
|
<tabstop>shortcutAssign</tabstop>
|
||||||
<tabstop>shortcutRemove</tabstop>
|
<tabstop>shortcutRemove</tabstop>
|
||||||
<tabstop>mouseTree</tabstop>
|
<tabstop>mouseTree</tabstop>
|
||||||
|
<tabstop>MouseImportButton</tabstop>
|
||||||
|
<tabstop>MouseExportButton</tabstop>
|
||||||
<tabstop>mouseReset</tabstop>
|
<tabstop>mouseReset</tabstop>
|
||||||
<tabstop>mouseButton</tabstop>
|
<tabstop>mouseButton</tabstop>
|
||||||
<tabstop>mouseControl</tabstop>
|
<tabstop>mouseControl</tabstop>
|
||||||
|
|
Loading…
Reference in a new issue