void ShortcutWidget::keyEvent(QKeyEvent* event) { event->accept(); if (event->type() != QEvent::KeyPress && event->type() != QEvent::KeyRelease) { return; } bool release = (event->type() == QEvent::KeyRelease); if (m_locked && release) { return; } Qt::Key key = static_cast<Qt::Key>(event->key()); if (key <= 0 || key == Qt::Key_unknown) { return; } Qt::KeyboardModifiers modifiers = event->modifiers() & (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META); bool keyIsModifier; switch (key) { case Qt::Key_Shift: case Qt::Key_Control: case Qt::Key_Meta: case Qt::Key_Alt: case Qt::Key_AltGr: keyIsModifier = true; break; default: keyIsModifier = false; } if (!release && !keyIsModifier) { if (modifiers != 0) { setShortcut(key, modifiers); } else { resetShortcut(); setStyleSheet(""); displayShortcut(key, modifiers); } } else { if (m_locked) { resetShortcut(); setStyleSheet(""); } displayShortcut(static_cast<Qt::Key>(0), modifiers); } }
QgsConfigureShortcutsDialog::QgsConfigureShortcutsDialog( QWidget* parent, QgsShortcutsManager* manager ) : QDialog( parent ) , mManager( manager ) , mGettingShortcut( false ) , mModifiers( 0 ) , mKey( 0 ) { setupUi( this ); if ( !mManager ) mManager = QgsShortcutsManager::instance(); connect( btnChangeShortcut, SIGNAL( clicked() ), this, SLOT( changeShortcut() ) ); connect( btnResetShortcut, SIGNAL( clicked() ), this, SLOT( resetShortcut() ) ); connect( btnSetNoShortcut, SIGNAL( clicked() ), this, SLOT( setNoShortcut() ) ); connect( btnSaveShortcuts, SIGNAL( clicked() ), this, SLOT( saveShortcuts() ) ); connect( btnLoadShortcuts, SIGNAL( clicked() ), this, SLOT( loadShortcuts() ) ); connect( treeActions, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ), this, SLOT( actionChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) ); populateActions(); restoreState(); }
QgsConfigureShortcutsDialog::QgsConfigureShortcutsDialog( QWidget* parent ) : QDialog( parent ), mGettingShortcut( false ) { setupUi( this ); connect( btnChangeShortcut, SIGNAL( clicked() ), this, SLOT( changeShortcut() ) ); connect( btnResetShortcut, SIGNAL( clicked() ), this, SLOT( resetShortcut() ) ); connect( btnSetNoShortcut, SIGNAL( clicked() ), this, SLOT( setNoShortcut() ) ); connect( btnSaveShortcuts, SIGNAL( clicked() ), this, SLOT( saveShortcuts() ) ); connect( btnLoadShortcuts, SIGNAL( clicked() ), this, SLOT( loadShortcuts() ) ); connect( treeActions, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ), this, SLOT( actionChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) ); populateActions(); }
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(); }