Example #1
0
bool QAccel::eventFilter( QObject *, QEvent *e )
{
    if ( enabled && e->type() == Event_Accel &&
	 parent() && parent()->isWidgetType() &&
	 ((QWidget *)parent())->isVisibleToTLW() ) {
	QKeyEvent *k = (QKeyEvent *)e;
	int key = k->key();
	if ( k->state() & ShiftButton )
	    key |= SHIFT;
	if ( k->state() & ControlButton )
	    key |= CTRL;
	if ( k->state() & AltButton )
	    key |= ALT;
	QAccelItem *item = find_key(aitems,key,k->ascii());
	if ( item && item->enabled ) {
	    if ( item->signal )
		item->signal->activate();
	    else
		emit activated( item->id );
	    k->accept();
	    return TRUE;
	}
    }
    return FALSE;
}
Example #2
0
void PWidget::eventKey(QObject *, QEvent *e)  
{
  PukeMessage pm;
  widgetId wI;

  QKeyEvent *ke = Q_KEY_EVENT(e);
  
  wI = widgetIden();
  pm.iCommand = - e->type() - 1020; // 1020 offset for events
  pm.iWinId = wI.iWinId;
  pm.iArg = 0;

  // special cArg handling
  pm.iTextSize = 3*sizeof(int);
  int *icArg = new int[3];
  icArg[0] = ke->key();
  icArg[1] = ke->ascii();
  icArg[2] = ke->state();
  pm.cArg = (char *) icArg;

  emit outputMessage(wI.fd, &pm);

  delete[] icArg;
  
}
Example #3
0
bool QAccel::eventFilter( QObject *o, QEvent *e )
{
    if ( e->type() == QEvent::Reparent && d->watch == o ) {
        repairEventFilter();
    } else  if ( d->enabled &&
                 ( e->type() == QEvent::Accel ||
                   e->type() == QEvent::AccelAvailable) &&
                 d->watch && d->watch->isVisible() ) {
        QKeyEvent *k = (QKeyEvent *)e;
        int key = k->key();
        if ( k->state() & ShiftButton )
            key |= SHIFT;
        if ( k->state() & ControlButton )
            key |= CTRL;
        if ( k->state() & AltButton )
            key |= ALT;
        QAccelItem *item = find_key( d->aitems, key, k->text()[0] );
        if ( key == Key_unknown )
            item = 0;
#ifndef QT_NO_WHATSTHIS
        bool b = QWhatsThis::inWhatsThisMode();
#else
        bool b = FALSE;
#endif
        if ( item && ( item->enabled || b )) {
            if (e->type() == QEvent::Accel) {
                if ( b && !d->ignorewhatsthis ) {
#ifndef QT_NO_WHATSTHIS
                    QWhatsThis::leaveWhatsThisMode( item->whatsthis );
#endif
                }
                else if ( item->enabled ) {
                    if ( item->signal )
                        item->signal->activate();
                    else
                        emit activated( item->id );
                }
            }
            k->accept();
            return TRUE;
        }
    }
    return QObject::eventFilter( o, e );
}
bool ossimQtImageControllerZoomEventFilter::eventFilter(QObject* /*obj*/,
                                                        QEvent* event)
{
   if(!theController) return false;
   
   if(!theController->getImageWidget()) return false;
   
   switch(event->type())
   {
      case QEvent::KeyPress:
      {
         QKeyEvent* keyEvent = (QKeyEvent*)event;
         if(keyEvent->stateAfter() & Qt::ShiftButton)
         {
	    theController->setZoomModeOut();
         }
         if(keyEvent->stateAfter() & Qt::ControlButton)
         {
            thePanToOverrideFlag = true;
         }
         break;
      }
      case QEvent::KeyRelease:
      {
         QKeyEvent* keyEvent = (QKeyEvent*)event;
         if(keyEvent->state() & Qt::ShiftButton)
         {
            theController->setZoomModeIn();
         }
         if(keyEvent->state() & Qt::ControlButton)
         {
            thePanToOverrideFlag = false;
         }
         break;
      }
      default:
      {
         break;
      }
   }
   
   return false;
}
/*!
    \reimp
 */
