Example #1
0
void KisAlternateInvocationAction::end(QEvent *event)
{
    if (!event) return;

    QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);

    QMouseEvent targetEvent(*mouseEvent);

    switch (m_d->savedAction) {
    case KisTool::AlternatePickFgNode:
        targetEvent = QMouseEvent(QEvent::MouseButtonRelease, mouseEvent->pos(), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
        break;
    case KisTool::AlternateThird:
        targetEvent = QMouseEvent(QEvent::MouseButtonRelease, mouseEvent->pos(), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier | Qt::AltModifier);
        break;
    }

    inputManager()->toolProxy()->forwardEvent(
        KisToolProxy::END, m_d->savedAction, &targetEvent, event,
        inputManager()->lastTabletEvent(),
        inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));

    KisAbstractInputAction::end(event);
}
bool MoveDelegate::editorEvent(QEvent *event, QAbstractItemModel *, const QStyleOptionViewItem &option, const QModelIndex &index)
{
    QRect rect = option.rect;
    QRect rectLeft(rect.x() + rect.width()/4 - 8, rect.y() + rect.height()/2 - 5 , 30, 15);
    QRect rectRight(rect.x() + rect.width()*3/4 -8, rect.y() + rect.height()/2 - 5 , 30, 15);

    if (event->type() == QEvent::MouseMove) {
//        QMouseEvent* e =(QMouseEvent*)event;
    }

    if (event->type() == QEvent::MouseButtonRelease) {
        QMouseEvent* e =(QMouseEvent*)event;
        int row = index.row();
        if (rectLeft.contains(e->x(), e->y())) {
            emit left(row);
            return true;
        }
        else if(rectRight.contains(e->x(), e->y())){
            emit right(row);
            return true;
        }
    }
    return false;
}
bool Nepomuk::AnnotationDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
{
    if ( event->type() == QEvent::MouseButtonPress ) {
        QMouseEvent* me = static_cast<QMouseEvent*>( event );
        if ( me->button() == Qt::LeftButton ) {
            if ( plusRect( option ).contains( me->pos() ) ) {
                kDebug() << "Clicked plus";
                Annotation* anno = index.data( AnnotationModel::AnnotationRole ).value<Nepomuk::Annotation*>();
                anno->create( d->resource );
                delete anno;
                return true;
            }
            else if ( minusRect( option ).contains( me->pos() ) ) {
                kDebug() << "Clicked minus";
                Annotation* anno = index.data( AnnotationModel::AnnotationRole ).value<Nepomuk::Annotation*>();
                anno->setUserRelevance( 0.0 );
                delete anno;
                return true;
            }
        }
    }

    return false;
}
bool HelpBrowser::eventFilter(QObject *object, QEvent *event)
{
    if (object == mWebView) {
        switch (event->type()) {
        case QEvent::MouseButtonPress: {
            QMouseEvent * mouseEvent = static_cast<QMouseEvent*>(event);
            switch (mouseEvent->button()) {
            case Qt::XButton1:
                mWebView->pageAction(QWebPage::Back)->trigger();
                return true;

            case Qt::XButton2:
                mWebView->pageAction(QWebPage::Forward)->trigger();
                return true;

            default:
                break;
            }
            break;
        }
        case QEvent::ShortcutOverride: {
            QKeyEvent * kevent = static_cast<QKeyEvent*>(event);
            if ( kevent == QKeySequence::Copy ||
                 kevent == QKeySequence::Paste )
            {
                kevent->accept();
                return true;
            }
            break;
        }
        default:
            break;
        }
    }
    return false;
}
Example #5
0
bool ComboBoxItemDelegate::mouseReleased(QEvent * event)
{
    if (event->type() != QEvent::MouseButtonRelease)
        return false;

    QAbstractItemModel* model = mCombo->model();
    QMouseEvent *ev = static_cast<QMouseEvent*>(event);
    QModelIndex index = mCombo->view()->indexAt(ev->pos());
    QVariant removable = index.data(ITEM_REMOVABLE_ROLE);
    bool remove = true;
    if (removable.type() == QVariant::Bool)
        remove = removable.toBool();

    if (remove && mLastIndex == index && model && index.data(Qt::UserRole).toString() != INVALID_DATA) {
        QStyleOptionMenuItem opt = getStyleOption(mLastStyleOption, index);
        int height = opt.rect.height();
        if (ev->x() >= opt.rect.width()-height) {
            emit removeItem(index.row());
            return true;
        }
    }

    return false;
}
Example #6
0
//=============================================================================
//	eControl::paintEvent
//-----------------------------------------------------------------------------
bool eControl::event(QEvent* event)
{
	switch(event->type())
	{
	case QEvent::MouseButtonPress:
	case QEvent::MouseButtonRelease:
	case QEvent::MouseMove:
		{
			QMouseEvent* me = (QMouseEvent*)event;
			bool ok = event->type() == QEvent::MouseMove ? ((me->buttons() & Qt::LeftButton) != 0) : (me->button() == Qt::LeftButton);
			if(ok)
			{
				float x = float(me->x())/width();
				float y = float(me->y())/height();
				OnTouch(x, y, event->type() != QEvent::MouseButtonRelease, 0);
				return true;
			}
		}
		return true;
	case QEvent::TouchBegin:
	case QEvent::TouchUpdate:
	case QEvent::TouchEnd:
		{
			QTouchEvent* te = (QTouchEvent*)event;
			foreach(const QTouchEvent::TouchPoint& p, te->touchPoints())
			{
				float x = p.pos().x()/width();
				float y = p.pos().x()/height();
				OnTouch(x, y, p.state() != Qt::TouchPointReleased, p.id());
			}
		}
		return true;
	default:
		return QWidget::event(event);
	}
}
Example #7
0
bool RSButtonOnText::isEventForThis(QObject *obj, QEvent *event, QPoint &point)
{
	switch (event->type()) {
		case QEvent::MouseButtonPress://2
		case QEvent::MouseButtonRelease://3
		case QEvent::MouseButtonDblClick://4
		case QEvent::MouseMove://5
		{
			QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
			point = mouseEvent->pos();
		}
		break;
		case QEvent::ToolTip://110
		{
			QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
			point = helpEvent->globalPos();
		}
		break;
		default:
		return false;
	}

	if (!event->isAccepted()) return false;//Already other take this event (true by default)

	if (obj ==_textEditViewPort) {
		if (_textEdit){

			QTextCursor cursor = _textEdit->cursorForPosition(point);
			if ( (_textCursor->anchor() <= cursor.anchor())
			     && (cursor.position() <= _textCursor->anchor()+_lenght)){
				return true;
			}
		}
	}
	return false;
}
Example #8
0
bool CustomerView::eventFilter(QObject* label, QEvent* vt)
{
    if(label==m_ui->m_scrollAreaVisual)
    {
        /*if(vt->type() == QEvent::Resize)
        {
            resizeLabel();
        }*/
    }
    else if((label == m_label)&&
           ((vt->type() == QEvent::MouseButtonPress)||(vt->type() == QEvent::MouseButtonRelease)||(vt->type() == QEvent::MouseMove)))
    {
        QMouseEvent* evt = static_cast<QMouseEvent*>(vt);
        QPoint posOnLabel= evt->pos();


        int w = m_label->geometry().width();
        int h = m_label->geometry().height();

        qreal ratioW =  static_cast<qreal>(m_window->width())/ static_cast<qreal>(w);
        qreal ratioH =  static_cast<qreal>(m_window->height())/static_cast<qreal>(h);

        qreal x = (posOnLabel.x()) * ratioW;
        qreal y = (posOnLabel.y()) * ratioH;

        QPointF posOnQML(x,y);
        QMouseEvent* event = new QMouseEvent(evt->type(),posOnQML.toPoint(),evt->button(),evt->buttons(),evt->modifiers());

        QObject* root = m_engine->rootObjects().first();
        //QCoreApplication::sendEvent(m_window,event);
        QCoreApplication::sendEvent(root,event);
        //m_window->sendEvent(m_window->contentItem(),event);
        return true;
    }
    return false;
}
Example #9
0
void QwtPlotWidget::slotMouseReleased( const QMouseEvent &e)
{
  double x,y;
  char buf[100];

  int dx = 0;
  int dy = 0;
  QwtScaleWidget *awx = axisWidget(QwtPlot::yLeft);
  if(awx != NULL) dx = awx->width();
  QwtScaleWidget *awy = axisWidget(QwtPlot::xTop);
  if(awy != NULL) dy = awy->height();
  x = this->invTransform(QwtPlot::xBottom, e.pos().x() - dx);
  y = this->invTransform(QwtPlot::yLeft,   e.pos().y() - dy);
  sprintf( buf, "QPlotMouseReleased(%d,%f,%f)\n",id, x, y );
  tcp_send(s,buf,strlen(buf));
}
Example #10
0
bool FancyTabProxyStyle::eventFilter(QObject* o, QEvent* e)
{
    QTabBar* bar = qobject_cast<QTabBar*>(o);
    if (bar && (e->type() == QEvent::MouseMove || e->type() == QEvent::Leave)) {
        QMouseEvent* event = static_cast<QMouseEvent*>(e);
        const QString old_hovered_tab = bar->property("tab_hover").toString();
        const QString hovered_tab = e->type() == QEvent::Leave ? QString() : bar->tabText(bar->tabAt(event->pos()));
        bar->setProperty("tab_hover", hovered_tab);

        if (old_hovered_tab != hovered_tab) {
            bar->update();
        }
    }

    return false;
}
Example #11
0
bool GooeyDoubleSpinBox::eventFilter(QObject* object, QEvent* event)
{
	QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
	switch(event->type())
	{
	case QEvent::MouseButtonPress:
		if(mouseEvent->button() == Qt::LeftButton)
		{
			_lastMousePos = mouseEvent->globalPos();
		}
		break;
	case QEvent::MouseButtonRelease:
		if(mouseEvent->button() == Qt::LeftButton)
		{
			_lastMousePos = QPoint(); // Reset the point !
		}
		break;
	case QEvent::MouseMove:
		if(mouseEvent->buttons() & Qt::LeftButton)
		{
			QPoint pos = mouseEvent->globalPos();

			double dx = _spinBox->singleStep() * (pos.x() - _lastMousePos.x());

			if(mouseEvent->modifiers() & Qt::CTRL)
			{
				dx *= 2.0;
			}
			else if(mouseEvent->modifiers() & Qt::SHIFT)
			{
				dx *= 0.5;
			}

			_spinBox->setValue( _spinBox->value() + dx );

			// Update position !
			_lastMousePos = pos;
		}
		break;
	default:
		break;
	}
	return false;
}
Example #12
0
bool ptToolBox::eventFilter(QObject* ASender, QEvent* AEvent) {
  if (ASender == FHelpIcon && AEvent->type() == QEvent::MouseButtonRelease) {
    QMouseEvent* e = (QMouseEvent*)AEvent;
    if (e->button() == Qt::LeftButton) {
      QDesktopServices::openUrl(QUrl(FFilter->helpUri()));
      return true;
    } else {
      return false;
    }


  } else if (ASender == FHeaderWidget && AEvent->type() == QEvent::MouseButtonRelease) {
    QMouseEvent* hEvent = (QMouseEvent*)AEvent;
    if (hEvent->button() == Qt::LeftButton && hEvent->modifiers() == Qt::NoModifier) {
      toggleFolded();
      return true;

    } else if (hEvent->button() == Qt::LeftButton && hEvent->modifiers() == Qt::ControlModifier) {
      // toggle block
      createMenuActions();
      FBlockAction->activate(QAction::Trigger);
      return true;

    } else if (hEvent->button() == Qt::RightButton) {
      // context menu
      execContextMenu(hEvent->globalPos());
      return true;

    } else {
      return false;
    }


  } else {
    return QWidget::eventFilter(ASender, AEvent);
  }
}
Example #13
0
bool WebPage::event(QEvent *ev)
{
    QMouseEvent* mouseEvent = NULL;
    QWheelEvent* wheelEvent = NULL;
    QKeyEvent* keyEvent = NULL;
    
    QByteArray byteArray;
    QBuffer buffer(&byteArray);
    buffer.open(QIODevice::ReadWrite);

    QDataStream out(&buffer);

    out << (int) ev->type();
    
    switch (ev->type()) {
    case QEvent::MouseMove:
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonDblClick:
    case QEvent::MouseButtonRelease:
        if (OPNET::OpNetwork::instance()->isReplay() || OPNET::OpNetwork::instance()->isReplica())
            return false;
        mouseEvent = (static_cast<QMouseEvent*>(ev));
        out << mouseEvent->pos() << mouseEvent->globalPos()
            << (int) mouseEvent->button() << (int) mouseEvent->buttons()
            << (int) mouseEvent->modifiers();
        OPNET::OpNetwork::instance()->sendSysCall(MSG_LOG_USER_INPUT, (int) ev->type(), byteArray);
        break;
    case QEvent::Wheel:
        if (OPNET::OpNetwork::instance()->isReplay() || OPNET::OpNetwork::instance()->isReplica())
            return false;;
        wheelEvent = (static_cast<QWheelEvent*>(ev));
        out << wheelEvent->pos() << wheelEvent->globalPos()
            << wheelEvent->delta() << (int) wheelEvent->buttons()
            << (int) wheelEvent->modifiers() << (int) wheelEvent->orientation();
        OPNET::OpNetwork::instance()->sendSysCall(MSG_LOG_USER_INPUT, (int) ev->type(), byteArray);
        break;
    case QEvent::KeyPress:
    case QEvent::KeyRelease:
        if (OPNET::OpNetwork::instance()->isReplay() || OPNET::OpNetwork::instance()->isReplica())
            return false;
        keyEvent = (static_cast<QKeyEvent*>(ev));
        out << keyEvent->key() << (int) keyEvent->modifiers()
            << keyEvent->text() << keyEvent->isAutoRepeat()
            << (int) keyEvent->count();
        OPNET::OpNetwork::instance()->sendSysCall(MSG_LOG_USER_INPUT, (int) ev->type(), byteArray);
        break;
    default:
        break;
    }

    return QWebPage::event(ev);
}
bool scissor::eventFilter(QObject *obj, QEvent *event)
{
    if(qobject_cast<QLabel*>(obj)==ui->label &&event->type() == QEvent::MouseButtonPress)
    {
        cout<<"click"<<endl;
        if(Is_start)
        {
            Is_graphed = 0;
            if(!Init_seed)
            {
                seed_vector.clear();
                fullPath_vector.clear();
                shortPath_vector.clear();
                cout<<"init_seed"<<endl;
                Init_seed = 1;
            }
            QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);

            int x = mouseEvent->pos().y();
            int y =mouseEvent->pos().x();
            cout<<"mouse click "<<x<<"  "<<y<<endl;
            if(x < image.rows && y < image.cols)
                if(!Is_closed)
                    findPathGraph(x,y);
                else
                    if(Is_mask)
                        getMask(x,y);
            closeDetect(x,y);

        }
    }
    if (qobject_cast<QLabel*>(obj)==ui->label &&event->type() == QEvent::MouseMove)
    {

        QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);


        statusBar()->showMessage(QString("Mouse move (%1,%2)").arg(mouseEvent->pos().y()).arg(mouseEvent->pos().x()));
        if(Is_graphed == 1)
        {
            int x = mouseEvent->pos().y();
            int y = mouseEvent->pos().x();
            //cout<<"x  "<<x<<"y   "<<y<<endl;
            if(x < image.rows && y < image.cols && !Is_closed)
            {
                moveMouse(x,y);
                cout<<"move mouse"<<x<<"  " <<y <<endl;
            }
        }
    }
    return false;
}
Example #15
0
void EWAUserAction::execute( QWebView *webViewPtr ) const
{
    if( !webViewPtr )
    {
        return;
    }
    
    //EWAWebView *pEwaWebView = qobject_cast<EWAWebView*>( webViewPtr );
    //bool bNeedSetFocus = false;
    QEvent *pEventCopy = 0;
    
    if( isMouseEvent( m_pEvent->type() ) )
    {
        QMouseEvent *pSrcMouseEvent = static_cast<QMouseEvent *>( m_pEvent );
        
        QPoint clickCoords = pSrcMouseEvent->pos();
        
        pEventCopy = new QMouseEvent( 
            pSrcMouseEvent->type(), 
            clickCoords, 
            webViewPtr->mapToGlobal( clickCoords ), 
            pSrcMouseEvent->button(), 
            pSrcMouseEvent->buttons(),
            pSrcMouseEvent->modifiers() );
        
        
    }
    
    else if( isKeyEvent( m_pEvent->type() ) )
    {
        QKeyEvent *pSrcKeyEvent = static_cast<QKeyEvent*>( m_pEvent );
        
        pEventCopy = new QKeyEvent( 
            pSrcKeyEvent->type(), 
            pSrcKeyEvent->key(), 
            pSrcKeyEvent->modifiers(),
            pSrcKeyEvent->text(), 
            pSrcKeyEvent->isAutoRepeat(), 
            pSrcKeyEvent->count() );
    }
     
     if( pEventCopy )
     {
        QSize dstSz = getWebViewSize();
        if( webViewPtr->page()->preferredContentsSize() != dstSz )
        {
            webViewPtr->page()->setPreferredContentsSize( dstSz );
        }
        
        EWAApplication::postEvent( webViewPtr, pEventCopy );
     }
}
bool KDockSplitter::eventFilter(QObject *o, QEvent *e)
{
  QMouseEvent *mev;
  bool handled = false;
  int factor = (mHighResolution)? 10000:100;

  switch (e->type()) {
    case QEvent::MouseMove:
      mev= (QMouseEvent*)e;
      child0->setUpdatesEnabled(mOpaqueResize);
      child1->setUpdatesEnabled(mOpaqueResize);
      if (orientation == Horizontal) {
        if (!mOpaqueResize) {
          int position = checkValue( mapFromGlobal(mev->globalPos()).y() );
          divider->move( 0, position );
        } else {
          xpos = factor * checkValue( mapFromGlobal(mev->globalPos()).y() ) / height();
          resizeEvent(0);
          divider->repaint(true);
        }
      } else {
        if (!mOpaqueResize) {
          int position = checkValue( mapFromGlobal(QCursor::pos()).x() );
          divider->move( position, 0 );
        } else {
          xpos = factor * checkValue( mapFromGlobal( mev->globalPos()).x() ) / width();
          resizeEvent(0);
          divider->repaint(true);
        }
      }
      handled= true;
      break;
    case QEvent::MouseButtonRelease:
      child0->setUpdatesEnabled(true);
      child1->setUpdatesEnabled(true);
      mev= (QMouseEvent*)e;
      if (orientation == Horizontal){
        xpos = factor* checkValue( mapFromGlobal(mev->globalPos()).y() ) / height();
        resizeEvent(0);
        divider->repaint(true);
      } else {
        xpos = factor* checkValue( mapFromGlobal(mev->globalPos()).x() ) / width();
        resizeEvent(0);
        divider->repaint(true);
      }
      handled= true;
      break;
    default:
      break;
  }
  return (handled) ? true : QWidget::eventFilter( o, e );
}
Example #17
0
bool TabBar::eventFilter(QObject *obj, QEvent *event)
{
  if (event->type() == QEvent::MouseButtonPress) {
    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    if (tabAt(mouseEvent->pos()) < 0)
      return false;
    if (mouseEvent->button() & Qt::MiddleButton) {
      emit closeTab(tabAt(mouseEvent->pos()));
    } else if (mouseEvent->button() & Qt::LeftButton) {
      if (tabAt(QPoint(mouseEvent->pos().x(), 0)) == 0)
        tabFixed_ = true;
      else
        tabFixed_ = false;
    }
  } else if (event->type() == QEvent::MouseMove) {
    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    if (mouseEvent->buttons() & Qt::LeftButton) {
      if ((tabAt(QPoint(mouseEvent->pos().x()-78, 0)) <= 0) || tabFixed_)
        return true;
    }
  }

  return QTabBar::eventFilter(obj, event);
}
bool RobotManualPlacementLayer::handleEvent(QObject *, QEvent *e)
{
    if (!mVisible || !mReferenceCoords.isValid())
        return false;

    if (e->type() == QEvent::MouseButtonPress
        || e->type() == QEvent::MouseMove
        || e->type() == QEvent::MouseButtonRelease)
    {
        QMouseEvent *event = static_cast<QMouseEvent*>(e);
        qreal mouseLon, mouseLat;
        bool isAboveMap = mMap->geoCoordinates(event->x(), event->y(),
                                               mouseLon, mouseLat, GeoDataCoordinates::Radian);
        if (!isAboveMap)
        {
            mMouseCoords = GeoDataCoordinates();
            mTracking = false;
            return false;
        }

        bool consumed = false;
        if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::LeftButton)
        {
            mTracking = true;
            consumed = true;
        }

        if (mTracking)
        {
            mMouseCoords.setLongitude(mouseLon);
            mMouseCoords.setLatitude(mouseLat);
            emit orientationUpdate(MapLibraryHelpers::transformCoords(mMouseCoords));
        }

        if (event->type() == QEvent::MouseButtonRelease && event->button() == Qt::LeftButton)
        {
            mMouseCoords = GeoDataCoordinates();
            mTracking = false;
            return true;
        }

        return consumed;
    }
    return false;
}
Example #19
0
bool Renderer::eventFilter(QObject *object, QEvent *event) {
	if (object == image_label_ && event->type() == QEvent::MouseButtonPress) {
        QMouseEvent *keyEvent = static_cast<QMouseEvent*>(event);
        if (keyEvent->button() == Qt::LeftButton && print_zp_) {
			// Sets the fixed frequency of the zoneplate to the corresponding
			// frequency of the click location
			double dist = sqrt(keyEvent->x()*keyEvent->x() + keyEvent->y()*keyEvent->y());
			dist = zone_plate_.Size() * dist / std::max(Height(), Width());
			freq_spin_->setValue(dist);
            return true;
        } else
            return false;
    }
    return false;
}
void Interactor2DMeasure::UpdateCursor( QEvent* event, QWidget* wnd )
{
  RenderView2D* view = ( RenderView2D* )wnd;
  if ( wnd->hasFocus() )
  {
    if ( event->type() == QEvent::MouseButtonPress ||
         event->type() == QEvent::MouseButtonRelease ||
         event->type() == QEvent::MouseMove)
    {
      QMouseEvent* e = ( QMouseEvent* )event;
      if ( ( ( e->button() == Qt::MidButton || e->button() == Qt::RightButton ) && !m_bEditing ) ||
           ( ( e->modifiers() & CONTROL_MODIFIER) && (e->modifiers() & Qt::ShiftModifier) ) )
      {
        Interactor2D::UpdateCursor( event, wnd );
        return;
      }
      else if ( ( !m_bEditing && !m_bDrawing && view->GetRegion( e->x(), e->y() ) ) ||
                ( m_bEditing && m_nPointIndex < 0 ) )
      {
        wnd->setCursor( CursorFactory::CursorGrab );
      }
      else
      {
        if ( m_nAction == MM_Line )
        {
          wnd->setCursor( CursorFactory::CursorMeasureLine );
        }
        else if ( m_nAction == MM_Rectangle )
        {
          wnd->setCursor( CursorFactory::CursorMeasureRectangle );
        }
        else if ( m_nAction == MM_Polyline || m_nAction == MM_Spline )
        {
          wnd->setCursor( CursorFactory::CursorMeasurePolyline );
        }
      }
    }
  }
  else
  {
    Interactor2D::UpdateCursor( event, wnd );
  }
}
Example #21
0
bool CursorWindow::handleMouseEvent(QEvent *ev)
{
    bool handledEvent = false;
    static int inhere=0;
    if ( !inhere ) {
	inhere++;
	if ( m_view ) {
	    if ( ev->type() >= QEvent::MouseButtonPress && ev->type() <= QEvent::MouseMove ) {
		QMouseEvent *e = (QMouseEvent*)ev;
		QPoint gp = e->globalPos();
		QPoint vp = m_view->mapFromGlobal(gp);
		QPoint sp = skin->mapFromGlobal(gp);
		if ( e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonDblClick ) {
		    if ( m_view->rect().contains(vp) )
			mouseRecipient = m_view;
		    else if ( skin->parentWidget()->geometry().contains(gp) )
			mouseRecipient = skin;
		    else
			mouseRecipient = 0;
		}
		if ( mouseRecipient ) {
		    setPos(gp);
		    QMouseEvent me(e->type(),mouseRecipient==skin ? sp : vp,gp,e->button(),e->buttons(),e->modifiers());
		    QApplication::sendEvent(mouseRecipient, &me);
		} else if ( !skin->parentWidget()->geometry().contains(gp) ) {
		    hide();
		} else {
		    setPos(gp);
		}
		if ( e->type() == QEvent::MouseButtonRelease )
		    mouseRecipient = 0;
		handledEvent = true;
	    }
	}
	inhere--;
    }
    return handledEvent;
}
bool MInverseMouseArea::eventFilter(QObject *obj, QEvent *ev)
{
    Q_UNUSED(obj);
    if (!m_enabled || !isVisible())
        return false;
    switch (ev->type()) {
    case QEvent::MouseButtonPress: {
        QMouseEvent *me = static_cast<QMouseEvent *>(ev);
        QPointF mappedPos = me->screenPos();//??is mapping to root item needed still
        m_pressed = !isUnderMouse() && !isClickedOnSoftwareInputPanel();

        if (m_pressed) {
            m_lastsceenPos = me->screenPos();
            emit pressedOutside(mappedPos.x(), mappedPos.y());
        }
        break;
    }
    case QEvent::MouseMove: {
        if (m_pressed) {
            QMouseEvent *me = static_cast<QMouseEvent *>(ev);
            const QPointF &dist = me->screenPos() - m_lastsceenPos;

            if (dist.x() * dist.x() + dist.y() * dist.y() > FlickThresholdSquare)
                m_pressed = false;
        }
        break;
    }
    case QEvent::MouseButtonRelease: {
        QMouseEvent *me = static_cast<QMouseEvent *>(ev);
        QPointF mappedPos = mapToRootItem(me->screenPos());

        if (m_pressed) {
            m_pressed = false;
            emit clickedOutside(mappedPos.x(), mappedPos.y());
        }
        break;
    }
    default:
        break;
    }

    return false;
}
bool KisInputManager::Private::EventEater::eventFilter(QObject* target, QEvent* event )
{
    if ((hungry && (event->type() == QEvent::MouseMove ||
                    event->type() == QEvent::MouseButtonPress ||
                    event->type() == QEvent::MouseButtonRelease))
        //  || (peckish && (event->type() == QEvent::MouseButtonPress))
        )
    {
        // Chow down
        if (KisTabletDebugger::instance()->debugEnabled()) {
            QString pre = QString("[BLOCKED]");
            QMouseEvent *ev = static_cast<QMouseEvent*>(event);
            dbgTablet << KisTabletDebugger::instance()->eventToString(*ev,pre);
        }
        peckish = false;
        return true;
    }
    else if ((event->type() == QEvent::MouseButtonPress) /* Need to scrutinize */ &&
             (!savedEvent)) /* Otherwise we enter a loop repeatedly storing the same event */
    {
        QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
        // Pocket the event and decide what to do with it later
        // savedEvent = *(static_cast<QMouseEvent*>(event));
        savedEvent = new QMouseEvent(QEvent::MouseButtonPress,
                                     mouseEvent->pos(),
                                     mouseEvent->windowPos(),
                                     mouseEvent->screenPos(),
                                     mouseEvent->button(),
                                     mouseEvent->buttons(),
                                     mouseEvent->modifiers());
        savedTarget = target;
        mouseEvent->accept();
        return true;
    }

    return false; // All clear - let this one through!
}
Example #24
0
bool  calibrationtestwidget::eventFilter ( QObject * watched, QEvent * event ){
    if(watched!=frame)
        return false;
    if(event->type()==QEvent::MouseButtonPress){
        QMouseEvent *mevent = static_cast<QMouseEvent *>(event);
        if(mevent->button() ==Qt::LeftButton){
            oldpoint = mevent->pos();
            paintpath.moveTo(oldpoint.x(),oldpoint.y());
            candrawline = TRUE;
            return TRUE;
        }
    }
    if(candrawline&&(event->type()==QEvent::MouseMove)){
        QMouseEvent *mevent = static_cast<QMouseEvent *>(event);
        if(mevent->buttons() ==Qt::LeftButton){
            newpoint = mevent->pos();
            frame->update();
            return TRUE;
        }
    }
    if(event->type()==QEvent::MouseButtonRelease){
        QMouseEvent *mevent = static_cast<QMouseEvent *>(event);
        if(mevent->buttons() ==Qt::LeftButton){
            candrawline = FALSE;
            return TRUE;
        }
    }
    if(event->type()==QEvent::Paint){
        //QPaintEvent *pevent = static_cast<QPaintEvent *>(event);
        QPainter painter(frame);
        //painter.setClipRect(oldpoint.x(),oldpoint.y(),newpoint.x(),newpoint.y());
        paintpath.lineTo(newpoint);
        painter.drawPath(paintpath);
        return FALSE;
    }
return FALSE;
}
Example #25
0
void PreviewPlot2D::onHZoom(const QMouseEvent& e)
{
    // some shortcuts
    int axl= QwtPlot::yLeft;
 
	// Don't invert any scales which aren't inverted
    int y1 = qwtMin(memPoint.y(), e.pos().y());
    int y2 = qwtMax(memPoint.y(), e.pos().y());
        
	// limit selected area to a minimum of 11x11 points
	int lim = 5 - (y2 - y1) / 2;
	if (lim > 0)
	{
		y1 -= lim;
		y2 += lim;
	}
       
	// Set fixed scales
	if(!autoscaleY)
		pPlot->setAxisScale(axl, pPlot->invTransform(axl,y1), pPlot->invTransform(axl,y2));
	pPlot->replot();
}
Example #26
0
bool MainWindow::eventFilter( QObject * object, QEvent * event )
{
    QScrollArea * scrollArea = ui->scrollArea;
    if ( object == scrollArea )
    {
        if ( event->type() == QEvent::MouseButtonPress )
        {
            QMouseEvent * mouseEvent = static_cast < QMouseEvent * > ( event );
            if ( mouseEvent->button() == Qt::LeftButton )
            {
                lastPos = mouseEvent->pos();

                if( scrollArea->horizontalScrollBar()->isVisible() || scrollArea->verticalScrollBar()->isVisible() )
                    scrollArea->setCursor( Qt::ClosedHandCursor );
                else
                    scrollArea->setCursor( Qt::ArrowCursor );
            }

        }else if ( event->type() == QEvent::MouseMove )
        {
            QMouseEvent *mouseEvent = static_cast < QMouseEvent * > ( event );

            if ( mouseEvent->buttons() == Qt::LeftButton )
            {
                lastPos -= mouseEvent->pos();

                int hValue = scrollArea->horizontalScrollBar()->value();
                int vValue = scrollArea->verticalScrollBar()->value();

                scrollArea->horizontalScrollBar()->setValue( lastPos.x() + hValue );
                scrollArea->verticalScrollBar()->setValue( lastPos.y() + vValue );

                lastPos = mouseEvent->pos();
            }

        }else if ( event->type() == QEvent::MouseButtonRelease )
            scrollArea->setCursor( Qt::ArrowCursor );
    }

    return QWidget::eventFilter(object, event);
}
Example #27
0
bool SearchPopup::eventFilter(QObject* obj, QEvent* event)
{
	bool filter = false;
	if (obj == widget_) {
		if (event->type() == QEvent::FocusOut) {
			filter = true; // keep focus displayed on underlying widget
		}
		else if ( (event->type() == QEvent::MouseButtonPress) ||
		          (event->type() == QEvent::Wheel) ||
		          ((event->type() == QEvent::InputMethod) && (event->spontaneous())) ) {
			close();
		}
	}
	else if (obj == window_) {
		if ( (event->type() == QEvent::ApplicationActivate) ||
		     (event->type() == QEvent::ApplicationDeactivate) ||
		     (event->type() == QEvent::MouseButtonPress) ||
		     (event->type() == QEvent::Move) ||
		     (event->type() == QEvent::Resize) ||
		     (event->type() == QEvent::Shortcut) /*||
		     (event->type() == QEvent::WindowActivate) ||
		     (event->type() == QEvent::WindowDeactivate)*/ ) {
			close();
		}
	}
	else if (obj == listView_->viewport()) {
		if (event->type() == QEvent::MouseMove) {
			QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
			if ((origMousePos_ - mouseEvent->globalPos()).manhattanLength() >= QApplication::startDragDistance()) {
				QMouseEvent changed(
					QEvent::MouseMove,
					mouseEvent->pos(),
					(mouseEvent->button() != Qt::NoButton) ? mouseEvent->button() : Qt::LeftButton,
					mouseEvent->buttons() | Qt::LeftButton, mouseEvent->modifiers()
				);
				*mouseEvent = changed;
			}
		}
	}
	return filter;
}
Example #28
0
//===============================================================
bool MouseElementDeleter::eventFilter(QObject *widget, QEvent *e) {
  QMouseEvent *qMouseEv = (QMouseEvent *) e;

  if(qMouseEv != NULL) {
    node tmpNode;
    edge tmpEdge;
    ElementType type;
    GlMainWidget *glMainWidget = (GlMainWidget *) widget;

    if(e->type() == QEvent::MouseMove) {
      if (glMainWidget->doSelect(qMouseEv->x(), qMouseEv->y(), type, tmpNode, tmpEdge)) {
        glMainWidget->setCursor(QCursor(QPixmap(":/i_del.png")));
      }
      else {
        glMainWidget->setCursor(Qt::ArrowCursor);
      }

      return false;
    }
    else if (e->type() == QEvent::MouseButtonPress && qMouseEv->button()==Qt::LeftButton) {
      if (glMainWidget->doSelect(qMouseEv->x(), qMouseEv->y(), type, tmpNode, tmpEdge)) {
        Observable::holdObservers();
        Graph* graph = glMainWidget->getGraph();
        // allow to undo
        graph->push();

        switch(type) {
        case NODE:
          graph->delNode(tmpNode);
          break;

        case EDGE:
          graph->delEdge(tmpEdge);
          break;
        }

        glMainWidget->redraw();
        Observable::unholdObservers();
        return true;
      }
    }
  }

  return false;
}
Example #29
0
/*!
 *  Method to emulate QGraphicsView::ScrollHandDrag option for both mouse buttons
 *  Therefore, user can navigate using right mouse button
 */
