• 7190阅读
  • 0回复

QT中drawarrow设置的箭头能弄大点不 [复制链接]

上一主题 下一主题
离线lancer
 
只看楼主 正序阅读 楼主  发表于: 2009-07-15
版本为2.3.10
在ScrollBar的设计中利用drawArrow画箭头,但是觉得箭头太小,想采用大点的,找到该函数是以下的描述,由于时间不够,发上来谁弄过的帮忙看下,谢谢
QMotifStyle::drawArrow( QPainter *p, ArrowType type, bool down,
         int x, int y, int w, int h,
         const QColorGroup &g, bool enabled, const QBrush * /* fill */ )
{
    // ### may be worth caching these as pixmaps, especially with the
    //        cost of rotate() for vertical arrows.

    QPointArray bFill;                // fill polygon
    QPointArray bTop;                // top shadow.
    QPointArray bBot;                // bottom shadow.
    QPointArray bLeft;                // left shadow.
    QWMatrix    matrix;                // xform matrix
    bool vertical = type == UpArrow || type == DownArrow;
    bool horizontal = !vertical;
    int     dim = w < h ? w : h;
    int     colspec = 0x0000;            // color specification array

    if ( dim < 2 )                // too small arrow
    return;

    // adjust size and center (to fix rotation below)
    if ( w >  dim ) {
    x += (w-dim)/2;
    w = dim;
    }
    if ( h > dim ) {
    y += (h-dim)/2;
    h = dim;
    }

    if ( dim > 3 ) {
    if ( dim > 6 )
        bFill.resize( dim & 1 ? 3 : 4 );
    bTop.resize( (dim/2)*2 );
    bBot.resize( dim & 1 ? dim + 1 : dim );
    bLeft.resize( dim > 4 ? 4 : 2 );
    bLeft.putPoints( 0, 2, 0,0, 0,dim-1 );
    if ( dim > 4 )
        bLeft.putPoints( 2, 2, 1,2, 1,dim-3 );
    bTop.putPoints( 0, 4, 1,0, 1,1, 2,1, 3,1 );
    bBot.putPoints( 0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2 );

    for( int i=0; i<dim/2-2 ; i++ ) {
        bTop.putPoints( i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i );
        bBot.putPoints( i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i );
    }
    if ( dim & 1 )                // odd number size: extra line
        bBot.putPoints( dim-1, 2, dim-3,dim/2, dim-1,dim/2 );
    if ( dim > 6 ) {            // dim>6: must fill interior
        bFill.putPoints( 0, 2, 1,dim-3, 1,2 );
        if ( dim & 1 )            // if size is an odd number
        bFill.setPoint( 2, dim - 3, dim / 2 );
        else
        bFill.putPoints( 2, 2, dim-4,dim/2-1, dim-4,dim/2 );
    }
    }
    else {
    if ( dim == 3 ) {            // 3x3 arrow pattern
        bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 );
        bTop .setPoints( 2, 1,0, 1,0 );
        bBot .setPoints( 2, 1,2, 2,1 );
    }
    else {                    // 2x2 arrow pattern
        bLeft.setPoints( 2, 0,0, 0,1 );
        bTop .setPoints( 2, 1,0, 1,0 );
        bBot .setPoints( 2, 1,1, 1,1 );
    }
    }

    if ( type == UpArrow || type == LeftArrow ) {
    matrix.translate( x, y );
    if ( vertical ) {
        matrix.translate( 0, h - 1 );
        matrix.rotate( -90 );
    } else {
        matrix.translate( w - 1, h - 1 );
        matrix.rotate( 180 );
    }
    if ( down )
        colspec = horizontal ? 0x2334 : 0x2343;
    else
        colspec = horizontal ? 0x1443 : 0x1434;
    }
    else if ( type == DownArrow || type == RightArrow ) {
    matrix.translate( x, y );
    if ( vertical ) {
        matrix.translate( w-1, 0 );
        matrix.rotate( 90 );
    }
    if ( down )
        colspec = horizontal ? 0x2443 : 0x2434;
    else
        colspec = horizontal ? 0x1334 : 0x1343;
    }

    QColor *cols[5];
    if ( enabled ) {
    cols[0] = 0;
    cols[1] = (QColor *)&g.button();
    cols[2] = (QColor *)&g.mid();
    cols[3] = (QColor *)&g.light();
    cols[4] = (QColor *)&g.dark();
    } else {
    cols[0] = 0;
    cols[1] = (QColor *)&g.button();
    cols[2] = (QColor *)&g.button();
    cols[3] = (QColor *)&g.button();
    cols[4] = (QColor *)&g.button();
    }
#define CMID    *cols[ (colspec>>12) & 0xf ]
#define CLEFT    *cols[ (colspec>>8) & 0xf ]
#define CTOP    *cols[ (colspec>>4) & 0xf ]
#define CBOT    *cols[ colspec & 0xf ]

    QPen     savePen   = p->pen();        // save current pen
    QBrush   saveBrush = p->brush();        // save current brush
    QWMatrix wxm = p->worldMatrix();
    QPen     pen( NoPen );
    QBrush brush = g.brush( enabled?QColorGroup::Button:QColorGroup::Mid );

    p->setPen( pen );
    p->setBrush( brush );
    p->setWorldMatrix( matrix, TRUE );        // set transformation matrix
    p->drawPolygon( bFill );            // fill arrow
    p->setBrush( NoBrush );            // don't fill

    p->setPen( CLEFT );
    p->drawLineSegments( bLeft );
    p->setPen( CTOP );
    p->drawLineSegments( bTop );
    p->setPen( CBOT );
    p->drawLineSegments( bBot );

    p->setWorldMatrix( wxm );
    p->setBrush( saveBrush );            // restore brush
    p->setPen( savePen );            // restore pen

#undef CMID
#undef CLEFT
#undef CTOP
#undef CBOT

}
新的开始
快速回复
限100 字节
 
上一个 下一个