Qt 4.8
Classes | Macros | Functions
qlcdnumber.cpp File Reference
#include "qlcdnumber.h"
#include "qbitarray.h"
#include "qpainter.h"
#include "private/qframe_p.h"

Go to the source code of this file.

Classes

class  QLCDNumberPrivate
 

Macros

#define DARK
 
#define DARK   p.setPen(darkColor)
 
#define LIGHT
 
#define LIGHT   p.setPen(lightColor)
 
#define LINETO(X, Y)   addPoint(a, QPoint(pt.x() + (X),pt.y() + (Y)))
 
#define LINETO(X, Y)
 

Functions

static void addPoint (QPolygon &a, const QPoint &p)
 
static QString double2string (double num, int base, int ndigits, bool *oflow)
 
static const char * getSegments (char ch)
 
static QString int2string (int num, int base, int ndigits, bool *oflow)
 

Macro Definition Documentation

◆ DARK [1/2]

#define DARK

◆ DARK [2/2]

#define DARK   p.setPen(darkColor)

◆ LIGHT [1/2]

#define LIGHT

◆ LIGHT [2/2]

#define LIGHT   p.setPen(lightColor)

◆ LINETO [1/2]

#define LINETO (   X,
 
)    addPoint(a, QPoint(pt.x() + (X),pt.y() + (Y)))

◆ LINETO [2/2]

#define LINETO (   X,
 
)
Value:
p.drawLine(ppt.x(), ppt.y(), pt.x()+(X), pt.y()+(Y)); \
ppt = QPoint(pt.x()+(X), pt.y()+(Y))
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

Function Documentation

◆ addPoint()

static void addPoint ( QPolygon a,
const QPoint p 
)
static

Definition at line 989 of file qlcdnumber.cpp.

990 {
991  uint n = a.size();
992  a.resize(n + 1);
993  a.setPoint(n, p);
994 }
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
unsigned int uint
Definition: qglobal.h:996
void setPoint(int index, int x, int y)
Sets the point at the given index to the point specified by ({x}, {y}).
Definition: qpolygon.h:120
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ double2string()

static QString double2string ( double  num,
int  base,
int  ndigits,
bool *  oflow 
)
static

Definition at line 235 of file qlcdnumber.cpp.

Referenced by QLCDNumber::checkOverflow(), and QLCDNumber::display().

236 {
237  QString s;
238  if (base != QLCDNumber::Dec) {
239  bool of = num >= 2147483648.0 || num < -2147483648.0;
240  if (of) { // oops, integer overflow
241  if (oflow)
242  *oflow = true;
243  return s;
244  }
245  s = int2string((int)num, base, ndigits, 0);
246  } else { // decimal base
247  int nd = ndigits;
248  do {
249  s.sprintf("%*.*g", ndigits, nd, num);
250  int i = s.indexOf(QLatin1Char('e'));
251  if (i > 0 && s[i+1]==QLatin1Char('+')) {
252  s[i] = QLatin1Char(' ');
253  s[i+1] = QLatin1Char('e');
254  }
255  } while (nd-- && (int)s.length() > ndigits);
256  }
257  if (oflow)
258  *oflow = (int)s.length() > ndigits;
259  return s;
260 }
QString & sprintf(const char *format,...)
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments...
Definition: qstring.cpp:5567
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const uint base
Definition: qurl.cpp:268
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static QString int2string(int num, int base, int ndigits, bool *oflow)
Definition: qlcdnumber.cpp:178

◆ getSegments()

static const char* getSegments ( char  ch)
static

Definition at line 263 of file qlcdnumber.cpp.

Referenced by QLCDNumberPrivate::drawDigit().

