Exemplo n.º 1
0
bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
{
    Q_UNUSED(o);

    if (!m_drag) {
        if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
            disableEventFilter();
            exitDndEventLoop();
            return true; // block the key release
        }
        return false;
    }

    switch (e->type()) {
        case QEvent::ShortcutOverride:
            // prevent accelerators from firing while dragging
            e->accept();
            return true;

        case QEvent::KeyPress:
        case QEvent::KeyRelease:
        {
            QKeyEvent *ke = static_cast<QKeyEvent *>(e);
            if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) {
                cancel();
                disableEventFilter();
                exitDndEventLoop();

            }
            return true; // Eat all key events
        }

        case QEvent::MouseMove:
        {
            QPoint nativePosition = getNativeMousePos(e, o);
            move(nativePosition);
            return true; // Eat all mouse move events
        }
        case QEvent::MouseButtonRelease:
            disableEventFilter();
            if (canDrop()) {
                QPoint nativePosition = getNativeMousePos(e, o);
                drop(nativePosition);
            } else {
                cancel();
            }
            exitDndEventLoop();
            QCoreApplication::postEvent(o, new QMouseEvent(*static_cast<QMouseEvent *>(e)));
            return true; // defer mouse release events until drag event loop has returned
        case QEvent::MouseButtonDblClick:
        case QEvent::Wheel:
            return true;
        default:
             break;
    }
    return false;
}
Exemplo n.º 2
0
void DrMarioApp::update() {
  bool dropped = false;
  for (auto &pill : pills_) {
    if (canDrop(pill)) {
      pill.drop();
      dropped = true;
    }
  }
  if (dropped)
    return;

  if (tryErase())
    return;

  pills_.emplace_back(dropPortal(), Blue, Red);
  if (!canDrop(pills_.back()))
    over_ = true;
}
Exemplo n.º 3
0
void QWaylandDrag::setResponse(const QPlatformDragQtResponse &response)
{
    setCanDrop(response.isAccepted());

    if (canDrop()) {
        updateCursor(defaultAction(drag()->supportedActions(), m_display->currentInputDevice()->modifiers()));
    } else {
        updateCursor(Qt::IgnoreAction);
    }
}
Exemplo n.º 4
0
void QWaylandDrag::updateTarget(const QString &mimeType)
{
    setCanDrop(!mimeType.isEmpty());

    if (canDrop()) {
        updateCursor(defaultAction(drag()->supportedActions(), m_display->currentInputDevice()->modifiers()));
    } else {
        updateCursor(Qt::IgnoreAction);
    }
}
Exemplo n.º 5
0
bool QBasicDrag::eventFilter(QObject *o, QEvent *e)
{
    Q_UNUSED(o);

    if (!m_drag) {
        if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
            disableEventFilter();
            exitDndEventLoop();
            return true; // block the key release
        }
        return false;
    }

    switch (e->type()) {
        case QEvent::ShortcutOverride:
            // prevent accelerators from firing while dragging
            e->accept();
            return true;

        case QEvent::KeyPress:
        case QEvent::KeyRelease:
        {
            QKeyEvent *ke = static_cast<QKeyEvent *>(e);
            if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) {
                cancel();
                disableEventFilter();
                exitDndEventLoop();

            }
            return true; // Eat all key events
        }

        case QEvent::MouseMove:
            move(static_cast<QMouseEvent *>(e));
            return true; // Eat all mouse events

        case QEvent::MouseButtonRelease:
            disableEventFilter();
            if (canDrop()) {
                drop(static_cast<QMouseEvent *>(e));
            } else {
                cancel();
            }
            exitDndEventLoop();
            return true; // Eat all mouse events

        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonDblClick:
        case QEvent::Wheel:
            return true;
        default:
             break;
    }
    return false;
}
Exemplo n.º 6
0
int main()
{
	int i=0;
	init_devices();
	lcd_set_4bit();
	lcd_init();
	color_sensor_scaling();
	/*
	//variable 'i' scales at 13,14 for sharp sensor for velocitty 240 240
	//u turn 1600ms at 200,200 velocity
	velocity(200,200);
	left();
	_delay_ms(1600);
	stop();
	while(1);
	
	threshold=6000;
	
	right();
	while(ADC_Conversion(11)<65)
	{
		i++;
		lcd_print(1,11,i,3);
	}
	stop();
	lcd_print(2,11,scan(),1);
	stop();
	while(1);
	*/
	setIndicatorAndColor();
	threshold=6000;
	ct = 0; adj = 2;
	//lcd("Begin");
	while (sorted<total)
	{
		canDrop();
		//buzzer_on();
		//_delay_ms(500);
		//buzzer_off();
		if (visitedCount == 3)
			predict();
		if (sorted == total)
			break;
		pickup();
		traverseToSort(ct, ct % 2 + 4);
		sortCheck();
	}
	for (i = 0; i<4; i++);
		//..printf("%d %d\n", term[i][0], term[i][1]);
	//..printf("Sort 0=%dSort 1=%d\nArm 0=%dArm 1=%d\n", sort[0], sort[1], arm[0], arm[1]);
	//..printf("Cost=%d\nSORTED!!!!!\n", cost + 7);
	//getch();
	return 0;
}
Exemplo n.º 7
0
void NodeConnectorView::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
    if(mTemporaryLink != nullptr)
    {
        NodeConnectorView* itemColliding = canDrop(event->scenePos());
        if(itemColliding != nullptr)
        {
            if(isOutput())
                emit draggingLinkDropped(socketView(), itemColliding->socketView());
            else
                emit draggingLinkDropped(itemColliding->socketView(), socketView());
        }

        mHoveredConnector = nullptr;

        // From Qt: It is more efficient to remove the item from the QGraphicsScene before destroying the item.
        scene()->removeItem(mTemporaryLink);
        delete mTemporaryLink;
        mTemporaryLink = nullptr;
    }
}
Exemplo n.º 8
0
int main()
{
	int i;
	setIndicatorAndColor();
	ct=0;adj=2;
	while(sorted<total)
	{
		canDrop();
		if(visitedCount==3)
			predict();
		if(sorted==total)
			break;
		pickup();
		traverseToSort(ct,ct%2+4);
		sortCheck();
	}
	for(i=0;i<4;i++)
		printf("%d %d\n",term[i][0],term[i][1]);
	printf("Sort 0=%dSort 1=%d\nArm 0=%dArm 1=%d\n",sort[0],sort[1],arm[0],arm[1]);
	printf("Cost=%d\nSORTED!!!!!\n",cost+7);
	//getch();
	return 0;
}
Exemplo n.º 9
0
void QBasicDrag::updateCursor(Qt::DropAction action)
{
#ifndef QT_NO_CURSOR
    Qt::CursorShape cursorShape = Qt::ForbiddenCursor;
    if (canDrop()) {
        switch (action) {
        case Qt::CopyAction:
            cursorShape = Qt::DragCopyCursor;
            break;
        case Qt::LinkAction:
            cursorShape = Qt::DragLinkCursor;
            break;
        default:
            cursorShape = Qt::DragMoveCursor;
            break;
        }
    }

    QCursor *cursor = QGuiApplication::overrideCursor();
    QPixmap pixmap = m_drag->dragCursor(action);
    if (!cursor) {
        QGuiApplication::changeOverrideCursor((pixmap.isNull()) ? QCursor(cursorShape) : QCursor(pixmap));
    } else {
        if (!pixmap.isNull()) {
            if ((cursor->pixmap().cacheKey() != pixmap.cacheKey())) {
                QGuiApplication::changeOverrideCursor(QCursor(pixmap));
            }
        } else {
            if (cursorShape != cursor->shape()) {
                QGuiApplication::changeOverrideCursor(QCursor(cursorShape));
            }
        }
    }
#endif
    updateAction(action);
}