コード例 #1
0
ファイル: pEditor.cpp プロジェクト: pasnox/monkeystudio2
void pEditor::keyPressEvent( QKeyEvent* e )
{
    const bool ctrl = e->modifiers() & Qt::ControlModifier;
    const bool shift = e->modifiers() & Qt::ShiftModifier;
    const bool alt = e->modifiers() & Qt::AltModifier;
    const bool meta = e->modifiers() & Qt::MetaModifier;
    
    if ( !e->isAutoRepeat() && ( shift || ctrl || alt || meta ) && e->key() == Qt::Key_Space ) {
        switch ( autoCompletionSource() ) {
            case QsciScintilla::AcsAll:
                autoCompleteFromAll();
                break;
            case QsciScintilla::AcsAPIs:
                autoCompleteFromAPIs();
                break;
            case QsciScintilla::AcsDocument:
                autoCompleteFromDocument();
                break;
            default:
                break;
        }
        
        e->accept();
        return;
    }
    
    QsciScintilla::keyPressEvent( e );
}
コード例 #2
0
ファイル: sqleditorwidget.cpp プロジェクト: jempe/sqliteman
void SqlEditorWidget::keyPressEvent(QKeyEvent * e)
{
    // handle editor shortcuts with TAB
    // It uses qscintilla lowlevel API to handle "word unde cursor"
    if (m_prefs->useShortcuts() && e->key() == Qt::Key_Tab)
    {
        int pos = SendScintilla(SCI_GETCURRENTPOS);
        int start = SendScintilla(SCI_WORDSTARTPOSITION, pos,true);
        int end = SendScintilla(SCI_WORDENDPOSITION, pos, true);
        SendScintilla(SCI_SETSELECTIONSTART, start, true);
        SendScintilla(SCI_SETSELECTIONEND, end, true);
        QString key(selectedText());
        bool done = false;
        if (m_prefs->shortcuts().contains(key))
        {
            removeSelectedText();
            insert(m_prefs->shortcuts().value(key).toString());
            SendScintilla(SCI_SETCURRENTPOS,
                          SendScintilla(SCI_GETCURRENTPOS) +
                          m_prefs->shortcuts().value(key).toString().length());
            done = true;
        }
        pos = SendScintilla(SCI_GETCURRENTPOS);
        SendScintilla(SCI_SETSELECTIONSTART, pos,true);
        SendScintilla(SCI_SETSELECTIONEND, pos, true);

        if (done)
            return;
    }

    // Manual popup with code completion
    if (m_prefs->codeCompletion()
            && (e->modifiers() & Qt::ControlModifier)
            && e->key() == Qt::Key_Space)
    {
        autoCompleteFromAll();
        return;
    }

    QsciScintilla::keyPressEvent(e);
}