?? qsgistyle.cpp
字號:
} } } p->setBrushOrigin(bo); } } p->setClipping( FALSE );}/*! Draws the sliding element of a slider-widget.*/voidQSGIStyle::drawSlider( QPainter* p, int x, int y, int w, int h, const QColorGroup& g, Orientation orient, bool /*tickAbove*/, bool /*tickBelow*/ ){ QRect sliderR( x, y, w-1, h-1 ); if ( sliderMoving ) { if ( sliderLastPosition.slider == (QWidget*)p->device() ) { if ( !sliderLastPosition.pos.isValid() ) { sliderLastPosition.pos= sliderR; } else { p->setClipRegion( QRegion(sliderLastPosition.pos ) - QRegion(sliderR) ); qDrawShadePanel( p, sliderLastPosition.pos, g, TRUE, 2, &g.brush( QColorGroup::Dark) ); } } } else sliderLastPosition.pos = QRect( 1, -1, 1, -1 ); if ( repaintByMouseMove) { bool aboutToBeActive = sliderR.contains( mousePos ); if ( sliderHandleActive == aboutToBeActive ) return; sliderHandleActive = aboutToBeActive; } p->setClipping( FALSE ); if ( deviceUnderMouse == p->device() && sliderR.contains( mousePos ) ) drawBevelButton( p, x, y, w-1, h-1, g, FALSE, &g.brush( QColorGroup::Midlight ) ); else drawBevelButton( p, x, y, w-1, h-1, g, FALSE ); if ( orient == Horizontal ) { QCOORD mid = x + w / 2 - 2; drawSeparator( p, mid, y+2 , mid, y + h - 4, g ); } else { QCOORD mid = y +h / 2; drawSeparator( p, x+2, mid, x + w - 4, mid, g ); }}/*! \reimp*/voidQSGIStyle::drawSliderMask( QPainter* p, int x, int y, int w, int h, Orientation orient, bool tickAbove, bool tickBelow ){ QColorGroup g1(color1, color1, color1, color1, color1, color1, color1); drawSlider( p, x, y, w, h, g1, orient, tickAbove, tickBelow);}/*! Draws the groove of a slider widget.*/voidQSGIStyle::drawSliderGroove( QPainter* p, int x, int y, int w, int h, const QColorGroup& g, QCOORD, Orientation ){ if ( repaintByMouseMove) return; if ( sliderLastPosition.slider == p->device() ) { if ( sliderMoving && sliderLastPosition.pos.isValid() ) p->setClipRegion( QRegion( x,y,w,h ) - QRegion( sliderLastPosition.pos ) ); } qDrawShadePanel( p, x, y, w, h, g, TRUE, 1 ); drawButton( p, x+1, y+1, w-2, h-2, g ); p->setClipping( FALSE );}/*! \reimp*/voidQSGIStyle::drawSliderGrooveMask( QPainter* p, int x, int y, int w, int h, QCOORD c, Orientation orient ){ QColorGroup g1(color1, color1, color1, color1, color1, color1, color1); drawSliderGroove( p, x, y, w, h, g1, c, orient);}/*! \reimp*/voidQSGIStyle::drawTab( QPainter *p, const QTabBar *tb, QTab* t, bool selected ){ QMotifStyle::drawTab( p, tb, t, selected );}/*! \reimp*/voidQSGIStyle::drawTabMask( QPainter *p, const QTabBar *tb, QTab* t, bool selected ){ QMotifStyle::drawTabMask( p, tb, t, selected );}/*! \reimp*/intQSGIStyle::splitterWidth() const{ return QMAX( 10, QApplication::globalStrut().width() );}/*! \reimp*/voidQSGIStyle::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 ) { int xPos = x + w/2; int kPos = motifOffset; int kSize = sw - 2; qDrawShadeLine( p, xPos, kPos + kSize - 1 , xPos, h, g ); drawBevelButton( p, xPos-sw/2+1, kPos, kSize, kSize+2, g, FALSE, &g.brush( QColorGroup::Button )); qDrawShadeLine( p, xPos+2, 0, xPos, kPos, g ); } else { int yPos = y + h/2; int kPos = w - motifOffset - sw; int kSize = sw - 2; qDrawShadeLine( p, 0, yPos, kPos, yPos, g ); drawBevelButton( p, kPos, yPos-sw/2+1, kSize+2, kSize, g, FALSE, &g.brush( QColorGroup::Button )); qDrawShadeLine( p, kPos + kSize+1, yPos, w, yPos, g ); }}/*! \reimp*/intQSGIStyle::popupMenuItemHeight( bool /* checkable*/, QMenuItem* mi, const QFontMetrics& fm ){ int h = 0; if ( mi->isSeparator() ) { h = sgiSepHeight; } else { if ( mi->pixmap() ) { h = mi->pixmap()->height() + 2*sgiItemFrame; } else { h = fm.height() + 2*sgiItemVMargin + 2*sgiItemFrame; } } if ( !mi->isSeparator() && mi->iconSet() != 0 ) { h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*sgiItemFrame ); h += 2; } if ( mi->custom() ) h = QMAX( h, mi->custom()->sizeHint().height() + 2*sgiItemVMargin + 2*sgiItemFrame ); return h;}/*! \reimp*/voidQSGIStyle::drawPopupPanel( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, int lineWidth, const QBrush *fill ){ if (lineWidth == 3 && w > 3 && h > 3 ) drawBevelButton( p, x, y, w, h, g, FALSE, fill ); else QMotifStyle::drawPopupPanel( p, x, y, w, h, g, lineWidth, fill );}static void drawSGIPrefix( QPainter *p, int x, int y, QString* miText ){ if ( miText && (!!(*miText)) ) { int amp = 0; bool nextAmp = FALSE; while ( ( amp = miText->find( '&', amp ) ) != -1 ) { if ( (uint)amp == miText->length()-1 ) return; miText->remove( amp,1 ); nextAmp = (*miText)[amp] == '&'; // next time if && if ( !nextAmp ) { // draw special underlining uint ulx = p->fontMetrics().width(*miText, amp); uint ulw = p->fontMetrics().width(*miText, amp+1) - ulx; p->drawLine( x+ulx, y, x+ulx+ulw, y ); p->drawLine( x+ulx, y+1, x+ulx+ulw/2, y+1 ); p->drawLine( x+ulx, y+2, x+ulx+ulw/4, y+2 ); } amp++; } }}/*! \reimp*/voidQSGIStyle::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, sgiCheckMarkSpace ); int checkcol = maxpmw; if (mi && mi->isSeparator() ) { p->setPen( g.mid() ); p->drawLine(x, y, x+w, y ); return; } int pw = sgiItemFrame; if ( act && !dis ) { if ( defaultFrameWidth() > 1 ) drawPanel( p, x, y, w, h, g, FALSE, pw, &g.brush( QColorGroup::Light ) ); else drawPanel( p, x+1, y+1, w-2, h-2, g, FALSE, 1, &g.brush( QColorGroup::Light ) ); } else { p->fillRect( x, y, w, h, g.brush( QColorGroup::Background ) ); } if ( !mi ) return; if ( mi->isChecked() ) { if ( mi->iconSet() ) { drawPanel( p, x+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame, g, TRUE, 1, &g.brush( QColorGroup::Light ) ); } } else { if ( !act ) p->fillRect( x+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame, g.brush( QColorGroup::Background ) ); } if ( mi->iconSet() ) { QIconSet::Mode mode = QIconSet::Normal; 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+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame ); QRect pmr( 0, 0, pixw, pixh ); pmr.moveCenter( cr.center() ); p->setPen( itemg.text() ); p->drawPixmap( pmr.topLeft(), pixmap ); } else { if ( checkable ) { int mw = checkcol; int mh = h - 2*sgiItemFrame; QColorGroup citemg = itemg; if ( act && enabled ) citemg.setColor( QColorGroup::Background, itemg.light() ); if ( mi->isChecked() ) drawIndicator( p, x+sgiItemFrame, y+sgiItemFrame, mw, mh, citemg, QButton::On, act, enabled ); } } p->setPen( g.buttonText() ); QColor discol; if ( dis ) { discol = itemg.text(); p->setPen( discol ); } int xm = sgiItemFrame + checkcol + sgiItemHMargin; if ( mi->custom() ) { int m = sgiItemVMargin; 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 ) { int t = s.find( '\t' ); int m = sgiItemVMargin; const int text_flags = AlignVCenter | DontClip | SingleLine; //special underline for &x QString miText = s; if ( t>=0 ) { p->drawText(x+w-tab-sgiItemHMargin-sgiItemFrame, y+m, tab, h-2*m, text_flags, miText.mid( t+1 ) ); miText = s.mid( 0, t ); } QRect br = p->fontMetrics().boundingRect( x+xm, y+m, w-xm-tab+1, h-2*m, AlignVCenter|DontClip|SingleLine, mi->text() ); drawSGIPrefix( p, br.x()+p->fontMetrics().leftBearing(miText[0]), br.y()+br.height()+p->fontMetrics().underlinePos()-2, &miText ); p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, miText, miText.length() ); } else { if ( mi->pixmap() ) { QPixmap *pixmap = mi->pixmap(); if ( pixmap->depth() == 1 ) p->setBackgroundMode( OpaqueMode ); p->drawPixmap( x+xm, y+sgiItemFrame, *pixmap ); if ( pixmap->depth() == 1 ) p->setBackgroundMode( TransparentMode ); } } if ( mi->popup() ) { int dim = (h-2*sgiItemFrame) / 2; drawArrow( p, RightArrow, FALSE, x+w-sgiArrowHMargin-sgiItemFrame-dim, y+h/2-dim/2, dim, dim, g, TRUE ); }}/*! \reimp*/void QSGIStyle::drawMenuBarItem( QPainter* p, int x, int y, int w, int h, QMenuItem* mi, QColorGroup& g, bool enabled, bool active ){ if ( active ) { p->setPen( QPen( g.shadow(), 1) ); p->drawRect( x, y, w, h ); qDrawShadePanel( p, QRect(x+1,y+1,w-2,h-2), g, FALSE, 2, &g.brush( QColorGroup::Light )); } if ( mi->pixmap() ) drawItem( p, x, y, w, h, AlignCenter|DontClip|SingleLine, g, enabled, mi->pixmap(), "", -1, &g.buttonText() ); if ( !!mi->text() ) { QString* text = new QString(mi->text()); QRect br = p->fontMetrics().boundingRect( x, y-2, w+1, h, AlignCenter|DontClip|SingleLine|ShowPrefix, mi->text() ); p->setPen( g.buttonText() ); drawSGIPrefix( p, br.x()+p->fontMetrics().leftBearing((*text)[0]), br.y()+br.height()+p->fontMetrics().underlinePos()-2, text ); p->drawText( x, y-2, w+1, h, AlignCenter|DontClip|SingleLine, *text, text->length() ); delete text; }}/*! Reimplemented to enable the SGI-like effect of "glowing" widgets.*/boolQSGIStyle::eventFilter( QObject* o, QEvent* e ){ switch ( e->type() ) { case QEvent::MouseButtonPress: { if ( o->inherits("QSlider") ) { sliderLastPosition.pos = QRect( 0, -1, 0, -1 ); sliderLastPosition.slider = (QWidget*)o; sliderMoving = TRUE; } } break; case QEvent::MouseButtonRelease: { if ( o->inherits("QSlider") ) { sliderLastPosition.pos = QRect( 0, -1, 0, -1 ); sliderLastPosition.slider = 0; sliderMoving = FALSE; ((QWidget*) o)->repaint( FALSE ); } } break; case QEvent::MouseMove: { QMouseEvent* me = (QMouseEvent*) e; mousePos = me->pos(); bool isSlider = o->inherits("QSlider"); if ( o->inherits("QScrollBar") || isSlider ) { repaintByMouseMove = me->button() == NoButton; ((QWidget*) o)->repaint( FALSE ); repaintByMouseMove = FALSE; } } break; case QEvent::Enter: { if (o->inherits("QButton")) { QWidget* w = (QWidget*) o; if (w->isEnabled()) { QPalette pal = w->palette(); lastWidget = w; if ( lastWidget->ownPalette() ) lastWidgetPalette = new QPalette( lastWidget->palette() ); pal.setColor( QPalette::Active, QColorGroup::Button, pal.active().midlight() ); lastWidget->setPalette( pal ); } } else if ( o->isWidgetType() ) { // must be either slider or scrollbar deviceUnderMouse = (QPaintDevice*)(QWidget*)o; ((QWidget*) o)->repaint( FALSE ); } } break; case QEvent::Leave: { if ((QPaintDevice*)(QWidget*)o == deviceUnderMouse) { deviceUnderMouse = 0; ((QWidget*) o)->repaint( FALSE ); } if ( lastWidget && o == lastWidget && lastWidget->testWState( WState_Created )) { if ( lastWidgetPalette ) { QPalette test = *lastWidgetPalette; test.setColor( QPalette::Active, QColorGroup::Button, test.active().midlight() ); if ( test == lastWidget->palette() ) lastWidget->setPalette( *lastWidgetPalette ); delete lastWidgetPalette; lastWidgetPalette = 0; } else { QPalette test = QApplication::palette( lastWidget ); test.setColor( QPalette::Active, QColorGroup::Button, test.active().midlight() ); if ( test == lastWidget->palette() ) lastWidget->unsetPalette(); } } } break; default: break; } return QMotifStyle::eventFilter( o, e );}#endif // QT_NO_STYLE_SGI
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -