Esempio n. 1
0
void KTriangleButton::paint( QPainter *painter )
{
    if ( isDown() || isOn() )
    {
        if ( style() == WindowsStyle )
            qDrawWinButton( painter, 0, 0, width(), 
                            height(), colorGroup(), TRUE );
        else
            qDrawShadePanel( painter, 0, 0, width(), 
                             height(), colorGroup(), TRUE, 2, 0L );
    }
    else if ( raised )
    {
        if ( style() == WindowsStyle )
            qDrawWinButton( painter, 0, 0, width(), height(), 
                            colorGroup(), FALSE );
        else
            qDrawShadePanel( painter, 0, 0, width(), height(), 
                             colorGroup(), FALSE, 2, 0L );
    }
    
    if (dir==Right)
    {
        int x=width()/4;
        int y=height()*2/6;
        int l=height()-y*2;
        int i=0;
        int maxi=width()-2*x;
        double m=((double)(l/2))/maxi;
        while (i<=maxi)
        {
            painter->drawLine(x,y+(int)(i*m),x,y+l-(int)(i*m));
            x++;
            i++;
        };
    }
    else if (dir==Left)
    {
        int x=width()/4;
        int y=height()*2/6;
        int l=height()-y*2;
        int i=0;
        int maxi=width()-2*x;
        x=width()-x;
        double m=((double)(l/2))/maxi;
        while (i<=maxi)
        {
            painter->drawLine(x,y+(int)(i*m),x,y+l-(int)(i*m));
            x--;
            i++;
        };
        
    };
    
}
Esempio n. 2
0
void QuickButton::drawButton(QPainter *p)
{
   if (isDown() || isOn()) {
      p->fillRect(rect(), colorGroup().brush(QColorGroup::Mid));
      qDrawWinButton(p, 0, 0, width(), height(), colorGroup(), true);
   }

   drawButtonLabel(p);
}
Esempio n. 3
0
void TrackView::paintTopMargin(QStylePainter &painter, const QRegion &region)
{
	const QRect &rect = region.boundingRect();
	painter.setClipRect(QRectF(QPointF(0.0f, 0.0f),
	                    QPointF(rect.right() + 1.0f, topMarginHeight - 0.5f)));

	QRect topMargin(QPoint(-2, 0),
	                QPoint(rect.right() + 3, topMarginHeight - 1));
	painter.fillRect(topMargin.adjusted(1, 1, -1, -1), palette().button());
	qDrawWinButton(&painter, topMargin, palette());

	int startTrack = qBound(0, getTrackFromPhysicalX(qMax(rect.left(), leftMarginWidth)), getTrackCount());
	int endTrack = qBound(0, getTrackFromPhysicalX(rect.right()) + 1, getTrackCount());

	for (int track = startTrack; track < endTrack; ++track) {
		const SyncTrack *t = getTrack(track);

		QRect topMargin(getPhysicalX(track), 0, trackWidth, topMarginHeight);
		if (!region.intersects(topMargin))
			continue;

		QRect fillRect = topMargin;

		QBrush bgBrush = palette().button();
		if (track == editTrack)
			bgBrush = editBrush;

		painter.fillRect(fillRect.adjusted(1, 1, -1, -1), bgBrush);
		qDrawWinButton(&painter, fillRect, bgBrush.color());

		if (!t->isActive())
			painter.setPen(QColor(128, 128, 128));
		else
			painter.setPen(QColor(0, 0, 0));

		painter.drawText(fillRect, t->getDisplayName());
	}

	// make sure that the top margin isn't overdrawn by the track-data
	painter.setClipRegion(QRect(0, topMarginHeight, rect.right() + 1, rect.bottom() + 1));
}
Esempio n. 4
0
void DrawView::drawShapes(QPainter *p, int sx, int sy) {
    int x = sx, y = sy;
    int w = 80, h = 35;

    p->save();  // 儲存繪圖裝置狀態,因為要修改p,所以,在修改成前先儲存先前狀態
   
    p->setPen(QPen(Qt::blue, 4, DotLine));  // 藍色、4pixel大的點狀畫筆
    p->drawLine(x, y, x+w, y); // 由(x, y)繪到(x+w, y)
    x += (w+10);

    p->setPen(SolidLine); // 實線
    p->setBrush(QBrush(Qt::green, DiagCrossPattern)); // 綠色的方格畫刷
    p->drawRect(x, y, w, h); // 畫方塊,左上座標(x, y),寬高(w, h)
    x += (w+10);

    p->setBrush(Qt::yellow); // 實心黃色畫刷
    p->drawRoundRect(x, y, w, h, 0, 20); // 圓角方塊,圓角半徑20pixel
    x += (w+10);

    p->drawEllipse(x, y, w, h); // 以方塊為範圍的橢圓形
    x = sx;
    y += (h+10);
    p->drawPie(x, y, w, h, 45*16, 300*16); // 畫缺角的圓
    p->drawArc(x+3, y, w, h, 45*16, -60*16); // 畫弧
    x += (w+10);
    p->drawChord(x, y, w, h, -45, 160*16); // 畫圓切
    x += (w+10);

    p->drawPixmap(x, y, QPixmap("pengiun.xpm")); // 畫圖片
    x += (w+10);

    QBrush b(Qt::lightGray);
    qDrawWinButton(p, x, y, w, h, colorGroup(), false, &b);  // 畫一個按鈕,qDrawWinButton不是QPainter的函數嗎?為什麼可以直接呼叫?

    x = sx;
    y += (h+10);

    p->setPen(Qt::red);
    p->setBrush(NoBrush); // 無畫刷
    p->drawRect(x, y, 2*w-12 , 3*h);  // 所以是空心方塊
    // 填圖
    p->drawTiledPixmap(x+2, y+2, 2*w-16, 3*h-4, QPixmap("pengiun.xpm"));

    p->restore(); // 復原繪圖裝置狀態,把之前存下來的p參數值還原
}
Esempio n. 5
0
//! Paint event
void QwtLegendLabel::paintEvent( QPaintEvent *e )
{
    const QRect cr = contentsRect();

    QPainter painter( this );
    painter.setClipRegion( e->region() );

    if ( d_data->isDown )
    {
        qDrawWinButton( &painter, 0, 0, width(), height(),
            palette(), true );
    }

    painter.save();

    if ( d_data->isDown )
    {
        const QSize shiftSize = buttonShift( this );
        painter.translate( shiftSize.width(), shiftSize.height() );
    }

    painter.setClipRect( cr );

    drawContents( &painter );

    if ( !d_data->icon.isNull() )
    {
        QRect iconRect = cr;
        iconRect.setX( iconRect.x() + margin() );
        if ( d_data->itemMode != QwtLegendData::ReadOnly )
            iconRect.setX( iconRect.x() + ButtonFrame );

        iconRect.setSize( d_data->icon.size() );
        iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) );

        painter.drawPixmap( iconRect, d_data->icon );
    }

    painter.restore();
}
Esempio n. 6
0
void QHeader::paintCell( QPainter *p, int row, int col )
{
    int i = ( orient == Horizontal ) ? col : row;
    int size = pSize( i );
    bool down = (i==handleIdx) && ( state == Pressed || state == Moving );

    QRect fr( 0, 0, orient == Horizontal ?  size : width(),
	      orient == Horizontal ?  height() : size );

    if ( style() == WindowsStyle )
	qDrawWinButton( p, fr, colorGroup(), down );
    else
	qDrawShadePanel( p, fr, colorGroup(), down );

    int logIdx = mapToLogical(i);

    const char *s = data->labels[logIdx];
    int d = 0;
    if ( style() == WindowsStyle  &&
	 i==handleIdx && ( state == Pressed || state == Moving ) )
	d = 1;

    QRect r;
    if (orient == Horizontal )
      r = QRect( QH_MARGIN+d, 2+d, size - 6, height() - 4 );
    else
      r = QRect( QH_MARGIN+d, 2+d, width() - 6, size - 4 );

    if ( s ) {
	p->drawText ( r, AlignLeft| AlignVCenter|SingleLine, s );
    } else {
	QString str;
	if ( orient == Horizontal )
	    str.sprintf( "Col %d", logIdx );
	else
	    str.sprintf( "Row %d", logIdx );
	p->drawText ( r, AlignLeft| AlignVCenter|SingleLine, str );
    }
}
Esempio n. 7
0
void TrackView::paintLeftMargin(QStylePainter &painter, const QRegion &region)
{
	const QRect &rect = region.boundingRect();
	const SyncDocument *doc = getDocument();

	int firstRow = qBound(0, getRowFromPhysicalY(qMax(rect.top(), topMarginHeight)), getRows() - 1);
	int lastRow = qBound(0, getRowFromPhysicalY(qMax(rect.bottom(), topMarginHeight)), getRows() - 1);

	painter.setClipRect(QRectF(QPointF(0.0f, topMarginHeight - 0.5f),
	                           QPointF(leftMarginWidth - 0.5f, rect.bottom() + 1.0f)));

	QRectF padding(QPointF(rect.left(), topMarginHeight - 0.5f),
	               QPointF(leftMarginWidth - 0.5f, rect.bottom() + 1.0f));
	painter.fillRect(padding, palette().dark());

	for (int row = firstRow; row <= lastRow; ++row) {
		QRect leftMargin(0, getPhysicalY(row), leftMarginWidth, rowHeight);
		if (!region.intersects(leftMargin))
			continue;

		QBrush fillBrush;
		if (row == editRow)
			fillBrush = editBrush;
		else if (doc->isRowBookmark(row))
			fillBrush = bookmarkBrush;
		else
			fillBrush = palette().button();

		painter.fillRect(leftMargin.adjusted(1, 1, -1, -1), fillBrush);
		qDrawWinButton(&painter, leftMargin, QPalette(fillBrush.color()));

		if ((row % 8) == 0)      painter.setPen(QColor(0, 0, 0));
		else if ((row % 4) == 0) painter.setPen(QColor(64, 64, 64));
		else                     painter.setPen(QColor(128, 128, 128));

		painter.drawText(leftMargin, QString("%1").arg(row, 5, 16, QChar('0')).toUpper() + "h");
	}
}
Esempio n. 8
0
void qDrawWinButton(QPainter *p, const QRect &r,
                     const QPalette &pal, bool sunken, const QBrush *fill)
{
    qDrawWinButton(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill);
}
Esempio n. 9
0
void qDrawWinButton( QPainter *p, const QRect &r,
		     const QColorGroup &g, bool sunken,
		     const QBrush *fill )
{
    qDrawWinButton( p, r.x(), r.y(), r.width(), r.height(), g, sunken, fill );
}
Esempio n. 10
0
// draw custom slider + handle for volume widget
void MpcVolumeSlideStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
                                       QPainter *p, const QWidget *widget) const
{
    if( cc == CC_Slider )
    {
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
            QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
            QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);

            if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {

                p->setPen(slider->palette.shadow().color());
                if (slider->orientation == Qt::Horizontal) {
                    static QPoint points[3] = {
                                QPoint(groove.x() , groove.y() + slider->rect.height() ),
                                QPoint(groove.x() + groove.width() -2 , groove.y() + slider->rect.height() ),
                                QPoint(groove.x() + groove.width() -2 , groove.y()  ),
                            };
                    QPen oldPen = p->pen();
                    
                    p->setPen(slider->palette.dark().color());
                    p->drawLine(QPoint(points[0].x(), points[0].y() -2 ),QPoint(points[2].x(), points[2].y()));

                    QPoint b[3] = { QPoint(points[0].x(),points[0].y()-1), QPoint(points[1].x()-1, points[1].y()-1), QPoint(points[2].x()-1,points[2].y()) };
                    p->setPen(slider->palette.light().color());
                    p->drawPolyline(b, 3);
                    p->setPen(oldPen);
                }
            }


            if (slider->subControls & SC_SliderTickmarks) {
                QStyleOptionSlider tmpSlider = *slider;
                tmpSlider.subControls = SC_SliderTickmarks;
                QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
            }

            if (slider->subControls & SC_SliderHandle) {
                QBrush handleBrush;

                if (slider->state & State_Enabled) {
                    handleBrush = slider->palette.color(QPalette::Button);
                } else {
                    handleBrush = QBrush(slider->palette.color(QPalette::Button),
                                         Qt::Dense4Pattern);
                }


                int x = handle.x() , y = handle.y(),
                   wi = handle.width() - 2, he = slider->rect.height();

                if (slider->state & State_HasFocus) {
                    QStyleOptionFocusRect fropt;
                    fropt.QStyleOption::operator=(*slider);
                    fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
                    drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
                }

                Qt::BGMode oldMode = p->backgroundMode();
                p->setBackgroundMode(Qt::OpaqueMode);
                qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
                                   &handleBrush);
                p->setBackgroundMode(oldMode);

            }
        }
    }
    else
    {
        QWindowsStyle::drawComplexControl(cc,opt,p,widget);
    }
}
Esempio n. 11
0
void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr )
{
    int x = cr.x();
    int y = cr.y();
    if ( !knownField || knownField->width() != cr.width() ||
	 knownField->height() != cr.height() ) {
	delete knownField;
	knownField = new QPixmap( cr.width(), cr.height() );
	QPainter pp( knownField );
	QBrush br( cg.button().dark(115) );
	qDrawWinButton( &pp, QRect( 0, 0, cr.width(), cr.height() ), cg, TRUE, &br );
    }

    const int pmmarg=cr.width()/5;

    if ( !unknownField || unknownField->width() != cr.width() ||
         unknownField->height() != cr.height() ) {
	delete unknownField;
	unknownField = new QPixmap( cr.width(), cr.height() );
	QPainter pp( unknownField );
	QBrush br( cg.button() );
	qDrawWinButton( &pp, QRect( 0, 0, cr.width(), cr.height() ), cg, FALSE, &br );
    }

    if ( !flag_pix || flag_pix->width() != cr.width()-pmmarg*2 ||
	 flag_pix->height() != cr.height()-pmmarg*2 ) {
	delete flag_pix;
	flag_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 );
	flag_pix->convertFromImage( QImage(pix_flag).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) );
    }

    if ( !mine_pix || mine_pix->width() != cr.width()-pmmarg*2 ||
	 mine_pix->height() != cr.height()-pmmarg*2 ) {
	delete mine_pix;
	mine_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 );
	mine_pix->convertFromImage( QImage(pix_mine).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) );
    }

    p->save();

    switch(st) {
    case Hidden:
	p->drawPixmap( x, y, *unknownField );
	break;
    case Empty:
	p->drawPixmap( x, y, *knownField );
	if ( hint > 0 ) {
	    switch( hint ) {
	    case 1:
		p->setPen( blue );
		break;
	    case 2:
		p->setPen( green.dark() );
		break;
	    case 3:
		p->setPen( red );
		break;
	    case 4:
		p->setPen( darkYellow.dark() );
		break;
	    case 5:
		p->setPen( darkMagenta );
		break;
	    case 6:
		p->setPen( darkRed );
		break;
	    default:
		p->setPen( black );
		break;
	    }
	    p->drawText( cr, AlignHCenter | AlignVCenter, QString::number( hint ) );
	}
	break;
    case Mined:
	p->drawPixmap( x, y, *knownField );
	p->drawPixmap( x+pmmarg, y+pmmarg, *mine_pix );
	break;
    case Exploded:
	p->drawPixmap( x, y, *knownField );
	p->drawPixmap( x+pmmarg, y+pmmarg, *mine_pix );
	p->setPen( red );
	p->drawText( cr, AlignHCenter | AlignVCenter, "X" );
	break;
    case Flagged:
	p->drawPixmap( x, y, *unknownField );
	p->drawPixmap( x+pmmarg, y+pmmarg, *flag_pix );
	break;
#ifdef MARK_UNSURE
    case Unsure:
	p->drawPixmap( x, y, *unknownField );
	p->drawText( cr, AlignHCenter | AlignVCenter, "?" );
	break;
#endif
    case Wrong:
	p->drawPixmap( x, y, *unknownField );
	p->drawPixmap( x+pmmarg, y+pmmarg, *flag_pix );
	p->setPen( red );
	p->drawText( cr, AlignHCenter | AlignVCenter, "X" );
	break;
    }

    p->restore();
}
Esempio n. 12
0
/*!\reimp
 */
