bool KKeyChooser::promptForReassign(const KKeySequence &cut, const QString &sAction, ActionType type, QWidget *parent) { if(cut.isNull()) return true; QString sTitle; QString s; if(type == Standard) { sTitle = i18n("Conflict with Standard Application Shortcut"); s = i18n( "The '%1' key combination has already been allocated " "to the standard action \"%2\".\n" "Do you want to reassign it from that action to the current one?"); } else if(type == Global) { sTitle = i18n("Conflict with Global Shortcut"); s = i18n( "The '%1' key combination has already been allocated " "to the global action \"%2\".\n" "Do you want to reassign it from that action to the current one?"); } else { sTitle = i18n("Key Conflict"); s = i18n( "The '%1' key combination has already been allocated " "to the \"%2\" action.\n" "Do you want to reassign it from that action to the current one?"); } s = s.arg(cut.toString()).arg(sAction.stripWhiteSpace()); return KMessageBox::warningContinueCancel(parent, s, sTitle, i18n("Reassign")) == KMessageBox::Continue; }
// KDE4 remove this void KKeyChooser::_warning(const KKeySequence &cut, QString sAction, QString sTitle) { sAction = sAction.stripWhiteSpace(); QString s = i18n( "The '%1' key combination has already been allocated " "to the \"%2\" action.\n" "Please choose a unique key combination.") .arg(cut.toString()) .arg(sAction); KMessageBox::sorry(this, s, sTitle); }
// public static QString kpTool::toolTipForTextAndShortcut (const QString &text, const KShortcut &shortcut) { for (int i = 0; i < (int) shortcut.count (); i++) { const KKeySequence seq = shortcut.seq (i); if (seq.count () == 1 && containsSingleKeyTrigger (seq)) { return i18n ("<Tool Name> (<Single Accel Key>)", "%1 (%2)") .arg (text, seq.toString ()); } } return text; }
void KKbdAccessExtensions::displayAccessKeys() { // Build a list of valid access keys that don't collide with shortcuts. QString availableAccessKeys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"; QPtrList<KXMLGUIClient> allClients = d->mainWindow->factory()->clients(); QPtrListIterator<KXMLGUIClient> it( allClients ); KXMLGUIClient *client; while( (client=it.current()) !=0 ) { ++it; KActionPtrList actions = client->actionCollection()->actions(); for (int j = 0; j < (int)actions.count(); j++) { KAction* action = actions[j]; KShortcut sc = action->shortcut(); for (int i = 0; i < (int)sc.count(); i++) { KKeySequence seq = sc.seq(i); if (seq.count() == 1) { QString s = seq.toString(); if (availableAccessKeys.contains(s)) availableAccessKeys.remove(s); } } } } // Find all visible, focusable widgets and create a QLabel for each. Don't exceed // available list of access keys. QWidgetList* allWidgets = kapp->allWidgets(); QWidget* widget = allWidgets->first(); int accessCount = 0; int maxAccessCount = availableAccessKeys.length(); int overlap = 20; QPoint prevGlobalPos = QPoint(-overlap, -overlap); while (widget && (accessCount < maxAccessCount)) { if (widget->isVisible() && widget->isFocusEnabled() ) { QRect r = widget->rect(); QPoint p(r.x(), r.y()); // Don't display an access key if within overlap pixels of previous one. QPoint globalPos = widget->mapToGlobal(p); QPoint diffPos = globalPos - prevGlobalPos; if (diffPos.manhattanLength() > overlap) { accessCount++; QLabel* lab=new QLabel(widget, "", widget, 0, Qt::WDestructiveClose); lab->setPalette(QToolTip::palette()); lab->setLineWidth(2); lab->setFrameStyle(QFrame::Box | QFrame::Plain); lab->setMargin(3); lab->adjustSize(); lab->move(p); if (!d->accessKeyLabels) { d->accessKeyLabels = new QPtrList<QLabel>; d->accessKeyLabels->setAutoDelete(true); } d->accessKeyLabels->append(lab); prevGlobalPos = globalPos; } } widget = allWidgets->next(); } if (accessCount > 0) { // Sort the access keys from left to right and down the screen. QValueList<KSortedLabel> sortedLabels; for (int i = 0; i < accessCount; i++) sortedLabels.append(KSortedLabel(d->accessKeyLabels->at(i))); qHeapSort( sortedLabels ); // Assign access key labels. for (int i = 0; i < accessCount; i++) { QLabel* lab = sortedLabels[i].label(); QChar s = availableAccessKeys[i]; lab->setText(s); lab->adjustSize(); lab->show(); } } }