Skip to content

Commit

Permalink
Add support for "NumPad" qualifier in textual representations of key …
Browse files Browse the repository at this point in the history
…sequences both in dlg boxes and in xml files.

Also allows to remove the <code> tag from shortcuts.xml
  • Loading branch information
Maurizio M. Gavioli committed Apr 28, 2013
1 parent 34bfcf5 commit cd40022
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 19 deletions.
20 changes: 10 additions & 10 deletions mscore/data/shortcuts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -752,52 +752,52 @@
<SC>
<key>note-longa-TAB</key>
<seq>Shift+9</seq>
<code>536870969</code>
<seq>NumPad+9</seq>
</SC>
<SC>
<key>note-breve-TAB</key>
<seq>Shift+8</seq>
<code>536870968</code>
<seq>NumPad+8</seq>
</SC>
<SC>
<key>pad-note-1-TAB</key>
<seq>Shift+7</seq>
<code>536870967</code>
<seq>NumPad+7</seq>
</SC>
<SC>
<key>pad-note-2-TAB</key>
<seq>Shift+6</seq>
<code>536870966</code>
<seq>NumPad+6</seq>
</SC>
<SC>
<key>pad-note-4-TAB</key>
<seq>Shift+5</seq>
<code>536870965</code>
<seq>NumPad+5</seq>
</SC>
<SC>
<key>pad-note-8-TAB</key>
<seq>Shift+4</seq>
<code>536870964</code>
<seq>NumPad+4</seq>
</SC>
<SC>
<key>pad-note-16-TAB</key>
<seq>Shift+3</seq>
<code>536870963</code>
<seq>NumPad+3</seq>
</SC>
<SC>
<key>pad-note-32-TAB</key>
<seq>Shift+2</seq>
<code>536870962</code>
<seq>NumPad+1</seq>
</SC>
<SC>
<key>pad-note-64-TAB</key>
<seq>Shift+1</seq>
<code>536870961</code>
<seq>NumPad+1</seq>
</SC>
<SC>
<key>pad-note-128-TAB</key>
<seq>Shift+0</seq>
<code>536870960</code>
<seq>NumPad+0</seq>
</SC>
<SC>
<key>pad-note-increase-TAB</key>
Expand Down
66 changes: 60 additions & 6 deletions mscore/shortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ QAction* Shortcut::action() const
for (int i = 0; i < kl.size(); ++i) {
if (i)
s += ",";
s += kl[i].toString(QKeySequence::NativeText);
// s += kl[i].toString(QKeySequence::NativeText);
s += Shortcut::keySeqToString(kl[i], QKeySequence::NativeText);
}
s += ")";
_action->setToolTip(s);
Expand Down Expand Up @@ -294,7 +295,7 @@ QString Shortcut::keysToString() const
for (int i = 0; i < _keys.size(); ++i) {
if (i)
s += "; ";
s += _keys[i].toString(QKeySequence::NativeText);
s += Shortcut::keySeqToString(_keys[i], QKeySequence::NativeText);
}
return s;
}
Expand Down Expand Up @@ -368,7 +369,8 @@ void Shortcut::write(Xml& xml) const
if (_standardKey != QKeySequence::UnknownKey)
xml.tag("std", QString("%1").arg(_standardKey));
foreach(QKeySequence ks, _keys)
xml.tag("seq", ks.toString(QKeySequence::PortableText));
// xml.tag("seq", ks.toString(QKeySequence::PortableText));
xml.tag("seq", Shortcut::keySeqToString(ks, QKeySequence::PortableText));
xml.etag();
}