void QWindowsStyle::drawSlider( QPainter *p,
			     int x, int y, int w, int h,
			     const QColorGroup &g,
			     Orientation orient, bool tickAbove, bool tickBelow )
{
#ifndef QT_NO_SLIDER    
    // 4444440
    // 4333310
    // 4322210
    // 4322210
    // 4322210
    // 4322210
    // *43210*
    // **410**
    // ***0***



    const QColor c0 = g.shadow();
    const QColor c1 = g.dark();
    //    const QColor c2 = g.button();
    const QColor c3 = g.midlight();
    const QColor c4 = g.light();


    int x1 = x;
    int x2 = x+w-1;
    int y1 = y;
    int y2 = y+h-1;

    p->fillRect( x, y, w, h, g.brush( QColorGroup::Background ) );

    if ( tickAbove && tickBelow || !tickAbove && !tickBelow ) {
	qDrawWinButton( p, QRect(x,y,w,h), g, FALSE,
			&g.brush( QColorGroup::Button ) );
	return;
    }


    enum  { SlUp, SlDown, SlLeft, SlRight } dir;

    if ( orient == Horizontal )
	if ( tickAbove )
	    dir = SlUp;
	else
	    dir = SlDown;
    else
	if ( tickAbove )
	    dir = SlLeft;
	else
	    dir = SlRight;

    QPointArray a;

    int d = 0;
    switch ( dir ) {
    case SlUp:
	y1 = y1 + w/2;
	d =  (w + 1) / 2 - 1;
	a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d );
	break;
    case SlDown:
	y2 = y2 - w/2;
	d =  (w + 1) / 2 - 1;
	a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1 );
	break;
    case SlLeft:
	d =  (h + 1) / 2 - 1;
	x1 = x1 + h/2;
	a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1);
	break;
    case SlRight:
	d =  (h + 1) / 2 - 1;
	x2 = x2 - h/2;
	a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1 );
	break;
    }


    QBrush oldBrush = p->brush();
    p->setBrush( g.brush( QColorGroup::Button ) );
    p->setPen( NoPen );
    p->drawRect( x1, y1, x2-x1+1, y2-y1+1 );
    p->drawPolygon( a );
    p->setBrush( oldBrush );



    if ( dir != SlUp ) {
	p->setPen( c4 );
	p->drawLine( x1, y1, x2, y1 );
	p->setPen( c3 );
	p->drawLine( x1, y1+1, x2, y1+1 );
    }
    if ( dir != SlLeft ) {
	p->setPen( c3 );
	p->drawLine( x1+1, y1+1, x1+1, y2 );
	p->setPen( c4 );
	p->drawLine( x1, y1, x1, y2 );
    }
    if ( dir != SlRight ) {
	p->setPen( c0 );
	p->drawLine( x2, y1, x2, y2 );
	p->setPen( c1 );
	p->drawLine( x2-1, y1+1, x2-1, y2-1 );
    }
    if ( dir != SlDown ) {
	p->setPen( c0 );
	p->drawLine( x1, y2, x2, y2 );
	p->setPen( c1 );
	p->drawLine( x1+1, y2-1, x2-1, y2-1 );
    }

    switch ( dir ) {
	case SlUp:
	    p->setPen( c4 );
	    p->drawLine( x1, y1, x1+d, y1-d);
	    p->setPen( c0 );
	    d = w - d - 1;
	    p->drawLine( x2, y1, x2-d, y1-d);
	    d--;
	    p->setPen( c3 );
	    p->drawLine( x1+1, y1, x1+1+d, y1-d );
	    p->setPen( c1 );
	    p->drawLine( x2-1, y1, x2-1-d, y1-d);
	    break;
	case SlDown:
	    p->setPen( c4 );
	    p->drawLine( x1, y2, x1+d, y2+d);
	    p->setPen( c0 );
	    d = w - d - 1;
	    p->drawLine( x2, y2, x2-d, y2+d);
	    d--;
	    p->setPen( c3 );
	    p->drawLine( x1+1, y2, x1+1+d, y2+d );
	    p->setPen( c1 );
	    p->drawLine( x2-1, y2, x2-1-d, y2+d);
	    break;
	case SlLeft:
	    p->setPen( c4 );
	    p->drawLine( x1, y1, x1-d, y1+d);
	    p->setPen( c0 );
	    d = h - d - 1;
	    p->drawLine( x1, y2, x1-d, y2-d);
	    d--;
	    p->setPen( c3 );
	    p->drawLine( x1, y1+1, x1-d, y1+1+d );
	    p->setPen( c1 );
	    p->drawLine( x1, y2-1, x1-d, y2-1-d);
	    break;
	case SlRight:
	    p->setPen( c4 );
	    p->drawLine( x2, y1, x2+d, y1+d);
	    p->setPen( c0 );
	    d = h - d - 1;
	    p->drawLine( x2, y2, x2+d, y2-d);
	    d--;
	    p->setPen( c3 );
	    p->drawLine(  x2, y1+1, x2+d, y1+1+d );
	    p->setPen( c1 );
	    p->drawLine( x2, y2-1, x2+d, y2-1-d);
	    break;
    }
#endif
}