📄 qplatinumstyle.cpp
字号:
drawArrow( p, DownArrow, FALSE, x+w-dx-1, y+2, dx, h-4, btn->colorGroup(), 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, btn->colorGroup(), btn->isEnabled(), btn->pixmap(), btn->text(), -1, on?&btn->colorGroup().brightText():&btn->colorGroup().buttonText());}#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 QPlatinumStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim ){ int maxLength; int b = 0; 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 + 1; //b + buttonDim; maxLength = length - b*2 - buttonDim*2 - 1; 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; } /* Old macintosh, but they changed it for 8.5 if (maxLength >= buttonDim) sliderLength = buttonDim; // macintosh */ sliderMax = sliderMin + maxLength - sliderLength;}/*! \reimp */void QPlatinumStyle::drawScrollBarBackground( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool horizontal, const QBrush* fill){ QPen oldPen = p->pen(); if (w < 3 || h < 3) { p->fillRect(x, y, w, h, fill?*fill:g.brush( QColorGroup::Mid )); p->setPen(g.shadow()); p->drawRect(x, y, w, h); p->setPen(oldPen); return; } if (horizontal) { p->fillRect(x+2, y+2, w-2, h-4,fill?*fill:g.brush( QColorGroup::Mid )); // the dark side p->setPen(g.dark().dark()); p->drawLine(x, y, x+w-1, y); p->setPen(g.shadow()); p->drawLine(x, y, x, y+h-1); p->setPen(g.mid().dark()); p->drawLine(x+1, y+1, x+w-1, y+1); p->drawLine(x+1, y+1, x+1, y+h-2); // the bright side! p->setPen(g.button()); p->drawLine(x+1, y+h-2 ,x+w-1, y+h-2); //p->drawLine(x+w-2, y+1, x+w-2, y+h-2); p->setPen(g.shadow()); p->drawLine(x, y+h-1,x+w-1, y+h-1); // p->drawLine(x+w-1, y, x+w-1, y+h-1); } else { p->fillRect(x+2, y+2, w-4, h-2,fill?*fill:g.brush( QColorGroup::Mid )); // the dark side p->setPen(g.dark().dark()); p->drawLine(x, y, x+w-1, y); p->setPen(g.shadow()); p->drawLine(x, y, x, y+h-1); p->setPen(g.mid().dark()); p->drawLine(x+1, y+1, x+w-2, y+1); p->drawLine(x+1, y+1, x+1, y+h-1); // the bright side! p->setPen(g.button()); //p->drawLine(x+1, y+h-2 ,x+w-2, y+h-2); p->drawLine(x+w-2, y+1, x+w-2, y+h-1); p->setPen(g.shadow()); //p->drawLine(x, y+h-1,x+w-1, y+h-1); p->drawLine(x+w-1, y, x+w-1, y+h-1); } p->setPen(oldPen);}/*!\reimp */QStyle::ScrollControl QPlatinumStyle::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;/* if (pos < buttonDim) return SubLine; if (pos < 2 * buttonDim) return AddLine; if (pos < sliderStart) return SubPage; if (pos > sliderStart + sliderLength) return AddPage; return Slider;*/}/*! \reimp */void QPlatinumStyle::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 (sliderStart > sliderMax) { // sanity check sliderStart = sliderMax; } int b = 0; 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 - b; //b; addX = length - dimB - b;// subY = addY = ( extent - dimB ) / 2;// subX = b;// addX = b + dimB; //length - dimB - b; } else { subX = addX = ( extent - dimB ) / 2; subY = length - dimB - dimB - b; //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( b + 1, b, sliderStart - 1 , sliderW ); addPageR.setRect( sliderEnd, b, subX - sliderEnd, sliderW ); sliderR .setRect( sliderStart, b, sliderLength, sliderW );// 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, b + 1, sliderW, sliderStart - b - 1 ); addPageR.setRect( b, sliderEnd, sliderW, subY - sliderEnd ); sliderR .setRect( b, sliderStart, sliderW, 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()); p->drawRect( addB ); drawArrow( p, VERTICAL ? DownArrow : RightArrow, FALSE, addB.x()+2, addB.y()+2, addB.width()-4, addB.height()-4, g, !maxedOut, ADD_LINE_ACTIVE ? &g.brush( QColorGroup::Mid ) : &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()); p->drawRect( subB ); drawArrow( p, VERTICAL ? UpArrow : LeftArrow, FALSE, subB.x()+2, subB.y()+2, subB.width()-4, subB.height()-4, g, !maxedOut, SUB_LINE_ACTIVE ? &g.brush( QColorGroup::Mid ) : &g.brush( QColorGroup::Button )); } if ( controls & SubPage ) drawScrollBarBackground( p, subPageR.x(), subPageR.y(), subPageR.width(), subPageR.height(), g, HORIZONTAL ); if ( controls & AddPage ) drawScrollBarBackground( p, addPageR.x(), addPageR.y(), addPageR.width(), addPageR.height(), g, HORIZONTAL ); if ( controls & Slider ) { QPoint bo = p->brushOrigin(); 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); p->setPen(g.shadow()); p->drawRect( sliderR ); } // ### 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() );}/*! draw the nifty Macintosh decoration used on sliders */void QPlatinumStyle::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 > 8) { int n = h / 4; int my = y+h/2-n; int i ; p->setPen(g.light()); for (i=0; i<n; i++) { p->drawLine(x+3, my+2*i, x+w-5, my+2*i); } p->setPen(g.dark()); my++; for (i=0; i<n; i++) { p->drawLine(x+4, my+2*i, x+w-4, my+2*i); } } } else { if (w > 20) { x += (w-20)/2 ; w = 20; } if (w > 8) { int n = w / 4; int mx = x+w/2-n; int i ; p->setPen(g.light()); for (i=0; i<n; i++) { p->drawLine(mx+2*i, y+3, mx + 2*i, y+h-5); } p->setPen(g.dark()); mx++; for (i=0; i<n; i++) { p->drawLine(mx+2*i, y+4, mx + 2*i, y+h-4); } } }}/*! \reimp */void QPlatinumStyle::drawIndicator( QPainter* p, int x, int y, int w, int h, const QColorGroup &g, int s, bool down, bool /*enabled*/ ){ QBrush fill; if ( down ) fill = g.brush( QColorGroup::Dark ); else fill = g.brush( QColorGroup::Button ); drawBevelButton( p, x, y, w-2, h, g, down, &fill ); p->fillRect(x+w-2, y, 2, h, g.brush( QColorGroup::Background ) ); p->setPen( g.shadow() ); p->drawRect( x, y, w-2, h ); static const QCOORD nochange_mark[] = { 3,5, 9,5, 3,6, 9,6 }; static const QCOORD check_mark[] = { 3,5, 5,5, 4,6, 5,6, 5,7, 6,7, 5,8, 6,8, 6,9, 9,9, 6,10, 8,10, 7,11, 8,11, 7,12, 7,12, 8,8, 9,8, 8,7, 10,7, 9,6, 10,6, 9,5, 11,5, 10,4, 11,4, 10,3, 12,3, 11,2, 12,2, 11,1, 13,1, 12,0, 13,0 }; if (s != QButton::Off) { QPen oldPen = p->pen();// p->setPen (QPen(g.text(), 2));// p->drawLine( x+2, y+h/2-1, x+w/2-1, y+h-4);// p->drawLine(x+w/2-1, y+h-4, x+w, 0);// p->setPen( oldPen ); int x1 = x; int y1 = y; if ( down ) { // shift check mark x1++; y1++; } QPointArray amark; if ( s == QButton::On ) amark = QPointArray( sizeof(check_mark)/(sizeof(QCOORD)*2), check_mark ); else amark = QPointArray( sizeof(nochange_mark)/(sizeof(QCOORD)*2), nochange_mark ); amark.translate( x1+1, y1+1 ); p->setPen( g.dark() ); p->drawLineSegments( amark ); amark.translate( -1, -1 ); p->setPen( g.foreground() ); p->drawLineSegments( amark );/* if ( s == QButton::On ) { p->setPen( g.dark() ); for ( int i=0; i<(int)(sizeof(check_mark_pix)/sizeof(QCOORD)); i+=2 ) p->drawPoint( x1 + check_mark_pix[i], y1 + check_mark_pix[i+1] ); }*/ p->setPen( oldPen ); }}/*! \reimp */voidQPlatinumStyle::drawIndicatorMask( QPainter *p, int x, int y, int w, int h, int s){ p->fillRect(x, y, w-2, h, color1); if (s != QButton::Off) { QPen oldPen = p->pen(); p->setPen (QPen(color1, 2)); p->drawLine( x+2, y+h/2-1, x+w/2-1, y+h-4); p->drawLine(x+w/2-1, y+h-4, x+w, 0); p->setPen( oldPen ); }}/*! \reimp */QSizeQPlatinumStyle::indicatorSize() const{ return QSize(15,13);}#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)/*! \reimp */void QPlatinumStyle::drawExclusiveIndicator( QPainter* p, int x, int y, int w, int h, const QColorGroup &g, bool on, bool down, bool /* enabled */ ){ static const QCOORD pts1[] = { // normal circle 5,0, 8,0, 9,1, 10,1, 11,2, 12,3, 12,4, 13,5, 13,8, 12,9, 12,10, 11,11, 10,12, 9,12, 8,13, 5,13, 4,12, 3,12, 2,11, 1,10, 1,9, 0,8, 0,5, 1,4, 1,3, 2,2, 3,1, 4,1 }; static const QCOORD pts2[] = { // top left shadow 5,1, 8,1, 3,2, 7,2, 2,3, 5,3, 2,4, 4,4, 1,5, 3,5, 1,6, 1,8, 2,6, 2,7 }; static const QCOORD pts3[] = { // bottom right, dark 5,12, 8,12, 7,11, 10,11, 8,10, 11,10, 9,9, 11,9, 10,8, 12,8, 11,7, 11,7, 12,5, 12,7 }; static const QCOORD pts4[] = { // bottom right, light 5,12, 8,12, 7,11, 10,11, 9,10, 11,10, 10,9, 11,9, 11,7, 11,8, 12,5, 12,8 }; static const QCOORD pts5[] = { // check mark 6,4, 8,4, 10,6, 10,8, 8,10, 6,10, 4,8, 4,6 }; static const QCOORD pts6[] = { // check mark extras 4,5, 5,4, 9,4, 10,5, 10,9, 9,10, 5,10, 4,9 }; p->eraseRect(x,y,w,h); p->setBrush((down||on) ? g.brush( QColorGroup::Dark ) : g.brush( QColorGroup::Button )); p->setPen(NoPen); p->drawEllipse( x, y, 13, 13); p->setPen( g.shadow() ); QPointArray a( QCOORDARRLEN(pts1), pts1 ); a.translate( x, y ); p->drawPolyline( a ); // draw normal circle QColor tc, bc; const QCOORD *bp; int bl; if ( down || on) { // pressed down or on tc = g.dark().dark(); bc = g.light(); bp = pts4; bl = QCOORDARRLEN(pts4); } else { // released tc = g.light(); bc = g.dark(); bp = pts3; bl = QCOORDARRLEN(pts3); } p->setPen( tc ); a.setPoints( QCOORDARRLEN(pts2), pts2 ); a.translate( x, y ); p->drawLineSegments( a ); // draw top shadow p->setPen( bc ); a.setPoints( bl, bp ); a.translate( x, y ); p->drawLineSegments( a ); if ( on ) { // draw check mark int x1=x, y1=y; p->setBrush( g.foreground() ); p->setPen( g.foreground() ); a.setPoints( QCOORDARRLEN(pts5), pts5 ); a.translate( x1, y1 ); p->drawPolygon( a ); p->setBrush( NoBrush ); p->setPen( g.dark() ); a.setPoints( QCOORDARRLEN(pts6), pts6 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -