More fun with auto scrolling

Koos Vriezen koos.vriezen at xs4all.nl
Fri Jul 12 16:57:21 BST 2002


> On Fri, 12 Jul 2002, Germain Garand wrote:
> > Le Vendredi 12 Juillet 2002 15:10, Koos Vriezen a écrit :
> > > What do you thing of always starting auto scrolling, maybe only start with
> > > the shift key down? Or, ...?
> >
> > Oh yes, please, definetly, having it triggered by shift-down would be perfect
> > and won't break old habits (I personnally love normal scrolling :/)...
> >
> > I think it's a far better solution than
> > yet-another-config-checkbox-you-won't-find-anyway...
> >
> > Cheers,
> > G.
>
> Yeah i agree as well, shift down sounds more reasonable to me.
> Oh and about the timer thingy yeah that might be a better idea. and
> increase the minimum to 1px/100ms (about a second per line with a
> smallish font), if people want it scroll faster they have to tap the down
> key a few more times :)

Ok, attached a patch that does:
- Only enable/accelerate/decelerate auto scrolling when shift key is down
- Changed scrolling velocity by changing interval and pixel/scroll
  These timings {100, 1}, {50, 1}, {30,1}, {20,1}, {10,1}, {10,2}, {10,3}
  are used ({interval, pixel}).

I do think though, intervals bigger than 30 are ugly.

Please test.

Koos
-------------- next part --------------
Index: khtmlview.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v
retrieving revision 1.476
diff -u -3 -p -r1.476 khtmlview.cpp
--- khtmlview.cpp	2002/07/11 06:15:26	1.476
+++ khtmlview.cpp	2002/07/12 15:49:24
@@ -177,6 +177,7 @@ public:
 
     int repaintTimerId;
     int scrollTimerId;
+    int scrollTiming;
     int scrollBy;
     bool complete;
     bool firstRelayout;
@@ -622,7 +623,8 @@ void KHTMLView::keyPressEvent( QKeyEvent
     }
 
     int offs = (clipper()->height() < 30) ? clipper()->height() : 30;
-    if (_ke->state()&ShiftButton)
+    static int timings [][2] = { {100, 1}, {50, 1}, {30,1}, {20,1}, {10,1}, {10,2}, {10,3}, {0,0} };
+    if (_ke->state() & Qt::ShiftButton)
       switch(_ke->key())
         {
         case Key_Space:
@@ -631,6 +633,30 @@ void KHTMLView::keyPressEvent( QKeyEvent
             else
                 scrollBy( 0, -clipper()->height() - offs );
             break;
+
+        case Key_Down:
+        case Key_J:
+            if (!d->scrollTimerId) {
+                d->scrollTiming = 0;
+                d->scrollBy = timings[0][1];
+                scrollBy( 0, d->scrollBy );
+                d->scrollTimerId = startTimer(timings[0][0]);
+            } else if (timings[d->scrollTiming+1][0]) {
+                d->scrollBy = timings[++d->scrollTiming][1];
+                scrollBy( 0, d->scrollBy );
+                killTimer(d->scrollTimerId);
+                d->scrollTimerId = startTimer(timings[d->scrollTiming][0]);
+            }
+            break;
+
+        case Key_Up:
+        case Key_K:
+            if (d->scrollTiming) {
+                d->scrollBy = timings[--d->scrollTiming][1];
+                killTimer(d->scrollTimerId);
+                d->scrollTimerId = startTimer(timings[d->scrollTiming][0]);
+            }
+            break;
         }
     else
         switch ( _ke->key() )
@@ -639,18 +665,13 @@ void KHTMLView::keyPressEvent( QKeyEvent
         case Key_J:
             if ( d->vmode == QScrollView::AlwaysOff )
                 _ke->accept();
-            else if (_ke->isAutoRepeat()) {
+            else {
                 if (d->scrollTimerId) {
                     killTimer(d->scrollTimerId);
                     d->scrollTimerId = 0;
                 }
                 scrollBy( 0, 10 );
-            } else if (!d->scrollTimerId) {
-                d->scrollBy = 1;
-                scrollBy( 0, d->scrollBy );
-                d->scrollTimerId = startTimer(30);
-            } else if (d->scrollBy < 10)
-                d->scrollBy++;
+            }
             break;
 
         case Key_Space:
@@ -665,13 +686,13 @@ void KHTMLView::keyPressEvent( QKeyEvent
         case Key_K:
             if ( d->vmode == QScrollView::AlwaysOff )
                 _ke->accept();
-            else if (d->scrollTimerId) {
-                if (--d->scrollBy <= 0) {
+            else {
+                if (d->scrollTimerId) {
                     killTimer(d->scrollTimerId);
                     d->scrollTimerId = 0;
                 }
-            } else
                 scrollBy( 0, -10 );
+            }
             break;
 
         case Key_Prior:
@@ -1481,7 +1502,7 @@ void KHTMLView::timerEvent ( QTimerEvent
 {
 //    kdDebug() << "timer event " << e->timerId() << endl;
     if (e->timerId() == d->scrollTimerId) {
-        if (contentsY() + visibleHeight () >= contentsHeight() || d->scrollBy <= 0) {
+        if (contentsY() + visibleHeight () >= contentsHeight()) {
             kdDebug() << "timer event killing timer" << endl;
             killTimer(d->scrollTimerId);
             d->scrollTimerId = 0;


More information about the kfm-devel mailing list