Example #1
0
void HideButton::drawButton(QPainter *p)
{
    if(m_arrow == Qt::LeftArrow)
    {
        p->setPen(colorGroup().mid());
        p->drawLine(width() - 1, 0, width() - 1, height());
    }
    else if(m_arrow == Qt::RightArrow)
    {
        p->setPen(colorGroup().mid());
        p->drawLine(0, 0, 0, height());
    }
    else if(m_arrow == Qt::UpArrow)
    {
        p->setPen(colorGroup().mid());
        p->drawLine(0, height() - 1, width(), height() - 1);
    }
    else if(m_arrow == Qt::DownArrow)
    {
        p->setPen(colorGroup().mid());
        p->drawLine(0, 0, width(), 0);
    }

    drawButtonLabel(p);
}
Example #2
0
/*!
  \brief Draw the knob
  \param p painter
  \param r borders of the knob
*/
void QwtKnob::drawKnob(QPainter *p, const QRect &r)
{
    const int bw2 = d_borderWidth / 2;

    QRect aRect(r.x() + bw2, r.y() + bw2,
          r.width() - 2 * bw2, r.height() - 2 * bw2);

    //
    // draw button face
    //
    p->setBrush(colorGroup().brush(QColorGroup::Button));
    p->drawEllipse(aRect);

    //
    // draw button shades
    //
    QPen pn;
    pn.setWidth(d_borderWidth);

    pn.setColor(colorGroup().light());
    p->setPen(pn);
    p->drawArc(aRect, 45*16,180*16);

    pn.setColor(colorGroup().dark());
    p->setPen(pn);
    p->drawArc(aRect, 225*16,180*16);

    //
    // draw marker
    //
    if ( isValid() )
        drawMarker(p, d_angle, colorGroup().buttonText());
}
Example #3
0
/*!
    \reimp
*/
void QProgressBar::drawContents( QPainter *p )
{
    const QRect bar = contentsRect();

    QSharedDoubleBuffer buffer( p, bar.x(), bar.y(), bar.width(), bar.height() );

    QPoint pn = backgroundOffset();
    buffer.painter()->setBrushOrigin( -pn.x(), -pn.y() );

    const QPixmap *bpm = paletteBackgroundPixmap();
    if ( bpm )
	buffer.painter()->fillRect( bar, QBrush( paletteBackgroundColor(), *bpm ) );
    else
	buffer.painter()->fillRect( bar, paletteBackgroundColor() );
    buffer.painter()->setFont( p->font() );

    QStyle::SFlags flags = QStyle::Style_Default;
    if (isEnabled())
	flags |= QStyle::Style_Enabled;
    if (hasFocus())
	flags |= QStyle::Style_HasFocus;

    style().drawControl(QStyle::CE_ProgressBarGroove, buffer.painter(), this,
			QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarGroove, this), this ),
			colorGroup(), flags);

    style().drawControl(QStyle::CE_ProgressBarContents, buffer.painter(), this,
			QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarContents, this), this ),
			colorGroup(), flags);

    if (percentageVisible())
	style().drawControl(QStyle::CE_ProgressBarLabel, buffer.painter(), this,
			    QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarLabel, this), this ),
			    colorGroup(), flags);
}
Example #4
0
void KColorButton::drawButtonLabel(QPainter *painter)
{
    int x, y, w, h;
    QRect r = style().subRect(QStyle::SR_PushButtonContents, this);
    r.rect(&x, &y, &w, &h);

    int margin = style().pixelMetric(QStyle::PM_ButtonMargin, this);
    x += margin;
    y += margin;
    w -= 2 * margin;
    h -= 2 * margin;

    if(isOn() || isDown())
    {
        x += style().pixelMetric(QStyle::PM_ButtonShiftHorizontal, this);
        y += style().pixelMetric(QStyle::PM_ButtonShiftVertical, this);
    }

    QColor fillCol = isEnabled() ? col : backgroundColor();
    qDrawShadePanel(painter, x, y, w, h, colorGroup(), true, 1, NULL);
    if(fillCol.isValid())
        painter->fillRect(x + 1, y + 1, w - 2, h - 2, fillCol);

    if(hasFocus())
    {
        QRect focusRect = style().subRect(QStyle::SR_PushButtonFocusRect, this);
        style().drawPrimitive(QStyle::PE_FocusRect, painter, focusRect, colorGroup());
    }
}
Example #5
0
void KTabCtl::paintEvent(QPaintEvent *)
{
    if (!tabs)
	return;

    if( !blBorder )
        return;
      
    QPainter p;
    p.begin(this);

    int y0 = getChildRect().top() - 1;
    int y1 = getChildRect().bottom() + 2;
    int x1 = getChildRect().right() + 2;
    int x0 = getChildRect().left() - 1;

    p.setPen( colorGroup().light() );
    p.drawLine(x0, y0, x1 - 1, y0);      /* top line */
    p.drawLine(x0, y0 + 1, x0, y1);      /* left line */
    p.setPen(black);
    p.drawLine(x1, y1, x0, y1);          /* bottom line */
    p.drawLine(x1, y1 - 1, x1, y0);
    p.setPen(colorGroup().dark());
    p.drawLine(x0 + 1, y1 - 1, x1 - 1, y1 - 1);  /* bottom */
    p.drawLine(x1 - 1, y1 - 2, x1 - 1, y0 + 1);
    p.end();
}
Example #6
0
void KDockButton_Private::drawButton( QPainter* p )
{
  p->fillRect( 0,0, width(), height(), QBrush(colorGroup().brush(QColorGroup::Background)) );
  p->drawPixmap( (width() - pixmap()->width()) / 2, (height() - pixmap()->height()) / 2, *pixmap() );
  if ( moveMouse && !isDown() ){
    p->setPen( white );
    p->moveTo( 0, height() - 1 );
    p->lineTo( 0, 0 );
    p->lineTo( width() - 1, 0 );

    p->setPen( colorGroup().dark() );
    p->lineTo( width() - 1, height() - 1 );
    p->lineTo( 0, height() - 1 );
  }
  if ( isOn() || isDown() ){
    p->setPen( colorGroup().dark() );
    p->moveTo( 0, height() - 1 );
    p->lineTo( 0, 0 );
    p->lineTo( width() - 1, 0 );

    p->setPen( white );
    p->lineTo( width() - 1, height() - 1 );
    p->lineTo( 0, height() - 1 );
  }
}
Example #7
0
/*!
  Draw the frame around the dial

  \param painter Painter
  \sa QwtDial::lineWidth, QwtDial::frameShadow
*/
void QwtDial::drawFrame(QPainter *painter)
{
    const int lw = lineWidth();
    const int off = (lw + 1) % 2;

    QRect r = boundingRect();
    r.setRect(r.x() + lw / 2 - off, r.y() + lw / 2 - off,
        r.width() - lw + off + 1, r.height() - lw + off + 1);

    if ( lw > 0 )
    {
        switch(d_frameShadow)
        {
            case QwtDial::Raised:
                QwtPainter::drawRoundFrame(painter, r, 
                    lw, colorGroup(), FALSE);
                break;
            case QwtDial::Sunken:
                QwtPainter::drawRoundFrame(painter, r, 
                    lw, colorGroup(), TRUE);
                break;
            default: // Plain
            {
                painter->save();
                painter->setPen(QPen(Qt::black, lw));
                painter->setBrush(Qt::NoBrush);
                painter->drawEllipse(r);
                painter->restore();
            }
        }
    }
}
Example #8
0
/*! 
  Draw the whole QwtThermo.

  \param painter Painter
  \param rect Update rectangle
*/
void QwtThermo::draw(QPainter *painter, const QRect& rect)
{
    if ( !d_data->thermoRect.contains(rect) )
    {
        if (d_data->scalePos != NoScale)
        {
#if QT_VERSION < 0x040000
            scaleDraw()->draw(painter, colorGroup());
#else
            scaleDraw()->draw(painter, palette());
#endif
        }

        qDrawShadePanel(painter,
            d_data->thermoRect.x() - d_data->borderWidth,
            d_data->thermoRect.y() - d_data->borderWidth,
            d_data->thermoRect.width() + 2 * d_data->borderWidth,
            d_data->thermoRect.height() + 2 * d_data->borderWidth,
#if QT_VERSION < 0x040000
            colorGroup(), 
#else
            palette(), 
#endif
            true, d_data->borderWidth, 0);
    }
    drawThermo(painter);
}
Example #9
0
void QProgressBar::drawContents( QPainter *p )
{
    const int unit_width  = 9;	    // includes 2 bg pixels
    const int unit_height = 12;
    const QRect bar = contentsRect();

    if ( style() == WindowsStyle ) {
	// Draw nu units out of a possible u of unit_width width, each
	// a rectangle bordered by background color, all in a sunken panel
	// with a percentage text display at the end.

	QFontMetrics fm = p->fontMetrics();
	int textw = fm.width("100%");
	int u = (bar.width() - textw - 2/*panel*/) / unit_width;
	int ox = ( bar.width() - (u*unit_width+textw) ) / 2;

	if (total_steps) { // Sanity check
	    // ### This part doesn't change as often as percentage does.
	    int nu = ( u * progress_val + total_steps/2 ) / total_steps;
	    int x = bar.x() + ox;
	    int uh = QMIN(bar.height()-4, unit_height);
	    int vm = (bar.height()-4 - uh)/2 + 2;
	    p->setPen(NoPen);
	    for (int i=0; i<nu; i++) {
		p->fillRect( x+2, bar.y()+vm,
			     unit_width-2, bar.height()-vm-vm,
			     QApplication::winStyleHighlightColor() );
		x += unit_width;
	    }
	}

	// ### This part doesn't actually change.
	const QRect r( ox + bar.x(), bar.y(), u*unit_width + 2, bar.height() );
	qDrawShadePanel( p, r, colorGroup(), TRUE, 1 );

	// ### This part changes every percentage change.
	p->setPen( colorGroup().text() );
	p->fillRect( r.x()+r.width(), bar.y(), textw, bar.height(),
	    backgroundColor() );
	p->drawText( r.x()+r.width(), bar.y(), textw, bar.height(),
	    AlignRight | AlignVCenter, progress_str );
    } else {
	if (total_steps) { // Sanity check
	    int pw = bar.width() * progress_val / total_steps;

	    p->setPen( colorGroup().base() );
	    p->setClipRect( bar.x(), bar.y(), pw, bar.height() );
	    p->fillRect( bar, QApplication::winStyleHighlightColor() );
	    p->drawText( bar, AlignCenter, progress_str );

	    p->setPen( QApplication::winStyleHighlightColor() );
	    p->setClipRect( bar.x()+pw, bar.y(), bar.width()-pw, bar.height() );
	}
	p->fillRect( bar, colorGroup().base() );
	p->setPen( colorGroup().text() );
	p->drawText( bar, AlignCenter, progress_str );
    }
}
Example #10
0
TextShow::TextShow(QWidget *p, const char *name)
        : QTextBrowser(p, name)
{
    srchdialog = NULL;
    bg = new TransparentBg(this);
    baseBG = colorGroup().color(QColorGroup::Base);
    baseFG = colorGroup().color(QColorGroup::Text);
    setTextFormat(RichText);
}
Example #11
0
TextShow::TextShow(QWidget *p)
        : QTextBrowser(p)
{
    bg = new TransparentBg(this);
    baseBG = colorGroup().color(QColorGroup::Base);
    baseFG = colorGroup().color(QColorGroup::Text);
    setTextFormat(RichText);
    menu = NULL;
}
Example #12
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);
}
//! Draw the focus indication
void QwtPlotCanvas::drawFocusIndicator(QPainter *painter, const QRect &rect)
{
#if QT_VERSION < 300
        style().drawFocusRect(painter, rect, colorGroup());
#else
        style().drawPrimitive(QStyle::PE_FocusRect, painter,
            rect, colorGroup());
#endif
}
Example #14
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++;
        };
        
    };
    
}
Example #15
0
void StyledButton::drawButton( QPainter *paint )
{
    style().drawPrimitive(QStyle::PE_ButtonBevel, paint, rect(), colorGroup(),
			  isDown() ? QStyle::Style_Sunken : QStyle::Style_Default);
    drawButtonLabel(paint);

    if (hasFocus())
	style().drawPrimitive(QStyle::PE_FocusRect, paint,
			      style().subRect(QStyle::SR_PushButtonFocusRect, this),
			      colorGroup(), QStyle::Style_Default);
}
Example #16
0
void ColorButton::drawButton(QPainter *p)
{
    style().drawPrimitive(QStyle::PE_ButtonBevel, p, rect(), colorGroup(),
			  isDown() ? QStyle::Style_Down : QStyle::Style_Raised);
    drawButtonLabel(p);

    if (hasFocus())
	style().drawPrimitive(QStyle::PE_FocusRect, p,
			      style().subRect(QStyle::SR_PushButtonFocusRect, this),
			      colorGroup(), QStyle::Style_Default);
}
void StringBody::drawButton(QPainter *painter) {
    if (appearance == HYPERLINK) {
      drawButtonLabel(painter);
      if (hasFocus()) {
        style().drawFocusRect(
            painter, rect(), colorGroup(), &colorGroup().button());
      }
    } else {
      QPushButton::drawButton(painter);
    }
}
void QGroupBox::paintEvent( QPaintEvent *event )
{
    QPainter paint( this );

    if ( lenvisible && !isCheckable() ) {	// draw title
        QFontMetrics fm = paint.fontMetrics();
        int h = fm.height();
        int tw = fm.width( str, lenvisible ) + fm.width(QChar(' '));
        int x;
        int marg = bFlat ? 0 : 8;
        if ( align & AlignHCenter )		// center alignment
            x = frameRect().width()/2 - tw/2;
        else if ( align & AlignRight )	// right alignment
            x = frameRect().width() - tw - marg;
        else if ( align & AlignLeft )		 // left alignment
            x = marg;
        else { // auto align
            if( QApplication::reverseLayout() )
                x = frameRect().width() - tw - marg;
            else
                x = marg;
        }
        QRect r( x, 0, tw, h );
        int va = style().styleHint(QStyle::SH_GroupBox_TextLabelVerticalAlignment, this);
        if(va & AlignTop)
            r.moveBy(0, fm.descent());
        QColor pen( (QRgb) style().styleHint(QStyle::SH_GroupBox_TextLabelColor, this )  );
        if (!style().styleHint(QStyle::SH_UnderlineAccelerator, this))
            va |= NoAccel;
        style().drawItem( &paint, r, ShowPrefix | AlignHCenter | va, colorGroup(),
                          isEnabled(), 0, str, -1, ownPalette() ? 0 : &pen );
        paint.setClipRegion( event->region().subtract( r ) ); // clip everything but title
#ifndef QT_NO_CHECKBOX
    } else if ( d->checkbox ) {
        QRect cbClip = d->checkbox->geometry();
        QFontMetrics fm = paint.fontMetrics();
        cbClip.setX( cbClip.x() - fm.width(QChar(' ')) );
        cbClip.setWidth( cbClip.width() + fm.width(QChar(' ')) );
        paint.setClipRegion( event->region().subtract( cbClip ) );
#endif
    }
    if ( bFlat ) {
        QRect fr = frameRect();
        QPoint p1( fr.x(), fr.y() + 1 );
        QPoint p2( fr.x() + fr.width(), p1.y() );
        // ### This should probably be a style primitive.
        qDrawShadeLine( &paint, p1, p2, colorGroup(), TRUE,
                        lineWidth(), midLineWidth() );
    } else {
        drawFrame(&paint);
    }
    drawContents( &paint );			// draw the contents
}
Example #19
0
//! Draw the slider into the specified rectangle.
void QwtSlider::drawSlider(QPainter *p, const QRect &r)
{
    QRect cr(r);

    if (d_bgStyle & BgTrough)
    {
        qDrawShadePanel(p, r.x(), r.y(),
            r.width(), r.height(),
            colorGroup(), TRUE, d_borderWidth,0);

        cr.setRect(r.x() + d_borderWidth,
            r.y() + d_borderWidth,
            r.width() - 2 * d_borderWidth,
            r.height() - 2 * d_borderWidth);

        p->fillRect(cr.x(), cr.y(), cr.width(), cr.height(), 
            colorGroup().brush(QColorGroup::Mid));
    }

    if ( d_bgStyle & BgSlot)
    {
        int ws = 4;
        int ds = d_thumbLength / 2 - 4;
        if ( ds < 1 )
            ds = 1;

        QRect rSlot;
        if (orientation() == Qt::Horizontal)
        {
            if ( cr.height() & 1 )
                ws++;
            rSlot = QRect(cr.x() + ds, 
                    cr.y() + (cr.height() - ws) / 2,
                    cr.width() - 2 * ds, ws);
        }
        else
        {
            if ( cr.width() & 1 )
                ws++;
            rSlot = QRect(cr.x() + (cr.width() - ws) / 2, 
                    cr.y() + ds,
                    ws, cr.height() - 2 * ds);
        }
        p->fillRect(rSlot.x(), rSlot.y(), rSlot.width(), rSlot.height(),
            colorGroup().brush(QColorGroup::Dark));
        qDrawShadePanel(p, rSlot.x(), rSlot.y(),
            rSlot.width(), rSlot.height(), colorGroup(), TRUE, 1 ,0);

    }

    if ( isValid() )
        drawThumb(p, cr, xyPosition(value()));
}
Example #20
0
void QSlider::drawWinGroove( QPainter *p, QCOORD c )
{
    if ( orient == Horizontal ) {
	qDrawWinPanel( p, 0, c - 2,  width(), 4, colorGroup(), TRUE );
	p->setPen( colorGroup().foreground() );
	p->drawLine( 1, c - 1, width() - 3, c - 1 );
    } else {
	qDrawWinPanel( p, c - 2, 0, 4, height(), colorGroup(), TRUE );
	p->setPen( colorGroup().foreground() );
	p->drawLine( c - 1, 1, c - 1, height() - 3 );
    }
}
void RegionGrabber::drawRubber()
{
  QPainter p;
  p.begin( this );
  p.setRasterOp( NotROP );
  p.setPen( QPen( color0, 1 ) );
  p.setBrush( NoBrush );

  style().drawPrimitive( QStyle::PE_FocusRect, &p, grabRect, colorGroup(),
      QStyle::Style_Default, QStyleOption( colorGroup().base() ) );

  p.end();
}
Example #22
0
    void drawButton( QPainter* p )
    {
#if ( QT_VERSION >= 300 )
        // Draw the background
        style( ).drawComplexControl( QStyle::CC_ToolButton, p, this, rect( ), colorGroup( ),
                                     QStyle::Style_Enabled, QStyle::SC_ToolButton );
        // Draw the label
        style( ).drawControl( QStyle::CE_ToolButtonLabel, p, this, rect( ), colorGroup( ),
                              QStyle::Style_Enabled );
#else
        p->drawText( rect( ), Qt::AlignVCenter | Qt::AlignLeft, text( ) );
#endif
    }
