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

📄 qmotifstyle.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}/*!\reimp */void QMotifStyle::drawSliderGroove( QPainter *p,				      int x, int y, int w, int h,				      const QColorGroup& g, QCOORD /*c */,				      Orientation ){    qDrawShadePanel( p, x, y, w, h, g, TRUE, 1, &g.brush( QColorGroup::Mid ) );}/*! \reimp*/int QMotifStyle::splitterWidth() const{    return QMAX( 10, QApplication::globalStrut().width() );}/*! \reimp*/void QMotifStyle::drawSplitter( QPainter *p, int x, int y, int w, int h,  const QColorGroup &g, Orientation orient){    const int motifOffset = 10;    int sw = splitterWidth();    if ( orient == Horizontal ) {	    QCOORD xPos = x + w/2;	    QCOORD kPos = motifOffset;	    QCOORD kSize = sw - 2;	    qDrawShadeLine( p, xPos, kPos + kSize - 1 ,			    xPos, h, g );	    qDrawShadePanel( p, xPos-sw/2+1, kPos,			     kSize, kSize, g, FALSE, 1,			     &g.brush( QColorGroup::Button ));	    qDrawShadeLine( p, xPos, 0, xPos, kPos, g );	} else {	    QCOORD yPos = y + h/2;	    QCOORD kPos = w - motifOffset - sw;	    QCOORD kSize = sw - 2;	    qDrawShadeLine( p, 0, yPos, kPos, yPos, g );	    qDrawShadePanel( p, kPos, yPos-sw/2+1,			     kSize, kSize, g, FALSE, 1,			     &g.brush( QColorGroup::Button ));	    qDrawShadeLine( p, kPos + kSize -1, yPos,			    w, yPos, g );	}}/*! \reimp*/void QMotifStyle::polishPopupMenu( QPopupMenu* p){    p->setLineWidth( defaultFrameWidth() );    p->setMouseTracking( FALSE );    if ( !p->testWState( WState_Polished ) )	p->setCheckable( FALSE );    p->setLineWidth( 2 );}static const int motifItemFrame		= 2;	// menu item frame widthstatic const int motifSepHeight		= 2;	// separator item heightstatic const int motifItemHMargin	= 3;	// menu item hor text marginstatic const int motifItemVMargin	= 2;	// menu item ver text marginstatic const int motifArrowHMargin	= 6;	// arrow horizontal marginstatic const int motifTabSpacing	= 12;	// space between text and tabstatic const int motifCheckMarkHMargin	= 2;	// horiz. margins of check markstatic const int motifCheckMarkSpace    = 12;/*! \reimp*/void QMotifStyle::drawCheckMark( QPainter *p, int x, int y, int w, int h,				 const QColorGroup &g,				 bool act, bool dis ){    const int markW = 6;    const int markH = 6;    int posX = x + ( w - markW )/2 - 1;    int posY = y + ( h - markH )/2;    if ( defaultFrameWidth() < 2) {	// Could do with some optimizing/caching...	QPointArray a( 7*2 );	int i, xx, yy;	xx = posX;	yy = 3 + posY;	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 ( dis && !act ) {	    int pnt;	    p->setPen( g.highlightedText() );	    QPoint offset(1,1);	    for ( pnt = 0; pnt < (int)a.size(); pnt++ )		a[pnt] += offset;	    p->drawLineSegments( a );	    for ( pnt = 0; pnt < (int)a.size(); pnt++ )		a[pnt] -= offset;	}	p->setPen( g.text() );	p->drawLineSegments( a );	qDrawShadePanel( p, posX-2, posY-2, markW+4, markH+6, g, TRUE,			 defaultFrameWidth());    }    else {	qDrawShadePanel( p, posX, posY, markW, markH, g, TRUE,		    defaultFrameWidth(), &g.brush( QColorGroup::Mid ) );    }}/*! \reimp*/int QMotifStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /* fm */){    int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm    if ( mi->isSeparator() )	return 10; // arbitrary    else if ( mi->pixmap() )	w += mi->pixmap()->width();	// pixmap only    if ( !mi->text().isNull() ) {	if ( mi->text().find('\t') >= 0 )	// string contains tab	    w += motifTabSpacing;    }    if ( checkable )	maxpmw = QMAX( maxpmw, motifCheckMarkSpace );    w += maxpmw;    if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)	w += motifCheckMarkHMargin; // add space to separate the columns    return w;}/*! \reimp*/int QMotifStyle::popupMenuItemHeight( bool /* checkable*/, QMenuItem* mi, const QFontMetrics& fm ){    int h = 0;    if ( mi->isSeparator() ) {			// separator height	h = motifSepHeight;    } else if ( mi->pixmap() ) {		// pixmap height	h = mi->pixmap()->height() + 2*motifItemFrame;    } else {					// text height	h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame;    }    if ( !mi->isSeparator() && mi->iconSet() != 0 ) {	h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame );	h += 2;				// Room for check rectangle    }    if ( mi->custom() )	h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame );    return h;}/*! \reimp*/void QMotifStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,				     const QPalette& pal,				     bool act, bool enabled, int x, int y, int w, int h){    const QColorGroup & g = pal.active();    bool dis	  = !enabled;    QColorGroup itemg = dis ? pal.disabled() : pal.active();    if ( checkable )	maxpmw = QMAX( maxpmw, motifCheckMarkSpace );    int checkcol	  =     maxpmw;    if ( mi && mi->isSeparator() ) {			// draw separator	p->setPen( g.dark() );	p->drawLine( x, y, x+w, y );	p->setPen( g.light() );	p->drawLine( x, y+1, x+w, y+1 );	return;    }    int pw = motifItemFrame;    if ( act && !dis ) {			// active item frame	if (defaultFrameWidth() > 1)	    qDrawShadePanel( p, x, y, w, h, g, FALSE, pw,			     &g.brush( QColorGroup::Button ) );	else	    qDrawShadePanel( p, x+1, y+1, w-2, h-2, g, TRUE, 1,			     &g.brush( QColorGroup::Button ) );    }    else				// incognito frame	p->fillRect(x, y, w, h, g.brush( QColorGroup::Button ));    if ( !mi )	return;    if ( mi->isChecked() ) {	if ( mi->iconSet() ) {	    qDrawShadePanel( p, x+motifItemFrame, y+motifItemFrame, checkcol, h-2*motifItemFrame,			     g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );	}    } else if ( !act ) {	p->fillRect(x+motifItemFrame, y+motifItemFrame, checkcol, h-2*motifItemFrame,		    g.brush( QColorGroup::Button ));    }    if ( mi->iconSet() ) {		// draw iconset	QIconSet::Mode mode = QIconSet::Normal; // no disabled icons in Motif	if (act && !dis )	    mode = QIconSet::Active;	QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );	int pixw = pixmap.width();	int pixh = pixmap.height();	QRect cr( x + motifItemFrame, y+motifItemFrame, checkcol, h-2*motifItemFrame );	QRect pmr( 0, 0, pixw, pixh );	pmr.moveCenter( cr.center() );	p->setPen( itemg.text() );	p->drawPixmap( pmr.topLeft(), pixmap );    } else  if ( checkable ) {	// just "checking"...	int mw = checkcol;	int mh = h - 2*motifItemFrame;	if ( mi->isChecked() ) {	    drawCheckMark( p, x+motifItemFrame,			   y+motifItemFrame, mw, mh, itemg, act, dis );	}    }    p->setPen( g.buttonText() );    QColor discol;    if ( dis ) {	discol = itemg.text();	p->setPen( discol );    }    int xm = motifItemFrame + checkcol + motifItemHMargin;    if ( mi->custom() ) {	int m = motifItemVMargin;	p->save();	mi->custom()->paint( p, itemg, act, enabled,			     x+xm, y+m, w-xm-tab+1, h-2*m );	p->restore();    }    QString s = mi->text();    if ( !s.isNull() ) {			// draw text	int t = s.find( '\t' );	int m = motifItemVMargin;	const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;	if ( t >= 0 ) {				// draw tab text	    p->drawText( x+w-tab-motifItemHMargin-motifItemFrame,			 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );	}	p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );    } else if ( mi->pixmap() ) {			// draw pixmap	QPixmap *pixmap = mi->pixmap();	if ( pixmap->depth() == 1 )	    p->setBackgroundMode( OpaqueMode );	p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );	if ( pixmap->depth() == 1 )	    p->setBackgroundMode( TransparentMode );    }    if ( mi->popup() ) {			// draw sub menu arrow	int dim = (h-2*motifItemFrame) / 2;	if ( act ) {	    drawArrow( p, RightArrow,		       mi->isEnabled(),		       x+w - motifArrowHMargin - motifItemFrame - dim,  y+h/2-dim/2,		       dim, dim, g,		       mi->isEnabled() );	} else {	    drawArrow( p, RightArrow,		       FALSE,		       x+w - motifArrowHMargin - motifItemFrame - dim,  y+h/2-dim/2,		       dim, dim, g, mi->isEnabled() );	}    }}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 +(ew-awh)/2;}/*! \reimp */void QMotifStyle::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 ( 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 */QRect QMotifStyle::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()-2-ew, r.height()-2);}/*! \reimp */QRect QMotifStyle::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);}#endif

⌨️ 快捷键说明

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