Esempio n. 1
0
void MetalStyle::drawComplexControl( ComplexControl cc,
				     QPainter *p,
				     const QWidget *widget,
				     const QRect &r,
				     const QColorGroup &cg,
				     SFlags how,
				     SCFlags sub,
				     SCFlags subActive,
				     const QStyleOption& opt ) const
{
    switch ( cc ) {
    case CC_Slider:
	{
	    const QSlider *slider = ( const QSlider* ) widget;
	    QRect handle = querySubControlMetrics( CC_Slider, widget,
						   SC_SliderHandle, opt);
	    if ( sub & SC_SliderGroove )
		QWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how,
						   SC_SliderGroove, subActive, opt );
	    if ( (sub & SC_SliderHandle) && handle.isValid() )
		drawMetalButton( p, handle.x(), handle.y(), handle.width(),
				 handle.height(), FALSE,
				 slider->orientation() == QSlider::Horizontal);
	    break;
	}
    case CC_ComboBox:
	{
	    // not exactly correct...
	    const QComboBox *cmb = ( const QComboBox* ) widget;
	
	    qDrawWinPanel( p, r.x(), r.y(), r.width(), r.height(), cg, TRUE,
			   cmb->isEnabled() ? &cg.brush( QColorGroup::Base ) :
			                      &cg.brush( QColorGroup::Background ) );
	    drawMetalButton( p, r.x() + r.width() - 2 - 16, r.y() + 2, 16, r.height() - 4,
			     how & Style_Sunken, TRUE );
	    drawPrimitive( PE_ArrowDown, p,
			   QRect( r.x() + r.width() - 2 - 16 + 2,
				  r.y() + 2 + 2, 16 - 4, r.height() - 4 -4 ),
			   cg,
			   cmb->isEnabled() ? Style_Enabled : Style_Default,
			   opt );
	    break;
	}
    default:
	QWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how, sub, subActive,
					   opt );
	break;
    }
}
Esempio n. 2
0
/*!\reimp
 */