Example #23
0
void KCheckEduca::drawButtonLabel( QPainter *p){
    int x, y, w, h;
    int extra_width, indicator_width;

    extra_width = 8;
    indicator_width = style().pixelMetric(QStyle::PM_IndicatorWidth, 0);

    y = 0;
    x = indicator_width + extra_width; //###
    w = width() - x;
    h = height();

    QRect cr(x,y,w,h);

    _doc = new QSimpleRichText( text(), font() );
    _doc->setWidth( 10 );

    _doc->setWidth(p, cr.width() );
    int rw = _doc->widthUsed() + extra_width;
    int rh = _doc->height();
    int xo = 0;
    int yo = 0;

    resize( width(), rh);

    yo = (cr.height()-rh)/2;

    if ( !isEnabled() ) {
        QColorGroup cg = colorGroup();
        cg.setColor( QColorGroup::Text, cg.light() );
        _doc->draw(p, cr.x()+xo+1, cr.y()+yo+1, cr, cg, 0);
    }
    _doc->draw(p, cr.x()+xo, cr.y()+yo, cr, colorGroup(), 0);

    if ( hasFocus() ) {
//	QRect br = style().itemRect( p, x, y, rw, rh+yo,
//				   AlignLeft|AlignVCenter|ShowPrefix,
//				   isEnabled(),
//				   pixmap(), text().visual() );
        QRect br(x,y,rw,rh+yo);

        br.setLeft( br.left()-3 );
        br.setRight( br.right()+2 );
        br.setTop( br.top()-2 );
        br.setBottom( br.bottom()+2);
        br = br.intersect( QRect(0,0,rw, rh+yo ) );

        style().drawPrimitive( QStyle::PE_FocusRect, p, br, colorGroup());
    }
}
Example #24
0
QPixmap LoadInfo::makeLabel( const QColor &col, const QString &text )
{
    int h = fontMetrics().height();
    QPixmap pm( 20 + fontMetrics().width( text ), h );
    QPainter p( &pm );
    p.fillRect( pm.rect(), colorGroup().background() );
    p.fillRect( 0, h/2-4, 18, h/2+3, black );
    p.setPen( col );
    p.drawLine( 2, h/2, 15, h/2 );
    p.setPen( colorGroup().text() );
    p.drawText( 20, fontMetrics().ascent(), text );

    return pm;
}
Example #25
0
/*!
 Draw the needle

 \param painter Painter
 \param center Center of the dial, start position for the needle
 \param length Length of the needle
 \param direction Direction of the needle, in degrees counter clockwise
 \param cg Color group, used for painting
*/
void QwtDialSimpleNeedle::draw(QPainter *painter, const QPoint &center,
    int length, double direction, QPalette::ColorGroup cg) const
{
    if ( d_style == Arrow )
    {
        drawArrowNeedle(painter, colorGroup(cg),
            center, length, d_width, direction, d_hasKnob);
    }
    else
    {
        drawRayNeedle(painter, colorGroup(cg), center, length, d_width,
            direction, d_hasKnob); 
    }
}
Example #26
0
/*!
    Draw the needle

    \param painter Painter
    \param center Center of the dial, start position for the needle
    \param length Length of the needle
    \param direction Direction of the needle, in degrees counter clockwise
    \param cg Color group, used for painting
*/
void QwtCompassMagnetNeedle::draw(QPainter *painter, const QPoint &center,
    int length, double direction, QPalette::ColorGroup cg) const
{
    if ( d_style == ThinStyle )
    {
        drawThinNeedle(painter, colorGroup(cg), 
            center, length, direction); 
    }
    else
    {
        drawTriangleNeedle(painter, colorGroup(cg),
            center, length, direction);
    }
}
Example #27
0
/*!
 Draw the needle

 \param painter Painter
 \param center Center of the dial, start position for the needle
 \param length Length of the needle
 \param direction Direction of the needle, in degrees counter clockwise
 \param cg Color group, used for painting
*/
void QwtCompassWindArrow::draw(QPainter *painter, const QPoint &center,
    int length, double direction, QPalette::ColorGroup cg) const
{
    if ( d_style == Style1 )
    {
        drawStyle1Needle(painter, colorGroup(cg),
            center, length, direction);
    }
    else
    {
        drawStyle2Needle(painter, colorGroup(cg),
            center, length, direction); 
    }
}
Example #28
0
//! Set up the color array for the background pixmap.
void QwtWheel::setColorArray()
{
    if ( !d_data->colors ) 
        return;

#if QT_VERSION < 0x040000
    const QColor light = colorGroup().light();
    const QColor dark = colorGroup().dark();
#else
    const QColor light = palette().color(QPalette::Light);
    const QColor dark = palette().color(QPalette::Dark);
#endif

    if ( !d_data->colors[0].isValid() ||
        d_data->colors[0] != light ||
        d_data->colors[NUM_COLORS - 1] != dark )
    {
#if QT_VERSION < 0x040000
        if ( d_data->allocContext )
            QColor::destroyAllocContext( d_data->allocContext );

        d_data->allocContext = QColor::enterAllocContext();
#endif

        d_data->colors[0] = light;
        d_data->colors[NUM_COLORS - 1] = dark;

        int dh, ds, dv, lh, ls, lv;
#if QT_VERSION < 0x040000
        d_data->colors[0].rgb(&lh, &ls, &lv);
        d_data->colors[NUM_COLORS - 1].rgb(&dh, &ds, &dv);
#else
        d_data->colors[0].getRgb(&lh, &ls, &lv);
        d_data->colors[NUM_COLORS - 1].getRgb(&dh, &ds, &dv);
#endif

        for ( int i = 1; i < NUM_COLORS - 1; ++i )
        {
            const double factor = double(i) / double(NUM_COLORS);

            d_data->colors[i].setRgb( lh + int( double(dh - lh) * factor ),
                      ls + int( double(ds - ls) * factor ),
                      lv + int( double(dv - lv) * factor ));
        }
#if QT_VERSION < 0x040000
        QColor::leaveAllocContext();
#endif
    }
}
Example #29
0
/*!
  \brief Draw the knob
  \param painter painter
  \param r Bounding rectangle of the knob (without scale)
*/
void QwtKnob::drawKnob(QPainter *painter, const QRect &r)
{
#if QT_VERSION < 0x040000
    const QBrush buttonBrush = colorGroup().brush(QColorGroup::Button);
    const QColor buttonTextColor = colorGroup().buttonText();
    const QColor lightColor = colorGroup().light();
    const QColor darkColor = colorGroup().dark();
#else
    const QBrush buttonBrush = palette().brush(QPalette::Button);
    const QColor buttonTextColor = palette().color(QPalette::ButtonText);
    const QColor lightColor = palette().color(QPalette::Light);
    const QColor darkColor = palette().color(QPalette::Dark);
#endif

    const int bw2 = d_data->borderWidth / 2;

    const int radius = (qwtMin(r.width(), r.height()) - bw2) / 2;

    const QRect aRect( 
        r.center().x() - radius, r.center().y() - radius,
        2 * radius, 2 * radius);

    //
    // draw button face
    //
    painter->setBrush(buttonBrush);
    painter->drawEllipse(aRect);

    //
    // draw button shades
    //
    QPen pn;
    pn.setWidth(d_data->borderWidth);

    pn.setColor(lightColor);
    painter->setPen(pn);
    painter->drawArc(aRect, 45*16, 180*16);

    pn.setColor(darkColor);
    painter->setPen(pn);
    painter->drawArc(aRect, 225*16, 180*16);

    //
    // draw marker
    //
    if ( isValid() )
        drawMarker(painter, d_data->angle, buttonTextColor);
}
/** Repaint custom item upon system notification */
void CustomItem::paintEvent(QPaintEvent *e)
{
#if REPORT_LEVEL <= LOG_INFORMATION
  QRect r(e->rect());
  reportToLog(LOG_INFORMATION, LC_HIGHUI, 
 	      "CustomItem::paintEvent (%d,%d,%d,%d)\n",
 	      r.left(), r.top(), r.right(), r.bottom());
#endif

  Item::paintEvent(e);

    if (hasFocus()) {
      QPainter painter(this);
      QRect focusRect = drawable->geometry();
      
      // focusRect.setWidth(focusRect.width() + 3);
      // focusRect.setHeight(focusRect.height() + 3);

      focusRect.moveBy(-2, -2);
      focusRect.rRight() += 4;
      focusRect.rBottom() += 4;

      style().drawFocusRect(&painter, focusRect, colorGroup());
    }
}