--- /dev/null
+#include "gaugelabel.h"
+#include <QDebug>
+#include <math.h>
+
+GaugeLabel::GaugeLabel(QGraphicsItem *parent) :
+ Gauge(parent)
+{
+ m_textSize=20;
+}
+
+void GaugeLabel::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ drawNumLabel(painter);
+};
+//////////////////////////////////////////////////////////////////////////
+void GaugeLabel::drawNumLabel(QPainter *painter)
+{
+ int ld,ldo,ud,fh;
+ int lDigits,lWidth;
+ int vsplit,hsplit,uw,base;
+ char text[50]="";
+ QString utext;
+ int h=size().height();
+ int w=size().width();
+ int val=m_value;
+ painter->save();
+ painter->setTransform(QTransform().translate(scenePos().x(),scenePos().y()).scale(m_scale,m_scale));
+ // qDebug() <<"drawnumlabel=" << m_name << " x=" << scenePos().x() << " y=" << scenePos().y() << " h=" << h << " w=" << w;
+ QFontMetrics fm(m_font);
+ painter->setFont(m_font);
+ if(m_style&SCROLL) {
+ lDigits=m_tickMinor;
+ int lIncr=(lDigits&1?10:1)*(lDigits&2?100:1)*(lDigits&4?10000:1);
+ lWidth=fm.width(QString().number(lIncr-1));
+
+
+ ld=abs(val%(lIncr));
+ ud=val/(lIncr);
+ ldo=lDigits>1?ld%10:0;
+
+
+
+ utext=QString("%1").arg(ud,3);
+ hsplit=lWidth+10;
+
+ uw=fm.width(utext);
+ fh=fm.ascent();
+ float lo=(fmod(m_value,lIncr/10)/lIncr)*fh*10;
+ vsplit=(h-fm.ascent()-8)/2;
+ base=fm.ascent()+vsplit;
+ drawFrame(painter, m_style,hsplit,vsplit);
+// qDebug("val=%f ld=%d ldo=%d lo=%f h=%d lDigits=%d lIncr=%d\n",m_value,ld,ldo,lo,h,lDigits,lIncr);
+ if((ld*10/lIncr)==9) {
+ ud=(val+lIncr/2)/(lIncr);
+ painter->drawText(w-hsplit- uw, base+lo, QString("%1").arg(abs(ud-1),3));
+ painter->drawText(w-hsplit- uw, base-fh+lo,QString("%1").arg(abs(ud ),3) );
+ } else painter->drawText(w-hsplit- uw, base,utext );
+ painter->drawText(w-hsplit, base +2*fh+lo, QString("%1").arg(abs(ld-ldo-2*lIncr/10+lIncr)%lIncr,lDigits,10,QLatin1Char('0')));
+ painter->drawText(w-hsplit, base +fh +lo, QString("%1").arg(abs(ld-ldo- lIncr/10+lIncr)%lIncr,lDigits,10,QLatin1Char('0')));
+ painter->drawText(w-hsplit, base +lo, QString("%1").arg(abs(ld-ldo),lDigits,10,QLatin1Char('0')));
+ painter->drawText(w-hsplit, base -fh +lo ,QString("%1").arg(abs((ld-ldo+ lIncr/10)%lIncr),lDigits,10,QLatin1Char('0')));
+ painter->drawText(w-hsplit, base -2*fh+lo ,QString("%1").arg(abs((ld-ldo+2*lIncr/10)%lIncr),lDigits,10,QLatin1Char('0')));
+
+
+ } else {
+ sprintf(text, "%3d", val);
+ painter->drawText(7,base + fh , text);
+ // drawLabel(painter, text,m_style);
+ }
+ painter->restore(); // Restore and remove clicping rectabgle
+}
+
+///////////////////////////////////////////////////////////////////////////
+void GaugeLabel::drawFrame(QPainter *painter,int style,int hsplit,int vsplit)
+{
+ int textlen = 0, i = 0;
+ int xplace=0;
+ int yplace=0;
+ int height=size().height();
+ int width=size().width();
+
+ // qDebug() << "height=" << height << " width=" << width << " hsplit=" << hsplit << " vsplit=" << vsplit;
+
+ QVector<QPoint> nboxv;
+
+ QPen pen(m_color);
+ painter->setPen(pen);
+
+
+ if (style&7 == LEFT) xplace+=5;
+
+ nboxv.push_back(QPoint(xplace,yplace+vsplit));
+
+
+
+ if (style&7 == UP) {
+ nboxv.push_back(QPoint(xplace+(width/2)-5,yplace ));
+ nboxv.push_back(QPoint(xplace+(width/2) ,yplace-5));
+ nboxv.push_back(QPoint(xplace+(width/2)+5,yplace ));
+ }
+
+ if (style&SCROLL) {
+ nboxv.push_back(QPoint(xplace+width-hsplit,yplace+vsplit));
+ nboxv.push_back(QPoint(xplace+width-hsplit,yplace));
+ nboxv.push_back(QPoint(xplace+width,yplace));
+ } else
+ nboxv.push_back(QPoint(xplace+width,yplace ));
+
+
+ if (style&7== RIGHT) {
+
+ nboxv.push_back(QPoint(xplace+width ,yplace+(height/2)-5));
+ nboxv.push_back(QPoint(xplace+width+5,yplace+(height/2) ));
+ nboxv.push_back(QPoint(xplace+width ,yplace+(height/2)+5));
+ }
+
+ if (style&SCROLL) {
+ nboxv.push_back(QPoint(xplace+width,yplace+height));
+ nboxv.push_back(QPoint(xplace+width-hsplit,yplace+height));
+ nboxv.push_back(QPoint(xplace+width-hsplit,yplace+height-vsplit));
+ } else
+ nboxv.push_back(QPoint(xplace,yplace+height-vsplit));
+
+ if (style&7== DOWN) {
+ nboxv.push_back(QPoint(xplace+(width/2)-5,yplace+height));
+ nboxv.push_back(QPoint(xplace+(width/2) ,yplace+height+5));
+ nboxv.push_back(QPoint(xplace+(width/2)+5,yplace+height));
+ }
+
+ nboxv.push_back(QPoint(xplace,yplace+height-vsplit));
+
+ if (style&7 == LEFT) {
+ nboxv.push_back(QPoint(xplace ,yplace+(height/2)+5));
+ nboxv.push_back(QPoint(xplace-5,yplace+(height/2) ));
+ nboxv.push_back(QPoint(xplace ,yplace+(height/2)-5));
+ }
+
+ nboxv.push_back(QPoint(xplace,yplace+vsplit));
+
+ // pdrawable->draw_rectangle(pwidget->get_style()->get_black_gc(),
+ // true, xplace, yplace, width, height);
+
+ if (style&SCROLL) {
+
+ painter->setClipRect(QRect(xplace+width-hsplit,yplace, width+10, height));
+ painter->setClipRect(QRect(xplace-5,yplace+vsplit, width+10, height-2*vsplit),Qt::UniteClip);
+ // painter->drawRect(QRect(xplace-5,yplace, width+10, height));
+ }
+
+ // QFont tapeFont("Helvetica [Cronyx]", 18);
+ // painter->setFont(tapeFont);
+ // painter->setPen(pen);
+ QBrush brush(m_backColor);
+ painter->setBrush(brush);
+
+ painter->drawPolygon(nboxv);
+
+ painter->drawLines(nboxv);
+ /* QPen redpen(Qt::red);
+ painter->setPen(redpen);
+ int ii=0;
+ foreach (QPoint p,nboxv) {
+ qDebug() << ii << p;
+ painter->drawText(p, QString().number(ii++));
+
+ }*/
+
+}
+