diff options
Diffstat (limited to 'src/actionseditor.cpp')
-rw-r--r-- | src/actionseditor.cpp | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/actionseditor.cpp b/src/actionseditor.cpp index aa64a1f..5f6d748 100644 --- a/src/actionseditor.cpp +++ b/src/actionseditor.cpp @@ -102,13 +102,15 @@ QString ActionsEditor::shortcutsToString(QList <QKeySequence> shortcuts_list) { if (n < (shortcuts_list.count()-1)) accelText += ", "; } + //qDebug("ActionsEditor::shortcutsToString: accelText: '%s'", accelText.toUtf8().constData()); + return accelText; } QList <QKeySequence> ActionsEditor::stringToShortcuts(QString shortcuts) { QList <QKeySequence> shortcuts_list; - QStringList l = shortcuts.split(','); + QStringList l = shortcuts.split(", "); for (int n=0; n < l.count(); n++) { //qDebug("%s", l[n].toUtf8().data()); @@ -120,7 +122,7 @@ QList <QKeySequence> ActionsEditor::stringToShortcuts(QString shortcuts) { #else QString s = QKeySequence( l[n].simplified() ); #endif - + //Work-around for Simplified-Chinese s.replace( QString::fromUtf8("左"), "Left"); s.replace( QString::fromUtf8("下"), "Down"); @@ -371,7 +373,8 @@ void ActionsEditor::editShortcut() { QString result = d.exec( i->text() ); if (!result.isNull()) { - QString accelText = QKeySequence(result).toString(QKeySequence::PortableText); + //qDebug("ActionsEditor::editShortcut: result: '%s'", result.toUtf8().constData()); + QString accelText = QKeySequence(result).toString(QKeySequence::PortableText); i->setText(accelText); if (hasConflicts()) qApp->beep(); } @@ -386,13 +389,31 @@ int ActionsEditor::findActionName(const QString & name) { return -1; } +bool ActionsEditor::containsShortcut(const QString & accel, const QString & shortcut) { + QStringList shortcut_list = accel.split(", "); + QString s; + foreach(s, shortcut_list) { + s = s.trimmed(); + //qDebug("ActionsEditor::containsShortcut: comparing '%s' with '%s'", s.toUtf8().constData(), shortcut.toUtf8().constData()); + if (s == shortcut) return true; + } + return false; +} + int ActionsEditor::findActionAccel(const QString & accel, int ignoreRow) { - for (int row=0; row < actionsTable->rowCount(); row++) { + QStringList shortcuts = accel.split(", "); + QString shortcut; + + for (int row = 0; row < actionsTable->rowCount(); row++) { QTableWidgetItem * i = actionsTable->item(row, COL_SHORTCUT); - if ( (i) && (i->text() == accel) ) { - if (ignoreRow == -1) return row; - else - if (ignoreRow != row) return row; + if (i && row != ignoreRow) { + if (!i->text().isEmpty()) { + foreach(shortcut, shortcuts) { + if (containsShortcut(i->text(), shortcut.trimmed())) { + return row; + } + } + } } } return -1; @@ -405,7 +426,7 @@ bool ActionsEditor::hasConflicts() { QString accelText; QTableWidgetItem *i; - for (int n=0; n < actionsTable->rowCount(); n++) { + for (int n = 0; n < actionsTable->rowCount(); n++) { //actionsTable->setText( n, COL_CONFLICTS, " "); i = actionsTable->item( n, COL_CONFLICTS ); if (i) i->setIcon( QPixmap() ); @@ -415,7 +436,7 @@ bool ActionsEditor::hasConflicts() { accelText = i->text(); if (!accelText.isEmpty()) { found = findActionAccel( accelText, n ); - if ( (found != -1) && (found != n) ) { + if ( (found != -1) /*&& (found != n)*/ ) { conflict = true; //actionsTable->setText( n, COL_CONFLICTS, "!"); actionsTable->item( n, COL_CONFLICTS )->setIcon( Images::icon("conflict") ); |