blob: 595f4982b7742da118867fa197201c67a099ffde (
plain)
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
|
// zoom.cpp
//
// Part of KVIEWSHELL - A framework for multipage text/gfx viewers
//
// (C) 2002 Stefan Kebekus
// Distributed under the GPL
// Add header files alphabetically
#include <config.h>
#include <math.h>
#include <tqstringlist.h>
#include <klocale.h>
#include "zoom.h"
#include "zoomlimits.h"
float zoomVals[] = {0.20, 0.33, 0.50, 0.75, 1.00, 1.25, 1.50, 2.00, 2.50, 0};
Zoom::Zoom()
{
valueNames << i18n("Fit to Page Width");
valueNames << i18n("Fit to Page Height");
valueNames << i18n("Fit to Page");
_zoomValue = 1.0;
valNo = 6; // 1.0 is 6rd entry in the list
for(int i=0; zoomVals[i] != 0; i++)
valueNames << TQString("%1%").tqarg(zoomVals[i]);
}
void Zoom::setZoomValue(const TQString &cval)
{
float fval;
// Remove a trailing '%', if any
TQString val = cval.stripWhiteSpace();
if (val.right(1) == "%")
val = val.left(val.length()-1).stripWhiteSpace();
bool ok;
fval = val.toFloat(&ok)/100.0;
if (ok == true)
setZoomValue(fval);
else {
emit(zoomNamesChanged(valueNames));
emit(valNoChanged(valNo));
emit(zoomNameChanged(TQString("%1%").tqarg((int)(_zoomValue*100.0+0.5))));
}
}
void Zoom::setZoomFitWidth(float zoom)
{
// Make sure _zoomValue is in the permissible range!
if (zoom < ZoomLimits::MinZoom/1000.0)
zoom = ZoomLimits::MinZoom/1000.0;
if (zoom > ZoomLimits::MaxZoom/1000.0)
zoom = ZoomLimits::MaxZoom/1000.0;
_zoomValue = zoom;
valNo = 0;
emit(valNoChanged(valNo));
emit(zoomNameChanged(TQString("%1%").tqarg((int)(_zoomValue*100.0+0.5))));
}
void Zoom::setZoomFitHeight(float zoom)
{
// Make sure _zoomValue is in the permissible range!
if (zoom < ZoomLimits::MinZoom/1000.0)
zoom = ZoomLimits::MinZoom/1000.0;
if (zoom > ZoomLimits::MaxZoom/1000.0)
zoom = ZoomLimits::MaxZoom/1000.0;
_zoomValue = zoom;
valNo = 1;
emit(valNoChanged(valNo));
emit(zoomNameChanged(TQString("%1%").tqarg((int)(_zoomValue*100.0+0.5))));
}
void Zoom::setZoomFitPage(float zoom)
{
// Make sure _zoomValue is in the permissible range!
if (zoom < ZoomLimits::MinZoom/1000.0)
zoom = ZoomLimits::MinZoom/1000.0;
if (zoom > ZoomLimits::MaxZoom/1000.0)
zoom = ZoomLimits::MaxZoom/1000.0;
_zoomValue = zoom;
valNo = 2;
emit(valNoChanged(valNo));
emit(zoomNameChanged(TQString("%1%").tqarg((int)(_zoomValue*100.0+0.5))));
}
void Zoom::setZoomValue(float f)
{
// Make sure _zoomValue is in the permissible range!
if (f < ZoomLimits::MinZoom/1000.0)
f = ZoomLimits::MinZoom/1000.0;
if (f > ZoomLimits::MaxZoom/1000.0)
f = ZoomLimits::MaxZoom/1000.0;
_zoomValue = f;
valueNames.clear();
valueNames << i18n("Fit to Page Width");
valueNames << i18n("Fit to Page Height");
valueNames << i18n("Fit to Page");
bool flag = false;
for(int i = 0; zoomVals[i] != 0; i++) {
if ((_zoomValue <= zoomVals[i]) && (flag == false)) {
flag = true;
valNo = i + 3;
if (fabs(_zoomValue-zoomVals[i]) > 0.01)
valueNames << TQString("%1%").tqarg((int)(_zoomValue*100.0+0.5));
}
valueNames << TQString("%1%").tqarg((int)(zoomVals[i]*100.0+0.5));
}
if (flag == false) {
valNo = valueNames.size();
valueNames << TQString("%1%").tqarg((int)(_zoomValue*100.0+0.5));
}
emit(zoomNamesChanged(valueNames));
emit(valNoChanged(valNo));
emit(zoomNameChanged(TQString("%1%").tqarg((int)(_zoomValue*100.0+0.5))));
}
float Zoom::zoomIn()
{
int i;
for(i=0; zoomVals[i] != 0; i++)
if (zoomVals[i] > _zoomValue)
return zoomVals[i];
return zoomVals[i-1];
}
float Zoom::zoomOut()
{
float result = zoomVals[0];
for(int i=0; zoomVals[i] != 0; i++)
if (_zoomValue > zoomVals[i])
result = zoomVals[i];
return result;
}
#include "zoom.moc"
|