当前位置: 首页>>代码示例>>C++>>正文


C++ KShortcut类代码示例

本文整理汇总了C++中KShortcut的典型用法代码示例。如果您正苦于以下问题:C++ KShortcut类的具体用法?C++ KShortcut怎么用?C++ KShortcut使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了KShortcut类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: slotCapturedShortcut

void BasicTab::slotCapturedShortcut(const KShortcut &cut)
{
    if(signalsBlocked())
        return;

    if(KKeyChooser::checkGlobalShortcutsConflict(cut, true, topLevelWidget())
       || KKeyChooser::checkStandardShortcutsConflict(cut, true, topLevelWidget()))
        return;

    if(KHotKeys::present())
    {
        if(!_menuEntryInfo->isShortcutAvailable(cut))
        {
            KService::Ptr service;
            emit findServiceShortcut(cut, service);
            if(!service)
                service = KHotKeys::findMenuEntry(cut.toString());
            if(service)
            {
                KMessageBox::sorry(this, i18n("<qt>The key <b>%1</b> can not be used here because it is already used to activate <b>%2</b>.")
                                             .arg(cut.toString(), service->name()));
                return;
            }
            else
            {
                KMessageBox::sorry(this, i18n("<qt>The key <b>%1</b> can not be used here because it is already in use.").arg(cut.toString()));
                return;
            }
        }
        _menuEntryInfo->setShortcut(cut);
    }
    _keyEdit->setShortcut(cut, false);
    if(_menuEntryInfo)
        emit changed(_menuEntryInfo);
}
开发者ID:serghei,项目名称:kde3-kdebase,代码行数:35,代码来源:basictab.cpp

示例2: containsSingleKeyTrigger

// 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;
}
开发者ID:serghei,项目名称:kde3-kdegraphics,代码行数:31,代码来源:kptool.cpp

示例3: shortcut

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();
}
开发者ID:serghei,项目名称:kde3-kdebase,代码行数:28,代码来源:utils.cpp

示例4: setShortcut

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();
    }
}
开发者ID:,项目名称:,代码行数:34,代码来源:

示例5: keyConflict

bool KKeyChooser::isKeyPresentLocally(const KShortcut &cut, KKeyChooserItem *ignoreItem, bool bWarnUser)
{
    if(cut.toString().isEmpty())
        return false;
    // Search for shortcut conflicts with other actions in the
    //  lists we're configuring.
    for(QListViewItemIterator it(d->pList); it.current(); ++it)
    {
        KKeyChooserItem *pItem2 = dynamic_cast< KKeyChooserItem * >(it.current());
        if(pItem2 && pItem2 != ignoreItem)
        {
            int iSeq = keyConflict(cut, pItem2->shortcut());
            if(iSeq > -1)
            {
                if(bWarnUser)
                {
                    if(!promptForReassign(cut.seq(iSeq), pItem2->text(0), Application, this))
                        return true;
                    // else remove the shortcut from it
                    KShortcut cut2 = pItem2->shortcut();
                    removeFromShortcut(cut2, cut);
                    pItem2->setShortcut(cut2);
                    updateButtons();
                    emit keyChange();
                }
            }
        }
    }
    return false;
}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例6: it

void KShortcutsEditorDelegate::stealShortcut(
    const QKeySequence &seq,
    KAction *action)
{
    QTreeWidget *view = static_cast<QTreeWidget *>(parent());

    // Iterate over all items
    QTreeWidgetItemIterator it(view, QTreeWidgetItemIterator::NoChildren);

    for (; (*it); ++it) {
        KShortcutsEditorItem* item = dynamic_cast<KShortcutsEditorItem *>(*it);
        if (item && item->data(0, ObjectRole).value<QObject*>() == action) {

            // We found the action, snapshot the current state. Steal the
            // shortcut. We will save the change later.
            KShortcut cut = action->shortcut();
            if (   cut.primary().matches(seq) != QKeySequence::NoMatch
                || seq.matches(cut.primary()) != QKeySequence::NoMatch) {
                item->setKeySequence(LocalPrimary, QKeySequence());
            }

            if (   cut.alternate().matches(seq) != QKeySequence::NoMatch
                || seq.matches(cut.alternate()) != QKeySequence::NoMatch) {
                item->setKeySequence(LocalAlternate, QKeySequence());
            }
            break;
        }
    }

}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例7: setupTest

