Commit 1967b29d authored by Michael Pyne's avatar Michael Pyne
Browse files

Merging in fixes to Ariya's syntax-highlighted editor widget, in this case for wheel mouse

support.

svn path=/trunk/playground/utils/abakus/; revision=472158
parent ebdd0544
......@@ -647,37 +647,49 @@ QString Editor::formatNumber( const Abakus::number_t &value ) const
return value.toString();
}
void Editor::keyPressEvent( QKeyEvent* e )
void Editor::historyBack()
{
if( e->key() == Key_Up && d->history.count() )
{
d->index--;
if( d->history.isEmpty() )
return;
if( d->index < 0 )
d->index = 0;
d->index--;
setText( d->history[ d->index ] );
setCursorPosition( 0, text().length() );
ensureCursorVisible();
if( d->index < 0 )
d->index = 0;
e->accept();
setText( d->history[ d->index ] );
setCursorPosition( 0, text().length() );
ensureCursorVisible();
}
void Editor::historyForward()
{
if( d->history.isEmpty() )
return;
}
if( e->key() == Key_Down && d->history.count() )
{
d->index++;
if( d->index >= (int) d->history.count() )
d->index = d->history.count() - 1;
d->index++;
setText( d->history[ d->index ] );
setCursorPosition( 0, text().length() );
ensureCursorVisible();
if( d->index >= (int) d->history.count() )
d->index = d->history.count() - 1;
e->accept();
setText( d->history[ d->index ] );
setCursorPosition( 0, text().length() );
ensureCursorVisible();
}
void Editor::keyPressEvent( QKeyEvent* e )
{
if( e->key() == Key_Up )
{
historyBack();
e->accept();
return;
}
if( e->key() == Key_Down )
{
historyForward();
e->accept();
return;
}
......@@ -698,6 +710,16 @@ void Editor::keyPressEvent( QKeyEvent* e )
QTextEdit::keyPressEvent( e );
}
void Editor::wheelEvent( QWheelEvent *e )
{
if( e->delta() > 0 )
historyBack();
else if( e->delta() < 0 )
historyForward();
e->accept();
}
void Editor::setSyntaxHighlight( bool enable )
{
d->syntaxHighlightEnabled = enable;
......@@ -865,3 +887,5 @@ void EditorCompletion::moveCompletionPopup()
}
#include "editor.moc"
// vim: set et sw=2 ts=8:
......@@ -85,9 +85,12 @@ class Editor : public QTextEdit
void checkMatching();
void doMatchingLeft();
void doMatchingRight();
void historyBack();
void historyForward();
protected:
void keyPressEvent( QKeyEvent* );
void wheelEvent( QWheelEvent* );
QString formatNumber( const Abakus::number_t &value ) const;
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment