00001 #include "SIGEL_MasterGUI/SIG_TextView.h" 00002 #include <qtimer.h> 00003 00004 SIG_TextView::SIG_TextView( QWidget *parent = 0, const char *name = 0 ) 00005 : QTextView( parent, name ), oldY(0), scrollDown( true ), scroll( true ) 00006 { 00007 QTimer *scrollTimer = new QTimer( this ); 00008 connect( scrollTimer, 00009 SIGNAL( timeout() ), 00010 this, 00011 SLOT( updateScroll() ) ); 00012 scrollTimer->start( 100 ); 00013 }; 00014 00015 SIG_TextView::~SIG_TextView() 00016 { 00017 00018 }; 00019 00020 void SIG_TextView::viewportMousePressEvent( QMouseEvent *e ) 00021 { 00022 oldY = e->y(); 00023 scroll = false; 00024 }; 00025 00026 void SIG_TextView::viewportMouseReleaseEvent( QMouseEvent * ) 00027 { 00028 scroll = true; 00029 }; 00030 00031 void SIG_TextView::viewportMouseMoveEvent( QMouseEvent *e ) 00032 { 00033 int newPos = e->y(); 00034 int toMove = oldY - newPos; 00035 scrollBy( 0, toMove ); 00036 oldY = newPos; 00037 }; 00038 00039 void SIG_TextView::updateScroll() 00040 { 00041 if( scroll ) 00042 { 00043 int cHeight = contentsHeight(); 00044 int cY = contentsY(); 00045 int vHeight = visibleHeight(); 00046 if( scrollDown ) 00047 { 00048 if ( cY + vHeight >= cHeight ) 00049 scrollDown = false; 00050 else 00051 scrollDown = true; 00052 } 00053 else 00054 { 00055 if( cY == 0 ) 00056 scrollDown = true; 00057 else 00058 scrollDown = false; 00059 } 00060 if( scrollDown ) 00061 scrollBy( 0, 1 ); 00062 else 00063 scrollBy( 0, -1 ); 00064 } 00065 };