1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
/**
* Copyright (C) 2001-2002 the KGhostView authors. See file AUTHORS.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tqdatetime.h>
#include <kdebug.h>
#include "kgvpageview.h"
KGVPageView::KGVPageView( TQWidget* parent, const char* name )
: TQScrollView( parent, name )
{
_page = 0;
setFocusPolicy( TQ_StrongFocus );
viewport()->setFocusPolicy( TQ_WheelFocus );
}
void KGVPageView::setPage( TQWidget* page )
{
if( page != 0 ) {
addChild( page );
centerContents();
_page = page;
}
}
bool KGVPageView::atTop() const
{
return verticalScrollBar()->value() == verticalScrollBar()->minValue();
}
bool KGVPageView::atBottom() const
{
return verticalScrollBar()->value() == verticalScrollBar()->maxValue();
}
bool KGVPageView::eventFilter( TQObject* o, TQEvent* e )
{
if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(_page) && e->type() == TQEvent::Resize ) {
// We need to call TQScrollView::eventFilter before centerContents,
// otherwise a loop will be introduced.
bool result = TQScrollView::eventFilter( o, e );
centerContents();
emit pageSizeChanged( _page->size() );
return result;
}
return TQScrollView::eventFilter( o, e );
}
void KGVPageView::wheelEvent( TQWheelEvent *e )
{
int delta = e->delta();
e->accept();
if ((e->state() & ControlButton) == ControlButton) {
if ( e->delta() < 0 )
emit zoomOut();
else
emit zoomIn();
}
else if ( delta <= -120 && atBottom() )
{
emit ReadDown();
}
else if ( delta >= 120 && atTop())
{
emit ReadUp();
}
else
TQScrollView::wheelEvent( e );
}
void KGVPageView::mousePressEvent( TQMouseEvent * e )
{
if ( e->button() & Qt::LeftButton )
{
_dragGrabPos = e -> globalPos();
setCursor( sizeAllCursor );
}
else if ( e->button() & Qt::MidButton )
{
emit ReadDown();
}
else if ( e -> button() & Qt::RightButton )
{
emit rightClick();
}
}
void KGVPageView::mouseReleaseEvent( TQMouseEvent *e )
{
if ( e -> button() & Qt::LeftButton )
{
setCursor( arrowCursor );
}
}
void KGVPageView::mouseMoveEvent( TQMouseEvent * e )
{
if ( e->state() & Qt::LeftButton )
{
TQPoint delta = _dragGrabPos - e->globalPos();
scrollBy( delta.x(), delta.y() );
_dragGrabPos = e->globalPos();
}
}
bool KGVPageView::readUp()
{
if( atTop() )
return false;
else {
int newValue = TQMAX( verticalScrollBar()->value() - height() + 50,
verticalScrollBar()->minValue() );
/*
int step = 10;
int value = verticalScrollBar()->value();
while( value > newValue - step ) {
verticalScrollBar()->setValue( value );
value -= step;
}
*/
verticalScrollBar()->setValue( newValue );
return true;
}
}
bool KGVPageView::readDown()
{
if( atBottom() )
return false;
else {
int newValue = TQMIN( verticalScrollBar()->value() + height() - 50,
verticalScrollBar()->maxValue() );
/*
int step = 10;
int value = verticalScrollBar()->value();
while( value < newValue + step ) {
verticalScrollBar()->setValue( value );
value += step;
}
*/
verticalScrollBar()->setValue( newValue );
return true;
}
}
void KGVPageView::scrollRight()
{
horizontalScrollBar()->addLine();
}
void KGVPageView::scrollLeft()
{
horizontalScrollBar()->subtractLine();
}
void KGVPageView::scrollDown()
{
verticalScrollBar()->addLine();
}
void KGVPageView::scrollUp()
{
verticalScrollBar()->subtractLine();
}
void KGVPageView::scrollBottom()
{
verticalScrollBar()->setValue( verticalScrollBar()->maxValue() );
}
void KGVPageView::scrollTop()
{
verticalScrollBar()->setValue( verticalScrollBar()->minValue() );
}
void KGVPageView::enableScrollBars( bool b )
{
setHScrollBarMode( b ? Auto : AlwaysOff );
setVScrollBarMode( b ? Auto : AlwaysOff );
}
void KGVPageView::keyPressEvent( TQKeyEvent* e )
{
switch ( e->key() ) {
case Key_Up:
scrollUp();
break;
case Key_Down:
scrollDown();
break;
case Key_Left:
scrollLeft();
break;
case Key_Right:
scrollRight();
break;
default:
e->ignore();
return;
}
e->accept();
}
void KGVPageView::viewportResizeEvent( TQResizeEvent* e )
{
TQScrollView::viewportResizeEvent( e );
emit viewSizeChanged( viewport()->size() );
centerContents();
}
void KGVPageView::centerContents()
{
if( !_page )
return;
int newX = 0;
int newY = 0;
TQSize newViewportSize = viewportSize( _page->width(),
_page->height() );
if( newViewportSize.width() > _page->width() )
newX = ( newViewportSize.width() - _page->width() )/2;
if( newViewportSize.height() > _page->height() )
newY = ( newViewportSize.height() - _page->height() )/2;
moveChild( _page, newX, newY );
}
#include "kgvpageview.moc"
|