22 bool VuoKeyComboBox::isPairOfItemsSorted(pair<QString, QVariant> item1, pair<QString, QVariant> item2)
24 if (item1.first == item2.first)
27 QString texts[] = { item1.first, item2.first };
29 for (
int i = 0; i < 2; ++i)
35 else if (texts[i].length() == 1)
37 QRegExp numberCheck(
"\\d");
38 if (numberCheck.exactMatch(texts[i]))
42 QRegExp punctuationCheck(
"[=\\-\\]\\[';\\\\,/.`]");
43 if (punctuationCheck.exactMatch(texts[i]))
44 groups[i] = Punctuation;
51 if (texts[i].endsWith(
"Arrow"))
53 else if (texts[i].startsWith(
"Keypad"))
57 QRegExp fKeyCheck(
"F\\d\\d?");
58 if (fKeyCheck.exactMatch(texts[i]))
61 groups[i] = OtherKeys;
66 if (groups[0] != groups[1])
67 return groups[0] < groups[1];
69 if (groups[0] == Numbers)
71 int n1 = texts[0].toInt();
72 int n2 = texts[1].toInt();
80 if (groups[0] == FKeys)
82 int n1 = texts[0].mid(1).toInt();
83 int n2 = texts[1].mid(1).toInt();
87 return texts[0] < texts[1];
96 view()->installEventFilter(
this);
98 vector<pair<QString, QVariant>> itemTextAndData;
99 for (
int i = VuoKey_Any; i <= VuoKey_Kana; ++i)
103 QString summaryAsUnicode = QString::fromUtf8(summary);
104 itemTextAndData.push_back(make_pair(summaryAsUnicode, key));
108 sort(itemTextAndData.begin(), itemTextAndData.end(), isPairOfItemsSorted);
110 for (vector<pair<QString, QVariant>>::iterator i = itemTextAndData.begin(); i != itemTextAndData.end(); ++i)
112 addItem(i->first, i->second);
121 int index = findData(key);
123 setCurrentIndex(index);
131 QVariant currentKeyAsData = itemData(currentIndex());
132 return (
VuoKey)currentKeyAsData.toInt();
140 if ((e->nativeVirtualKey() == 0 && e->text().isEmpty()) || e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter || e->key() == Qt::Key_Escape)
142 QComboBox::keyPressEvent(e);
156 if (e->type() == QEvent::KeyPress)
158 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(e);
160 QModelIndex index = model()->index(currentIndex(), 0);
161 ((QAbstractItemView *)
object)->setCurrentIndex(index);