bool SearchBar::eventFilter(QObject* object, QEvent* e) { QFocusEvent* focusEvent = 0; // HACK This event comes from the ViewContainer when // updateViewActions is called. ViewContainer can't // check the status of the search box, and so tramples // on the QAction we're managing - that is until the // ambiguous shortcut dialog box pops up, at which point // a focus event is sent to the searchbar and the other // stanza in this method is triggered. // 414 was the time of day when I named the event. bool hack = (object == parent() && e->type() == QEvent::User+414); if (hack && hasFocus()) focusEvent = new QFocusEvent(QEvent::FocusIn); else focusEvent = dynamic_cast<QFocusEvent*>(e); if (focusEvent) { Application* konvApp = Application::instance(); QAction * action = static_cast<QAction*>(konvApp->getMainWindow()->actionCollection()->action("focus_input_box")); if (action->shortcut().matches(QKeySequence(Qt::Key_Escape))) { action->setEnabled(focusEvent->lostFocus()); m_closeShortcut->setEnabled(focusEvent->gotFocus()); } } if (hack) delete focusEvent; return hack; }
bool HotkeyWidget::event(QEvent *event) { if (event->type() == QEvent::LanguageChange) { setHotkeyText(); } else if (event->type() == QEvent::KeyPress) { keyPressEvent(static_cast<QKeyEvent *>(event)); return true; } else if (event->type() == QEvent::FocusIn) { QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event); if (focusEvent->reason() != Qt::TabFocusReason) { setText(tr("Type your hotkey")); mKeyboardFocus = false; grabKeyboard(); } else { mKeyboardFocus = true; } } else if (event->type() == QEvent::FocusOut) { if (text() == tr("Invalid hotkey")) { emit invalidHotkeyError(); showError(); } releaseKeyboard(); setHotkeyText(); // Reset the text } else if ((event->type() == QEvent::KeyPress || event->type() == QEvent::ShortcutOverride || event->type() == QEvent::Shortcut) && hasFocus()) { event->accept(); return true; } return QPushButton::event(event); }
bool SpinBox2::eventFilter(QObject* obj, QEvent* e) { bool updateButtons = false; if (obj == mSpinbox) { //if (e->type() != QEvent::Paint) qCDebug(KALARM_LOG)<<e->type(); switch (e->type()) { case QEvent::Enter: case QEvent::Leave: QApplication::postEvent(mUpdown2, new QEvent(e->type())); updateButtons = true; break; case QEvent::HoverEnter: { QHoverEvent* he = (QHoverEvent*)e; QApplication::postEvent(mUpdown2, new QHoverEvent(e->type(), QPoint(1, he->pos().y()), he->oldPos())); updateButtons = true; break; } case QEvent::HoverLeave: { QHoverEvent* he = (QHoverEvent*)e; QApplication::postEvent(mUpdown2, new QHoverEvent(e->type(), he->pos(), QPoint(1, he->oldPos().y()))); updateButtons = true; break; } case QEvent::FocusIn: case QEvent::FocusOut: { QFocusEvent* fe = (QFocusEvent*)e; QApplication::postEvent(mUpdown2, new QFocusEvent(e->type(), fe->reason())); updateButtons = true; break; } default: break; } } else if (obj == mUpdown2) { switch (e->type()) { case QEvent::Enter: case QEvent::Leave: case QEvent::HoverEnter: case QEvent::HoverLeave: case QEvent::EnabledChange: updateButtons = true; break; default: break; } } if (updateButtons) QTimer::singleShot(0, this, &SpinBox2::updateMirrorButtons); return false; }
bool KItemListRoleEditor::event(QEvent* event) { if (event->type() == QEvent::FocusOut) { QFocusEvent* focusEvent = static_cast<QFocusEvent*>(event); if (focusEvent->reason() != Qt::PopupFocusReason) { emitRoleEditingFinished(); } } return KTextEdit::event(event); }
bool PropertyEditorDelegate::eventFilter(QObject *object, QEvent *event) { if(event->type() == QEvent::FocusOut) { QFocusEvent *fe = static_cast<QFocusEvent *>(event); if(fe->reason() == Qt::ActiveWindowFocusReason) return false; } return QItemDelegate::eventFilter(object, event); }
bool ColorEditor::eventFilter(QObject *obj, QEvent *event) { if (obj == m_button){ if (event->type() == QEvent::FocusOut && !m_buttonPressed){ QFocusEvent* focusEvent = dynamic_cast<QFocusEvent*>(event); if (focusEvent && focusEvent->reason()!=Qt::MouseFocusReason){ setFocusToParent(); emit(editingFinished()); } return false; } } return false; }
bool KisInputManager::Private::CanvasSwitcher::eventFilter(QObject* object, QEvent* event ) { if (canvasResolver.contains(object)) { switch (event->type()) { case QEvent::FocusIn: { QFocusEvent *fevent = static_cast<QFocusEvent*>(event); eatOneMouseStroke = 2 * (fevent->reason() == Qt::MouseFocusReason); KisCanvas2 *canvas = canvasResolver.value(object); d->canvas = canvas; d->toolProxy = dynamic_cast<KisToolProxy*>(canvas->toolProxy()); d->q->setupAsEventFilter(object); object->removeEventFilter(this); object->installEventFilter(this); QEvent event(QEvent::Enter); d->q->eventFilter(object, &event); break; } case QEvent::Wheel: { QWidget *widget = static_cast<QWidget*>(object); widget->setFocus(); break; } case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::TabletPress: case QEvent::TabletRelease: if (eatOneMouseStroke) { eatOneMouseStroke--; return true; } break; case QEvent::MouseButtonDblClick: if (eatOneMouseStroke) { return true; } break; default: break; } } return QObject::eventFilter(object, event); }
void PWidget::eventFocus(QObject *, QEvent *e) { PukeMessage pm; widgetId wI; // debug("PWidget: eventFocus"); QFocusEvent *fe = Q_FOCUS_EVENT(e); wI = widgetIden(); pm.iCommand = - e->type() - 1020; // 1020 offset for events pm.iWinId = wI.iWinId; pm.iArg = 0; pm.cArg = new char[2]; pm.iTextSize = 2*sizeof(char); pm.cArg[0] = fe->gotFocus(); pm.cArg[1] = fe->lostFocus(); emit outputMessage(wI.fd, &pm); delete[] pm.cArg; }
bool QtEvent::eventFilter(QObject *target, QEvent *event) { int type = event->type(); void *func = m_hash.value(type); if (func != 0) { int accept = event->isAccepted() ? 1 : 0; switch(type) { case QEvent::Create: case QEvent::Close: case QEvent::Show: case QEvent::Hide: case QEvent::Enter: case QEvent::Leave: { base_event ev = {accept}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } case QEvent::FocusIn: case QEvent::FocusOut: { QFocusEvent *e = (QFocusEvent*)event; focus_event ev = {accept,e->reason()}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } case QEvent::Timer: { QTimerEvent *e = (QTimerEvent*)event; timer_event ev = {accept,e->timerId()}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } case QEvent::HoverEnter: case QEvent::HoverLeave: case QEvent::HoverMove: { QHoverEvent *e = (QHoverEvent*)event; const QPoint &pt = e->pos(); const QPoint &opt = e->oldPos(); hover_event ev = {accept,pt.x(),pt.y(),opt.x(),opt.y()}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } case QEvent::KeyPress: case QEvent::KeyRelease: { QKeyEvent *e = (QKeyEvent*)event; string_head sh; drvSetString(&sh,e->text()); key_event ev = {accept,e->modifiers(),e->count(),e->isAutoRepeat()?1:0,e->key(),e->nativeModifiers(),e->nativeScanCode(),e->nativeVirtualKey(),&sh}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::MouseMove: { QMouseEvent *e = (QMouseEvent*)event; const QPoint &gpt = e->globalPos(); const QPoint &pt = e->pos(); mouse_event ev = {accept,e->modifiers(),e->button(),e->buttons(),gpt.x(),gpt.y(),pt.x(),pt.y()}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } case QEvent::Move: { QMoveEvent *e = (QMoveEvent*)event; const QPoint &pt = e->pos(); const QPoint &opt = e->oldPos(); move_event ev = {accept,pt.x(),pt.y(),opt.x(),opt.y()}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } case QEvent::Resize: { QResizeEvent *e = (QResizeEvent*)event; const QSize &sz = e->size(); const QSize &osz = e->oldSize(); resize_event ev = {accept,sz.width(),sz.height(),osz.width(),osz.height()}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } case QEvent::Paint: { QPaintEvent *e = (QPaintEvent*)event; const QRect &rc = e->rect(); paint_event ev = {accept,rc.x(),rc.y(),rc.width(),rc.height()}; drv_callback(func,&ev,0,0,0); event->setAccepted(ev.accept != 0); break; } default: { return QObject::eventFilter(target,event); } } return true; } return QObject::eventFilter(target,event); }
bool View::eventFilter( QObject * watched, QEvent * e ) { // kDebug() << k_funcinfo << e->type() << endl; if ( watched != m_pFocusWidget ) return false; switch ( e->type() ) { case QEvent::FocusIn: { p_viewContainer->setActiveViewArea( viewAreaId() ); if ( KTechlab * ktl = KTechlab::self() ) { ktl->actionByName("file_save")->setEnabled(true); ktl->actionByName("file_save_as")->setEnabled(true); ktl->actionByName("file_close")->setEnabled(true); ktl->actionByName("file_print")->setEnabled(true); ktl->actionByName("edit_paste")->setEnabled(true); ktl->actionByName("view_split_leftright")->setEnabled(true); ktl->actionByName("view_split_topbottom")->setEnabled(true); ItemInterface::self()->updateItemActions(); } // kDebug() << k_funcinfo << "Focused In\n"; emit focused(this); break; } case QEvent::FocusOut: { // kDebug() << k_funcinfo << "Focused Out.\n"; QFocusEvent *fe = static_cast<QFocusEvent*>(e); if ( QWidget * fw = qApp->focusWidget() ) { QString fwClassName( fw->className() ); // kDebug() << "New focus widget is \""<<fw->name()<<"\" of type " << fwClassName << endl; if ( (fwClassName != "KateViewInternal") && (fwClassName != "QViewportWidget") ) { // kDebug() << "Returning as a non-view widget has focus.\n"; break; } } else { // kDebug() << "No widget currently has focus.\n"; } if ( fe->reason() == Qt::PopupFocusReason ) { // kDebug() << k_funcinfo << "Ignoring focus-out event as was a popup.\n"; break; } if ( fe->reason() == Qt::ActiveWindowFocusReason ) { // kDebug() << k_funcinfo << "Ignoring focus-out event as main window lost focus.\n"; break; } emit unfocused(); break; } default: break; } return false; }
bool CompletionListView::event(QEvent *e) { if (m_blockFocusOut) return QListView::event(e); bool forwardKeys = true; if (e->type() == QEvent::FocusOut) { QModelIndex index; #if defined(Q_OS_DARWIN) && ! defined(QT_MAC_USE_COCOA) QFocusEvent *fe = static_cast<QFocusEvent *>(e); if (fe->reason() == Qt::OtherFocusReason) { // Qt/carbon workaround // focus out is received before the key press event. index = currentIndex(); } #endif m_completionWidget->closeList(index); if (m_infoFrame) m_infoFrame->close(); return true; } else if (e->type() == QEvent::ShortcutOverride) { QKeyEvent *ke = static_cast<QKeyEvent *>(e); switch (ke->key()) { case Qt::Key_N: case Qt::Key_P: // select next/previous completion if (ke->modifiers() == Qt::ControlModifier) { e->accept(); int change = (ke->key() == Qt::Key_N) ? 1 : -1; int nrows = model()->rowCount(); int row = currentIndex().row(); int newRow = (row + change + nrows) % nrows; if (newRow == row + change || !ke->isAutoRepeat()) setCurrentIndex(m_model->index(newRow)); return true; } } } else if (e->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast<QKeyEvent *>(e); switch (ke->key()) { case Qt::Key_N: case Qt::Key_P: // select next/previous completion - so don't pass on to editor if (ke->modifiers() == Qt::ControlModifier) forwardKeys = false; break; case Qt::Key_Escape: m_completionWidget->closeList(); return true; case Qt::Key_Right: case Qt::Key_Left: case Qt::Key_Home: case Qt::Key_End: // We want these navigation keys to work in the editor, so forward them break; case Qt::Key_Tab: case Qt::Key_Return: //independently from style, accept current entry if return is pressed if (qApp->focusWidget() == this) m_completionWidget->closeList(currentIndex()); return true; case Qt::Key_Up: m_explicitlySelected = true; if (!ke->isAutoRepeat() && currentIndex().row() == 0) { setCurrentIndex(model()->index(model()->rowCount()-1, 0)); return true; } forwardKeys = false; break; case Qt::Key_Down: m_explicitlySelected = true; if (!ke->isAutoRepeat() && currentIndex().row() == model()->rowCount()-1) { setCurrentIndex(model()->index(0, 0)); return true; } forwardKeys = false; break; case Qt::Key_Enter: case Qt::Key_PageDown: case Qt::Key_PageUp: forwardKeys = false; break; default: // if a key is forwarded, completion widget is re-opened and selected item is reset to first, // so only forward keys that insert text and refine the completed item forwardKeys = !ke->text().isEmpty(); break; } const CompletionPolicy policy = m_support->policy(); if (forwardKeys && policy != QuickFixCompletion) { if (ke->text().length() == 1 && currentIndex().isValid() && qApp->focusWidget() == this) { QChar typedChar = ke->text().at(0); const CompletionItem &item = m_model->itemAt(currentIndex()); if (item.collector->typedCharCompletes(item, typedChar)) { m_typedChar = typedChar; m_completionWidget->closeList(currentIndex()); return true; } } m_blockFocusOut = true; QApplication::sendEvent(m_editorWidget, e); m_blockFocusOut = false; // Have the completion support update the list of items m_support->complete(m_editor, policy, false); return true; } } return QListView::event(e); }
bool KCompletionBox::eventFilter( QObject *o, QEvent *e ) { int type = e->type(); QWidget *wid = qobject_cast<QWidget*>(o); if (o == this) { return false; } if (wid && wid == d->m_parent && (type == QEvent::Move || type == QEvent::Resize)) { hide(); return false; } if (wid && (wid->windowFlags() & Qt::Window) && type == QEvent::Move && wid == d->m_parent->window()) { hide(); return false; } if (type == QEvent::MouseButtonPress && (wid && !isAncestorOf(wid))) { if (!d->emitSelected && currentItem() && !qobject_cast<QScrollBar*>(o)) { Q_ASSERT(currentItem()); emit currentTextChanged(currentItem()->text() ); } hide(); e->accept(); return true; } if (wid && wid->isAncestorOf(d->m_parent) && isVisible()) { if ( type == QEvent::KeyPress ) { QKeyEvent *ev = static_cast<QKeyEvent *>( e ); switch ( ev->key() ) { case Qt::Key_Backtab: if ( d->tabHandling && (ev->modifiers() == Qt::NoButton || (ev->modifiers() & Qt::ShiftModifier)) ) { up(); ev->accept(); return true; } break; case Qt::Key_Tab: if ( d->tabHandling && (ev->modifiers() == Qt::NoButton) ) { down(); // #65877: Key_Tab should complete using the first // (or selected) item, and then offer completions again if (count() == 1) { KLineEdit* parent = qobject_cast<KLineEdit*>(d->m_parent); if (parent) { parent->doCompletion(currentItem()->text()); } else { hide(); } } ev->accept(); return true; } break; case Qt::Key_Down: down(); ev->accept(); return true; case Qt::Key_Up: // If there is no selected item and we've popped up above // our parent, select the first item when they press up. if ( !selectedItems().isEmpty() || mapToGlobal( QPoint( 0, 0 ) ).y() > d->m_parent->mapToGlobal( QPoint( 0, 0 ) ).y() ) up(); else down(); ev->accept(); return true; case Qt::Key_PageUp: pageUp(); ev->accept(); return true; case Qt::Key_PageDown: pageDown(); ev->accept(); return true; case Qt::Key_Escape: canceled(); ev->accept(); return true; case Qt::Key_Enter: case Qt::Key_Return: if ( ev->modifiers() & Qt::ShiftModifier ) { hide(); ev->accept(); // Consume the Enter event return true; } break; case Qt::Key_End: if ( ev->modifiers() & Qt::ControlModifier ) { end(); ev->accept(); return true; } break; case Qt::Key_Home: if ( ev->modifiers() & Qt::ControlModifier ) { home(); ev->accept(); return true; } default: break; } } else if ( type == QEvent::ShortcutOverride ) { // Override any accelerators that match // the key sequences we use here... QKeyEvent *ev = static_cast<QKeyEvent *>( e ); switch ( ev->key() ) { case Qt::Key_Down: case Qt::Key_Up: case Qt::Key_PageUp: case Qt::Key_PageDown: case Qt::Key_Escape: case Qt::Key_Enter: case Qt::Key_Return: ev->accept(); return true; break; case Qt::Key_Tab: case Qt::Key_Backtab: if ( ev->modifiers() == Qt::NoButton || (ev->modifiers() & Qt::ShiftModifier)) { ev->accept(); return true; } break; case Qt::Key_Home: case Qt::Key_End: if ( ev->modifiers() & Qt::ControlModifier ) { ev->accept(); return true; } break; default: break; } } else if ( type == QEvent::FocusOut ) { QFocusEvent* event = static_cast<QFocusEvent*>( e ); if (event->reason() != Qt::PopupFocusReason #ifdef Q_WS_WIN && (event->reason() != Qt::ActiveWindowFocusReason || QApplication::activeWindow() != this) #endif ) hide(); } } return KListWidget::eventFilter( o, e ); }