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