void QPlatinumStyle::drawComplexControl( ComplexControl control,
					 QPainter *p,
					 const QWidget *widget,
					 const QRect &r,
					 const QColorGroup &cg,
					 SFlags how,
					 SCFlags sub,
					 SCFlags subActive,
					 const QStyleOption& opt ) const
{
    switch ( control ) {
    case CC_ComboBox:
	{
	    int x,
		y,
		w,
		h;
	    r.rect( &x, &y, &w, &h );
	    p->fillRect( x + 2,  y + 2, w - 4,
			 h - 4, cg.brush(QColorGroup::Button) );
	    // the bright side
	    p->setPen(cg.shadow());
	    p->drawLine( x, y, x + w - 1, y );
	    p->drawLine( x, y, x, y + h - 1 );

	    p->setPen( cg.light() );
	    p->drawLine( x + 1, y + 1,
			 x + w - 2, y + 1 );
	    p->drawLine( x + 1, y + 1,
			 x + 1, y + h - 2 );

	    // the dark side!


	    p->setPen( cg.mid() );
	    p->drawLine( x + 2, y + h - 2,
			 x + w - 2, y + h - 2 );
	    p->drawLine( x + w - 2, y + 2,
			 x + w - 2, y + h - 2 );

	    p->setPen (cg.shadow() );
	    p->drawLine( x + 1, y + h - 1,
			 x + w - 1, y + h - 1 );
	    p->drawLine( x + w - 1, y,
			 x + w - 1, y + h - 1 );

	    // top left corner:
	    p->setPen( cg.background() );
	    p->drawPoint( x, y );
	    p->drawPoint( x + 1, y );
	    p->drawPoint( x, y + 1 );
	    p->setPen( cg.shadow() );
	    p->drawPoint( x + 1, y + 1 );
	    p->setPen( white );
	    p->drawPoint( x + 3, y + 3 );
	    // bottom left corner:
	    p->setPen( cg.background() );
	    p->drawPoint( x, y + h - 1 );
	    p->drawPoint( x + 1, y + h - 1 );
	    p->drawPoint( x, y + h - 2 );
	    p->setPen( cg.shadow() );
	    p->drawPoint( x + 1, y + h - 2 );
	    // top right corner:
	    p->setPen( cg.background() );
	    p->drawPoint( x + w - 1, y );
	    p->drawPoint( x + w - 2, y );
	    p->drawPoint( x + w - 1, y + 1 );
	    p->setPen( cg.shadow() );
	    p->drawPoint( x + w - 2, y + 1 );
	    // bottom right corner:
	    p->setPen( cg.background() );
	    p->drawPoint( x + w - 1, y + h - 1 );
	    p->drawPoint( x + w - 2, y + h - 1 );
	    p->drawPoint( x + w - 1, y + h - 2 );
	    p->setPen( cg.shadow() );
	    p->drawPoint( x + w - 2, y + h - 2 );
	    p->setPen( cg.dark() );
	    p->drawPoint( x + w - 3, y + h - 3 );

	    if ( sub & SC_ComboBoxArrow ) {
		QRect rTmp = querySubControlMetrics( CC_ComboBox, widget,
						     SC_ComboBoxArrow, opt );
		int xx = rTmp.x(),
		    yy = rTmp.y(),
		    ww = rTmp.width(),
		    hh = rTmp.height();
		// the bright side

		p->setPen( cg.mid() );
		p->drawLine( xx, yy+2, xx, yy+hh-3 );

		p->setPen( cg.button() );
		p->drawLine( xx+1, yy+1, xx+ww-2, yy+1 );
		p->drawLine( xx+1, yy+1, xx+1, yy+hh-2 );

		p->setPen( cg.light() );
		p->drawLine( xx+2, yy+2, xx+2, yy+hh-2 );
		p->drawLine( xx+2, yy+2, xx+ww-2, yy+2 );


		// the dark side!

		p->setPen( cg.mid() );
		p->drawLine( xx+3, yy+hh-3 ,xx+ww-3, yy+hh-3 );
		p->drawLine( xx+ww-3, yy+3, xx+ww-3, yy+hh-3 );

		p->setPen( cg.dark() );
		p->drawLine( xx+2, yy+hh-2 ,xx+ww-2, yy+hh-2 );
		p->drawLine( xx+ww-2, yy+2, xx+ww-2, yy+hh-2 );

		p->setPen( cg.shadow() );
		p->drawLine( xx+1, yy+hh-1,xx+ww-1, yy+hh-1 );
		p->drawLine( xx+ww-1, yy, xx+ww-1, yy+hh-1 );

		// top right corner:
		p->setPen( cg.background() );
		p->drawPoint( xx + ww - 1, yy );
		p->drawPoint( xx + ww - 2, yy );
		p->drawPoint( xx + ww - 1, yy + 1 );
		p->setPen( cg.shadow() );
		p->drawPoint( xx + ww - 2, yy + 1 );
		// bottom right corner:
		p->setPen( cg.background() );
		p->drawPoint( xx + ww - 1, yy + hh - 1 );
		p->drawPoint( xx + ww - 2, yy + hh - 1 );
		p->drawPoint( xx + ww - 1, yy + hh - 2 );
		p->setPen( cg.shadow() );
		p->drawPoint( xx + ww - 2, yy + hh - 2 );
		p->setPen( cg.dark() );
		p->drawPoint( xx + ww - 3, yy + hh - 3 );
		p->setPen( cg.mid() );
		p->drawPoint( xx + ww - 4, yy + hh - 4 );

		// and the arrows
		p->setPen( cg.foreground() );
		QPointArray a ;
		a.setPoints(  7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2  );
		a.translate( xx + ww / 2, yy + hh / 2 - 3 );
		p->drawLineSegments( a, 0, 3 );		// draw arrow
		p->drawPoint( a[6] );
		a.setPoints( 7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2 );
		a.translate( xx + ww / 2, yy + hh / 2 + 2 );
		p->drawLineSegments( a, 0, 3 );		// draw arrow
		p->drawPoint( a[6] );

	    }
#ifndef QT_NO_COMBOBOX
	    if ( sub & SC_ComboBoxEditField ) {
		const QComboBox *cmb;
		cmb = (const QComboBox*)widget;
		// sadly this is pretty much the windows code, except
		// for the first fillRect call...
		QRect re =
		    QStyle::visualRect( querySubControlMetrics( CC_ComboBox,
								widget,
								SC_ComboBoxEditField ),
					widget );
		if ( cmb->hasFocus() && !cmb->editable() )
		    p->fillRect( re.x() + 1, re.y() + 1,
				 re.width() - 2, re.height() - 2,
				 cg.brush( QColorGroup::Highlight ) );

		if ( cmb->hasFocus() ) {
		    p->setPen( cg.highlightedText() );
		    p->setBackgroundColor( cg.highlight() );
		} else {
		    p->setPen( cg.text() );
		    p->setBackgroundColor( cg.background() );
		}

		if ( cmb->hasFocus() && !cmb->editable() ) {
		    QRect re =
			QStyle::visualRect( subRect( SR_ComboBoxFocusRect,
						     cmb ),
					    widget );
		    drawPrimitive( PE_FocusRect, p, re, cg,
				   Style_FocusAtBorder,
				   QStyleOption(cg.highlight()));
		}
		if ( cmb->editable() ) {
		    // need this for the moment...
		    // was the code in comboButton rect
		    QRect ir( x + 3, y + 3,
			      w - 6 - 16, h - 6 );
		    if ( QApplication::reverseLayout() )
			ir.moveBy( 16, 0 );
		    // end comboButtonRect...
		    ir.setRect( ir.left() - 1, ir.top() - 1, ir.width() + 2,
				ir.height() + 2 );
		    qDrawShadePanel( p, ir, cg, TRUE, 2, 0 );
		}
	    }
#endif
	    break;
	}
    case CC_Slider:
	{
#ifndef QT_NO_SLIDER
	    const QSlider *slider = (const QSlider *) widget;
	    int thickness = pixelMetric( PM_SliderControlThickness, widget );
	    int len = pixelMetric( PM_SliderLength, widget );
	    int ticks = slider->tickmarks();

	    QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
						  opt),
		  handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
						  opt);

	    if ((sub & SC_SliderGroove) && groove.isValid()) {
		p->fillRect( groove, cg.brush(QColorGroup::Background) );

		int x, y, w, h;
		int mid = thickness / 2;

		if ( ticks & QSlider::Above )
		    mid += len / 8;
		if ( ticks & QSlider::Below )
		    mid -= len / 8;

		if ( slider->orientation() == Horizontal ) {
		    x = 0;
		    y = groove.y() + mid - 3;
		    w = slider->width();
		    h = 7;
		} else {
		    x = groove.x() + mid - 3;
		    y = 0;
		    w = 7;
		    h = slider->height();
		}

		p->fillRect( x, y, w, h, cg.brush( QColorGroup::Dark ));
		// the dark side
		p->setPen( cg.dark() );
		p->drawLine( x, y, x + w - 1, y );
		p->drawLine( x, y, x, y + h - 1);
		p->setPen( cg.shadow() );
		p->drawLine( x + 1, y + 1, x + w - 2, y + 1 );
		p->drawLine( x + 1, y + 1, x + 1, y + h - 2 );
		// the bright side!
		p->setPen(cg.shadow());
		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 - 2 );
		p->setPen( cg.light() );
		p->drawLine( x, y + h - 1, x + w - 1, y + h - 1 );
		p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 );
		// top left corner:
		p->setPen(cg.background());
		p->drawPoint( x, y );
		p->drawPoint( x + 1, y );
		p->drawPoint( x, y + 1 );
		p->setPen(cg.shadow());
		p->drawPoint( x + 1, y + 1 );
		// bottom left corner:
		p->setPen( cg.background() );
		p->drawPoint( x, y + h - 1 );
		p->drawPoint( x + 1, y + h - 1 );
		p->drawPoint( x, y + h - 2 );
		p->setPen( cg.light() );
		p->drawPoint( x + 1, y + h - 2 );
		// top right corner:
		p->setPen( cg.background() );
		p->drawPoint( x + w - 1, y );
		p->drawPoint( x + w - 2, y );
		p->drawPoint( x + w - 1, y + 1 );
		p->setPen( cg.dark() );
		p->drawPoint( x + w - 2, y + 1 );
		// bottom right corner:
		p->setPen( cg.background() );
		p->drawPoint( x + w - 1, y + h - 1 );
		p->drawPoint( x + w - 2, y + h - 1 );
		p->drawPoint( x + w - 1, y + h - 2 );
		p->setPen( cg.light() );
		p->drawPoint( x + w - 2, y + h - 2 );
		p->setPen( cg.dark() );
		p->drawPoint( x + w - 3, y + h - 3 );
		// ### end slider groove

		if ( how & Style_HasFocus )
		    drawPrimitive( PE_FocusRect, p, groove, cg );
	    }

	    if ((sub & SC_SliderHandle) && handle.isValid()) {
		const QColor c0 = cg.shadow();
		const QColor c1 = cg.dark();
		const QColor c3 = cg.light();

		int x1 = handle.x();
		int x2 = handle.x() + handle.width() - 1;
		int y1 = handle.y();
		int y2 = handle.y() + handle.height() - 1;
		int mx = handle.width() / 2;
		int my = handle.height() / 2;

		if ( slider->orientation() == Vertical ) {
		    // Background
		    QBrush oldBrush = p->brush();
		    p->setBrush( cg.brush( QColorGroup::Button ) );
		    p->setPen( NoPen );
		    QPointArray a(6);
		    a.setPoint( 0, x1 + 1, y1 + 1 );
		    a.setPoint( 1, x2 - my + 2, y1 + 1 );
		    a.setPoint( 2, x2 - 1, y1 + my - 1 );
		    a.setPoint( 3, x2 - 1, y2 - my + 1 );
		    a.setPoint( 4, x2 - my + 2, y2 - 1 );
		    a.setPoint( 5, x1 + 1, y2 - 1 );
		    p->drawPolygon( a );
		    p->setBrush( oldBrush );

		    // shadow border
		    p->setPen( c0 );
		    p->drawLine( x1, y1 + 1, x1,y2 - 1 );
		    p->drawLine( x2 - my + 2, y1, x2, y1 + my - 2 );
		    p->drawLine( x2 - my + 2, y2, x2, y1 + my + 2 );
		    p->drawLine( x2, y1 + my - 2, x2, y1 + my + 2 );
		    p->drawLine( x1 + 1, y1, x2 - my + 2, y1 );
		    p->drawLine( x1 + 1, y2, x2 - my + 2, y2 );

		    // light shadow
		    p->setPen( c3 );
		    p->drawLine( x1 + 1, y1 + 2, x1 + 1, y2 - 2 );
		    p->drawLine( x1 + 1, y1 + 1, x2 - my + 2, y1 + 1 );
		    p->drawLine( x2 - my + 2, y1 + 1, x2 - 1, y1 + my - 2 );

		    // dark shadow
		    p->setPen(c1);
		    p->drawLine( x2 - 1, y1 + my - 2, x2 - 1, y1 + my + 2 );
		    p->drawLine( x2 - my + 2, y2 - 1, x2 - 1, y1 + my + 2 );
		    p->drawLine( x1 + 1, y2 - 1, x2 -my + 2, y2 - 1 );

		    drawRiffles( p, handle.x(), handle.y() + 2, handle.width() - 3,
				 handle.height() - 4, cg, TRUE );
		} else {  // Horizontal
		    QBrush oldBrush = p->brush();
		    p->setBrush( cg.brush( QColorGroup::Button ) );
		    p->setPen( NoPen );
		    QPointArray a(6);
		    a.setPoint( 0, x2 - 1, y1 + 1 );
		    a.setPoint( 1, x2 - 1, y2 - mx + 2 );
		    a.setPoint( 2, x2 - mx + 1, y2 - 1 );
		    a.setPoint( 3, x1 + mx - 1, y2 - 1 );
		    a.setPoint( 4, x1 + 1, y2 - mx + 2 );
		    a.setPoint( 5, x1 + 1, y1 + 1 );
		    p->drawPolygon( a );
		    p->setBrush( oldBrush );

		    // shadow border
		    p->setPen( c0 );
		    p->drawLine( x1 + 1, y1, x2 - 1, y1 );
		    p->drawLine( x1, y2 - mx + 2, x1 + mx - 2, y2 );
		    p->drawLine( x2, y2 - mx + 2, x1 + mx + 2, y2 );
		    p->drawLine( x1 + mx - 2, y2, x1 + mx + 2, y2 );
		    p->drawLine( x1, y1 + 1, x1, y2 - mx + 2 );
		    p->drawLine( x2, y1 + 1, x2, y2 - mx + 2 );

		    // light shadow
		    p->setPen(c3);
		    p->drawLine( x1 + 1, y1 + 1, x2 - 1, y1 + 1 );
		    p->drawLine( x1 + 1, y1 + 1, x1 + 1, y2 - mx + 2 );

		    // dark shadow
		    p->setPen(c1);
		    p->drawLine( x2 - 1, y1 + 1, x2 - 1, y2 - mx + 2 );
		    p->drawLine( x1 + 1, y2 - mx + 2, x1 + mx - 2, y2 - 1 );
		    p->drawLine( x2 - 1, y2 - mx + 2, x1 + mx + 2, y2 - 1 );
		    p->drawLine( x1 + mx - 2, y2 - 1, x1 + mx + 2, y2 - 1 );

		    drawRiffles( p, handle.x() + 2, handle.y(), handle.width() - 4,
				 handle.height() - 5, cg, FALSE );
		}
	    }

	    if ( sub & SC_SliderTickmarks )
		QCommonStyle::drawComplexControl( control, p, widget, r,
						  cg, how, SC_SliderTickmarks,
						  subActive, opt );
#endif
	    break;
	}
    default:
	QWindowsStyle::drawComplexControl( control, p, widget, r, cg,
					   how, sub, subActive, opt );
	break;
    }
}