Exemple #1
0
void Window::setMouseCursor(MouseCursor cursor)
{
    switch (cursor)
    {
        case MouseCursor::None: hideMouseCursor(); break;
        case MouseCursor::Default: useDefaultMouseCursor(); break;
        case MouseCursor::Custom: useCustomMouseCursor(); break;
        default: break;
    }
}
Exemple #2
0
void window::Window::open(const char *title, int width, int height, bool fullscreen, int msaa_level) {
	if (_fail) return;		

    if (msaa_level > 0) {
        glfwWindowHint(GLFW_SAMPLES, msaa_level);
					
        _aa = msaa_level;
    }
	
	glfwWindowHint(GLFW_RED_BITS, 8);
	glfwWindowHint(GLFW_GREEN_BITS, 8);
	glfwWindowHint(GLFW_BLUE_BITS, 8);
	glfwWindowHint(GLFW_ALPHA_BITS, 8);
	glfwWindowHint(GLFW_DEPTH_BITS, 24);
	glfwWindowHint(GLFW_STENCIL_BITS, 8);
	
	glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
	// opengl 3.3
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
		
	//glfwWindowHint(GLFW_STEREO, GL_TRUE);
			
	_primary_monitor = glfwGetPrimaryMonitor();
					
	_glfw_vid_mode = glfwGetVideoMode(_primary_monitor);
	
	if (width == 0 && height == 0) {
        width  = _glfw_vid_mode->width;
        height = _glfw_vid_mode->height;
        
        setRefreshRate(_glfw_vid_mode->refreshRate);
	}
					
	if (fullscreen) {
        _glfw_window = glfwCreateWindow(width, height, title, _primary_monitor, NULL);
	} else {
        _glfw_window = glfwCreateWindow(width, height, title, NULL, NULL);
	}
					
	if (!_glfw_window) {
        log("open(...) failed");
        _fail = true;
        
        return;
	}
					
	glfwMakeContextCurrent(_glfw_window);
				
	_window_width  = width;
	_window_height = height;
    
    hideMouseCursor();
    setVSync();
}
Exemple #3
0
void GenericCodeEditor::keyPressEvent(QKeyEvent * event)
{
    hideMouseCursor(event);

    QTextCursor cursor( textCursor() );

    bool updateCursor = false;

    if (event == QKeySequence::InsertLineSeparator) {
        // override to avoid entering a "soft" new line
        cursor.insertBlock();
        updateCursor = true;
    } else {
        switch (event->key()) {
        case Qt::Key_BraceRight:
        case Qt::Key_BracketRight:
        case Qt::Key_ParenRight:
            handleKeyRightParentheses( event, cursor );
            break;

        case Qt::Key_Delete:
            handleKeyDelete( event, cursor );
            break;

        case Qt::Key_Backspace:
            handleKeyBackspace( event, cursor, updateCursor );
            break;

        case Qt::Key_Down:
            handleKeyDown( event, cursor );
            break;

        case Qt::Key_Up:
            handleKeyUp( event, cursor );
            break;

        default:
            QPlainTextEdit::keyPressEvent(event);
        }
    }

    if (updateCursor) {
        cursor.setVerticalMovementX(-1);
        setTextCursor( cursor );
        ensureCursorVisible();
    }

    if (mDoc->keyDownActionEnabled() || Main::documentManager()->globalKeyDownActionEnabled())
        doKeyAction(event);
}
Exemple #4
0
void GenericCodeEditor::hideMouseCursor(QKeyEvent * event)
{
    switch (event->key()) {
    case Qt::Key_Shift:
    case Qt::Key_Control:
    case Qt::Key_Meta:
    case Qt::Key_Alt:
    case Qt::Key_Super_L:
    case Qt::Key_Super_R:
    case Qt::Key_Hyper_L:
    case Qt::Key_Hyper_R:
    case Qt::Key_Menu:
        return;

    default:
        hideMouseCursor();
    }
}
Exemple #5
0
void GenericCodeEditor::keyPressEvent(QKeyEvent * e)
{
    hideMouseCursor(e);

    QTextCursor cursor( textCursor() );

    switch (e->key()) {
    case Qt::Key_Enter:
    case Qt::Key_Return:
        // override to avoid entering a "soft" new line when certain modifier is held
        cursor.insertBlock();
        break;

    case Qt::Key_Delete:
        if (e->modifiers() & Qt::META) {
            cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
            cursor.removeSelectedText();
        } else
            QPlainTextEdit::keyPressEvent(e);
        break;

    case Qt::Key_Backspace:
        if (e->modifiers() & Qt::META) {
            cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
            cursor.removeSelectedText();
        } else
            QPlainTextEdit::keyPressEvent(e);
        break;

    case Qt::Key_Down:
    {
        if (cursor.block() == textDocument()->lastBlock()) {
            QTextCursor::MoveMode moveMode = e->modifiers() & Qt::SHIFT ? QTextCursor::KeepAnchor
                                                                        : QTextCursor::MoveAnchor;

            cursor.movePosition(QTextCursor::EndOfBlock, moveMode);
            setTextCursor(cursor);
        } else
            QPlainTextEdit::keyPressEvent(e);
        break;
    }

    case Qt::Key_Up:
    {
        if (cursor.block() == textDocument()->firstBlock()) {
            QTextCursor::MoveMode moveMode = e->modifiers() & Qt::SHIFT ? QTextCursor::KeepAnchor
                                                                        : QTextCursor::MoveAnchor;

            cursor.movePosition(QTextCursor::StartOfBlock, moveMode);
            setTextCursor(cursor);
        } else
            QPlainTextEdit::keyPressEvent(e);
        break;
    }

    default:
        QPlainTextEdit::keyPressEvent(e);
    }

    switch (e->key()) {
    case Qt::Key_Enter:
    case Qt::Key_Return:
    case Qt::Key_Backspace:
        cursor.setVerticalMovementX(-1);
        setTextCursor( cursor );
        ensureCursorVisible();
        break;
    default:;
    }
}
void ScCodeEditor::keyPressEvent( QKeyEvent *e )
{
    hideMouseCursor(e);

    QTextCursor cursor( textCursor() );
    bool cursorMoved = true;

    if (e == QKeySequence::MoveToNextWord)
        moveToNextToken( cursor, QTextCursor::MoveAnchor );
    else if (e == QKeySequence::MoveToPreviousWord)
        moveToPreviousToken( cursor, QTextCursor::MoveAnchor );
    else if (e == QKeySequence::SelectNextWord)
        moveToNextToken( cursor, QTextCursor::KeepAnchor );
    else if (e == QKeySequence::SelectPreviousWord)
        moveToPreviousToken( cursor, QTextCursor::KeepAnchor );
    else
        cursorMoved = false;

    if (cursorMoved) {
        setTextCursor( cursor );
        return;
    }

    switch (e->key()) {
    case Qt::Key_Home:
    {
        Qt::KeyboardModifiers mods(e->modifiers());
        if (mods && mods != Qt::ShiftModifier) {
            GenericCodeEditor::keyPressEvent(e);
            return;
        }

        QTextCursor::MoveMode mode =
            mods & Qt::ShiftModifier ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor;

        QTextCursor c(textCursor());
        QTextBlock b(c.block());

        int pos = indentedStartOfLine(b);
        pos += b.position();

        if (c.position() == pos)
            c.movePosition(QTextCursor::StartOfLine, mode);
        else
            c.setPosition(pos, mode);

        setTextCursor(c);

        return;
    }

    case Qt::Key_Backtab:
    {
        QTextCursor cursor = textCursor();
        insertSpaceToNextTabStop( cursor );
        ensureCursorVisible();
        return;
    }
    case Qt::Key_Backspace:
        if (mInsertMatchingTokens && !overwriteMode() && e->modifiers() == 0)
            if (removeMatchingTokens())
                break;
        GenericCodeEditor::keyPressEvent(e);
        break;
    case Qt::Key_Enter:
    case Qt::Key_Return:
    {
        QTextBlock cursorBlock = cursor.block();
        int cursorPosInBlock = cursor.position() - cursorBlock.position();
        TokenIterator nextToken = TokenIterator::rightOf(cursorBlock, cursorPosInBlock);
        if ( nextToken.block() == cursorBlock && nextToken.type() == Token::ClosingBracket )
        {
            cursor.beginEditBlock();
            cursor.insertBlock();
            cursor.insertBlock();
            cursor.endEditBlock();
            cursor.movePosition( QTextCursor::PreviousBlock, QTextCursor::KeepAnchor );
            indent(cursor, JoinEditBlock);
            cursor.movePosition( QTextCursor::EndOfBlock );
        }
        else {
            cursor.beginEditBlock();
            cursor.insertBlock();
            cursor.endEditBlock();
            indent(cursor, JoinEditBlock);
        }
        cursor.setVerticalMovementX(-1);
        setTextCursor(cursor);
        break;
    }
    default:
        if (!overwriteMode() && insertMatchingTokens(e->text()))
            break;
        GenericCodeEditor::keyPressEvent(e);
    }

    mAutoCompleter->keyPress(e);
}
void GenericCodeEditor::keyPressEvent(QKeyEvent * e)
{
    hideMouseCursor(e);

    QTextCursor cursor( textCursor() );

    bool updateCursor = false;

    if (e == QKeySequence::InsertLineSeparator) {
        // override to avoid entering a "soft" new line
        cursor.insertBlock();
        updateCursor = true;
    } else {
        switch (e->key()) {

        case Qt::Key_Delete:
            if (e->modifiers() & Qt::META) {
                cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
                cursor.removeSelectedText();
            } else
                QPlainTextEdit::keyPressEvent(e);
            break;

        case Qt::Key_Backspace:
            if (e->modifiers() & Qt::META) {
                cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
                cursor.removeSelectedText();
            } else {
                if ( !overwriteMode()
                     || (cursor.positionInBlock() == 0)
                     || cursor.hasSelection() ) {
                    QPlainTextEdit::keyPressEvent(e);
                } else {
                    // in overwrite mode, backspace should insert a space
                    cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
                    QString selectedText = cursor.selectedText();
                    if (selectedText == QString(" ") ||
                        selectedText == QString("\t") ) {
                        cursor.clearSelection();
                    } else {
                        cursor.insertText(QString(QChar(' ')));
                        cursor.movePosition(QTextCursor::PreviousCharacter);
                    }
                }
                updateCursor = true;
            }
            break;

        case Qt::Key_Down:
        {
            if (cursor.block() == textDocument()->lastBlock()) {
                QTextCursor::MoveMode moveMode = e->modifiers() & Qt::SHIFT ? QTextCursor::KeepAnchor
                                                                            : QTextCursor::MoveAnchor;

                cursor.movePosition(QTextCursor::EndOfBlock, moveMode);
                setTextCursor(cursor);
            } else
                QPlainTextEdit::keyPressEvent(e);
            break;
        }

        case Qt::Key_Up:
        {
            if (cursor.block() == textDocument()->firstBlock()) {
                QTextCursor::MoveMode moveMode = e->modifiers() & Qt::SHIFT ? QTextCursor::KeepAnchor
                                                                            : QTextCursor::MoveAnchor;

                cursor.movePosition(QTextCursor::StartOfBlock, moveMode);
                setTextCursor(cursor);
            } else
                QPlainTextEdit::keyPressEvent(e);
            break;
        }

        default:
            QPlainTextEdit::keyPressEvent(e);

        }
    } // else...

    if (updateCursor) {
        cursor.setVerticalMovementX(-1);
        setTextCursor( cursor );
        ensureCursorVisible();
    }
    doKeyAction(e);
}
void ScCodeEditor::keyPressEvent( QKeyEvent *e )
{
    QTextCursor cursor( textCursor() );
    bool cursorMoved = true;
    if (e == QKeySequence::MoveToNextWord)
        moveToNextToken( cursor, QTextCursor::MoveAnchor );
    else if (e == QKeySequence::MoveToPreviousWord)
        moveToPreviousToken( cursor, QTextCursor::MoveAnchor );
    else if (e == QKeySequence::SelectNextWord)
        moveToNextToken( cursor, QTextCursor::KeepAnchor );
    else if (e == QKeySequence::SelectPreviousWord)
        moveToPreviousToken( cursor, QTextCursor::KeepAnchor );
    else
        cursorMoved = false;

    if (cursorMoved) {
        setTextCursor( cursor );
        return;
    }

    switch (e->key()) {
    case Qt::Key_Home:
    {
        Qt::KeyboardModifiers mods(e->modifiers());
        if (mods && mods != Qt::ShiftModifier) {
            GenericCodeEditor::keyPressEvent(e);
            return;
        }

        hideMouseCursor();

        QTextCursor::MoveMode mode =
            mods & Qt::ShiftModifier ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor;

        QTextCursor c(textCursor());
        QTextBlock b(c.block());

        int pos = indentedStartOfLine(b);
        pos += b.position();

        if (c.position() == pos)
            c.movePosition(QTextCursor::StartOfLine, mode);
        else
            c.setPosition(pos, mode);

        setTextCursor(c);

        return;
    }

    case Qt::Key_Backtab:
    {
        hideMouseCursor();
        QTextCursor cursor = textCursor();
        insertSpaceToNextTabStop( cursor );
        ensureCursorVisible();
        return;
    }
    default:
    {
        static const QString closingBrackets(")]}");

        bool indentCurrentLine =
                e->key() == Qt::Key_Enter ||
                e->key() == Qt::Key_Return ||
                ( !e->text().isEmpty() && closingBrackets.contains(e->text()) );

        if (indentCurrentLine)
            cursor.beginEditBlock();

        GenericCodeEditor::keyPressEvent(e);

        if (indentCurrentLine) {
            cursor.endEditBlock();
            cursor.joinPreviousEditBlock();
            indent();
            cursor.endEditBlock();
        }
    }
    }

    mAutoCompleter->keyPress(e);
}
Exemple #9
0
void ScCodeEditor::keyPressEvent( QKeyEvent *e )
{
    QTextCursor cursor( textCursor() );
    bool cursorMoved = true;
    if (e == QKeySequence::MoveToNextWord)
        moveToNextToken( cursor, QTextCursor::MoveAnchor );
    else if (e == QKeySequence::MoveToPreviousWord)
        moveToPreviousToken( cursor, QTextCursor::MoveAnchor );
    else if (e == QKeySequence::SelectNextWord)
        moveToNextToken( cursor, QTextCursor::KeepAnchor );
    else if (e == QKeySequence::SelectPreviousWord)
        moveToPreviousToken( cursor, QTextCursor::KeepAnchor );
    else
        cursorMoved = false;

    if (cursorMoved) {
        setTextCursor( cursor );
        return;
    }

    switch (e->key()) {
    case Qt::Key_Home:
    {
        Qt::KeyboardModifiers mods(e->modifiers());
        if (mods && mods != Qt::ShiftModifier) {
            GenericCodeEditor::keyPressEvent(e);
            return;
        }

        hideMouseCursor();

        QTextCursor::MoveMode mode =
            mods & Qt::ShiftModifier ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor;

        QTextCursor c(textCursor());
        QTextBlock b(c.block());

        int pos = indentedStartOfLine(b);
        pos += b.position();

        if (c.position() == pos)
            c.movePosition(QTextCursor::StartOfLine, mode);
        else
            c.setPosition(pos, mode);

        setTextCursor(c);

        return;
    }

    case Qt::Key_Backtab:
    {
        hideMouseCursor();
        QTextCursor cursor = textCursor();
        insertSpaceToNextTabStop( cursor );
        ensureCursorVisible();
        return;
    }

    case Qt::Key_Enter:
    case Qt::Key_Return:
    case Qt::Key_BraceRight:
    case Qt::Key_BracketRight:
    case Qt::Key_ParenRight: {
        hideMouseCursor();

        // Wrap superclass' implementation into an edit block,
        // so it can be joined with indentation later:

        QTextCursor cursor = textCursor();

        cursor.beginEditBlock();
        GenericCodeEditor::keyPressEvent(e);
        cursor.endEditBlock();

        cursor.joinPreviousEditBlock();
        indent();
        cursor.endEditBlock();

        cursor.setVerticalMovementX(-1);
        setTextCursor(cursor);

        break;
    }
    default:
        GenericCodeEditor::keyPressEvent(e);
    }

    mAutoCompleter->keyPress(e);
}