bool QTabWidget::eventFilter( QObject *o, QEvent * e)
{
    if ( o == this ) {
	if ( e->type() == QEvent::LanguageChange || e->type() == QEvent::LayoutHint ) {
	    d->dirty = TRUE;
	    setUpLayout();
	    updateGeometry();
	} else if ( e->type() == QEvent::KeyPress ) {
	    QKeyEvent *ke = (QKeyEvent*) e;
	    if ( ( ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab ) &&
		 count() > 1 &&
		 ke->state() & Qt::ControlButton ) {
		int page = currentPageIndex();
		if ( ke->key() == Qt::Key_Backtab || ke->state() & Qt::ShiftButton ) {
		    page--;
		    if ( page < 0 )
			page = count() - 1;
		} else {
		    page++;
		    if ( page >= count() )
			page = 0;
		}
		setCurrentPage( page );
		if ( !qApp->focusWidget() )
		    d->tabs->setFocus();
		return TRUE;
	    }
	}

    } else if ( o == d->stack ) {
	if ( e->type() == QEvent::ChildRemoved
	     && ( (QChildEvent*)e )->child()->isWidgetType() ) {
	    removePage( (QWidget*)  ( (QChildEvent*)e )->child() );
	    return TRUE;
	} else if ( e->type() == QEvent::LayoutHint ) {
	    updateGeometry();
	}
    }
    return FALSE;
}
Example #6
0
bool Window::eventFilter(QObject*, QEvent* event) {
	if (event->type() != QEvent::KeyPress) {
		return false;
	}

	QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
	if (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down) {
		QKeyEvent* newEvent = new QKeyEvent(
			keyEvent->type(), keyEvent->key(), keyEvent->ascii(),
			keyEvent->state(), keyEvent->text());
		QApplication::postEvent(mView, newEvent);
		return true;
	}

	return false;
}
Example #7
0
bool KexiBlobTableEdit::eventFilter( QObject *o, QEvent *e )
{
	if (o == d->popup && e->type()==QEvent::KeyPress) {
		QKeyEvent* ke = static_cast<QKeyEvent*>(e);
		const int state = ke->state();
		const int k = ke->key();
		if (   (state==Qt::NoButton && (k==Qt::Key_Tab || k==Qt::Key_Left || k==Qt::Key_Right))
		    || (state==Qt::ShiftButton && k==Qt::Key_Backtab)
		   )
		{
			d->popup->hide();
	    QApplication::sendEvent( this, ke ); //re-send to move cursor
			return true;
		}
	}
	return false;
}
Example #8
0
// Reimplemented 
bool QmvList::eventFilter( QObject *o, QEvent *e )
{
    if ( !o || !e )
	return TRUE;

    QmvItem *i = (QmvItem*)currentItem();
    if ( o != this &&e->type() == QEvent::KeyPress )
    {
	QKeyEvent *ke = (QKeyEvent*)e;
	if ( ( ke->key() == Key_Up || ke->key() == Key_Down ) &&
	     ( o != this || o != viewport() ) &&
	     !( ke->state() & ControlButton ) )
        {
	    QApplication::sendEvent( this, (QKeyEvent*)e );
	    return TRUE;
	} else
            if ( ( !o->inherits( "QLineEdit" ) ||
                   ( o->inherits( "QLineEdit" ) && ( (QLineEdit*)o )->isReadOnly() ) ) &&
                 i && i->hasSubItems() )
            {
                if ( !i->isOpen() &&
                     ( ke->key() == Key_Plus ||
                       ke->key() == Key_Right ))
                    i->setOpen( TRUE );
                else
                    if ( i->isOpen() &&
                         ( ke->key() == Key_Minus ||
                           ke->key() == Key_Left ) )
                        i->setOpen( FALSE );
            } else
                if ( ( ke->key() == Key_Return || ke->key() == Key_Enter ) && o->inherits( "QComboBox" ) )
                {
                    QKeyEvent ke2( QEvent::KeyPress, Key_Space, 0, 0 );
                    QApplication::sendEvent( o, &ke2 );
                    return TRUE;
                }
    }
    
    return QListView::eventFilter( o, e );
}
bool KLSHistoryCombo::eventFilter( QObject *o, QEvent *ev )
{
    // Handle Ctrl+Del/Backspace etc better than the Qt widget, which always
    // jumps to the next whitespace.
    QLineEdit *edit = lineEdit();
    if ( o == edit )
    {
        int type = ev->type();
        if ( type == QEvent::KeyPress )
        {
            QKeyEvent *e = static_cast<QKeyEvent *>( ev );

            if ( e->key() == Key_Return || e->key() == Key_Enter )
            {
                //m_modifier = e->state();
                return false;
            }

            int delete_word_back = KStdAccel::deleteWordBack().keyCodeQt();
            int delete_word_forward = KStdAccel::deleteWordForward().keyCodeQt();

            if ( KKey( e ) == KKey(delete_word_back) ||
                    KKey( e ) == KKey(delete_word_forward) ||
                    ((e->state() & ControlButton) &&
                     (e->key() == Key_Left || e->key() == Key_Right) ) )
            {
                selectWord(e);
                e->accept();
                return true;
            }
        }

        else if ( type == QEvent::MouseButtonDblClick )
        {
            edit->selectAll();
            return true;
        }
    }
    return KComboBox::eventFilter( o, ev );
}
Example #10
0
// ----------------------------------------------------------------------
bool QmvTable::eventFilter( QObject *o, QEvent *e )
{
#ifdef QMVTABLE_DEBUG
    const char *name = o ? o->name() : "NO_OBJECT";
    const char *classname = o ? o->className() : "NO_CLASS";
    int etype = e ? e->type() : -9999;
//    qDebug( "%-20.20s::eventFilter(%20.20s/%20.20s, %6d)", "QmvTable", name, classname, etype );
#endif
    // test disabing this eventfilter while tracing crash - Issue#324
    // return QTable::eventFilter( o, e );
    if ( !o || !e )
  	return true;

    if ( e->type() == QEvent::KeyPress )
    {
        QKeyEvent *ke = (QKeyEvent *) e;

            // keyboard row select.
        if ( ke->key() == Key_Return || ke->key() == Key_Enter )
            if  ( ke->state() & AltButton )
            {
                    // the mouse point is a fake - TODO: decide what to make it.
                emit clicked( currentRow(), currentColumn(), 1, QPoint(0,0) );
                return true;
            } else {
                activateNextCell();
                return true;
            }
        
    }

        // focus out - do nothing
        // TODO:  popup a reminder to do something
    if ( e->type() == QEvent::FocusOut )
        return true;
    
    return QTable::eventFilter( o, e );
}
Example #11
0
/*
    \internal
    Checks for possible accelerators, if no widget
    ate the keypres, or we are in the middle of a
    partial key sequence.
*/
bool QAccelManager::dispatchAccelEvent( QWidget* w, QKeyEvent* e )
{
#ifndef QT_NO_STATUSBAR
    // Needs to be declared and used here because of "goto doclash"
    QStatusBar* mainStatusBar = 0;
#endif

    // Modifiers can NOT be accelerators...
    if ( e->key() >= Key_Shift &&
	 e->key() <= Key_Alt )
	 return FALSE;

    SequenceMatch result = Qt::NoMatch;
    QKeySequence tocheck, partial;
    QAccelPrivate* accel = 0;
    QAccelItem* item = 0;
    QAccelPrivate* firstaccel = 0;
    QAccelItem* firstitem = 0;
    QAccelPrivate* lastaccel = 0;
    QAccelItem* lastitem = 0;
    
    QKeyEvent pe = *e;
    int n = -1;
    int hasShift = (e->state()&Qt::ShiftButton)?1:0;
    bool identicalDisabled = FALSE;
    bool matchFound = FALSE;
    do {
	accel = accels.first();
	matchFound = FALSE;
	while ( accel ) {
	    if ( correctSubWindow( w, accel ) ) {
		if ( accel->enabled ) {
		    item = accel->aitems.last();
		    while( item ) {
			if ( Qt::Identical == (result = match( &pe, item, tocheck )) ) {
			    if ( item->enabled ) {
				if ( !firstaccel ) {
				    firstaccel = accel;
				    firstitem = item;
				}
				lastaccel = accel;
				lastitem = item;
				n++;
				matchFound = TRUE;
				if ( n > QMAX(clash,0) )
				    goto doclash;
			    } else {
				identicalDisabled = TRUE;
			    }
			}
			if ( item->enabled && Qt::PartialMatch == result ) {
			    partial = tocheck;
			    matchFound = TRUE;
			}
			item = accel->aitems.prev();
		    }
		} else {
		    item = accel->aitems.last();
		    while( item ) {
			if ( Qt::Identical == match( &pe, item, tocheck ) )
			    identicalDisabled = TRUE;
			item = accel->aitems.prev();
		    }
		}
	    }
	    accel = accels.next();
	}
	pe = QKeyEvent( QEvent::Accel, pe.key(), pe.ascii(), pe.state()&~Qt::ShiftButton, pe.text() );
    } while ( hasShift-- && !matchFound && !identicalDisabled );

#ifndef QT_NO_STATUSBAR
    mainStatusBar = (QStatusBar*) w->topLevelWidget()->child( 0, "QStatusBar" );
#endif
    if ( n < 0 ) { // no match found
	currentState = partial.count() ? PartialMatch : NoMatch;
#ifndef QT_NO_STATUSBAR
	// Only display message if we are, or were, in a partial match
	if ( mainStatusBar && (PartialMatch == currentState || intermediate.count() ) ) {
	    if ( currentState == Qt::PartialMatch ) {
		mainStatusBar->message( (QString)partial + ", ...", 0 );
	    } else if (!identicalDisabled) {
		QString message = QAccel::tr("%1, %2 not defined").
		    arg( (QString)intermediate ).
		    arg( QKeySequence::encodeString( e->key() | translateModifiers(e->state()) ) );
		mainStatusBar->message( message, 2000 );
		// Since we're a NoMatch, reset the clash count
		clash = -1;
	    } else {
	    	mainStatusBar->clear();
	    }
	}
#endif

	bool eatKey = (PartialMatch == currentState || intermediate.count() );
	intermediate = partial;
	if ( eatKey )
	    e->accept();
	return eatKey;
    } else if ( n == 0 ) { // found exactly one match
	clash = -1; // reset
#ifndef QT_NO_STATUSBAR
	if ( currentState == Qt::PartialMatch && mainStatusBar )
		mainStatusBar->clear();
#endif
	currentState = Qt::NoMatch; // Free sequence keylock
	intermediate = QKeySequence();
	lastaccel->activate( lastitem );
	e->accept();
	return TRUE;
    }

 doclash: // found more than one match
#ifndef QT_NO_STATUSBAR
    if ( !mainStatusBar ) // if "goto doclash", we need to get statusbar again.
	mainStatusBar = (QStatusBar*) w->topLevelWidget()->child( 0, "QStatusBar" );
#endif

    QString message = QAccel::tr( "Ambiguous \"%1\" not handled" ).arg( (QString)tocheck );
    if ( clash >= 0 && n > clash ) { // pick next  match
	intermediate = QKeySequence();
	currentState = Qt::NoMatch; // Free sequence keylock
	clash++;
#ifndef QT_NO_STATUSBAR
	if ( mainStatusBar &&
	     !lastitem->signal &&
	     !(lastaccel->parent->receivers( "activatedAmbiguously(int)" )) )
	    mainStatusBar->message( message, 2000 );
#endif
	lastaccel->activateAmbiguously( lastitem );
    } else { // start (or wrap) with the first matching
	intermediate = QKeySequence();
	currentState = Qt::NoMatch; // Free sequence keylock
	clash = 0;
#ifndef QT_NO_STATUSBAR
	if ( mainStatusBar &&
	     !firstitem->signal &&
	     !(firstaccel->parent->receivers( "activatedAmbiguously(int)" )) )
	    mainStatusBar->message( message, 2000 );
#endif
	firstaccel->activateAmbiguously( firstitem );
    }
    e->accept();
    return TRUE;
}
Example #12
0
bool OCompletionBox::eventFilter( QObject *o, QEvent *e )
{
    int type = e->type();

    if ( o == d->m_parent ) {
        if ( isVisible() ) {
            if ( type == QEvent::KeyPress ) {
                QKeyEvent *ev = static_cast<QKeyEvent *>( e );
                switch ( ev->key() ) {
                    case Key_BackTab:
                        if ( d->tabHandling ) {
                            up();
                            ev->accept();
                            return true;
                        }
                        break;
                    case Key_Tab:
                        if ( d->tabHandling ) {
                            down(); // Only on TAB!!
                            ev->accept();
                            return true;
                        }
                        break;
                    case Key_Down:
                        down();
                        ev->accept();
                        return true;
                    case Key_Up:
                        up();
                        ev->accept();
                        return true;
                    case Key_Prior:
                        pageUp();
                        ev->accept();
                        return true;
                    case Key_Next:
                        pageDown();
                        ev->accept();
                        return true;
                    case Key_Escape:
                        cancelled();
                        ev->accept();
                        return true;
                    case Key_Enter:
                    case Key_Return:
                        if ( ev->state() & ShiftButton ) {
                            hide();
                            ev->accept();  // Consume the Enter event
                            return true;
                        }
                        break;
                    default:
                        break;
                }
            }
            else if ( type == QEvent::AccelOverride ) {
                // Override any acceleartors that match
                // the key sequences we use here...
                QKeyEvent *ev = static_cast<QKeyEvent *>( e );
                switch ( ev->key() ) {
                    case Key_Tab:
                    case Key_BackTab:
                    case Key_Down:
                    case Key_Up:
                    case Key_Prior:
                    case Key_Next:
                    case Key_Escape:
                    case Key_Enter:
                    case Key_Return:
                      ev->accept();
                      return true;
                      break;
                    default:
                        break;
                }
            }

            // parent loses focus or gets a click -> we hide
            else if ( type == QEvent::FocusOut || type == QEvent::Resize ||
                      type == QEvent::Close || type == QEvent::Hide ||
                      type == QEvent::Move ) {
                hide();
            }
            else if ( type == QEvent::Move )
                move( d->m_parent->mapToGlobal(QPoint(0, d->m_parent->height())));
            else if ( type == QEvent::Resize )
                resize( sizeHint() );
        }
    }

    // any mouse-click on something else than "this" makes us hide
    else if ( type == QEvent::MouseButtonPress ) {
        QMouseEvent *ev = static_cast<QMouseEvent *>( e );
        if ( !rect().contains( ev->pos() )) // this widget
            hide();
    }

    return OListBox::eventFilter( o, e );
}
Example #13
0
bool QUimInputContext::filterEvent( const QEvent *event )
{
#ifdef ENABLE_DEBUG
    // qDebug("filterEvent");
#endif

    int type = event->type();

    if ( type != QEvent::KeyPress &&
            type != QEvent::KeyRelease )
        return FALSE;

    QKeyEvent *keyevent = ( QKeyEvent * ) event;
    int qkey = keyevent->key();

    int modifier = 0;
    if ( keyevent->state() & Qt::ShiftButton )
        modifier |= UMod_Shift;
    if ( keyevent->state() & Qt::ControlButton )
        modifier |= UMod_Control;
    if ( keyevent->state() & Qt::AltButton )
        modifier |= UMod_Alt;
#if defined(Q_WS_X11)
    if ( keyevent->state() & Qt::MetaButton )
        modifier |= UMod_Meta;
#endif

    int key = 0;
    if ( isascii( qkey ) && isprint( qkey ) )
    {
        int ascii = keyevent->ascii();
        if ( isalpha( ascii ) )
        {
            key = ascii;  // uim needs lower/upper encoded key
        }
        else
        {
            if ( keyevent->state() & Qt::ControlButton &&
                 ( ascii >= 0x01 && ascii <= 0x1a ) )
                if ( keyevent->state() & Qt::ShiftButton )
                    key = ascii + 0x40;
                else
                    key = ascii + 0x60;
            else
                key = qkey;
        }
    }
    else if ( qkey == Qt::Key_unknown )
    {
        QString text = keyevent->text();
        if ( !text.isNull() )
        {
            QChar s = text.at(0);
            key = unicodeToUKey ( s.unicode() );
        }
        else
        {
            key = UKey_Other;
        }
    }
    else
    {
        if ( qkey >= Qt::Key_F1 && qkey <= Qt::Key_F35 )
        {
            key = qkey - Qt::Key_F1 + UKey_F1;
        }
        else if ( qkey >= Qt::Key_Dead_Grave && qkey <= Qt::Key_Dead_Horn )
        {
            key = qkey - Qt::Key_Dead_Grave + UKey_Dead_Grave;
        }
        else if ( qkey >= Qt::Key_Kanji && qkey <= Qt::Key_Eisu_toggle )
        {
            key = qkey - Qt::Key_Kanji + UKey_Kanji;
        }
        else if ( qkey >= Qt::Key_Hangul && qkey <= Qt::Key_Hangul_Special )
        {
            key = qkey - Qt::Key_Hangul + UKey_Hangul;
        }
        else
        {
            switch ( qkey )
            {
            case Qt::Key_Tab: key = UKey_Tab; break;
            case Qt::Key_BackSpace: key = UKey_Backspace; break;
            case Qt::Key_Escape: key = UKey_Escape; break;
            case Qt::Key_Delete: key = UKey_Delete; break;
            case Qt::Key_Return: key = UKey_Return; break;
            case Qt::Key_Left: key = UKey_Left; break;
            case Qt::Key_Up: key = UKey_Up; break;
            case Qt::Key_Right: key = UKey_Right; break;
            case Qt::Key_Down: key = UKey_Down; break;
            case Qt::Key_Prior: key = UKey_Prior; break;
            case Qt::Key_Next: key = UKey_Next; break;
            case Qt::Key_Home: key = UKey_Home; break;
            case Qt::Key_End: key = UKey_End; break;
            case Qt::Key_Multi_key: key = UKey_Multi_key; break;
            case Qt::Key_Mode_switch: key = UKey_Mode_switch; break;
            case Qt::Key_Codeinput: key = UKey_Codeinput; break;
            case Qt::Key_SingleCandidate: key = UKey_SingleCandidate; break;
            case Qt::Key_MultipleCandidate: key = UKey_MultipleCandidate; break;
            case Qt::Key_PreviousCandidate: key = UKey_PreviousCandidate; break;
            case Qt::Key_Shift: key = UKey_Shift_key; break;
            case Qt::Key_Control: key = UKey_Control_key; break;
            case Qt::Key_Alt: key = UKey_Alt_key; break;
            case Qt::Key_Meta: key = UKey_Meta_key; break;
            case Qt::Key_CapsLock: key = UKey_Caps_Lock; break;
            case Qt::Key_NumLock: key = UKey_Num_Lock; break;
            case Qt::Key_ScrollLock: key = UKey_Scroll_Lock; break;
            default: key = UKey_Other;
            }
        }
    }

    int notFiltered;
    if ( type == QEvent::KeyPress )
    {
        notFiltered = uim_press_key( m_uc, key, modifier );
#ifdef Q_WS_X11
        if ( notFiltered )
            return mCompose->handle_qkey( keyevent );
#else
        if ( notFiltered )
            return FALSE;
#endif
    }
    else if ( type == QEvent::KeyRelease )
    {
        notFiltered = uim_release_key( m_uc, key, modifier );
#ifdef Q_WS_X11
        if ( notFiltered )
            return mCompose->handle_qkey( keyevent );
#else
        if ( notFiltered )
            return FALSE;
#endif
    }

    return TRUE;
}
Example #14
0
/*! Reimplementation of the \c QObject function. Always returns \p false (meaning event is \e not
  handled and should be forwarded to the \p qglviewer).

  When EventRecorder isRecording(), the following \c QEvent::type are recorded in an internal data
  structure: \c KeyPress, \c KeyRelease, \c MouseButtonPress, \c MouseButtonRelease, \c
  MouseButtonDblClick, \c MouseMove, \c Wheel and \c Timer (used by QGLViewer::animate()). Does
  nothing when isRecording() is \c false.

  You may overload this method to filter other \c QEvent::type (your implementation should probably
  call this function).

  Other specific events can be recorded using recordFrameState() and recordCustomEvent(). */
bool EventRecorder::eventFilter(QObject *, QEvent *e)
{
  if (isRecording())
    {
      bool record = true;
      switch (e->type())
	{
	case QEvent::KeyPress:
	case QEvent::KeyRelease:
	  {
	    QKeyEvent* ke = (QKeyEvent*)(e);
	    eventRecords_[eventIndex_].event.keyEvent = new QKeyEvent(e->type(), ke->key(), ke->ascii(), int(ke->state()));
	    break;
	  }
	case QEvent::MouseButtonPress:
	case QEvent::MouseButtonRelease:
	case QEvent::MouseButtonDblClick:
	case QEvent::MouseMove:
	  {
	    QMouseEvent* me = (QMouseEvent*)(e);
	    eventRecords_[eventIndex_].event.mouseEvent = new QMouseEvent(e->type(), me->pos(), int(me->button()), int(me->state()));
	    break;
	  }
	case QEvent::Wheel:
	  {
	    QWheelEvent* we = (QWheelEvent*)(e);
	    eventRecords_[eventIndex_].event.wheelEvent = new QWheelEvent(we->pos(), we->delta(), int(we->state()));
	    break;
	  }
	case QEvent::Timer:
	  {
	    eventRecords_[eventIndex_].event.keyEvent = NULL; // or any other pointer
	    break;
	  }
	default:
	    record = false;
	  break;
	}

      if (record)
	{
	  eventRecords_[eventIndex_].type = e->type();
	  eventRecords_[eventIndex_].time = time_.elapsed();
	  eventIndex_++;
	}
    }
  return false;
}
Example #15
0
bool TEWidget::eventFilter( QObject *obj, QEvent *e )
{
#if 0
// because QT4 using  QShortcut, so I diable this function
  if ( (e->type() == QEvent::Accel ||
       e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this )
  {
      static_cast<QKeyEvent *>( e )->ignore();
      return true;
  }
#endif
  if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
      return FALSE; // not us
  if ( e->type() == QEvent::Wheel)
  {
    QApplication::sendEvent(scrollbar, e);
  }

#ifdef FAKE_CTRL_AND_ALT
    static bool control = FALSE;
    static bool alt = FALSE;
    // Has a keyboard with no CTRL and ALT keys, but we fake it:
    bool dele=FALSE;
    if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
  QKeyEvent* ke = (QKeyEvent*)e;
  bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
  switch (ke->key()) {
      case Key_F9: // let this be "Control"
    control = keydown;
    e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
    dele=TRUE;
    break;
      case Key_F13: // let this be "Alt"
    alt = keydown;
    e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
    dele=TRUE;
    break;
      default:
    if ( control ) {
        int a = toupper(ke->ascii())-64;
        if ( a >= 0 && a < ' ' ) {
      e = new QKeyEvent(e->type(), ke->key(),
        a, ke->state()|ControlButton, QChar(a,0));
      dele=TRUE;
        }
    }
    if ( alt ) {
        e = new QKeyEvent(e->type(), ke->key(),
        ke->ascii(), ke->state()|AltButton, ke->text());
        dele=TRUE;
    }
  }
    }
#endif

  if ( e->type() == QEvent::KeyPress )
  {
    QKeyEvent* ke = (QKeyEvent*)e;

    actSel=0; // Key stroke implies a screen update, so TEWidget won't
              // know where the current selection is.

    emit keyPressedSignal(ke); // expose
    ke->accept();
#ifdef FAKE_CTRL_AND_ALT
    if ( dele ) delete e;
#endif
    return true;               // stop the event
  }
  if ( e->type() == QEvent::Enter )
  {
    QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
      this, SLOT(onClearSelection()) );
  }
  if ( e->type() == QEvent::Leave )
  {
    QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
      this, SLOT(onClearSelection()) );
  }
  return QFrame::eventFilter( obj, e );
}
Example #16
0
bool KKbdAccessExtensions::eventFilter( QObject *o, QEvent *e )
{
    if ( e->type() == QEvent::KeyPress ) {
        // TODO: This permits only a single-key shortcut.  For example, Alt+S,R would not work.
        // If user configures a multi-key shortcut, it is undefined what will happen here.
        // It would be better to handle these as KShortcut activate() signals, but the problem
        // is that once a QDockWindow is undocked and has focus, the KShortcut activate() signals
        // don't fire anymore.
        KShortcut fwdSc = d->fwdAction->shortcut();
        KShortcut revSc = d->revAction->shortcut();
        KShortcut accessKeysSc = d->accessKeysAction->shortcut();
        QKeyEvent* kev = dynamic_cast<QKeyEvent *>(e);
        KKey k = KKey(kev);
        KShortcut sc = KShortcut(k);
        // kdDebug() << "KKbdAccessExtensions::eventFilter: Key press " << sc << endl;
        if (!d->accessKeyLabels) {
            if (sc == fwdSc) {
                nextHandle();
                return true;
            }
            if (sc == revSc) {
                prevHandle();
                return true;
            }
        }
        if (d->panel) {
            if (k == KKey(Key_Escape))
                exitSizing();
            else
                resizePanelFromKey(kev->key(), kev->state());
            // Eat the key.
            return true;
        }
        if (sc == accessKeysSc && !d->panel) {
            if (d->accessKeyLabels) {
                delete d->accessKeyLabels;
                d->accessKeyLabels = 0;
            } else
                displayAccessKeys();
            return true;
        }
        if (d->accessKeyLabels) {
            if (k == KKey(Key_Escape)) {
                delete d->accessKeyLabels;
                d->accessKeyLabels = 0;
            } else
                handleAccessKey(kev);
            return true;
        }
        return false;
    }
    else if (d->icon->isActive && e->type() == QEvent::MouseButtonPress) {
        exitSizing();
        return true;
    }
    else if (d->accessKeyLabels && e->type() == QEvent::MouseButtonPress) {
        delete d->accessKeyLabels;
        d->accessKeyLabels = 0;
        return true;
    }
/*    else if (e->type() == QEvent::MouseMove && d->icon->isActive) {
        // Lock mouse cursor down.
        showIcon();
        dynamic_cast<QMouseEvent *>(e)->accept();
        return true;
    }*/
    else if (e->type() == QEvent::MouseMove && d->icon->isActive && d->panel) {
        // Resize according to mouse movement.
        QMouseEvent* me = dynamic_cast<QMouseEvent *>(e);
        QSize s = d->icon->delta();
        int dx = s.width();
        int dy = s.height();
        resizePanel(dx, dy, me->state());
        me->accept();
        showIcon();
        return true;
    }
    else if (e->type() == QEvent::Resize && d->panel && o == d->panel) {
        // TODO: This doesn't always work.
        showIcon();
    }
    return false;
}
Example #17
0
/******************************************************************************
* Receives events destined for the spin widget or for the edit field.
*/
bool SpinBox::eventFilter(QObject* obj, QEvent* e)
{
	if (obj == editor())
	{
		if (e->type() == QEvent::KeyPress)
		{
			// Up and down arrow keys step the value
			QKeyEvent* ke = (QKeyEvent*)e;
			int key = ke->key();
			if (key == Qt::Key_Up  ||  key == Qt::Key_Down)
			{
				if (mReadOnly)
					return true;    // discard up/down arrow keys
				int step;
				if ((ke->state() & (Qt::ShiftButton | Qt::AltButton)) == Qt::ShiftButton)
				{
					// Shift stepping
					int val = value();
					if (key == Qt::Key_Up)
						step = mLineShiftStep - val % mLineShiftStep;
					else
						step = - ((val + mLineShiftStep - 1) % mLineShiftStep + 1);
				}
				else
					step = (key == Qt::Key_Up) ? mLineStep : -mLineStep;
				addValue(step, false);
				return true;
			}
		}
#if KDE_IS_VERSION(3,1,90)
		else if (e->type() == QEvent::Leave)
		{
			if (mEdited)
				interpretText();
		}
#endif
	}
	else
	{
		int etype = e->type();    // avoid switch compile warnings
		switch (etype)
		{
			case QEvent::MouseButtonPress:
			case QEvent::MouseButtonDblClick:
			{
				QMouseEvent* me = (QMouseEvent*)e;
				if (me->button() == Qt::LeftButton)
				{
					// It's a left button press. Set normal or shift stepping as appropriate.
					if (mReadOnly)
						return true;   // discard the event
					mCurrentButton = whichButton(me->pos());
					if (mCurrentButton == NO_BUTTON)
						return true;
					bool shift = (me->state() & (Qt::ShiftButton | Qt::AltButton)) == Qt::ShiftButton;
					if (setShiftStepping(shift))
						return true;     // hide the event from the spin widget
					return false;    // forward event to the destination widget
				}
				break;
			}
			case QEvent::MouseButtonRelease:
			{
				QMouseEvent* me = (QMouseEvent*)e;
				if (me->button() == Qt::LeftButton  &&  mShiftMouse)
				{
					setShiftStepping(false);    // cancel shift stepping
					return false;    // forward event to the destination widget
				}
				break;
			}
			case QEvent::MouseMove:
			{
				QMouseEvent* me = (QMouseEvent*)e;
				if (me->state() & Qt::LeftButton)
				{
					// The left button is down. Track which spin button it's in.
					if (mReadOnly)
						return true;   // discard the event
					int newButton = whichButton(me->pos());
					if (newButton != mCurrentButton)
					{
						// The mouse has moved to a new spin button.
						// Set normal or shift stepping as appropriate.
						mCurrentButton = newButton;
						bool shift = (me->state() & (Qt::ShiftButton | Qt::AltButton)) == Qt::ShiftButton;
						if (setShiftStepping(shift))
							return true;     // hide the event from the spin widget
					}
					return false;    // forward event to the destination widget
				}
				break;
			}
			case QEvent::KeyPress:
			case QEvent::KeyRelease:
			case QEvent::AccelOverride:      // this is needed to receive Shift presses!
			{
				QKeyEvent* ke = (QKeyEvent*)e;
				int key   = ke->key();
				int state = ke->state();
				if ((state & Qt::LeftButton)
				&&  (key == Qt::Key_Shift  ||  key == Qt::Key_Alt))
				{
					// The left mouse button is down, and the Shift or Alt key has changed
					if (mReadOnly)
						return true;   // discard the event
					state ^= (key == Qt::Key_Shift) ? Qt::ShiftButton : Qt::AltButton;    // new state
					bool shift = (state & (Qt::ShiftButton | Qt::AltButton)) == Qt::ShiftButton;
					if (!shift && mShiftMouse  ||  shift && !mShiftMouse)
					{
						// The effective shift state has changed.
						// Set normal or shift stepping as appropriate.
						if (setShiftStepping(shift))
							return true;     // hide the event from the spin widget
					}
				}
				break;
			}
		}
	}
	return QSpinBox::eventFilter(obj, e);
}
Example #18
0
//     My own version of the table's actions
//    In principle it does the same as QTable, but
//       deletes selected cells
//      closes application on ESCAPE
bool MTable::eventFilter( QObject *o, QEvent *e )
{
    if ( !o || !e )
	return QScrollView::eventFilter( o, e );

    //QWidget *editorWidget = cellWidget( currentRow(), currentColumn() );

    switch ( e->type() ) {
    case QEvent::KeyPress:
	if ( !isEditing() ) {
                  QKeyEvent *ke = (QKeyEvent*)e;
	    if ( ke->key() == Key_Escape ) {
                           QApplication::sendEvent( parentWidget ( FALSE ) , e );
		return TRUE;
	    }

	    if ( ke->key() == Key_Return || ke->key() == Key_Enter ) {
		if ( currentRow() >= numRows() - 1 ){
		    setUpdatesEnabled( false );
		    setNumRows( numRows() + 10 );
		    setUpdatesEnabled( true );
		}
	        activateNextCell();
                ensureCellVisible ( currentRow(), currentColumn() );
		return TRUE;
	    }

	    if ( ke->key() == Key_Delete ) {
	            if (numSelections() > 0) {
		    QTableSelection ts = selection( currentSelection() );
		    for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){
			for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
                                         clearCell( irow, icol );
		      }
		    }
		    setCurrentCell ( ts.anchorRow(), ts.anchorCol() );
		    clearSelection ( TRUE );
		}
	              else {
                                 clearCell( currentRow(), currentColumn() );
	              }
		return TRUE;
	    }
	    if ( ke->key() == Key_C && ( ke->state() & ControlButton ) == ControlButton ) {
	              QString cellText;
		 itemCopy.clear();
		if (numSelections() > 0) {
	                  QTableSelection ts;
		    ts = selection( currentSelection() );
		    for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
		      for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){
		             cellText = text( irow, icol );
                                         if ( !cellText.isEmpty() )
                                              itemCopy.push_back( cellText.latin1() );
		             else
                                              itemCopy.push_back( "" );
		      }
		    }
		}
		else {
	                   cellText = text( currentRow(), currentColumn() );
                                 if ( !cellText.isEmpty() )
                                              itemCopy.push_back( cellText.latin1() );
                                 else      itemCopy.push_back( "" );
		}
		return TRUE;
	    }
	    if ( ke->key() == Key_V && ( ke->state() & ControlButton ) == ControlButton ) {
		if ( numSelections() > 0 && itemCopy.size() > 0 ) {
		    QTableSelection ts = selection( currentSelection() );
		    uint icount;
		    for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
		       for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){
		             //icount = (icol - ts.leftCol())*(ts.bottomRow() - ts.topRow()+1) + irow-ts.topRow();
		             icount = (irow - ts.topRow())*(ts.rightCol() - ts.leftCol()+1) + icol-ts.leftCol();
                                         if ( icount < itemCopy.size() )
                                            setText( irow, icol, (itemCopy[icount]).c_str() );
		      }
		    }
		}
		else {
		    if ( itemCopy.size() > 0 ) // there was not selection, copy first item only
		         setText( currentRow(), currentColumn(), (itemCopy[0]).c_str() );
		}
		return TRUE;
	    }
	    if ( ke->key() == Key_X && ( ke->state() & ControlButton ) == ControlButton ) {
		QString cellText;
		if (numSelections() > 0) {
		    itemCopy.clear();
		   QTableSelection ts;
		    ts = selection( currentSelection() );
		    for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
		      for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){
		             cellText = text( irow, icol );
                                         if ( !cellText.isEmpty() )
                                              itemCopy.push_back( cellText.latin1() );
		             else
                                              itemCopy.push_back( "" );
                                         clearCell( irow, icol );
		      }
		    }
		    setCurrentCell ( ts.anchorRow(), ts.anchorCol() );
		    clearSelection ( TRUE );
		}
		else {
	                   cellText = text( currentRow(), currentColumn() );
                                 if ( !cellText.isEmpty() )
                                              itemCopy.push_back( cellText.latin1() );
                                 else      itemCopy.push_back( "" );
                                clearCell( currentRow(), currentColumn() );
		}
		return TRUE;
	    }

	    if ( currentColumn() == 0 &&
	         ctype == ComboBox   &&
                       ke->key() != Key_Left  && ke->key() != Key_Right &&
                       ke->key() != Key_Up  && ke->key() != Key_Down &&
                       ke->key() != Key_Control && ke->key() != Key_Alt &&
                       ke->key() != Key_Shift ) {
		//QApplication::beep ();
		keyPressEvent( (QKeyEvent*)e );
		return true;
	    }
	}
        else{
            QKeyEvent *ke = (QKeyEvent*)e;
	    if ( ke->key() == Key_Return || ke->key() == Key_Enter ) {
                stopEditing();
		if ( currentRow() >= numRows() - 1 ){
		    setUpdatesEnabled( false );
		    setNumRows( numRows() + 10 );
		    setUpdatesEnabled( true );
		}
                //else {stopEditing();}
                activateNextCell();
		return true;
	    }
        }
        break;
    default:
	break;
    }

    return QTable::eventFilter( o, e ) ;
}
Example #19
0
bool KuickShow::eventFilter( QObject *o, QEvent *e )
{
    if ( m_delayedRepeatItem ) // we probably need to install an eventFilter over
	{
        return true;    // kapp, to make it really safe
	}

    bool ret = false;
    int eventType = e->type();
    QKeyEvent *k = 0L;
    if ( eventType == QEvent::KeyPress )
        k = static_cast<QKeyEvent *>( e );

    if ( k ) {
        if ( KStdAccel::quit().contains( KKey( k ) ) ) {
            saveSettings();
            deleteAllViewers();
            FileCache::shutdown();
            ::exit(0);
        }
        else if ( KStdAccel::help().contains( KKey( k ) ) ) {
            appHelpActivated();
            return true;
        }
    }


    ImageWindow *window = dynamic_cast<ImageWindow*>( o );

    if ( window ) {
        // The XWindow used to display Imlib's image is being resized when
        // switching images, causing enter- and leaveevents for this
        // ImageWindow, leading to the cursor being unhidden. So we simply
        // don't pass those events to KCursor to prevent that.
        if ( eventType != QEvent::Leave && eventType != QEvent::Enter )
            KCursor::autoHideEventFilter( o, e );

        m_viewer = window;
        QString img;
        KFileItem *item = 0L;      // the image to be shown
        KFileItem *item_next = 0L; // the image to be cached

        if ( k ) { // keypress
            ret = true;
            int key = k->key();

            // Key_Shift shouldn't load the browser in nobrowser mode, it
            // is used for zooming in the imagewindow
            // Key_Alt shouldn't either - otherwise Alt+F4 doesn't work, the
            // F4 gets eaten (by NetAccess' modal dialog maybe?)

            if ( !fileWidget )
            {
                if ( key != Key_Escape && key != Key_Shift && key != Key_Alt )
                {
                    KuickFile *file = m_viewer->currentFile();
//                    QFileInfo fi( m_viewer->filename() );
//                    start.setPath( fi.dirPath( true ) );
                    initGUI( file->url().upURL() );

                    // the fileBrowser will list the start-directory
                    // asynchronously so we can't immediately continue. There
                    // is no current-item and no next-item (actually no item
                    // at all). So we tell the browser the initial
                    // current-item and wait for it to tell us when it's ready.
                    // Then we will replay this KeyEvent.
                    delayedRepeatEvent( m_viewer, k );

                    // OK, once again, we have a problem with the now async and
                    // sync KDirLister :( If the startDir is already cached by
                    // KDirLister, we won't ever get that finished() signal
                    // because it is emitted before we can connect(). So if
                    // our dirlister has a rootFileItem, we assume the
                    // directory is read already and simply call
                    // slotReplayEvent() without the need for the finished()
                    // signal.

                    // see slotAdvanceImage() for similar code
                    if ( fileWidget->dirLister()->isFinished() )
                    {
                        if ( fileWidget->dirLister()->rootItem() )
                        {
                            fileWidget->setCurrentItem( file->url().fileName() );
                            QTimer::singleShot( 0, this, SLOT( slotReplayEvent()));
                        }
                        else // finished, but no root-item -- probably an error, kill repeat-item!
                        {
                            abortDelayedEvent();
                        }
                    }
                    else // not finished yet
                    {
                        fileWidget->setInitialItem( file->url().fileName() );
                        connect( fileWidget, SIGNAL( finished() ),
                                 SLOT( slotReplayEvent() ));
                    }

                    return true;
                }

                return KMainWindow::eventFilter( o, e );
            }

            // we definitely have a fileWidget here!

            KKey kkey( k );
            if ( key == Key_Home || KStdAccel::home().contains( kkey ) )
            {
                item = fileWidget->gotoFirstImage();
                item_next = fileWidget->getNext( false );
            }

            else if ( key == Key_End || KStdAccel::end().contains( kkey ) )
            {
                item = fileWidget->gotoLastImage();
                item_next = fileWidget->getPrevious( false );
            }

            else if ( fileWidget->actionCollection()->action("delete")->shortcut().contains( key ))
            {
                kdDebug() << "WOW, deletion happens here!" << endl;
//      KFileItem *cur = fileWidget->getCurrentItem( false );
                (void) fileWidget->getCurrentItem( false );
                item = fileWidget->getNext( false ); // don't move
                if ( !item )
                    item = fileWidget->getPrevious( false );
                KFileItem it( KFileItem::Unknown, KFileItem::Unknown,
                              m_viewer->url() );
                KFileItemList list;
                list.append( &it );
                if ( fileWidget->del(list, window,
                                     (k->state() & ShiftButton) == 0) == 0L )
                    return true; // aborted deletion

                // ### check failure asynchronously and restore old item?
                fileWidget->setCurrentItem( item );
            }

            else if ( m_toggleBrowserAction->shortcut().contains( key ) )
            {
                toggleBrowser();
                return true; // don't pass keyEvent
            }

            else
                ret = false;


            if ( FileWidget::isImage( item ) ) {
//                QString filename;
//                KIO::NetAccess::download(item->url(), filename, this);
                m_viewer->showNextImage( item->url() );

                if ( kdata->preloadImage && item_next ) { // preload next image
                    if ( FileWidget::isImage( item_next ) )
                        m_viewer->cacheImage( item_next->url() );
                }

                ret = true; // don't pass keyEvent
            }
        } // keyPressEvent on ImageWindow


        // doubleclick closes image window
        // and shows browser when last window closed via doubleclick
        else if ( eventType == QEvent::MouseButtonDblClick )
        {
            QMouseEvent *ev = static_cast<QMouseEvent*>( e );
            if ( ev->button() == LeftButton )
            {
                if ( s_viewers.count() == 1 )
                {
                    if ( !fileWidget )
                    {
//                        KURL start;
//                        QFileInfo fi( window->filename() );
//                        start.setPath( fi.dirPath( true ) );
                        initGUI( window->currentFile()->url().fileName() );
                    }
                    show();
                    raise();
                }

                window->close( true );

                ev->accept();
                ret = true;
            }
        }

    } // isA ImageWindow


    if ( ret )
        return true;

    return KMainWindow::eventFilter( o, e );
}