Example #1
0
void ShortcutButton::clearShortcuts()
{
    while ( shortcutCount() > 0 ) {
        QWidget *w = shortcutButton(0);
        emit shortcutRemoved( shortcutForButton(*w) );
        delete w;
    }
}
Example #2
0
QList<QKeySequence> ShortcutButton::shortcuts() const
{
    QList<QKeySequence> shortcuts;

    for ( int i = 0; i < shortcutCount(); ++i ) {
        QWidget *w = shortcutButton(i);
        shortcuts.append( shortcutForButton(*w) );
    }

    return shortcuts;
}
Example #3
0
void ShortcutButton::addShortcut(const QKeySequence &shortcut)
{
    if ( shortcut.isEmpty() || shortcuts().contains(shortcut) )
        return;

    QPushButton *button = new QPushButton(this);
    m_layout->insertWidget( shortcutCount(), button, 1 );
    connect( button, SIGNAL(clicked()),
             this, SLOT(onShortcutButtonClicked()) );
    button->setText( shortcut.toString(QKeySequence::NativeText) );
    emit shortcutAdded(shortcut);
}
Example #4
0
bool ShortcutButton::focusNextPrevChild(bool next)
{
    if ( m_buttonAddShortcut->hasFocus() ) {
        if (next || shortcutCount() == 0)
            return QWidget::focusNextPrevChild(next);
        shortcutButton(shortcutCount() - 1)->setFocus();
        return true;
    } else if (shortcutCount() == 0) {
        m_buttonAddShortcut->setFocus();
        return true;
    }

    int current = -1;
    for ( int i = 0; i < shortcutCount(); ++i ) {
        if ( shortcutButton(i)->hasFocus() ) {
            current = i;
            break;
        }
    }

    if (current == 0 && !next)
        return QWidget::focusNextPrevChild(next);

    if (current == shortcutCount() - 1 && next) {
        m_buttonAddShortcut->setFocus();
    } else if (current == -1 && !next) {
        shortcutButton(shortcutCount() - 1)->setFocus();
    } else {
        shortcutButton(current + (next ? 1 : -1))->setFocus();
    }

    return true;
}
Example #5
0
void ShortcutButton::addShortcut(const QKeySequence &shortcut)
{
    if ( shortcut.isEmpty() || shortcuts().contains(shortcut) )
        return;

    auto button = new QPushButton(this);
    const int buttonIndex = shortcutCount();
    m_layout->insertWidget(buttonIndex, button, 1);

    setTabOrder(m_buttonAddShortcut, button);

    connect( button, &QAbstractButton::clicked,
             this, &ShortcutButton::onShortcutButtonClicked );
    setButtonShortcut(button, shortcut);
    emit shortcutAdded(shortcut);
}