43 #ifndef QT_NO_LCDNUMBER 46 #include "private/qframe_p.h" 190 s.
sprintf(
"%*x", ndigits, num);
193 s.
sprintf(
"%*i", ndigits, num);
196 s.
sprintf(
"%*o", ndigits, num);
206 *--p = (char)((n&1)+
'0');
218 for (
int i=0; i<(int)s.
length(); i++) {
239 bool of = num >= 2147483648.0 || num < -2147483648.0;
249 s.
sprintf(
"%*.*g", ndigits, nd, num);
265 static const char segments[30][8] =
266 { { 0, 1, 2, 4, 5, 6,99, 0},
267 { 2, 5,99, 0, 0, 0, 0, 0},
268 { 0, 2, 3, 4, 6,99, 0, 0},
269 { 0, 2, 3, 5, 6,99, 0, 0},
270 { 1, 2, 3, 5,99, 0, 0, 0},
271 { 0, 1, 3, 5, 6,99, 0, 0},
272 { 0, 1, 3, 4, 5, 6,99, 0},
273 { 0, 2, 5,99, 0, 0, 0, 0},
274 { 0, 1, 2, 3, 4, 5, 6,99},
275 { 0, 1, 2, 3, 5, 6,99, 0},
276 { 3,99, 0, 0, 0, 0, 0, 0},
277 { 7,99, 0, 0, 0, 0, 0, 0},
278 { 0, 1, 2, 3, 4, 5,99, 0},
279 { 1, 3, 4, 5, 6,99, 0, 0},
280 { 0, 1, 4, 6,99, 0, 0, 0},
281 { 2, 3, 4, 5, 6,99, 0, 0},
282 { 0, 1, 3, 4, 6,99, 0, 0},
283 { 0, 1, 3, 4,99, 0, 0, 0},
284 { 1, 3, 4, 5,99, 0, 0, 0},
285 { 1, 2, 3, 4, 5,99, 0, 0},
286 { 1, 4, 6,99, 0, 0, 0, 0},
287 { 3, 4, 5, 6,99, 0, 0, 0},
288 { 0, 1, 2, 3, 4,99, 0, 0},
289 { 3, 4,99, 0, 0, 0, 0, 0},
290 { 4, 5, 6,99, 0, 0, 0, 0},
291 { 1, 2, 4, 5, 6,99, 0, 0},
292 { 1, 2, 3, 5, 6,99, 0, 0},
293 { 8, 9,99, 0, 0, 0, 0, 0},
294 { 0, 1, 2, 3,99, 0, 0, 0},
295 {99, 0, 0, 0, 0, 0, 0, 0} };
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];
446 q->setDigitCount(ndigits);
498 if (numDigits > 99) {
499 qWarning(
"QLCDNumber::setNumDigits: (%s) Max 99 digits allowed",
504 qWarning(
"QLCDNumber::setNumDigits: (%s) Min 0 digits allowed",
508 if (
d->digitStr.isNull()) {
511 d->points.fill(0,
d->ndigits);
514 bool doDisplay =
d->ndigits == 0;
515 if (numDigits ==
d->ndigits)
519 if (numDigits >
d->ndigits) {
520 dif = numDigits -
d->ndigits;
523 d->digitStr.insert(0, buf);
524 d->points.resize(numDigits);
525 for (i=numDigits-1; i>=dif; i--)
526 d->points.setBit(i,
d->points.testBit(i-dif));
527 for (i=0; i<dif; i++)
528 d->points.clearBit(i);
531 d->digitStr =
d->digitStr.right(numDigits);
533 d->points.resize(numDigits);
534 for (i=0; i<(int)numDigits; i++)
535 d->points.setBit(i, tmpPoints.
testBit(i+dif));
664 d->internalSetString(s);
701 d->val = (double)num;
707 d->internalSetString(s);
732 d->internalSetString(s);
814 return d->smallPoint;
833 d->drawString(
d->digitStr, p, &
d->points,
false);
835 d->drawString(
d->digitStr, p, 0,
false);
854 bool lastWasPoint =
true;
856 for (i=0; i<len; i++) {
859 if (index == ndigits - 1)
867 if (index == ndigits - 1)
870 buffer[
index] = s[i];
872 lastWasPoint =
false;
875 if (index < ((
int) ndigits) - 1) {
876 for(i=index; i>=0; i--) {
877 buffer[ndigits - 1 - index + i] = buffer[i];
878 newPoints.
setBit(ndigits - 1 - index + i,
881 for(i=0; i<ndigits-index-1; i++) {
888 if (buffer == digitStr)
907 int digitSpace = smallPoint ? 2 : 1;
908 int xSegLen = q->width()*5/(ndigits*(5 + digitSpace) + digitSpace);
909 int ySegLen = q->height()*5/12;
910 int segLen = ySegLen > xSegLen ? xSegLen : ySegLen;
911 int xAdvance = segLen*(5 + digitSpace)/5;
912 int xOffset = (q->width() - ndigits*xAdvance + segLen/5)/2;
913 int yOffset = (q->height() - segLen*2)/2;
915 for (
int i=0; i<ndigits; i++) {
916 pos =
QPoint(xOffset + xAdvance*i, yOffset);
918 drawDigit(pos, p, segLen, s[i].toLatin1(), digitStr[i].toLatin1());
920 drawDigit(pos, p, segLen, s[i].toLatin1());
922 char newPoint = newPoints->
testBit(i) ?
'.' :
' ';
924 char oldPoint = points.testBit(i) ?
'.' :
' ';
925 drawDigit(pos, p, segLen, newPoint, oldPoint);
927 drawDigit(pos, p, segLen, newPoint);
945 char newCh,
char oldCh)
957 const char erase = 0;
959 const char leaveAlone = 2;
962 for (nErases=0; segs[nErases] != 99; nErases++) {
963 updates[nErases][0] = erase;
964 updates[nErases][1] = segs[nErases];
968 for(i = 0 ; segs[i] != 99 ; i++) {
969 for (j=0; j<nErases; j++)
970 if (segs[i] == updates[j][1]) {
971 updates[j][0] = leaveAlone;
975 updates[nUpdates][0] = draw;
976 updates[nUpdates][1] = segs[i];
980 for (i=0; i<nUpdates; i++) {
981 if (updates[i][0] == draw)
982 drawSegment(pos, updates[i][1], p, segLen);
983 if (updates[i][0] == erase)
984 drawSegment(pos, updates[i][1], p, segLen,
true);
1001 int segLen,
bool erase)
1006 int width = segLen/5;
1008 const QPalette &pal = q->palette();
1009 QColor lightColor,darkColor,fgColor;
1011 lightColor = pal.
color(q->backgroundRole());
1012 darkColor = lightColor;
1013 fgColor = lightColor;
1017 fgColor = pal.
color(q->foregroundRole());
1021 #define LINETO(X,Y) addPoint(a, QPoint(pt.x() + (X),pt.y() + (Y))) 1029 switch (segmentNo) {
1035 LINETO(segLen - width - 1,width);
1045 LINETO(width,segLen - width/2 - 2);
1051 pt +=
QPoint(segLen - 1 , 1);
1055 LINETO(-width,segLen - width/2 - 2);
1061 pt +=
QPoint(0 , segLen);
1065 LINETO(segLen - width - 1,-width/2);
1069 LINETO(segLen - width - 3,width/2 + 1);
1070 LINETO(width + 2,width/2 + 1);
1072 LINETO(segLen - width - 1,width/2);
1078 pt +=
QPoint(0 , segLen + 1);
1083 LINETO(width,segLen - width - 2);
1089 pt +=
QPoint(segLen - 1 , segLen + 1);
1093 LINETO(-width,segLen - width - 2);
1099 pt +=
QPoint(0 , segLen*2);
1103 LINETO(segLen - width - 1,-width);
1110 pt +=
QPoint(segLen + width/2 , segLen*2);
1112 pt +=
QPoint(segLen/2 , segLen*2);
1122 pt +=
QPoint(segLen/2 - width/2 + 1 , segLen/2 + width);
1132 pt +=
QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width);
1142 qWarning(
"QLCDNumber::drawSegment: (%s) Illegal segment id: %d\n",
1143 q->objectName().toLocal8Bit().constData(), segmentNo);
1157 #define LINETO(X,Y) p.drawLine(ppt.x(), ppt.y(), pt.x()+(X), pt.y()+(Y)); \ 1158 ppt = QPoint(pt.x()+(X), pt.y()+(Y)) 1159 #define LIGHT p.setPen(lightColor) 1160 #define DARK p.setPen(darkColor) 1162 switch (segmentNo) {
1168 LINETO(segLen - width - 1,width);
1178 LINETO(width,segLen - width/2 - 2);
1184 pt +=
QPoint(segLen - 1 , 1);
1188 LINETO(-width,segLen - width/2 - 2);
1194 pt +=
QPoint(0 , segLen);
1198 LINETO(segLen - width - 1,-width/2);
1202 LINETO(segLen - width - 3,width/2 + 1);
1203 LINETO(width + 2,width/2 + 1);
1205 LINETO(segLen - width - 1,width/2);
1211 pt +=
QPoint(0 , segLen + 1);
1216 LINETO(width,segLen - width - 2);
1222 pt +=
QPoint(segLen - 1 , segLen + 1);
1226 LINETO(-width,segLen - width - 2);
1232 pt +=
QPoint(0 , segLen*2);
1236 LINETO(segLen - width - 1,-width);
1243 pt +=
QPoint(segLen + width/2 , segLen*2);
1245 pt +=
QPoint(segLen/2 , segLen*2);
1255 pt +=
QPoint(segLen/2 - width/2 + 1 , segLen/2 + width);
1265 pt +=
QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width);
1275 qWarning(
"QLCDNumber::drawSegment: (%s) Illegal segment id: %d\n",
1276 q->objectName().toLocal8Bit().constData(), segmentNo);
1319 if (!
d->fill &&
d->shadow)
1321 if (
d->fill &&
d->shadow)
1364 #endif // QT_NO_LCDNUMBER
The QPainter class performs low-level painting on widgets and other paint devices.
The QColor class provides colors based on RGB, HSV or CMYK values.
void drawString(const QString &s, QPainter &, QBitArray *=0, bool=true)
QString & sprintf(const char *format,...)
Safely builds a formatted string from the format string cformat and an arbitrary list of arguments...
QT_DEPRECATED void setNumDigits(int nDigits)
QT_DEPRECATED int numDigits() const
void setBit(int i)
Sets the bit at index position i to 1.
#define QT_END_NAMESPACE
This macro expands to.
const QColor & color() const
Returns the brush color.
static QString double2string(double num, int base, int ndigits, bool *oflow)
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
const QBrush & dark() const
Returns the dark brush of the current color group.
int length() const
Returns the number of characters in this string.
void internalSetString(const QString &s)
static void addPoint(QPolygon &a, const QPoint &p)
bool event(QEvent *e)
Reimplemented Function
Mode
This type determines how numbers are shown.
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPolygon class provides a vector of points using integer precision.
The QString class provides a Unicode character string.
bool testBit(int i) const
Returns true if the bit at index position i is 1; otherwise returns false.
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
void overflow()
This signal is emitted whenever the QLCDNumber is asked to display a too-large number or a too-long s...
~QLCDNumber()
Destroys the LCD number.
void resize(int size)
Sets the size of the vector to size.
QString rightJustified(int width, QChar fill=QLatin1Char(' '), bool trunc=false) const Q_REQUIRED_RESULT
Returns a string of size() width that contains the fill character followed by the string...
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setSmallDecimalPoint(bool)
void truncate(int pos)
Truncates the string at the given position index.
const QBrush & light() const
Returns the light brush of the current color group.
static int numDigits(qlonglong n)
void setBinMode()
Calls setMode(Bin).
Q_CORE_EXPORT void qWarning(const char *,...)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
SegmentStyle segmentStyle() const
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
void drawFrame(QPainter *)
em>Reimplemented Function
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
QSize sizeHint() const
em>Reimplemented Function
void setOctMode()
Calls setMode(Oct).
void setHexMode()
Calls setMode(Hex).
bool smallDecimalPoint() const
The QBitArray class provides an array of bits.
bool checkOverflow(double num) const
Returns true if num is too big to be displayed in its entirety; otherwise returns false...
#define Q_DECLARE_PUBLIC(Class)
void drawDigit(const QPoint &, QPainter &, int, char, char=' ')
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
static const char * getSegments(char ch)
The QPoint class defines a point in the plane using integer precision.
bool event(QEvent *e)
Reimplemented Function
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
double toDouble(bool *ok=0) const
Returns the string converted to a double value.
void setPen(const QColor &color)
Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color.
QString & fill(QChar c, int size=-1)
Sets every character in the string to character ch.
QString objectName() const
void setDigitCount(int nDigits)
Sets the current number of digits to numDigits.
void setPoint(int index, int x, int y)
Sets the point at the given index to the point specified by ({x}, {y}).
The QLCDNumber widget displays a number with LCD-like digits.
SegmentStyle
This type determines the visual appearance of the QLCDNumber widget.
The QSize class defines the size of a two-dimensional object using integer point precision.
QLCDNumber(QWidget *parent=0)
Constructs an LCD number, sets the number of digits to 5, the base to decimal, the decimal point mode...
void setSegmentStyle(SegmentStyle)
void drawSegment(const QPoint &, char, QPainter &, int, bool=false)
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
The QPaintEvent class contains event parameters for paint events.
void setDecMode()
Calls setMode(Dec).
The QEvent class is the base class of all event classes.
The QFrame class is the base class of widgets that can have a frame.
QString & insert(int i, QChar c)
void clearBit(int i)
Sets the bit at index position i to 0.
int size() const
Returns the number of items in the vector.
void display(const QString &str)
Displays the number represented by the string s.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
static QString int2string(int num, int base, int ndigits, bool *oflow)
Q_DECL_CONSTEXPR int qRound(qreal d)
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
The QPalette class contains color groups for each widget state.