Example #1
0
void Editor::keyPressEvent( QKeyEvent* e )
{
    if( e->key() == Key_Up )
    {
        historyBack();
        e->accept();
        return;
    }

    if( e->key() == Key_Down )
    {
        historyForward();
        e->accept();
        return;
    }

    if( e->key() == Key_Enter || e->key() == Key_Return )
    {
        emit returnPressed();
        return;
    }

    if( e->key() == Key_Left ||
            e->key() == Key_Right ||
            e->key() == Key_Home ||
            e->key() == Key_End )
    {
        checkMatching();
    }

    QTextEdit::keyPressEvent( e );
}
Example #2
0
Editor::Editor( QWidget* parent, const char* name ):
    QTextEdit( parent, name )
{
    d = new Private;
    d->eval = 0;
    d->index = 0;
    d->autoCompleteEnabled = true;
    d->completion = new EditorCompletion( this );
    d->completionTimer = new QTimer( this );
    d->autoCalcEnabled = true;
    d->syntaxHighlightEnabled = true;
    d->highlighter = new EditorHighlighter( this );
    d->autoCalcTimer = new QTimer( this );
    d->matchingTimer = new QTimer( this );

    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
    setWordWrap( NoWrap );
    setHScrollBarMode( AlwaysOff );
    setVScrollBarMode( AlwaysOff );
    setTextFormat( PlainText );
    setAutoFormatting( AutoNone );
    setTabChangesFocus( true );
    setLinkUnderline( false );

    connect( d->completion, SIGNAL( selectedCompletion( const QString& ) ),
        SLOT( autoComplete( const QString& ) ) );
    connect( this, SIGNAL( textChanged() ), SLOT( checkAutoComplete() ) );
    connect( d->completionTimer, SIGNAL( timeout() ), SLOT( triggerAutoComplete() ) );

    connect( this, SIGNAL( textChanged() ), SLOT( checkMatching() ) );
    connect( d->matchingTimer, SIGNAL( timeout() ), SLOT( doMatchingLeft() ) );
    connect( d->matchingTimer, SIGNAL( timeout() ), SLOT( doMatchingRight() ) );
    connect( this, SIGNAL( textChanged() ), SLOT( checkAutoCalc() ) );
    connect( d->autoCalcTimer, SIGNAL( timeout() ), SLOT( autoCalc() ) );
    d->autoCalcLabel = new CalcResultLabel( 0, "autocalc", WStyle_StaysOnTop |
        WStyle_Customize | WStyle_NoBorder | WStyle_Tool |  WX11BypassWM );
    d->autoCalcLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
    d->autoCalcLabel->setPalette( QToolTip::palette() );
    d->autoCalcLabel->hide();

    setHighlightColor( Number, QColor(0,0,127) );
    setHighlightColor( FunctionName, QColor(85,0,0) );
    setHighlightColor( Variable, QColor(0,85,0) );
    setHighlightColor( MatchedPar, QColor(255,255,183) );
}
Example #3
0
Editor::Editor(QWidget* parent)
    : QPlainTextEdit(parent)
{
    m_evaluator = Evaluator::instance();
    m_currentHistoryIndex = 0;
    m_isAutoCompletionEnabled = true;
    m_completion = new EditorCompletion(this);
    m_constantCompletion = 0;
    m_completionTimer = new QTimer(this);
    m_isAutoCalcEnabled = true;
    m_highlighter = new SyntaxHighlighter(this);
    m_autoCalcTimer = new QTimer(this);
    m_autoCalcSelTimer = new QTimer(this);
    m_matchingTimer = new QTimer(this);
    m_isAnsAvailable = false;
    m_shouldPaintCustomCursor = true;

    setViewportMargins(0, 0, 0, 0);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
    setTabChangesFocus(true);
    setWordWrapMode(QTextOption::NoWrap);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setCursorWidth(0);

    connect(m_autoCalcTimer, SIGNAL(timeout()), SLOT(autoCalc()));
    connect(m_autoCalcSelTimer, SIGNAL(timeout()), SLOT(autoCalcSelection()));
    connect(m_completion, SIGNAL(selectedCompletion(const QString&)), SLOT(autoComplete(const QString&)));
    connect(m_completionTimer, SIGNAL(timeout()), SLOT(triggerAutoComplete()));
    connect(m_matchingTimer, SIGNAL(timeout()), SLOT(doMatchingPar()));
    connect(this, SIGNAL(selectionChanged()), SLOT(startSelAutoCalcTimer()));
    connect(this, SIGNAL(textChanged()), SLOT(checkAutoCalc()));
    connect(this, SIGNAL(textChanged()), SLOT(checkAutoComplete()));
    connect(this, SIGNAL(textChanged()), SLOT(checkMatching()));

    adjustSize();
    setFixedHeight(sizeHint().height());
}
Example #4
0
 void checkFull(unsigned firstSize, unsigned secondSize)
 {
     checkMatching(std::min(firstSize, secondSize), createEdgesForFull(firstSize, secondSize));
 }
Example #5
0
void Editor::keyPressEvent(QKeyEvent* event)
{
    int key = event->key();

    switch (key) {
    case Qt::Key_Enter:
    case Qt::Key_Return:
        QTimer::singleShot(0, this, SLOT(triggerEnter()));
        event->accept();
        return;

    case Qt::Key_Up:
        if (event->modifiers() & Qt::ShiftModifier)
            emit shiftUpPressed();
        else
            historyBack();
        event->accept();
        return;

    case Qt::Key_Down:
        if (event->modifiers() & Qt::ShiftModifier)
            emit shiftDownPressed();
        else
            historyForward();
        event->accept();
        return;

    case Qt::Key_PageUp:
        if (event->modifiers() & Qt::ShiftModifier)
            emit shiftPageUpPressed();
        else if (event->modifiers() & Qt::ControlModifier)
            emit controlPageUpPressed();
        else
            emit pageUpPressed();
        event->accept();
        return;

    case Qt::Key_PageDown:
        if (event->modifiers() & Qt::ShiftModifier)
            emit shiftPageDownPressed();
        else if (event->modifiers() & Qt::ControlModifier)
            emit controlPageDownPressed();
        else
            emit pageDownPressed();
        event->accept();
        return;

    case Qt::Key_Left:
    case Qt::Key_Right:
    case Qt::Key_Home:
    case Qt::Key_End:
        checkMatching();
        checkAutoCalc();

    case Qt::Key_Space:
        if (event->modifiers() == Qt::ControlModifier && !m_constantCompletion) {
            m_constantCompletion = new ConstantCompletion(this);
            connect(m_constantCompletion, SIGNAL(selectedCompletion(const QString&)), SLOT(insertConstant(const QString&)));
            connect(m_constantCompletion, SIGNAL(canceledCompletion()), SLOT(cancelConstantCompletion()));
            m_constantCompletion->showCompletion();
            event->accept();
            return;
        }

    case Qt::Key_P:
        if (event->modifiers() == Qt::ControlModifier) {
            QTextCursor cursor = textCursor();
            if (cursor.hasSelection()) {
                const int selectionStart = cursor.selectionStart();
                const int selectionEnd = cursor.selectionEnd();
                cursor.setPosition(selectionStart);
                cursor.insertText("(");
                cursor.setPosition(selectionEnd + 1);
                cursor.insertText(")");
            } else {
                cursor.movePosition(QTextCursor::Start);
                cursor.insertText("(");
                cursor.movePosition(QTextCursor::End);
                cursor.insertText(")");
            }
            setTextCursor(cursor);
            event->accept();
            return;
        }

    default:;
    }

    if (event->matches(QKeySequence::Copy)) {
        emit copySequencePressed();
        event->accept();
        return;
    }

    QPlainTextEdit::keyPressEvent(event);
}