author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /microkde/kdeui/knuminput.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
Diffstat (limited to 'microkde/kdeui/knuminput.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kdeui/knuminput.cpp | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/microkde/kdeui/knuminput.cpp b/microkde/kdeui/knuminput.cpp index 335d6f4..da01a20 100644 --- a/microkde/kdeui/knuminput.cpp +++ b/microkde/kdeui/knuminput.cpp | |||
@@ -1,1095 +1,1098 @@ | |||
1 | // -*- c-basic-offset: 4 -*- | 1 | // -*- c-basic-offset: 4 -*- |
2 | /* | 2 | /* |
3 | * knuminput.cpp | 3 | * knuminput.cpp |
4 | * | 4 | * |
5 | * Initial implementation: | 5 | * Initial implementation: |
6 | * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca> | 6 | * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca> |
7 | * Rewritten and maintained by: | 7 | * Rewritten and maintained by: |
8 | * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org> | 8 | * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org> |
9 | * KDoubleSpinBox: | 9 | * KDoubleSpinBox: |
10 | * Copyright (c) 2002 Marc Mutz <mutz@kde.org> | 10 | * Copyright (c) 2002 Marc Mutz <mutz@kde.org> |
11 | * | 11 | * |
12 | * Requires the Qt widget libraries, available at no cost at | 12 | * Requires the Qt widget libraries, available at no cost at |
13 | * http://www.troll.no/ | 13 | * http://www.troll.no/ |
14 | * | 14 | * |
15 | * This library is free software; you can redistribute it and/or | 15 | * This library is free software; you can redistribute it and/or |
16 | * modify it under the terms of the GNU Library General Public | 16 | * modify it under the terms of the GNU Library General Public |
17 | * License as published by the Free Software Foundation; either | 17 | * License as published by the Free Software Foundation; either |
18 | * version 2 of the License, or (at your option) any later version. | 18 | * version 2 of the License, or (at your option) any later version. |
19 | * | 19 | * |
20 | * This library is distributed in the hope that it will be useful, | 20 | * This library is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
23 | * Library General Public License for more details. | 23 | * Library General Public License for more details. |
24 | * | 24 | * |
25 | * You should have received a copy of the GNU Library General Public License | 25 | * You should have received a copy of the GNU Library General Public License |
26 | * along with this library; see the file COPYING.LIB. If not, write to | 26 | * along with this library; see the file COPYING.LIB. If not, write to |
27 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 27 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
28 | * Boston, MA 02111-1307, USA. | 28 | * Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | //US #include <config.h> | 31 | //US #include <config.h> |
32 | #ifdef HAVE_LIMITS_H | 32 | #ifdef HAVE_LIMITS_H |
33 | #include <limits.h> | 33 | #include <limits.h> |
34 | #endif | 34 | #endif |
35 | #include <assert.h> | 35 | #include <assert.h> |
36 | #include <math.h> | 36 | #include <math.h> |
37 | #include <algorithm> | 37 | #include <algorithm> |
38 | 38 | ||
39 | #include <qlabel.h> | 39 | #include <qlabel.h> |
40 | #include <qlineedit.h> | 40 | #include <qlineedit.h> |
41 | #include <qsize.h> | 41 | #include <qsize.h> |
42 | #include <qslider.h> | 42 | #include <qslider.h> |
43 | #include <qspinbox.h> | 43 | #include <qspinbox.h> |
44 | #include <qstyle.h> | 44 | #include <qstyle.h> |
45 | //Added by qt3to4: | ||
46 | #include <QResizeEvent> | ||
47 | #include <QEvent> | ||
45 | 48 | ||
46 | #include <kglobal.h> | 49 | #include <kglobal.h> |
47 | #include <klocale.h> | 50 | #include <klocale.h> |
48 | #include <kdebug.h> | 51 | #include <kdebug.h> |
49 | 52 | ||
50 | #include "knumvalidator.h" | 53 | #include "knumvalidator.h" |
51 | #include "knuminput.h" | 54 | #include "knuminput.h" |
52 | 55 | ||
53 | static inline int calcDiffByTen( int x, int y ) { | 56 | static inline int calcDiffByTen( int x, int y ) { |
54 | // calculate ( x - y ) / 10 without overflowing ints: | 57 | // calculate ( x - y ) / 10 without overflowing ints: |
55 | return ( x / 10 ) - ( y / 10 ) + ( x % 10 - y % 10 ) / 10; | 58 | return ( x / 10 ) - ( y / 10 ) + ( x % 10 - y % 10 ) / 10; |
56 | } | 59 | } |
57 | 60 | ||
58 | // ---------------------------------------------------------------------------- | 61 | // ---------------------------------------------------------------------------- |
59 | 62 | ||
60 | KNumInput::KNumInput(QWidget* parent, const char* name) | 63 | KNumInput::KNumInput(QWidget* parent, const char* name) |
61 | : QWidget(parent, name) | 64 | : QWidget(parent, name) |
62 | { | 65 | { |
63 | init(); | 66 | init(); |
64 | } | 67 | } |
65 | 68 | ||
66 | KNumInput::KNumInput(KNumInput* below, QWidget* parent, const char* name) | 69 | KNumInput::KNumInput(KNumInput* below, QWidget* parent, const char* name) |
67 | : QWidget(parent, name) | 70 | : QWidget(parent, name) |
68 | { | 71 | { |
69 | init(); | 72 | init(); |
70 | 73 | ||
71 | if(below) { | 74 | if(below) { |
72 | m_next = below->m_next; | 75 | m_next = below->m_next; |
73 | m_prev = below; | 76 | m_prev = below; |
74 | below->m_next = this; | 77 | below->m_next = this; |
75 | if(m_next) | 78 | if(m_next) |
76 | m_next->m_prev = this; | 79 | m_next->m_prev = this; |
77 | } | 80 | } |
78 | } | 81 | } |
79 | 82 | ||
80 | void KNumInput::init() | 83 | void KNumInput::init() |
81 | { | 84 | { |
82 | m_prev = m_next = 0; | 85 | m_prev = m_next = 0; |
83 | m_colw1 = m_colw2 = 0; | 86 | m_colw1 = m_colw2 = 0; |
84 | 87 | ||
85 | m_label = 0; | 88 | m_label = 0; |
86 | m_slider = 0; | 89 | m_slider = 0; |
87 | m_alignment = 0; | 90 | m_alignment = 0; |
88 | } | 91 | } |
89 | 92 | ||
90 | KNumInput::~KNumInput() | 93 | KNumInput::~KNumInput() |
91 | { | 94 | { |
92 | if(m_prev) | 95 | if(m_prev) |
93 | m_prev->m_next = m_next; | 96 | m_prev->m_next = m_next; |
94 | 97 | ||
95 | if(m_next) | 98 | if(m_next) |
96 | m_next->m_prev = m_prev; | 99 | m_next->m_prev = m_prev; |
97 | } | 100 | } |
98 | 101 | ||
99 | void KNumInput::setLabel(const QString & label, int a) | 102 | void KNumInput::setLabel(const QString & label, int a) |
100 | { | 103 | { |
101 | if(label.isEmpty()) { | 104 | if(label.isEmpty()) { |
102 | delete m_label; | 105 | delete m_label; |
103 | m_label = 0; | 106 | m_label = 0; |
104 | m_alignment = 0; | 107 | m_alignment = 0; |
105 | } | 108 | } |
106 | else { | 109 | else { |
107 | if (m_label) m_label->setText(label); | 110 | if (m_label) m_label->setText(label); |
108 | else m_label = new QLabel(label, this, "KNumInput::QLabel"); | 111 | else m_label = new QLabel(label, this, "KNumInput::QLabel"); |
109 | m_label->setAlignment((a & (~(AlignTop|AlignBottom|AlignVCenter))) | 112 | m_label->setAlignment((a & (~(Qt::AlignTop|Qt::AlignBottom|Qt::AlignVCenter))) |
110 | | AlignVCenter); | 113 | | Qt::AlignVCenter); |
111 | // if no vertical alignment set, use Top alignment | 114 | // if no vertical alignment set, use Top alignment |
112 | if(!(a & (AlignTop|AlignBottom|AlignVCenter))) | 115 | if(!(a & (Qt::AlignTop|Qt::AlignBottom|Qt::AlignVCenter))) |
113 | a |= AlignTop; | 116 | a |= Qt::AlignTop; |
114 | m_alignment = a; | 117 | m_alignment = a; |
115 | } | 118 | } |
116 | 119 | ||
117 | layout(true); | 120 | layout(true); |
118 | } | 121 | } |
119 | 122 | ||
120 | QString KNumInput::label() const | 123 | QString KNumInput::label() const |
121 | { | 124 | { |
122 | if (m_label) return m_label->text(); | 125 | if (m_label) return m_label->text(); |
123 | return QString::null; | 126 | return QString::null; |
124 | } | 127 | } |
125 | 128 | ||
126 | void KNumInput::layout(bool deep) | 129 | void KNumInput::layout(bool deep) |
127 | { | 130 | { |
128 | int w1 = m_colw1; | 131 | int w1 = m_colw1; |
129 | int w2 = m_colw2; | 132 | int w2 = m_colw2; |
130 | 133 | ||
131 | // label sizeHint | 134 | // label sizeHint |
132 | m_sizeLabel = (m_label ? m_label->sizeHint() : QSize(0,0)); | 135 | m_sizeLabel = (m_label ? m_label->sizeHint() : QSize(0,0)); |
133 | 136 | ||
134 | if(m_label && (m_alignment & AlignVCenter)) | 137 | if(m_label && (m_alignment & Qt::AlignVCenter)) |
135 | m_colw1 = m_sizeLabel.width() + 4; | 138 | m_colw1 = m_sizeLabel.width() + 4; |
136 | else | 139 | else |
137 | m_colw1 = 0; | 140 | m_colw1 = 0; |
138 | 141 | ||
139 | // slider sizeHint | 142 | // slider sizeHint |
140 | m_sizeSlider = (m_slider ? m_slider->sizeHint() : QSize(0, 0)); | 143 | m_sizeSlider = (m_slider ? m_slider->sizeHint() : QSize(0, 0)); |
141 | 144 | ||
142 | doLayout(); | 145 | doLayout(); |
143 | 146 | ||
144 | if(!deep) { | 147 | if(!deep) { |
145 | m_colw1 = w1; | 148 | m_colw1 = w1; |
146 | m_colw2 = w2; | 149 | m_colw2 = w2; |
147 | return; | 150 | return; |
148 | } | 151 | } |
149 | 152 | ||
150 | KNumInput* p = this; | 153 | KNumInput* p = this; |
151 | while(p) { | 154 | while(p) { |
152 | p->doLayout(); | 155 | p->doLayout(); |
153 | w1 = QMAX(w1, p->m_colw1); | 156 | w1 = QMAX(w1, p->m_colw1); |
154 | w2 = QMAX(w2, p->m_colw2); | 157 | w2 = QMAX(w2, p->m_colw2); |
155 | p = p->m_prev; | 158 | p = p->m_prev; |
156 | } | 159 | } |
157 | 160 | ||
158 | p = m_next; | 161 | p = m_next; |
159 | while(p) { | 162 | while(p) { |
160 | p->doLayout(); | 163 | p->doLayout(); |
161 | w1 = QMAX(w1, p->m_colw1); | 164 | w1 = QMAX(w1, p->m_colw1); |
162 | w2 = QMAX(w2, p->m_colw2); | 165 | w2 = QMAX(w2, p->m_colw2); |
163 | p = p->m_next; | 166 | p = p->m_next; |
164 | } | 167 | } |
165 | 168 | ||
166 | p = this; | 169 | p = this; |
167 | while(p) { | 170 | while(p) { |
168 | p->m_colw1 = w1; | 171 | p->m_colw1 = w1; |
169 | p->m_colw2 = w2; | 172 | p->m_colw2 = w2; |
170 | p = p->m_prev; | 173 | p = p->m_prev; |
171 | } | 174 | } |
172 | 175 | ||
173 | p = m_next; | 176 | p = m_next; |
174 | while(p) { | 177 | while(p) { |
175 | p->m_colw1 = w1; | 178 | p->m_colw1 = w1; |
176 | p->m_colw2 = w2; | 179 | p->m_colw2 = w2; |
177 | p = p->m_next; | 180 | p = p->m_next; |
178 | } | 181 | } |
179 | 182 | ||
180 | // kdDebug() << "w1 " << w1 << " w2 " << w2 << endl; | 183 | // kdDebug() << "w1 " << w1 << " w2 " << w2 << endl; |
181 | } | 184 | } |
182 | 185 | ||
183 | QSizePolicy KNumInput::sizePolicy() const | 186 | QSizePolicy KNumInput::sizePolicy() const |
184 | { | 187 | { |
185 | return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); | 188 | return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ); |
186 | } | 189 | } |
187 | 190 | ||
188 | QSize KNumInput::sizeHint() const | 191 | QSize KNumInput::sizeHint() const |
189 | { | 192 | { |
190 | return minimumSizeHint(); | 193 | return minimumSizeHint(); |
191 | } | 194 | } |
192 | 195 | ||
193 | void KNumInput::setSteps(int minor, int major) | 196 | void KNumInput::setSteps(int minor, int major) |
194 | { | 197 | { |
195 | if(m_slider) | 198 | if(m_slider) |
196 | m_slider->setSteps( minor, major ); | 199 | m_slider->setSteps( minor, major ); |
197 | } | 200 | } |
198 | 201 | ||
199 | 202 | ||
200 | // ---------------------------------------------------------------------------- | 203 | // ---------------------------------------------------------------------------- |
201 | 204 | ||
202 | KIntSpinBox::KIntSpinBox(QWidget *parent, const char *name) | 205 | KIntSpinBox::KIntSpinBox(QWidget *parent, const char *name) |
203 | : QSpinBox(0, 99, 1, parent, name) | 206 | : QSpinBox(0, 99, 1, parent, name) |
204 | { | 207 | { |
205 | editor()->setAlignment(AlignRight); | 208 | setAlignment(Qt::AlignRight); |
206 | val_base = 10; | 209 | val_base = 10; |
207 | setValue(0); | 210 | setValue(0); |
208 | } | 211 | } |
209 | 212 | ||
210 | KIntSpinBox::~KIntSpinBox() | 213 | KIntSpinBox::~KIntSpinBox() |
211 | { | 214 | { |
212 | } | 215 | } |
213 | 216 | ||
214 | KIntSpinBox::KIntSpinBox(int lower, int upper, int step, int value, int base, | 217 | KIntSpinBox::KIntSpinBox(int lower, int upper, int step, int value, int base, |
215 | QWidget* parent, const char* name) | 218 | QWidget* parent, const char* name) |
216 | : QSpinBox(lower, upper, step, parent, name) | 219 | : QSpinBox(lower, upper, step, parent, name) |
217 | { | 220 | { |
218 | editor()->setAlignment(AlignRight); | 221 | setAlignment(Qt::AlignRight); |
219 | val_base = base; | 222 | val_base = base; |
220 | setValue(value); | 223 | setValue(value); |
221 | } | 224 | } |
222 | 225 | ||
223 | void KIntSpinBox::setBase(int base) | 226 | void KIntSpinBox::setBase(int base) |
224 | { | 227 | { |
225 | val_base = base; | 228 | val_base = base; |
226 | } | 229 | } |
227 | 230 | ||
228 | 231 | ||
229 | int KIntSpinBox::base() const | 232 | int KIntSpinBox::base() const |
230 | { | 233 | { |
231 | return val_base; | 234 | return val_base; |
232 | } | 235 | } |
233 | 236 | ||
234 | QString KIntSpinBox::mapValueToText(int v) | 237 | QString KIntSpinBox::mapValueToText(int v) |
235 | { | 238 | { |
236 | return QString::number(v, val_base); | 239 | return QString::number(v, val_base); |
237 | } | 240 | } |
238 | 241 | ||
239 | int KIntSpinBox::mapTextToValue(bool* ok) | 242 | int KIntSpinBox::mapTextToValue(bool* ok) |
240 | { | 243 | { |
241 | return cleanText().toInt(ok, val_base); | 244 | return cleanText().toInt(ok, val_base); |
242 | } | 245 | } |
243 | 246 | ||
244 | void KIntSpinBox::setEditFocus(bool mark) | 247 | void KIntSpinBox::setEditFocus(bool mark) |
245 | { | 248 | { |
246 | editor()->setFocus(); | 249 | setFocus(); |
247 | if(mark) | 250 | if(mark) |
248 | editor()->selectAll(); | 251 | selectAll(); |
249 | } | 252 | } |
250 | 253 | ||
251 | 254 | ||
252 | // ---------------------------------------------------------------------------- | 255 | // ---------------------------------------------------------------------------- |
253 | 256 | ||
254 | class KIntNumInput::KIntNumInputPrivate { | 257 | class KIntNumInput::KIntNumInputPrivate { |
255 | public: | 258 | public: |
256 | int referencePoint; | 259 | int referencePoint; |
257 | short blockRelative; | 260 | short blockRelative; |
258 | KIntNumInputPrivate( int r ) | 261 | KIntNumInputPrivate( int r ) |
259 | : referencePoint( r ), | 262 | : referencePoint( r ), |
260 | blockRelative( 0 ) {} | 263 | blockRelative( 0 ) {} |
261 | }; | 264 | }; |
262 | 265 | ||
263 | 266 | ||
264 | KIntNumInput::KIntNumInput(KNumInput* below, int val, QWidget* parent, | 267 | KIntNumInput::KIntNumInput(KNumInput* below, int val, QWidget* parent, |
265 | int _base, const char* name) | 268 | int _base, const char* name) |
266 | : KNumInput(below, parent, name) | 269 | : KNumInput(below, parent, name) |
267 | { | 270 | { |
268 | init(val, _base); | 271 | init(val, _base); |
269 | } | 272 | } |
270 | 273 | ||
271 | KIntNumInput::KIntNumInput(QWidget *parent, const char *name) | 274 | KIntNumInput::KIntNumInput(QWidget *parent, const char *name) |
272 | : KNumInput(parent, name) | 275 | : KNumInput(parent, name) |
273 | { | 276 | { |
274 | init(0, 10); | 277 | init(0, 10); |
275 | } | 278 | } |
276 | 279 | ||
277 | KIntNumInput::KIntNumInput(int val, QWidget *parent, int _base, const char *name) | 280 | KIntNumInput::KIntNumInput(int val, QWidget *parent, int _base, const char *name) |
278 | : KNumInput(parent, name) | 281 | : KNumInput(parent, name) |
279 | { | 282 | { |
280 | init(val, _base); | 283 | init(val, _base); |
281 | 284 | ||
282 | } | 285 | } |
283 | 286 | ||
284 | void KIntNumInput::init(int val, int _base) | 287 | void KIntNumInput::init(int val, int _base) |
285 | { | 288 | { |
286 | d = new KIntNumInputPrivate( val ); | 289 | d = new KIntNumInputPrivate( val ); |
287 | m_spin = new KIntSpinBox(INT_MIN, INT_MAX, 1, val, _base, this, "KIntNumInput::KIntSpinBox"); | 290 | m_spin = new KIntSpinBox(INT_MIN, INT_MAX, 1, val, _base, this, "KIntNumInput::KIntSpinBox"); |
288 | m_spin->setValidator(new KIntValidator(this, _base, "KNumInput::KIntValidtr")); | 291 | m_spin->setValidator(new KIntValidator(this, _base, "KNumInput::KIntValidtr")); |
289 | connect(m_spin, SIGNAL(valueChanged(int)), SLOT(spinValueChanged(int))); | 292 | connect(m_spin, SIGNAL(valueChanged(int)), SLOT(spinValueChanged(int))); |
290 | connect(this, SIGNAL(valueChanged(int)), | 293 | connect(this, SIGNAL(valueChanged(int)), |
291 | SLOT(slotEmitRelativeValueChanged(int))); | 294 | SLOT(slotEmitRelativeValueChanged(int))); |
292 | 295 | ||
293 | setFocusProxy(m_spin); | 296 | setFocusProxy(m_spin); |
294 | layout(true); | 297 | layout(true); |
295 | } | 298 | } |
296 | 299 | ||
297 | void KIntNumInput::setReferencePoint( int ref ) { | 300 | void KIntNumInput::setReferencePoint( int ref ) { |
298 | // clip to valid range: | 301 | // clip to valid range: |
299 | ref = kMin( maxValue(), kMax( minValue(), ref ) ); | 302 | ref = kMin( maxValue(), kMax( minValue(), ref ) ); |
300 | d->referencePoint = ref; | 303 | d->referencePoint = ref; |
301 | } | 304 | } |
302 | 305 | ||
303 | int KIntNumInput::referencePoint() const { | 306 | int KIntNumInput::referencePoint() const { |
304 | return d->referencePoint; | 307 | return d->referencePoint; |
305 | } | 308 | } |
306 | 309 | ||
307 | void KIntNumInput::spinValueChanged(int val) | 310 | void KIntNumInput::spinValueChanged(int val) |
308 | { | 311 | { |
309 | if(m_slider) | 312 | if(m_slider) |
310 | m_slider->setValue(val); | 313 | m_slider->setValue(val); |
311 | 314 | ||
312 | emit valueChanged(val); | 315 | emit valueChanged(val); |
313 | } | 316 | } |
314 | 317 | ||
315 | void KIntNumInput::slotEmitRelativeValueChanged( int value ) { | 318 | void KIntNumInput::slotEmitRelativeValueChanged( int value ) { |
316 | if ( d->blockRelative || !d->referencePoint ) return; | 319 | if ( d->blockRelative || !d->referencePoint ) return; |
317 | emit relativeValueChanged( double( value ) / double( d->referencePoint ) ); | 320 | emit relativeValueChanged( double( value ) / double( d->referencePoint ) ); |
318 | } | 321 | } |
319 | 322 | ||
320 | void KIntNumInput::setRange(int lower, int upper, int step, bool slider) | 323 | void KIntNumInput::setRange(int lower, int upper, int step, bool slider) |
321 | { | 324 | { |
322 | upper = kMax(upper, lower); | 325 | upper = kMax(upper, lower); |
323 | lower = kMin(upper, lower); | 326 | lower = kMin(upper, lower); |
324 | m_spin->setMinValue(lower); | 327 | m_spin->setMinValue(lower); |
325 | m_spin->setMaxValue(upper); | 328 | m_spin->setMaxValue(upper); |
326 | m_spin->setLineStep(step); | 329 | m_spin->setLineStep(step); |
327 | 330 | ||
328 | step = m_spin->lineStep(); // maybe QRangeControl didn't like out lineStep? | 331 | step = m_spin->singleStep(); // maybe QRangeControl didn't like out lineStep? |
329 | 332 | ||
330 | if(slider) { | 333 | if(slider) { |
331 | if (m_slider) | 334 | if (m_slider) |
332 | m_slider->setRange(lower, upper); | 335 | m_slider->setRange(lower, upper); |
333 | else { | 336 | else { |
334 | m_slider = new QSlider(lower, upper, step, m_spin->value(), | 337 | m_slider = new QSlider(lower, upper, step, m_spin->value(), |
335 | QSlider::Horizontal, this); | 338 | Qt::Horizontal, this); |
336 | m_slider->setTickmarks(QSlider::Below); | 339 | m_slider->setTickmarks(QSlider::Below); |
337 | connect(m_slider, SIGNAL(valueChanged(int)), | 340 | connect(m_slider, SIGNAL(valueChanged(int)), |
338 | m_spin, SLOT(setValue(int))); | 341 | m_spin, SLOT(setValue(int))); |
339 | } | 342 | } |
340 | 343 | ||
341 | // calculate (upper-lower)/10 without overflowing int's: | 344 | // calculate (upper-lower)/10 without overflowing int's: |
342 | int major = calcDiffByTen( upper, lower ); | 345 | int major = calcDiffByTen( upper, lower ); |
343 | if ( major==0 ) major = step; // #### workaround Qt bug in 2.1-beta4 | 346 | if ( major==0 ) major = step; // #### workaround Qt bug in 2.1-beta4 |
344 | 347 | ||
345 | m_slider->setSteps(step, major); | 348 | m_slider->setSteps(step, major); |
346 | m_slider->setTickInterval(major); | 349 | m_slider->setTickInterval(major); |
347 | } | 350 | } |
348 | else { | 351 | else { |
349 | delete m_slider; | 352 | delete m_slider; |
350 | m_slider = 0; | 353 | m_slider = 0; |
351 | } | 354 | } |
352 | 355 | ||
353 | // check that reference point is still inside valid range: | 356 | // check that reference point is still inside valid range: |
354 | setReferencePoint( referencePoint() ); | 357 | setReferencePoint( referencePoint() ); |
355 | 358 | ||
356 | layout(true); | 359 | layout(true); |
357 | } | 360 | } |
358 | 361 | ||
359 | void KIntNumInput::setMinValue(int min) | 362 | void KIntNumInput::setMinValue(int min) |
360 | { | 363 | { |
361 | setRange(min, m_spin->maxValue(), m_spin->lineStep(), m_slider); | 364 | setRange(min, m_spin->maxValue(), m_spin->singleStep(), m_slider); |
362 | } | 365 | } |
363 | 366 | ||
364 | int KIntNumInput::minValue() const | 367 | int KIntNumInput::minValue() const |
365 | { | 368 | { |
366 | return m_spin->minValue(); | 369 | return m_spin->minValue(); |
367 | } | 370 | } |
368 | 371 | ||
369 | void KIntNumInput::setMaxValue(int max) | 372 | void KIntNumInput::setMaxValue(int max) |
370 | { | 373 | { |
371 | setRange(m_spin->minValue(), max, m_spin->lineStep(), m_slider); | 374 | setRange(m_spin->minValue(), max, m_spin->singleStep(), m_slider); |
372 | } | 375 | } |
373 | 376 | ||
374 | int KIntNumInput::maxValue() const | 377 | int KIntNumInput::maxValue() const |
375 | { | 378 | { |
376 | return m_spin->maxValue(); | 379 | return m_spin->maxValue(); |
377 | } | 380 | } |
378 | 381 | ||
379 | void KIntNumInput::setSuffix(const QString &suffix) | 382 | void KIntNumInput::setSuffix(const QString &suffix) |
380 | { | 383 | { |
381 | m_spin->setSuffix(suffix); | 384 | m_spin->setSuffix(suffix); |
382 | 385 | ||
383 | layout(true); | 386 | layout(true); |
384 | } | 387 | } |
385 | 388 | ||
386 | QString KIntNumInput::suffix() const | 389 | QString KIntNumInput::suffix() const |
387 | { | 390 | { |
388 | return m_spin->suffix(); | 391 | return m_spin->suffix(); |
389 | } | 392 | } |
390 | 393 | ||
391 | void KIntNumInput::setPrefix(const QString &prefix) | 394 | void KIntNumInput::setPrefix(const QString &prefix) |
392 | { | 395 | { |
393 | m_spin->setPrefix(prefix); | 396 | m_spin->setPrefix(prefix); |
394 | 397 | ||
395 | layout(true); | 398 | layout(true); |
396 | } | 399 | } |
397 | 400 | ||
398 | QString KIntNumInput::prefix() const | 401 | QString KIntNumInput::prefix() const |
399 | { | 402 | { |
400 | return m_spin->prefix(); | 403 | return m_spin->prefix(); |
401 | } | 404 | } |
402 | 405 | ||
403 | void KIntNumInput::setEditFocus(bool mark) | 406 | void KIntNumInput::setEditFocus(bool mark) |
404 | { | 407 | { |
405 | m_spin->setEditFocus(mark); | 408 | m_spin->setEditFocus(mark); |
406 | } | 409 | } |
407 | 410 | ||
408 | QSize KIntNumInput::minimumSizeHint() const | 411 | QSize KIntNumInput::minimumSizeHint() const |
409 | { | 412 | { |
410 | constPolish(); | 413 | constPolish(); |
411 | 414 | ||
412 | int w; | 415 | int w; |
413 | int h; | 416 | int h; |
414 | 417 | ||
415 | h = 2 + QMAX(m_sizeSpin.height(), m_sizeSlider.height()); | 418 | h = 2 + QMAX(m_sizeSpin.height(), m_sizeSlider.height()); |
416 | 419 | ||
417 | // if in extra row, then count it here | 420 | // if in extra row, then count it here |
418 | if(m_label && (m_alignment & (AlignBottom|AlignTop))) | 421 | if(m_label && (m_alignment & (Qt::AlignBottom|Qt::AlignTop))) |
419 | h += 4 + m_sizeLabel.height(); | 422 | h += 4 + m_sizeLabel.height(); |
420 | else | 423 | else |
421 | // label is in the same row as the other widgets | 424 | // label is in the same row as the other widgets |
422 | h = QMAX(h, m_sizeLabel.height() + 2); | 425 | h = QMAX(h, m_sizeLabel.height() + 2); |
423 | 426 | ||
424 | w = m_slider ? m_slider->sizeHint().width() + 8 : 0; | 427 | w = m_slider ? m_slider->sizeHint().width() + 8 : 0; |
425 | w += m_colw1 + m_colw2; | 428 | w += m_colw1 + m_colw2; |
426 | 429 | ||
427 | if(m_alignment & (AlignTop|AlignBottom)) | 430 | if(m_alignment & (Qt::AlignTop|Qt::AlignBottom)) |
428 | w = QMAX(w, m_sizeLabel.width() + 4); | 431 | w = QMAX(w, m_sizeLabel.width() + 4); |
429 | 432 | ||
430 | return QSize(w, h); | 433 | return QSize(w, h); |
431 | } | 434 | } |
432 | 435 | ||
433 | void KIntNumInput::doLayout() | 436 | void KIntNumInput::doLayout() |
434 | { | 437 | { |
435 | m_sizeSpin = m_spin->sizeHint(); | 438 | m_sizeSpin = m_spin->sizeHint(); |
436 | m_colw2 = m_sizeSpin.width(); | 439 | m_colw2 = m_sizeSpin.width(); |
437 | 440 | ||
438 | if (m_label) | 441 | if (m_label) |
439 | m_label->setBuddy(m_spin); | 442 | m_label->setBuddy(m_spin); |
440 | } | 443 | } |
441 | 444 | ||
442 | void KIntNumInput::resizeEvent(QResizeEvent* e) | 445 | void KIntNumInput::resizeEvent(QResizeEvent* e) |
443 | { | 446 | { |
444 | int w = m_colw1; | 447 | int w = m_colw1; |
445 | int h = 0; | 448 | int h = 0; |
446 | 449 | ||
447 | if(m_label && (m_alignment & AlignTop)) { | 450 | if(m_label && (m_alignment & Qt::AlignTop)) { |
448 | m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height()); | 451 | m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height()); |
449 | h += m_sizeLabel.height() + 4; | 452 | h += m_sizeLabel.height() + 4; |
450 | } | 453 | } |
451 | 454 | ||
452 | if(m_label && (m_alignment & AlignVCenter)) | 455 | if(m_label && (m_alignment & Qt::AlignVCenter)) |
453 | m_label->setGeometry(0, 0, w, m_sizeSpin.height()); | 456 | m_label->setGeometry(0, 0, w, m_sizeSpin.height()); |
454 | 457 | ||
455 | m_spin->setGeometry(w, h, m_slider ? m_colw2 : QMAX(m_colw2, e->size().width() - w), m_sizeSpin.height()); | 458 | m_spin->setGeometry(w, h, m_slider ? m_colw2 : QMAX(m_colw2, e->size().width() - w), m_sizeSpin.height()); |
456 | w += m_colw2 + 8; | 459 | w += m_colw2 + 8; |
457 | 460 | ||
458 | if(m_slider) | 461 | if(m_slider) |
459 | m_slider->setGeometry(w, h, e->size().width() - w, m_sizeSpin.height()); | 462 | m_slider->setGeometry(w, h, e->size().width() - w, m_sizeSpin.height()); |
460 | 463 | ||
461 | h += m_sizeSpin.height() + 2; | 464 | h += m_sizeSpin.height() + 2; |
462 | 465 | ||
463 | if(m_label && (m_alignment & AlignBottom)) | 466 | if(m_label && (m_alignment & Qt::AlignBottom)) |
464 | m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height()); | 467 | m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height()); |
465 | } | 468 | } |
466 | 469 | ||
467 | KIntNumInput::~KIntNumInput() | 470 | KIntNumInput::~KIntNumInput() |
468 | { | 471 | { |
469 | delete d; | 472 | delete d; |
470 | } | 473 | } |
471 | 474 | ||
472 | void KIntNumInput::setValue(int val) | 475 | void KIntNumInput::setValue(int val) |
473 | { | 476 | { |
474 | m_spin->setValue(val); | 477 | m_spin->setValue(val); |
475 | // slider value is changed by spinValueChanged | 478 | // slider value is changed by spinValueChanged |
476 | } | 479 | } |
477 | 480 | ||
478 | void KIntNumInput::setRelativeValue( double r ) { | 481 | void KIntNumInput::setRelativeValue( double r ) { |
479 | if ( !d->referencePoint ) return; | 482 | if ( !d->referencePoint ) return; |
480 | ++d->blockRelative; | 483 | ++d->blockRelative; |
481 | setValue( int( d->referencePoint * r + 0.5 ) ); | 484 | setValue( int( d->referencePoint * r + 0.5 ) ); |
482 | --d->blockRelative; | 485 | --d->blockRelative; |
483 | } | 486 | } |
484 | 487 | ||
485 | double KIntNumInput::relativeValue() const { | 488 | double KIntNumInput::relativeValue() const { |
486 | if ( !d->referencePoint ) return 0; | 489 | if ( !d->referencePoint ) return 0; |
487 | return double( value() ) / double ( d->referencePoint ); | 490 | return double( value() ) / double ( d->referencePoint ); |
488 | } | 491 | } |
489 | 492 | ||
490 | int KIntNumInput::value() const | 493 | int KIntNumInput::value() const |
491 | { | 494 | { |
492 | return m_spin->value(); | 495 | return m_spin->value(); |
493 | } | 496 | } |
494 | 497 | ||
495 | void KIntNumInput::setSpecialValueText(const QString& text) | 498 | void KIntNumInput::setSpecialValueText(const QString& text) |
496 | { | 499 | { |
497 | m_spin->setSpecialValueText(text); | 500 | m_spin->setSpecialValueText(text); |
498 | layout(true); | 501 | layout(true); |
499 | } | 502 | } |
500 | 503 | ||
501 | QString KIntNumInput::specialValueText() const | 504 | QString KIntNumInput::specialValueText() const |
502 | { | 505 | { |
503 | return m_spin->specialValueText(); | 506 | return m_spin->specialValueText(); |
504 | } | 507 | } |
505 | 508 | ||
506 | void KIntNumInput::setLabel(const QString & label, int a) | 509 | void KIntNumInput::setLabel(const QString & label, int a) |
507 | { | 510 | { |
508 | KNumInput::setLabel(label, a); | 511 | KNumInput::setLabel(label, a); |
509 | 512 | ||
510 | if(m_label) | 513 | if(m_label) |
511 | m_label->setBuddy(m_spin); | 514 | m_label->setBuddy(m_spin); |
512 | } | 515 | } |
513 | 516 | ||
514 | // ---------------------------------------------------------------------------- | 517 | // ---------------------------------------------------------------------------- |
515 | 518 | ||
516 | class KDoubleNumInput::KDoubleNumInputPrivate { | 519 | class KDoubleNumInput::KDoubleNumInputPrivate { |
517 | public: | 520 | public: |
518 | KDoubleNumInputPrivate( double r ) | 521 | KDoubleNumInputPrivate( double r ) |
519 | : spin( 0 ), | 522 | : spin( 0 ), |
520 | referencePoint( r ), | 523 | referencePoint( r ), |
521 | blockRelative ( 0 ) {} | 524 | blockRelative ( 0 ) {} |
522 | KDoubleSpinBox * spin; | 525 | KDoubleSpinBox * spin; |
523 | double referencePoint; | 526 | double referencePoint; |
524 | short blockRelative; | 527 | short blockRelative; |
525 | }; | 528 | }; |
526 | 529 | ||
527 | KDoubleNumInput::KDoubleNumInput(QWidget *parent, const char *name) | 530 | KDoubleNumInput::KDoubleNumInput(QWidget *parent, const char *name) |
528 | : KNumInput(parent, name) | 531 | : KNumInput(parent, name) |
529 | { | 532 | { |
530 | init(0.0, 0.0, 9999.0, 0.01, 2); | 533 | init(0.0, 0.0, 9999.0, 0.01, 2); |
531 | } | 534 | } |
532 | 535 | ||
533 | KDoubleNumInput::KDoubleNumInput(double lower, double upper, double value, | 536 | KDoubleNumInput::KDoubleNumInput(double lower, double upper, double value, |
534 | double step, int precision, QWidget* parent, | 537 | double step, int precision, QWidget* parent, |
535 | const char *name) | 538 | const char *name) |
536 | : KNumInput(parent, name) | 539 | : KNumInput(parent, name) |
537 | { | 540 | { |
538 | init(value, lower, upper, step, precision); | 541 | init(value, lower, upper, step, precision); |
539 | } | 542 | } |
540 | 543 | ||
541 | KDoubleNumInput::KDoubleNumInput(KNumInput *below, | 544 | KDoubleNumInput::KDoubleNumInput(KNumInput *below, |
542 | double lower, double upper, double value, | 545 | double lower, double upper, double value, |
543 | double step, int precision, QWidget* parent, | 546 | double step, int precision, QWidget* parent, |
544 | const char *name) | 547 | const char *name) |
545 | : KNumInput(below, parent, name) | 548 | : KNumInput(below, parent, name) |
546 | { | 549 | { |
547 | init(value, lower, upper, step, precision); | 550 | init(value, lower, upper, step, precision); |
548 | } | 551 | } |
549 | 552 | ||
550 | KDoubleNumInput::KDoubleNumInput(double value, QWidget *parent, const char *name) | 553 | KDoubleNumInput::KDoubleNumInput(double value, QWidget *parent, const char *name) |
551 | : KNumInput(parent, name) | 554 | : KNumInput(parent, name) |
552 | { | 555 | { |
553 | init(value, kMin(0.0, value), kMax(0.0, value), 0.01, 2 ); | 556 | init(value, kMin(0.0, value), kMax(0.0, value), 0.01, 2 ); |
554 | } | 557 | } |
555 | 558 | ||
556 | KDoubleNumInput::KDoubleNumInput(KNumInput* below, double value, QWidget* parent, | 559 | KDoubleNumInput::KDoubleNumInput(KNumInput* below, double value, QWidget* parent, |
557 | const char* name) | 560 | const char* name) |
558 | : KNumInput(below, parent, name) | 561 | : KNumInput(below, parent, name) |
559 | { | 562 | { |
560 | init( value, kMin(0.0, value), kMax(0.0, value), 0.01, 2 ); | 563 | init( value, kMin(0.0, value), kMax(0.0, value), 0.01, 2 ); |
561 | } | 564 | } |
562 | 565 | ||
563 | KDoubleNumInput::~KDoubleNumInput() | 566 | KDoubleNumInput::~KDoubleNumInput() |
564 | { | 567 | { |
565 | delete d; | 568 | delete d; |
566 | } | 569 | } |
567 | 570 | ||
568 | // ### remove when BIC changes are allowed again: | 571 | // ### remove when BIC changes are allowed again: |
569 | 572 | ||
570 | bool KDoubleNumInput::eventFilter( QObject * o, QEvent * e ) { | 573 | bool KDoubleNumInput::eventFilter( QObject * o, QEvent * e ) { |
571 | return KNumInput::eventFilter( o, e ); | 574 | return KNumInput::eventFilter( o, e ); |
572 | } | 575 | } |
573 | 576 | ||
574 | void KDoubleNumInput::resetEditBox() { | 577 | void KDoubleNumInput::resetEditBox() { |
575 | 578 | ||
576 | } | 579 | } |
577 | 580 | ||
578 | // ### end stuff to remove when BIC changes are allowed again | 581 | // ### end stuff to remove when BIC changes are allowed again |
579 | 582 | ||
580 | 583 | ||
581 | 584 | ||
582 | void KDoubleNumInput::init(double value, double lower, double upper, | 585 | void KDoubleNumInput::init(double value, double lower, double upper, |
583 | double step, int precision ) | 586 | double step, int precision ) |
584 | { | 587 | { |
585 | // ### init no longer used members: | 588 | // ### init no longer used members: |
586 | edit = 0; | 589 | edit = 0; |
587 | m_range = true; | 590 | m_range = true; |
588 | m_value = 0.0; | 591 | m_value = 0.0; |
589 | m_precision = 2; | 592 | m_precision = 2; |
590 | // ### end | 593 | // ### end |
591 | 594 | ||
592 | d = new KDoubleNumInputPrivate( value ); | 595 | d = new KDoubleNumInputPrivate( value ); |
593 | 596 | ||
594 | d->spin = new KDoubleSpinBox( lower, upper, step, value, precision, | 597 | d->spin = new KDoubleSpinBox( lower, upper, step, value, precision, |
595 | this, "KDoubleNumInput::d->spin" ); | 598 | this, "KDoubleNumInput::d->spin" ); |
596 | setFocusProxy(d->spin); | 599 | setFocusProxy(d->spin); |
597 | connect( d->spin, SIGNAL(valueChanged(double)), | 600 | connect( d->spin, SIGNAL(valueChanged(double)), |
598 | this, SIGNAL(valueChanged(double)) ); | 601 | this, SIGNAL(valueChanged(double)) ); |
599 | connect( this, SIGNAL(valueChanged(double)), | 602 | connect( this, SIGNAL(valueChanged(double)), |
600 | this, SLOT(slotEmitRelativeValueChanged(double)) ); | 603 | this, SLOT(slotEmitRelativeValueChanged(double)) ); |
601 | 604 | ||
602 | updateLegacyMembers(); | 605 | updateLegacyMembers(); |
603 | 606 | ||
604 | layout(true); | 607 | layout(true); |
605 | } | 608 | } |
606 | 609 | ||
607 | void KDoubleNumInput::updateLegacyMembers() { | 610 | void KDoubleNumInput::updateLegacyMembers() { |
608 | // ### update legacy members that are either not private or for | 611 | // ### update legacy members that are either not private or for |
609 | // which an inlined getter exists: | 612 | // which an inlined getter exists: |
610 | m_lower = minValue(); | 613 | m_lower = minValue(); |
611 | m_upper = maxValue(); | 614 | m_upper = maxValue(); |
612 | m_step = d->spin->lineStep(); | 615 | m_step = d->spin->lineStep(); |
613 | m_specialvalue = specialValueText(); | 616 | m_specialvalue = specialValueText(); |
614 | } | 617 | } |
615 | 618 | ||
616 | 619 | ||
617 | double KDoubleNumInput::mapSliderToSpin( int val ) const | 620 | double KDoubleNumInput::mapSliderToSpin( int val ) const |
618 | { | 621 | { |
619 | // map [slidemin,slidemax] to [spinmin,spinmax] | 622 | // map [slidemin,slidemax] to [spinmin,spinmax] |
620 | double spinmin = d->spin->minValue(); | 623 | double spinmin = d->spin->minValue(); |
621 | double spinmax = d->spin->maxValue(); | 624 | double spinmax = d->spin->maxValue(); |
622 | double slidemin = m_slider->minValue(); // cast int to double to avoid | 625 | double slidemin = m_slider->minValue(); // cast int to double to avoid |
623 | double slidemax = m_slider->maxValue(); // overflow in rel denominator | 626 | double slidemax = m_slider->maxValue(); // overflow in rel denominator |
624 | double rel = ( double(val) - slidemin ) / ( slidemax - slidemin ); | 627 | double rel = ( double(val) - slidemin ) / ( slidemax - slidemin ); |
625 | return spinmin + rel * ( spinmax - spinmin ); | 628 | return spinmin + rel * ( spinmax - spinmin ); |
626 | } | 629 | } |
627 | 630 | ||
628 | void KDoubleNumInput::sliderMoved(int val) | 631 | void KDoubleNumInput::sliderMoved(int val) |
629 | { | 632 | { |
630 | d->spin->setValue( mapSliderToSpin( val ) ); | 633 | d->spin->setValue( mapSliderToSpin( val ) ); |
631 | } | 634 | } |
632 | 635 | ||
633 | void KDoubleNumInput::slotEmitRelativeValueChanged( double value ) | 636 | void KDoubleNumInput::slotEmitRelativeValueChanged( double value ) |
634 | { | 637 | { |
635 | if ( !d->referencePoint ) return; | 638 | if ( !d->referencePoint ) return; |
636 | emit relativeValueChanged( value / d->referencePoint ); | 639 | emit relativeValueChanged( value / d->referencePoint ); |
637 | } | 640 | } |
638 | 641 | ||
639 | QSize KDoubleNumInput::minimumSizeHint() const | 642 | QSize KDoubleNumInput::minimumSizeHint() const |
640 | { | 643 | { |
641 | constPolish(); | 644 | constPolish(); |
642 | 645 | ||
643 | int w; | 646 | int w; |
644 | int h; | 647 | int h; |
645 | 648 | ||
646 | h = 2 + QMAX(m_sizeEdit.height(), m_sizeSlider.height()); | 649 | h = 2 + QMAX(m_sizeEdit.height(), m_sizeSlider.height()); |
647 | 650 | ||
648 | // if in extra row, then count it here | 651 | // if in extra row, then count it here |
649 | if(m_label && (m_alignment & (AlignBottom|AlignTop))) | 652 | if(m_label && (m_alignment & (Qt::AlignBottom|Qt::AlignTop))) |
650 | h += 4 + m_sizeLabel.height(); | 653 | h += 4 + m_sizeLabel.height(); |
651 | else | 654 | else |
652 | // label is in the same row as the other widgets | 655 | // label is in the same row as the other widgets |
653 | h = QMAX(h, m_sizeLabel.height() + 2); | 656 | h = QMAX(h, m_sizeLabel.height() + 2); |
654 | 657 | ||
655 | w = m_slider ? m_slider->sizeHint().width() + 8 : 0; | 658 | w = m_slider ? m_slider->sizeHint().width() + 8 : 0; |
656 | w += m_colw1 + m_colw2; | 659 | w += m_colw1 + m_colw2; |
657 | 660 | ||
658 | if(m_alignment & (AlignTop|AlignBottom)) | 661 | if(m_alignment & (Qt::AlignTop|Qt::AlignBottom)) |
659 | w = QMAX(w, m_sizeLabel.width() + 4); | 662 | w = QMAX(w, m_sizeLabel.width() + 4); |
660 | 663 | ||
661 | return QSize(w, h); | 664 | return QSize(w, h); |
662 | } | 665 | } |
663 | 666 | ||
664 | void KDoubleNumInput::resizeEvent(QResizeEvent* e) | 667 | void KDoubleNumInput::resizeEvent(QResizeEvent* e) |
665 | { | 668 | { |
666 | int w = m_colw1; | 669 | int w = m_colw1; |
667 | int h = 0; | 670 | int h = 0; |
668 | 671 | ||
669 | if(m_label && (m_alignment & AlignTop)) { | 672 | if(m_label && (m_alignment & Qt::AlignTop)) { |
670 | m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height()); | 673 | m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height()); |
671 | h += m_sizeLabel.height() + 4; | 674 | h += m_sizeLabel.height() + 4; |
672 | } | 675 | } |
673 | 676 | ||
674 | if(m_label && (m_alignment & AlignVCenter)) | 677 | if(m_label && (m_alignment & Qt::AlignVCenter)) |
675 | m_label->setGeometry(0, 0, w, m_sizeEdit.height()); | 678 | m_label->setGeometry(0, 0, w, m_sizeEdit.height()); |
676 | 679 | ||
677 | d->spin->setGeometry(w, h, m_slider ? m_colw2 | 680 | d->spin->setGeometry(w, h, m_slider ? m_colw2 |
678 | : e->size().width() - w, m_sizeEdit.height()); | 681 | : e->size().width() - w, m_sizeEdit.height()); |
679 | w += m_colw2 + 8; | 682 | w += m_colw2 + 8; |
680 | 683 | ||
681 | if(m_slider) | 684 | if(m_slider) |
682 | m_slider->setGeometry(w, h, e->size().width() - w, m_sizeEdit.height()); | 685 | m_slider->setGeometry(w, h, e->size().width() - w, m_sizeEdit.height()); |
683 | 686 | ||
684 | h += m_sizeEdit.height() + 2; | 687 | h += m_sizeEdit.height() + 2; |
685 | 688 | ||
686 | if(m_label && (m_alignment & AlignBottom)) | 689 | if(m_label && (m_alignment & Qt::AlignBottom)) |
687 | m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height()); | 690 | m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height()); |
688 | } | 691 | } |
689 | 692 | ||
690 | void KDoubleNumInput::doLayout() | 693 | void KDoubleNumInput::doLayout() |
691 | { | 694 | { |
692 | m_sizeEdit = d->spin->sizeHint(); | 695 | m_sizeEdit = d->spin->sizeHint(); |
693 | m_colw2 = m_sizeEdit.width(); | 696 | m_colw2 = m_sizeEdit.width(); |
694 | } | 697 | } |
695 | 698 | ||
696 | void KDoubleNumInput::setValue(double val) | 699 | void KDoubleNumInput::setValue(double val) |
697 | { | 700 | { |
698 | d->spin->setValue( val ); | 701 | d->spin->setValue( val ); |
699 | } | 702 | } |
700 | 703 | ||
701 | void KDoubleNumInput::setRelativeValue( double r ) | 704 | void KDoubleNumInput::setRelativeValue( double r ) |
702 | { | 705 | { |
703 | if ( !d->referencePoint ) return; | 706 | if ( !d->referencePoint ) return; |
704 | ++d->blockRelative; | 707 | ++d->blockRelative; |
705 | setValue( r * d->referencePoint ); | 708 | setValue( r * d->referencePoint ); |
706 | --d->blockRelative; | 709 | --d->blockRelative; |
707 | } | 710 | } |
708 | 711 | ||
709 | void KDoubleNumInput::setReferencePoint( double ref ) | 712 | void KDoubleNumInput::setReferencePoint( double ref ) |
710 | { | 713 | { |
711 | // clip to valid range: | 714 | // clip to valid range: |
712 | ref = kMin( maxValue(), kMax( minValue(), ref ) ); | 715 | ref = kMin( maxValue(), kMax( minValue(), ref ) ); |
713 | d->referencePoint = ref; | 716 | d->referencePoint = ref; |
714 | } | 717 | } |
715 | 718 | ||
716 | void KDoubleNumInput::setRange(double lower, double upper, double step, | 719 | void KDoubleNumInput::setRange(double lower, double upper, double step, |
717 | bool slider) | 720 | bool slider) |
718 | { | 721 | { |
719 | if( m_slider ) { | 722 | if( m_slider ) { |
720 | // don't update the slider to avoid an endless recursion | 723 | // don't update the slider to avoid an endless recursion |
721 | QSpinBox * spin = d->spin; | 724 | QSpinBox * spin = d->spin; |
722 | disconnect(spin, SIGNAL(valueChanged(int)), | 725 | disconnect(spin, SIGNAL(valueChanged(int)), |
723 | m_slider, SLOT(setValue(int)) ); | 726 | m_slider, SLOT(setValue(int)) ); |
724 | } | 727 | } |
725 | d->spin->setRange( lower, upper, step, d->spin->precision() ); | 728 | d->spin->setRange( lower, upper, step, d->spin->precision() ); |
726 | 729 | ||
727 | if(slider) { | 730 | if(slider) { |
728 | // upcast to base type to get the min/maxValue in int form: | 731 | // upcast to base type to get the min/maxValue in int form: |
729 | QSpinBox * spin = d->spin; | 732 | QSpinBox * spin = d->spin; |
730 | int slmax = spin->maxValue(); | 733 | int slmax = spin->maxValue(); |
731 | int slmin = spin->minValue(); | 734 | int slmin = spin->minValue(); |
732 | int slvalue = spin->value(); | 735 | int slvalue = spin->value(); |
733 | int slstep = spin->lineStep(); | 736 | int slstep = spin->singleStep(); |
734 | if (m_slider) { | 737 | if (m_slider) { |
735 | m_slider->setRange(slmin, slmax); | 738 | m_slider->setRange(slmin, slmax); |
736 | m_slider->setLineStep(slstep); | 739 | m_slider->setLineStep(slstep); |
737 | m_slider->setValue(slvalue); | 740 | m_slider->setValue(slvalue); |
738 | } else { | 741 | } else { |
739 | m_slider = new QSlider(slmin, slmax, slstep, slvalue, | 742 | m_slider = new QSlider(slmin, slmax, slstep, slvalue, |
740 | QSlider::Horizontal, this); | 743 | Qt::Horizontal, this); |
741 | m_slider->setTickmarks(QSlider::Below); | 744 | m_slider->setTickmarks(QSlider::Below); |
742 | // feedback line: when one moves, the other moves, too: | 745 | // feedback line: when one moves, the other moves, too: |
743 | connect(m_slider, SIGNAL(valueChanged(int)), | 746 | connect(m_slider, SIGNAL(valueChanged(int)), |
744 | SLOT(sliderMoved(int)) ); | 747 | SLOT(sliderMoved(int)) ); |
745 | } | 748 | } |
746 | connect(spin, SIGNAL(valueChanged(int)), | 749 | connect(spin, SIGNAL(valueChanged(int)), |
747 | m_slider, SLOT(setValue(int)) ); | 750 | m_slider, SLOT(setValue(int)) ); |
748 | // calculate ( slmax - slmin ) / 10 without overflowing ints: | 751 | // calculate ( slmax - slmin ) / 10 without overflowing ints: |
749 | int major = calcDiffByTen( slmax, slmin ); | 752 | int major = calcDiffByTen( slmax, slmin ); |
750 | if ( !major ) major = slstep; // ### needed? | 753 | if ( !major ) major = slstep; // ### needed? |
751 | m_slider->setTickInterval(major); | 754 | m_slider->setTickInterval(major); |
752 | } else { | 755 | } else { |
753 | delete m_slider; | 756 | delete m_slider; |
754 | m_slider = 0; | 757 | m_slider = 0; |
755 | } | 758 | } |
756 | 759 | ||
757 | setReferencePoint( referencePoint() ); | 760 | setReferencePoint( referencePoint() ); |
758 | 761 | ||
759 | layout(true); | 762 | layout(true); |
760 | updateLegacyMembers(); | 763 | updateLegacyMembers(); |
761 | } | 764 | } |
762 | 765 | ||
763 | void KDoubleNumInput::setMinValue(double min) | 766 | void KDoubleNumInput::setMinValue(double min) |
764 | { | 767 | { |
765 | setRange(min, maxValue(), d->spin->lineStep(), m_slider); | 768 | setRange(min, maxValue(), d->spin->lineStep(), m_slider); |
766 | } | 769 | } |
767 | 770 | ||
768 | double KDoubleNumInput::minValue() const | 771 | double KDoubleNumInput::minValue() const |
769 | { | 772 | { |
770 | return d->spin->minValue(); | 773 | return d->spin->minValue(); |
771 | } | 774 | } |
772 | 775 | ||
773 | void KDoubleNumInput::setMaxValue(double max) | 776 | void KDoubleNumInput::setMaxValue(double max) |
774 | { | 777 | { |
775 | setRange(minValue(), max, d->spin->lineStep(), m_slider); | 778 | setRange(minValue(), max, d->spin->lineStep(), m_slider); |
776 | } | 779 | } |
777 | 780 | ||
778 | double KDoubleNumInput::maxValue() const | 781 | double KDoubleNumInput::maxValue() const |
779 | { | 782 | { |
780 | return d->spin->maxValue(); | 783 | return d->spin->maxValue(); |
781 | } | 784 | } |
782 | 785 | ||
783 | double KDoubleNumInput::value() const | 786 | double KDoubleNumInput::value() const |
784 | { | 787 | { |
785 | return d->spin->value(); | 788 | return d->spin->value(); |
786 | } | 789 | } |
787 | 790 | ||
788 | double KDoubleNumInput::relativeValue() const | 791 | double KDoubleNumInput::relativeValue() const |
789 | { | 792 | { |
790 | if ( !d->referencePoint ) return 0; | 793 | if ( !d->referencePoint ) return 0; |
791 | return value() / d->referencePoint; | 794 | return value() / d->referencePoint; |
792 | } | 795 | } |
793 | 796 | ||
794 | double KDoubleNumInput::referencePoint() const | 797 | double KDoubleNumInput::referencePoint() const |
795 | { | 798 | { |
796 | return d->referencePoint; | 799 | return d->referencePoint; |
797 | } | 800 | } |
798 | 801 | ||
799 | QString KDoubleNumInput::suffix() const | 802 | QString KDoubleNumInput::suffix() const |
800 | { | 803 | { |
801 | return d->spin->suffix(); | 804 | return d->spin->suffix(); |
802 | } | 805 | } |
803 | 806 | ||
804 | QString KDoubleNumInput::prefix() const | 807 | QString KDoubleNumInput::prefix() const |
805 | { | 808 | { |
806 | return d->spin->prefix(); | 809 | return d->spin->prefix(); |
807 | } | 810 | } |
808 | 811 | ||
809 | void KDoubleNumInput::setSuffix(const QString &suffix) | 812 | void KDoubleNumInput::setSuffix(const QString &suffix) |
810 | { | 813 | { |
811 | d->spin->setSuffix( suffix ); | 814 | d->spin->setSuffix( suffix ); |
812 | 815 | ||
813 | layout(true); | 816 | layout(true); |
814 | } | 817 | } |
815 | 818 | ||
816 | void KDoubleNumInput::setPrefix(const QString &prefix) | 819 | void KDoubleNumInput::setPrefix(const QString &prefix) |
817 | { | 820 | { |
818 | d->spin->setPrefix( prefix ); | 821 | d->spin->setPrefix( prefix ); |
819 | 822 | ||
820 | layout(true); | 823 | layout(true); |
821 | } | 824 | } |
822 | 825 | ||
823 | void KDoubleNumInput::setPrecision(int precision) | 826 | void KDoubleNumInput::setPrecision(int precision) |
824 | { | 827 | { |
825 | d->spin->setPrecision( precision ); | 828 | d->spin->setPrecision( precision ); |
826 | 829 | ||
827 | layout(true); | 830 | layout(true); |
828 | } | 831 | } |
829 | 832 | ||
830 | int KDoubleNumInput::precision() const | 833 | int KDoubleNumInput::precision() const |
831 | { | 834 | { |
832 | return d->spin->precision(); | 835 | return d->spin->precision(); |
833 | } | 836 | } |
834 | 837 | ||
835 | void KDoubleNumInput::setSpecialValueText(const QString& text) | 838 | void KDoubleNumInput::setSpecialValueText(const QString& text) |
836 | { | 839 | { |
837 | d->spin->setSpecialValueText( text ); | 840 | d->spin->setSpecialValueText( text ); |
838 | 841 | ||
839 | layout(true); | 842 | layout(true); |
840 | updateLegacyMembers(); | 843 | updateLegacyMembers(); |
841 | } | 844 | } |
842 | 845 | ||
843 | void KDoubleNumInput::setLabel(const QString & label, int a) | 846 | void KDoubleNumInput::setLabel(const QString & label, int a) |
844 | { | 847 | { |
845 | KNumInput::setLabel(label, a); | 848 | KNumInput::setLabel(label, a); |
846 | 849 | ||
847 | if(m_label) | 850 | if(m_label) |
848 | m_label->setBuddy(d->spin); | 851 | m_label->setBuddy(d->spin); |
849 | 852 | ||
850 | } | 853 | } |
851 | 854 | ||
852 | // ---------------------------------------------------------------------------- | 855 | // ---------------------------------------------------------------------------- |
853 | 856 | ||
854 | 857 | ||
855 | // We use a kind of fixed-point arithmetic to represent the range of | 858 | // We use a kind of fixed-point arithmetic to represent the range of |
856 | // doubles [mLower,mUpper] in steps of 10^(-mPrecision). Thus, the | 859 | // doubles [mLower,mUpper] in steps of 10^(-mPrecision). Thus, the |
857 | // following relations hold: | 860 | // following relations hold: |
858 | // | 861 | // |
859 | // 1. factor = 10^mPrecision | 862 | // 1. factor = 10^mPrecision |
860 | // 2. basicStep = 1/factor = 10^(-mPrecision); | 863 | // 2. basicStep = 1/factor = 10^(-mPrecision); |
861 | // 3. lowerInt = lower * factor; | 864 | // 3. lowerInt = lower * factor; |
862 | // 4. upperInt = upper * factor; | 865 | // 4. upperInt = upper * factor; |
863 | // 5. lower = lowerInt * basicStep; | 866 | // 5. lower = lowerInt * basicStep; |
864 | // 6. upper = upperInt * basicStep; | 867 | // 6. upper = upperInt * basicStep; |
865 | class KDoubleSpinBox::Private { | 868 | class KDoubleSpinBox::Private { |
866 | public: | 869 | public: |
867 | Private( int precision=1 ) | 870 | Private( int precision=1 ) |
868 | : mPrecision( precision ), | 871 | : mPrecision( precision ), |
869 | mValidator( 0 ) | 872 | mValidator( 0 ) |
870 | { | 873 | { |
871 | } | 874 | } |
872 | 875 | ||
873 | int factor() const { | 876 | int factor() const { |
874 | int f = 1; | 877 | int f = 1; |
875 | for ( int i = 0 ; i < mPrecision ; ++i ) f *= 10; | 878 | for ( int i = 0 ; i < mPrecision ; ++i ) f *= 10; |
876 | return f; | 879 | return f; |
877 | } | 880 | } |
878 | 881 | ||
879 | double basicStep() const { | 882 | double basicStep() const { |
880 | return 1.0/double(factor()); | 883 | return 1.0/double(factor()); |
881 | } | 884 | } |
882 | 885 | ||
883 | int mapToInt( double value, bool * ok ) const { | 886 | int mapToInt( double value, bool * ok ) const { |
884 | assert( ok ); | 887 | assert( ok ); |
885 | const double f = factor(); | 888 | const double f = factor(); |
886 | if ( value > double(INT_MAX) / f ) { | 889 | if ( value > double(INT_MAX) / f ) { |
887 | kdWarning() << "KDoubleSpinBox: can't represent value " << value | 890 | kdWarning() << "KDoubleSpinBox: can't represent value " << value |
888 | << "in terms of fixed-point numbers with precision " | 891 | << "in terms of fixed-point numbers with precision " |
889 | << mPrecision << endl; | 892 | << mPrecision << endl; |
890 | *ok = false; | 893 | *ok = false; |
891 | return INT_MAX; | 894 | return INT_MAX; |
892 | } else if ( value < double(INT_MIN) / f ) { | 895 | } else if ( value < double(INT_MIN) / f ) { |
893 | kdWarning() << "KDoubleSpinBox: can't represent value " << value | 896 | kdWarning() << "KDoubleSpinBox: can't represent value " << value |
894 | << "in terms of fixed-point numbers with precision " | 897 | << "in terms of fixed-point numbers with precision " |
895 | << mPrecision << endl; | 898 | << mPrecision << endl; |
896 | *ok = false; | 899 | *ok = false; |
897 | return INT_MIN; | 900 | return INT_MIN; |
898 | } else { | 901 | } else { |
899 | *ok = true; | 902 | *ok = true; |
900 | return int( value * f + ( value < 0 ? -0.5 : 0.5 ) ); | 903 | return int( value * f + ( value < 0 ? -0.5 : 0.5 ) ); |
901 | } | 904 | } |
902 | } | 905 | } |
903 | 906 | ||
904 | double mapToDouble( int value ) const { | 907 | double mapToDouble( int value ) const { |
905 | return double(value) * basicStep(); | 908 | return double(value) * basicStep(); |
906 | } | 909 | } |
907 | 910 | ||
908 | int mPrecision; | 911 | int mPrecision; |
909 | KDoubleValidator * mValidator; | 912 | KDoubleValidator * mValidator; |
910 | }; | 913 | }; |
911 | 914 | ||
912 | KDoubleSpinBox::KDoubleSpinBox( QWidget * parent, const char * name ) | 915 | KDoubleSpinBox::KDoubleSpinBox( QWidget * parent, const char * name ) |
913 | : QSpinBox( parent, name ) | 916 | : QSpinBox( parent, name ) |
914 | { | 917 | { |
915 | editor()->setAlignment( Qt::AlignRight ); | 918 | setAlignment( Qt::AlignRight ); |
916 | d = new Private(); | 919 | d = new Private(); |
917 | updateValidator(); | 920 | updateValidator(); |
918 | } | 921 | } |
919 | 922 | ||
920 | KDoubleSpinBox::KDoubleSpinBox( double lower, double upper, double step, | 923 | KDoubleSpinBox::KDoubleSpinBox( double lower, double upper, double step, |
921 | double value, int precision, | 924 | double value, int precision, |
922 | QWidget * parent, const char * name ) | 925 | QWidget * parent, const char * name ) |
923 | : QSpinBox( parent, name ) | 926 | : QSpinBox( parent, name ) |
924 | { | 927 | { |
925 | editor()->setAlignment( Qt::AlignRight ); | 928 | setAlignment( Qt::AlignRight ); |
926 | d = new Private(); | 929 | d = new Private(); |
927 | setRange( lower, upper, step, precision ); | 930 | setRange( lower, upper, step, precision ); |
928 | setValue( value ); | 931 | setValue( value ); |
929 | connect( this, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)) ); | 932 | connect( this, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)) ); |
930 | } | 933 | } |
931 | 934 | ||
932 | KDoubleSpinBox::~KDoubleSpinBox() { | 935 | KDoubleSpinBox::~KDoubleSpinBox() { |
933 | delete d; d = 0; | 936 | delete d; d = 0; |
934 | } | 937 | } |
935 | 938 | ||
936 | bool KDoubleSpinBox::acceptLocalizedNumbers() const { | 939 | bool KDoubleSpinBox::acceptLocalizedNumbers() const { |
937 | if ( !d->mValidator ) return true; // we'll set one that does; | 940 | if ( !d->mValidator ) return true; // we'll set one that does; |
938 | // can't do it now, since we're const | 941 | // can't do it now, since we're const |
939 | return d->mValidator->acceptLocalizedNumbers(); | 942 | return d->mValidator->acceptLocalizedNumbers(); |
940 | } | 943 | } |
941 | 944 | ||
942 | void KDoubleSpinBox::setAcceptLocalizedNumbers( bool accept ) { | 945 | void KDoubleSpinBox::setAcceptLocalizedNumbers( bool accept ) { |
943 | if ( !d->mValidator ) updateValidator(); | 946 | if ( !d->mValidator ) updateValidator(); |
944 | d->mValidator->setAcceptLocalizedNumbers( accept ); | 947 | d->mValidator->setAcceptLocalizedNumbers( accept ); |
945 | } | 948 | } |
946 | 949 | ||
947 | void KDoubleSpinBox::setRange( double lower, double upper, double step, | 950 | void KDoubleSpinBox::setRange( double lower, double upper, double step, |
948 | int precision ) { | 951 | int precision ) { |
949 | lower = kMin(upper, lower); | 952 | lower = kMin(upper, lower); |
950 | upper = kMax(upper, lower); | 953 | upper = kMax(upper, lower); |
951 | setPrecision( precision, true ); // disable bounds checking, since | 954 | setPrecision( precision, true ); // disable bounds checking, since |
952 | setMinValue( lower ); // it's done in set{Min,Max}Value | 955 | setMinValue( lower ); // it's done in set{Min,Max}Value |
953 | setMaxValue( upper ); // anyway and we want lower, upper | 956 | setMaxValue( upper ); // anyway and we want lower, upper |
954 | setLineStep( step ); // and step to have the right precision | 957 | setLineStep( step ); // and step to have the right precision |
955 | } | 958 | } |
956 | 959 | ||
957 | int KDoubleSpinBox::precision() const { | 960 | int KDoubleSpinBox::precision() const { |
958 | return d->mPrecision; | 961 | return d->mPrecision; |
959 | } | 962 | } |
960 | 963 | ||
961 | void KDoubleSpinBox::setPrecision( int precision ) { | 964 | void KDoubleSpinBox::setPrecision( int precision ) { |
962 | setPrecision( precision, false ); | 965 | setPrecision( precision, false ); |
963 | } | 966 | } |
964 | 967 | ||
965 | void KDoubleSpinBox::setPrecision( int precision, bool force ) { | 968 | void KDoubleSpinBox::setPrecision( int precision, bool force ) { |
966 | if ( precision < 1 ) return; | 969 | if ( precision < 1 ) return; |
967 | if ( !force ) { | 970 | if ( !force ) { |
968 | int maxPrec = maxPrecision(); | 971 | int maxPrec = maxPrecision(); |
969 | if ( precision > maxPrec ) | 972 | if ( precision > maxPrec ) |
970 | precision = maxPrec; | 973 | precision = maxPrec; |
971 | } | 974 | } |
972 | d->mPrecision = precision; | 975 | d->mPrecision = precision; |
973 | updateValidator(); | 976 | updateValidator(); |
974 | } | 977 | } |
975 | 978 | ||
976 | int KDoubleSpinBox::maxPrecision() const { | 979 | int KDoubleSpinBox::maxPrecision() const { |
977 | // INT_MAX must be > maxAbsValue * 10^precision | 980 | // INT_MAX must be > maxAbsValue * 10^precision |
978 | // ==> 10^precision < INT_MAX / maxAbsValue | 981 | // ==> 10^precision < INT_MAX / maxAbsValue |
979 | // ==> precision < log10 ( INT_MAX / maxAbsValue ) | 982 | // ==> precision < log10 ( INT_MAX / maxAbsValue ) |
980 | // ==> maxPrecision = floor( log10 ( INT_MAX / maxAbsValue ) ); | 983 | // ==> maxPrecision = floor( log10 ( INT_MAX / maxAbsValue ) ); |
981 | double maxAbsValue = kMax( fabs(minValue()), fabs(maxValue()) ); | 984 | double maxAbsValue = kMax( fabs(minValue()), fabs(maxValue()) ); |
982 | if ( maxAbsValue == 0 ) return 6; // return arbitrary value to avoid dbz... | 985 | if ( maxAbsValue == 0 ) return 6; // return arbitrary value to avoid dbz... |
983 | 986 | ||
984 | return int( floor( log10( double(INT_MAX) / maxAbsValue ) ) ); | 987 | return int( floor( log10( double(INT_MAX) / maxAbsValue ) ) ); |
985 | } | 988 | } |
986 | 989 | ||
987 | double KDoubleSpinBox::value() const { | 990 | double KDoubleSpinBox::value() const { |
988 | return d->mapToDouble( base::value() ); | 991 | return d->mapToDouble( base::value() ); |
989 | } | 992 | } |
990 | 993 | ||
991 | void KDoubleSpinBox::setValue( double value ) { | 994 | void KDoubleSpinBox::setValue( double value ) { |
992 | if ( value == this->value() ) return; | 995 | if ( value == this->value() ) return; |
993 | if ( value < minValue() ) | 996 | if ( value < minValue() ) |
994 | base::setValue( base::minValue() ); | 997 | base::setValue( base::minValue() ); |
995 | else if ( value > maxValue() ) | 998 | else if ( value > maxValue() ) |
996 | base::setValue( base::maxValue() ); | 999 | base::setValue( base::maxValue() ); |
997 | else { | 1000 | else { |
998 | bool ok = false; | 1001 | bool ok = false; |
999 | base::setValue( d->mapToInt( value, &ok ) ); | 1002 | base::setValue( d->mapToInt( value, &ok ) ); |
1000 | assert( ok ); | 1003 | assert( ok ); |
1001 | } | 1004 | } |
1002 | } | 1005 | } |
1003 | 1006 | ||
1004 | double KDoubleSpinBox::minValue() const { | 1007 | double KDoubleSpinBox::minValue() const { |
1005 | return d->mapToDouble( base::minValue() ); | 1008 | return d->mapToDouble( base::minValue() ); |
1006 | } | 1009 | } |
1007 | 1010 | ||
1008 | void KDoubleSpinBox::setMinValue( double value ) { | 1011 | void KDoubleSpinBox::setMinValue( double value ) { |
1009 | bool ok = false; | 1012 | bool ok = false; |
1010 | int min = d->mapToInt( value, &ok ); | 1013 | int min = d->mapToInt( value, &ok ); |
1011 | if ( !ok ) return; | 1014 | if ( !ok ) return; |
1012 | base::setMinValue( min ); | 1015 | base::setMinValue( min ); |
1013 | updateValidator(); | 1016 | updateValidator(); |
1014 | } | 1017 | } |
1015 | 1018 | ||
1016 | 1019 | ||
1017 | double KDoubleSpinBox::maxValue() const { | 1020 | double KDoubleSpinBox::maxValue() const { |
1018 | return d->mapToDouble( base::maxValue() ); | 1021 | return d->mapToDouble( base::maxValue() ); |
1019 | } | 1022 | } |
1020 | 1023 | ||
1021 | void KDoubleSpinBox::setMaxValue( double value ) { | 1024 | void KDoubleSpinBox::setMaxValue( double value ) { |
1022 | bool ok = false; | 1025 | bool ok = false; |
1023 | int max = d->mapToInt( value, &ok ); | 1026 | int max = d->mapToInt( value, &ok ); |
1024 | if ( !ok ) return; | 1027 | if ( !ok ) return; |
1025 | base::setMaxValue( max ); | 1028 | base::setMaxValue( max ); |
1026 | updateValidator(); | 1029 | updateValidator(); |
1027 | } | 1030 | } |
1028 | 1031 | ||
1029 | double KDoubleSpinBox::lineStep() const { | 1032 | double KDoubleSpinBox::lineStep() const { |
1030 | return d->mapToDouble( base::lineStep() ); | 1033 | return d->mapToDouble( base::singleStep() ); |
1031 | } | 1034 | } |
1032 | 1035 | ||
1033 | void KDoubleSpinBox::setLineStep( double step ) { | 1036 | void KDoubleSpinBox::setLineStep( double step ) { |
1034 | bool ok = false; | 1037 | bool ok = false; |
1035 | if ( step > maxValue() - minValue() ) | 1038 | if ( step > maxValue() - minValue() ) |
1036 | base::setLineStep( 1 ); | 1039 | base::setLineStep( 1 ); |
1037 | else | 1040 | else |
1038 | base::setLineStep( kMax( d->mapToInt( step, &ok ), 1 ) ); | 1041 | base::setLineStep( kMax( d->mapToInt( step, &ok ), 1 ) ); |
1039 | } | 1042 | } |
1040 | 1043 | ||
1041 | QString KDoubleSpinBox::mapValueToText( int value ) { | 1044 | QString KDoubleSpinBox::mapValueToText( int value ) { |
1042 | if ( acceptLocalizedNumbers() ) | 1045 | if ( acceptLocalizedNumbers() ) |
1043 | return KGlobal::locale() | 1046 | return KGlobal::locale() |
1044 | ->formatNumber( d->mapToDouble( value ), d->mPrecision ); | 1047 | ->formatNumber( d->mapToDouble( value ), d->mPrecision ); |
1045 | else | 1048 | else |
1046 | return QString().setNum( d->mapToDouble( value ), 'f', d->mPrecision ); | 1049 | return QString().setNum( d->mapToDouble( value ), 'f', d->mPrecision ); |
1047 | } | 1050 | } |
1048 | 1051 | ||
1049 | int KDoubleSpinBox::mapTextToValue( bool * ok ) { | 1052 | int KDoubleSpinBox::mapTextToValue( bool * ok ) { |
1050 | double value; | 1053 | double value; |
1051 | if ( acceptLocalizedNumbers() ) | 1054 | if ( acceptLocalizedNumbers() ) |
1052 | value = KGlobal::locale()->readNumber( cleanText(), ok ); | 1055 | value = KGlobal::locale()->readNumber( cleanText(), ok ); |
1053 | else | 1056 | else |
1054 | value = cleanText().toDouble( ok ); | 1057 | value = cleanText().toDouble( ok ); |
1055 | if ( !*ok ) return 0; | 1058 | if ( !*ok ) return 0; |
1056 | if ( value > maxValue() ) | 1059 | if ( value > maxValue() ) |
1057 | value = maxValue(); | 1060 | value = maxValue(); |
1058 | else if ( value < minValue() ) | 1061 | else if ( value < minValue() ) |
1059 | value = minValue(); | 1062 | value = minValue(); |
1060 | return d->mapToInt( value, ok ); | 1063 | return d->mapToInt( value, ok ); |
1061 | } | 1064 | } |
1062 | 1065 | ||
1063 | void KDoubleSpinBox::setValidator( const QValidator * ) { | 1066 | void KDoubleSpinBox::setValidator( const QValidator * ) { |
1064 | // silently discard the new validator. We don't want another one ;-) | 1067 | // silently discard the new validator. We don't want another one ;-) |
1065 | } | 1068 | } |
1066 | 1069 | ||
1067 | void KDoubleSpinBox::slotValueChanged( int value ) { | 1070 | void KDoubleSpinBox::slotValueChanged( int value ) { |
1068 | emit valueChanged( d->mapToDouble( value ) ); | 1071 | emit valueChanged( d->mapToDouble( value ) ); |
1069 | } | 1072 | } |
1070 | 1073 | ||
1071 | void KDoubleSpinBox::updateValidator() { | 1074 | void KDoubleSpinBox::updateValidator() { |
1072 | if ( !d->mValidator ) { | 1075 | if ( !d->mValidator ) { |
1073 | d->mValidator = new KDoubleValidator( minValue(), maxValue(), precision(), | 1076 | d->mValidator = new KDoubleValidator( minValue(), maxValue(), precision(), |
1074 | this, "d->mValidator" ); | 1077 | this, "d->mValidator" ); |
1075 | base::setValidator( d->mValidator ); | 1078 | lineEdit()->setValidator( d->mValidator ); |
1076 | } else | 1079 | } else |
1077 | d->mValidator->setRange( minValue(), maxValue(), precision() ); | 1080 | d->mValidator->setRange( minValue(), maxValue(), precision() ); |
1078 | } | 1081 | } |
1079 | 1082 | ||
1080 | void KNumInput::virtual_hook( int, void* ) | 1083 | void KNumInput::virtual_hook( int, void* ) |
1081 | { /*BASE::virtual_hook( id, data );*/ } | 1084 | { /*BASE::virtual_hook( id, data );*/ } |
1082 | 1085 | ||
1083 | void KIntNumInput::virtual_hook( int id, void* data ) | 1086 | void KIntNumInput::virtual_hook( int id, void* data ) |
1084 | { KNumInput::virtual_hook( id, data ); } | 1087 | { KNumInput::virtual_hook( id, data ); } |
1085 | 1088 | ||
1086 | void KDoubleNumInput::virtual_hook( int id, void* data ) | 1089 | void KDoubleNumInput::virtual_hook( int id, void* data ) |
1087 | { KNumInput::virtual_hook( id, data ); } | 1090 | { KNumInput::virtual_hook( id, data ); } |
1088 | 1091 | ||
1089 | void KIntSpinBox::virtual_hook( int, void* ) | 1092 | void KIntSpinBox::virtual_hook( int, void* ) |
1090 | { /*BASE::virtual_hook( id, data );*/ } | 1093 | { /*BASE::virtual_hook( id, data );*/ } |
1091 | 1094 | ||
1092 | void KDoubleSpinBox::virtual_hook( int, void* ) | 1095 | void KDoubleSpinBox::virtual_hook( int, void* ) |
1093 | { /*BASE::virtual_hook( id, data );*/ } | 1096 | { /*BASE::virtual_hook( id, data );*/ } |
1094 | 1097 | ||
1095 | //US #include "knuminput.moc" | 1098 | //US #include "knuminput.moc" |