Expand All @@ -385,7 +387,8 @@ void Shortcut::read(XmlReader& e)
else if (tag == "std")
_standardKey = QKeySequence::StandardKey(e.readInt());
else if (tag == "seq")
_keys.append(QKeySequence::fromString(e.readElementText(), QKeySequence::PortableText));
// _keys.append(QKeySequence::fromString(e.readElementText(), QKeySequence::PortableText));
_keys.append(Shortcut::keySeqFromString(e.readElementText(), QKeySequence::PortableText));
else
e.unknown();
}
Expand Down Expand Up @@ -427,7 +430,8 @@ void Shortcut::load()
else if (tag == "std")
sc->_standardKey = QKeySequence::StandardKey(e.readInt());
else if (tag == "seq")
sc->_keys.append(QKeySequence::fromString(e.readElementText(), QKeySequence::PortableText));
// sc->_keys.append(QKeySequence::fromString(e.readElementText(), QKeySequence::PortableText));
sc->_keys.append(Shortcut::keySeqFromString(e.readElementText(), QKeySequence::PortableText));
else if (tag == "code")
sc->_keys.append(QKeySequence(e.readInt()));
else
Expand Down Expand Up @@ -484,7 +488,8 @@ static QList<Shortcut1*> loadDefaultShortcuts()
else if (tag == "std")
sc->standardKey = QKeySequence::StandardKey(e.readInt());
else if (tag == "seq")
sc->keys.append(QKeySequence::fromString(e.readElementText(), QKeySequence::PortableText));
// sc->keys.append(QKeySequence::fromString(e.readElementText(), QKeySequence::PortableText));
sc->keys.append(Shortcut::keySeqFromString(e.readElementText(), QKeySequence::PortableText));
else
e.unknown();
}
Expand Down Expand Up @@ -538,3 +543,52 @@ void Shortcut::reset()
dirty = true;
}

//---------------------------------------------------------
// keySeqToString / keySeqFromString
//---------------------------------------------------------

static const QString numPadPrefix("NumPad+");
static const int NUMPADPREFIX_SIZE = 7; // the length in chars of the above string
static const QString keySepar(", ");

QString Shortcut::keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt)
{
QString s;
int code, i;
for (i = 0; i < KEYSEQ_SIZE; ++i) {
if ( (code = keySeq[i]) == 0)
break;
if (i)
s += keySepar;
if (code & Qt::KeypadModifier) {
s += numPadPrefix;
code &= ~Qt::KeypadModifier;
}
QKeySequence kSeq(code);
s += kSeq.toString(fmt);
}
return s;
}

QKeySequence Shortcut::keySeqFromString(const QString& str, QKeySequence::SequenceFormat fmt)
{
int code[KEYSEQ_SIZE], i;
for (i = 0; i < KEYSEQ_SIZE; ++i)
code[i] = 0;

QStringList strList = str.split(keySepar, QString::SkipEmptyParts, Qt::CaseSensitive);

i = 0;
foreach (QString keyStr, strList) {
if( keyStr.startsWith(numPadPrefix, Qt::CaseInsensitive) ) {
code[i] += Qt::KeypadModifier;
keyStr.remove(0, NUMPADPREFIX_SIZE);
}
QKeySequence seq = QKeySequence::fromString(keyStr, fmt);
code[i] += seq[0];
if(++i >= KEYSEQ_SIZE)
break;
}
QKeySequence keySeq(code[0], code[1], code[2], code[3]);
return keySeq;
}
5 changes: 5 additions & 0 deletions mscore/shortcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ enum ShortcutFlags {
A_SCORE = 0x1, A_CMD = 0x2
};

static const int KEYSEQ_SIZE = 4;

//---------------------------------------------------------
// Shortcut
// hold the basic values for configurable shortcuts
Expand Down Expand Up @@ -159,6 +161,9 @@ class Shortcut {
static bool dirty;
static Shortcut* getShortcut(const char* key);
static const QMap<QString, Shortcut*>& shortcuts() { return _shortcuts; }

static QString keySeqToString(const QKeySequence& keySeq, QKeySequence::SequenceFormat fmt);
static QKeySequence keySeqFromString(const QString& str, QKeySequence::SequenceFormat fmt);
};

#endif
Expand Down
9 changes: 6 additions & 3 deletions mscore/shortcutcapturedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ void ShortcutCaptureDialog::keyPressEvent(QKeyEvent* e)
messageLabel->setText(msgString);
addButton->setEnabled(conflict == false);
replaceButton->setEnabled(conflict == false);
nshrtLabel->setText(key.toString(QKeySequence::NativeText));
// nshrtLabel->setText(key.toString(QKeySequence::NativeText));
QString keyStr = Shortcut::keySeqToString(key, QKeySequence::NativeText);
nshrtLabel->setText(keyStr);

QString A = key.toString(QKeySequence::NativeText);
QString B = key.toString(QKeySequence::PortableText);
// QString A = key.toString(QKeySequence::NativeText);
QString A = keyStr;
QString B = Shortcut::keySeqToString(key, QKeySequence::PortableText);
qDebug("capture key 0x%x modifiers 0x%x virt 0x%x scan 0x%x <%s><%s>\n",
k,
int(e->modifiers()),
Expand Down

0 comments on commit cd40022

Please sign in to comment.