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

📄 qsgistyle.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    drawBevelButton( p, x+1, y+3, w-7, h-7, g,            enabled && down, &g.brush( QColorGroup::Button) );    if (s != QButton::Off)	    drawCheckMark( p, x+w-18, y+h-14, w, h, g, s==QButton::On, !enabled );    p->setPen( oldPen );}/*!    Draws a fancy red checkmark indicating the state of choice    in checkboxes or checkable menu items.*/voidQSGIStyle::drawCheckMark( QPainter* p, int x, int y, int /*w*/, int /*h*/,			  const QColorGroup &g, bool act, bool dis ){    static const QCOORD check_mark[] = {	14,0,  10,0,  11,1,  8,1,  9,2,	 7,2,  8,3,  6,3,	7,4,  1,4,  6,5,  1,5,	6,6,  3,6,  5,7,  4,7,	5,8,  5,8,  4,3,  2,3,	3,2,  3,2 };    QPen oldPen = p->pen();    QPointArray amark;    amark = QPointArray( sizeof(check_mark)/(sizeof(QCOORD)*2), check_mark );    amark.translate( x+1, y+1 );    if (act) {	p->setPen( dis ? g.dark() : g.shadow() );	p->drawLineSegments( amark );	amark.translate( -1, -1 );	p->setPen( dis ? g.dark() : QColor(255,0,0) );	p->drawLineSegments( amark );	p->setPen( oldPen );    } else    {	p->setPen( dis ? g.dark() : g.mid() );	p->drawLineSegments( amark );	amark.translate( -1, -1 );	p->setPen( dis ? g.dark() : QColor(230,120,120) );	p->drawLineSegments( amark );	p->setPen( oldPen );    }}/*!    Draws a mask for an indicator in state /e s.  \sa drawIndicator()*/voidQSGIStyle::drawIndicatorMask( QPainter* p, int x, int y, int w, int h, int s ){    QPen oldPen = p->pen();    QBrush oldBrush = p->brush();    p->setPen( color1 );    p->setBrush( color1 );    p->fillRect( x, y, w, h, QBrush(color0) );    p->fillRect( x+2, y+3, w-7, h-7, QBrush(color1) );    if (s != QButton::Off ) {        static const QCOORD check_mark[] = {	        14,0,  10,0,  11,1,  8,1,  9,2,	 7,2,  8,3,  6,3,	        7,4,  1,4,  6,5,  1,5,	6,6,  3,6,  5,7,  4,7,	        5,8,  5,8,  4,3,  2,3,	3,2,  3,2 };        QPointArray amark;        amark = QPointArray( sizeof(check_mark)/(sizeof(QCOORD)*2), check_mark );        amark.translate( x+w-18, y+h-14 );        p->drawLineSegments( amark );        amark.translate( +1, +1 );        p->drawLineSegments( amark );    }    p->setBrush( oldBrush );    p->setPen( oldPen );}/*! \reimp*/QSizeQSGIStyle::exclusiveIndicatorSize() const{    return QSize(12,12);}/*!    Draws an interface element used to show the state    of an exclusive choice as used in a radio button.*/void QSGIStyle::drawExclusiveIndicator( QPainter* p,					int x, int y, int w, int h, const QColorGroup &g,					bool on, bool down, bool enabled ){    p->save();    p->eraseRect( x, y, w, h );    p->translate( x, y );    p->setPen( g.button() );    p->setBrush( g.button() );    QPointArray a;    a.setPoints( 4, 5,0, 11,6, 6,11, 0,5);    p->drawPolygon( a );    p->setPen( g.dark() );    p->drawLine( 0,5, 5,0 );    p->drawLine( 6,0, 11,5 );    p->setPen( down ? g.light() : g.dark().dark(200) );    p->drawLine( 11,6, 6,11 );    p->drawLine( 5,11, 0,6 );    p->drawLine( 2,7, 5,10 );    p->drawLine( 6,10, 9,7 );    p->setPen( g.light() );    p->drawLine( 2,5, 5,2 );    if (on) {	p->setPen( enabled ? blue : darkGray );	p->setBrush( enabled ? blue : darkGray  );	a.setPoints(3, 6,2, 8,4, 6,6 );	p->drawPolygon( a );	p->setBrush( NoBrush );	p->setPen( g.shadow() );	p->drawLine( 7,7, 9,5 );    } else {	p->drawLine( 6,2, 9,5 );    }    p->restore();}/*!  Draws the mask of a mark indicating the state of an exclusive choice*/voidQSGIStyle::drawExclusiveIndicatorMask( QPainter *p, int x, int y,                int /* w*/, int /*h*/, bool /*on*/ ){    p->save();    QPen oldPen = p->pen();    QBrush oldBrush = p->brush();    p->setPen( color1 );    p->setBrush( color1 );    QPointArray a;    a.setPoints( 8, 0,5, 5,0, 6,0, 11,5, 11,6, 6,11, 5,11, 0,6 );    a.translate( x, y );    p->drawPolygon( a );    p->setBrush( oldBrush );    p->setPen( oldPen );    p->restore();}static int get_combo_extra_width( int h, int *return_awh=0 ){    int awh;    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;}/*!    Draws a raised shape used as a combobox. */voidQSGIStyle::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 );    drawBevelButton( p, x, y, w, h, g, FALSE, &fill );    QBrush arrow = g.brush( QColorGroup::Dark );    drawArrow( p, DownArrow, FALSE, ax, ay, awh, awh, g, TRUE );    p->fillRect( ax, sy, awh, sh, arrow );    if ( editable ) {	QRect r( comboButtonRect( x, y, w, h ) );	qDrawShadePanel( p, QRect( r.x()-1, r.y()-1, r.width()+2, r.height()+2 ),			 g, TRUE, 1, &fill );    }}/*! \reimp */QRectQSGIStyle::comboButtonRect( int x, int y, int w, int h){    QRect r = buttonRect( x, y, w, h );    int ew = get_combo_extra_width( r.height() );    return QRect(r.x()+1, r.y()+1, r.width()-6-ew, r.height()-2);}/*! \reimp */QRectQSGIStyle::comboButtonFocusRect( int x, int y, int w, int h){    int awh, ax, ay, sh, sy, dh, ew;    get_combo_parameters( buttonRect( x, y, w, h ),			  ew, awh, ax, ay, sh, dh, sy );    return QRect(ax-2, ay-2, awh+4, awh+sh+dh+4);}#define HORIZONTAL	(sb->orientation() == QScrollBar::Horizontal)#define VERTICAL	!HORIZONTAL#define SGI_BORDER	1#define SLIDER_MIN	9 //### motif says 6 but that's too small#define ADD_LINE_ACTIVE ( activeControl == AddLine )#define SUB_LINE_ACTIVE ( activeControl == SubLine )/*!\reimp */voidQSGIStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int&buttonDim ){    int maxLength;    int b = SGI_BORDER;    int length = HORIZONTAL ? sb->width()  : sb->height();    int extent = HORIZONTAL ? sb->height() : sb->width();    if ( length > ( extent - b*2 - 1 )*2 + b*2 )	buttonDim = extent - b*2;    else	buttonDim = ( length - b*2 )/2 - 1;    sliderMin = b + buttonDim;    maxLength  = length - b*2 - buttonDim*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;}static QRect scrollerStartOldPos(1, -1, 1, -1);static bool scrollerMoving = FALSE;/*!    Draws scrollbar controls in SGI-like style.*/voidQSGIStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb,				  int sliderStart, uint controls, uint activeControl ){    ( (QScrollBar*)sb )->setBackgroundMode( QWidget::PaletteButton );    QColorGroup g = sb->colorGroup();    QColor lazyButton;    lazyButton = QApplication::palette().active().button();    int sliderMin, sliderMax, sliderLength, buttonDim;    scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );    if ( sliderStart > sliderMax )	sliderStart = sliderMax;    int b = SGI_BORDER;    int dimB = buttonDim;    QRect addB;    QRect subB;    QRect addPageR;    QRect subPageR;    QRect sliderR;    int addX, addY, subX, subY, sliderM;    int length = HORIZONTAL ? sb->width() : sb->height();    int extent = HORIZONTAL ? sb->height() : sb->width();    if ( HORIZONTAL ) {	subY = addY = ( extent - dimB ) / 2;	subX = b;	addX = length - dimB - b;    } else {	subX = addX = ( extent - dimB ) / 2;	subY = b;	addY = length - dimB - b;    }    subB.setRect( subX,subY,dimB,dimB );    addB.setRect( addX,addY,dimB,dimB );    int sliderEnd = sliderStart + sliderLength;    int sliderW = extent - b*2;    if ( HORIZONTAL ) {	subPageR.setRect( subB.right() + 1, b,			  sliderStart - subB.right() - 1 , sliderW );	addPageR.setRect( sliderEnd, b, addX - sliderEnd, sliderW );	sliderR .setRect( sliderStart, b, sliderLength, sliderW );    } else {	subPageR.setRect( b, subB.bottom() + 1, sliderW,			  sliderStart - subB.bottom() - 1 );	addPageR.setRect( b, sliderEnd, sliderW, addY - sliderEnd );	sliderR .setRect( b, sliderStart, sliderW, sliderLength );    }    sliderM = sliderStart + sliderLength / 2;    bool isScrollBarUpToDate = FALSE;    if ( repaintByMouseMove ) {	if ( addB.contains( mousePos ) ) {	    isScrollBarUpToDate = ( activeScrollBarElement == AddLine );	    activeScrollBarElement = AddLine;	} else if ( subB.contains( mousePos )) {	    isScrollBarUpToDate = ( activeScrollBarElement == SubLine );	    activeScrollBarElement = SubLine;	} else if ( sliderR.contains( mousePos )) {	    isScrollBarUpToDate = ( activeScrollBarElement == Slider );	    activeScrollBarElement = Slider;	} else {	    activeScrollBarElement = 0;	}    } else    {	activeScrollBarElement = 0;    }    if ( !isScrollBarUpToDate )    {	QBrush fill( lazyButton );	if ( controls & AddLine && addB.isValid() ) {	    drawButton( p, addB.x(), addB.y(),			addB.width(), addB.height(), g, FALSE,			(deviceUnderMouse == p->device()			&& addB.contains(mousePos)			&& !ADD_LINE_ACTIVE ) ?			    &g.brush( QColorGroup::Midlight ) : &fill );	    drawArrow( p, VERTICAL ? DownArrow : RightArrow,		       ADD_LINE_ACTIVE, addB.x()+2, addB.y()+2,		       addB.width()-4, addB.height()-4, g, TRUE );	}	if ( controls & SubLine && subB.isValid() ) {	    drawButton( p, subB.x(), subB.y(),			subB.width(), subB.height(), g, FALSE,			(deviceUnderMouse == p->device()			&& subB.contains(mousePos)			&& !SUB_LINE_ACTIVE ) ?			    &g.brush( QColorGroup::Midlight ) : &fill );	    drawArrow( p, VERTICAL ? UpArrow : LeftArrow,		       SUB_LINE_ACTIVE, subB.x()+2, subB.y()+2,		       subB.width()-4, subB.height()-4, g, TRUE );	}	if (sb->backgroundPixmap() )	    fill = QBrush( g.mid(), *sb->backgroundPixmap() );	if ( scrollerMoving )	    p->setClipRegion( QRegion(subPageR) - QRegion(scrollerStartOldPos) - QRegion(sliderR) );	if ( controls & SubPage && subPageR.isValid() )	    qDrawShadePanel( p, subPageR, g, FALSE, 1, &fill );	if ( scrollerMoving )	    p->setClipRegion( QRegion(addPageR) - QRegion(scrollerStartOldPos) - QRegion(sliderR) );	if ( controls & AddPage && addPageR.isValid() )	    qDrawShadePanel( p, addPageR, g, FALSE, 1, &fill );	if ( activeControl & Slider) {	    if ( scrollerMoving) {		p->setClipRegion( QRegion(scrollerStartOldPos) - QRegion(sliderR) );		qDrawShadePanel( p, scrollerStartOldPos, g, TRUE, 2, &g.brush( QColorGroup::Dark) );	    } else {		scrollerStartOldPos = sliderR;		scrollerMoving = TRUE;	    }	}	if ( controls & Slider && sliderR.isValid() ) {	    if ( scrollerMoving && activeControl != Slider ) {		p->setClipping( FALSE );		scrollerMoving = FALSE;		qDrawShadePanel( p, subPageR, g, FALSE, 1, &fill );		qDrawShadePanel( p, addPageR, g, FALSE, 1, &fill );	    }	    QRegion lineRegion( sliderR );	    if ( sliderLength >= 20 ) {		if ( HORIZONTAL ) {		    lineRegion -= QRegion( sliderM-4, sliderR.y()+2, 0, sliderR.height()-5 );		    lineRegion -= QRegion( sliderM, sliderR.y()+2, 0, sliderR.height()-5 );		    lineRegion -= QRegion( sliderM+4, sliderR.y()+2, 0, sliderR.height()-5 );		} else {		    lineRegion -= QRegion( sliderR.x()+2, sliderM-4, sliderR.width()-5, 0 );		    lineRegion -= QRegion( sliderR.x()+2, sliderM, sliderR.width()-5, 0 );		    lineRegion -= QRegion( sliderR.x()+2, sliderM+4, sliderR.width()-5, 0 );		}	    }	    p->setClipRegion( lineRegion );	    QPoint bo = p->brushOrigin();	    p->setBrushOrigin(sliderR.topLeft());	    if ( sliderR.isValid() ) {		if ( deviceUnderMouse == p->device() && sliderR.contains(mousePos))		    drawBevelButton( p, sliderR.x(), sliderR.y(),				 sliderR.width(), sliderR.height(), g,				 FALSE, &g.brush( QColorGroup::Midlight ) );		else		    drawBevelButton( p, sliderR.x(), sliderR.y(),				 sliderR.width(), sliderR.height(), g );		if (sliderLength >= 20 ) {		    p->setClipping( FALSE );		    if ( HORIZONTAL ) {			drawSeparator( p, sliderM-5, sliderR.y()+2, sliderM-5, sliderR.y()+sliderR.height()-3, g );			drawSeparator( p, sliderM-1, sliderR.y()+2, sliderM-1, sliderR.y()+sliderR.height()-3, g );			drawSeparator( p, sliderM+3, sliderR.y()+2, sliderM+3, sliderR.y()+sliderR.height()-3, g );		    } else {			drawSeparator( p, sliderR.x()+2, sliderM-5, sliderR.x()+sliderR.width()-3, sliderM-5, g );			drawSeparator( p, sliderR.x()+2, sliderM-1, sliderR.x()+sliderR.width()-3, sliderM-1, g );			drawSeparator( p, sliderR.x()+2, sliderM+3, sliderR.x()+sliderR.width()-3, sliderM+3, g );

⌨️ 快捷键说明

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