void KGlobalShortcutTest::testSaveRestore()
{
    setupTest("testSaveRestore");

    //It /would be nice/ to test persistent storage. That is not so easy...
    KShortcut cutA = m_actionA->globalShortcut();
    // Delete the action
    delete m_actionA;

    // Recreate it
    m_actionA = new KAction("Text For Action A", this);
    m_actionA->setObjectName("Action A:testSaveRestore");

    // Now it's empty
    QVERIFY(m_actionA->globalShortcut().isEmpty());

    m_actionA->setGlobalShortcut(KShortcut());
    // Now it's restored
    QCOMPARE(m_actionA->globalShortcut(), cutA);

    // And again
    delete m_actionA;
    m_actionA = new KAction("Text For Action A", this);
    m_actionA->setObjectName("Action A:testSaveRestore");
    m_actionA->setGlobalShortcut(KShortcut(QKeySequence(), cutA.primary()));
    QCOMPARE(m_actionA->globalShortcut(), cutA);

}
开发者ID:fluxer,项目名称:kdelibs,代码行数:28,代码来源:kglobalshortcuttest.cpp

示例8: SLOT

/**
 * create the action events create the gui.
 */
void KJezzball::initXMLUI()
{
    m_newAction = KStdGameAction::gameNew( this, SLOT(newGame()), actionCollection() );
    // AB: originally KBounce/KJezzball used Space for new game - but Ctrl+N is
    // default. We solve this by providing space as an alternative key
    KShortcut s = m_newAction->shortcut();
    s.append(KKeySequence(QKeySequence(Key_Space)));
    m_newAction->setShortcut(s);

    KStdGameAction::quit(this, SLOT(close()), actionCollection() );
    KStdGameAction::highscores(this, SLOT(showHighscore()), actionCollection() );
    m_pauseButton = KStdGameAction::pause(this, SLOT(pauseGame()), actionCollection());
    KStdGameAction::end(this, SLOT(closeGame()), actionCollection());
    KStdGameAction::configureHighscores(this, SLOT(configureHighscores()),actionCollection());

    new KAction( i18n("&Select Background Folder..."), 0, this, SLOT(selectBackground()),
                       actionCollection(), "background_select" );
    m_backgroundShowAction =
        new KToggleAction( i18n("Show &Backgrounds"), 0, this, SLOT(showBackground()),
                           actionCollection(), "background_show" );
    m_backgroundShowAction->setCheckedState(i18n("Hide &Backgrounds"));
    m_backgroundShowAction->setEnabled( !m_backgroundDir.isEmpty() );
    m_backgroundShowAction->setChecked( m_showBackground );

    m_soundAction = new KToggleAction( i18n("&Play Sounds"), 0, 0, 0, actionCollection(), "toggle_sound");
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例9: addShortcut

void starter::addShortcut(const KShortcut &cut)
{
   // in case of empty shortcut, remove the entry from the list and return
   if (!short(cut.keyCodeQt()))
   {
      ShortcutList::Iterator it;
      for ( it = shortcutList.begin(); it != shortcutList.end(); ++it )
         if (it.data() == configDialog->categoryList->currentText())
         {
            shortcutList.remove(it);
            break;
         }
      configDialog->buttonShortcut->setShortcut(KShortcut::null(), false);
      return;
   }
   // generate MyKey
   short state = 0;
   if (cut.seq(0).key(0).modFlags() & KKey::CTRL)
      state |= Qt::ControlButton;
   if (cut.seq(0).key(0).modFlags() & KKey::ALT)
      state |= Qt::AltButton;
   if (cut.seq(0).key(0).modFlags() & KKey::SHIFT)
      state |= Qt::ShiftButton;
   MyKey key(cut.seq(0).keyCodeQt(), state);
   // Test if this is a valid shotrcut, i.e. contains 'ctrl' or 'alt', returns iff not
   if (!(state & Qt::ControlButton || state & Qt::AltButton))
   {
      KMessageBox::sorry(this, i18n("<qt>To ensure usefull behaviour of the searchline, the shortcut <b>must contain</b> a metabutton, i.e. <b>'ctrl' and/or 'alt'</b></qt>"), i18n("Sorry, invalid Shortcut"));
      return;
   }
   // test if the cut was allready bound to another category and ask the user whta to do (return iff not rebind)
   ShortcutList::Iterator it = shortcutList.find(key);
   if ((it != shortcutList.end() && KMessageBox::questionYesNo(this, i18n("<qt>The selected shortcut is allready bound to the category \"%1\".<br>Do you want to <b>rebind</b> it?</qt>").arg(it.data()), i18n("Rebind Shortcut?")) == KMessageBox::No))
      return;
   // if rebind (it is not end and we did not return ;) remove the old shortcut
   if (it != shortcutList.end())
   {
      shortcutList.remove(it);
   }
   // test if another shortcut is bound to this category and remove it in case
   for ( it = shortcutList.begin(); it != shortcutList.end(); ++it )
      if (it.data() == configDialog->categoryList->currentText())
      {
         shortcutList.remove(it);
         break;
      }
   // add new shortcut/category map entry
   shortcutList[key] = configDialog->categoryList->currentText();
   // update UI
   configDialog->buttonShortcut->setShortcut(cut, false);
}
开发者ID:iegor,项目名称:x11-themes-baghira,代码行数:51,代码来源:starter.cpp

示例10: shortcutForKey

// public static
KShortcut kpTool::shortcutForKey (int key)
{
    KShortcut shortcut;

    if (key)
    {
        shortcut.append (KKeySequence (KKey (key)));
        // (CTRL+<key>, ALT+<key>, CTRL+ALT+<key>, CTRL+SHIFT+<key>
        //  all clash with global KDE shortcuts)
        shortcut.append (KKeySequence (KKey (Qt::ALT + Qt::SHIFT + key)));
    }

    return shortcut;
}
开发者ID:serghei,项目名称:kde3-kdegraphics,代码行数:15,代码来源:kptool.cpp

示例11: toolTipForTextAndShortcut

// 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;
}
开发者ID:serghei,项目名称:kde3-kdegraphics,代码行数:17,代码来源:kptool.cpp

示例12: capturedShortcut

void KKeyChooser::capturedShortcut(const KShortcut &cut)
{
    if(cut.isNull())
        slotNoKey();
    else
        setShortcut(cut);
}
开发者ID:,项目名称:,代码行数:7,代码来源:

示例13: shortcutDefault3

KShortcut shortcutDefault3(StdAccel id)
{
    KShortcut cut;

    KStdAccelInfo *pInfo = infoPtr(id);
    if(pInfo)
    {
        if(pInfo->cutDefault)
            cut.init(pInfo->cutDefault);
        // FIXME: if there is no cutDefault, then this we be made the primary
        //  instead of alternate shortcut.
        if(pInfo->cutDefault3B)
            cut.append(KKey(pInfo->cutDefault3B));
    }

    return cut;
}
开发者ID:serghei,项目名称:kde3-kdelibs,代码行数:17,代码来源:kstdaccel.cpp

示例14: initPrivate

void KAction::initPrivate( const QString& text, const KShortcut& cut,
                  const QObject* receiver, const char* slot )
{
    d->m_cutDefault = cut;

    m_parentCollection = dynamic_cast<KActionCollection *>( parent() );
    kdDebug(129) << "KAction::initPrivate(): this = " << this << " name = \"" << name() << "\" cut = " << cut.toStringInternal() << " m_parentCollection = " << m_parentCollection << endl;
    if ( m_parentCollection )
        m_parentCollection->insert( this );

    if ( receiver && slot )
        connect( this, SIGNAL( activated() ), receiver, slot );

    if( !cut.isNull() && !qstrcmp( name(), "unnamed" ) )
        kdWarning(129) << "KAction::initPrivate(): trying to assign a shortcut (" << cut.toStringInternal() << ") to an unnamed action." << endl;
    d->setText( text );
    initShortcut( cut );
}
开发者ID:,项目名称:,代码行数:18,代码来源:

示例15: checkStandardShortcutsConflict

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;
}
开发者ID:,项目名称:,代码行数:19,代码来源:


注:本文中的KShortcut类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。