コード例 #1
0
ファイル: kis_tool_proxy.cpp プロジェクト: ChrisJong/krita
KoPointerEvent KisToolProxy::convertEventToPointerEvent(QEvent *event, const QPointF &docPoint, bool *result)
{
    switch (event->type()) {
    case QEvent::TabletPress:
    case QEvent::TabletRelease:
    case QEvent::TabletMove:
    {
        *result = true;
        QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
        KoPointerEvent ev(tabletEvent, docPoint);
        ev.setTabletButton(Qt::LeftButton);
        return ev;
    }
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonDblClick:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseMove:
    {
        *result = true;
        QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
        return KoPointerEvent(mouseEvent, docPoint);
    }
    default:
        ;
    }

    *result = false;
    QMouseEvent fakeEvent(QEvent::MouseMove, QPoint(),
                          Qt::NoButton, Qt::NoButton,
                          Qt::NoModifier);

    return KoPointerEvent(&fakeEvent, QPointF());
}
コード例 #2
0
ファイル: MapperGLCanvas.cpp プロジェクト: flv0/mapmap
void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event)
{
  Q_UNUSED(event);

  // Wrap-up dragging the scene with middle button.
  if (event->buttons() & Qt::MiddleButton)
  {
    QMouseEvent fakeEvent(event->type(), event->pos(), event->globalPos(),
        Qt::LeftButton, event->buttons() & ~Qt::LeftButton, event->modifiers());
    QGraphicsView::mouseReleaseEvent(&fakeEvent);
    setDragMode(QGraphicsView::NoDrag);
    setCursor(Qt::ArrowCursor);
  }
//  // Click on vertex ==> select the vertex.
//  if ((event->buttons() & Qt::LeftButton) && _mousePressedOnVertex)
//  {
//  }
  if (_mousePressedOnVertex)
  {
  }
  else if (_shapeGrabbed)
  {

  }
  _mousePressedOnVertex = false;
  _shapeGrabbed = false;
}
コード例 #3
0
ファイル: view.cpp プロジェクト: james-kennedy/boxology
void GraphicsNodeView::middleMouseButtonRelease(QMouseEvent *event) {
    QMouseEvent fakeEvent(event->type(), event->localPos(), event->screenPos(),
                          event->windowPos(), Qt::LeftButton,
                          event->buttons() & ~Qt::LeftButton,
                          event->modifiers());
    QGraphicsView::mouseReleaseEvent(&fakeEvent);
    setDragMode(QGraphicsView::NoDrag);
}
コード例 #4
0
void QtWebPageEventHandler::handleHoverLeaveEvent(QHoverEvent* ev)
{
    // To get the correct behavior of mouseout, we need to turn the Leave event of our webview into a mouse move
    // to a very far region.
    QHoverEvent fakeEvent(QEvent::HoverMove, QPoint(INT_MIN, INT_MIN), ev->oldPosF());
    fakeEvent.setTimestamp(ev->timestamp());
    // This will apply the transform on the event.
    handleHoverMoveEvent(&fakeEvent);
}
コード例 #5
0
void QtWebPageEventHandler::handleHoverLeaveEvent(QHoverEvent* ev)
{
    // To get the correct behavior of mouseout, we need to turn the Leave event of our webview into a mouse move
    // to a very far region.
    QTransform fromItemTransform = m_webPage->transformFromItem();
    QHoverEvent fakeEvent(QEvent::HoverMove, QPoint(INT_MIN, INT_MIN), fromItemTransform.map(ev->oldPosF()));
    fakeEvent.setTimestamp(ev->timestamp());
    handleHoverMoveEvent(&fakeEvent);
}
コード例 #6
0
// This is used by the Context2D QtScript benchmark.
void Environment::triggerTimers()
{
    for (int x = 0; x < 2; ++x) {
        QList<int> timerIds = x ? m_intervalHash.keys() : m_timeoutHash.keys();
        for (int i = 0; i < timerIds.size(); ++i) {
            QTimerEvent fakeEvent(timerIds.at(i));
            timerEvent(&fakeEvent);
        }
    }
}
コード例 #7
0
int getEvent(AnitaEventFull_t *theEventPtr, const char *lastEventNumberFile) {
    /*Returns 1 if it gets an event, 0 otrherwise */

    int retVal;
    static int firstTime=1;
    static int eventNumber=0;
    /* This is just to get the lastEventNumber in case of program restart. */
    FILE *pFile;
    if(firstTime) {
	pFile = fopen (lastEventNumberFile, "r");
	if(pFile == NULL) {
	    syslog (LOG_ERR,"fopen: %s ---  %s\n",strerror(errno),
		    lastEventNumberFile);
	}
	else {	    	    
	    retVal=fscanf(pFile,"%d",&eventNumber);
	    if(retVal<0) {
		syslog (LOG_ERR,"fscanff: %s ---  %s\n",strerror(errno),
			lastEventNumberFile);
	    }
	    fclose (pFile);
	}
	printf("The last event number is %d\n",eventNumber);
	firstTime=0;
    }

    /* At the moment have to get fake (random) waveforms  */
    if(waitForFakeTrigger()) {
	fakeEvent(theEventPtr);
	printf("Event %d, Time %d %d\n",theEventPtr->header.eventNumber,
	       theEventPtr->header.unixTime,theEventPtr->header.unixTimeUs);
	/* Need to increment eventNumber and write out the last eventNumber to 
	   a file. */
	eventNumber++;
	theEventPtr->header.eventNumber=eventNumber;
	
	if(eventNumber%100) {
	  pFile = fopen (lastEventNumberFile, "w");
	  if(pFile == NULL) {
	    syslog (LOG_ERR,"fopen: %s ---  %s\n",strerror(errno),
		    lastEventNumberFile);
	  }
	  else {
	    retVal=fprintf(pFile,"%d\n",eventNumber);
	    if(retVal<0) {
	      syslog (LOG_ERR,"fprintf: %s ---  %s\n",strerror(errno),
		      lastEventNumberFile);
	    }
	    fclose (pFile);
	  }
	}
	return 1;
    }
    return 0;
}
コード例 #8
0
bool KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent, QTabletEvent *lastTabletEvent, const QPoint &canvasOriginWorkaround)
{
    bool retval = true;

    QTabletEvent *tabletEvent = dynamic_cast<QTabletEvent*>(event);
    QTouchEvent *touchEvent = dynamic_cast<QTouchEvent*>(event);
    QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);

    if (tabletEvent) {
        QPointF docPoint = tabletToDocument(tabletEvent->hiResGlobalPos(), canvasOriginWorkaround);
        tabletEvent->accept();
        this->tabletEvent(tabletEvent, docPoint);
        forwardToTool(state, action, tabletEvent, docPoint);
        retval = tabletEvent->isAccepted();
    } else if (touchEvent) {
        if (state == END && touchEvent->type() != QEvent::TouchEnd) {
            //Fake a touch end if we are "upgrading" a single-touch gesture to a multi-touch gesture.
            QTouchEvent fakeEvent(QEvent::TouchEnd, touchEvent->deviceType(), touchEvent->modifiers(), touchEvent->touchPointStates(), touchEvent->touchPoints());
            this->touchEvent(&fakeEvent);
        } else {
            this->touchEvent(touchEvent);
        }
    } else if (mouseEvent) {
        if (lastTabletEvent) {
            QPointF docPoint = tabletToDocument(lastTabletEvent->hiResGlobalPos(), canvasOriginWorkaround);
            lastTabletEvent->accept();
            this->tabletEvent(lastTabletEvent, docPoint);
            forwardToTool(state, action, lastTabletEvent, docPoint);
            retval = lastTabletEvent->isAccepted();
        } else {
            QPointF docPoint = widgetToDocument(mouseEvent->posF());
            mouseEvent->accept();
            if (mouseEvent->type() == QEvent::MouseButtonPress) {
                mousePressEvent(mouseEvent, docPoint);
            } else if (mouseEvent->type() == QEvent::MouseButtonDblClick) {
                mouseDoubleClickEvent(mouseEvent, docPoint);
            } else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
                mouseReleaseEvent(mouseEvent, docPoint);
            } else if (mouseEvent->type() == QEvent::MouseMove) {
                mouseMoveEvent(mouseEvent, docPoint);
            }
            forwardToTool(state, action, originalEvent, docPoint);
            retval = mouseEvent->isAccepted();
        }
    } else if(event->type() == QEvent::KeyPress) {
        QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
        keyPressEvent(kevent);
    } else if(event->type() == QEvent::KeyRelease) {
        QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
        keyReleaseEvent(kevent);
    }

    return retval;
}
コード例 #9
0
ファイル: view.cpp プロジェクト: james-kennedy/boxology
void GraphicsNodeView::middleMouseButtonPress(QMouseEvent *event) {
    QMouseEvent releaseEvent(QEvent::MouseButtonRelease, event->localPos(),
                             event->screenPos(), event->windowPos(),
                             Qt::LeftButton, 0, event->modifiers());
    QGraphicsView::mouseReleaseEvent(&releaseEvent);
    setDragMode(QGraphicsView::ScrollHandDrag);
    QMouseEvent fakeEvent(event->type(), event->localPos(), event->screenPos(),
                          event->windowPos(), Qt::LeftButton,
                          event->buttons() | Qt::LeftButton,
                          event->modifiers());
    QGraphicsView::mousePressEvent(&fakeEvent);
}
コード例 #10
0
ファイル: view.cpp プロジェクト: eliemichel/ZodiacGraph
void View::mouseReleaseEvent(QMouseEvent* event)
{
    if (event->button() == s_dragMoveButton){
        // disable scroll dragging, if it was enabled
        if(dragMode()==QGraphicsView::ScrollHandDrag){
            QMouseEvent fakeEvent(event->type(), event->pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers());
            QGraphicsView::mouseReleaseEvent(&fakeEvent);
        }
    }

    // make sure to reset the drag mode
    setDragMode(QGraphicsView::RubberBandDrag);

    QGraphicsView::mouseReleaseEvent(event);
}
コード例 #11
0
ファイル: CompositePdf.cpp プロジェクト: BillyLiggins/oxsx
int main(){
    // Build the constituent parts independently
    Gaussian gaus2d(2); // normal parameters by default
    AnalyticPdf pdf2d(&gaus2d);
    // 2d pdf will look at observables 1 and 3
    // you can address these by names if they come from a data set
    std::vector<size_t> indices;
    indices.push_back(1);
    indices.push_back(3);

    pdf2d.SetDataRep(DataRepresentation(indices));

    Gaussian gaus1d(1);
    AnalyticPdf pdf1d(&gaus1d);
    // 1d pdf will look at observable 4
    pdf1d.SetDataRep(4);


    // Now we combine them into a single composite pdf
    CompositePdf combinedPdf = pdf2d * pdf1d;
    

    std::cout << "From a "<< pdf2d.GetNDims() << "D pdf\n"
              << "and a " << pdf1d.GetNDims() << "D pdf\n"
              << "we have created a " << combinedPdf.GetNDims()
              << "D pdf" << std::endl;

    std::cout << "Like any other pdf it can be normalised " << std::endl;
    
    EventData fakeEvent(std::vector<double>(10, 2));

    std::cout << "Calling probability on the composite pdf "
              << "gives you " 
              << combinedPdf.Probability(fakeEvent)
              << "\n individually the pdfs give you " 
              << pdf2d.Probability(fakeEvent) << " and " 
              << pdf1d.Probability(fakeEvent)
              << "\n their product is " 
              << pdf2d.Probability(fakeEvent) * pdf1d.Probability(fakeEvent)
              << "\n so we have combined two independent components!"
              << std::endl;
        
    
}
コード例 #12
0
ファイル: webpage.cpp プロジェクト: 593in/qupzilla
bool WebPage::event(QEvent* event)
{
    if (event->type() == QEvent::Leave) {
        // QWebPagePrivate::leaveEvent():
        // Fake a mouse move event just outside of the widget, since all
        // the interesting mouse-out behavior like invalidating scrollbars
        // is handled by the WebKit event handler's mouseMoved function.

        // However, its implementation fake mouse move event on QCursor::pos()
        // position that is in global screen coordinates. So instead of
        // really faking it, it just creates mouse move event somewhere in
        // page. It can for example focus a link, and then link url gets
        // stuck in status bar message.

        // So we are faking mouse move event with proper coordinates for
        // so called "just outside of the widget" position

        const QPoint cursorPos = view()->mapFromGlobal(QCursor::pos());
        QPoint mousePos;

        if (cursorPos.y() < 0) {
            // Left on top
            mousePos = QPoint(cursorPos.x(), -1);
        }
        else if (cursorPos.x() < 0) {
            // Left on left
            mousePos = QPoint(-1, cursorPos.y());
        }
        else if (cursorPos.y() > view()->height()) {
            // Left on bottom
            mousePos = QPoint(cursorPos.x(), view()->height() + 1);
        }
        else {
            // Left on right
            mousePos = QPoint(view()->width() + 1, cursorPos.y());
        }

        QMouseEvent fakeEvent(QEvent::MouseMove, mousePos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
        return QWebPage::event(&fakeEvent);
    }

    return QWebPage::event(event);
}
コード例 #13
0
ファイル: view.cpp プロジェクト: eliemichel/ZodiacGraph
void View::mousePressEvent(QMouseEvent* event)
{
    static const QTransform nullTransform = QTransform();

    if(event->button() == s_dragMoveButton){
        // only allow scroll dragging if no item is clicked
        if(!scene()->itemAt(mapToScene(event->pos()), nullTransform)){
            setDragMode(QGraphicsView::ScrollHandDrag);
            QMouseEvent fakeEvent(event->type(), event->pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers());
            QGraphicsView::mousePressEvent(&fakeEvent);
        }
        return;

    } else if (event->button() != s_selectionButton){
        // do not allow rubberband selection with any button other than the selection button
        setDragMode(QGraphicsView::NoDrag);
    }
    QGraphicsView::mousePressEvent(event);
}
コード例 #14
0
/*! \reimp
*/
bool QGraphicsWebView::event(QEvent* event)
{
    // Re-implemented in order to allows fixing event-related bugs in patch releases.

    if (d->page) {
#ifndef QT_NO_CONTEXTMENU
        if (event->type() == QEvent::GraphicsSceneContextMenu) {
            if (!isEnabled())
                return false;

            QGraphicsSceneContextMenuEvent* ev = static_cast<QGraphicsSceneContextMenuEvent*>(event);
            QContextMenuEvent fakeEvent(QContextMenuEvent::Reason(ev->reason()), ev->pos().toPoint());
            if (d->page->swallowContextMenuEvent(&fakeEvent)) {
                event->accept();
                return true;
            }
            d->page->updatePositionDependentActions(fakeEvent.pos());
        } else
#endif // QT_NO_CONTEXTMENU
        {
#ifndef QT_NO_CURSOR
#if QT_VERSION >= 0x040400
            if (event->type() == QEvent::CursorChange) {
                // An unsetCursor will set the cursor to Qt::ArrowCursor.
                // Thus this cursor change might be a QWidget::unsetCursor()
                // If this is not the case and it came from WebCore, the
                // QWebPageClient already has set its cursor internally
                // to Qt::ArrowCursor, so updating the cursor is always
                // right, as it falls back to the last cursor set by
                // WebCore.
                // FIXME: Add a QEvent::CursorUnset or similar to Qt.
                if (cursor().shape() == Qt::ArrowCursor)
                    d->resetCursor();
            }
#endif
#endif
        }
    }
    return QGraphicsWidget::event(event);
}
コード例 #15
0
ファイル: tagwidget.cpp プロジェクト: Farzana89/subsurface
void TagWidget::keyPressEvent(QKeyEvent *e)
{
	switch (e->key()) {
	case Qt::Key_Return:
	case Qt::Key_Enter:
	case Qt::Key_Tab:
		/*
		 * Fake the QLineEdit behaviour by simply
		 * closing the QAbstractViewitem
		 */
		if (m_completer) {
			QAbstractItemView *popup = m_completer->popup();
			if (popup)
				popup->hide();
		}
	}
	if (e->key() == Qt::Key_Tab) { // let's pretend this is a comma instead
		QKeyEvent fakeEvent(e->type(), Qt::Key_Comma, e->modifiers(), QString(","));
		GroupedLineEdit::keyPressEvent(&fakeEvent);
	} else {
		GroupedLineEdit::keyPressEvent(e);
	}
}
コード例 #16
0
void QgsMapToolAdvancedDigitizing::cadPointChanged( const QgsPoint& point )
{
    QgsMapMouseEvent fakeEvent( mCanvas, QMouseEvent::Move, QPoint( 0, 0 ) );
    fakeEvent.setMapPoint( point );
    canvasMoveEvent( &fakeEvent );
}
コード例 #17
0
ファイル: MapperGLCanvas.cpp プロジェクト: flv0/mapmap
void MapperGLCanvas::mousePressEvent(QMouseEvent* event)
{
  bool mousePressedOnSomething = false;

  _mousePressedPosition = event->pos();
  QPointF pos = mapToScene(event->pos());

  // Drag the scene with middle button.
  if (event->buttons() & Qt::MiddleButton)
  {
    // NOTE: This is a trick code to implement scroll hand drag using the middle button.
    QMouseEvent releaseEvent(QEvent::MouseButtonRelease, event->pos(), event->globalPos(), Qt::LeftButton, 0, event->modifiers());
    QGraphicsView::mouseReleaseEvent(&releaseEvent);
    setDragMode(QGraphicsView::ScrollHandDrag);

    // We need to pretend it is actually the left button that was pressed!
    QMouseEvent fakeEvent(event->type(), event->pos(), event->globalPos(),
                          Qt::LeftButton, event->buttons() | Qt::LeftButton, event->modifiers());
    QGraphicsView::mousePressEvent(&fakeEvent);
  }

  // Check for vertex selection first.
  else if (event->buttons() & Qt::LeftButton)
  {
    MShape* shape = getCurrentShape();
    if (shape)
    {
      // Note: we compare with the square value for fastest computation of the distance
      int minDistance = sq(MM::VERTEX_SELECT_RADIUS);

      // Find the ID of the nearest vertex (from currently selected shape)
      for (int i = 0; i < shape->nVertices(); i++)
      {
        int dist = distSq(_mousePressedPosition, mapFromScene(shape->getVertex(i))); // squared distance
        if (dist < minDistance)
        {
          _activeVertex = i;
          minDistance = dist;

          _mousePressedOnVertex = true;
          mousePressedOnSomething = true;

          _grabbedObjectStartPosition = shape->getVertex(i);
        }
      }
    }
  }

  if (mousePressedOnSomething)
    return;

  // Check for shape selection.
  if (event->buttons() & (Qt::LeftButton | Qt::RightButton)) // Add Right click for context menu
  {
    MShape* selectedShape = getCurrentShape();

    // Possibility of changing shape in output by clicking on it.
    MappingManager manager = getMainWindow()->getMappingManager();
    QVector<Mapping::ptr> mappings = manager.getVisibleMappings();
    for (QVector<Mapping::ptr>::const_iterator it = mappings.end() - 1; it >= mappings.begin(); --it)
    {
      MShape *shape = getShapeFromMappingId((*it)->getId());

      // Check if mouse was pressed on that shape.
      if (shape && shape->includesPoint(pos))
      {
        mousePressedOnSomething = true;

        // Deselect vertices.
        deselectVertices();

        // Change mapping (only available in destination).
        if (isOutput() && shape != selectedShape)
        {
          // Change current mapping.
          getMainWindow()->setCurrentMapping((*it)->getId());

          // Reset selected shape to new one.
          selectedShape = getCurrentShape();
        }

        break;
      }
    }

    // Grab the shape.
    if (event->buttons() & Qt::LeftButton) // This preserve me from duplicate code above
    {
      if (selectedShape && selectedShape->includesPoint(pos))
      {
        _shapeGrabbed = true;
        _shapeFirstGrab = true;

        _grabbedObjectStartPosition = pos;
      }
    }
  }

  if (mousePressedOnSomething)
    return;

  // Deactivate.
  deselectAll();
}