bool PosEdit::event(QEvent* event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* ke = static_cast<QKeyEvent*>(event); if (ke->key() == Qt::Key_Return) { //printf("key press event Return\n"); //enterPressed(); bool changed = finishEdit(); if(changed || _returnMode) // Force valueChanged if return mode set, even if not modified. { emit valueChanged(_pos); } emit returnPressed(); emit editingFinished(); return true; } if (ke->key() == Qt::Key_Escape) { //printf("key press event Escape\n"); if(lineEdit()) lineEdit()->undo(); // "By default, isAccepted() is set to true, but don't rely on this as subclasses may // choose to clear it in their constructor." // Just to be sure. Otherwise escape will close a midi editor for example, which is annoying. ke->setAccepted(true); emit escapePressed(); return true; } int segment = curSegment(); if (ke->key() == Qt::Key_Backtab) { if (_smpte) { if (segment == 3) { lineEdit()->setSelection(7, 2); return true; } else if (segment == 2) { lineEdit()->setSelection(4, 2); return true; } else if (segment == 1) { lineEdit()->setSelection(0, 3); return true; } } else { if (segment == 2) { lineEdit()->setSelection(5, 2); return true; } if (segment == 1) { lineEdit()->setSelection(0, 4); return true; } } } if (ke->key() == Qt::Key_Tab) { if (_smpte) { if (segment == 0) { lineEdit()->setSelection(4, 2); return true; } else if (segment == 1) { lineEdit()->setSelection(7, 2); return true; } else if (segment == 2) { lineEdit()->setSelection(10, 2); return true; } } else { if (segment == 0) { lineEdit()->setSelection(5, 2); return true; } if (segment == 1) { lineEdit()->setSelection(8, 3); return true; } } } } else if (event->type() == QEvent::FocusIn) { QFocusEvent* fe = static_cast<QFocusEvent*>(event); QAbstractSpinBox::focusInEvent(fe); int segment = curSegment(); switch(segment) { case 0: lineEdit()->setSelection(0,4); break; case 1: lineEdit()->setSelection(5,2); break; case 2: lineEdit()->setSelection(8,3); break; } return true; } else if (event->type() == QEvent::FocusOut) { QFocusEvent* fe = static_cast<QFocusEvent*>(event); QAbstractSpinBox::focusOutEvent(fe); if(finishEdit()) emit valueChanged(_pos); emit lostFocus(); emit editingFinished(); return true; } return QAbstractSpinBox::event(event); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RiuTreeViewEventFilter::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast<QKeyEvent *>(event); std::vector<caf::PdmUiItem*> uiItems; caf::SelectionManager::instance()->selectedItems(uiItems); if (uiItems.size() > 0) { std::vector<caf::CmdFeature*> matches; if (keyEvent->matches(QKeySequence::Copy)) { matches.push_back(caf::CmdFeatureManager::instance()->getCommandFeature("RicCopyReferencesToClipboardFeature")); } else if (keyEvent->matches(QKeySequence::Cut)) { matches.push_back(caf::CmdFeatureManager::instance()->getCommandFeature("RicCutReferencesToClipboardFeature")); } else if (keyEvent->matches(QKeySequence::Paste)) { if (uiItems.size() == 1) { matches = caf::CmdFeatureManager::instance()->commandFeaturesMatchingSubString("Paste"); } } for (caf::CmdFeature* feature : matches) { if (feature->canFeatureBeExecuted()) { feature->actionTriggered(false); keyEvent->setAccepted(true); return true; } } } // Do not toggle state if currently editing a name in the tree view bool toggleStateForSelection = true; if (RiuMainWindow::instance()->projectTreeView() && RiuMainWindow::instance()->projectTreeView()->isTreeItemEditWidgetActive()) { toggleStateForSelection = false; } else if (RiaApplication::instance()->mainPlotWindow() && RiaApplication::instance()->mainPlotWindow()->projectTreeView() && RiaApplication::instance()->mainPlotWindow()->projectTreeView()->isTreeItemEditWidgetActive()) { toggleStateForSelection = false; } if (toggleStateForSelection) { switch (keyEvent->key()) { case Qt::Key_Space: case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Select: { RicToggleItemsFeatureImpl::setObjectToggleStateForSelection(RicToggleItemsFeatureImpl::TOGGLE); keyEvent->setAccepted(true); return true; } } } } // standard event processing return QObject::eventFilter(obj, event); }