1 /*==================================================================
3 ! mardrone application AR-Drone for MeeGo
5 ! Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
8 ! Author:Kate Alhola kate.alhola@nokia.com
10 ! GNU Lesser General Public License Usage
11 ! This file may be used under the terms of the GNU Lesser
12 ! General Public License version 2.1 as published by the Free Software
13 ! Foundation and appearing in the file LICENSE.LGPL included in the
14 ! packaging of this file. Please review the following information to
15 ! ensure the GNU Lesser General Public License version 2.1 requirements
16 ! will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
20 *===================================================================*/
22 #include "gaugelabel.h"
26 GaugeLabel::GaugeLabel(QGraphicsItem *parent) :
31 void GaugeLabel::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
34 drawNumLabel(painter);
36 //////////////////////////////////////////////////////////////////////////
37 void GaugeLabel::drawNumLabel(QPainter *painter)
42 int h=size().height();
46 qDebug() <<"drawnumlabel=" << m_name << " h=" << h << "w=" << w;
48 QFont sansFont("Helvetica [Cronyx]", 12);
49 QFontMetrics fm(sansFont);
50 painter->setFont(sansFont);
55 printf("ld=%d ldo=%d lo=%d h=%d\n",ld,ldo,lo,h);
57 drawLabel(painter, text, m_style);
58 sprintf(text, "%3d", ud);
60 base=(h+fm.ascent())/2;
63 painter->drawText(split-uw+6, base, text);
64 sprintf(text, "%02d", abs((ld-ldo-20)%100));
65 painter->drawText(split+ 7, base -h +lo, text);
66 sprintf(text, "%02d", abs((ld-ldo-10)%100));
67 painter->drawText(split+ 7, base -h/2 +lo, text);
68 sprintf(text, "%02d", abs((ld-ldo)%100));
69 painter->drawText(split +7, base +lo, text);
70 sprintf(text, "%02d", abs((ld-ldo+10)%100));
71 painter->drawText(split + 7,base + h/2 +lo , text);
72 sprintf(text, "%02d", abs((ld-ldo+20)%100));
73 painter->drawText(split + 7,base + h +lo , text);
77 sprintf(text, "%3d", val);
78 drawLabel(painter, text,m_style);
80 painter->restore(); // Restore and remove clicping rectabgle
83 ///////////////////////////////////////////////////////////////////////////
84 void GaugeLabel::drawLabel(QPainter *painter,char *text,int style)
86 int textlen = 0, i = 0;
89 int height=size().height();
90 int width=size().width();
91 int scrbox=(height*10)/30;
94 QVector<QPoint> nboxv;
100 if (style&7 == LEFT) xplace+=5;
102 nboxv.push_back(QPoint(xplace,yplace));
107 nboxv.push_back(QPoint(xplace+(width/2)-5,yplace ));
108 nboxv.push_back(QPoint(xplace+(width/2) ,yplace-5));
109 nboxv.push_back(QPoint(xplace+(width/2)+5,yplace ));
113 nboxv.push_back(QPoint(xplace+width/2,yplace));
114 nboxv.push_back(QPoint(xplace+width/2,yplace-scrbox));
115 nboxv.push_back(QPoint(xplace+width,yplace-scrbox ));
117 nboxv.push_back(QPoint(xplace+width,yplace ));
120 if (style&7== RIGHT) {
122 nboxv.push_back(QPoint(xplace+width ,yplace+(height/2)-5));
123 nboxv.push_back(QPoint(xplace+width+5,yplace+(height/2) ));
124 nboxv.push_back(QPoint(xplace+width ,yplace+(height/2)+5));
128 nboxv.push_back(QPoint(xplace+width,yplace+height+scrbox));
129 nboxv.push_back(QPoint(xplace+width/2,yplace+height+scrbox));
130 nboxv.push_back(QPoint(xplace+width/2,yplace+height));
132 nboxv.push_back(QPoint(xplace+width,yplace+height));
134 if (style&7== DOWN) {
135 nboxv.push_back(QPoint(xplace+(width/2)-5,yplace+height));
136 nboxv.push_back(QPoint(xplace+(width/2) ,yplace+height+5));
137 nboxv.push_back(QPoint(xplace+(width/2)+5,yplace+height));
140 nboxv.push_back(QPoint(xplace,yplace+height));
142 if (style&7 == LEFT) {
143 nboxv.push_back(QPoint(xplace ,yplace+(height/2)+5));
144 nboxv.push_back(QPoint(xplace-5,yplace+(height/2) ));
145 nboxv.push_back(QPoint(xplace ,yplace+(height/2)-5));
148 nboxv.push_back(QPoint(xplace,yplace));
150 textlen = strlen(text) + 2;
152 // pdrawable->draw_rectangle(pwidget->get_style()->get_black_gc(),
153 // true, xplace, yplace, width, height);
156 painter->setClipRect(QRect(xplace-5,yplace-scrbox, width+10, height+2*scrbox+1));
158 QBrush brush(QColor(0,0,0,255));
159 // QFont tapeFont("Helvetica [Cronyx]", 18);
160 // painter->setFont(tapeFont);
161 // painter->setPen(pen);
162 painter->setBrush(brush);
164 painter->drawPolygon(nboxv);
166 painter->drawLines(nboxv);
168 // painter->setBrush(brush);
169 QFont sansFont("Helvetica [Cronyx]", 12);
170 QFontMetrics fm(sansFont);
171 painter->setFont(sansFont);
173 painter->drawText(xplace + 3, yplace + (height+fm.ascent())/2, text);