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; }
void ShortcutDialog::accept() { for(int i = 0;; ++i) { KKeySequence seq = shortcut().seq(i); if(seq.isNull()) break; if(seq.key(0) == Key_Escape) { reject(); return; } if(seq.key(0) == Key_Space) { // clear setShortcut(KShortcut()); KShortcutDialog::accept(); return; } if(seq.key(0).modFlags() == 0) { // no shortcuts without modifiers KShortcut cut = shortcut(); cut.setSeq(i, KKeySequence()); setShortcut(cut); return; } } KShortcutDialog::accept(); }
// public static bool kpTool::containsSingleKeyTrigger (const KKeySequence &seq) { for (int i = 0; i < (int) seq.count (); i++) { const KKey key = seq.key (i); if (keyIsText (key.keyCodeQt ())) return true; } return false; }
// 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; }
// 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); }
StdAccel findStdAccel(const KKeySequence &seq) { if(!seq.isNull()) { for(uint i = 0; g_infoStdAccel[i].psName != 0; i++) { StdAccel id = g_infoStdAccel[i].id; if(id != AccelNone) { if(!g_infoStdAccel[i].bInitialized) initialize(id); if(g_infoStdAccel[i].cut.contains(seq)) return id; } } } return AccelNone; }
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(); } } }