264 {
265  static const char segments[30][8] =
266  { { 0, 1, 2, 4, 5, 6,99, 0}, // 0 0 / O
267  { 2, 5,99, 0, 0, 0, 0, 0}, // 1 1
268  { 0, 2, 3, 4, 6,99, 0, 0}, // 2 2
269  { 0, 2, 3, 5, 6,99, 0, 0}, // 3 3
270  { 1, 2, 3, 5,99, 0, 0, 0}, // 4 4
271  { 0, 1, 3, 5, 6,99, 0, 0}, // 5 5 / S
272  { 0, 1, 3, 4, 5, 6,99, 0}, // 6 6
273  { 0, 2, 5,99, 0, 0, 0, 0}, // 7 7
274  { 0, 1, 2, 3, 4, 5, 6,99}, // 8 8
275  { 0, 1, 2, 3, 5, 6,99, 0}, // 9 9 / g
276  { 3,99, 0, 0, 0, 0, 0, 0}, // 10 -
277  { 7,99, 0, 0, 0, 0, 0, 0}, // 11 .
278  { 0, 1, 2, 3, 4, 5,99, 0}, // 12 A
279  { 1, 3, 4, 5, 6,99, 0, 0}, // 13 B
280  { 0, 1, 4, 6,99, 0, 0, 0}, // 14 C
281  { 2, 3, 4, 5, 6,99, 0, 0}, // 15 D
282  { 0, 1, 3, 4, 6,99, 0, 0}, // 16 E
283  { 0, 1, 3, 4,99, 0, 0, 0}, // 17 F
284  { 1, 3, 4, 5,99, 0, 0, 0}, // 18 h
285  { 1, 2, 3, 4, 5,99, 0, 0}, // 19 H
286  { 1, 4, 6,99, 0, 0, 0, 0}, // 20 L
287  { 3, 4, 5, 6,99, 0, 0, 0}, // 21 o
288  { 0, 1, 2, 3, 4,99, 0, 0}, // 22 P
289  { 3, 4,99, 0, 0, 0, 0, 0}, // 23 r
290  { 4, 5, 6,99, 0, 0, 0, 0}, // 24 u
291  { 1, 2, 4, 5, 6,99, 0, 0}, // 25 U
292  { 1, 2, 3, 5, 6,99, 0, 0}, // 26 Y
293  { 8, 9,99, 0, 0, 0, 0, 0}, // 27 :
294  { 0, 1, 2, 3,99, 0, 0, 0}, // 28 '
295  {99, 0, 0, 0, 0, 0, 0, 0} }; // 29 empty
296 
297  if (ch >= '0' && ch <= '9')
298  return segments[ch - '0'];
299  if (ch >= 'A' && ch <= 'F')
300  return segments[ch - 'A' + 12];
301  if (ch >= 'a' && ch <= 'f')
302  return segments[ch - 'a' + 12];
303 
304  int n;
305  switch (ch) {
306  case '-':
307  n = 10; break;
308  case 'O':
309  n = 0; break;
310  case 'g':
311  n = 9; break;
312  case '.':
313  n = 11; break;
314  case 'h':
315  n = 18; break;
316  case 'H':
317  n = 19; break;
318  case 'l':
319  case 'L':
320  n = 20; break;
321  case 'o':
322  n = 21; break;
323  case 'p':
324  case 'P':
325  n = 22; break;
326  case 'r':
327  case 'R':
328  n = 23; break;
329  case 's':
330  case 'S':
331  n = 5; break;
332  case 'u':
333  n = 24; break;
334  case 'U':
335  n = 25; break;
336  case 'y':
337  case 'Y':
338  n = 26; break;
339  case ':':
340  n = 27; break;
341  case '\'':
342  n = 28; break;
343  default:
344  n = 29; break;
345  }
346  return segments[n];
347 }

◆ int2string()

static QString int2string ( int  num,
int  base,
int  ndigits,
bool *  oflow 
)
static

Definition at line 178 of file qlcdnumber.cpp.

Referenced by QLCDNumber::checkOverflow(), QLCDNumber::display(), and double2string().

179 {
180  QString s;
181  bool negative;
182  if (num < 0) {
183  negative = true;
184  num = -num;
185  } else {
186  negative = false;
187  }
188  switch(base) {
189  case QLCDNumber::Hex:
190  s.sprintf("%*x", ndigits, num);
191  break;
192  case QLCDNumber::Dec:
193  s.sprintf("%*i", ndigits, num);
194  break;
195  case QLCDNumber::Oct:
196  s.sprintf("%*o", ndigits, num);
197  break;
198  case QLCDNumber::Bin:
199  {
200  char buf[42];
201  char *p = &buf[41];
202  uint n = num;
203  int len = 0;
204  *p = '\0';
205  do {
206  *--p = (char)((n&1)+'0');
207  n >>= 1;
208  len++;
209  } while (n != 0);
210  len = ndigits - len;
211  if (len > 0)
212  s.fill(QLatin1Char(' '), len);
213  s += QString::fromLatin1(p);
214  }
215  break;
216  }
217  if (negative) {
218  for (int i=0; i<(int)s.length(); i++) {
219  if (s[i] != QLatin1Char(' ')) {
220  if (i != 0) {
221  s[i-1] = QLatin1Char('-');
222  } else {
223  s.insert(0, QLatin1Char('-'));
224  }
225  break;
226  }
227  }
228  }
229  if (oflow)
230  *oflow = (int)s.length() > ndigits;
231  return s;
232 }
QString & sprintf(const char *format,...)
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments...
Definition: qstring.cpp:5567
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const uint base
Definition: qurl.cpp:268
unsigned int uint
Definition: qglobal.h:996
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QString & fill(QChar c, int size=-1)
Sets every character in the string to character ch.
Definition: qstring.cpp:4641
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55