Fix keysequence strings for Mac again
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 2 Jun 2010 14:18:06 +0000 (16:18 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 2 Jun 2010 14:18:06 +0000 (16:18 +0200)
Qt actually offers QKeySequence::NativeText to do Mac special casing for toString().
So it makes sense to use that. We now also simulate Qt's behavior for modifier names, that is,
on Mac those will be unicode symbols and no '+' is set between keys. Also the order should be
the commonly used one now (I hope).

src/qtui/settingspages/keysequencewidget.cpp
src/qtui/settingspages/shortcutsmodel.cpp
src/qtui/settingspages/shortcutssettingspage.cpp

index b37d98b..169a8f0 100644 (file)
@@ -240,27 +240,22 @@ bool KeySequenceWidget::isShiftAsModifierAllowed(int keyQt) const {
 }
 
 void KeySequenceWidget::updateShortcutDisplay() {
 }
 
 void KeySequenceWidget::updateShortcutDisplay() {
-  // make translators happy
-#if defined(Q_WS_MAC)
-  static QString metaKey = tr("Ctrl", "Ctrl key on Mac");
-  static QString ctrlKey = tr("⌘", "Cmd key on Mac");
-#else
-  static QString metaKey = tr("Meta", "Meta key");
-  static QString ctrlKey = tr("Ctrl", "Ctrl key");
-#endif
-  static QString altKey = tr("Alt", "Alt key");
-  static QString shiftKey = tr("Shift", "Shift key");
-
   QString s = _keySequence.toString(QKeySequence::NativeText);
   s.replace('&', QLatin1String("&&"));
 
   if(_isRecording) {
     if(_modifierKeys) {
   QString s = _keySequence.toString(QKeySequence::NativeText);
   s.replace('&', QLatin1String("&&"));
 
   if(_isRecording) {
     if(_modifierKeys) {
-      if(_modifierKeys & Qt::META)  s += metaKey + '+';
-      if(_modifierKeys & Qt::CTRL)  s += ctrlKey + '+';
-      if(_modifierKeys & Qt::ALT)   s += altKey + '+';
-      if(_modifierKeys & Qt::SHIFT) s += shiftKey + '+';
-
+#ifdef Q_WS_MAC
+      if(_modifierKeys & Qt::META)  s += QChar(kControlUnicode);
+      if(_modifierKeys & Qt::ALT)   s += QChar(kOptionUnicode);
+      if(_modifierKeys & Qt::SHIFT) s += QChar(kShiftUnicode);
+      if(_modifierKeys & Qt::CTRL)  s += QChar(kCommandUnicode);
+#else
+      if(_modifierKeys & Qt::META)  s += tr("Meta", "Meta key") + '+';
+      if(_modifierKeys & Qt::CTRL)  s += tr("Ctrl", "Ctrl key") + '+';
+      if(_modifierKeys & Qt::ALT)   s += tr("Alt", "Alt key") + '+';
+      if(_modifierKeys & Qt::SHIFT) s += tr("Shift", "Shift key") + '+';
+#endif
     } else {
       s = tr("Input", "What the user inputs now will be taken as the new shortcut");
     }
     } else {
       s = tr("Input", "What the user inputs now will be taken as the new shortcut");
     }
@@ -353,7 +348,7 @@ bool KeySequenceWidget::isKeySequenceAvailable(const QKeySequence &seq) {
 
       if(!actIdx.data(ShortcutsModel::IsConfigurableRole).toBool()) {
         QMessageBox::warning(this, tr("Shortcut Conflict"),
 
       if(!actIdx.data(ShortcutsModel::IsConfigurableRole).toBool()) {
         QMessageBox::warning(this, tr("Shortcut Conflict"),
-                             tr("The \"%1\" shortcut is already in use, and cannot be configured.\nPlease choose another one.").arg(seq.toString()),
+                             tr("The \"%1\" shortcut is already in use, and cannot be configured.\nPlease choose another one.").arg(seq.toString(QKeySequence::NativeText)),
                              QMessageBox::Ok);
         return false;
       }
                              QMessageBox::Ok);
         return false;
       }
@@ -362,7 +357,7 @@ bool KeySequenceWidget::isKeySequenceAvailable(const QKeySequence &seq) {
                       (tr("The \"%1\" shortcut is ambiguous with the shortcut for the following action:")
                        + "<br><ul><li>%2</li></ul><br>"
                        + tr("Do you want to reassign this shortcut to the selected action?")
                       (tr("The \"%1\" shortcut is ambiguous with the shortcut for the following action:")
                        + "<br><ul><li>%2</li></ul><br>"
                        + tr("Do you want to reassign this shortcut to the selected action?")
-                       ).arg(seq.toString(), actIdx.data().toString()),
+                       ).arg(seq.toString(QKeySequence::NativeText), actIdx.data().toString()),
                       QMessageBox::Cancel, this);
       box.addButton(tr("Reassign"), QMessageBox::AcceptRole);
       if(box.exec() == QMessageBox::Cancel)
                       QMessageBox::Cancel, this);
       box.addButton(tr("Reassign"), QMessageBox::AcceptRole);
       if(box.exec() == QMessageBox::Cancel)
index f9dcbe2..c1e5d26 100644 (file)
@@ -142,7 +142,7 @@ QVariant ShortcutsModel::data(const QModelIndex &index, int role) const {
     case 0:
       return stripAcceleratorMarkers(action->text());
     case 1:
     case 0:
       return stripAcceleratorMarkers(action->text());
     case 1:
-      return item->shortcut.toString();
+      return item->shortcut.toString(QKeySequence::NativeText);
     default:
       return QVariant();
     }
     default:
       return QVariant();
     }
index 2317a7b..af97445 100644 (file)
@@ -89,7 +89,7 @@ void ShortcutsSettingsPage::setWidgetStates() {
   if(ui.shortcutsView->currentIndex().isValid() && ui.shortcutsView->currentIndex().parent().isValid()) {
     QKeySequence active = ui.shortcutsView->currentIndex().data(ShortcutsModel::ActiveShortcutRole).value<QKeySequence>();
     QKeySequence def = ui.shortcutsView->currentIndex().data(ShortcutsModel::DefaultShortcutRole).value<QKeySequence>();
   if(ui.shortcutsView->currentIndex().isValid() && ui.shortcutsView->currentIndex().parent().isValid()) {
     QKeySequence active = ui.shortcutsView->currentIndex().data(ShortcutsModel::ActiveShortcutRole).value<QKeySequence>();
     QKeySequence def = ui.shortcutsView->currentIndex().data(ShortcutsModel::DefaultShortcutRole).value<QKeySequence>();
-    ui.defaultShortcut->setText(def.isEmpty()? tr("None") : def.toString());
+    ui.defaultShortcut->setText(def.isEmpty()? tr("None") : def.toString(QKeySequence::NativeText));
     ui.actionBox->setEnabled(true);
     if(active == def) {
       ui.useDefault->setChecked(true);
     ui.actionBox->setEnabled(true);
     if(active == def) {
       ui.useDefault->setChecked(true);