mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Added option for alternate mouse shortcuts with defaults that match LDD.
This commit is contained in:
parent
42e63cace2
commit
f5f98994bb
4 changed files with 128 additions and 49 deletions
|
@ -131,14 +131,24 @@ bool lcKeyboardShortcuts::Load(QTextStream& Stream)
|
||||||
void lcMouseShortcuts::Reset()
|
void lcMouseShortcuts::Reset()
|
||||||
{
|
{
|
||||||
memset(mShortcuts, 0, sizeof(mShortcuts));
|
memset(mShortcuts, 0, sizeof(mShortcuts));
|
||||||
mShortcuts[LC_TOOL_ROTATE_VIEW].Modifiers = Qt::AltModifier;
|
|
||||||
mShortcuts[LC_TOOL_ROTATE_VIEW].Button = Qt::LeftButton;
|
mShortcuts[LC_TOOL_ROTATE_VIEW].Modifiers1 = Qt::AltModifier;
|
||||||
|
mShortcuts[LC_TOOL_ROTATE_VIEW].Button1 = Qt::LeftButton;
|
||||||
|
mShortcuts[LC_TOOL_ROTATE_VIEW].Modifiers2 = Qt::NoModifier;
|
||||||
|
mShortcuts[LC_TOOL_ROTATE_VIEW].Button2 = Qt::RightButton;
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
|
||||||
mShortcuts[LC_TOOL_PAN].Modifiers = Qt::AltModifier;
|
mShortcuts[LC_TOOL_PAN].Modifiers1 = Qt::AltModifier;
|
||||||
mShortcuts[LC_TOOL_PAN].Button = Qt::MiddleButton;
|
mShortcuts[LC_TOOL_PAN].Button1 = Qt::MiddleButton;
|
||||||
|
mShortcuts[LC_TOOL_PAN].Modifiers2 = Qt::ShiftModifier;
|
||||||
|
mShortcuts[LC_TOOL_PAN].Button2 = Qt::RightButton;
|
||||||
|
#else
|
||||||
|
mShortcuts[LC_TOOL_PAN].Modifiers1 = Qt::ShiftModifier;
|
||||||
|
mShortcuts[LC_TOOL_PAN].Button1 = Qt::RightButton;
|
||||||
#endif
|
#endif
|
||||||
mShortcuts[LC_TOOL_ZOOM].Modifiers = Qt::AltModifier;
|
|
||||||
mShortcuts[LC_TOOL_ZOOM].Button = Qt::RightButton;
|
mShortcuts[LC_TOOL_ZOOM].Modifiers1 = Qt::AltModifier;
|
||||||
|
mShortcuts[LC_TOOL_ZOOM].Button1 = Qt::RightButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lcMouseShortcuts::Save(QStringList& Shortcuts)
|
bool lcMouseShortcuts::Save(QStringList& Shortcuts)
|
||||||
|
@ -147,14 +157,22 @@ bool lcMouseShortcuts::Save(QStringList& Shortcuts)
|
||||||
|
|
||||||
for (int ToolIdx = 0; ToolIdx < LC_NUM_TOOLS; ToolIdx++)
|
for (int ToolIdx = 0; ToolIdx < LC_NUM_TOOLS; ToolIdx++)
|
||||||
{
|
{
|
||||||
int ButtonIndex = 0;
|
int ButtonIndex1 = 0;
|
||||||
for (int Button = mShortcuts[ToolIdx].Button; Button; Button >>= 1)
|
for (int Button1 = mShortcuts[ToolIdx].Button1; Button1; Button1 >>= 1)
|
||||||
ButtonIndex++;
|
ButtonIndex1++;
|
||||||
|
|
||||||
if (!ButtonIndex)
|
if (!ButtonIndex1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QString Shortcut = QKeySequence(mShortcuts[ToolIdx].Modifiers | (Qt::Key_0 + ButtonIndex)).toString(QKeySequence::PortableText);
|
QString Shortcut = QKeySequence(mShortcuts[ToolIdx].Modifiers1 | (Qt::Key_0 + ButtonIndex1)).toString(QKeySequence::PortableText);
|
||||||
|
|
||||||
|
int ButtonIndex2 = 0;
|
||||||
|
for (int Button2 = mShortcuts[ToolIdx].Button2; Button2; Button2 >>= 1)
|
||||||
|
ButtonIndex2++;
|
||||||
|
|
||||||
|
if (ButtonIndex2)
|
||||||
|
Shortcut += ',' + QKeySequence(mShortcuts[ToolIdx].Modifiers2 | (Qt::Key_0 + ButtonIndex2)).toString(QKeySequence::PortableText);
|
||||||
|
|
||||||
Shortcuts << QString::fromLatin1(gToolNames[ToolIdx]) + QLatin1String("=") + Shortcut;
|
Shortcuts << QString::fromLatin1(gToolNames[ToolIdx]) + QLatin1String("=") + Shortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,14 +200,32 @@ bool lcMouseShortcuts::Load(const QStringList& Shortcuts)
|
||||||
if (ToolIdx == LC_NUM_TOOLS)
|
if (ToolIdx == LC_NUM_TOOLS)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
QStringList Shortcuts = Shortcut.mid(Equals + 1).split(',');
|
||||||
|
bool AddedShortcut = false;
|
||||||
|
|
||||||
|
for (const QString& Shortcut : Shortcuts)
|
||||||
|
{
|
||||||
QKeySequence KeySequence(Shortcut.mid(Equals + 1));
|
QKeySequence KeySequence(Shortcut.mid(Equals + 1));
|
||||||
|
|
||||||
if (KeySequence.isEmpty())
|
if (KeySequence.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int ShortcutKey = KeySequence[0];
|
int ShortcutKey = KeySequence[0];
|
||||||
mShortcuts[ToolIdx].Modifiers = (Qt::KeyboardModifier)(ShortcutKey & Qt::KeyboardModifierMask);
|
Qt::KeyboardModifiers Modifiers = (Qt::KeyboardModifier)(ShortcutKey & Qt::KeyboardModifierMask);
|
||||||
mShortcuts[ToolIdx].Button = (Qt::MouseButton)(1 << ((ShortcutKey & ~Qt::KeyboardModifierMask) - Qt::Key_0 - 1));
|
Qt::MouseButton Button = (Qt::MouseButton)(1 << ((ShortcutKey & ~Qt::KeyboardModifierMask) - Qt::Key_0 - 1));
|
||||||
|
|
||||||
|
if (!AddedShortcut)
|
||||||
|
{
|
||||||
|
mShortcuts[ToolIdx].Modifiers1 = Modifiers;
|
||||||
|
mShortcuts[ToolIdx].Button1 = Button;
|
||||||
|
AddedShortcut = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mShortcuts[ToolIdx].Modifiers2 = Modifiers;
|
||||||
|
mShortcuts[ToolIdx].Button2 = Button;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -198,7 +234,7 @@ bool lcMouseShortcuts::Load(const QStringList& Shortcuts)
|
||||||
lcTool lcMouseShortcuts::GetTool(Qt::MouseButton Button, Qt::KeyboardModifiers Modifiers) const
|
lcTool lcMouseShortcuts::GetTool(Qt::MouseButton Button, Qt::KeyboardModifiers Modifiers) const
|
||||||
{
|
{
|
||||||
for (int ToolIdx = 0; ToolIdx < LC_NUM_TOOLS; ToolIdx++)
|
for (int ToolIdx = 0; ToolIdx < LC_NUM_TOOLS; ToolIdx++)
|
||||||
if (mShortcuts[ToolIdx].Button == Button && mShortcuts[ToolIdx].Modifiers == Modifiers)
|
if ((mShortcuts[ToolIdx].Button1 == Button && mShortcuts[ToolIdx].Modifiers1 == Modifiers) || (mShortcuts[ToolIdx].Button2 == Button && mShortcuts[ToolIdx].Modifiers2 == Modifiers))
|
||||||
return (lcTool)ToolIdx;
|
return (lcTool)ToolIdx;
|
||||||
|
|
||||||
return LC_NUM_TOOLS;
|
return LC_NUM_TOOLS;
|
||||||
|
|
|
@ -31,8 +31,10 @@ public:
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
Qt::KeyboardModifiers Modifiers;
|
Qt::KeyboardModifiers Modifiers1;
|
||||||
Qt::MouseButton Button;
|
Qt::MouseButton Button1;
|
||||||
|
Qt::KeyboardModifiers Modifiers2;
|
||||||
|
Qt::MouseButton Button2;
|
||||||
}
|
}
|
||||||
mShortcuts[LC_NUM_TOOLS];
|
mShortcuts[LC_NUM_TOOLS];
|
||||||
};
|
};
|
||||||
|
|
|
@ -71,7 +71,15 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget *parent, void *data) :
|
||||||
commandChanged(nullptr);
|
commandChanged(nullptr);
|
||||||
|
|
||||||
UpdateMouseTree();
|
UpdateMouseTree();
|
||||||
new lcQTreeWidgetColumnStretcher(ui->mouseTree, 0);
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||||
|
ui->mouseTree->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||||
|
ui->mouseTree->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||||
|
ui->mouseTree->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||||
|
#else
|
||||||
|
ui->mouseTree->header()->setResizeMode(0, QHeaderView::Stretch);
|
||||||
|
ui->mouseTree->header()->setResizeMode(1, QHeaderView::ResizeToContents);
|
||||||
|
ui->mouseTree->header()->setResizeMode(2, QHeaderView::ResizeToContents);
|
||||||
|
#endif
|
||||||
MouseTreeItemChanged(nullptr);
|
MouseTreeItemChanged(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,8 +613,9 @@ void lcQPreferencesDialog::UpdateMouseTree()
|
||||||
|
|
||||||
void lcQPreferencesDialog::UpdateMouseTreeItem(int ItemIndex)
|
void lcQPreferencesDialog::UpdateMouseTreeItem(int ItemIndex)
|
||||||
{
|
{
|
||||||
Qt::MouseButton Button = options->MouseShortcuts.mShortcuts[ItemIndex].Button;
|
auto GetShortcutText = [](Qt::MouseButton Button, Qt::KeyboardModifiers Modifiers)
|
||||||
QString Shortcut = QKeySequence(options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers).toString(QKeySequence::NativeText);
|
{
|
||||||
|
QString Shortcut = QKeySequence(Modifiers).toString(QKeySequence::NativeText);
|
||||||
|
|
||||||
switch (Button)
|
switch (Button)
|
||||||
{
|
{
|
||||||
|
@ -627,13 +636,21 @@ void lcQPreferencesDialog::UpdateMouseTreeItem(int ItemIndex)
|
||||||
default:
|
default:
|
||||||
Shortcut.clear();
|
Shortcut.clear();
|
||||||
}
|
}
|
||||||
|
return Shortcut;
|
||||||
|
};
|
||||||
|
|
||||||
|
QString Shortcut1 = GetShortcutText(options->MouseShortcuts.mShortcuts[ItemIndex].Button1, options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers1);
|
||||||
|
QString Shortcut2 = GetShortcutText(options->MouseShortcuts.mShortcuts[ItemIndex].Button2, options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers2);
|
||||||
|
|
||||||
QTreeWidgetItem* Item = ui->mouseTree->topLevelItem(ItemIndex);
|
QTreeWidgetItem* Item = ui->mouseTree->topLevelItem(ItemIndex);
|
||||||
|
|
||||||
if (Item)
|
if (Item)
|
||||||
Item->setText(1, Shortcut);
|
{
|
||||||
|
Item->setText(1, Shortcut1);
|
||||||
|
Item->setText(2, Shortcut2);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
new QTreeWidgetItem(ui->mouseTree, QStringList() << tr(gToolNames[ItemIndex]) << Shortcut);
|
new QTreeWidgetItem(ui->mouseTree, QStringList() << tr(gToolNames[ItemIndex]) << Shortcut1 << Shortcut2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcQPreferencesDialog::on_mouseAssign_clicked()
|
void lcQPreferencesDialog::on_mouseAssign_clicked()
|
||||||
|
@ -677,20 +694,36 @@ void lcQPreferencesDialog::on_mouseAssign_clicked()
|
||||||
|
|
||||||
for (int ToolIdx = 0; ToolIdx < LC_NUM_TOOLS; ToolIdx++)
|
for (int ToolIdx = 0; ToolIdx < LC_NUM_TOOLS; ToolIdx++)
|
||||||
{
|
{
|
||||||
if (ToolIdx != ButtonIndex && options->MouseShortcuts.mShortcuts[ToolIdx].Button == Button && options->MouseShortcuts.mShortcuts[ToolIdx].Modifiers == Modifiers)
|
if (ToolIdx == ButtonIndex)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (options->MouseShortcuts.mShortcuts[ToolIdx].Button2 == Button && options->MouseShortcuts.mShortcuts[ToolIdx].Modifiers2 == Modifiers)
|
||||||
{
|
{
|
||||||
if (QMessageBox::question(this, tr("Override Shortcut"), tr("This shortcut is already assigned to '%1', do you want to replace it?").arg(tr(gToolNames[ToolIdx])), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
if (QMessageBox::question(this, tr("Override Shortcut"), tr("This shortcut is already assigned to '%1', do you want to replace it?").arg(tr(gToolNames[ToolIdx])), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
options->MouseShortcuts.mShortcuts[ToolIdx].Button = Qt::NoButton;
|
options->MouseShortcuts.mShortcuts[ToolIdx].Button2 = Qt::NoButton;
|
||||||
options->MouseShortcuts.mShortcuts[ToolIdx].Modifiers = Qt::NoModifier;
|
options->MouseShortcuts.mShortcuts[ToolIdx].Modifiers2 = Qt::NoModifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options->MouseShortcuts.mShortcuts[ToolIdx].Button1 == Button && options->MouseShortcuts.mShortcuts[ToolIdx].Modifiers1 == Modifiers)
|
||||||
|
{
|
||||||
|
if (QMessageBox::question(this, tr("Override Shortcut"), tr("This shortcut is already assigned to '%1', do you want to replace it?").arg(tr(gToolNames[ToolIdx])), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
|
||||||
|
return;
|
||||||
|
|
||||||
|
options->MouseShortcuts.mShortcuts[ToolIdx].Button1 = options->MouseShortcuts.mShortcuts[ToolIdx].Button2;
|
||||||
|
options->MouseShortcuts.mShortcuts[ToolIdx].Modifiers1 = options->MouseShortcuts.mShortcuts[ToolIdx].Modifiers2;
|
||||||
|
options->MouseShortcuts.mShortcuts[ToolIdx].Button2 = Qt::NoButton;
|
||||||
|
options->MouseShortcuts.mShortcuts[ToolIdx].Modifiers2 = Qt::NoModifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemIndex = ui->mouseTree->indexOfTopLevelItem(Current);
|
int ItemIndex = ui->mouseTree->indexOfTopLevelItem(Current);
|
||||||
options->MouseShortcuts.mShortcuts[ItemIndex].Button = Button;
|
options->MouseShortcuts.mShortcuts[ItemIndex].Button2 = options->MouseShortcuts.mShortcuts[ItemIndex].Button1;
|
||||||
options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers = Modifiers;
|
options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers2 = options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers1;
|
||||||
|
options->MouseShortcuts.mShortcuts[ItemIndex].Button1 = Button;
|
||||||
|
options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers1 = Modifiers;
|
||||||
|
|
||||||
options->MouseShortcutsModified = true;
|
options->MouseShortcutsModified = true;
|
||||||
options->MouseShortcutsDefault = false;
|
options->MouseShortcutsDefault = false;
|
||||||
|
@ -706,13 +739,16 @@ void lcQPreferencesDialog::on_mouseRemove_clicked()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int ItemIndex = ui->mouseTree->indexOfTopLevelItem(Current);
|
int ItemIndex = ui->mouseTree->indexOfTopLevelItem(Current);
|
||||||
options->MouseShortcuts.mShortcuts[ItemIndex].Button = Qt::NoButton;
|
options->MouseShortcuts.mShortcuts[ItemIndex].Button1 = options->MouseShortcuts.mShortcuts[ItemIndex].Button2;
|
||||||
options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers = Qt::NoModifier;
|
options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers1 = options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers2;
|
||||||
|
options->MouseShortcuts.mShortcuts[ItemIndex].Button2 = Qt::NoButton;
|
||||||
|
options->MouseShortcuts.mShortcuts[ItemIndex].Modifiers2 = Qt::NoModifier;
|
||||||
|
|
||||||
options->MouseShortcutsModified = true;
|
options->MouseShortcutsModified = true;
|
||||||
options->MouseShortcutsDefault = false;
|
options->MouseShortcutsDefault = false;
|
||||||
|
|
||||||
UpdateMouseTreeItem(ItemIndex);
|
UpdateMouseTreeItem(ItemIndex);
|
||||||
|
MouseTreeItemChanged(Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcQPreferencesDialog::on_mouseReset_clicked()
|
void lcQPreferencesDialog::on_mouseReset_clicked()
|
||||||
|
@ -739,7 +775,7 @@ void lcQPreferencesDialog::MouseTreeItemChanged(QTreeWidgetItem* Current)
|
||||||
|
|
||||||
int ToolIndex = ui->mouseTree->indexOfTopLevelItem(Current);
|
int ToolIndex = ui->mouseTree->indexOfTopLevelItem(Current);
|
||||||
|
|
||||||
Qt::MouseButton Button = options->MouseShortcuts.mShortcuts[ToolIndex].Button;
|
Qt::MouseButton Button = options->MouseShortcuts.mShortcuts[ToolIndex].Button1;
|
||||||
|
|
||||||
switch (Button)
|
switch (Button)
|
||||||
{
|
{
|
||||||
|
@ -762,7 +798,7 @@ void lcQPreferencesDialog::MouseTreeItemChanged(QTreeWidgetItem* Current)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::KeyboardModifiers Modifiers = options->MouseShortcuts.mShortcuts[ToolIndex].Modifiers;
|
Qt::KeyboardModifiers Modifiers = options->MouseShortcuts.mShortcuts[ToolIndex].Modifiers1;
|
||||||
ui->mouseControl->setChecked((Modifiers & Qt::ControlModifier) != 0);
|
ui->mouseControl->setChecked((Modifiers & Qt::ControlModifier) != 0);
|
||||||
ui->mouseShift->setChecked((Modifiers & Qt::ShiftModifier) != 0);
|
ui->mouseShift->setChecked((Modifiers & Qt::ShiftModifier) != 0);
|
||||||
ui->mouseAlt->setChecked((Modifiers & Qt::AltModifier) != 0);
|
ui->mouseAlt->setChecked((Modifiers & Qt::AltModifier) != 0);
|
||||||
|
|
|
@ -652,7 +652,12 @@
|
||||||
</column>
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Shortcut</string>
|
<string>Shortcut 1</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Shortcut 2</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Reference in a new issue