Ejemplo n.º 1
0
void GraphicsView::keyPressEvent(QKeyEvent *event)
{
	switch(event->key())
	{
		case Qt::Key_Left:
			moveSelectedItemsBy(0 - MOVE_STEPS, 0);
			break;
		case Qt::Key_Up:
			moveSelectedItemsBy(0, 0 - MOVE_STEPS);
			break;
		case Qt::Key_Right:
			moveSelectedItemsBy(MOVE_STEPS, 0);
			break;
		case Qt::Key_Down:
			moveSelectedItemsBy(0, MOVE_STEPS);
			break;
		default:
			QGraphicsView::keyPressEvent(event);
			break;
	}
}
Ejemplo n.º 2
0
void SnapshotCanvas::keyPressEvent(QKeyEvent *event)
{
    if (!m_captureKeyboardEvents) {
        QGraphicsView::keyPressEvent(event);
        return;
    }

    switch(event->key()) {
    case Qt::Key_Backspace:
    case Qt::Key_Delete:
        removeSelectedItems();
        break;
    case Qt::Key_Escape:
        deselectItems();
        break;
    case Qt::Key_Up:
        moveSelectedItemsBy(0, -2);
        break;
    case Qt::Key_Right:
        moveSelectedItemsBy(2, 0);
        break;
    case Qt::Key_Down:
        moveSelectedItemsBy(0, 2);
        break;
    case Qt::Key_Left:
        moveSelectedItemsBy(-2, 0);
        break;
    }

    if (event->matches(QKeySequence::SelectAll)) {
        QPainterPath selectionArea;
        selectionArea.addRect(sceneRect());
        m_scene->setSelectionArea(selectionArea);
    } else if (event->matches(QKeySequence::Copy)) {
        copy();
    } else if (event->matches(QKeySequence::Paste)) {
        paste();
    }
}