0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "qlcdnumber.h"
|
|
43 |
#ifndef QT_NO_LCDNUMBER
|
|
44 |
#include "qbitarray.h"
|
|
45 |
#include "qpainter.h"
|
|
46 |
#include "private/qframe_p.h"
|
|
47 |
|
|
48 |
QT_BEGIN_NAMESPACE
|
|
49 |
|
|
50 |
class QLCDNumberPrivate : public QFramePrivate
|
|
51 |
{
|
|
52 |
Q_DECLARE_PUBLIC(QLCDNumber)
|
|
53 |
public:
|
|
54 |
void init();
|
|
55 |
void internalSetString(const QString& s);
|
|
56 |
void drawString(const QString& s, QPainter &, QBitArray * = 0, bool = true);
|
|
57 |
//void drawString(const QString &, QPainter &, QBitArray * = 0) const;
|
|
58 |
void drawDigit(const QPoint &, QPainter &, int, char, char = ' ');
|
|
59 |
void drawSegment(const QPoint &, char, QPainter &, int, bool = false);
|
|
60 |
|
|
61 |
int ndigits;
|
|
62 |
double val;
|
|
63 |
uint base : 2;
|
|
64 |
uint smallPoint : 1;
|
|
65 |
uint fill : 1;
|
|
66 |
uint shadow : 1;
|
|
67 |
QString digitStr;
|
|
68 |
QBitArray points;
|
|
69 |
};
|
|
70 |
|
|
71 |
/*!
|
|
72 |
\class QLCDNumber
|
|
73 |
|
|
74 |
\brief The QLCDNumber widget displays a number with LCD-like digits.
|
|
75 |
|
|
76 |
\ingroup basicwidgets
|
|
77 |
|
|
78 |
|
|
79 |
It can display a number in just about any size. It can display
|
|
80 |
decimal, hexadecimal, octal or binary numbers. It is easy to
|
|
81 |
connect to data sources using the display() slot, which is
|
|
82 |
overloaded to take any of five argument types.
|
|
83 |
|
|
84 |
There are also slots to change the base with setMode() and the
|
|
85 |
decimal point with setSmallDecimalPoint().
|
|
86 |
|
|
87 |
QLCDNumber emits the overflow() signal when it is asked to display
|
|
88 |
something beyond its range. The range is set by setNumDigits(),
|
|
89 |
but setSmallDecimalPoint() also influences it. If the display is
|
|
90 |
set to hexadecimal, octal or binary, the integer equivalent of the
|
|
91 |
value is displayed.
|
|
92 |
|
|
93 |
These digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S,
|
|
94 |
6, 7, 8, 9/g, minus, decimal point, A, B, C, D, E, F, h, H, L, o,
|
|
95 |
P, r, u, U, Y, colon, degree sign (which is specified as single
|
|
96 |
quote in the string) and space. QLCDNumber substitutes spaces for
|
|
97 |
illegal characters.
|
|
98 |
|
|
99 |
It is not possible to retrieve the contents of a QLCDNumber
|
|
100 |
object, although you can retrieve the numeric value with value().
|
|
101 |
If you really need the text, we recommend that you connect the
|
|
102 |
signals that feed the display() slot to another slot as well and
|
|
103 |
store the value there.
|
|
104 |
|
|
105 |
Incidentally, QLCDNumber is the very oldest part of Qt, tracing
|
|
106 |
its roots back to a BASIC program on the \link
|
|
107 |
http://www.nvg.ntnu.no/sinclair/computers/zxspectrum/zxspectrum.htm
|
|
108 |
Sinclair Spectrum\endlink.
|
|
109 |
|
|
110 |
\table
|
|
111 |
\row \o \inlineimage motif-lcdnumber.png Screenshot of a Motif style LCD number widget
|
|
112 |
\inlineimage cde-lcdnumber.png Screenshot of a CDE style LCD number widget
|
|
113 |
\inlineimage windows-lcdnumber.png Screenshot of a Windows style LCD number widget
|
|
114 |
\inlineimage windowsxp-lcdnumber.png Screenshot of a Windows XP style LCD number widget
|
|
115 |
\inlineimage macintosh-lcdnumber.png Screenshot of a Macintosh style LCD number widget
|
|
116 |
\inlineimage plastique-lcdnumber.png Screenshot of a Plastique style LCD number widget
|
|
117 |
\row \o LCD number widgets shown in various widget styles (from left to right):
|
|
118 |
\l{Motif Style Widget Gallery}{Motif}, \l{CDE Style Widget Gallery}{CDE},
|
|
119 |
\l{Windows Style Widget Gallery}{Windows}, \l{Windows XP Style Widget Gallery}{Windows XP},
|
|
120 |
\l{Macintosh Style Widget Gallery}{Macintosh}, \l{Plastique Style Widget Gallery}{Plastique}.
|
|
121 |
\endtable
|
|
122 |
|
|
123 |
\sa QLabel, QFrame, {Digital Clock Example}, {Tetrix Example}
|
|
124 |
*/
|
|
125 |
|
|
126 |
/*!
|
|
127 |
\enum QLCDNumber::Mode
|
|
128 |
|
|
129 |
This type determines how numbers are shown.
|
|
130 |
|
|
131 |
\value Hex Hexadecimal
|
|
132 |
\value Dec Decimal
|
|
133 |
\value Oct Octal
|
|
134 |
\value Bin Binary
|
|
135 |
\omitvalue HEX
|
|
136 |
\omitvalue DEC
|
|
137 |
\omitvalue OCT
|
|
138 |
\omitvalue BIN
|
|
139 |
|
|
140 |
If the display is set to hexadecimal, octal or binary, the integer
|
|
141 |
equivalent of the value is displayed.
|
|
142 |
*/
|
|
143 |
|
|
144 |
/*!
|
|
145 |
\enum QLCDNumber::SegmentStyle
|
|
146 |
|
|
147 |
This type determines the visual appearance of the QLCDNumber
|
|
148 |
widget.
|
|
149 |
|
|
150 |
\value Outline gives raised segments filled with the background color.
|
|
151 |
\value Filled gives raised segments filled with the windowText color.
|
|
152 |
\value Flat gives flat segments filled with the windowText color.
|
|
153 |
*/
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
/*!
|
|
158 |
\fn void QLCDNumber::overflow()
|
|
159 |
|
|
160 |
This signal is emitted whenever the QLCDNumber is asked to display
|
|
161 |
a too-large number or a too-long string.
|
|
162 |
|
|
163 |
It is never emitted by setNumDigits().
|
|
164 |
*/
|
|
165 |
|
|
166 |
|
|
167 |
static QString int2string(int num, int base, int ndigits, bool *oflow)
|
|
168 |
{
|
|
169 |
QString s;
|
|
170 |
bool negative;
|
|
171 |
if (num < 0) {
|
|
172 |
negative = true;
|
|
173 |
num = -num;
|
|
174 |
} else {
|
|
175 |
negative = false;
|
|
176 |
}
|
|
177 |
switch(base) {
|
|
178 |
case QLCDNumber::Hex:
|
|
179 |
s.sprintf("%*x", ndigits, num);
|
|
180 |
break;
|
|
181 |
case QLCDNumber::Dec:
|
|
182 |
s.sprintf("%*i", ndigits, num);
|
|
183 |
break;
|
|
184 |
case QLCDNumber::Oct:
|
|
185 |
s.sprintf("%*o", ndigits, num);
|
|
186 |
break;
|
|
187 |
case QLCDNumber::Bin:
|
|
188 |
{
|
|
189 |
char buf[42];
|
|
190 |
char *p = &buf[41];
|
|
191 |
uint n = num;
|
|
192 |
int len = 0;
|
|
193 |
*p = '\0';
|
|
194 |
do {
|
|
195 |
*--p = (char)((n&1)+'0');
|
|
196 |
n >>= 1;
|
|
197 |
len++;
|
|
198 |
} while (n != 0);
|
|
199 |
len = ndigits - len;
|
|
200 |
if (len > 0)
|
|
201 |
s.fill(QLatin1Char(' '), len);
|
|
202 |
s += QString::fromLatin1(p);
|
|
203 |
}
|
|
204 |
break;
|
|
205 |
}
|
|
206 |
if (negative) {
|
|
207 |
for (int i=0; i<(int)s.length(); i++) {
|
|
208 |
if (s[i] != QLatin1Char(' ')) {
|
|
209 |
if (i != 0) {
|
|
210 |
s[i-1] = QLatin1Char('-');
|
|
211 |
} else {
|
|
212 |
s.insert(0, QLatin1Char('-'));
|
|
213 |
}
|
|
214 |
break;
|
|
215 |
}
|
|
216 |
}
|
|
217 |
}
|
|
218 |
if (oflow)
|
|
219 |
*oflow = (int)s.length() > ndigits;
|
|
220 |
return s;
|
|
221 |
}
|
|
222 |
|
|
223 |
|
|
224 |
static QString double2string(double num, int base, int ndigits, bool *oflow)
|
|
225 |
{
|
|
226 |
QString s;
|
|
227 |
if (base != QLCDNumber::Dec) {
|
|
228 |
bool of = num >= 2147483648.0 || num < -2147483648.0;
|
|
229 |
if (of) { // oops, integer overflow
|
|
230 |
if (oflow)
|
|
231 |
*oflow = true;
|
|
232 |
return s;
|
|
233 |
}
|
|
234 |
s = int2string((int)num, base, ndigits, 0);
|
|
235 |
} else { // decimal base
|
|
236 |
int nd = ndigits;
|
|
237 |
do {
|
|
238 |
s.sprintf("%*.*g", ndigits, nd, num);
|
|
239 |
int i = s.indexOf(QLatin1Char('e'));
|
|
240 |
if (i > 0 && s[i+1]==QLatin1Char('+')) {
|
|
241 |
s[i] = QLatin1Char(' ');
|
|
242 |
s[i+1] = QLatin1Char('e');
|
|
243 |
}
|
|
244 |
} while (nd-- && (int)s.length() > ndigits);
|
|
245 |
}
|
|
246 |
if (oflow)
|
|
247 |
*oflow = (int)s.length() > ndigits;
|
|
248 |
return s;
|
|
249 |
}
|
|
250 |
|
|
251 |
|
|
252 |
static const char *getSegments(char ch) // gets list of segments for ch
|
|
253 |
{
|
|
254 |
static const char segments[30][8] =
|
|
255 |
{ { 0, 1, 2, 4, 5, 6,99, 0}, // 0 0 / O
|
|
256 |
{ 2, 5,99, 0, 0, 0, 0, 0}, // 1 1
|
|
257 |
{ 0, 2, 3, 4, 6,99, 0, 0}, // 2 2
|
|
258 |
{ 0, 2, 3, 5, 6,99, 0, 0}, // 3 3
|
|
259 |
{ 1, 2, 3, 5,99, 0, 0, 0}, // 4 4
|
|
260 |
{ 0, 1, 3, 5, 6,99, 0, 0}, // 5 5 / S
|
|
261 |
{ 0, 1, 3, 4, 5, 6,99, 0}, // 6 6
|
|
262 |
{ 0, 2, 5,99, 0, 0, 0, 0}, // 7 7
|
|
263 |
{ 0, 1, 2, 3, 4, 5, 6,99}, // 8 8
|
|
264 |
{ 0, 1, 2, 3, 5, 6,99, 0}, // 9 9 / g
|
|
265 |
{ 3,99, 0, 0, 0, 0, 0, 0}, // 10 -
|
|
266 |
{ 7,99, 0, 0, 0, 0, 0, 0}, // 11 .
|
|
267 |
{ 0, 1, 2, 3, 4, 5,99, 0}, // 12 A
|
|
268 |
{ 1, 3, 4, 5, 6,99, 0, 0}, // 13 B
|
|
269 |
{ 0, 1, 4, 6,99, 0, 0, 0}, // 14 C
|
|
270 |
{ 2, 3, 4, 5, 6,99, 0, 0}, // 15 D
|
|
271 |
{ 0, 1, 3, 4, 6,99, 0, 0}, // 16 E
|
|
272 |
{ 0, 1, 3, 4,99, 0, 0, 0}, // 17 F
|
|
273 |
{ 1, 3, 4, 5,99, 0, 0, 0}, // 18 h
|
|
274 |
{ 1, 2, 3, 4, 5,99, 0, 0}, // 19 H
|
|
275 |
{ 1, 4, 6,99, 0, 0, 0, 0}, // 20 L
|
|
276 |
{ 3, 4, 5, 6,99, 0, 0, 0}, // 21 o
|
|
277 |
{ 0, 1, 2, 3, 4,99, 0, 0}, // 22 P
|
|
278 |
{ 3, 4,99, 0, 0, 0, 0, 0}, // 23 r
|
|
279 |
{ 4, 5, 6,99, 0, 0, 0, 0}, // 24 u
|
|
280 |
{ 1, 2, 4, 5, 6,99, 0, 0}, // 25 U
|
|
281 |
{ 1, 2, 3, 5, 6,99, 0, 0}, // 26 Y
|
|
282 |
{ 8, 9,99, 0, 0, 0, 0, 0}, // 27 :
|
|
283 |
{ 0, 1, 2, 3,99, 0, 0, 0}, // 28 '
|
|
284 |
{99, 0, 0, 0, 0, 0, 0, 0} }; // 29 empty
|
|
285 |
|
|
286 |
if (ch >= '0' && ch <= '9')
|
|
287 |
return segments[ch - '0'];
|
|
288 |
if (ch >= 'A' && ch <= 'F')
|
|
289 |
return segments[ch - 'A' + 12];
|
|
290 |
if (ch >= 'a' && ch <= 'f')
|
|
291 |
return segments[ch - 'a' + 12];
|
|
292 |
|
|
293 |
int n;
|
|
294 |
switch (ch) {
|
|
295 |
case '-':
|
|
296 |
n = 10; break;
|
|
297 |
case 'O':
|
|
298 |
n = 0; break;
|
|
299 |
case 'g':
|
|
300 |
n = 9; break;
|
|
301 |
case '.':
|
|
302 |
n = 11; break;
|
|
303 |
case 'h':
|
|
304 |
n = 18; break;
|
|
305 |
case 'H':
|
|
306 |
n = 19; break;
|
|
307 |
case 'l':
|
|
308 |
case 'L':
|
|
309 |
n = 20; break;
|
|
310 |
case 'o':
|
|
311 |
n = 21; break;
|
|
312 |
case 'p':
|
|
313 |
case 'P':
|
|
314 |
n = 22; break;
|
|
315 |
case 'r':
|
|
316 |
case 'R':
|
|
317 |
n = 23; break;
|
|
318 |
case 's':
|
|
319 |
case 'S':
|
|
320 |
n = 5; break;
|
|
321 |
case 'u':
|
|
322 |
n = 24; break;
|
|
323 |
case 'U':
|
|
324 |
n = 25; break;
|
|
325 |
case 'y':
|
|
326 |
case 'Y':
|
|
327 |
n = 26; break;
|
|
328 |
case ':':
|
|
329 |
n = 27; break;
|
|
330 |
case '\'':
|
|
331 |
n = 28; break;
|
|
332 |
default:
|
|
333 |
n = 29; break;
|
|
334 |
}
|
|
335 |
return segments[n];
|
|
336 |
}
|
|
337 |
|
|
338 |
|
|
339 |
#ifdef QT3_SUPPORT
|
|
340 |
/*! \obsolete
|
|
341 |
Constructs an LCD number, sets the number of digits to 5, the base
|
|
342 |
to decimal, the decimal point mode to 'small' and the frame style
|
|
343 |
to a raised box. The segmentStyle() is set to \c Outline.
|
|
344 |
|
|
345 |
The \a parent and \a name arguments are passed to the QFrame
|
|
346 |
constructor.
|
|
347 |
|
|
348 |
\sa setNumDigits(), setSmallDecimalPoint()
|
|
349 |
*/
|
|
350 |
|
|
351 |
QLCDNumber::QLCDNumber(QWidget *parent, const char *name)
|
|
352 |
: QFrame(*new QLCDNumberPrivate, parent)
|
|
353 |
{
|
|
354 |
setObjectName(QString::fromAscii(name));
|
|
355 |
Q_D(QLCDNumber);
|
|
356 |
d->ndigits = 5;
|
|
357 |
d->init();
|
|
358 |
}
|
|
359 |
|
|
360 |
|
|
361 |
/*! \obsolete
|
|
362 |
Constructs an LCD number, sets the number of digits to \a
|
|
363 |
numDigits, the base to decimal, the decimal point mode to 'small'
|
|
364 |
and the frame style to a raised box. The segmentStyle() is set to
|
|
365 |
\c Outline.
|
|
366 |
|
|
367 |
The \a parent and \a name arguments are passed to the QFrame
|
|
368 |
constructor.
|
|
369 |
|
|
370 |
\sa setNumDigits(), setSmallDecimalPoint()
|
|
371 |
*/
|
|
372 |
|
|
373 |
QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent, const char *name)
|
|
374 |
: QFrame(*new QLCDNumberPrivate, parent)
|
|
375 |
{
|
|
376 |
setObjectName(QString::fromAscii(name));
|
|
377 |
Q_D(QLCDNumber);
|
|
378 |
d->ndigits = numDigits;
|
|
379 |
d->init();
|
|
380 |
}
|
|
381 |
#endif //QT3_SUPPORT
|
|
382 |
|
|
383 |
/*!
|
|
384 |
Constructs an LCD number, sets the number of digits to 5, the base
|
|
385 |
to decimal, the decimal point mode to 'small' and the frame style
|
|
386 |
to a raised box. The segmentStyle() is set to \c Outline.
|
|
387 |
|
|
388 |
The \a parent argument is passed to the QFrame constructor.
|
|
389 |
|
|
390 |
\sa setNumDigits(), setSmallDecimalPoint()
|
|
391 |
*/
|
|
392 |
|
|
393 |
QLCDNumber::QLCDNumber(QWidget *parent)
|
|
394 |
: QFrame(*new QLCDNumberPrivate, parent)
|
|
395 |
{
|
|
396 |
Q_D(QLCDNumber);
|
|
397 |
d->ndigits = 5;
|
|
398 |
d->init();
|
|
399 |
}
|
|
400 |
|
|
401 |
|
|
402 |
/*!
|
|
403 |
Constructs an LCD number, sets the number of digits to \a
|
|
404 |
numDigits, the base to decimal, the decimal point mode to 'small'
|
|
405 |
and the frame style to a raised box. The segmentStyle() is set to
|
|
406 |
\c Filled.
|
|
407 |
|
|
408 |
The \a parent argument is passed to the QFrame constructor.
|
|
409 |
|
|
410 |
\sa setNumDigits(), setSmallDecimalPoint()
|
|
411 |
*/
|
|
412 |
|
|
413 |
QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent)
|
|
414 |
: QFrame(*new QLCDNumberPrivate, parent)
|
|
415 |
{
|
|
416 |
Q_D(QLCDNumber);
|
|
417 |
d->ndigits = numDigits;
|
|
418 |
d->init();
|
|
419 |
}
|
|
420 |
|
|
421 |
void QLCDNumberPrivate::init()
|
|
422 |
{
|
|
423 |
Q_Q(QLCDNumber);
|
|
424 |
|
|
425 |
q->setFrameStyle(QFrame::Box | QFrame::Raised);
|
|
426 |
val = 0;
|
|
427 |
base = QLCDNumber::Dec;
|
|
428 |
smallPoint = false;
|
|
429 |
q->setNumDigits(ndigits);
|
|
430 |
q->setSegmentStyle(QLCDNumber::Filled);
|
|
431 |
q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
|
|
432 |
}
|
|
433 |
|
|
434 |
/*!
|
|
435 |
Destroys the LCD number.
|
|
436 |
*/
|
|
437 |
|
|
438 |
QLCDNumber::~QLCDNumber()
|
|
439 |
{
|
|
440 |
}
|
|
441 |
|
|
442 |
|
|
443 |
/*!
|
|
444 |
\property QLCDNumber::numDigits
|
|
445 |
\brief the current number of digits displayed
|
|
446 |
|
|
447 |
Corresponds to the current number of digits. If \l
|
|
448 |
QLCDNumber::smallDecimalPoint is false, the decimal point occupies
|
|
449 |
one digit position.
|
|
450 |
|
|
451 |
By default, this property contains a value of 5.
|
|
452 |
|
|
453 |
\sa smallDecimalPoint
|
|
454 |
*/
|
|
455 |
|
|
456 |
void QLCDNumber::setNumDigits(int numDigits)
|
|
457 |
{
|
|
458 |
Q_D(QLCDNumber);
|
|
459 |
if (numDigits > 99) {
|
|
460 |
qWarning("QLCDNumber::setNumDigits: (%s) Max 99 digits allowed",
|
|
461 |
objectName().toLocal8Bit().constData());
|
|
462 |
numDigits = 99;
|
|
463 |
}
|
|
464 |
if (numDigits < 0) {
|
|
465 |
qWarning("QLCDNumber::setNumDigits: (%s) Min 0 digits allowed",
|
|
466 |
objectName().toLocal8Bit().constData());
|
|
467 |
numDigits = 0;
|
|
468 |
}
|
|
469 |
if (d->digitStr.isNull()) { // from constructor
|
|
470 |
d->ndigits = numDigits;
|
|
471 |
d->digitStr.fill(QLatin1Char(' '), d->ndigits);
|
|
472 |
d->points.fill(0, d->ndigits);
|
|
473 |
d->digitStr[d->ndigits - 1] = QLatin1Char('0'); // "0" is the default number
|
|
474 |
} else {
|
|
475 |
bool doDisplay = d->ndigits == 0;
|
|
476 |
if (numDigits == d->ndigits) // no change
|
|
477 |
return;
|
|
478 |
register int i;
|
|
479 |
int dif;
|
|
480 |
if (numDigits > d->ndigits) { // expand
|
|
481 |
dif = numDigits - d->ndigits;
|
|
482 |
QString buf;
|
|
483 |
buf.fill(QLatin1Char(' '), dif);
|
|
484 |
d->digitStr.insert(0, buf);
|
|
485 |
d->points.resize(numDigits);
|
|
486 |
for (i=numDigits-1; i>=dif; i--)
|
|
487 |
d->points.setBit(i, d->points.testBit(i-dif));
|
|
488 |
for (i=0; i<dif; i++)
|
|
489 |
d->points.clearBit(i);
|
|
490 |
} else { // shrink
|
|
491 |
dif = d->ndigits - numDigits;
|
|
492 |
d->digitStr = d->digitStr.right(numDigits);
|
|
493 |
QBitArray tmpPoints = d->points;
|
|
494 |
d->points.resize(numDigits);
|
|
495 |
for (i=0; i<(int)numDigits; i++)
|
|
496 |
d->points.setBit(i, tmpPoints.testBit(i+dif));
|
|
497 |
}
|
|
498 |
d->ndigits = numDigits;
|
|
499 |
if (doDisplay)
|
|
500 |
display(value());
|
|
501 |
update();
|
|
502 |
}
|
|
503 |
}
|
|
504 |
|
|
505 |
int QLCDNumber::numDigits() const
|
|
506 |
{
|
|
507 |
Q_D(const QLCDNumber);
|
|
508 |
return d->ndigits;
|
|
509 |
}
|
|
510 |
|
|
511 |
/*!
|
|
512 |
\overload
|
|
513 |
|
|
514 |
Returns true if \a num is too big to be displayed in its entirety;
|
|
515 |
otherwise returns false.
|
|
516 |
|
|
517 |
\sa display(), numDigits(), smallDecimalPoint()
|
|
518 |
*/
|
|
519 |
|
|
520 |
bool QLCDNumber::checkOverflow(int num) const
|
|
521 |
{
|
|
522 |
Q_D(const QLCDNumber);
|
|
523 |
bool of;
|
|
524 |
int2string(num, d->base, d->ndigits, &of);
|
|
525 |
return of;
|
|
526 |
}
|
|
527 |
|
|
528 |
|
|
529 |
/*!
|
|
530 |
Returns true if \a num is too big to be displayed in its entirety;
|
|
531 |
otherwise returns false.
|
|
532 |
|
|
533 |
\sa display(), numDigits(), smallDecimalPoint()
|
|
534 |
*/
|
|
535 |
|
|
536 |
bool QLCDNumber::checkOverflow(double num) const
|
|
537 |
{
|
|
538 |
Q_D(const QLCDNumber);
|
|
539 |
bool of;
|
|
540 |
double2string(num, d->base, d->ndigits, &of);
|
|
541 |
return of;
|
|
542 |
}
|
|
543 |
|
|
544 |
|
|
545 |
/*!
|
|
546 |
\property QLCDNumber::mode
|
|
547 |
\brief the current display mode (number base)
|
|
548 |
|
|
549 |
Corresponds to the current display mode, which is one of \c Bin,
|
|
550 |
\c Oct, \c Dec (the default) and \c Hex. \c Dec mode can display
|
|
551 |
floating point values, the other modes display the integer
|
|
552 |
equivalent.
|
|
553 |
|
|
554 |
\sa smallDecimalPoint(), setHexMode(), setDecMode(), setOctMode(), setBinMode()
|
|
555 |
*/
|
|
556 |
|
|
557 |
QLCDNumber::Mode QLCDNumber::mode() const
|
|
558 |
{
|
|
559 |
Q_D(const QLCDNumber);
|
|
560 |
return (QLCDNumber::Mode) d->base;
|
|
561 |
}
|
|
562 |
|
|
563 |
void QLCDNumber::setMode(Mode m)
|
|
564 |
{
|
|
565 |
Q_D(QLCDNumber);
|
|
566 |
d->base = m;
|
|
567 |
display(d->val);
|
|
568 |
}
|
|
569 |
|
|
570 |
|
|
571 |
/*!
|
|
572 |
\property QLCDNumber::value
|
|
573 |
\brief the displayed value
|
|
574 |
|
|
575 |
This property corresponds to the current value displayed by the
|
|
576 |
LCDNumber.
|
|
577 |
|
|
578 |
If the displayed value is not a number, the property has a value
|
|
579 |
of 0.
|
|
580 |
|
|
581 |
By default, this property contains a value of 0.
|
|
582 |
*/
|
|
583 |
|
|
584 |
double QLCDNumber::value() const
|
|
585 |
{
|
|
586 |
Q_D(const QLCDNumber);
|
|
587 |
return d->val;
|
|
588 |
}
|
|
589 |
|
|
590 |
/*!
|
|
591 |
\overload
|
|
592 |
|
|
593 |
Displays the number \a num.
|
|
594 |
*/
|
|
595 |
void QLCDNumber::display(double num)
|
|
596 |
{
|
|
597 |
Q_D(QLCDNumber);
|
|
598 |
d->val = num;
|
|
599 |
bool of;
|
|
600 |
QString s = double2string(d->val, d->base, d->ndigits, &of);
|
|
601 |
if (of)
|
|
602 |
emit overflow();
|
|
603 |
else
|
|
604 |
d->internalSetString(s);
|
|
605 |
}
|
|
606 |
|
|
607 |
/*!
|
|
608 |
\property QLCDNumber::intValue
|
|
609 |
\brief the displayed value rounded to the nearest integer
|
|
610 |
|
|
611 |
This property corresponds to the nearest integer to the current
|
|
612 |
value displayed by the LCDNumber. This is the value used for
|
|
613 |
hexadecimal, octal and binary modes.
|
|
614 |
|
|
615 |
If the displayed value is not a number, the property has a value
|
|
616 |
of 0.
|
|
617 |
|
|
618 |
By default, this property contains a value of 0.
|
|
619 |
*/
|
|
620 |
int QLCDNumber::intValue() const
|
|
621 |
{
|
|
622 |
Q_D(const QLCDNumber);
|
|
623 |
return qRound(d->val);
|
|
624 |
}
|
|
625 |
|
|
626 |
|
|
627 |
/*!
|
|
628 |
\overload
|
|
629 |
|
|
630 |
Displays the number \a num.
|
|
631 |
*/
|
|
632 |
void QLCDNumber::display(int num)
|
|
633 |
{
|
|
634 |
Q_D(QLCDNumber);
|
|
635 |
d->val = (double)num;
|
|
636 |
bool of;
|
|
637 |
QString s = int2string(num, d->base, d->ndigits, &of);
|
|
638 |
if (of)
|
|
639 |
emit overflow();
|
|
640 |
else
|
|
641 |
d->internalSetString(s);
|
|
642 |
}
|
|
643 |
|
|
644 |
|
|
645 |
/*!
|
|
646 |
Displays the number represented by the string \a s.
|
|
647 |
|
|
648 |
This version of the function disregards mode() and
|
|
649 |
smallDecimalPoint().
|
|
650 |
|
|
651 |
These digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S,
|
|
652 |
6, 7, 8, 9/g, minus, decimal point, A, B, C, D, E, F, h, H, L, o,
|
|
653 |
P, r, u, U, Y, colon, degree sign (which is specified as single
|
|
654 |
quote in the string) and space. QLCDNumber substitutes spaces for
|
|
655 |
illegal characters.
|
|
656 |
*/
|
|
657 |
|
|
658 |
void QLCDNumber::display(const QString &s)
|
|
659 |
{
|
|
660 |
Q_D(QLCDNumber);
|
|
661 |
d->val = 0;
|
|
662 |
bool ok = false;
|
|
663 |
double v = s.toDouble(&ok);
|
|
664 |
if (ok)
|
|
665 |
d->val = v;
|
|
666 |
d->internalSetString(s);
|
|
667 |
}
|
|
668 |
|
|
669 |
/*!
|
|
670 |
Calls setMode(Hex). Provided for convenience (e.g. for
|
|
671 |
connecting buttons to it).
|
|
672 |
|
|
673 |
\sa setMode(), setDecMode(), setOctMode(), setBinMode(), mode()
|
|
674 |
*/
|
|
675 |
|
|
676 |
void QLCDNumber::setHexMode()
|
|
677 |
{
|
|
678 |
setMode(Hex);
|
|
679 |
}
|
|
680 |
|
|
681 |
|
|
682 |
/*!
|
|
683 |
Calls setMode(Dec). Provided for convenience (e.g. for
|
|
684 |
connecting buttons to it).
|
|
685 |
|
|
686 |
\sa setMode(), setHexMode(), setOctMode(), setBinMode(), mode()
|
|
687 |
*/
|
|
688 |
|
|
689 |
void QLCDNumber::setDecMode()
|
|
690 |
{
|
|
691 |
setMode(Dec);
|
|
692 |
}
|
|
693 |
|
|
694 |
|
|
695 |
/*!
|
|
696 |
Calls setMode(Oct). Provided for convenience (e.g. for
|
|
697 |
connecting buttons to it).
|
|
698 |
|
|
699 |
\sa setMode(), setHexMode(), setDecMode(), setBinMode(), mode()
|
|
700 |
*/
|
|
701 |
|
|
702 |
void QLCDNumber::setOctMode()
|
|
703 |
{
|
|
704 |
setMode(Oct);
|
|
705 |
}
|
|
706 |
|
|
707 |
|
|
708 |
/*!
|
|
709 |
Calls setMode(Bin). Provided for convenience (e.g. for
|
|
710 |
connecting buttons to it).
|
|
711 |
|
|
712 |
\sa setMode(), setHexMode(), setDecMode(), setOctMode(), mode()
|
|
713 |
*/
|
|
714 |
|
|
715 |
void QLCDNumber::setBinMode()
|
|
716 |
{
|
|
717 |
setMode(Bin);
|
|
718 |
}
|
|
719 |
|
|
720 |
|
|
721 |
/*!
|
|
722 |
\property QLCDNumber::smallDecimalPoint
|
|
723 |
\brief the style of the decimal point
|
|
724 |
|
|
725 |
If true the decimal point is drawn between two digit positions.
|
|
726 |
Otherwise it occupies a digit position of its own, i.e. is drawn
|
|
727 |
in a digit position. The default is false.
|
|
728 |
|
|
729 |
The inter-digit space is made slightly wider when the decimal
|
|
730 |
point is drawn between the digits.
|
|
731 |
|
|
732 |
\sa mode
|
|
733 |
*/
|
|
734 |
|
|
735 |
void QLCDNumber::setSmallDecimalPoint(bool b)
|
|
736 |
{
|
|
737 |
Q_D(QLCDNumber);
|
|
738 |
d->smallPoint = b;
|
|
739 |
update();
|
|
740 |
}
|
|
741 |
|
|
742 |
bool QLCDNumber::smallDecimalPoint() const
|
|
743 |
{
|
|
744 |
Q_D(const QLCDNumber);
|
|
745 |
return d->smallPoint;
|
|
746 |
}
|
|
747 |
|
|
748 |
|
|
749 |
|
|
750 |
/*!\reimp
|
|
751 |
*/
|
|
752 |
|
|
753 |
|
|
754 |
void QLCDNumber::paintEvent(QPaintEvent *)
|
|
755 |
{
|
|
756 |
Q_D(QLCDNumber);
|
|
757 |
QPainter p(this);
|
|
758 |
drawFrame(&p);
|
|
759 |
p.setRenderHint(QPainter::Antialiasing);
|
|
760 |
if (d->shadow)
|
|
761 |
p.translate(0.5, 0.5);
|
|
762 |
|
|
763 |
if (d->smallPoint)
|
|
764 |
d->drawString(d->digitStr, p, &d->points, false);
|
|
765 |
else
|
|
766 |
d->drawString(d->digitStr, p, 0, false);
|
|
767 |
}
|
|
768 |
|
|
769 |
|
|
770 |
void QLCDNumberPrivate::internalSetString(const QString& s)
|
|
771 |
{
|
|
772 |
Q_Q(QLCDNumber);
|
|
773 |
QString buffer;
|
|
774 |
int i;
|
|
775 |
int len = s.length();
|
|
776 |
QBitArray newPoints(ndigits);
|
|
777 |
|
|
778 |
if (!smallPoint) {
|
|
779 |
if (len == ndigits)
|
|
780 |
buffer = s;
|
|
781 |
else
|
|
782 |
buffer = s.right(ndigits).rightJustified(ndigits, QLatin1Char(' '));
|
|
783 |
} else {
|
|
784 |
int index = -1;
|
|
785 |
bool lastWasPoint = true;
|
|
786 |
newPoints.clearBit(0);
|
|
787 |
for (i=0; i<len; i++) {
|
|
788 |
if (s[i] == QLatin1Char('.')) {
|
|
789 |
if (lastWasPoint) { // point already set for digit?
|
|
790 |
if (index == ndigits - 1) // no more digits
|
|
791 |
break;
|
|
792 |
index++;
|
|
793 |
buffer[index] = QLatin1Char(' '); // 2 points in a row, add space
|
|
794 |
}
|
|
795 |
newPoints.setBit(index); // set decimal point
|
|
796 |
lastWasPoint = true;
|
|
797 |
} else {
|
|
798 |
if (index == ndigits - 1)
|
|
799 |
break;
|
|
800 |
index++;
|
|
801 |
buffer[index] = s[i];
|
|
802 |
newPoints.clearBit(index); // decimal point default off
|
|
803 |
lastWasPoint = false;
|
|
804 |
}
|
|
805 |
}
|
|
806 |
if (index < ((int) ndigits) - 1) {
|
|
807 |
for(i=index; i>=0; i--) {
|
|
808 |
buffer[ndigits - 1 - index + i] = buffer[i];
|
|
809 |
newPoints.setBit(ndigits - 1 - index + i,
|
|
810 |
newPoints.testBit(i));
|
|
811 |
}
|
|
812 |
for(i=0; i<ndigits-index-1; i++) {
|
|
813 |
buffer[i] = QLatin1Char(' ');
|
|
814 |
newPoints.clearBit(i);
|
|
815 |
}
|
|
816 |
}
|
|
817 |
}
|
|
818 |
|
|
819 |
if (buffer == digitStr)
|
|
820 |
return;
|
|
821 |
|
|
822 |
digitStr = buffer;
|
|
823 |
if (smallPoint)
|
|
824 |
points = newPoints;
|
|
825 |
q->update();
|
|
826 |
}
|
|
827 |
|
|
828 |
/*!
|
|
829 |
\internal
|
|
830 |
*/
|
|
831 |
|
|
832 |
void QLCDNumberPrivate::drawString(const QString &s, QPainter &p,
|
|
833 |
QBitArray *newPoints, bool newString)
|
|
834 |
{
|
|
835 |
Q_Q(QLCDNumber);
|
|
836 |
QPoint pos;
|
|
837 |
|
|
838 |
int digitSpace = smallPoint ? 2 : 1;
|
|
839 |
int xSegLen = q->width()*5/(ndigits*(5 + digitSpace) + digitSpace);
|
|
840 |
int ySegLen = q->height()*5/12;
|
|
841 |
int segLen = ySegLen > xSegLen ? xSegLen : ySegLen;
|
|
842 |
int xAdvance = segLen*(5 + digitSpace)/5;
|
|
843 |
int xOffset = (q->width() - ndigits*xAdvance + segLen/5)/2;
|
|
844 |
int yOffset = (q->height() - segLen*2)/2;
|
|
845 |
|
|
846 |
for (int i=0; i<ndigits; i++) {
|
|
847 |
pos = QPoint(xOffset + xAdvance*i, yOffset);
|
|
848 |
if (newString)
|
|
849 |
drawDigit(pos, p, segLen, s[i].toLatin1(), digitStr[i].toLatin1());
|
|
850 |
else
|
|
851 |
drawDigit(pos, p, segLen, s[i].toLatin1());
|
|
852 |
if (newPoints) {
|
|
853 |
char newPoint = newPoints->testBit(i) ? '.' : ' ';
|
|
854 |
if (newString) {
|
|
855 |
char oldPoint = points.testBit(i) ? '.' : ' ';
|
|
856 |
drawDigit(pos, p, segLen, newPoint, oldPoint);
|
|
857 |
} else {
|
|
858 |
drawDigit(pos, p, segLen, newPoint);
|
|
859 |
}
|
|
860 |
}
|
|
861 |
}
|
|
862 |
if (newString) {
|
|
863 |
digitStr = s;
|
|
864 |
digitStr.truncate(ndigits);
|
|
865 |
if (newPoints)
|
|
866 |
points = *newPoints;
|
|
867 |
}
|
|
868 |
}
|
|
869 |
|
|
870 |
|
|
871 |
/*!
|
|
872 |
\internal
|
|
873 |
*/
|
|
874 |
|
|
875 |
void QLCDNumberPrivate::drawDigit(const QPoint &pos, QPainter &p, int segLen,
|
|
876 |
char newCh, char oldCh)
|
|
877 |
{
|
|
878 |
// Draws and/or erases segments to change display of a single digit
|
|
879 |
// from oldCh to newCh
|
|
880 |
|
|
881 |
char updates[18][2]; // can hold 2 times number of segments, only
|
|
882 |
// first 9 used if segment table is correct
|
|
883 |
int nErases;
|
|
884 |
int nUpdates;
|
|
885 |
const char *segs;
|
|
886 |
int i,j;
|
|
887 |
|
|
888 |
const char erase = 0;
|
|
889 |
const char draw = 1;
|
|
890 |
const char leaveAlone = 2;
|
|
891 |
|
|
892 |
segs = getSegments(oldCh);
|
|
893 |
for (nErases=0; segs[nErases] != 99; nErases++) {
|
|
894 |
updates[nErases][0] = erase; // get segments to erase to
|
|
895 |
updates[nErases][1] = segs[nErases]; // remove old char
|
|
896 |
}
|
|
897 |
nUpdates = nErases;
|
|
898 |
segs = getSegments(newCh);
|
|
899 |
for(i = 0 ; segs[i] != 99 ; i++) {
|
|
900 |
for (j=0; j<nErases; j++)
|
|
901 |
if (segs[i] == updates[j][1]) { // same segment ?
|
|
902 |
updates[j][0] = leaveAlone; // yes, already on screen
|
|
903 |
break;
|
|
904 |
}
|
|
905 |
if (j == nErases) { // if not already on screen
|
|
906 |
updates[nUpdates][0] = draw;
|
|
907 |
updates[nUpdates][1] = segs[i];
|
|
908 |
nUpdates++;
|
|
909 |
}
|
|
910 |
}
|
|
911 |
for (i=0; i<nUpdates; i++) {
|
|
912 |
if (updates[i][0] == draw)
|
|
913 |
drawSegment(pos, updates[i][1], p, segLen);
|
|
914 |
if (updates[i][0] == erase)
|
|
915 |
drawSegment(pos, updates[i][1], p, segLen, true);
|
|
916 |
}
|
|
917 |
}
|
|
918 |
|
|
919 |
|
|
920 |
static void addPoint(QPolygon &a, const QPoint &p)
|
|
921 |
{
|
|
922 |
uint n = a.size();
|
|
923 |
a.resize(n + 1);
|
|
924 |
a.setPoint(n, p);
|
|
925 |
}
|
|
926 |
|
|
927 |
/*!
|
|
928 |
\internal
|
|
929 |
*/
|
|
930 |
|
|
931 |
void QLCDNumberPrivate::drawSegment(const QPoint &pos, char segmentNo, QPainter &p,
|
|
932 |
int segLen, bool erase)
|
|
933 |
{
|
|
934 |
Q_Q(QLCDNumber);
|
|
935 |
QPoint ppt;
|
|
936 |
QPoint pt = pos;
|
|
937 |
int width = segLen/5;
|
|
938 |
|
|
939 |
const QPalette &pal = q->palette();
|
|
940 |
QColor lightColor,darkColor,fgColor;
|
|
941 |
if (erase){
|
|
942 |
lightColor = pal.color(q->backgroundRole());
|
|
943 |
darkColor = lightColor;
|
|
944 |
fgColor = lightColor;
|
|
945 |
} else {
|
|
946 |
lightColor = pal.light().color();
|
|
947 |
darkColor = pal.dark().color();
|
|
948 |
fgColor = pal.color(q->foregroundRole());
|
|
949 |
}
|
|
950 |
|
|
951 |
|
|
952 |
#define LINETO(X,Y) addPoint(a, QPoint(pt.x() + (X),pt.y() + (Y)))
|
|
953 |
#define LIGHT
|
|
954 |
#define DARK
|
|
955 |
|
|
956 |
if (fill) {
|
|
957 |
QPolygon a(0);
|
|
958 |
//The following is an exact copy of the switch below.
|
|
959 |
//don't make any changes here
|
|
960 |
switch (segmentNo) {
|
|
961 |
case 0 :
|
|
962 |
ppt = pt;
|
|
963 |
LIGHT;
|
|
964 |
LINETO(segLen - 1,0);
|
|
965 |
DARK;
|
|
966 |
LINETO(segLen - width - 1,width);
|
|
967 |
LINETO(width,width);
|
|
968 |
LINETO(0,0);
|
|
969 |
break;
|
|
970 |
case 1 :
|
|
971 |
pt += QPoint(0 , 1);
|
|
972 |
ppt = pt;
|
|
973 |
LIGHT;
|
|
974 |
LINETO(width,width);
|
|
975 |
DARK;
|
|
976 |
LINETO(width,segLen - width/2 - 2);
|
|
977 |
LINETO(0,segLen - 2);
|
|
978 |
LIGHT;
|
|
979 |
LINETO(0,0);
|
|
980 |
break;
|
|
981 |
case 2 :
|
|
982 |
pt += QPoint(segLen - 1 , 1);
|
|
983 |
ppt = pt;
|
|
984 |
DARK;
|
|
985 |
LINETO(0,segLen - 2);
|
|
986 |
LINETO(-width,segLen - width/2 - 2);
|
|
987 |
LIGHT;
|
|
988 |
LINETO(-width,width);
|
|
989 |
LINETO(0,0);
|
|
990 |
break;
|
|
991 |
case 3 :
|
|
992 |
pt += QPoint(0 , segLen);
|
|
993 |
ppt = pt;
|
|
994 |
LIGHT;
|
|
995 |
LINETO(width,-width/2);
|
|
996 |
LINETO(segLen - width - 1,-width/2);
|
|
997 |
LINETO(segLen - 1,0);
|
|
998 |
DARK;
|
|
999 |
if (width & 1) { // adjust for integer division error
|
|
1000 |
LINETO(segLen - width - 3,width/2 + 1);
|
|
1001 |
LINETO(width + 2,width/2 + 1);
|
|
1002 |
} else {
|
|
1003 |
LINETO(segLen - width - 1,width/2);
|
|
1004 |
LINETO(width,width/2);
|
|
1005 |
}
|
|
1006 |
LINETO(0,0);
|
|
1007 |
break;
|
|
1008 |
case 4 :
|
|
1009 |
pt += QPoint(0 , segLen + 1);
|
|
1010 |
ppt = pt;
|
|
1011 |
LIGHT;
|
|
1012 |
LINETO(width,width/2);
|
|
1013 |
DARK;
|
|
1014 |
LINETO(width,segLen - width - 2);
|
|
1015 |
LINETO(0,segLen - 2);
|
|
1016 |
LIGHT;
|
|
1017 |
LINETO(0,0);
|
|
1018 |
break;
|
|
1019 |
case 5 :
|
|
1020 |
pt += QPoint(segLen - 1 , segLen + 1);
|
|
1021 |
ppt = pt;
|
|
1022 |
DARK;
|
|
1023 |
LINETO(0,segLen - 2);
|
|
1024 |
LINETO(-width,segLen - width - 2);
|
|
1025 |
LIGHT;
|
|
1026 |
LINETO(-width,width/2);
|
|
1027 |
LINETO(0,0);
|
|
1028 |
break;
|
|
1029 |
case 6 :
|
|
1030 |
pt += QPoint(0 , segLen*2);
|
|
1031 |
ppt = pt;
|
|
1032 |
LIGHT;
|
|
1033 |
LINETO(width,-width);
|
|
1034 |
LINETO(segLen - width - 1,-width);
|
|
1035 |
LINETO(segLen - 1,0);
|
|
1036 |
DARK;
|
|
1037 |
LINETO(0,0);
|
|
1038 |
break;
|
|
1039 |
case 7 :
|
|
1040 |
if (smallPoint) // if smallpoint place'.' between other digits
|
|
1041 |
pt += QPoint(segLen + width/2 , segLen*2);
|
|
1042 |
else
|
|
1043 |
pt += QPoint(segLen/2 , segLen*2);
|
|
1044 |
ppt = pt;
|
|
1045 |
DARK;
|
|
1046 |
LINETO(width,0);
|
|
1047 |
LINETO(width,-width);
|
|
1048 |
LIGHT;
|
|
1049 |
LINETO(0,-width);
|
|
1050 |
LINETO(0,0);
|
|
1051 |
break;
|
|
1052 |
case 8 :
|
|
1053 |
pt += QPoint(segLen/2 - width/2 + 1 , segLen/2 + width);
|
|
1054 |
ppt = pt;
|
|
1055 |
DARK;
|
|
1056 |
LINETO(width,0);
|
|
1057 |
LINETO(width,-width);
|
|
1058 |
LIGHT;
|
|
1059 |
LINETO(0,-width);
|
|
1060 |
LINETO(0,0);
|
|
1061 |
break;
|
|
1062 |
case 9 :
|
|
1063 |
pt += QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width);
|
|
1064 |
ppt = pt;
|
|
1065 |
DARK;
|
|
1066 |
LINETO(width,0);
|
|
1067 |
LINETO(width,-width);
|
|
1068 |
LIGHT;
|
|
1069 |
LINETO(0,-width);
|
|
1070 |
LINETO(0,0);
|
|
1071 |
break;
|
|
1072 |
default :
|
|
1073 |
qWarning("QLCDNumber::drawSegment: (%s) Illegal segment id: %d\n",
|
|
1074 |
q->objectName().toLocal8Bit().constData(), segmentNo);
|
|
1075 |
}
|
|
1076 |
// End exact copy
|
|
1077 |
p.setPen(Qt::NoPen);
|
|
1078 |
p.setBrush(fgColor);
|
|
1079 |
p.drawPolygon(a);
|
|
1080 |
p.setBrush(Qt::NoBrush);
|
|
1081 |
|
|
1082 |
pt = pos;
|
|
1083 |
}
|
|
1084 |
#undef LINETO
|
|
1085 |
#undef LIGHT
|
|
1086 |
#undef DARK
|
|
1087 |
|
|
1088 |
#define LINETO(X,Y) p.drawLine(ppt.x(), ppt.y(), pt.x()+(X), pt.y()+(Y)); \
|
|
1089 |
ppt = QPoint(pt.x()+(X), pt.y()+(Y))
|
|
1090 |
#define LIGHT p.setPen(lightColor)
|
|
1091 |
#define DARK p.setPen(darkColor)
|
|
1092 |
if (shadow)
|
|
1093 |
switch (segmentNo) {
|
|
1094 |
case 0 :
|
|
1095 |
ppt = pt;
|
|
1096 |
LIGHT;
|
|
1097 |
LINETO(segLen - 1,0);
|
|
1098 |
DARK;
|
|
1099 |
LINETO(segLen - width - 1,width);
|
|
1100 |
LINETO(width,width);
|
|
1101 |
LINETO(0,0);
|
|
1102 |
break;
|
|
1103 |
case 1 :
|
|
1104 |
pt += QPoint(0,1);
|
|
1105 |
ppt = pt;
|
|
1106 |
LIGHT;
|
|
1107 |
LINETO(width,width);
|
|
1108 |
DARK;
|
|
1109 |
LINETO(width,segLen - width/2 - 2);
|
|
1110 |
LINETO(0,segLen - 2);
|
|
1111 |
LIGHT;
|
|
1112 |
LINETO(0,0);
|
|
1113 |
break;
|
|
1114 |
case 2 :
|
|
1115 |
pt += QPoint(segLen - 1 , 1);
|
|
1116 |
ppt = pt;
|
|
1117 |
DARK;
|
|
1118 |
LINETO(0,segLen - 2);
|
|
1119 |
LINETO(-width,segLen - width/2 - 2);
|
|
1120 |
LIGHT;
|
|
1121 |
LINETO(-width,width);
|
|
1122 |
LINETO(0,0);
|
|
1123 |
break;
|
|
1124 |
case 3 :
|
|
1125 |
pt += QPoint(0 , segLen);
|
|
1126 |
ppt = pt;
|
|
1127 |
LIGHT;
|
|
1128 |
LINETO(width,-width/2);
|
|
1129 |
LINETO(segLen - width - 1,-width/2);
|
|
1130 |
LINETO(segLen - 1,0);
|
|
1131 |
DARK;
|
|
1132 |
if (width & 1) { // adjust for integer division error
|
|
1133 |
LINETO(segLen - width - 3,width/2 + 1);
|
|
1134 |
LINETO(width + 2,width/2 + 1);
|
|
1135 |
} else {
|
|
1136 |
LINETO(segLen - width - 1,width/2);
|
|
1137 |
LINETO(width,width/2);
|
|
1138 |
}
|
|
1139 |
LINETO(0,0);
|
|
1140 |
break;
|
|
1141 |
case 4 :
|
|
1142 |
pt += QPoint(0 , segLen + 1);
|
|
1143 |
ppt = pt;
|
|
1144 |
LIGHT;
|
|
1145 |
LINETO(width,width/2);
|
|
1146 |
DARK;
|
|
1147 |
LINETO(width,segLen - width - 2);
|
|
1148 |
LINETO(0,segLen - 2);
|
|
1149 |
LIGHT;
|
|
1150 |
LINETO(0,0);
|
|
1151 |
break;
|
|
1152 |
case 5 :
|
|
1153 |
pt += QPoint(segLen - 1 , segLen + 1);
|
|
1154 |
ppt = pt;
|
|
1155 |
DARK;
|
|
1156 |
LINETO(0,segLen - 2);
|
|
1157 |
LINETO(-width,segLen - width - 2);
|
|
1158 |
LIGHT;
|
|
1159 |
LINETO(-width,width/2);
|
|
1160 |
LINETO(0,0);
|
|
1161 |
break;
|
|
1162 |
case 6 :
|
|
1163 |
pt += QPoint(0 , segLen*2);
|
|
1164 |
ppt = pt;
|
|
1165 |
LIGHT;
|
|
1166 |
LINETO(width,-width);
|
|
1167 |
LINETO(segLen - width - 1,-width);
|
|
1168 |
LINETO(segLen - 1,0);
|
|
1169 |
DARK;
|
|
1170 |
LINETO(0,0);
|
|
1171 |
break;
|
|
1172 |
case 7 :
|
|
1173 |
if (smallPoint) // if smallpoint place'.' between other digits
|
|
1174 |
pt += QPoint(segLen + width/2 , segLen*2);
|
|
1175 |
else
|
|
1176 |
pt += QPoint(segLen/2 , segLen*2);
|
|
1177 |
ppt = pt;
|
|
1178 |
DARK;
|
|
1179 |
LINETO(width,0);
|
|
1180 |
LINETO(width,-width);
|
|
1181 |
LIGHT;
|
|
1182 |
LINETO(0,-width);
|
|
1183 |
LINETO(0,0);
|
|
1184 |
break;
|
|
1185 |
case 8 :
|
|
1186 |
pt += QPoint(segLen/2 - width/2 + 1 , segLen/2 + width);
|
|
1187 |
ppt = pt;
|
|
1188 |
DARK;
|
|
1189 |
LINETO(width,0);
|
|
1190 |
LINETO(width,-width);
|
|
1191 |
LIGHT;
|
|
1192 |
LINETO(0,-width);
|
|
1193 |
LINETO(0,0);
|
|
1194 |
break;
|
|
1195 |
case 9 :
|
|
1196 |
pt += QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width);
|
|
1197 |
ppt = pt;
|
|
1198 |
DARK;
|
|
1199 |
LINETO(width,0);
|
|
1200 |
LINETO(width,-width);
|
|
1201 |
LIGHT;
|
|
1202 |
LINETO(0,-width);
|
|
1203 |
LINETO(0,0);
|
|
1204 |
break;
|
|
1205 |
default :
|
|
1206 |
qWarning("QLCDNumber::drawSegment: (%s) Illegal segment id: %d\n",
|
|
1207 |
q->objectName().toLocal8Bit().constData(), segmentNo);
|
|
1208 |
}
|
|
1209 |
|
|
1210 |
#undef LINETO
|
|
1211 |
#undef LIGHT
|
|
1212 |
#undef DARK
|
|
1213 |
}
|
|
1214 |
|
|
1215 |
|
|
1216 |
|
|
1217 |
/*!
|
|
1218 |
\property QLCDNumber::segmentStyle
|
|
1219 |
\brief the style of the LCDNumber
|
|
1220 |
|
|
1221 |
\table
|
|
1222 |
\header \i Style \i Result
|
|
1223 |
\row \i \c Outline
|
|
1224 |
\i Produces raised segments filled with the background color
|
|
1225 |
\row \i \c Filled
|
|
1226 |
(this is the default).
|
|
1227 |
\i Produces raised segments filled with the foreground color.
|
|
1228 |
\row \i \c Flat
|
|
1229 |
\i Produces flat segments filled with the foreground color.
|
|
1230 |
\endtable
|
|
1231 |
|
|
1232 |
\c Outline and \c Filled will additionally use
|
|
1233 |
QPalette::light() and QPalette::dark() for shadow effects.
|
|
1234 |
*/
|
|
1235 |
void QLCDNumber::setSegmentStyle(SegmentStyle s)
|
|
1236 |
{
|
|
1237 |
Q_D(QLCDNumber);
|
|
1238 |
d->fill = (s == Flat || s == Filled);
|
|
1239 |
d->shadow = (s == Outline || s == Filled);
|
|
1240 |
update();
|
|
1241 |
}
|
|
1242 |
|
|
1243 |
QLCDNumber::SegmentStyle QLCDNumber::segmentStyle() const
|
|
1244 |
{
|
|
1245 |
Q_D(const QLCDNumber);
|
|
1246 |
Q_ASSERT(d->fill || d->shadow);
|
|
1247 |
if (!d->fill && d->shadow)
|
|
1248 |
return Outline;
|
|
1249 |
if (d->fill && d->shadow)
|
|
1250 |
return Filled;
|
|
1251 |
return Flat;
|
|
1252 |
}
|
|
1253 |
|
|
1254 |
|
|
1255 |
/*!\reimp
|
|
1256 |
*/
|
|
1257 |
QSize QLCDNumber::sizeHint() const
|
|
1258 |
{
|
|
1259 |
return QSize(10 + 9 * (numDigits() + (smallDecimalPoint() ? 0 : 1)), 23);
|
|
1260 |
}
|
|
1261 |
|
|
1262 |
/*! \reimp */
|
|
1263 |
bool QLCDNumber::event(QEvent *e)
|
|
1264 |
{
|
|
1265 |
return QFrame::event(e);
|
|
1266 |
}
|
|
1267 |
|
|
1268 |
/*!
|
|
1269 |
\fn void QLCDNumber::setMargin(int margin)
|
|
1270 |
Sets the width of the margin around the contents of the widget to \a margin.
|
|
1271 |
|
|
1272 |
Use QWidget::setContentsMargins() instead.
|
|
1273 |
\sa margin(), QWidget::setContentsMargins()
|
|
1274 |
*/
|
|
1275 |
|
|
1276 |
/*!
|
|
1277 |
\fn int QLCDNumber::margin() const
|
|
1278 |
Returns the width of the margin around the contents of the widget.
|
|
1279 |
|
|
1280 |
Use QWidget::getContentsMargins() instead.
|
|
1281 |
\sa setMargin(), QWidget::getContentsMargins()
|
|
1282 |
*/
|
|
1283 |
|
|
1284 |
QT_END_NAMESPACE
|
|
1285 |
|
|
1286 |
#endif // QT_NO_LCDNUMBER
|