void ShortcutCatcher::doneRecording() {
  m_isRecording = false;
  m_btnChange->releaseKeyboard();
  m_btnChange->setDown(false);

  updateDisplayShortcut();

  emit shortcutChanged(m_currentSequence);
}
void ShortcutCatcher::startRecording() {
  m_numKey = 0;
  m_modifierKeys = 0;
  m_currentSequence = QKeySequence();
  m_isRecording = true;
  m_btnChange->setDown(true);
  m_btnChange->grabKeyboard();

  updateDisplayShortcut();
}
示例#3
0
void QKeySequenceWidgetPrivate::doneRecording()
{
    modifierlessTimeout.stop();

    isRecording = false;
    shortcutButton->releaseKeyboard();
    shortcutButton->setDown(false);

    // if sequence is not changed
    if (currentSequence == oldSequence)
    {
        // update Shortcut display
        updateDisplayShortcut();

        return;
    }

    // key sequnce is changed
    emit q_ptr->keySequenceChanged(currentSequence);

    // update Shortcut display
    updateDisplayShortcut();
}
示例#4
0
void QKeySequenceWidgetPrivate::startRecording()
{
    numKey = 0;
    modifierKeys = 0;
    oldSequence = currentSequence;
    currentSequence = QKeySequence();
    isRecording = true;
    shortcutButton->setDown(true);

    shortcutButton->grabKeyboard();

    if (!QWidget::keyboardGrabber())
    {
        qWarning() << "Failed to grab the keyboard! Most likely qt's nograb option is active";
    }

    // update Shortcut display
    updateDisplayShortcut();
}
示例#5
0
void QKeySequenceWidgetPrivate::init(const QKeySequence keySeq, const QString noneStr)
{
    Q_Q(QKeySequenceWidget);
    Q_UNUSED(q);
    layout = new QHBoxLayout(q_func());
    layout->setMargin(0);
    layout->setSpacing(1);

    clearButton = new QToolButton(q_func());
    clearButton->setText("x");

    layout->addWidget(clearButton);

    shortcutButton = new QShortcutButton(this, q_func());

    if (noneStr.isNull() == true)
    {
        noneSequenceText = "...";
    }
    else
    {
        noneSequenceText = noneStr;
    }

    q_ptr->clearKeySequence();
    currentSequence = keySeq;

    shortcutButton->setFocusPolicy(Qt::StrongFocus);    

    layout->addWidget(shortcutButton);

    showClearButton = QKeySequenceWidget::ShowRight;

    clearButton->setIcon(QIcon::fromTheme("dialog-cancel", QIcon(":/icons/dialog-cancel.png")));

    // unfocused clear button  afyer created (small hack)
    clearButton->setFocusPolicy(Qt::NoFocus);

    // update ui
    updateDisplayShortcut();
    updateView();
}
ShortcutCatcher::ShortcutCatcher(QWidget *parent)
  : QWidget(parent) {
  // Setup layout of the control
  m_layout = new QHBoxLayout(this);
  m_layout->setMargin(0);
  m_layout->setSpacing(1);

  // Create reset button.
  m_btnReset = new PlainToolButton(this);
  m_btnReset->setIcon(IconFactory::instance()->fromTheme("edit-revert"));
  m_btnReset->setFocusPolicy(Qt::NoFocus);
  m_btnReset->setToolTip(tr("Reset to original shortcut."));

  // Create clear button.
  m_btnClear = new PlainToolButton(this);
  m_btnClear->setIcon(IconFactory::instance()->fromTheme("item-remove"));
  m_btnClear->setFocusPolicy(Qt::NoFocus);
  m_btnClear->setToolTip(tr("Clear current shortcut."));

  // Clear main shortcut catching button.
  m_btnChange = new ShortcutButton(this);
  m_btnChange->setFocusPolicy(Qt::StrongFocus);
  m_btnChange->setToolTip(tr("Click and hit new shortcut."));

  // Add both buttons to the layout.
  m_layout->addWidget(m_btnChange);
  m_layout->addWidget(m_btnReset);
  m_layout->addWidget(m_btnClear);

  // Establish needed connections.
  connect(m_btnReset, SIGNAL(clicked()), this, SLOT(resetShortcut()));
  connect(m_btnClear, SIGNAL(clicked()), this, SLOT(clearShortcut()));
  connect(m_btnChange, SIGNAL(clicked()), this, SLOT(startRecording()));

  // Prepare initial state of the control.
  updateDisplayShortcut();
}