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

📄 qpestyle.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    switch ( contents ) {    case CT_PopupMenuItem:	{	    if ( !widget || data.isDefault() )		break;	    sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );	    sz = QSize( sz.width(), sz.height()-2 );	    break;	}    default:	sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );	break;    }    return sz;}#else#include <qfontmetrics.h>#include <qpalette.h>#include <qdrawutil.h>#include <qscrollbar.h>#include <qbutton.h>#include <qframe.h>#include <qtabbar.h>#define INCLUDE_MENUITEM_DEF#include <qmenudata.h>#include <qpopupmenu.h>/*! */QPEStyle::QPEStyle(){#if QT_VERSION < 0x030000    setButtonMargin(buttonMargin());    setScrollBarExtent(scrollBarExtent().width(),scrollBarExtent().height());#endif}/*! */QPEStyle::~QPEStyle(){}/*! */int QPEStyle::buttonMargin() const{    return 2;}/*! */QSize QPEStyle::scrollBarExtent() const{    return QSize(13,13);}/*! */void QPEStyle::polish ( QPalette & ){}class QStyleHackWidget : public QWidget {public:    static void setGlobalBrushOrigin(QWidget *w) {	((QStyleHackWidget*)w)->setWState(WState_GlobalBrushOrigin);    }    static void clearGlobalBrushOrigin(QWidget *w) {	((QStyleHackWidget*)w)->clearWState(WState_GlobalBrushOrigin);    }};/*! */void QPEStyle::polish( QWidget *w ){    if ( w->inherits( "QListBox" ) ||	 w->inherits( "QListView" ) ||	 w->inherits( "QPopupMenu" ) ||	 w->inherits( "QSpinBox" ) ) {	QFrame *f = (QFrame *)w;	f->setFrameShape( QFrame::StyledPanel );	f->setLineWidth( 1 );    }    if (w->backgroundMode() == QWidget::PaletteBackground) {	QWidget *p = w->parentWidget();	if (!p || strcmp(p->name(), "qt_viewport"))	    w->setBackgroundOrigin(QWidget::AncestorOrigin);    }    QStyleHackWidget::setGlobalBrushOrigin(w);}/*! */void QPEStyle::unPolish( QWidget *w ){    if ( w->inherits( "QListBox" ) ||	 w->inherits( "QListView" ) ||	 w->inherits( "QPopupMenu" ) ||	 w->inherits( "QSpinBox" ) ) {	QFrame *f = (QFrame *)w;	f->setFrameShape( QFrame::StyledPanel );	f->setLineWidth( 2 );    }    w->setBackgroundOrigin(QWidget::WidgetOrigin);    QStyleHackWidget::clearGlobalBrushOrigin(w);}/*! */int QPEStyle::defaultFrameWidth() const{    return 1;}/*! */void QPEStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,			    const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill ){    qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );}/*! */void QPEStyle::drawButton( QPainter *p, int x, int y, int w, int h,                                const QColorGroup &g, bool sunken, const QBrush* fill ){    QPen oldPen = p->pen();    if ( sunken )	p->setPen( g.dark() );    else	p->setPen( g.light() );    int x2 = x+w-1;    int y2 = y+h-1;    p->drawLine( x, y, x, y2 );    p->drawLine( x, y, x2, y );    if ( sunken )	p->setPen( g.light() );    else	p->setPen( g.dark() );    p->drawLine( x2, y, x2, y2 );    p->drawLine( x, y2, x2, y2 );    p->setPen( oldPen );    p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) );}/*! */void QPEStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h ){    p->fillRect( x, y, w, h, color1 );}/*! */void QPEStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,                                const QColorGroup &g, bool sunken, const QBrush* fill ){    drawButton( p, x, y, w, h, g, sunken, fill );}/*! */QRect QPEStyle::comboButtonRect( int x, int y, int w, int h){    return QRect(x+1, y+1, w-2-14, h-2);}             /*! */QRect QPEStyle::comboButtonFocusRect( int x, int y, int w, int h){    return QRect(x+2, y+2, w-4-14, h-4);}/*! */void QPEStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,				     const QColorGroup &g, bool sunken,				     bool /*editable*/,				     bool enabled,				     const QBrush *fill ){    drawBevelButton( p, x, y, w, h, g, FALSE, fill );    drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill );    drawArrow( p, QStyle::DownArrow, sunken,	       x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled,	       &g.brush( QColorGroup::Button ) );}/*! */void QPEStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,	int h, const QColorGroup & g, 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), pts1 );    a.translate( x, y );    p->setPen( g.dark() );    p->drawPolyline( a );    a.setPoints( QCOORDARRLEN(pts4), pts4 );    a.translate( x, y );    p->setPen( g.light() );    p->drawPolyline( a );    a.setPoints( QCOORDARRLEN(pts5), pts5 );    a.translate( x, y );    QColor fillColor = ( down || !enabled ) ? g.button() : g.base();    p->setPen( fillColor );    p->setBrush( fillColor  ) ;    p->drawPolygon( a );    if ( on ) {	p->setPen( NoPen );	p->setBrush( g.text() );	p->drawRect( x+5, y+4, 2, 4 );	p->drawRect( x+4, y+5, 4, 2 );    }}/*! */void QPEStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,	const QColorGroup & g, int state, bool down, bool enabled ){    QBrush fill;    if ( state == QButton::NoChange ) {	QBrush b = p->brush();	QColor c = p->backgroundColor();	p->setBackgroundMode( TransparentMode );	p->setBackgroundColor( green );	fill = QBrush(g.base(), Dense4Pattern);	p->setBackgroundColor( c );	p->setBrush( b );    } else if ( down )	fill = g.brush( QColorGroup::Button );    else	fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background );    drawPanel( p, x, y, w, h, g, TRUE, 1, &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( g.dark() );	} else {	    p->setPen( g.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 QPEStyle::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;     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 QPEStyle::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 QPEStyle::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->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid ));    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;	addX = length - dimB;    } else {	subX = addX = ( extent - dimB ) / 2;	subY = length - dimB - dimB;	addY = length - dimB;    }    int sliderEnd = sliderStart + sliderLength;    int sliderW = extent;    if ( HORIZONTAL ) {	subB.setRect( subX,subY+1,dimB,dimB-1 );	addB.setRect( addX,addY+1,dimB,dimB-1 );	subPageR.setRect( 0, 0,			  sliderStart+1, sliderW );	addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW );	sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 );    } else {	subB.setRect( subX+1,subY,dimB-1,dimB );	addB.setRect( addX+1,addY,dimB-1,dimB );	subPageR.setRect( 0, 0, sliderW,			  sliderStart+1 );	addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 );	sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength );    }    bool maxedOut = (sb->maxValue() == sb->minValue());    if ( controls & AddLine ) {	drawBevelButton( p, addB.x(), addB.y(),			 addB.width(), addB.height(), g,			 ADD_LINE_ACTIVE);	p->setPen(g.shadow());	drawArrow( p, VERTICAL ? DownArrow : RightArrow,		   FALSE, addB.x()+2, addB.y()+2,		   addB.width()-4, addB.height()-4, g, !maxedOut,				     &g.brush( QColorGroup::Button ));    }    if ( controls & SubLine ) {	drawBevelButton( p, subB.x(), subB.y(),			 subB.width(), subB.height(), g,			 SUB_LINE_ACTIVE );	p->setPen(g.shadow());	drawArrow( p, VERTICAL ? UpArrow : LeftArrow,		    FALSE, subB.x()+2, subB.y()+2,		   subB.width()-4, subB.height()-4, g, !maxedOut,				     &g.brush( QColorGroup::Button ));    }    if ( controls & SubPage )	p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(),		    subPageR.height(), g.brush( QColorGroup::Mid ));    if ( controls & AddPage )	p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(),		     addPageR.height(), g.brush( QColorGroup::Mid ));    if ( controls & Slider ) {	QPoint bo = p->brushOrigin();	if ( !sb->testWState(WState_GlobalBrushOrigin) )	    p->setBrushOrigin(sliderR.topLeft());        drawBevelButton( p, sliderR.x(), sliderR.y(),                         sliderR.width(), sliderR.height(), g,                         FALSE, &g.brush( QColorGroup::Button ) );	p->setBrushOrigin(bo);        drawRiffles( p, sliderR.x(), sliderR.y(),                     sliderR.width(), sliderR.height(), g, 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,

⌨️ 快捷键说明

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