📄 qmotifstyle.cpp
字号:
QBrush brush = g.brush( enabled?QColorGroup::Button:QColorGroup::Mid ); p->setPen( pen ); p->setBrush( brush ); p->setWorldMatrix( matrix, TRUE ); // set transformation matrix p->drawPolygon( bFill ); // fill arrow p->setBrush( NoBrush ); // don't fill p->setPen( CLEFT ); p->drawLineSegments( bLeft ); p->setPen( CTOP ); p->drawLineSegments( bTop ); p->setPen( CBOT ); p->drawLineSegments( bBot ); p->setWorldMatrix( wxm ); p->setBrush( saveBrush ); // restore brush p->setPen( savePen ); // restore pen#undef CMID#undef CLEFT#undef CTOP#undef CBOT}/*! Draws a press-sensitive shape.*/void QMotifStyle::drawButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush* fill){ qDrawShadePanel( p, x, y, w, h, g, sunken, defaultFrameWidth(), fill ? fill : (sunken ? &g.brush( QColorGroup::Mid ) : &g.brush( QColorGroup::Button ) ));}/*! \reimp */void QMotifStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush* fill){ QMotifStyle::drawButton(p, x, y, w, h, g, sunken, fill);}/*! \reimp */voidQMotifStyle::drawFocusRect( QPainter* p, const QRect& r, const QColorGroup &g , const QColor* bg, bool atBorder){ if (bg ) { int h,s,v; bg->hsv(&h,&s,&v); if (v >= 128) p->setPen( Qt::black ); else p->setPen( Qt::white ); } else p->setPen( g.foreground() ); p->setBrush( NoBrush ); if ( atBorder ) p->drawRect( QRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2 ) ); else p->drawRect( r );}/*! \reimp */voidQMotifStyle::drawPushButton( QPushButton* btn, QPainter *p){ QColorGroup g = btn->colorGroup(); int x1, y1, x2, y2; btn->rect().coords( &x1, &y1, &x2, &y2 ); // get coordinates p->setPen( g.foreground() ); p->setBrush( QBrush(g.button(),NoBrush) ); int diw = buttonDefaultIndicatorWidth(); if ( btn->isDefault() || btn->autoDefault() ) { x1 += diw; y1 += diw; x2 -= diw; y2 -= diw; } QBrush fill; if ( btn->isDown() ) fill = g.brush( QColorGroup::Mid ); else if ( btn->isOn() ) fill = QBrush( g.mid(), Dense4Pattern ); else fill = g.brush( QColorGroup::Button ); if ( btn->isDefault() ) { if ( diw == 0 ) { QPointArray a; a.setPoints( 9, x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1, x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 ); p->setPen( g.shadow() ); p->drawPolyline( a ); x1 += 2; y1 += 2; x2 -= 2; y2 -= 2; } else { qDrawShadePanel( p, btn->rect(), g, TRUE ); } } if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) drawButton( p, x1, y1, x2-x1+1, y2-y1+1, g, btn->isOn() || btn->isDown(), &fill ); if ( p->brush().style() != NoBrush ) p->setBrush( NoBrush );}/*! \reimp */void QMotifStyle::tabbarMetrics( const QTabBar* t, int& hframe, int& vframe, int& overlap){ QCommonStyle::tabbarMetrics( t, hframe, vframe, overlap );}/*! \reimp */void QMotifStyle::drawTab( QPainter* p, const QTabBar* tb, QTab* t , bool selected ){ QRect r( t->r ); int o = defaultFrameWidth() > 1 ? 1 : 0; if ( tb->shape() == QTabBar::RoundedAbove ) { if ( o ) { p->setPen( tb->colorGroup().light() ); p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); p->setPen( tb->colorGroup().light() ); p->drawLine( r.left(), r.bottom()-1, r.right(), r.bottom()-1 ); if ( r.left() == 0 ) p->drawPoint( tb->rect().bottomLeft() ); } else { p->setPen( tb->colorGroup().light() ); p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); } if ( selected ) { p->fillRect( QRect( r.left()+1, r.bottom()-o, r.width()-3, 2), tb->palette().normal().brush( QColorGroup::Background )); p->setPen( tb->colorGroup().background() );// p->drawLine( r.left()+1, r.bottom(), r.right()-2, r.bottom() );// if (o)// p->drawLine( r.left()+1, r.bottom()-1, r.right()-2, r.bottom()-1 ); p->drawLine( r.left()+1, r.bottom(), r.left()+1, r.top()+2 ); p->setPen( tb->colorGroup().light() ); } else { p->setPen( tb->colorGroup().light() ); r.setRect( r.left() + 2, r.top() + 2, r.width() - 4, r.height() - 2 ); } p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 ); p->drawPoint( r.left()+1, r.top() + 1 ); p->drawLine( r.left()+2, r.top(), r.right() - 2, r.top() ); p->drawPoint( r.left(), r.bottom()); if ( o ) { p->drawLine( r.left()+1, r.bottom(), r.left()+1, r.top() + 2 ); p->drawLine( r.left()+2, r.top()+1, r.right() - 2, r.top()+1 ); } p->setPen( tb->colorGroup().dark() ); p->drawLine( r.right() - 1, r.top() + 2, r.right() - 1, r.bottom() - 1 + (selected?o:-o)); if ( o ) { p->drawPoint( r.right() - 1, r.top() + 1 ); p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - (selected?1:1+o)); p->drawPoint( r.right() - 1, r.top() + 1 ); } } else if ( tb->shape() == QTabBar::RoundedBelow ) { if ( selected ) { p->fillRect( QRect( r.left()+1, r.top(), r.width()-3, 1), tb->palette().normal().brush( QColorGroup::Background )); p->setPen( tb->colorGroup().background() );// p->drawLine( r.left()+1, r.top(), r.right()-2, r.top() ); p->drawLine( r.left()+1, r.top(), r.left()+1, r.bottom()-2 ); p->setPen( tb->colorGroup().dark() ); } else { p->setPen( tb->colorGroup().dark() ); p->drawLine( r.left(), r.top(), r.right(), r.top() ); r.setRect( r.left() + 2, r.top(), r.width() - 4, r.height() - 2 ); } p->drawLine( r.right() - 1, r.top(), r.right() - 1, r.bottom() - 2 ); p->drawPoint( r.right() - 2, r.bottom() - 2 ); p->drawLine( r.right() - 2, r.bottom() - 1, r.left() + 1, r.bottom() - 1 ); p->drawPoint( r.left() + 1, r.bottom() - 2 ); if (defaultFrameWidth() > 1) { p->drawLine( r.right(), r.top(), r.right(), r.bottom() - 1 ); p->drawPoint( r.right() - 1, r.bottom() - 1 ); p->drawLine( r.right() - 1, r.bottom(), r.left() + 2, r.bottom() ); } p->setPen( tb->colorGroup().light() ); p->drawLine( r.left(), r.top(), r.left(), r.bottom() - 2 ); } else { QCommonStyle::drawTab( p, tb, t, selected ); }}/*! \reimp */void QMotifStyle::drawTabMask( QPainter* p, const QTabBar* tb, QTab* t, bool selected ){ QCommonStyle::drawTabMask(p, tb, t, selected );}#define HORIZONTAL (sb->orientation() == QScrollBar::Horizontal)#define VERTICAL !HORIZONTAL#define MOTIF_BORDER defaultFrameWidth()#define SLIDER_MIN 9 // ### motif says 6 but that's too small/*! \reimp */void QMotifStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int &buttonDim ){ int maxLength; int b = MOTIF_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 { uint range = sb->maxValue()-sb->minValue(); sliderLength = (sb->pageStep()*maxLength)/ (range + sb->pageStep()); if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 ) sliderLength = SLIDER_MIN; if ( sliderLength > maxLength ) sliderLength = maxLength; } sliderMax = sliderMin + maxLength - sliderLength;}/*! \reimp */void QMotifStyle::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 ) ) qDrawShadePanel( p, sb->rect(), g, TRUE ); if (sliderStart > sliderMax) { // sanity check sliderStart = sliderMax; } int b = MOTIF_BORDER; 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 = 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 ); } if ( controls & AddLine ) drawArrow( p, VERTICAL ? DownArrow : RightArrow, ADD_LINE_ACTIVE, addB.x(), addB.y(), addB.width(), addB.height(), g, TRUE ); if ( controls & SubLine ) drawArrow( p, VERTICAL ? UpArrow : LeftArrow, SUB_LINE_ACTIVE, subB.x(), subB.y(), subB.width(), subB.height(), g, TRUE ); QBrush fill = g.brush( QColorGroup::Mid ); if (sb->backgroundPixmap() ){ fill = QBrush( g.mid(), *sb->backgroundPixmap() ); } if ( controls & SubPage ) p->fillRect( subPageR, fill ); if ( controls & AddPage ) p->fillRect( addPageR, fill ); if ( controls & Slider ) { QPoint bo = p->brushOrigin(); p->setBrushOrigin(sliderR.topLeft()); if ( sliderR.isValid() ) drawBevelButton( p, sliderR.x(), sliderR.y(), sliderR.width(), sliderR.height(), g, FALSE, &g.brush( QColorGroup::Button ) ); // qDrawShadePanel( p, sliderR, g, FALSE, 2, &g.fillButton() ); p->setBrushOrigin(bo); }}/*!\reimp */int QMotifStyle::sliderLength() const{ return 30;}/*!\reimp */void QMotifStyle::drawSlider( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, Orientation orient, bool, bool ){ drawBevelButton( p, x, y, w, h, g, FALSE, &g.brush( QColorGroup::Button) ); if ( orient == Horizontal ) { QCOORD mid = x + w / 2; qDrawShadeLine( p, mid, y , mid, y + h - 2, g, TRUE, 1); } else { QCOORD mid = y +h / 2; qDrawShadeLine( p, x, mid, x + w - 2, mid, g, TRUE, 1); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -