[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/utils/abakus/src
From:       Michael Pyne <michael.pyne () kdemail ! net>
Date:       2005-10-20 1:13:14
Message-ID: 1129770794.432126.14902.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 472158 by mpyne:

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


 M  +45 -21    editor.cpp  
 M  +3 -0      editor.h  


--- trunk/playground/utils/abakus/src/editor.cpp #472157:472158
@@ -647,40 +647,52 @@
   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;
 
+  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;
+  }
+    
   if( e->key() == Key_Enter || e->key() == Key_Return )
   {
     emit returnPressed();
@@ -698,6 +710,16 @@
   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 @@
 }
 
 #include "editor.moc"
+
+// vim: set et sw=2 ts=8:
--- trunk/playground/utils/abakus/src/editor.h #472157:472158
@@ -85,9 +85,12 @@
     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:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic