Exemplo n.º 1
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) );
}
Exemplo n.º 2
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());
}