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

📄 flat.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
void FlatStyle::drawPushButtonLabel( QPushButton *btn, QPainter *p ){    QRect r = pushButtonContentsRect( btn );    int x, y, w, h;    r.rect( &x, &y, &w, &h );    QColorGroup cg = btn->colorGroup();    if ( btn->isToggleButton() && btn->isOn() && btn->isEnabled() && !btn->isDown() )	cg.setColor( QColorGroup::ButtonText, btn->colorGroup().text() );    else if ( btn->isDown() || btn->isOn() )	cg.setColor( QColorGroup::ButtonText, btn->colorGroup().button() );    if ( btn->isMenuButton() ) {	int dx = menuButtonIndicatorWidth( btn->height() );	drawArrow( p, DownArrow, FALSE,		x+w-dx, y+2, dx-4, h-4,		cg,		btn->isEnabled() );	w -= dx;    }    if ( btn->iconSet() && !btn->iconSet()->isNull() ) {	QIconSet::Mode mode = btn->isEnabled()	    ? QIconSet::Normal : QIconSet::Disabled;	if ( mode == QIconSet::Normal && btn->hasFocus() )	    mode = QIconSet::Active;	QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, mode );	int pixw = pixmap.width();	int pixh = pixmap.height();	p->drawPixmap( x+2, y+h/2-pixh/2, pixmap );	x += pixw + 4;	w -= pixw + 4;    }    drawItem( p, x, y, w, h,	    AlignCenter | ShowPrefix,	    cg, btn->isEnabled(),	    btn->pixmap(), btn->text(), -1, &cg.buttonText() );}QRect FlatStyle::comboButtonRect( int x, int y, int w, int h){    return QRect(x+2, y+2, w-4-13, h-4);}             QRect FlatStyle::comboButtonFocusRect( int x, int y, int w, int h){    return QRect(x+2, y+2, w-4-14, h-4);}void FlatStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,				     const QColorGroup &g, bool sunken,				     bool /*editable*/,				     bool enabled,				     const QBrush * /*fill*/ ){    x++; y++;    w-=2; h-=2;    p->setPen( g.foreground() );    p->setBrush( QBrush(NoBrush) );    p->drawRect( x, y, w, h );    p->setPen( g.background() );    p->drawRect( x+1, y+1, w-14, h-2 );    p->fillRect( x+2, y+2, w-16, h-4, g.brush( QColorGroup::Base ) );    QColorGroup cg( g );    if ( sunken ) {	cg.setColor( QColorGroup::ButtonText, g.button() );	cg.setColor( QColorGroup::Button, g.buttonText() );    }    drawArrow( p, QStyle::DownArrow, FALSE,	       x+w-13, y+1, 12, h-2, cg, enabled,	       &cg.brush( QColorGroup::Button ) );}void FlatStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,	int h, const QColorGroup &cg, bool on, bool down, bool enabled ){    static const QCOORD pts1[] = {              // dark lines	1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };    static const QCOORD pts4[] = {              // white lines	2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,	11,4, 10,3, 10,2 };    static const QCOORD pts5[] = {              // inner fill	4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };    p->eraseRect( x, y, w, h );    QPointArray a( QCOORDARRLEN(pts1), pts4 );    a.translate( x, y );    p->setPen( cg.foreground() );    p->drawPolyline( a );    a.setPoints( QCOORDARRLEN(pts4), pts1 );    a.translate( x, y );    p->setPen( cg.foreground() );    p->drawPolyline( a );    a.setPoints( QCOORDARRLEN(pts5), pts5 );    a.translate( x, y );    QColor fillColor = ( down || !enabled ) ? cg.button() : cg.base();    p->setPen( fillColor );    p->setBrush( fillColor  ) ;    p->drawPolygon( a );    if ( on ) {	p->setPen( NoPen );	p->setBrush( cg.text() );	p->drawRect( x+5, y+4, 2, 4 );	p->drawRect( x+4, y+5, 4, 2 );    }}void FlatStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,	const QColorGroup &cg, int state, bool down, bool enabled ){    QColorGroup mycg( cg );    mycg.setBrush( QColorGroup::Button, QBrush() );    QBrush fill;    drawButton( p, x, y, w, h, mycg, TRUE, 0 );    if ( down )	fill = cg.brush( QColorGroup::Button );    else	fill = cg.brush( enabled ? QColorGroup::Base : QColorGroup::Background );    mycg.setBrush( QColorGroup::Button, fill );    p->fillRect( x+1, y+1, w-2, h-2, fill );    if ( state != QButton::Off ) {	QPointArray a( 7*2 );	int i, xx, yy;	xx = x+3;	yy = y+5;	for ( i=0; i<3; i++ ) {	    a.setPoint( 2*i,   xx, yy );	    a.setPoint( 2*i+1, xx, yy+2 );	    xx++; yy++;	}	yy -= 2;	for ( i=3; i<7; i++ ) {	    a.setPoint( 2*i,   xx, yy );	    a.setPoint( 2*i+1, xx, yy+2 );	    xx++; yy--;	}	if ( state == QButton::NoChange ) {	    p->setPen( mycg.dark() );	} else {	    p->setPen( mycg.text() );	}	p->drawLineSegments( a );    }}#define HORIZONTAL	(sb->orientation() == QScrollBar::Horizontal)#define VERTICAL	!HORIZONTAL#define MOTIF_BORDER	2#define SLIDER_MIN	9 // ### motif says 6 but that's too small/*! \reimp */void FlatStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim ){    int maxLength;    int length = HORIZONTAL ? sb->width()  : sb->height();    int extent = HORIZONTAL ? sb->height() : sb->width();    if ( length > (extent - 1)*2 )	buttonDim = extent;    else	buttonDim = length/2 - 1;    sliderMin = 0;    maxLength  = length - buttonDim*2 + 2;     if ( sb->maxValue() == sb->minValue() ) {	sliderLength = maxLength;     } else {	sliderLength = (sb->pageStep()*maxLength)/			(sb->maxValue()-sb->minValue()+sb->pageStep());	uint range = sb->maxValue()-sb->minValue();	if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )	    sliderLength = SLIDER_MIN;	if ( sliderLength > maxLength )	    sliderLength = maxLength;     }    sliderMax = sliderMin + maxLength - sliderLength;}/*!\reimp */QStyle::ScrollControl FlatStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p ){    if ( !sb->rect().contains( p ) )	return NoScroll;    int sliderMin, sliderMax, sliderLength, buttonDim, pos;    scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );    if (sb->orientation() == QScrollBar::Horizontal)	pos = p.x();    else	pos = p.y();    if (pos < sliderStart)	return SubPage;    if (pos < sliderStart + sliderLength)	return Slider;    if (pos < sliderMax + sliderLength)	return AddPage;    if (pos < sliderMax + sliderLength + buttonDim)	return SubLine;    return AddLine;}/*! \reimp */void FlatStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl ){#define ADD_LINE_ACTIVE ( activeControl == AddLine )#define SUB_LINE_ACTIVE ( activeControl == SubLine )    QColorGroup g  = sb->colorGroup();    int sliderMin, sliderMax, sliderLength, buttonDim;    scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );    if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) ) {	p->setPen( g.foreground() );	p->setBrush( g.brush( QColorGroup::Mid ) );	p->drawRect( 0, 0, sb->width(), sb->height() );    }    if (sliderStart > sliderMax) { // sanity check	sliderStart = sliderMax;    }    int dimB = buttonDim;    QRect addB;    QRect subB;    QRect addPageR;    QRect subPageR;    QRect sliderR;    int addX, addY, subX, subY;    int length = HORIZONTAL ? sb->width()  : sb->height();    int extent = HORIZONTAL ? sb->height() : sb->width();    if ( HORIZONTAL ) {	subY = addY = ( extent - dimB ) / 2;	subX = length - dimB - dimB + 1;	addX = length - dimB;    } else {	subX = addX = ( extent - dimB ) / 2;	subY = length - dimB - dimB + 1;	addY = length - dimB;    }    int sliderEnd = sliderStart + sliderLength;    int sliderW = extent;    if ( HORIZONTAL ) {	subB.setRect( subX,subY,dimB,dimB );	addB.setRect( addX,addY,dimB,dimB );	subPageR.setRect( 0, 0, sliderStart+1, sliderW );	addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+2, sliderW );	sliderR .setRect( sliderStart, 0, sliderLength, sliderW );    } else {	subB.setRect( subX,subY,dimB,dimB );	addB.setRect( addX,addY,dimB,dimB );	subPageR.setRect( 0, 0, sliderW, sliderStart+1 );	addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+2 );	sliderR .setRect( 0, sliderStart, sliderW, sliderLength );    }    bool maxedOut = (sb->maxValue() == sb->minValue());    p->setPen( g.foreground() );    if ( controls & AddLine ) {	p->setBrush( ADD_LINE_ACTIVE ? g.foreground() : g.button() );	p->drawRect( addB.x(), addB.y(), addB.width(), addB.height() );	p->setPen( ADD_LINE_ACTIVE ? g.button() : g.foreground() );	QColorGroup cg( g );	if ( maxedOut )	    cg.setColor( QColorGroup::ButtonText, g.mid() );	else if ( ADD_LINE_ACTIVE )	    cg.setColor( QColorGroup::ButtonText, g.button() );	int xo = VERTICAL ? 1 : 0;	drawArrow( p, VERTICAL ? DownArrow : RightArrow, FALSE,		   addB.x()+2+xo, addB.y()+2, addB.width()-4-xo, addB.height()-4,		   cg, TRUE, &p->brush() );    }    if ( controls & SubLine ) {	p->setBrush( SUB_LINE_ACTIVE ? g.foreground() : g.button() );	p->drawRect( subB.x(), subB.y(), subB.width(), subB.height() );	p->setPen( SUB_LINE_ACTIVE ? g.button() : g.foreground() );	QColorGroup cg( g );	if ( maxedOut )	    cg.setColor( QColorGroup::ButtonText, g.mid() );	else if ( SUB_LINE_ACTIVE )	    cg.setColor( QColorGroup::ButtonText, g.button() );	int xo = VERTICAL ? 1 : 0;	drawArrow( p, VERTICAL ? UpArrow : LeftArrow, FALSE,		   subB.x()+2+xo, subB.y()+2, subB.width()-4-xo, subB.height()-4,		   cg, TRUE, &p->brush() );    }    p->setPen( g.foreground() );    p->setBrush( g.brush( QColorGroup::Mid ) );    if ( controls & SubPage )	p->drawRect( subPageR.x(), subPageR.y(), subPageR.width(), subPageR.height() );    if ( controls & AddPage && addPageR.y() < addPageR.bottom() &&	 addPageR.x() < addPageR.right() )	p->drawRect( addPageR.x(), addPageR.y(), addPageR.width(), addPageR.height() );    if ( controls & Slider ) {	QPoint bo = p->brushOrigin();	p->setBrushOrigin(sliderR.topLeft());	p->setPen( g.foreground() );	p->setBrush( g.button() );	p->drawRect( sliderR.x(), sliderR.y(), sliderR.width(), sliderR.height() );	p->setBrushOrigin(bo);	QColorGroup cg( g );	if ( maxedOut )	    cg.setColor( QColorGroup::ButtonText, g.mid() );	drawRiffles( p, sliderR.x(), sliderR.y(),		     sliderR.width(), sliderR.height(), cg, HORIZONTAL );    }    // ### perhaps this should not be able to accept focus if maxedOut?    if ( sb->hasFocus() && (controls & Slider) )	p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,			     sliderR.width()-5, sliderR.height()-5,			     sb->backgroundColor() );}void FlatStyle::drawRiffles( QPainter* p,  int x, int y, int w, int h,                      const QColorGroup &g, bool horizontal ){    if (!horizontal) {	if (h > 20) {	    y += (h-20)/2 ;	    h = 20;	}	if (h > 12) {	    int n = 3;	    int my = y+h/2-2;	    int i ;	    p->setPen(g.buttonText());	    for (i=0; i<n; i++) {		p->drawLine(x+4, my+3*i, x+w-5, my+3*i);	    }	}    } else {	if (w > 20) {	    x += (w-20)/2 ;	    w = 20;	}	if (w > 12) {	    int n = 3;	    int mx = x+w/2-4;	    int i ;	    p->setPen(g.buttonText());	    for (i=0; i<n; i++) {		p->drawLine(mx+3*i, y+4, mx + 3*i, y+h-5);	    }	}    }}int FlatStyle::sliderLength() const{    return 12;}void FlatStyle::drawSlider( QPainter *p, int x, int y, int w, int h,	const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow ){    int a = tickAbove ? 3 : 0;    int b = tickBelow ? 3 : 0;    p->setPen( g.foreground() );    p->setBrush( g.button() );    if ( o == Horizontal ) {	p->drawRect( x, y+a, w, h-a-b );

⌨️ 快捷键说明

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