23 #include <tqapplication.h>
25 #include "kscrollview.h"
27 #include <tdeconfig.h>
28 #include <tdeglobal.h>
30 struct KScrollView::KScrollViewPrivate {
31 KScrollViewPrivate() : dx(0), dy(0), ddx(0), ddy(0), rdx(0), rdy(0), scrolling(false) {}
43 KScrollView::KScrollView( TQWidget *parent,
const char *name, TQt::WFlags f )
44 : TQScrollView( parent,
name, f )
46 d =
new KScrollViewPrivate;
47 connect(&d->timer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(scrollTick()));
50 KScrollView::~KScrollView()
55 void KScrollView::scrollBy(
int dx,
int dy)
58 if( !cfg.readBoolEntry(
"SmoothScrolling",
true )) {
59 TQScrollView::scrollBy( dx, dy );
63 int full_dx = d->dx + dx;
64 int full_dy = d->dy + dy;
70 int steps = SCROLL_TIME/SCROLL_TICK;
72 ddx = (full_dx*16)/steps;
73 ddy = (full_dy*16)/steps;
76 if (ddx > 0 && ddx < 16) ddx = 16;
77 if (ddy > 0 && ddy < 16) ddy = 16;
78 if (ddx < 0 && ddx > -16) ddx = -16;
79 if (ddy < 0 && ddy > -16) ddy = -16;
133 void KScrollView::scrollTick() {
134 if (d->dx == 0 && d->dy == 0) {
139 int tddx = d->ddx + d->rdx;
140 int tddy = d->ddy + d->rdy;
147 if (d->dx > 0 && ddx > d->dx) ddx = d->dx;
149 if (d->dx < 0 && ddx < d->dx) ddx = d->dx;
151 if (d->dy > 0 && ddy > d->dy) ddy = d->dy;
153 if (d->dy < 0 && ddy < d->dy) ddy = d->dy;
159 TQScrollView::scrollBy(ddx, ddy);
162 void KScrollView::startScrolling()
165 d->timer.start(SCROLL_TICK,
false);
168 void KScrollView::stopScrolling()
172 d->scrolling =
false;
176 void KScrollView::wheelEvent( TQWheelEvent *e )
178 int pageStep = verticalScrollBar()->pageStep();
179 int lineStep = verticalScrollBar()->lineStep();
180 int step = TQMIN( TQApplication::wheelScrollLines()*lineStep, pageStep );
181 if ( ( e->state() & ControlButton ) || ( e->state() & ShiftButton ) )
184 int dy = (e->delta()*step)/120;
189 #include "kscrollview.moc"
static TDEConfig * config()
TQString name(StdAccel id)