bool BaseViewer::scrollOnMouse(QEvent *e)
{
    // !!! DO NOT SCROLL ON RIGHT BUTTON BECAUSE OF CONTEXT MENU
    QMouseEvent * mouseEvent = static_cast<QMouseEvent*>(e);
    if (mouseEvent)
    {
        if (mouseEvent->type() == QEvent::MouseButtonPress &&
                mouseEvent->button() == Qt::LeftButton)
        {
            _handScrolling = true;
            _ui->_view->viewport()->setCursor(Qt::ClosedHandCursor);
            _lastMouseEvent = storeMouseEvent(mouseEvent);
            return true;
        }
        else if (mouseEvent->type() == QEvent::MouseMove)
        {
            if (_handScrolling)
            {
                QScrollBar *hBar = _ui->_view->horizontalScrollBar();
                QScrollBar *vBar = _ui->_view->verticalScrollBar();
                QPoint delta = mouseEvent->pos() - _lastMouseEvent.pos();
                hBar->setValue(hBar->value() + (_ui->_view->isRightToLeft() ? delta.x() : -delta.x()));
                vBar->setValue(vBar->value() - delta.y());
                _lastMouseEvent = storeMouseEvent(mouseEvent);
                return true;
            }
        }
        else if (mouseEvent->type() == QEvent::MouseButtonRelease &&
                    mouseEvent->button() == Qt::LeftButton)
        {

            _handScrolling = false;
            _ui->_view->viewport()->setCursor(_cursor);
            centerOnAtZoom(_zoomLevel);
            return true;
        }
    }
    return false;
}
Example #30
0
bool UBMousePressFilter::eventFilter(QObject *obj, QEvent *event)
{
    const bool isMousePress = event->type() == QEvent::MouseButtonPress;
    const bool isMouseRelease = event->type() == QEvent::MouseButtonRelease;
    const bool isMouseMove = event->type() == QEvent::MouseMove;

    if (isMousePress)
    {
        QMouseEvent * mouseEvent = static_cast<QMouseEvent *>(event);

        if (mouseEvent)
        {
            if (mPendingEvent)
            {
                delete mPendingEvent;
            }

            mPendingEvent = new QMouseEvent(QEvent::MouseButtonDblClick,
                mouseEvent->pos(), mouseEvent->globalPos(),
                mouseEvent->button(), mouseEvent->buttons(),
                mouseEvent->modifiers());

            mObject = obj;

            QTimer::singleShot(1000, this, SLOT(mouseDownElapsed()));
        }
    }
    else if (isMouseRelease || isMouseMove)
    {
        if (mPendingEvent)
        {
            QTabletEvent * tabletEvent = static_cast<QTabletEvent *>(event);
            QPoint point = tabletEvent->globalPos() - mPendingEvent->globalPos();
            if (isMouseRelease || point.manhattanLength() > QApplication::startDragDistance())
            {
                delete mPendingEvent;
                mPendingEvent = 0;
                mObject = 0;
            }
        }
    }

    return false;
}