static CFIndex maxLabelWidth(CFArrayRef plist, CFIndex indent) {
    CFIndex count = CFArrayGetCount(plist);
    CFIndex ix;
    CFIndex maxWidth = 0;
    for (ix = 0; ix < count ; ++ix) {
        CFDictionaryRef prop = (CFDictionaryRef)CFArrayGetValueAtIndex(plist,
            ix);
        CFStringRef pType = (CFStringRef)CFDictionaryGetValue(prop,
            kSecPropertyKeyType);
        CFStringRef llabel = (CFStringRef)CFDictionaryGetValue(prop,
            kSecPropertyKeyLocalizedLabel);
        CFTypeRef value = (CFTypeRef)CFDictionaryGetValue(prop,
            kSecPropertyKeyValue);

        if (CFEqual(pType, kSecPropertyTypeSection)) {
            CFIndex width = maxLabelWidth((CFArrayRef)value, indent + 1);
            if (width > maxWidth)
                maxWidth = width;
        } else if (llabel) {
            CFIndex width = indent * 4 + CFStringGetLength(llabel);
            if (width > maxWidth)
                maxWidth = width;
        }
    }

    return maxWidth;
}
예제 #2
0
/*!
   Calculate the width/height that is needed for a
   vertical/horizontal scale.

   The extent is calculated from the pen width of the backbone,
   the major tick length, the spacing and the maximum width/height
   of the labels.

   \param pen Pen that is used for painting backbone and ticks
   \param font Font used for painting the labels

   \sa minLength()
*/
int QwtScaleDraw::extent(const QPen &pen, const QFont &font) const
{
    int d = 0;

    if ( hasComponent(QwtAbstractScaleDraw::Labels) )
    {
        if ( orientation() == Qt::Vertical )
            d = maxLabelWidth(font);
        else
            d = maxLabelHeight(font);

        if ( d > 0 )
            d += spacing();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Ticks) )
    {
        d += majTickLength();
    }

    if ( hasComponent(QwtAbstractScaleDraw::Backbone) )
    {
        const int pw = qwtMax( 1, pen.width() );  // penwidth can be zero
        d += pw;
    }

    d = qwtMax(d, minimumExtent());
    return d;
}
예제 #3
0
QSize Q3PlotAxis::sizeHint() const
{
    int margin = Q3PlotFrameContainer::Margin;

    switch (position_) {
        case Q3PlotFrame::PositionLeft:
        case Q3PlotFrame::PositionRight: {
            if (!labelsVisible_)
                return QSize(2 * margin, QWIDGETSIZE_MAX);

            int axisWidth = maxLabelWidth() + 2 * margin;
            axisWidth = axisWidth < 50 ? 50 : axisWidth;
            return QSize(axisWidth, QWIDGETSIZE_MAX);
        }
        case Q3PlotFrame::PositionBottom:
        case Q3PlotFrame::PositionTop: {
            QFontMetrics fm(font());
            if (!labelsVisible_)
                return QSize(QWIDGETSIZE_MAX, 2 * margin);

            return QSize(QWIDGETSIZE_MAX, 2 * margin + fm.height());
        }
    }
    return QSize(0, 0);
}
예제 #4
0
// The rect of a scale without the title
QRect ScalePicker::scaleRect(const QwtScale *scale) const
{
    const int bld = scale->baseLineDist();
    const int mjt = scale->scaleDraw()->majTickLength();
    const int sbd = scale->startBorderDist();
    const int ebd = scale->endBorderDist();
	
	int mlw, mlh;

    QRect rect;
    switch(scale->position())   
    {
        case QwtScale::Left:
        {
			mlw=maxLabelWidth(scale);
			
			rect.setRect(scale->width() - bld - mjt-mlw, sbd,
                mjt+mlw, scale->height() - sbd - ebd);
			
            break;
        }
        case QwtScale::Right:
        {
			mlw=maxLabelWidth(scale);
			rect.setRect(bld, sbd,
                 mjt+mlw, scale->height() - sbd - ebd);
            break;
        }
        case QwtScale::Bottom:
        {
			mlh=maxLabelHeight(scale);
			rect.setRect(sbd, bld, 
                scale->width() - sbd - ebd, mjt+mlh);
	        break;
        }
        case QwtScale::Top:
        {
			mlh=maxLabelHeight(scale);
			rect.setRect(sbd, scale->height() - bld - mjt-mlh, 
                scale->width() - sbd - ebd, mjt+mlh);
            break;
        }
    }
    return rect;
}
static void print_plist(CFArrayRef plist) {
    if (plist)
        printPlist(plist, 0, maxLabelWidth(plist, 0));
    else
        printf("NULL plist\n");
}
예제 #6
0
파일: scldraw.cpp 프로젝트: UIKit0/muse
//------------------------------------------------------------
//
//.F ScaleDraw:maxBoundingRect
//      Return the maximum bounding rectangle of the scale
//      for a specified painter
//
//.u Parameters
//.p  const QFontMetrics& fm -- font metrics used for calculations
//
//.u Description
//      The bounding rectangle is not very exact for round scales
//      with strange angle ranges.
//
//------------------------------------------------------------
QRect ScaleDraw::maxBoundingRect(const QFontMetrics& fm) const
{
    int i, wl; //,wmax;
    int a, ar, amin, amax;
    double arc;

    QRect r;

    wl = maxLabelWidth(fm, true);

    switch(d_orient)
    {
    case Left:
        
        r = QRect( d_xorg - d_hpad - d_majLen - wl,
                  d_yorg - fm.ascent(),
                  d_majLen + d_hpad + wl,
                  d_len + fm.height());
        break;
        
    case Right:
        
        r = QRect( d_xorg,
                  d_yorg - fm.ascent(),
                  d_majLen + d_hpad + wl,
                  d_len + fm.height());
        break;
        
    case Top:
        
        r = QRect ( d_xorg - wl / 2,
                   d_yorg - d_majLen - fm.ascent(),
                   d_len + wl,
                   d_majLen + d_vpad + fm.ascent());
        break;
        
    case Bottom:
        
        r = QRect ( d_xorg - wl / 2,
                   d_yorg,
                   d_len + wl,
                   d_majLen + d_vpad + fm.height());
        break;
        
    case Round:

        amin = 2880;
        amax = 0;
        ar = 0;

        for (i=0; i< d_scldiv.majCnt(); i++)
        {
            a = transform(d_scldiv.majMark(i));
        
            while (a > 2880) a -= 5760;
            while (a < - 2880) a += 5760;

            ar = MusECore::qwtAbs(a);

            if (ar < amin) amin = ar;
            if (ar > amax) amax = ar;

        }

        for (i=0; i< d_scldiv.minCnt(); i++)
        {
            a = transform(d_scldiv.majMark(i));
        
            while (a > 2880) a -= 5760;
            while (a < - 2880) a += 5760;

            ar = MusECore::qwtAbs(a);

            if (ar < amin) amin = ar;
            if (ar > amax) amax = ar;
        }

        arc = double(amin) / 16.0 * M_PI / 180.0;
        r.setTop(MusECore::qwtInt(d_yCenter - (d_radius + double(d_majLen + d_vpad)) * cos(arc))
                 + fm.ascent() );

        arc = double(amax) / 16.0 * M_PI / 180.0;
        r.setBottom(MusECore::qwtInt(d_yCenter - (d_radius + double(d_majLen + d_vpad)) * cos(arc))
                    + fm.height() );

        //wmax = d_len + d_majLen + d_hpad + wl; DELETETHIS

        r.setLeft(d_xorg - d_majLen - d_hpad - wl);
        r.setWidth(d_len + 2*(d_majLen + d_hpad + wl));
        break;
        
    case InsideHorizontal:
    case InsideVertical:
        return r;
        break;
    }

    return r;

}
예제 #7
0
파일: scldraw.cpp 프로젝트: UIKit0/muse
//------------------------------------------------------------
//
//.F    ScaleDraw::maxWidth
//      Return the maximum width of the scale for a specified QPainter
//
//.u    Syntax
//.f    int ScaleDraw::maxWidth(QPainter *p, int penWidth)
//
//.u    Parameters
//.p    const QFontMetrics& fm -- font metrics used for calculations
//      bool worst -- if TRUE, assume the worst possible case. If FALSE,
//                      calculate the real maximum width, which is more
//                      CPU intensive.
//      int penWidth -- the width of the pen that will be used to draw the scale
//
//------------------------------------------------------------
int ScaleDraw::maxWidth(const QFontMetrics& fm, bool worst, int penWidth) const
{
    return maxLabelWidth(fm,worst) + scaleWidth(penWidth);
}