Esempio n. 1
0
void ShortcutButton::addShortcut(QPushButton *shortcutButton)
{
    QWidget *parent = this;
    // Destroy shortcut dialog, if its shortcut button is deleted.
    if (shortcutButton != nullptr)
        parent = shortcutButton;

    auto dialog = new ShortcutDialog(parent);
    if (dialog->exec() == QDialog::Rejected)
        return;

    const QKeySequence newShortcut = dialog->shortcut();
    const QKeySequence oldShortcut = shortcutButton
            ? shortcutForButton(*shortcutButton)
            : QKeySequence();

    if (oldShortcut == newShortcut)
        return;

    // Remove shortcut button if shortcut is removed, unrecognized or already set.
    if ( newShortcut.isEmpty() || shortcuts().contains(newShortcut) ) {
        if (shortcutButton) {
            delete shortcutButton;
            emit shortcutRemoved(oldShortcut);
        }
    } else if (shortcutButton) {
        emit shortcutRemoved(oldShortcut);
        setButtonShortcut(shortcutButton, newShortcut);
        emit shortcutAdded(newShortcut);
    } else {
        addShortcut(newShortcut);
    }
}
Esempio n. 2
0
void ShortcutButton::addShortcut(QPushButton *shortcutButton)
{
    QWidget *parent = this;
    // Destroy shortcut dialog, if its shortcut button is deleted.
    if (shortcutButton != NULL)
        parent = shortcutButton;

    ShortcutDialog *dialog = new ShortcutDialog(parent);
    dialog->setExpectModifier(m_expectModifier);

    if (dialog->exec() == QDialog::Accepted) {
        const QKeySequence shortcut = dialog->shortcut();
        const QString text = shortcut.toString(QKeySequence::NativeText);
        if ( shortcut.isEmpty() || shortcuts().contains(shortcut) ) {
            if (shortcutButton == NULL || shortcutButton->text() != text ) {
                if (shortcutButton != NULL)
                    emit shortcutRemoved(shortcutButton->text());
                delete shortcutButton;
            }
        } else {
            if (shortcutButton != NULL) {
                if ( shortcutButton->text() != text ) {
                    emit shortcutRemoved(shortcutButton->text());
                    shortcutButton->setText(text);
                    emit shortcutAdded(text);
                }
            } else {
                addShortcut(text);
            }
        }
    }
}
Esempio n. 3
0
void ShortcutsWidget::loadShortcuts(QSettings &settings)
{
    MenuItems items = menuItems();
    ::loadShortcuts(&items, settings);

    m_actions.clear();
    m_shortcuts.clear();

    QTableWidget *table = ui->tableWidget;
    while (table->rowCount() > 0)
        table->removeRow(0);


    foreach (const MenuItem &item, items) {
        MenuAction action;
        action.iconName = item.iconName;
        action.iconId = item.iconId;
        action.text = item.text;
        action.settingsKey = item.settingsKey;

        const int row = table->rowCount();
        table->insertRow(row);

        QTableWidgetItem *tableItem = new QTableWidgetItem();
        table->setItem(row, Columns::Empty, tableItem);
        tableItem->setFlags(Qt::NoItemFlags);

        tableItem = new QTableWidgetItem();
        action.tableItem = tableItem;
        table->setItem(row, Columns::Icon, tableItem);
        tableItem->setFlags(Qt::ItemIsEnabled);

        tableItem = new QTableWidgetItem(uiText(action.text));
        table->setItem(row, Columns::Text, tableItem);
        tableItem->setFlags(Qt::ItemIsEnabled);

        action.shortcutButton = new ShortcutButton(table);
        table->setCellWidget(row, Columns::Shortcut, action.shortcutButton);
        action.shortcutButton->setDefaultShortcut(item.defaultShortcut);
        foreach (const QKeySequence &shortcut, item.shortcuts)
            action.shortcutButton->addShortcut(shortcut);

        action.iconId = item.iconId;
        m_actions.append(action);

        m_shortcuts << item.shortcuts;
        m_timerCheckAmbiguous.start();

        connect( action.shortcutButton, SIGNAL(shortcutAdded(QKeySequence)),
                 this, SLOT(onShortcutAdded(QKeySequence)) );
        connect( action.shortcutButton, SIGNAL(shortcutRemoved(QKeySequence)),
                 this, SLOT(onShortcutRemoved(QKeySequence)) );
    }
Esempio n. 4
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);
}
Esempio n. 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);
}