[Macro] Use a key catcher line edit to get modifier(s) for recent macros
This commit is contained in:
@@ -336,16 +336,10 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="5" colspan="3">
|
||||
<widget class="Gui::PrefLineEdit" name="ShortcutModifiers">
|
||||
<widget class="Gui::ModifierLineEdit" name="ShortcutModifiers">
|
||||
<property name="toolTip">
|
||||
<string>Keyboard modifiers, default = Ctrl+Shift+</string>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>ShortcutModifiers</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>RecentMacros</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -369,9 +363,9 @@
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::PrefLineEdit</class>
|
||||
<class>Gui::ModifierLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
<header>Gui/Widgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefSpinBox</class>
|
||||
|
||||
@@ -82,7 +82,8 @@ void DlgSettingsMacroImp::saveSettings()
|
||||
ui->FileLogCheckBox->onSave();
|
||||
ui->MacroPath_2->onSave();
|
||||
ui->RecentMacros->onSave();
|
||||
ui->ShortcutModifiers->onSave();
|
||||
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("RecentMacros");
|
||||
hGrp->SetASCII("ShortcutModifiers", qPrintable(ui->ShortcutModifiers->text()));
|
||||
ui->ShortcutCount->onSave();
|
||||
setRecentMacroSize();
|
||||
}
|
||||
@@ -97,7 +98,8 @@ void DlgSettingsMacroImp::loadSettings()
|
||||
ui->FileLogCheckBox->onRestore();
|
||||
ui->MacroPath_2->onRestore();
|
||||
ui->RecentMacros->onRestore();
|
||||
ui->ShortcutModifiers->onRestore();
|
||||
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("RecentMacros");
|
||||
ui->ShortcutModifiers->setText(QString::fromStdString(hGrp->GetASCII("ShortcutModifiers", "Ctrl+Shift+")));
|
||||
ui->ShortcutCount->onRestore();
|
||||
}
|
||||
|
||||
|
||||
@@ -463,6 +463,66 @@ void AccelLineEdit::keyPressEvent ( QKeyEvent * e)
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
/* TRANSLATOR Gui::ModifierLineEdit */
|
||||
|
||||
/**
|
||||
* Constructs a line edit with no text.
|
||||
* The \a parent argument is sent to the QLineEdit constructor.
|
||||
*/
|
||||
ModifierLineEdit::ModifierLineEdit ( QWidget * parent )
|
||||
: QLineEdit(parent)
|
||||
{
|
||||
setPlaceholderText(tr("none"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks which modifiers are pressed and show it as text.
|
||||
*/
|
||||
void ModifierLineEdit::keyPressEvent ( QKeyEvent * e)
|
||||
{
|
||||
int key = e->key();
|
||||
Qt::KeyboardModifiers state = e->modifiers();
|
||||
|
||||
switch(key) {
|
||||
case Qt::Key_Backspace:
|
||||
case Qt::Key_Delete:
|
||||
clear();
|
||||
return;
|
||||
case Qt::Key_Control:
|
||||
case Qt::Key_Shift:
|
||||
case Qt::Key_Alt:
|
||||
case Qt::Key_Meta:
|
||||
break;;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
clear();
|
||||
QString txtLine;
|
||||
|
||||
// Handles modifiers applying a mask.
|
||||
if ((state & Qt::ControlModifier) == Qt::ControlModifier) {
|
||||
QKeySequence ks(Qt::CTRL);
|
||||
txtLine += ks.toString(QKeySequence::NativeText);
|
||||
}
|
||||
if ((state & Qt::AltModifier) == Qt::AltModifier) {
|
||||
QKeySequence ks(Qt::ALT);
|
||||
txtLine += ks.toString(QKeySequence::NativeText);
|
||||
}
|
||||
if ((state & Qt::ShiftModifier) == Qt::ShiftModifier) {
|
||||
QKeySequence ks(Qt::SHIFT);
|
||||
txtLine += ks.toString(QKeySequence::NativeText);
|
||||
}
|
||||
if ((state & Qt::MetaModifier) == Qt::MetaModifier) {
|
||||
QKeySequence ks(Qt::META);
|
||||
txtLine += ks.toString(QKeySequence::NativeText);
|
||||
}
|
||||
|
||||
setText(txtLine);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
#if QT_VERSION >= 0x050200
|
||||
ClearLineEdit::ClearLineEdit (QWidget * parent)
|
||||
: QLineEdit(parent)
|
||||
|
||||
@@ -149,6 +149,22 @@ private:
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The ModifierLineEdit class provides a lineedit to specify modifiers.
|
||||
*/
|
||||
class GuiExport ModifierLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ModifierLineEdit(QWidget * parent=0);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent * e);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The ClearLineEdit class adds a clear button at the right side.
|
||||
* http://stackoverflow.com/questions/21232224/qlineedit-with-custom-button
|
||||
|
||||
Reference in New Issue
Block a user