1 #include "gaugelabel.h"
5 GaugeLabel::GaugeLabel(QGraphicsItem *parent) :
10 void GaugeLabel::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
13 drawNumLabel(painter);
15 //////////////////////////////////////////////////////////////////////////
16 void GaugeLabel::drawNumLabel(QPainter *painter)
21 int h=size().height();
25 qDebug() <<"drawnumlabel=" << m_name << " h=" << h << "w=" << w;
27 QFont sansFont("Helvetica [Cronyx]", 12);
28 QFontMetrics fm(sansFont);
29 painter->setFont(sansFont);
34 printf("ld=%d ldo=%d lo=%d h=%d\n",ld,ldo,lo,h);
36 drawLabel(painter, text, m_style);
37 sprintf(text, "%3d", ud);
39 base=(h+fm.ascent())/2;
42 painter->drawText(split-uw+6, base, text);
43 sprintf(text, "%02d", abs((ld-ldo-20)%100));
44 painter->drawText(split+ 7, base -h +lo, text);
45 sprintf(text, "%02d", abs((ld-ldo-10)%100));
46 painter->drawText(split+ 7, base -h/2 +lo, text);
47 sprintf(text, "%02d", abs((ld-ldo)%100));
48 painter->drawText(split +7, base +lo, text);
49 sprintf(text, "%02d", abs((ld-ldo+10)%100));
50 painter->drawText(split + 7,base + h/2 +lo , text);
51 sprintf(text, "%02d", abs((ld-ldo+20)%100));
52 painter->drawText(split + 7,base + h +lo , text);
56 sprintf(text, "%3d", val);
57 drawLabel(painter, text,m_style);
59 painter->restore(); // Restore and remove clicping rectabgle
62 ///////////////////////////////////////////////////////////////////////////
63 void GaugeLabel::drawLabel(QPainter *painter,char *text,int style)
65 int textlen = 0, i = 0;
68 int height=size().height();
69 int width=size().width();
70 int scrbox=(height*10)/30;
73 QVector<QPoint> nboxv;
79 if (style&7 == LEFT) xplace+=5;
81 nboxv.push_back(QPoint(xplace,yplace));
86 nboxv.push_back(QPoint(xplace+(width/2)-5,yplace ));
87 nboxv.push_back(QPoint(xplace+(width/2) ,yplace-5));
88 nboxv.push_back(QPoint(xplace+(width/2)+5,yplace ));
92 nboxv.push_back(QPoint(xplace+width/2,yplace));
93 nboxv.push_back(QPoint(xplace+width/2,yplace-scrbox));
94 nboxv.push_back(QPoint(xplace+width,yplace-scrbox ));
96 nboxv.push_back(QPoint(xplace+width,yplace ));
99 if (style&7== RIGHT) {
101 nboxv.push_back(QPoint(xplace+width ,yplace+(height/2)-5));
102 nboxv.push_back(QPoint(xplace+width+5,yplace+(height/2) ));
103 nboxv.push_back(QPoint(xplace+width ,yplace+(height/2)+5));
107 nboxv.push_back(QPoint(xplace+width,yplace+height+scrbox));
108 nboxv.push_back(QPoint(xplace+width/2,yplace+height+scrbox));
109 nboxv.push_back(QPoint(xplace+width/2,yplace+height));
111 nboxv.push_back(QPoint(xplace+width,yplace+height));
113 if (style&7== DOWN) {
114 nboxv.push_back(QPoint(xplace+(width/2)-5,yplace+height));
115 nboxv.push_back(QPoint(xplace+(width/2) ,yplace+height+5));
116 nboxv.push_back(QPoint(xplace+(width/2)+5,yplace+height));
119 nboxv.push_back(QPoint(xplace,yplace+height));
121 if (style&7 == LEFT) {
122 nboxv.push_back(QPoint(xplace ,yplace+(height/2)+5));
123 nboxv.push_back(QPoint(xplace-5,yplace+(height/2) ));
124 nboxv.push_back(QPoint(xplace ,yplace+(height/2)-5));
127 nboxv.push_back(QPoint(xplace,yplace));
129 textlen = strlen(text) + 2;
131 // pdrawable->draw_rectangle(pwidget->get_style()->get_black_gc(),
132 // true, xplace, yplace, width, height);
135 painter->setClipRect(QRect(xplace-5,yplace-scrbox, width+10, height+2*scrbox+1));
137 QBrush brush(QColor(0,0,0,255));
138 // QFont tapeFont("Helvetica [Cronyx]", 18);
139 // painter->setFont(tapeFont);
140 // painter->setPen(pen);
141 painter->setBrush(brush);
143 painter->drawPolygon(nboxv);
145 painter->drawLines(nboxv);
147 // painter->setBrush(brush);
148 QFont sansFont("Helvetica [Cronyx]", 12);
149 QFontMetrics fm(sansFont);
150 painter->setFont(sansFont);
152 painter->drawText(xplace + 3, yplace + (height+fm.ascent())/2, text);