src/gui/widgets/qlabel.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
  1168     // text. We cannot use the shortcutId itself because on the mac mnemonics are
  1168     // text. We cannot use the shortcutId itself because on the mac mnemonics are
  1169     // off by default, so QKeySequence::mnemonic always returns an empty sequence.
  1169     // off by default, so QKeySequence::mnemonic always returns an empty sequence.
  1170     // But then we do want to hide the ampersands, so we can't use shortcutId.
  1170     // But then we do want to hide the ampersands, so we can't use shortcutId.
  1171     hasShortcut = false;
  1171     hasShortcut = false;
  1172 
  1172 
  1173     if (control) {
  1173     if (!text.contains(QLatin1Char('&')))
  1174         ensureTextPopulated();
  1174         return;
  1175         // Underline the first character that follows an ampersand
  1175     hasShortcut = true;
  1176         shortcutCursor = control->document()->find(QLatin1String("&"));
  1176     shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
  1177         if (shortcutCursor.isNull())
       
  1178             return;
       
  1179         hasShortcut = true;
       
  1180         shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
       
  1181         shortcutCursor.deleteChar(); // remove the ampersand
       
  1182         shortcutCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
       
  1183     } else {
       
  1184         if (!text.contains(QLatin1Char('&')))
       
  1185             return;
       
  1186         hasShortcut = true;
       
  1187         shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
       
  1188     }
       
  1189 }
  1177 }
  1190 
  1178 
  1191 #endif // QT_NO_SHORTCUT
  1179 #endif // QT_NO_SHORTCUT
  1192 
  1180 
  1193 #ifndef QT_NO_MOVIE
  1181 #ifndef QT_NO_MOVIE
  1454                 doc->setPlainText(text);
  1442                 doc->setPlainText(text);
  1455 #else
  1443 #else
  1456             doc->setPlainText(text);
  1444             doc->setPlainText(text);
  1457 #endif
  1445 #endif
  1458             doc->setUndoRedoEnabled(false);
  1446             doc->setUndoRedoEnabled(false);
       
  1447 
       
  1448 #ifndef QT_NO_SHORTCUT
       
  1449             if (hasShortcut) {
       
  1450                 // Underline the first character that follows an ampersand (and remove the others ampersands)
       
  1451                 int from = 0;
       
  1452                 bool found = false;
       
  1453                 QTextCursor cursor;
       
  1454                 while (!(cursor = control->document()->find((QLatin1String("&")), from)).isNull()) {
       
  1455                     cursor.deleteChar(); // remove the ampersand
       
  1456                     cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
       
  1457                     from = cursor.position();
       
  1458                     if (!found && cursor.selectedText() != QLatin1String("&")) { //not a second &
       
  1459                         found = true;
       
  1460                         shortcutCursor = cursor;
       
  1461                     }
       
  1462                 }
       
  1463             }
       
  1464 #endif
  1459         }
  1465         }
  1460     }
  1466     }
  1461     textDirty = false;
  1467     textDirty = false;
  1462 }
  1468 }
  1463 
  1469