⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wood.cpp

📁 《Linux程序设计权威指南》一书qt下的源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    if ( h < 8 ) {	awh = 6;    } else if ( h < 14 ) {	awh = h - 2;    } else {	awh = h/2;    }    if ( return_awh )	*return_awh = awh;    return awh*3/2;}static void get_combo_parameters( const QRect &r,				  int &ew, int &awh, int &ax,				  int &ay, int &sh, int &dh,				  int &sy ){    ew = get_combo_extra_width( r.height(), &awh );    sh = (awh+3)/4;    if ( sh < 3 )	sh = 3;    dh = sh/2 + 1;    ay = r.y() + (r.height()-awh-sh-dh)/2;    if ( ay < 0 ) {	//panic mode	ay = 0;	sy = r.height();    } else {	sy = ay+awh+dh;    }    ax = r.x() + r.width() - ew +(ew-awh)/2;}void NorwegianWoodStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,				    const QColorGroup &g,				    bool /* sunken */,				    bool editable,				    bool /*enabled */,				    const QBrush *fb ){    QBrush fill = fb ? *fb : g.brush( QColorGroup::Button );    int awh, ax, ay, sh, sy, dh, ew;    get_combo_parameters( buttonRect(x,y,w,h), ew, awh, ax, ay, sh, dh, sy );    drawButton( p, x, y, w, h, g, FALSE, &fill );    qDrawArrow( p, DownArrow, MotifStyle, FALSE,		ax, ay, awh, awh, g, TRUE );    p->setPen( g.light() );    p->drawLine( ax, sy, ax+awh-1, sy );    p->drawLine( ax, sy, ax, sy+sh-1 );    p->setPen( g.dark() );    p->drawLine( ax+1, sy+sh-1, ax+awh-1, sy+sh-1 );    p->drawLine( ax+awh-1, sy+1, ax+awh-1, sy+sh-1 );    if ( 0 && editable ) {	QRect r( comboButtonRect(x-1,y-1,w+2,h+2) );	qDrawShadePanel( p, r, g, TRUE, 1, &fill );    }}static inline int buttonthickness( int d ){ return  d > 20 ? 5 : ( d < 10 ? 2: 3 ); }enum { PointUp, PointDown, PointLeft, PointRight };void NorwegianWoodStyle::drawSemicircleButton( QPainter *p, const QRect &r, 					       int dir, bool sunken,					       const QColorGroup &g ){    int b = scrollBarExtent().height() > 20 ? 3 : 2;        QRegion extrn(  r.x(),   r.y(),   r.width(),     r.height(),     QRegion::Ellipse );    QRegion intern( r.x()+b, r.y()+b, r.width()-2*b, r.height()-2*b, QRegion::Ellipse );    int w2 = r.width()/2;    int h2 = r.height()/2;    int bug = 1; //off-by-one somewhere!!!???        switch( dir ) {    case PointRight:	extrn +=  QRegion( r.x(),  r.y(),   w2,     r.height() );	intern += QRegion( r.x()+b,r.y()+b, w2-2*b, r.height()-2*b );	break;    case PointLeft:	extrn +=  QRegion( r.x()+w2,  r.y(),   w2,     r.height() );	intern += QRegion( r.x()+w2+b,r.y()+b, w2-2*b, r.height()-2*b );	break;    case PointUp:	extrn +=  QRegion( r.x(),  r.y()+h2,   r.width(),     h2 );	intern += QRegion( r.x()+b,r.y()+h2+b, r.width()-2*b-bug, h2-2*b-bug );	break;    case PointDown:	extrn +=  QRegion( r.x(),  r.y(),   r.width(),     h2 );	intern += QRegion( r.x()+b,r.y()+b, r.width()-2*b-bug, h2-2*b-bug );	break;    }    extrn = extrn - intern;    QPointArray a;    a.setPoints( 3, r.x(), r.y(), r.x(), r.bottom(), r.right(), r.top() );        QRegion oldClip = p->clipRegion();    p->setClipRegion( intern );    p->fillRect( r, g.brush( QColorGroup::Button ) );    p->setClipRegion( QRegion(a)&extrn );    p->fillRect( r, sunken ? g.dark() : g.light() );    a.setPoints( 3, r.right(), r.bottom(), r.x(), r.bottom(), r.right(), r.top() );    p->setClipRegion( QRegion(a) &  extrn );    p->fillRect( r, sunken ? g.light() : g.dark() );        p->setClipRegion( oldClip );}void NorwegianWoodStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb,						int sliderStart, uint controls,						uint activeControl ){    QWindowsStyle::drawScrollBarControls( p, sb, sliderStart, controls & ~(AddLine|SubLine),					activeControl & ~(AddLine|SubLine) );    bool horz = sb->orientation() == QScrollBar::Horizontal;    int b = 2;    int w = horz ? sb->height() : sb->width();    QColorGroup g = sb->colorGroup();        if ( controls & AddLine ) {	bool sunken = activeControl & AddLine;	QRect r( b, b, w-2*b, w-2*b ) ;	if ( horz ) {	    r.moveBy( sb->width() - w, 0 );	    drawSemicircleButton( p, r, PointRight, sunken, g );	} else {	    r.moveBy( 0, sb->height() - w );	    drawSemicircleButton( p, r, PointDown, sunken, g );	}    }     if ( controls & SubLine ) {	bool sunken = activeControl & SubLine;	QRect r( b, b, w-2*b, w-2*b ) ;	if ( horz ) {	    drawSemicircleButton( p, r, PointLeft, sunken, g );	} else {	    drawSemicircleButton( p, r, PointUp, sunken, g );	}    }}void NorwegianWoodStyle::drawButton( QPainter *p, int x, int y, int w, int h,			     const QColorGroup &g, bool sunken, const QBrush* fill){    int d = QMIN(w,h)/2;    int b = buttonthickness( d );        QRegion internR = roundRectRegion( QRect(x+b, y+b, w-2*b, h-2*b), d-b );    //    qDrawShadePanel( p, x, y, w, h, g, sunken, 5);    QPen oldPen = p->pen();    QBrush brush( fill ? *fill : (sunken ? g.brush( QColorGroup::Mid ) :                                          g.brush( QColorGroup::Button )));    p->setClipRegion( internR );    p->fillRect( x, y, w, h, brush );        int e = QMIN( w, h )/2;         QPoint p2(x+w-1-e,y+e);    QPoint p3(x+e, y+h-1-e);        QPointArray a;    a.setPoints( 5, x,y, x+w-1, y, p2.x(),p2.y(), p3.x(),p3.y(), x, y+h-1 );        p->setClipRegion( QRegion( a )- internR );        p->fillRect( x,y,w,h, (sunken ? QBrush( g.dark(), *sunkenDark )			   : g.brush( QColorGroup::Light ) ));        a.setPoint( 0, x+w-1, y+w-1 );    p->setClipRegion( QRegion( a ) - internR );        p->fillRect( x,y,w,h, (sunken ? QBrush( g.light(), *sunkenLight )			   : g.brush( QColorGroup::Dark )));        p->setClipRegion( internR );    p->setClipping( FALSE );    p->setPen( g.foreground() );    drawroundrect( p, x, y, w, h, d );    p->setPen( oldPen );}void NorwegianWoodStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,				const QColorGroup &g, bool sunken, const QBrush* fill){    QWindowsStyle::drawBevelButton(p, x, y, w, h, g, sunken, fill);}void NorwegianWoodStyle::drawPushButton( QPushButton* btn, QPainter *p){    QColorGroup g = btn->colorGroup();    int x1, y1, x2, y2;    btn->rect().coords( &x1, &y1, &x2, &y2 );	// get coordinates    p->setPen( g.foreground() );    p->setBrush( QBrush(g.button(),NoBrush) );    QBrush fill;    if ( btn->isDown() )	fill = g.brush( QColorGroup::Mid );    else if ( btn->isOn() )	fill = QBrush( g.mid(), Dense4Pattern );    else	fill = g.brush( QColorGroup::Button );	    if ( btn->isDefault() ) {	x1 += 2;	y1 += 2;	x2 -= 2;	y2 -= 2;    }	    drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, btn->isOn() || btn->isDown(), &fill);        if ( btn->isDefault() ) {	QPen pen( Qt::black, 4 );	pen.setCapStyle( Qt::RoundCap );	pen.setJoinStyle( Qt::RoundJoin );	p->setPen( pen );	drawroundrect( p, x1-1, y1-1, x2-x1+3, y2-y1+3, 8 );    }    if ( btn->isMenuButton() ) {	int dx = (y1-y2-4)/3;	drawArrow( p, DownArrow, FALSE,		   x2 - dx, dx, y1, y2 - y1,		   g, btn->isEnabled() );    }    if ( p->brush().style() != NoBrush )	p->setBrush( NoBrush );}void NorwegianWoodStyle::drawPushButtonLabel( QPushButton* btn, QPainter *p){    QRect r = btn->rect();    int x, y, w, h;    r.rect( &x, &y, &w, &h );    int x1, y1, x2, y2;    btn->rect().coords( &x1, &y1, &x2, &y2 );	// get coordinates    int dx = 0;    int dy = 0;    if ( btn->isMenuButton() )	dx = (y2-y1) / 3;    if ( dx || dy )	p->translate( dx, dy );    x += 2;  y += 2;  w -= 4;  h -= 4;    QColorGroup g = btn->colorGroup();    drawItem( p, x, y, w, h,	      AlignCenter|ShowPrefix,	      g, btn->isEnabled(),	      btn->pixmap(), btn->text(), -1,	      (btn->isDown() || btn->isOn())?&btn->colorGroup().brightText():&btn->colorGroup().buttonText());    if ( dx || dy )	p->translate( -dx, -dy );}QRect NorwegianWoodStyle::buttonRect( int x, int y, int w, int h){    int d = QMIN(w,h)/2;    int b = buttonthickness( d );    d -= b;    b++;        if ( w<h )	return QRect(x+b, y+d, w-2*b, h-2*d);    else	return QRect(x+d, y+b, w-2*d, h-2*b);}void NorwegianWoodStyle::drawButtonMask( QPainter *p, int x, int y, int w, int h){    int d = QMIN(w,h)/2;    drawroundrect( p, x, y, w, h, d );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -