bool MainWindow::eventFilter(QObject *, QEvent *event)
{
    if(event->type() == QEvent::KeyPress)
    {
        event_ctr++;
        QKeyEvent *KeyEvent = (QKeyEvent*)event;
        if(KeyEvent->key()==Qt::Key_R && event_ctr%5==1){
            std::cout<<"R"<<std::endl;
            createBird();
        }
        if(KeyEvent->key()==Qt::Key_Q){
            restart();
        }

        if(KeyEvent->key()==Qt::Key_Equal){
            ui->graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
            ui->graphicsView-> scale(scaleFactor, scaleFactor);
        }
        if(KeyEvent->key()==Qt::Key_Minus){
            ui->graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
            ui->graphicsView->scale(1.0 / scaleFactor, 1.0 / scaleFactor);
        }
        if(KeyEvent->key()==Qt::Key_Down){
            timer_z.start(10);
        }
        if(KeyEvent->key()==Qt::Key_Space){
            timer_z.stop();
            timer_f.stop();
            ui->graphicsView->setTransform(QTransform(0.5, 0, 0, 0.5, 0, 0));
            ui->graphicsView->centerOn(600,300);
        }
    }
    if(event->type() == QEvent::GraphicsSceneMousePress)
    {
        if(nowHoldState==release){
            nowHoldState=hold;
        }
        else if(!birdList.isEmpty()){
            birdList.back()->controled();
        }


    }
    if(event->type() == QEvent::GraphicsSceneMouseMove)
    {
        QGraphicsSceneMouseEvent  *mouseEvent = (QGraphicsSceneMouseEvent *)event;
        mousePoint=mouseEvent->scenePos();
    }
    if(event->type() == QEvent::GraphicsSceneMouseRelease)
    {
        std::cout << "Release !" <<std::endl ;
        if(nowHoldState==hold){
            timer_waiter.start(10000);
            shoot();
        }

    }
    return false;
}
void DashboardWindowContainer::mouseWasGrabbedByParent()
{
	// fake a mouse cancel
	QGraphicsSceneMouseEvent ev;
	ev.setCanceled(true);
	mouseReleaseEvent(&ev);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == scene)
    {
        QGraphicsSceneMouseEvent* mouseEvent;

        switch(event->type())
        {

        // ** MOUSE BUTTON RELEASE ** //
        case QEvent::GraphicsSceneMouseRelease:
        {
            mouseEvent   = static_cast<QGraphicsSceneMouseEvent*>(event);
            QPoint pos = mouseEvent->scenePos().toPoint();

            if (mouseEvent->button() == Qt::LeftButton)
            {
                if (inputPoints == 0 || inputPoints == 1)
                    points[inputPoints++] = pos;

                if (inputPoints == 2)
                {
                    // We've finished adding points now.
                    view->setCursor(Qt::ArrowCursor);
                    updateScene();
                }
            }
            return true;
        }


        // ** MOUSE MOVED ** //
        case QEvent::GraphicsSceneMouseMove:
        {
            mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
            QPoint pos = mouseEvent->scenePos().toPoint();

            if (inputPoints == 0)
            {

                points[0] = pos;
                updateScene();
            }

            if (inputPoints == 1)
            {
                points[1] = pos;
                updateScene();
            }
            return true;
        }

        default:
            return QMainWindow::eventFilter(obj, event);
        }
    }

    // pass the event on to the parent class
    return QMainWindow::eventFilter(obj, event);
}
Beispiel #4
0
bool Pane::eventFilter(QObject *obj, QEvent *event)
{
    switch (event->type()) {
    case QEvent::WindowActivate: {
        QRectF newSceneRect(QPointF(0.0, 0.0), maximumViewportSize());
        m_scene->setSceneRect(newSceneRect);
    }
        break;
    case QEvent::GraphicsSceneMousePress: {
        if (!m_active) {
            /* Clear everything */
            m_points.clear();
            m_angles.clear();
            QList<QGraphicsItem*> items = m_scene->items();
            foreach (QGraphicsItem *item, items) {
                m_scene->removeItem(item);
                delete item;
            }
            m_active = true;
        }
        QGraphicsSceneMouseEvent *mouseEvent =
            static_cast<QGraphicsSceneMouseEvent*>(event);

        Q_ASSERT(mouseEvent);

        QPointF point = mouseEvent->scenePos();
        m_out << point.x() << ","
              << point.y() << ","
              << QDateTime::currentMSecsSinceEpoch() << "\n";

        m_points << point;
    }
bool CDiagramProxyWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
{
	QGraphicsSceneMouseEvent	*mouseEvent = NULL;

	mouseEvent = dynamic_cast<QGraphicsSceneMouseEvent*>(event);
	if (mouseEvent && mouseEvent->buttons() & Qt::LeftButton)
		setSelected(true);
	return scene()->sendEvent(m_proxy, event);
}
	bool treeVisualiserFrame::eventFilter(QObject* object, QEvent *event)
	{
		if(event->type() == QEvent::GraphicsSceneMouseMove && object == graphicsScene)
		{
			QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
			QPointF position = mouseEvent->scenePos();
			emit positionChanged(position.x(), position.y());
			return true;
		}
		else if(event->type() == QEvent::GraphicsSceneMousePress && object == graphicsScene)
		{
			QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
			QPointF scenePosition = mouseEvent->scenePos();
			QList<QGraphicsItem*> possibleItems = graphicsScene->items(scenePosition.x() - 2*pointSize, scenePosition.y() - 2*pointSize, 4*pointSize, 4*pointSize, Qt::ContainsItemBoundingRect, Qt::DescendingOrder);
			QGraphicsItem* clicked = NULL;
			for(QList<QGraphicsItem*>::iterator i = possibleItems.begin(); i != possibleItems.end(); i++)
			{
				if((*i)->flags() & QGraphicsItem::ItemIsSelectable)
				{
					if(clicked)
					{
						clicked = NULL; break;
					}
					clicked = *i;
				}
			}
			if(clicked) emit vertexSelected(static_cast<treeVisualiserVertex*>(clicked)->getVertexID());
			return true;
		}
		if(event->type() == QEvent::KeyPress)
		{
			QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
			if(keyEvent->key() == Qt::Key_Left && keyEvent->modifiers() & Qt::ShiftModifier)
			{
				emit observationLeft();
				return true;
			}
			else if(keyEvent->key() == Qt::Key_Right && keyEvent->modifiers() & Qt::ShiftModifier)
			{
				emit observationRight();
				return true;
			}
			else if(keyEvent->key() == Qt::Key_Up && keyEvent->modifiers() & Qt::ShiftModifier)
			{
				emit observationDown();
				return true;
			}
			else if(keyEvent->key() == Qt::Key_Down && keyEvent->modifiers() & Qt::ShiftModifier)
			{
				emit observationUp();
				return true;
			}
		}
		return false;
	}
void DashboardWindowContainer::mouseWasGrabbedByParent()
{
	// fake a mouse cancel
	QGraphicsSceneMouseEvent ev;
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
	ev.setCanceled(true);
#else
    ev.ignore();
#endif
	mouseReleaseEvent(&ev);
}
//void MyGraphicsView::mousePressEvent(QGraphicsSceneMouseEvent* pMouseEvent)
void MyGraphicsView::mousePressEvent(QMouseEvent* pMouseEvent)
{
  //QGraphicsItem* pItemUnderMouse = itemAt(pMouseEvent->scenePos().x(), pMouseEvent->scenePos().y());
  //std::cout << "pItemUnderMouse: " << pItemUnderMouse << std::endl;
  std::cout << "mouseEvent" << std::endl;
  
  //QGraphicsSceneMouseEvent* event = dynamic_cast<QGraphicsSceneMouseEvent*>(pMouseEvent);
  QGraphicsSceneMouseEvent* event = reinterpret_cast<QGraphicsSceneMouseEvent*>(pMouseEvent);
  QGraphicsItem* pItemUnderMouse = itemAt(event->scenePos().x(), event->scenePos().y());
  std::cout << "pItemUnderMouse: " << pItemUnderMouse << std::endl;
}
dmz::V8Value
dmz::JsModuleUiV8QtBasic::_gscene_mouse_event_screen_pos (const v8::Arguments &Args) {

   v8::HandleScope scope;
   V8Value result = v8::Undefined ();

   JsModuleUiV8QtBasic *self = _to_self (Args);
   if (self) {

      QGraphicsSceneMouseEvent *event =
         (QGraphicsSceneMouseEvent *)self->_to_qevent (Args.This ());
      if (event) { result = qpoint_to_v8 (event->screenPos ()); }
   }

   return scope.Close (result);
}
bool SelectionArrowItem::sceneEvent(QEvent *event) {
  if (event->type() == QEvent::GraphicsSceneMouseMove) {
    QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent *>(event);
    qreal diffPosY = e->pos().y() - e->lastPos().y();

    if (pos().y() + diffPosY > initPos.y() + 130)
      diffPosY = initPos.y() + 130 - pos().y();

    if (pos().y() + diffPosY < initPos.y() - 30)
      diffPosY = initPos.y() - 30 - pos().y();

    moveBy(0, diffPosY);

    emit circleMoved();

    return true;
  }

  return false;
}
bool subObservationVisualiserBase::eventFilter(QObject* object, QEvent *event)
{
    if(event->type() == QEvent::GraphicsSceneMouseMove && object == graphicsScene)
    {
        QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
        QPointF position = mouseEvent->scenePos();
        emit positionChanged(position.x(), position.y());

        return true;
    }
    else if(event->type() == QEvent::KeyPress)
    {
        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        if(keyEvent->key() == Qt::Key_Left && keyEvent->modifiers() & Qt::ShiftModifier)
        {
            emit observationLeft();
            return true;
        }
        else if(keyEvent->key() == Qt::Key_Right && keyEvent->modifiers() & Qt::ShiftModifier)
        {
            emit observationRight();
            return true;
        }
        else if(keyEvent->key() == Qt::Key_Up && keyEvent->modifiers() & Qt::ShiftModifier)
        {
            emit observationDown();
            return true;
        }
        else if(keyEvent->key() == Qt::Key_Down && keyEvent->modifiers() & Qt::ShiftModifier)
        {
            emit observationUp();
            return true;
        }
    }
    else if(event->type() == QEvent::Leave && object == graphicsScene)
    {
        updateGraphics();
        return true;
    }
    return false;
}
bool MovablePathItem::sceneEvent(QEvent *event) {
  if (event->type() == QEvent::GraphicsSceneMouseMove) {
    QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent *>(event);
    qreal diffPosY = e->pos().y() - e->lastPos().y();

    if (_currentRect.bottom() * 160 + diffPosY > 160)
      diffPosY = 160 - _currentRect.bottom() * 160;

    if (_currentRect.top() * 160 + diffPosY < 0)
      diffPosY = -_currentRect.top() * 160;

    updatePath();
    _currentRect.translate(0, diffPosY / 160.);

    emit moved(_currentRect.top(), _currentRect.bottom());

    return true;
  }

  return false;
}
Beispiel #13
0
bool BlockRemoveButton::sceneEventFilter(QGraphicsItem * watched, QEvent * event)
{
    if (watched != this)
    {
        // not expected to get here
        return false;
    }

    QGraphicsSceneMouseEvent * mevent = dynamic_cast<QGraphicsSceneMouseEvent*> (event);
    if (mevent == NULL)
    {
        // this is not one of the mouse events we are interrested in
        return false;
    }

    if (event->type() == QEvent::GraphicsSceneMousePress)
    {
        //If mouse press event is not handled, mouse released event is never emitted
        return true;
    }
    else if (event->type() == QEvent::GraphicsSceneMouseRelease)
    {
        QGraphicsSceneMouseEvent * mouseEvent = ((QGraphicsSceneMouseEvent *) event);
        if (mouseEvent->button() == Qt::LeftButton)
        {
            BlockItem* parentBlock = dynamic_cast<BlockItem*>(parentItem());
            if(parentBlock != NULL)
            {
                parentBlock->getEditor()->runScriptCommand(
                    QString("Delete the block %1")
                    .arg(parentBlock->name())
                );
                
                return true;
            }
        }
    }

    return false;
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event) 
{
  if (event->type() ==  QEvent::GraphicsSceneMouseMove ) {
    QGraphicsSceneMouseEvent *mouseEvent = dynamic_cast<QGraphicsSceneMouseEvent*>(event);

    QPointF img_coord_pt = mouseEvent->scenePos();
    
    double x = img_coord_pt.x();
    double y = img_coord_pt.y();
    
    QColor color = QColor(pix.toImage().pixel(x,y));
    int average = (color.red()+color.green()+color.blue())/3;

    ui->label_X->setText(QString::number(x));
    ui->label_Y->setText(QString::number(y));
    ui->label_Value->setText(QString::number(average));

    return true;
  } else {
    return QObject::eventFilter(obj, event);
  }
}
dmz::V8Value
dmz::JsModuleUiV8QtBasic::_gscene_mouse_event_button_down_screen_pos (const v8::Arguments &Args) {

   v8::HandleScope scope;
   V8Value result = v8::Undefined ();

   JsModuleUiV8QtBasic *self = _to_self (Args);
   if (self) {

      QGraphicsSceneMouseEvent *event =
         (QGraphicsSceneMouseEvent *)self->_to_qevent (Args.This ());
      if (event) {

         if (Args.Length ()) {

            Qt::MouseButton button = (Qt::MouseButton) v8_to_uint32 (Args[0]);
            result = qpoint_to_v8 (event->buttonDownScreenPos (button));
         }
      }
   }

   return scope.Close (result);
}
Beispiel #16
0
QGraphicsSceneMouseEvent* EventSender::createGraphicsSceneMouseEvent(QEvent::Type type, const QPoint& pos, const QPoint& screenPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
{
    QGraphicsSceneMouseEvent* event;
    event = new QGraphicsSceneMouseEvent(type);
    event->setPos(pos);
    event->setScreenPos(screenPos);
    event->setButton(button);
    event->setButtons(buttons);
    event->setModifiers(modifiers);

    return event;
}
bool MInverseMouseArea::eventFilter(QObject *obj, QEvent *ev)
{
    Q_UNUSED(obj);
    if (!m_enabled || !isVisible())
        return false;    
    switch (ev->type()) {
    case QEvent::GraphicsSceneMousePress: {
        QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(ev);
        QPointF mappedPos = mapToRootItem(me->scenePos());
        m_pressed = !contains(mapFromScene(me->scenePos())) && !isClickedOnSoftwareInputPanel(me);

        if (m_pressed)
            emit pressedOutside(mappedPos.x(), mappedPos.y());
        break;
    }
    case QEvent::GraphicsSceneMouseMove: {
        if (m_pressed) {
            QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(ev);
            const QPointF &dist = me->scenePos() - me->buttonDownScenePos(Qt::LeftButton);

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

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

    return false;
}
Beispiel #18
0
bool WorldScene::event(QEvent *event)
{
    //Allowing hovered item to display differently.
    if (event->type() == QEvent::GraphicsSceneMouseMove)
    {
        QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent *>(event);
        QGraphicsItem * itemHovered = itemAt(e->scenePos(), QGraphicsItem::UserType + 1);
        if(itemHovered != m_hoveredItem )
        {
	    if(m_hoveredItem)
                static_cast<HexTile *>(m_hoveredItem)->hoverLeaveEvent(e);
	    if(itemHovered)
                static_cast<HexTile *>(itemHovered)->hoverEnterEvent(e);

            m_hoveredItem = itemHovered;
        }
        e->accept();
        return true;
    }
    //Handling clicks to create/remove towers
    else if(event->type() == QEvent::GraphicsSceneMousePress)
    {
        QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent *>(event);
        if(e->button() == Qt::LeftButton)
        {
	    QGraphicsItem * item = itemAt(e->scenePos(), QGraphicsItem::UserType + 1);
	    if(item)
		emit placeTower(item);
        }
        else if(e->button() == Qt::RightButton)
        {
	    QGraphicsItem * item = itemAt(e->scenePos(), QGraphicsItem::UserType + 1);
	    if(item)
		emit removeTower(item);
        }
    }

    return QGraphicsScene::event(event);
    //return true;
}
void Ut_VolumeBar::testMousePressesAndMovesUpdatePercentage()
{
    volumeBar->setGeometry(QRectF(0, 0, 50, 30));
    mWidgetIsOnDisplay = false;

    QGraphicsSceneMouseEvent event;
    event.setPos(QPointF(25, 10));
    volumeBar->mousePressEvent(&event);
    QCOMPARE(event.isAccepted(), true);
    QCOMPARE(volumeBar->currentPercentage(), (volumeBar->geometry().height() - event.pos().y()) / volumeBar->geometry().height());

    event.setPos(QPointF(35, 20));
    volumeBar->mouseMoveEvent(&event);
    QCOMPARE(volumeBar->currentPercentage(), (volumeBar->geometry().height() - event.pos().y()) / volumeBar->geometry().height());
}
bool CustomEdit::startSelection(const QPointF &hitPoint)
{
    QPointF startSelectionPoint = startPoint(hitPoint);

    //fake double click to activate selection on text edit
    QGraphicsSceneMouseEvent event;
    event.setPos(startSelectionPoint);
    event.setButton(Qt::LeftButton);
    mousePressEvent(&event);
    event.setPos(startSelectionPoint);
    mouseReleaseEvent(&event);

    event.setPos(startSelectionPoint);
    mousePressEvent(&event);
    event.setPos(startSelectionPoint);
    mouseReleaseEvent(&event);

    return hasSelectedText();
}
bool CMindMapEventHandler::onEvent(CDiagramPrivateData *p, QEvent *evt)
{
	bool					r = false;
	CDiagram				*d = NULL;
	CDiagramItem			*item = NULL;
	CMindMapNode			*node = NULL;
	QList<CDiagramItem*>	items;
	
	if ( !p || !p->m_d || p->m_d->mode() == CDiagram::EditTextMode )
		return r;

	d = p->m_d;
	m_pdata = p;

	switch(evt->type())
	{
	case QEvent::GraphicsSceneDragEnter:
        r = dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent*>(evt));
		break;

	case QEvent::GraphicsSceneDragMove:
        r = dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent*>(evt));
		break;

	case QEvent::GraphicsSceneDrop:
        r = dropEvent(static_cast<QGraphicsSceneDragDropEvent*>(evt));
		break;

	case QEvent::GraphicsSceneMousePress:
        if (m_draggedImage->scene() == d)
            d->removeItem(m_draggedImage);
		m_pdata->m_customPressedItem = NULL;
		m_target = NULL;
		break;

	case QEvent::GraphicsSceneMouseMove:
		{
			QGraphicsSceneMouseEvent	*event = NULL;
			QPointF						endPos;
			QPointF						startPos;
			QDrag						*drag = NULL;
			QMimeData					*mime = NULL;
			QByteArray					mimeData;
			QDataStream					dataStream(&mimeData, QIODevice::WriteOnly);

			event = static_cast<QGraphicsSceneMouseEvent*>(evt);
			if (event && d->mode() == CDiagram::CursorMode)
			{
				if (event->buttons() & Qt::LeftButton )
				{
					endPos = event->scenePos();
					startPos = event->buttonDownScenePos(Qt::LeftButton);

					if (!m_pdata->m_customPressedItem)
					{
						items = d->selectedTopLevelItems();
						if (items.length() == 1)
						{
							node = dynamic_cast<CMindMapNode*>(items.first());
                            if (node && node->isMovable() && node->mapToScene( node->boundingRect() ).containsPoint(event->scenePos(), Qt::WindingFill ) )
							{
								m_pdata->m_customPressedItem = node;
							}
							else if (node && node->isRoot())
							{
								r = true;
							}
						}
						else
						{
							foreach (item, items)
							{
								node = dynamic_cast<CMindMapNode*>(item);
								if (node && node->isRoot())
								{
									r = true;
									break;
								}
							}
						}
					}

					// check whether we should start the moving action
					// using manhattanLength.
					if (m_pdata->m_customPressedItem && 
						m_draggedImage->scene() != d && 
						((startPos, endPos).manhattanLength() > QApplication::startDragDistance() ) )
					{
						((CMindMapDragImage*)m_draggedImage)->updateDraggedItemsRect(d, m_pdata->m_customPressedItem);
                        m_pdata->m_d->addItem(m_draggedImage);
						m_draggedImage->setVisible(true);
						m_draggedImageInitPos = m_draggedImage->pos();
						
						dataStream << event->buttonDownScenePos(Qt::LeftButton);
						mime = new QMimeData();
						mime->setData(DND_DRAGMINDMAPNODE, mimeData);

                        drag = new QDrag( d->getMainView() );
						drag->setMimeData(mime);
						
						if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction) == Qt::MoveAction)
						{
							// Should do something here.
						}

						event->accept();
                        r = true;
					}
				}
			}
Beispiel #22
0
bool KisSketchView::sceneEvent(QEvent* event)
{
    if (d->canvas && d->canvasWidget) {
        switch(event->type()) {
        case QEvent::GraphicsSceneMousePress: {
            QGraphicsSceneMouseEvent *gsmevent = static_cast<QGraphicsSceneMouseEvent*>(event);
            QMouseEvent mevent(QMouseEvent::MouseButtonPress, gsmevent->pos().toPoint(), gsmevent->button(), gsmevent->buttons(), gsmevent->modifiers());
            QApplication::sendEvent(d->canvasWidget, &mevent);
            emit interactionStarted();
            return true;
        }
        case QEvent::GraphicsSceneMouseMove: {
            QGraphicsSceneMouseEvent *gsmevent = static_cast<QGraphicsSceneMouseEvent*>(event);
            QMouseEvent mevent(QMouseEvent::MouseMove, gsmevent->pos().toPoint(), gsmevent->button(), gsmevent->buttons(), gsmevent->modifiers());
            QApplication::sendEvent(d->canvasWidget, &mevent);
            update();
            emit interactionStarted();
            return true;
        }
        case QEvent::GraphicsSceneMouseRelease: {
            QGraphicsSceneMouseEvent *gsmevent = static_cast<QGraphicsSceneMouseEvent*>(event);
            QMouseEvent mevent(QMouseEvent::MouseButtonRelease, gsmevent->pos().toPoint(), gsmevent->button(), gsmevent->buttons(), gsmevent->modifiers());
            QApplication::sendEvent(d->canvasWidget, &mevent);
            emit interactionStarted();
            return true;
        }
        case QEvent::GraphicsSceneWheel: {
            QGraphicsSceneWheelEvent *gswevent = static_cast<QGraphicsSceneWheelEvent*>(event);
            QWheelEvent wevent(gswevent->pos().toPoint(), gswevent->delta(), gswevent->buttons(), gswevent->modifiers(), gswevent->orientation());
            QApplication::sendEvent(d->canvasWidget, &wevent);
            emit interactionStarted();
            return true;
        }
        case QEvent::GraphicsSceneHoverEnter: {
            QGraphicsSceneHoverEvent *hevent = static_cast<QGraphicsSceneHoverEvent*>(event);
            QHoverEvent e(QEvent::Enter, hevent->screenPos(), hevent->lastScreenPos());
            QApplication::sendEvent(d->canvasWidget, &e);
            return true;
        }
        case QEvent::GraphicsSceneHoverLeave: {
            QGraphicsSceneHoverEvent *hevent = static_cast<QGraphicsSceneHoverEvent*>(event);
            QHoverEvent e(QEvent::Leave, hevent->screenPos(), hevent->lastScreenPos());
            QApplication::sendEvent(d->canvasWidget, &e);
            return true;
        }
        case QEvent::TouchBegin: {
            QApplication::sendEvent(d->canvasWidget, event);
            event->accept();
            emit interactionStarted();
            return true;
        }
        case QEvent::TabletPress:
        case QEvent::TabletMove:
        case QEvent::TabletRelease:
            d->canvas->inputManager()->stopIgnoringEvents();
            QApplication::sendEvent(d->canvasWidget, event);
            return true;
        default:
            if (QApplication::sendEvent(d->canvasWidget, event)) {
                emit interactionStarted();
                return true;
            }
        }
    }
    return QDeclarativeItem::sceneEvent(event);
}
Beispiel #23
0
bool QNodeGraph::eventFilter(QObject *o, QEvent *e)
{
	QGraphicsSceneMouseEvent *me = (QGraphicsSceneMouseEvent*) e;

	switch ((int) e->type())
	{
        case QEvent::KeyPress:
            {
                QKeyEvent *k = static_cast<QKeyEvent *>(e);
                switch(k->key())
                {
                    case Qt::Key_P:
                        {
                            parseGraph();

                            break;
                        }
                    case Qt::Key_X:
                        {
                            BaseSDFOP* op = new Mandelbulb_SDFOP();
                            DistanceOpNode *c = new DistanceOpNode(op, scene, 0);

                            break;
                        }
                    case Qt::Key_C:
                        {
                            BaseSDFOP* op = new Union_SDFOP();
                            DistanceOpNode *c = new DistanceOpNode(op, scene, 0);

                            break;
                        }
                    case Qt::Key_V:
                        {
                            BaseSDFOP* op = new Sphere_SDFOP(1.0);
                            DistanceOpNode *c = new DistanceOpNode(op, scene, 0);

                            break;
                        }
                }
                break;
            }
        case QEvent::GraphicsSceneMousePress:
            {
                switch ((int) me->button())
                {
                    case Qt::LeftButton:
                        {
                            QGraphicsItem *item = itemAt(me->scenePos());
                            if (item && item->type() == QNEPort::Type)
                            {
                                conn = new QNEConnection(0);
                                scene->addItem(conn);
                                conn->setPort1((QNEPort*) item);
                                conn->setPos1(item->scenePos());
                                conn->setPos2(me->scenePos());
                                conn->updatePath();

//                                emit graphChanged();

                                return true;
                            } else if (item && item->type() == QNEBlock::Type)
                            {
                                /* if (selBlock)
                    selBlock->setSelected(); */
                                // selBlock = (QNEBlock*) item;


                            }
                            break;
                        }
                    case Qt::RightButton:
                        {
                            QGraphicsItem *item = itemAt(me->scenePos());
                            if (item && (item->type() == QNEConnection::Type || item->type() == QNEBlock::Type))
                            {
                                delete item;
                                emit graphChanged();
                            }
                            // if (selBlock == (QNEBlock*) item)
                            // selBlock = 0;

                            break;
                        }
                }
            }
        case QEvent::GraphicsSceneMouseMove:
            {
                if (conn)
                {
                    conn->setPos2(me->scenePos());
                    conn->updatePath();
                    return true;
                }
                break;
            }
        case QEvent::GraphicsSceneMouseRelease:
            {
                if (conn && me->button() == Qt::LeftButton)
                {
                    QGraphicsItem *item = itemAt(me->scenePos());
                    if (item && item->type() == QNEPort::Type)
                    {
                        QNEPort *port1 = conn->port1();
                        QNEPort *port2 = (QNEPort*) item;

                        if (port1->block() != port2->block() && port1->isOutput() != port2->isOutput() && !port1->isConnected(port2))
                        {
                            conn->setPos2(port2->scenePos());
                            conn->setPort2(port2);
                            conn->updatePath();
                            conn = 0;

                            emit graphChanged();

                            return true;
                        }
                    }

                    delete conn;
                    conn = 0;
                    return true;
                }
                break;
            }
    }
    return QObject::eventFilter(o, e);
}
Beispiel #24
0
/**
  * This scene event filter has been registered with all four corner grabber items.
  * When called, a pointer to the sending item is provided along with a generic
  * event.  A dynamic_cast is used to determine if the event type is one of the events
  * we are interrested in.
  */
bool StateBox::sceneEventFilter ( QGraphicsItem * watched, QEvent * event )
{
    qDebug() << " QEvent == " + QString::number(event->type());

    CornerGrabber * corner = dynamic_cast<CornerGrabber *>(watched);
    if ( corner == NULL) return false; // not expected to get here

    QGraphicsSceneMouseEvent * mevent = dynamic_cast<QGraphicsSceneMouseEvent*>(event);
    if ( mevent == NULL)
    {
        // this is not one of the mouse events we are interrested in
        return false;
    }


    switch (event->type() )
    {
            // if the mouse went down, record the x,y coords of the press, record it inside the corner object
        case QEvent::GraphicsSceneMousePress:
            {
                corner->setMouseState(CornerGrabber::kMouseDown);
                corner->mouseDownX = mevent->pos().x();
                corner->mouseDownY = mevent->pos().y();
            }
            break;

        case QEvent::GraphicsSceneMouseRelease:
            {
                corner->setMouseState(CornerGrabber::kMouseReleased);

            }
            break;

        case QEvent::GraphicsSceneMouseMove:
            {
                corner->setMouseState(CornerGrabber::kMouseMoving );
            }
            break;

        default:
            // we dont care about the rest of the events
            return false;
            break;
    }


    if ( corner->getMouseState() == CornerGrabber::kMouseMoving )
    {

        qreal x = mevent->pos().x(), y = mevent->pos().y();

        // depending on which corner has been grabbed, we want to move the position
        // of the item as it grows/shrinks accordingly. so we need to eitehr add
        // or subtract the offsets based on which corner this is.

        int XaxisSign = 0;
        int YaxisSign = 0;
        switch( corner->getCorner() )
        {
        case 0:
            {
                XaxisSign = +1;
                YaxisSign = +1;
            }
            break;

        case 1:
            {
                XaxisSign = -1;
                YaxisSign = +1;
            }
            break;

        case 2:
            {
                XaxisSign = -1;
                YaxisSign = -1;
            }
            break;

        case 3:
            {
                XaxisSign = +1;
                YaxisSign = -1;
            }
            break;

        }

        // if the mouse is being dragged, calculate a new size and also re-position
        // the box to give the appearance of dragging the corner out/in to resize the box

        int xMoved = corner->mouseDownX - x;
        int yMoved = corner->mouseDownY - y;

        int newWidth = _width + ( XaxisSign * xMoved);
        if ( newWidth < 40 ) newWidth  = 40;

        int newHeight = _height + (YaxisSign * yMoved) ;
        if ( newHeight < 40 ) newHeight = 40;

        int deltaWidth  =   newWidth - _width ;
        int deltaHeight =   newHeight - _height ;

        adjustSize(  deltaWidth ,   deltaHeight);

        deltaWidth *= (-1);
        deltaHeight *= (-1);

        if ( corner->getCorner() == 0 )
        {
            int newXpos = this->pos().x() + deltaWidth;
            int newYpos = this->pos().y() + deltaHeight;
            this->setPos(newXpos, newYpos);
        }
        else   if ( corner->getCorner() == 1 )
        {
            int newYpos = this->pos().y() + deltaHeight;
            this->setPos(this->pos().x(), newYpos);
        }
        else   if ( corner->getCorner() == 3 )
        {
            int newXpos = this->pos().x() + deltaWidth;
            this->setPos(newXpos,this->pos().y());
        }

        setCornerPositions();

        this->update();
    }

    return true;// true => do not send event to watched - we are finished with this event
}
Beispiel #25
0
static QEvent *cloneEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseButtonDblClick:
    case QEvent::MouseMove:
        return new QMouseEvent(*static_cast<QMouseEvent*>(e));
    case QEvent::KeyPress:
    case QEvent::KeyRelease:
        return new QKeyEvent(*static_cast<QKeyEvent*>(e));
    case QEvent::FocusIn:
    case QEvent::FocusOut:
        return new QFocusEvent(*static_cast<QFocusEvent*>(e));
    case QEvent::Enter:
        return new QEvent(*e);
    case QEvent::Leave:
        return new QEvent(*e);
        break;
    case QEvent::Paint:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Move:
        return new QMoveEvent(*static_cast<QMoveEvent*>(e));
    case QEvent::Resize:
        return new QResizeEvent(*static_cast<QResizeEvent*>(e));
    case QEvent::Create:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Destroy:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Show:
        return new QShowEvent(*static_cast<QShowEvent*>(e));
    case QEvent::Hide:
        return new QHideEvent(*static_cast<QHideEvent*>(e));
    case QEvent::Close:
        return new QCloseEvent(*static_cast<QCloseEvent*>(e));
    case QEvent::Quit:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ParentChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ParentAboutToChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ThreadChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::WindowActivate:
    case QEvent::WindowDeactivate:
        return new QEvent(*e);

    case QEvent::ShowToParent:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::HideToParent:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Wheel:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::WindowTitleChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::WindowIconChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ApplicationWindowIconChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ApplicationFontChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ApplicationLayoutDirectionChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ApplicationPaletteChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::PaletteChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Clipboard:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Speech:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::MetaCall:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::SockAct:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::WinEventAct:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::DeferredDelete:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::DragEnter:
        return new QDragEnterEvent(*static_cast<QDragEnterEvent*>(e));
    case QEvent::DragMove:
        return new QDragMoveEvent(*static_cast<QDragMoveEvent*>(e));
    case QEvent::DragLeave:
        return new QDragLeaveEvent(*static_cast<QDragLeaveEvent*>(e));
    case QEvent::Drop:
        return new QDropEvent(*static_cast<QDragMoveEvent*>(e));
    case QEvent::DragResponse:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ChildAdded:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ChildPolished:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#ifdef QT3_SUPPORT
    case QEvent::ChildInsertedRequest:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ChildInserted:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::LayoutHint:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#endif
    case QEvent::ChildRemoved:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ShowWindowRequest:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::PolishRequest:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Polish:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::LayoutRequest:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::UpdateRequest:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::UpdateLater:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::EmbeddingControl:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ActivateControl:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::DeactivateControl:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ContextMenu:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::InputMethod:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::AccessibilityPrepare:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::TabletMove:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::LocaleChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::LanguageChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::LayoutDirectionChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Style:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::TabletPress:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::TabletRelease:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::OkRequest:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::HelpRequest:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::IconDrag:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::FontChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::EnabledChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ActivationChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::StyleChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::IconTextChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ModifiedChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::MouseTrackingChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::WindowBlocked:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::WindowUnblocked:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::WindowStateChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::ToolTip:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::WhatsThis:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::StatusTip:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::ActionChanged:
    case QEvent::ActionAdded:
    case QEvent::ActionRemoved:
        return new QActionEvent(*static_cast<QActionEvent*>(e));

    case QEvent::FileOpen:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::Shortcut:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ShortcutOverride:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

#ifdef QT3_SUPPORT
    case QEvent::Accel:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::AccelAvailable:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#endif

    case QEvent::WhatsThisClicked:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::ToolBarChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::ApplicationActivate:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ApplicationDeactivate:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::QueryWhatsThis:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::EnterWhatsThisMode:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::LeaveWhatsThisMode:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::ZOrderChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::HoverEnter:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::HoverLeave:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::HoverMove:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::AccessibilityHelp:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::AccessibilityDescription:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

#ifdef QT_KEYPAD_NAVIGATION
    case QEvent::EnterEditFocus:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::LeaveEditFocus:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#endif
    case QEvent::AcceptDropsChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::MenubarUpdated:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::ZeroTimerEvent:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::GraphicsSceneMouseMove:
    case QEvent::GraphicsSceneMousePress:
    case QEvent::GraphicsSceneMouseRelease:
    case QEvent::GraphicsSceneMouseDoubleClick: {
        QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent*>(e);
        QGraphicsSceneMouseEvent *me2 = new QGraphicsSceneMouseEvent(me->type());
        me2->setWidget(me->widget());
        me2->setPos(me->pos());
        me2->setScenePos(me->scenePos());
        me2->setScreenPos(me->screenPos());
// ### for all buttons
        me2->setButtonDownPos(Qt::LeftButton, me->buttonDownPos(Qt::LeftButton));
        me2->setButtonDownPos(Qt::RightButton, me->buttonDownPos(Qt::RightButton));
        me2->setButtonDownScreenPos(Qt::LeftButton, me->buttonDownScreenPos(Qt::LeftButton));
        me2->setButtonDownScreenPos(Qt::RightButton, me->buttonDownScreenPos(Qt::RightButton));
        me2->setLastPos(me->lastPos());
        me2->setLastScenePos(me->lastScenePos());
        me2->setLastScreenPos(me->lastScreenPos());
        me2->setButtons(me->buttons());
        me2->setButton(me->button());
        me2->setModifiers(me->modifiers());
        return me2;
    }

    case QEvent::GraphicsSceneContextMenu: {
        QGraphicsSceneContextMenuEvent *me = static_cast<QGraphicsSceneContextMenuEvent*>(e);
        QGraphicsSceneContextMenuEvent *me2 = new QGraphicsSceneContextMenuEvent(me->type());
        me2->setWidget(me->widget());
        me2->setPos(me->pos());
        me2->setScenePos(me->scenePos());
        me2->setScreenPos(me->screenPos());
        me2->setModifiers(me->modifiers());
        me2->setReason(me->reason());
        return me2;
    }

    case QEvent::GraphicsSceneHoverEnter:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneHoverMove:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneHoverLeave:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneHelp:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneDragEnter:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneDragMove:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneDragLeave:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneDrop:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneWheel:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::KeyboardLayoutChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::DynamicPropertyChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::TabletEnterProximity:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::TabletLeaveProximity:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::NonClientAreaMouseMove:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::NonClientAreaMouseButtonPress:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::NonClientAreaMouseButtonRelease:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::NonClientAreaMouseButtonDblClick:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::MacSizeChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::ContentsRectChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::MacGLWindowChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::FutureCallOut:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::GraphicsSceneResize:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::GraphicsSceneMove: {
        QGraphicsSceneMoveEvent *me = static_cast<QGraphicsSceneMoveEvent*>(e);
        QGraphicsSceneMoveEvent *me2 = new QGraphicsSceneMoveEvent();
        me2->setWidget(me->widget());
        me2->setNewPos(me->newPos());
        me2->setOldPos(me->oldPos());
        return me2;
    }

    case QEvent::CursorChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::ToolTipChange:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::NetworkReplyUpdated:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::GrabMouse:
    case QEvent::UngrabMouse:
    case QEvent::GrabKeyboard:
    case QEvent::UngrabKeyboard:
        return new QEvent(*e);

#if defined(QT_MAC_USE_COCOA) && (QT_VERSION >= 0x040500)
    case QEvent::CocoaRequestModal:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#endif
    case QEvent::User:
    case QEvent::MaxUser:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    default:
        ;
    }
    return qcoreStateMachineHandler()->cloneEvent(e);
}
Beispiel #26
0
bool QNodesEditor::eventFilter(QObject *o, QEvent *e)
{
    QGraphicsSceneMouseEvent* me = (QGraphicsSceneMouseEvent*)e;

    const QPen unconnectedPen(QColor(0x3498db), 3);
    const QPen errorPen(QColor(0xe74c3c), 3);
    const QPen connectedPen(QColor(0x2c3e50), 3);

    switch ((int) e->type())
    {
        case QEvent::GraphicsSceneContextMenu:
        {
            QGraphicsItem *item = itemAt(me->scenePos());
            if (!item)
            {
                emit contextMenu(me);
            }
            else if (item->type() == QNEPort::Type)
            {
                emit portContextMenu(me, (QNEPort*)item);
            }
            else if (item->type() == QNEBlock::Type)
            {
                emit blockContextMenu(me, (QNEBlock*)item);
            }
            else if (item->type() == QNEConnection::Type)
            {
                emit connectionContextMenu(me, (QNEConnection*)item);
            }
            else
            {
                emit itemContextMenu(me, item);
            }
        }
        break;
        case QEvent::GraphicsSceneMousePress:
        {

            switch ((int) me->button())
            {
                case Qt::LeftButton:
                {
                    QGraphicsItem *item = itemAt(me->scenePos());
                    if (item && item->type() == QNEPort::Type)
                    {
                        m_connection = new QNEConnection(0);
                        m_scene->addItem(m_connection);
                        m_connection->setPort1((QNEPort*) item);
                        m_connection->setPos2(me->scenePos());
                        m_connection->setPen(unconnectedPen);

                        return true;
                    }
                    else if (item && item->type() == QNEBlock::Type)
                    {
                        /* if (selBlock)
                    selBlock->setSelected(); */
                        // selBlock = (QNEBlock*) item;
                    }
                    break;
                }
//                case Qt::RightButton:
//                {
//                    QGraphicsItem *item = itemAt(me->scenePos());
//                    if (item && (item->type() == QNEConnection::Type || item->type() == QNEBlock::Type))
//                    {
//                        delete item;
//                        return true;
//                    }
//                    break;
//                }
            }
        }
        case QEvent::GraphicsSceneMouseMove:
        {
            if (m_connection)
            {
                m_connection->setPos2(me->scenePos());

                QGraphicsItem *item = itemAt(me->scenePos());
                if (item && item->type() == QNEPort::Type)
                {
                    QNEPort *port1 = m_connection->port1();
                    QNEPort *port2 = (QNEPort*) item;
                    if (port1->block() != port2->block() &&
                            port1->isOutput() != port2->isOutput() &&
                            port1->portType() == port2->portType() &&
                            (port1->portRate() == port2->portRate() || port1->portRate() == 0 || port2->portRate() == 0) &&
                            !port1->isConnected(port2))
                    {
                        m_connection->setPen(connectedPen);
                    }
                    else
                    {
                        m_connection->setPen(errorPen);
                    }
                }
                else
                {
                    m_connection->setPen(unconnectedPen);
                }

                return true;
            }
            break;
        }
        case QEvent::GraphicsSceneMouseRelease:
        {
            if (m_connection && me->button() == Qt::LeftButton)
            {
                QGraphicsItem *item = itemAt(me->scenePos());
                if (item && item->type() == QNEPort::Type)
                {
                    QNEPort *port1 = m_connection->port1();
                    QNEPort *port2 = (QNEPort*) item;

                    if (port1->block() != port2->block() &&
                            port1->isOutput() != port2->isOutput() &&
                            port1->portType() == port2->portType() &&
                            !port1->isConnected(port2))
                    {
                        port1->connectedSignal.execute(port2);
                        port2->connectedSignal.execute(port1);

                        m_connection->setPort2(port2);
                        m_connection->setPen(connectedPen);
                        m_connection = 0;
                        return true;
                    }
                }

                delete m_connection;
                m_connection = 0;
                return true;
            }
            break;
        }
    }
    return QObject::eventFilter(o, e);
}
bool NetPanelController::eventFilter(QObject *watched, QEvent *event)
{
    if (event->type() == QEvent::GraphicsSceneMousePress) {
        m_watched = qobject_cast<Plasma::ToolButton *>(watched);
    } else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
        m_watched = 0;
    } else if (watched == m_moveButton && event->type() == QEvent::GraphicsSceneMouseMove) {
        QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
        QRect screenGeom = Kephal::ScreenUtils::screenGeometry(m_containment->screen());

        //only move when the mouse cursor is out of the controller to avoid an endless reposition cycle
        if (geometry().contains(me->screenPos())) {
            return false;
        }

        if (!screenGeom.contains(me->screenPos())) {
            //move panel to new screen if dragged there
            int targetScreen = Kephal::ScreenUtils::screenId(me->screenPos());
            //kDebug() << "Moving panel from screen" << containment()->screen() << "to screen" << targetScreen;
            m_containment->setScreen(targetScreen);
            return false;
        }

        //create a dead zone so you can go across the middle without having it hop to one side
        float dzFactor = 0.35;
        QPoint offset = QPoint(screenGeom.width()*dzFactor,screenGeom.height()*dzFactor);
        QRect deadzone = QRect(screenGeom.topLeft()+offset, screenGeom.bottomRight()-offset);
        if (deadzone.contains(me->screenPos())) {
            //kDebug() << "In the deadzone:" << deadzone;
            return false;
        }

        const Plasma::Location oldLocation = m_containment->location();
        Plasma::Location newLocation = oldLocation;
        float screenAspect = float(screenGeom.height())/screenGeom.width();

        /* Use diagonal lines so we get predictable behavior when moving the panel
         * y=topleft.y+(x-topleft.x)*aspectratio   topright < bottomleft
         * y=bottomleft.y-(x-topleft.x)*aspectratio   topleft < bottomright
         */
        if (me->screenPos().y() < screenGeom.y()+(me->screenPos().x()-screenGeom.x())*screenAspect) {
            if (me->screenPos().y() < screenGeom.bottomLeft().y()-(me->screenPos().x()-screenGeom.x())*screenAspect) {
                if (m_containment->location() == Plasma::TopEdge) {
                    return false;
                } else {
                    newLocation = Plasma::TopEdge;
                }
            } else if (m_containment->location() == Plasma::RightEdge) {
                    return false;
            } else {
                newLocation = Plasma::RightEdge;
            }
        } else {
            if (me->screenPos().y() < screenGeom.bottomLeft().y()-(me->screenPos().x()-screenGeom.x())*screenAspect) {
                if (m_containment->location() == Plasma::LeftEdge) {
                    return false;
                } else {
                    newLocation = Plasma::LeftEdge;
                }
            } else if(m_containment->location() == Plasma::BottomEdge) {
                    return false;
            } else {
                newLocation = Plasma::BottomEdge;
            }
        }

        m_containment->setLocation(newLocation);

    } else if (watched == m_resizeButton && event->type() == QEvent::GraphicsSceneMouseMove) {
        QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
        QPointF deltaPos(me->screenPos() - me->lastScreenPos());

        m_containment->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);

        switch (m_containment->location()) {
        case Plasma::LeftEdge:

            m_containment->setMinimumWidth(qBound((qreal)KIconLoader::SizeSmall, m_containment->size().width() + deltaPos.x(), (qreal)(KIconLoader::SizeEnormous*2)));
            m_containment->setMaximumWidth(m_containment->minimumWidth());

            break;
        case Plasma::RightEdge:

            m_containment->setMinimumWidth(qBound((qreal)KIconLoader::SizeSmall, m_containment->size().width() - deltaPos.x(), (qreal)(KIconLoader::SizeEnormous*2)));
            m_containment->setMaximumWidth(m_containment->minimumWidth());
            break;
        case Plasma::TopEdge:

            m_containment->setMinimumHeight(qBound((qreal)KIconLoader::SizeSmall, m_containment->size().height() + deltaPos.y(), (qreal)(KIconLoader::SizeEnormous*2)));
            m_containment->setMaximumHeight(m_containment->minimumHeight());
            break;
        case Plasma::BottomEdge:

            m_containment->setMinimumHeight(qBound((qreal)KIconLoader::SizeSmall, m_containment->size().height() - deltaPos.y(), (qreal)(KIconLoader::SizeEnormous*2)));
            m_containment->setMaximumHeight(m_containment->minimumHeight());
            break;
        default:
            break;
        }
    }
    return Plasma::Dialog::eventFilter(watched, event);
}
Beispiel #28
0
bool QNodesEditor::eventFilter(QObject *o, QEvent *e)
{
	QGraphicsSceneMouseEvent *me = (QGraphicsSceneMouseEvent*) e;

	switch ((int) e->type())
	{
	case QEvent::GraphicsSceneMousePress:
	{

		switch ((int) me->button())
		{
		case Qt::LeftButton:
		{
			QGraphicsItem *item = itemAt(me->scenePos());
			if (item && item->type() == QNEPort::Type)
			{
                conn = new QNEConnection(0);
                scene->addItem(conn);
				conn->setPort1((QNEPort*) item);
				conn->setPos1(item->scenePos());
				conn->setPos2(me->scenePos());
				conn->updatePath();

				return true;
			} else if (item && item->type() == QNEBlock::Type)
			{
				/* if (selBlock)
					selBlock->setSelected(); */
				// selBlock = (QNEBlock*) item;
			}
			break;
		}
		case Qt::RightButton:
		{
			QGraphicsItem *item = itemAt(me->scenePos());
			if (item && (item->type() == QNEConnection::Type))
			{
				QNEConnection *conn = (QNEConnection *) item;
				QNEBlock *node1 = (QNEBlock *) conn->port1()->parentItem();
				QNEBlock *node2 = (QNEBlock *) conn->port2()->parentItem();

				for(INodesEditorListener *listener : listeners)
				{
					listener->connectionDeleted(node1, node2);
				}

				delete item;
			}
			else if(item && (item->type() == QNEBlock::Type))
			{
				QNEBlock *block = (QNEBlock *) item;
				for(INodesEditorListener *listener : listeners)
				{
					listener->nodeDeleted(block->id(), block->type());
				}


				delete item;
			}

			// if (selBlock == (QNEBlock*) item)
				// selBlock = 0;

			break;
		}
		}
		break;
	}
	case QEvent::GraphicsSceneMouseMove:
	{
		if (conn)
		{
			conn->setPos2(me->scenePos());
			conn->updatePath();
			return true;
		}
		break;
	}
	case QEvent::GraphicsSceneMouseRelease:
	{
		if (conn && me->button() == Qt::LeftButton)
		{
			QGraphicsItem *item = itemAt(me->scenePos());
			if (item && item->type() == QNEPort::Type)
			{
				QNEPort *port1 = conn->port1();
				QNEPort *port2 = (QNEPort*) item;

				if (port1->block() != port2->block() && port1->isOutput() != port2->isOutput() && !port1->isConnected(port2))
				{
					conn->setPos2(port2->scenePos());
					conn->setPort2(port2);
					conn->updatePath();
					conn = 0;

					QNEBlock *node1 = (QNEBlock *) port1->parentItem();
					QNEBlock *node2 = (QNEBlock *) port2->parentItem();

					for(INodesEditorListener *listener : listeners)
					{
						listener->connectionMade(node1, node2);
					}

					return true;
				}
			}

			delete conn;
			conn = 0;
			return true;
		}
		break;
	}
	}
	return QObject::eventFilter(o, e);
}
Beispiel #29
0
static QEvent *cloneEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseButtonDblClick:
    case QEvent::MouseMove:
        return new QMouseEvent(*static_cast<QMouseEvent*>(e));
    case QEvent::KeyPress:
    case QEvent::KeyRelease:
        return new QKeyEvent(*static_cast<QKeyEvent*>(e));
    case QEvent::FocusIn:
    case QEvent::FocusOut:
        return new QFocusEvent(*static_cast<QFocusEvent*>(e));
    case QEvent::Enter:
        return new QEvent(*e);
    case QEvent::Leave:
        return new QEvent(*e);
        break;
    case QEvent::Paint:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Move:
        return new QMoveEvent(*static_cast<QMoveEvent*>(e));
    case QEvent::Resize:
        return new QResizeEvent(*static_cast<QResizeEvent*>(e));
    case QEvent::Create:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Destroy:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Show:
        return new QShowEvent(*static_cast<QShowEvent*>(e));
    case QEvent::Hide:
        return new QHideEvent(*static_cast<QHideEvent*>(e));
    case QEvent::Close:
        return new QCloseEvent(*static_cast<QCloseEvent*>(e));
    case QEvent::Quit:
        return new QEvent(*e);
    case QEvent::ParentChange:
        return new QEvent(*e);
    case QEvent::ParentAboutToChange:
        return new QEvent(*e);
    case QEvent::ThreadChange:
        return new QEvent(*e);

    case QEvent::WindowActivate:
    case QEvent::WindowDeactivate:
        return new QEvent(*e);

    case QEvent::ShowToParent:
        return new QEvent(*e);
    case QEvent::HideToParent:
        return new QEvent(*e);
#ifndef QT_NO_WHEELEVENT
    case QEvent::Wheel:
        return new QWheelEvent(*static_cast<QWheelEvent*>(e));
#endif //QT_NO_WHEELEVENT
    case QEvent::WindowTitleChange:
        return new QEvent(*e);
    case QEvent::WindowIconChange:
        return new QEvent(*e);
    case QEvent::ApplicationWindowIconChange:
        return new QEvent(*e);
    case QEvent::ApplicationFontChange:
        return new QEvent(*e);
    case QEvent::ApplicationLayoutDirectionChange:
        return new QEvent(*e);
    case QEvent::ApplicationPaletteChange:
        return new QEvent(*e);
    case QEvent::PaletteChange:
        return new QEvent(*e);
    case QEvent::Clipboard:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::Speech:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::MetaCall:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::SockAct:
        return new QEvent(*e);
    case QEvent::WinEventAct:
        return new QEvent(*e);
    case QEvent::DeferredDelete:
        return new QEvent(*e);
#ifndef QT_NO_DRAGANDDROP 
   case QEvent::DragEnter:
        return new QDragEnterEvent(*static_cast<QDragEnterEvent*>(e));
    case QEvent::DragMove:
        return new QDragMoveEvent(*static_cast<QDragMoveEvent*>(e));
    case QEvent::DragLeave:
        return new QDragLeaveEvent(*static_cast<QDragLeaveEvent*>(e));
    case QEvent::Drop:
        return new QDropEvent(*static_cast<QDragMoveEvent*>(e));
    case QEvent::DragResponse:
        return new QDragResponseEvent(*static_cast<QDragResponseEvent*>(e));
#endif
    case QEvent::ChildAdded:
        return new QChildEvent(*static_cast<QChildEvent*>(e));
    case QEvent::ChildPolished:
        return new QChildEvent(*static_cast<QChildEvent*>(e));
#ifdef QT3_SUPPORT
    case QEvent::ChildInsertedRequest:
        return new QEvent(*e);
    case QEvent::ChildInserted:
        return new QChildEvent(*static_cast<QChildEvent*>(e));
    case QEvent::LayoutHint:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#endif
    case QEvent::ChildRemoved:
        return new QChildEvent(*static_cast<QChildEvent*>(e));
    case QEvent::ShowWindowRequest:
        return new QEvent(*e);
    case QEvent::PolishRequest:
        return new QEvent(*e);
    case QEvent::Polish:
        return new QEvent(*e);
    case QEvent::LayoutRequest:
        return new QEvent(*e);
    case QEvent::UpdateRequest:
        return new QEvent(*e);
    case QEvent::UpdateLater:
        return new QEvent(*e);

    case QEvent::EmbeddingControl:
        return new QEvent(*e);
    case QEvent::ActivateControl:
        return new QEvent(*e);
    case QEvent::DeactivateControl:
        return new QEvent(*e);

#ifndef QT_NO_CONTEXTMENU
    case QEvent::ContextMenu:
        return new QContextMenuEvent(*static_cast<QContextMenuEvent*>(e));
#endif
    case QEvent::InputMethod:
        return new QInputMethodEvent(*static_cast<QInputMethodEvent*>(e));
    case QEvent::AccessibilityPrepare:
        return new QEvent(*e);
#ifndef QT_NO_TABLETEVENT
    case QEvent::TabletMove:
        return new QTabletEvent(*static_cast<QTabletEvent*>(e));
#endif //QT_NO_TABLETEVENT
    case QEvent::LocaleChange:
        return new QEvent(*e);
    case QEvent::LanguageChange:
        return new QEvent(*e);
    case QEvent::LayoutDirectionChange:
        return new QEvent(*e);
    case QEvent::Style:
        return new QEvent(*e);
#ifndef QT_NO_TABLETEVENT
    case QEvent::TabletPress:
        return new QTabletEvent(*static_cast<QTabletEvent*>(e));
    case QEvent::TabletRelease:
        return new QTabletEvent(*static_cast<QTabletEvent*>(e));
#endif //QT_NO_TABLETEVENT
    case QEvent::OkRequest:
        return new QEvent(*e);
    case QEvent::HelpRequest:
        return new QEvent(*e);

    case QEvent::IconDrag:
        return new QIconDragEvent(*static_cast<QIconDragEvent*>(e));

    case QEvent::FontChange:
        return new QEvent(*e);
    case QEvent::EnabledChange:
        return new QEvent(*e);
    case QEvent::ActivationChange:
        return new QEvent(*e);
    case QEvent::StyleChange:
        return new QEvent(*e);
    case QEvent::IconTextChange:
        return new QEvent(*e);
    case QEvent::ModifiedChange:
        return new QEvent(*e);
    case QEvent::MouseTrackingChange:
        return new QEvent(*e);

    case QEvent::WindowBlocked:
        return new QEvent(*e);
    case QEvent::WindowUnblocked:
        return new QEvent(*e);
    case QEvent::WindowStateChange:
        return new QWindowStateChangeEvent(*static_cast<QWindowStateChangeEvent*>(e));

    case QEvent::ToolTip:
        return new QHelpEvent(*static_cast<QHelpEvent*>(e));
    case QEvent::WhatsThis:
        return new QHelpEvent(*static_cast<QHelpEvent*>(e));
#ifndef QT_NO_STATUSTIP
    case QEvent::StatusTip:
        return new QStatusTipEvent(*static_cast<QStatusTipEvent*>(e));
#endif //QT_NO_STATUSTIP
#ifndef QT_NO_ACTION
    case QEvent::ActionChanged:
    case QEvent::ActionAdded:
    case QEvent::ActionRemoved:
        return new QActionEvent(*static_cast<QActionEvent*>(e));
#endif
    case QEvent::FileOpen:
        return new QFileOpenEvent(*static_cast<QFileOpenEvent*>(e));

#ifndef QT_NO_SHORTCUT
    case QEvent::Shortcut:
        return new QShortcutEvent(*static_cast<QShortcutEvent*>(e));
#endif //QT_NO_SHORTCUT
    case QEvent::ShortcutOverride:
        return new QKeyEvent(*static_cast<QKeyEvent*>(e));

#ifdef QT3_SUPPORT
    case QEvent::Accel:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::AccelAvailable:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#endif

#ifndef QT_NO_WHATSTHIS
    case QEvent::WhatsThisClicked:
        return new QWhatsThisClickedEvent(*static_cast<QWhatsThisClickedEvent*>(e));
#endif //QT_NO_WHATSTHIS

#ifndef QT_NO_TOOLBAR
    case QEvent::ToolBarChange:
        return new QToolBarChangeEvent(*static_cast<QToolBarChangeEvent*>(e));
#endif //QT_NO_TOOLBAR

    case QEvent::ApplicationActivate:
        return new QEvent(*e);
    case QEvent::ApplicationDeactivate:
        return new QEvent(*e);

    case QEvent::QueryWhatsThis:
        return new QHelpEvent(*static_cast<QHelpEvent*>(e));
    case QEvent::EnterWhatsThisMode:
        return new QEvent(*e);
    case QEvent::LeaveWhatsThisMode:
        return new QEvent(*e);

    case QEvent::ZOrderChange:
        return new QEvent(*e);

    case QEvent::HoverEnter:
    case QEvent::HoverLeave:
    case QEvent::HoverMove:
        return new QHoverEvent(*static_cast<QHoverEvent*>(e));

    case QEvent::AccessibilityHelp:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    case QEvent::AccessibilityDescription:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

#ifdef QT_KEYPAD_NAVIGATION
    case QEvent::EnterEditFocus:
        return new QEvent(*e);
    case QEvent::LeaveEditFocus:
        return new QEvent(*e);
#endif
    case QEvent::AcceptDropsChange:
        return new QEvent(*e);

#ifdef QT3_SUPPORT
    case QEvent::MenubarUpdated:
        return new QMenubarUpdatedEvent(*static_cast<QMenubarUpdatedEvent*>(e));
#endif

    case QEvent::ZeroTimerEvent:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#ifndef QT_NO_GRAPHICSVIEW
    case QEvent::GraphicsSceneMouseMove:
    case QEvent::GraphicsSceneMousePress:
    case QEvent::GraphicsSceneMouseRelease:
    case QEvent::GraphicsSceneMouseDoubleClick: {
        QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent*>(e);
        QGraphicsSceneMouseEvent *me2 = new QGraphicsSceneMouseEvent(me->type());
        me2->setWidget(me->widget());
        me2->setPos(me->pos());
        me2->setScenePos(me->scenePos());
        me2->setScreenPos(me->screenPos());
// ### for all buttons
        me2->setButtonDownPos(Qt::LeftButton, me->buttonDownPos(Qt::LeftButton));
        me2->setButtonDownPos(Qt::RightButton, me->buttonDownPos(Qt::RightButton));
        me2->setButtonDownScreenPos(Qt::LeftButton, me->buttonDownScreenPos(Qt::LeftButton));
        me2->setButtonDownScreenPos(Qt::RightButton, me->buttonDownScreenPos(Qt::RightButton));
        me2->setLastPos(me->lastPos());
        me2->setLastScenePos(me->lastScenePos());
        me2->setLastScreenPos(me->lastScreenPos());
        me2->setButtons(me->buttons());
        me2->setButton(me->button());
        me2->setModifiers(me->modifiers());
        return me2;
    }

    case QEvent::GraphicsSceneContextMenu: {
        QGraphicsSceneContextMenuEvent *me = static_cast<QGraphicsSceneContextMenuEvent*>(e);
        QGraphicsSceneContextMenuEvent *me2 = new QGraphicsSceneContextMenuEvent(me->type());
        me2->setWidget(me->widget());
        me2->setPos(me->pos());
        me2->setScenePos(me->scenePos());
        me2->setScreenPos(me->screenPos());
        me2->setModifiers(me->modifiers());
        me2->setReason(me->reason());
        return me2;
    }

    case QEvent::GraphicsSceneHoverEnter:
    case QEvent::GraphicsSceneHoverMove:
    case QEvent::GraphicsSceneHoverLeave: {
        QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(e);
        QGraphicsSceneHoverEvent *he2 = new QGraphicsSceneHoverEvent(he->type());
        he2->setPos(he->pos());
        he2->setScenePos(he->scenePos());
        he2->setScreenPos(he->screenPos());
        he2->setLastPos(he->lastPos());
        he2->setLastScenePos(he->lastScenePos());
        he2->setLastScreenPos(he->lastScreenPos());
        he2->setModifiers(he->modifiers());
        return he2;
    }
    case QEvent::GraphicsSceneHelp:
        return new QHelpEvent(*static_cast<QHelpEvent*>(e));
    case QEvent::GraphicsSceneDragEnter:
    case QEvent::GraphicsSceneDragMove:
    case QEvent::GraphicsSceneDragLeave:
    case QEvent::GraphicsSceneDrop: {
        QGraphicsSceneDragDropEvent *dde = static_cast<QGraphicsSceneDragDropEvent*>(e);
        QGraphicsSceneDragDropEvent *dde2 = new QGraphicsSceneDragDropEvent(dde->type());
        dde2->setPos(dde->pos());
        dde2->setScenePos(dde->scenePos());
        dde2->setScreenPos(dde->screenPos());
        dde2->setButtons(dde->buttons());
        dde2->setModifiers(dde->modifiers());
        return dde2;
    }
    case QEvent::GraphicsSceneWheel: {
        QGraphicsSceneWheelEvent *we = static_cast<QGraphicsSceneWheelEvent*>(e);
        QGraphicsSceneWheelEvent *we2 = new QGraphicsSceneWheelEvent(we->type());
        we2->setPos(we->pos());
        we2->setScenePos(we->scenePos());
        we2->setScreenPos(we->screenPos());
        we2->setButtons(we->buttons());
        we2->setModifiers(we->modifiers());
        we2->setOrientation(we->orientation());
        we2->setDelta(we->delta());
        return we2;
    }
#endif
    case QEvent::KeyboardLayoutChange:
        return new QEvent(*e);

    case QEvent::DynamicPropertyChange:
        return new QDynamicPropertyChangeEvent(*static_cast<QDynamicPropertyChangeEvent*>(e));

#ifndef QT_NO_TABLETEVENT
    case QEvent::TabletEnterProximity:
    case QEvent::TabletLeaveProximity:
        return new QTabletEvent(*static_cast<QTabletEvent*>(e));
#endif //QT_NO_TABLETEVENT

    case QEvent::NonClientAreaMouseMove:
    case QEvent::NonClientAreaMouseButtonPress:
    case QEvent::NonClientAreaMouseButtonRelease:
    case QEvent::NonClientAreaMouseButtonDblClick:
        return new QMouseEvent(*static_cast<QMouseEvent*>(e));

    case QEvent::MacSizeChange:
        return new QEvent(*e);

    case QEvent::ContentsRectChange:
        return new QEvent(*e);

    case QEvent::MacGLWindowChange:
        return new QEvent(*e);

    case QEvent::FutureCallOut:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#ifndef QT_NO_GRAPHICSVIEW
    case QEvent::GraphicsSceneResize: {
        QGraphicsSceneResizeEvent *re = static_cast<QGraphicsSceneResizeEvent*>(e);
        QGraphicsSceneResizeEvent *re2 = new QGraphicsSceneResizeEvent();
        re2->setOldSize(re->oldSize());
        re2->setNewSize(re->newSize());
        return re2;
    }
    case QEvent::GraphicsSceneMove: {
        QGraphicsSceneMoveEvent *me = static_cast<QGraphicsSceneMoveEvent*>(e);
        QGraphicsSceneMoveEvent *me2 = new QGraphicsSceneMoveEvent();
        me2->setWidget(me->widget());
        me2->setNewPos(me->newPos());
        me2->setOldPos(me->oldPos());
        return me2;
    }
#endif
    case QEvent::CursorChange:
        return new QEvent(*e);
    case QEvent::ToolTipChange:
        return new QEvent(*e);

    case QEvent::NetworkReplyUpdated:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;

    case QEvent::GrabMouse:
    case QEvent::UngrabMouse:
    case QEvent::GrabKeyboard:
    case QEvent::UngrabKeyboard:
        return new QEvent(*e);

    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
        return new QTouchEvent(*static_cast<QTouchEvent*>(e));

#ifndef QT_NO_GESTURES
    case QEvent::NativeGesture:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
#endif

    case QEvent::RequestSoftwareInputPanel:
    case QEvent::CloseSoftwareInputPanel:
        return new QEvent(*e);

    case QEvent::UpdateSoftKeys:
        return new QEvent(*e);

    case QEvent::User:
    case QEvent::MaxUser:
        Q_ASSERT_X(false, "cloneEvent()", "not implemented");
        break;
    default:
        ;
    }
    return qcoreStateMachineHandler()->cloneEvent(e);
}
void DashboardWindowContainer::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
	event->accept();

	if (G_UNLIKELY(m_trackingMouseDirection)) {

		int deltaX = event->pos().x() - event->buttonDownPos(Qt::LeftButton).x();
		int deltaY = event->pos().y() - event->buttonDownPos(Qt::LeftButton).y();

		if ((deltaX * deltaX + deltaY * deltaY) <
			Settings::LunaSettings()->tapRadiusSquared)
			return;

		m_trackingMouseDirection = false;

		if (abs(deltaX) > abs(deltaY)) {
			m_vertLockedMovement = false;
			Q_EMIT signalItemDragState(true);
		} else if(m_dashboardManualDrag) {
			QGraphicsSceneMouseEvent ev;
			ev.setCanceled(true);
			mouseReleaseEvent(&ev);
			m_dashboardManualDrag = false;
		}
	}

	if(m_isMenu && m_vertLockedMovement)
		return;

	if (m_vertLockedMovement) {

		// Set the flag that a vertical mouse move is in progress, so that we can change the # of items getting painted.
		if(false == m_verticalMouseMoveInProgress) 
			m_verticalMouseMoveInProgress = true;

		int deltaY = event->pos().y() - event->lastPos().y();
		if (deltaY == 0) {
			return;
		}

		setScrollBottom(m_scrollBottom - deltaY);

		// 	Set the direction of the flick
		if(Ignore == m_FlickDirection) {
			if(deltaY > 0) {
				m_FlickDirection = FlickDown;
			}
			else {
				m_FlickDirection = FlickUp;
			}
		}

		showOrHideMasks();

		return;
	}

	
	if (DashboardWindow* w = m_draggedWindow.data()) {
		if(!m_dashboardManualDrag) {
			// draw the window
			int deltaX = event->pos().x() - event->lastPos().x();
			if (deltaX == 0)
				return;

			w->setPos(MAX(w->boundingRect().width()/2, w->pos().x() + deltaX), w->pos().y());
		} else {
			// send the mouse events to the window
			int winX = event->pos().x() + (m_isMenu ? 0 : w->boundingRect().width()/2);
			int winY = event->pos().y() - w->pos().y() + w->boundingRect().height()/2;

			// send the mouse down to the web app side
			Event ev;
			ev.type = Event::PenMove;
			ev.setMainFinger(true);
			ev.x = winX;
			ev.y = winY;
			ev.clickCount = 1;
			ev.modifiers = Event::modifiersFromQt(event->modifiers());
			ev.time = Time::curSysTimeMs();

			w->inputEvent(&ev);
		}
	}
}