Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

qwt_scldraw.cpp

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 // vim: expandtab
00011 
00012 #include <qpainter.h>
00013 #include "qwt_math.h"
00014 #include "qwt_painter.h"
00015 #include "qwt_scldraw.h"
00016 #include "qwt_layout_metrics.h"
00017 
00018 static const double step_eps = 1.0e-6;
00019 
00028 QwtScaleDraw::QwtScaleDraw():
00029     d_options(Backbone),
00030     d_hpad(4),
00031     d_vpad(4),
00032     d_medLen(6),
00033     d_majLen(8),
00034     d_minLen(4),
00035     d_minAngle(-135 * 16),
00036     d_maxAngle(135 * 16),
00037     d_fmt('g'),
00038     d_prec(4),
00039     d_fieldwidth(0),
00040     d_labelAlignment(0),
00041     d_labelRotation(0.0)
00042 {
00043     setGeometry(0,0,100,Bottom);
00044     setScale(0,100,0,0,10);
00045 }
00046 
00048 QwtScaleDraw::~QwtScaleDraw()
00049 {
00050 }
00051 
00053 void QwtScaleDraw::setOptions(int opt)
00054 {
00055     d_options = opt;
00056 }
00057 
00061 int QwtScaleDraw::options() const
00062 {
00063     return d_options;
00064 }
00065 
00078 void QwtScaleDraw::setScale(double x1, double x2, int maxMajIntv,
00079                             int maxMinIntv, double step, int logscale)
00080 {
00081     d_scldiv.rebuild( x1, x2, maxMajIntv, maxMinIntv, logscale, step, FALSE );
00082     setDblRange( d_scldiv.lBound(), d_scldiv.hBound(), d_scldiv.logScale());
00083 }
00084 
00085 
00090 void QwtScaleDraw::setScale(const QwtScaleDiv &sd)
00091 {
00092     d_scldiv = sd;
00093     setDblRange(d_scldiv.lBound(),d_scldiv.hBound(),d_scldiv.logScale());
00094 }
00095 
00100 void QwtScaleDraw::draw(QPainter *p) const
00101 {
00102     uint i;
00103 
00104     for (i=0; i< d_scldiv.majCnt(); i++)
00105     {
00106         const double val = d_scldiv.majMark(i);
00107         drawTick(p, val, d_majLen);
00108         drawLabel(p, val);
00109     }
00110 
00111     if (d_scldiv.logScale())
00112     {
00113         for (i=0; i< d_scldiv.minCnt(); i++)
00114             drawTick(p, d_scldiv.minMark(i), d_minLen);
00115     }
00116     else
00117     {
00118         const int kmax = d_scldiv.majCnt() - 1;
00119         if (kmax > 0) 
00120         {
00121             double majTick = d_scldiv.majMark(0);
00122             double hval = majTick - 0.5 * d_scldiv.majStep();
00123 
00124             int k = 0;
00125             for (i=0; i< d_scldiv.minCnt(); i++)
00126             {
00127                 const double val = d_scldiv.minMark(i);
00128                 if  (val > majTick)
00129                 {
00130                     if (k < kmax)
00131                     {
00132                         k++;
00133                         majTick = d_scldiv.majMark(k);
00134                     }
00135                     else
00136                     {
00137                         majTick += d_scldiv.majMark(kmax) + d_scldiv.majStep();
00138                     }
00139                     hval = majTick - 0.5 * d_scldiv.majStep();
00140 
00141                 }
00142                 if (qwtAbs(val-hval) < step_eps * d_scldiv.majStep())
00143                     drawTick(p, val, d_medLen);
00144                 else
00145                     drawTick(p, val, d_minLen);
00146             }
00147         }
00148     }
00149 
00150     if ( options() & Backbone )
00151         drawBackbone(p);
00152 }
00153 
00154 
00156 void QwtScaleDraw::drawTick(QPainter *p, double val, int len) const
00157 {
00158     if ( len <= 0 )
00159         return;
00160 
00161     const int tval = transform(val);
00162 
00163     switch(d_orient)
00164     {
00165         case Left:
00166             QwtPainter::drawLine(p, d_xorg, tval, d_xorg - len, tval);
00167             break;
00168 
00169         case Right:
00170             QwtPainter::drawLine(p, d_xorg, tval, d_xorg + len, tval);
00171             break;
00172 
00173         case Bottom: 
00174             QwtPainter::drawLine(p, tval, d_yorg, tval, d_yorg + len);
00175             break;
00176 
00177         case Top:
00178             QwtPainter::drawLine(p, tval, d_yorg, tval, d_yorg - len);
00179             break;
00180 
00181         case Round:
00182             if ((tval <= d_minAngle + 359 * 16) 
00183                 || (tval >= d_minAngle - 359 * 16))
00184             {
00185                 const double arc = double(tval) / 16.0 * M_PI / 180.0;
00186                 const int x1 = qwtInt(d_xCenter + sin(arc) * d_radius);
00187                 const int x2 = qwtInt(d_xCenter + sin(arc) 
00188                     * (d_radius + double(len)));
00189                 const int y1 = qwtInt(d_yCenter - cos(arc) * d_radius);
00190                 const int y2 = qwtInt(d_yCenter - cos(arc) 
00191                     * (d_radius + double(len)));
00192 
00193                 QwtPainter::drawLine(p, x1, y1, x2, y2);
00194             }
00195             break;
00196     }
00197 }
00198 
00200 void QwtScaleDraw::drawLabel(QPainter *p, double val) const
00201 {
00202     QPoint pos;
00203     int alignment;
00204     double rotation;
00205     labelPlacement(QFontMetrics(p->font()), val, pos, alignment, rotation);
00206 
00207     if ( alignment )
00208     {
00209         const QString txt = label(val);
00210         if ( !txt.isEmpty() )
00211         {
00212             QWMatrix m = labelWorldMatrix(QFontMetrics(p->font()),
00213                 pos, alignment, rotation, txt);
00214 
00215             p->save();
00216 #ifndef QT_NO_TRANSFORMATIONS
00217             p->setWorldMatrix(m, TRUE);
00218 #else
00219             p->translate(m.dx(), m.dy());
00220 #endif
00221             QwtPainter::drawText(p, 0, 0, txt);
00222             p->restore();
00223         }
00224     }
00225 }
00226 
00228 void QwtScaleDraw::labelPlacement( const QFontMetrics &fm, double val, 
00229     QPoint &pos, int &alignment, double &rotation) const
00230 {
00231     // correct rounding errors if val = 0
00232     if ((!d_scldiv.logScale()) 
00233         && (qwtAbs(val) < qwtAbs(step_eps * d_scldiv.majStep())))
00234     {
00235        val = 0.0;
00236     }
00237     
00238     const int tval = transform(val);
00239 
00240     int x = 0;
00241     int y = 0;
00242     int align = 0;
00243 
00244     switch(d_orient)
00245     {
00246         case Right:
00247         {
00248             x = d_xorg + d_majLen + d_hpad + 1;
00249             y = tval;
00250             align = d_labelAlignment;
00251             if ( align == 0 )
00252                 align = Qt::AlignRight | Qt::AlignVCenter;
00253             break;
00254         }
00255         case Left:
00256         {
00257             x = d_xorg - d_majLen - d_hpad - 1;
00258             y = tval;
00259             align = d_labelAlignment;
00260             if ( align == 0 )
00261                 align = Qt::AlignLeft | Qt::AlignVCenter;
00262             break;
00263         }
00264         case Bottom:
00265         {
00266             x = tval;
00267             y = d_yorg + d_majLen + d_vpad + 1;
00268             align = d_labelAlignment;
00269             if ( align == 0 )
00270                 align = Qt::AlignHCenter | Qt::AlignBottom;
00271             break;
00272         }
00273         case Top:
00274         {
00275             x = tval;
00276             y = d_yorg - d_majLen - d_vpad - 1;
00277             align = d_labelAlignment;
00278             if ( align == 0 )
00279                 align = Qt::AlignHCenter | Qt::AlignTop;
00280             break;
00281         }
00282         case Round:
00283         {
00284             if ((tval > d_minAngle + 359 * 16) 
00285                 || (tval < d_minAngle - 359 * 16))
00286             {
00287                break;
00288             }
00289             
00290             const int fmh = fm.ascent() - 2; 
00291             const double arc = tval / 16.0 / 360.0 * 2 * M_PI;
00292             const double radius = d_radius + d_majLen + d_vpad;
00293 
00294             // First we find the point on a circle enlarged
00295             // by half of the font height.
00296 
00297             double xOffset = ( radius + fmh / 2 ) * sin(arc); 
00298             double yOffset = ( radius + fmh / 2 ) * cos(arc);
00299 
00300             if ( qwtInt(xOffset) != 0 ) 
00301             {
00302                 // The centered label might cut the circle 
00303                 // with distance: d_radius + d_majLen + d_vpad
00304                 // We align the label to the circle by moving
00305                 // the x-coordinate, because we have only
00306                 // horizontal labels here.
00307 
00308                 const int fmw = fm.width(label(val));
00309 
00310                 const double circleX = radius * sin(arc); 
00311                 if ( xOffset < 0 )
00312                     xOffset = circleX - fmw / 2; // left
00313                 else
00314                     xOffset = circleX + fmw / 2; // right
00315             }
00316             x = qwtInt(d_xCenter + xOffset);
00317             y = qwtInt(d_yCenter - yOffset);
00318             align = Qt::AlignHCenter | Qt::AlignVCenter;
00319 
00320             break;
00321         }
00322     }
00323 
00324     pos = QPoint(x, y);
00325     alignment = align;
00326     rotation = d_labelRotation;
00327 }
00328 
00330 
00331 QWMatrix QwtScaleDraw::labelWorldMatrix(const QFontMetrics &fm,
00332     const QPoint &pos, int alignment, 
00333 #ifdef QT_NO_TRANSFORMATIONS
00334     double,
00335 #else
00336     double rotation, 
00337 #endif
00338     const QString &txt) const
00339 {
00340     const int w = fm.boundingRect(0, 0, 
00341         QCOORD_MAX, QCOORD_MAX, 0, txt).width() - 2;
00342     const int h = fm.ascent() - 2;
00343     
00344     int x, y;
00345     if ( alignment & Qt::AlignLeft )
00346         x = -w;
00347     else if ( alignment & Qt::AlignRight )
00348         x = 0 - w % 2;
00349     else // Qt::AlignHCenter
00350         x = -(w / 2);
00351         
00352     if ( alignment & Qt::AlignTop )
00353         y = 0;
00354     else if ( alignment & Qt::AlignBottom )
00355         y = h - 1;
00356     else // Qt::AlignVCenter
00357         y = h / 2;
00358     
00359     QWMatrix m;
00360     m.translate(pos.x(), pos.y());
00361 #ifndef QT_NO_TRANSFORMATIONS
00362     m.rotate(rotation);
00363 #endif
00364     m.translate(x, y);
00365 
00366     return m;
00367 }
00368 
00370 void QwtScaleDraw::drawBackbone(QPainter *p) const
00371 {
00372     const int bw2 = p->pen().width() / 2;
00373     
00374     switch(d_orient)
00375     {
00376         case Left:
00377             QwtPainter::drawLine(p, d_xorg - bw2, 
00378                 d_yorg, d_xorg - bw2, d_yorg + d_len - 1);
00379             break;
00380         case Right:
00381             QwtPainter::drawLine(p, d_xorg + bw2, 
00382                 d_yorg, d_xorg + bw2, d_yorg + d_len - 1);
00383             break;
00384         case Top:
00385             QwtPainter::drawLine(p, d_xorg, d_yorg - bw2, 
00386                 d_xorg + d_len - 1, d_yorg - bw2);
00387             break;
00388         case Bottom:
00389             QwtPainter::drawLine(p, d_xorg, d_yorg + bw2, 
00390                 d_xorg + d_len - 1, d_yorg + bw2);
00391             break;
00392         case Round:
00393         {
00394             const int a1 = qwtMin(i1(), i2()) - 90 * 16; 
00395             const int a2 = qwtMax(i1(), i2()) - 90 * 16; 
00396             
00397             p->drawArc(d_xorg, d_yorg, d_len, d_len,
00398                 -a2, a2 - a1 + 1);           // counterclockwise
00399             break;
00400         }
00401     }
00402 }
00403 
00404 
00444 void QwtScaleDraw::setGeometry(int xorigin, int yorigin, 
00445     int length, Orientation o)
00446 {
00447     static int minLen = 10;
00448 
00449     d_xorg = xorigin;
00450     d_yorg = yorigin;
00451     d_radius = double(length) * 0.5;
00452     d_xCenter = double(xorigin) + double(length) * 0.5;
00453     d_yCenter = double(yorigin) + double(length) * 0.5;
00454     
00455     if (length > minLen)
00456        d_len = length;
00457     else
00458        d_len = minLen;
00459     
00460     d_orient = o;
00461     
00462     switch(d_orient)
00463     {
00464         case Left:
00465         case Right:
00466             setIntRange(d_yorg + d_len - 1, d_yorg);
00467             break;
00468         case Round:
00469             setIntRange(d_minAngle, d_maxAngle);
00470             break;
00471         case Top:
00472         case Bottom:
00473             setIntRange(d_xorg, d_xorg + d_len - 1);
00474             break;
00475     }
00476 }
00477 
00483 int QwtScaleDraw::maxWidth(const QPen &pen, const QFontMetrics &fm) const
00484 {
00485     int w = 0;
00486 
00487     switch (d_orient)
00488     {
00489         case Left:
00490         case Right:
00491             w += pen.width() + d_majLen + d_hpad + maxLabelWidth(fm);
00492             break;
00493         case Round:
00494             w += pen.width() + d_majLen + d_vpad + maxLabelWidth(fm);
00495             break;
00496         case Top:
00497         case Bottom:
00498             w = d_len + maxLabelWidth(fm);
00499             break;
00500     }
00501     return w;
00502 }
00503 
00509 int QwtScaleDraw::maxHeight(const QPen &pen, const QFontMetrics &fm) const 
00510 {
00511     int h = 0;
00512     
00513     switch (d_orient)
00514     {
00515         case Top:
00516         case Bottom:
00517             h = pen.width() + d_vpad + d_majLen + maxLabelHeight(fm);
00518             break;
00519         case Left:
00520         case Right:
00521             h = d_len + maxLabelHeight(fm);
00522             break;
00523         case Round:
00524             h = d_vpad + d_majLen;
00525             if ( maxLabelHeight(fm) > 0 )
00526                 h += fm.ascent() - 2;
00527             break;
00528     }
00529     
00530     return h;
00531 }
00532 
00542 void QwtScaleDraw::setLabelRotation(double rotation)
00543 {
00544     d_labelRotation = rotation;
00545 }
00546 
00551 double QwtScaleDraw::labelRotation() const
00552 {
00553     return d_labelRotation;
00554 }
00555 
00575 void QwtScaleDraw::setLabelAlignment(int alignment)
00576 {
00577     d_labelAlignment = alignment;
00578 }
00579 
00584 int QwtScaleDraw::labelAlignment() const
00585 {
00586     return d_labelAlignment;
00587 }
00588 
00607 void QwtScaleDraw::setAngleRange(double angle1, double angle2)
00608 {
00609     angle1 = qwtLim(angle1, -360.0, 360.0);
00610     angle2 = qwtLim(angle2, -360.0, 360.0);
00611 
00612     int amin = int(floor (qwtMin(angle1, angle2) * 16.0 + 0.5));
00613     int amax = int(floor (qwtMax(angle1, angle2) * 16.0 + 0.5));
00614     
00615     if (amin == amax)
00616     {
00617         amin -= 1;
00618         amax += 1;
00619     }
00620     
00621     d_minAngle = amin;
00622     d_maxAngle = amax;
00623     setIntRange(d_minAngle, d_maxAngle);
00624 }
00625 
00636 void QwtScaleDraw::setLabelFormat(char f, int prec, int fieldwidth)
00637 {
00638     d_fmt = f;
00639     d_prec = prec;
00640     d_fieldwidth = fieldwidth;
00641 }
00642 
00651 void QwtScaleDraw::labelFormat(char &f, int &prec, int &fieldwidth) const
00652 {
00653     f = d_fmt;
00654     prec = d_prec;
00655     fieldwidth = d_fieldwidth;
00656 }
00657 
00664 void QwtScaleDraw::setMargin(uint hMargin, uint vMargin)
00665 {
00666     d_hpad = hMargin;
00667     d_vpad = vMargin;
00668 }
00669 
00673 void QwtScaleDraw::setTickLength(unsigned int minLen, 
00674     unsigned int medLen, unsigned int majLen)
00675 {
00676     const unsigned int maxTickLen = 1000;
00677 
00678     d_minLen = QMIN(minLen, maxTickLen);
00679     d_medLen = QMIN(medLen, maxTickLen);
00680     d_majLen = QMIN(majLen, maxTickLen);
00681 }
00682 
00687 void QwtScaleDraw::tickLength(unsigned int &minLen,
00688         unsigned int &medLen, unsigned int &majLen) const
00689 {
00690     minLen = d_minLen;
00691     medLen = d_medLen;
00692     majLen = d_majLen;
00693 }
00694 
00699 unsigned int QwtScaleDraw::majTickLength() const
00700 {
00701     return d_majLen;
00702 }
00703 
00708 int QwtScaleDraw::maxLabelWidth(const QFontMetrics &fm) const
00709 {
00710     int maxWidth = 0;
00711 
00712     for (uint i = 0; i < d_scldiv.majCnt(); i++)
00713     {
00714         double val = d_scldiv.majMark(i);
00715 
00716         // correct rounding errors if val = 0
00717 
00718         if ((!d_scldiv.logScale()) 
00719             && (qwtAbs(val) < step_eps * qwtAbs(d_scldiv.majStep())))
00720         {
00721             val = 0.0;
00722         }
00723 
00724         const int w = labelBoundingRect(fm, val).width();
00725         if ( w > maxWidth )
00726             maxWidth = w;
00727     }
00728 
00729     return maxWidth;
00730 }
00731 
00736 int QwtScaleDraw::maxLabelHeight(const QFontMetrics &fm) const
00737 {
00738     int maxHeight = 0;
00739 
00740     for (uint i = 0; i < d_scldiv.majCnt(); i++)
00741     {
00742         double val = d_scldiv.majMark(i);
00743 
00744         // correct rounding errors if val = 0
00745 
00746         if ((!d_scldiv.logScale()) 
00747             && (qwtAbs(val) < step_eps * qwtAbs(d_scldiv.majStep())))
00748         {
00749             val = 0.0;
00750         }
00751 
00752         const int h = labelBoundingRect(fm, val).height();
00753         if ( h > maxHeight )
00754             maxHeight = h;
00755     }
00756 
00757     return maxHeight;
00758 }
00759 
00765 QRect QwtScaleDraw::labelBoundingRect(
00766     const QFontMetrics &fm, double val) const
00767 {
00768     QString zeroString;
00769     if ( d_fieldwidth > 0 )
00770         zeroString.fill('0', d_fieldwidth);
00771 
00772     const QString lbl = label(val);
00773 
00774     const QString &txt = fm.width(zeroString) > fm.width(lbl) 
00775         ? zeroString : lbl;
00776     if ( txt.isEmpty() )
00777         return QRect(0, 0, 0, 0);
00778 
00779     QRect br;
00780 
00781     QPoint pos;
00782     int alignment;
00783     double rotation;
00784 
00785     labelPlacement(fm, val, pos, alignment, rotation);
00786     if ( alignment )
00787     {
00788         // Don't use fm.boundingRect(txt), it cuts off pixels.
00789         const int w = fm.boundingRect(0, 0, 
00790             QCOORD_MAX, QCOORD_MAX, 0, txt).width();
00791         const int h = -(fm.ascent() - 2);
00792 
00793         QWMatrix m = labelWorldMatrix(fm, pos, alignment, rotation, txt);
00794         br = QwtMetricsMap::translate(m, QRect(0, 0, w, h));
00795         br.moveBy(-pos.x(), -pos.y());
00796     }
00797 
00798     return br;
00799 }
00800 
00811 void QwtScaleDraw::minBorderDist(const QFontMetrics &fm,
00812     int &start, int &end ) const
00813 {
00814     start = 0;
00815     end = 0;
00816 
00817     if ( d_scldiv.majCnt() > 0 )
00818     {
00819         const QRect labelRectMin = labelBoundingRect(fm, d_scldiv.majMark(0));
00820         const QRect labelRectMax = labelBoundingRect(fm, 
00821             d_scldiv.majMark(d_scldiv.majCnt() - 1));
00822 
00823         switch (d_orient)
00824         {
00825             case Left:
00826             case Right:
00827                 end = -labelRectMin.y();
00828                 start = labelRectMax.height() + labelRectMax.y();
00829                 break;
00830             case Top:
00831             case Bottom:
00832                 start = -labelRectMin.x();
00833                 end = labelRectMax.width() + labelRectMax.x();
00834                 break;
00835             case Round:
00836                 start = labelRectMin.width();
00837                 end = labelRectMax.width();
00838                 break;
00839         }
00840     }
00841 }
00842 
00852 int QwtScaleDraw::minLabelDist(const QFontMetrics &fm) const
00853 {
00854     if ( d_orient == Round ) // no implementation
00855         return 0;
00856 
00857     if (0 == d_scldiv.majCnt())
00858     {
00859         return 0;
00860     }
00861 
00862     const bool vertical = (d_orient == Left || d_orient == Right);
00863 
00864     QRect bRect1;
00865     QRect bRect2 = labelBoundingRect(fm, d_scldiv.majMark(0));
00866     if ( vertical )
00867     {
00868         bRect2.setRect(-bRect2.bottom(), 0, bRect2.height(), bRect2.width());
00869     }
00870     int maxDist = 0;
00871 
00872     for (uint i = 1; i < d_scldiv.majCnt(); i++ )
00873     {
00874         bRect1 = bRect2;
00875         bRect2 = labelBoundingRect(fm, d_scldiv.majMark(i));
00876         if ( vertical )
00877         {
00878             bRect2.setRect(-bRect2.bottom(), 0,
00879                 bRect2.height(), bRect2.width());
00880         }
00881 
00882         int dist = fm.leading(); // space between the labels
00883         if ( bRect1.right() > 0 )
00884             dist += bRect1.right();
00885         if ( bRect2.left() < 0 )
00886             dist += -bRect2.left();
00887 
00888         if ( dist > maxDist )
00889             maxDist = dist;
00890     }
00891 
00892     double angle = d_labelRotation / 180.0 * M_PI;
00893     if ( vertical )
00894         angle += M_PI / 2;
00895 
00896     if ( sin(angle) == 0.0 )
00897         return maxDist;
00898 
00899     const int fmHeight = fm.ascent() - 2; 
00900 
00901     // The distance we need until there is
00902     // the height of the label font. This height is needed
00903     // for the neighbour labal.
00904 
00905     int labelDist = (int)(fmHeight / sin(angle) * cos(angle));
00906     if ( labelDist < 0 )
00907         labelDist = -labelDist;
00908 
00909     // The cast above floored labelDist. We want to ceil.
00910     labelDist++; 
00911 
00912     // For text orientations close to the scale orientation 
00913 
00914     if ( labelDist > maxDist )
00915         labelDist = maxDist;
00916 
00917     // For text orientations close to the opposite of the 
00918     // scale orientation
00919 
00920     if ( labelDist < fmHeight )
00921         labelDist = fmHeight;
00922 
00923     return labelDist;
00924 }
00925 
00932 int QwtScaleDraw::minHeight( const QPen &pen, const QFontMetrics &fm ) const
00933 {
00934     const int pw = QMAX( 1, pen.width() );  // penwidth can be zero
00935 
00936     int h = 0;
00937     switch ( d_orient )
00938     {
00939         case Left:
00940         case Right:
00941         {
00942             int bottomDist, topDist;
00943             minBorderDist(fm, bottomDist, topDist);
00944 
00945             h = bottomDist + topDist;
00946             if ( d_scldiv.majCnt() >= 2 ) 
00947                 h += minLabelDist(fm) * (d_scldiv.majCnt() - 1);
00948 
00949             int th = 2 * (d_scldiv.majCnt() + d_scldiv.minCnt()) * pw;
00950             if ( th > h )
00951                 h = th;
00952             break;
00953         }
00954         case Round:
00955             // compute the radial thickness
00956             h = pw + d_vpad + d_majLen + maxLabelWidth(fm);
00957             break;
00958         case Top:
00959         case Bottom:
00960             h = pw + d_vpad + d_majLen + maxLabelHeight(fm);
00961             break;
00962     }
00963     return h;
00964 }
00965 
00972 int QwtScaleDraw::minWidth( const QPen &pen, const QFontMetrics &fm ) const
00973 {
00974     const int pw = QMAX( 1, pen.width() );  // penwidth can be zero
00975 
00976     int w = 0;
00977 
00978     switch(d_orient)
00979     {
00980         case Left:
00981         case Right:
00982         {
00983             w = pw + d_hpad + d_majLen + maxLabelWidth(fm);
00984             break;
00985         }
00986         case Round:
00987         {   
00988             w = pw + d_vpad + d_majLen + maxLabelWidth(fm);
00989             break;
00990         }
00991         case Top:
00992         case Bottom:
00993         {
00994             int leftDist, rightDist;
00995             minBorderDist(fm, leftDist, rightDist);
00996 
00997             w = leftDist + rightDist + 
00998                 minLabelDist(fm) * (d_scldiv.majCnt() - 1);
00999 
01000             int tw = 2 * (d_scldiv.majCnt() + d_scldiv.minCnt()) * pw;
01001             if ( tw > w )
01002                 w = tw;
01003 
01004             break;
01005         }
01006     }
01007     return w;
01008 }
01009 
01018 QString QwtScaleDraw::label(double value) const
01019 {
01020 #if 1
01021     if ( value == -0 )
01022         value = 0;
01023 #endif
01024 
01025    return QString::fromLatin1("%1").arg(value, d_fieldwidth, d_fmt, d_prec);
01026 }
01027 
01029 int QwtScaleDraw::x() const
01030 {
01031     return d_xorg;
01032 }
01033 
01035 int QwtScaleDraw::y() const
01036 {
01037     return d_yorg;
01038 }
01040 int QwtScaleDraw::length() const
01041 {
01042     return d_len;
01043 }
01044 
01046 QwtScaleDraw::Orientation QwtScaleDraw::orientation() const 
01047 { 
01048     return d_orient; 
01049 }
01050 
01051 // Local Variables:
01052 // mode: C++
01053 // c-file-style: "stroustrup"
01054 // indent-tabs-mode: nil
01055 // End:

Generated on Sun Sep 26 23:24:37 2004 for Qwt User's Guide by doxygen 1.3.6