• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
kscrollview.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2005 Allan Sandfeld Jensen <kde@carewolf.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "config.h"
20 
21 #include <tqtimer.h>
22 #include <tqevent.h>
23 #include <tqapplication.h>
24 
25 #include "kscrollview.h"
26 #include <kdebug.h>
27 #include <kconfig.h>
28 #include <kglobal.h>
29 
30 struct KScrollView::KScrollViewPrivate {
31  KScrollViewPrivate() : dx(0), dy(0), ddx(0), ddy(0), rdx(0), rdy(0), scrolling(false) {}
32  TQTimer timer;
33  int dx;
34  int dy;
35  // Step size * 16 and residual to avoid huge difference between 1px/step and 2px/step
36  int ddx;
37  int ddy;
38  int rdx;
39  int rdy;
40  bool scrolling;
41 };
42 
43 KScrollView::KScrollView( TQWidget *parent, const char *name, Qt::WFlags f )
44  : TQScrollView( parent, name, f )
45 {
46  d = new KScrollViewPrivate;
47  connect(&d->timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(scrollTick()));
48 }
49 
50 KScrollView::~KScrollView()
51 {
52  delete d;
53 }
54 
55 void KScrollView::scrollBy(int dx, int dy)
56 {
57  KConfigGroup cfg( KGlobal::config(), "KDE" );
58  if( !cfg.readBoolEntry( "SmoothScrolling", true )) {
59  TQScrollView::scrollBy( dx, dy );
60  return;
61  }
62  // scrolling destination
63  int full_dx = d->dx + dx;
64  int full_dy = d->dy + dy;
65 
66  // scrolling speed
67  int ddx = 0;
68  int ddy = 0;
69 
70  int steps = SCROLL_TIME/SCROLL_TICK;
71 
72  ddx = (full_dx*16)/steps;
73  ddy = (full_dy*16)/steps;
74 
75  // don't go under 1px/step
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;
80 
81  d->dx = full_dx;
82  d->dy = full_dy;
83  d->ddx = ddx;
84  d->ddy = ddy;
85 
86  if (!d->scrolling) {
87  scrollTick();
88  startScrolling();
89  }
90 }
91 /*
92 void KScrollView::scrollBy(int dx, int dy)
93 {
94  if (d->scrolling)
95  setContentsPos( d->x+dx, d->y+dy );
96  else
97  setContentsPos( contentsX() + dx, contentsY() + dy);
98 }
99 
100 void KScrollView::setContentsPos(int x, int y)
101 {
102  if (x < 0) x = 0;
103  if (y < 0) y = 0;
104 
105  int dx = x - contentsX();
106  int dy = y - contentsY();
107 
108  // to large to smooth out
109 // if (dx > 1000 || dy > 1000) return TQScrollView::setContentsPos(x,y);
110 
111  // scrolling speed
112  int ddx = 0;
113  int ddy = 0;
114 
115  int steps = SCROLL_TIME/SCROLL_TICK;
116 
117  ddx = (dx*16)/steps;
118  ddy = (dy*16)/steps;
119 
120  d->x = x;
121  d->y = y;
122  d->dx = dx;
123  d->dy = dy;
124  d->ddx = ddx;
125  d->ddy = ddy;
126 
127  if (!d->scrolling) {
128  scrollTick();
129  startScrolling();
130  }
131 } */
132 
133 void KScrollView::scrollTick() {
134  if (d->dx == 0 && d->dy == 0) {
135  stopScrolling();
136  return;
137  }
138 
139  int tddx = d->ddx + d->rdx;
140  int tddy = d->ddy + d->rdy;
141 
142  int ddx = tddx / 16;
143  int ddy = tddy / 16;
144  d->rdx = tddx % 16;
145  d->rdy = tddy % 16;
146 
147  if (d->dx > 0 && ddx > d->dx) ddx = d->dx;
148  else
149  if (d->dx < 0 && ddx < d->dx) ddx = d->dx;
150 
151  if (d->dy > 0 && ddy > d->dy) ddy = d->dy;
152  else
153  if (d->dy < 0 && ddy < d->dy) ddy = d->dy;
154 
155  d->dx -= ddx;
156  d->dy -= ddy;
157 
158 // TQScrollView::setContentsPos( contentsX() + ddx, contentsY() + ddy);
159  TQScrollView::scrollBy(ddx, ddy);
160 }
161 
162 void KScrollView::startScrolling()
163 {
164  d->scrolling = true;
165  d->timer.start(SCROLL_TICK, false);
166 }
167 
168 void KScrollView::stopScrolling()
169 {
170  d->timer.stop();
171  d->dx = d->dy = 0;
172  d->scrolling = false;
173 }
174 
175 // Overloaded from TQScrollView and QScrollBar
176 void KScrollView::wheelEvent( TQWheelEvent *e )
177 {
178  int pageStep = verticalScrollBar()->pageStep();
179  int lineStep = verticalScrollBar()->lineStep();
180  int step = QMIN( TQApplication::wheelScrollLines()*lineStep, pageStep );
181  if ( ( e->state() & ControlButton ) || ( e->state() & ShiftButton ) )
182  step = pageStep;
183 
184  int dy = (e->delta()*step)/120;
185  scrollBy(0,-dy);
186  e->accept();
187 }
188 
189 #include "kscrollview.moc"
KConfigGroup
KGlobal::config
static KConfig * config()

kdeui

Skip menu "kdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.6
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |