Exemple #1
0
// Returns iSeq index if cut2 has a sequence of equal or higher priority to a sequence in cut.
// else -1
static int keyConflict(const KShortcut &cut, const KShortcut &cut2)
{
    for(uint iSeq = 0; iSeq < cut.count(); iSeq++)
    {
        for(uint iSeq2 = 0; iSeq2 < cut2.count(); iSeq2++)
        {
            if(cut.seq(iSeq) == cut2.seq(iSeq2))
                return iSeq;
        }
    }
    return -1;
}
Exemple #2
0
// public static
bool kpTool::containsSingleKeyTrigger (const KShortcut &shortcut,
    KShortcut *shortcutWithoutSingleKeyTriggers)
{
    if (shortcutWithoutSingleKeyTriggers)
        *shortcutWithoutSingleKeyTriggers = shortcut;


    KShortcut newShortcut;
    bool needNewShortcut = false;

    for (int i = 0; i < (int) shortcut.count (); i++)
    {
        const KKeySequence seq = shortcut.seq (i);

        if (containsSingleKeyTrigger (seq))
        {
            needNewShortcut = true;
        }
        else
        {
            newShortcut.append (seq);
        }
    }


    if (needNewShortcut && shortcutWithoutSingleKeyTriggers)
        *shortcutWithoutSingleKeyTriggers = newShortcut;

    return needNewShortcut;
}
Exemple #3
0
void KKeyChooser::setShortcut(const KShortcut &cut)
{
    kdDebug(125) << "KKeyChooser::setShortcut( " << cut.toString() << " )" << endl;
    KKeyChooserItem *pItem = dynamic_cast< KKeyChooserItem * >(d->pList->currentItem());
    if(!pItem)
        return;

    for(uint i = 0; i < cut.count(); i++)
    {
        const KKeySequence &seq = cut.seq(i);
        const KKey &key = seq.key(0);

        if(!d->bAllowLetterShortcuts && key.modFlags() == 0 && key.sym() < 0x3000 && QChar(key.sym()).isLetterOrNumber())
        {
            QString s = i18n(
                            "In order to use the '%1' key as a shortcut, "
                            "it must be combined with the "
                            "Win, Alt, Ctrl, and/or Shift keys.")
                            .arg(QChar(key.sym()));
            KMessageBox::sorry(this, s, i18n("Invalid Shortcut Key"));
            return;
        }
    }

    // If key isn't already in use,
    if(!isKeyPresent(cut))
    {
        // Set new key code
        pItem->setShortcut(cut);
        // Update display
        updateButtons();
        emit keyChange();
    }
}
Exemple #4
0
// 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;
}
Exemple #5
0
QString KKeyChooserItem::text(int iCol) const
{
    if(iCol == 0)
    {
        // Quick HACK to get rid of '&'s.
        QString s = m_pList->label(m_iAction);
        QString s2;
        for(uint i = 0; i < s.length(); i++)
            if(s[i] != '&' || (i + 1 < s.length() && s[i + 1] == '&'))
                s2 += s[i];
        return s2;
    }
    else if(iCol <= (int)m_cut.count())
        return m_cut.seq(iCol - 1).toString();
    else
        return QString::null;
}
Exemple #6
0
bool KKeyChooser::checkStandardShortcutsConflict(const KShortcut &cut, bool bWarnUser, QWidget *parent)
{
    // For each key sequence in the shortcut,
    for(uint i = 0; i < cut.count(); i++)
    {
        const KKeySequence &seq = cut.seq(i);
        KStdAccel::StdAccel id = KStdAccel::findStdAccel(seq);
        if(id != KStdAccel::AccelNone && keyConflict(cut, KStdAccel::shortcut(id)) > -1)
        {
            if(bWarnUser)
            {
                if(!promptForReassign(seq, KStdAccel::label(id), Standard, parent))
                    return true;
                removeStandardShortcut(KStdAccel::label(id), dynamic_cast< KKeyChooser * >(parent), KStdAccel::shortcut(id), cut);
            }
        }
    }
    return false;
}
Exemple #7
0
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();
        }
    }
}
Exemple #8
0
// Removes the sequences in cut2 from cut1
static void removeFromShortcut(KShortcut &cut1, const KShortcut &cut2)
{
    for(uint iSeq2 = 0; iSeq2 < cut2.count(); iSeq2++)
        cut1.remove(cut2.seq(iSeq2));
}