Beispiel #1
0
void KSelector::paintEvent( QPaintEvent * )
{
  QPainter painter;
  int w = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
  int iw = (w < ARROWSIZE) ? ARROWSIZE : w;

  painter.begin( this );

  drawContents( &painter );

  QBrush brush;

  QPoint pos = calcArrowPos( value() );
  drawArrow( &painter, pos );

  if ( indent() )
  {
    QStyleOptionFrame opt;
    opt.initFrom( this );
    opt.state = QStyle::State_Sunken;
    if ( orientation() == Qt::Vertical )
      opt.rect.adjust( 0, iw - w, -5, w - iw );
    else
      opt.rect.adjust(iw - w, 0, w - iw, -5);
    style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );
  }


  painter.end();
}
Beispiel #2
0
void MultiLineEdit::updateSizeHint()
{
    QFontMetrics fm(font());
    int minPixelHeight = fm.lineSpacing() * _minHeight;
    int maxPixelHeight = fm.lineSpacing() * _maxHeight;
    int scrollBarHeight = horizontalScrollBar()->isVisible() ? horizontalScrollBar()->height() : 0;

    // use the style to determine a decent size
    int h = qMin(qMax((int)document()->size().height() + scrollBarHeight, minPixelHeight), maxPixelHeight) + 2 * frameWidth();

    QStyleOptionFrame opt;
    opt.initFrom(this);
    opt.rect = QRect(0, 0, 100, h);
    opt.lineWidth = lineWidth();
    opt.midLineWidth = midLineWidth();
    opt.state |= QStyle::State_Sunken;
    QWidget* widget = this;
#ifdef Q_OS_MAC
    widget = 0;
#endif
    QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h).expandedTo(QApplication::globalStrut()), widget);
    if (s != _sizeHint) {
        _sizeHint = s;
        updateGeometry();
    }
}
Beispiel #3
0
QSize QILineEdit::featTextWidth (const QString &aText) const
{
    QStyleOptionFrame sof;
    sof.initFrom (this);
    sof.rect = contentsRect();
    sof.lineWidth = hasFrame() ? style()->pixelMetric (QStyle::PM_DefaultFrameWidth) : 0;
    sof.midLineWidth = 0;
    sof.state |= QStyle::State_Sunken;

    /* The margins are based on qlineedit.cpp of Qt. Maybe they where changed
     * at some time in the future. */
    QSize sc (fontMetrics().width (aText) + 2*2,
              fontMetrics().xHeight()     + 2*1);
    QSize sa = style()->sizeFromContents (QStyle::CT_LineEdit, &sof, sc, this);

#if defined (Q_WS_WIN32)
    /* Vista l&f style has a bug where the last parameter of sizeFromContents
     * function ('widget' what corresponds to 'this' in our class) is ignored.
     * Due to it QLineEdit processed as QComboBox and size calculation includes
     * non-existing combo-box button of 23 pix in width. So fixing it here: */
    if (qobject_cast <QWindowsVistaStyle*> (style()))
    {
        /* Check if l&f style theme is really active else painting performed by
         * Windows Classic theme and there is no such shifting error. */
        typedef bool (*IsAppThemedFunction)();
        IsAppThemedFunction isAppThemed =
            (IsAppThemedFunction) QLibrary::resolve ("uxtheme", "IsAppThemed");
        if (isAppThemed && isAppThemed()) sa -= QSize (23, 0);
    }
#endif

    return sa;
}
Beispiel #4
0
void QxtToolTipPrivate::paintEvent(QPaintEvent* event)
{
    Q_UNUSED(event);
    QStylePainter painter(this);
    QStyleOptionFrame opt;
    opt.initFrom(this);
    painter.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
}
Beispiel #5
0
void ColorButton::paintEvent(QPaintEvent *ev)
{
	QPushButton::paintEvent(ev);
	QPainter p(this);

	// Get contents rectangle
	QStyleOptionButton opt;
	initStyleOption(&opt);
	QRect cRect;
	if(isFlat()) {
		// Fill the entire widget area
		cRect = rect();
	} else {
		// Only fill the contents area
		cRect =
			style()->subElementRect(QStyle::SE_PushButtonContents, &opt, this);
	}
	cRect.adjust(1, 1, -1, -1); // A little larger padding please

	// Colour fill
	if(m_color.alpha() == 255)
		p.fillRect(cRect, m_color);
	else {
		// Separate left and right rectangles
		QRect lRect = cRect;
		lRect.setWidth(lRect.width() / 2 + 1);
		QRect rRect = cRect;
		rRect.setLeft(lRect.right());

		// Fill the left with the solid colour
		p.fillRect(
			lRect, QColor(m_color.red(), m_color.green(), m_color.blue()));

		// Fill the right with the transparent colour on a checkerboard
		drawCheckerboard(p, rRect, 5, Qt::white, QColor(0xCC, 0xCC, 0xCC));
		p.fillRect(rRect, m_color);
	}

	// Sunken frame
	QStyleOptionFrame fOpt;
	fOpt.initFrom(this);
	fOpt.rect = cRect;
	fOpt.features = QStyleOptionFrame::None;
	fOpt.frameShape = QFrame::Panel;
	fOpt.lineWidth = 1;
	fOpt.midLineWidth = 0;
	fOpt.state |= QStyle::State_Sunken;
	style()->drawControl(QStyle::CE_ShapedFrame, &fOpt, &p, this);

	// Fade out when disabled
	if(!isEnabled()) {
		QBrush brush = palette().base();
		QColor col = brush.color();
		col.setAlpha(127); // 50% transparency
		brush.setColor(col);
		p.fillRect(cRect, brush);
	}
}
void QwtPlotAbstractCanvas::drawStyled( QPainter *painter, bool hackStyledBackground )
{
    fillBackground( painter );

    if ( hackStyledBackground )
    {
        // Antialiasing rounded borders is done by
        // inserting pixels with colors between the 
        // border color and the color on the canvas,
        // When the border is painted before the plot items
        // these colors are interpolated for the canvas
        // and the plot items need to be clipped excluding
        // the anialiased pixels. In situations, where
        // the plot items fill the area at the rounded
        // borders this is noticeable.
        // The only way to avoid these annoying "artefacts"
        // is to paint the border on top of the plot items.

        if ( !d_data->styleSheet.hasBorder ||
            d_data->styleSheet.borderPath.isEmpty() )
        {
            // We have no border with at least one rounded corner
            hackStyledBackground = false;
        }
    }
    
    QWidget *w = canvasWidget();

    if ( hackStyledBackground )
    {
        painter->save();
        
        // paint background without border
        painter->setPen( Qt::NoPen );
        painter->setBrush( d_data->styleSheet.background.brush );
        painter->setBrushOrigin( d_data->styleSheet.background.origin );
        painter->setClipPath( d_data->styleSheet.borderPath );
        painter->drawRect( w->contentsRect() );

        painter->restore();

        drawCanvas( painter );

        // Now paint the border on top
        QStyleOptionFrame opt;
        opt.initFrom( w );
        w->style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, w);
    }   
    else
    {
        QStyleOption opt;
        opt.initFrom( w );
        w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w );
    
        drawCanvas( painter );
    }   
}   
void QgsGradientStopEditor::paintEvent( QPaintEvent *event )
{
  Q_UNUSED( event );
  QPainter painter( this );

  QRect frameRect( rect().x() + MARGIN_X, rect().y(),
                   rect().width() - 2 * MARGIN_X,
                   rect().height() - MARGIN_BOTTOM );

  //draw frame
  QStyleOptionFrame option;
  option.initFrom( this );
  option.state = hasFocus() ? QStyle::State_KeyboardFocusChange : QStyle::State_None;
  option.rect = frameRect;
  style()->drawPrimitive( QStyle::PE_Frame, &option, &painter );

  if ( hasFocus() )
  {
    //draw focus rect
    QStyleOptionFocusRect option;
    option.initFrom( this );
    option.state = QStyle::State_KeyboardFocusChange;
    option.rect = frameRect;
    style()->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter );
  }

  //start with the checkboard pattern
  QBrush checkBrush = QBrush( transparentBackground() );
  painter.setBrush( checkBrush );
  painter.setPen( Qt::NoPen );

  QRect box( frameRect.x() + FRAME_MARGIN, frameRect.y() + FRAME_MARGIN,
             frameRect.width() - 2 * FRAME_MARGIN,
             frameRect.height() - 2 * FRAME_MARGIN );

  painter.drawRect( box );

  // draw gradient preview on top of checkerboard
  for ( int i = 0; i < box.width() + 1; ++i )
  {
    QPen pen( mGradient.color( static_cast< double >( i ) / box.width() ) );
    painter.setPen( pen );
    painter.drawLine( box.left() + i, box.top(), box.left() + i, box.height() + 1 );
  }

  // draw stop markers
  int markerTop = frameRect.bottom() + 1;
  drawStopMarker( painter, QPoint( box.left(), markerTop ), mGradient.color1(), mSelectedStop == 0 );
  drawStopMarker( painter, QPoint( box.right(), markerTop ), mGradient.color2(), mSelectedStop == mGradient.count() - 1 );
  int i = 1;
  Q_FOREACH ( const QgsGradientStop& stop, mStops )
  {
    int x = stop.offset * box.width() + box.left();
    drawStopMarker( painter, QPoint( x, markerTop ), stop.color, mSelectedStop == i );
    ++i;
  }
Beispiel #8
0
void ComboBox::paintEvent( QPaintEvent * _pe )
{
	QPainter p( this );

	p.fillRect( 2, 2, width()-2, height()-4, *s_background );

	QColor shadow = palette().shadow().color();
	QColor highlight = palette().highlight().color();

	shadow.setAlpha( 124 );
	highlight.setAlpha( 124 );

	// button-separator
	p.setPen( shadow );
	p.drawLine( width() - CB_ARROW_BTN_WIDTH - 1, 1, width() - CB_ARROW_BTN_WIDTH - 1, height() - 3 );

	p.setPen( highlight );
	p.drawLine( width() - CB_ARROW_BTN_WIDTH, 1, width() - CB_ARROW_BTN_WIDTH, height() - 3 );

	// Border
	QStyleOptionFrame opt;
	opt.initFrom( this );
	opt.state = 0;

	style()->drawPrimitive( QStyle::PE_Frame, &opt, &p, this );

	QPixmap * arrow = m_pressed ? s_arrowSelected : s_arrow;

	p.drawPixmap( width() - CB_ARROW_BTN_WIDTH + 5, 4, *arrow );

	if( model() && model()->size() > 0 )
	{
		p.setFont( font() );
		p.setClipRect( QRect( 4, 2, width() - CB_ARROW_BTN_WIDTH - 8, height() - 2 ) );
		QPixmap pm = model()->currentData() ?  model()->currentData()->pixmap() : QPixmap();
		int tx = 5;
		if( !pm.isNull() )
		{
			if( pm.height() > 16 )
			{
				pm = pm.scaledToHeight( 16, Qt::SmoothTransformation );
			}
			p.drawPixmap( tx, 3, pm );
			tx += pm.width() + 3;
		}
		const int y = ( height()+p.fontMetrics().height() ) /2;
		p.setPen( QColor( 64, 64, 64 ) );
		p.drawText( tx+1, y-3, model()->currentText() );
		p.setPen( QColor( 224, 224, 224 ) );
		p.drawText( tx, y-4, model()->currentText() );
	}
}
Beispiel #9
0
void KXYSelector::paintEvent( QPaintEvent * /* ev */ )
{
  QStyleOptionFrame opt;
  opt.initFrom(this);

  QPainter painter;
  painter.begin( this );

  drawContents( &painter );
  drawMarker( &painter, d->px, d->py );

  style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );

  painter.end();
}
Beispiel #10
0
void KviThemedComboBox::paintEvent(QPaintEvent * event)
{
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	QPainter * p = new QPainter(this);
	QLineEdit * le = lineEdit();
	if(le)
	{
		QRect r = rect();
		QPalette pal = palette();

		QStyleOptionFrame option;

		option.initFrom(this);
		option.rect = contentsRect();
		option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, le);
		option.midLineWidth = 0;
		option.state |= QStyle::State_Sunken;
		if(le->isReadOnly())
			option.state |= QStyle::State_ReadOnly;
		option.features = QStyleOptionFrame::None;
		style()->drawPrimitive(QStyle::PE_FrameLineEdit, &option, p, this);

		r = style()->subElementRect(QStyle::SE_LineEditContents, &option, le);
		int left, right, top, bottom;
		le->getTextMargins(&left, &top, &right, &bottom);
		r.setX(r.x() + left);
		r.setY(r.y() + top);
		r.setRight(r.right() - right);
		r.setBottom(r.bottom() - bottom);
		p->setClipRect(r);
	} // else not editable

	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		p->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		p->fillRect(contentsRect(), col);
	}
	else if(g_pShadedChildGlobalDesktopBackground)
	{
		QPoint pnt = m_pKviWindow->isDocked() ? mapTo(g_pMainWindow, contentsRect().topLeft()) : mapTo(m_pKviWindow, contentsRect().topLeft());
		p->drawTiledPixmap(contentsRect(), *(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	delete p;
#endif
	QComboBox::paintEvent(event);
}
Beispiel #11
0
void ValueSlider::paintEvent(QPaintEvent *)
{
	QPainter painter(this);
	drawFrame(&painter);
	QRect rectangle = contentsRect();
	QStyleOptionFrame optionFrame;
	optionFrame.initFrom(this);
	if (optionFrame.state & QStyle::State_Enabled)
	{
		painter.drawPixmap(rectangle.topLeft(), pixMap);
		DrawTriangle(&painter, trianglePoint);
	} else {
		QIcon icon(pixMap);
		icon.paint(&painter, rectangle, 0, QIcon::Disabled);
	}
}
Beispiel #12
0
/*!
  \internal
  Updates the frame widths from the style.
*/
void QFramePrivate::updateStyledFrameWidths()
{
    Q_Q(const QFrame);
    QStyleOptionFrame opt;
    opt.initFrom(q);
    opt.lineWidth = lineWidth;
    opt.midLineWidth = midLineWidth;
    opt.frameShape = QFrame::Shape(frameStyle & QFrame::Shape_Mask);

    QRect cr = q->style()->subElementRect(QStyle::SE_ShapedFrameContents, &opt, q);
    leftFrameWidth = cr.left() - opt.rect.left();
    topFrameWidth = cr.top() - opt.rect.top();
    rightFrameWidth = opt.rect.right() - cr.right(),
    bottomFrameWidth = opt.rect.bottom() - cr.bottom();
    frameWidth = qMax(qMax(leftFrameWidth, rightFrameWidth),
                      qMax(topFrameWidth, bottomFrameWidth));
}
/*!
   Calculate a mask, that can be used to clip away the border frame

   \param size Size including the frame
*/
QBitmap QwtPlotCanvas::borderMask( const QSize &size ) const
{
    const QRect r( 0, 0, size.width(), size.height() );

    const QPainterPath path = borderPath( r );
    if ( path.isEmpty() )
        return QBitmap();

    QImage image( size, QImage::Format_ARGB32_Premultiplied );
    image.fill( Qt::color0 );

    QPainter painter( &image );
    painter.setClipPath( path );
    painter.fillRect( r, Qt::color1 );

    // now erase the frame

    painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );

    if ( testAttribute(Qt::WA_StyledBackground ) )
    {
        QStyleOptionFrame opt;
        opt.initFrom(this);
        opt.rect = r;
        style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );
    }
    else
    {
        if ( d_data->borderRadius > 0 && frameWidth() > 0 )
        {
            painter.setPen( QPen( Qt::color1, frameWidth() ) );
            painter.setBrush( Qt::NoBrush );
            painter.setRenderHint( QPainter::Antialiasing, true );

            painter.drawPath( path );
        }
    }

    painter.end();

    const QImage mask = image.createMaskFromColor(
        QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );

    return QBitmap::fromImage( mask );
}
void ColorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                           const QModelIndex &index) const
{
    if (index.data().canConvert<QColor>())
    {
        QStyleOptionFrame panel;
        panel.initFrom(option.widget);
        if (option.widget->isEnabled())
            panel.state = QStyle::State_Enabled;
        panel.rect = option.rect;
        panel.lineWidth = 2;
        panel.midLineWidth = 0;
        panel.state |= QStyle::State_Sunken;
        option.widget->style()->drawPrimitive(QStyle::PE_Frame, &panel, painter, nullptr);
        QRect r = option.widget->style()->subElementRect(QStyle::SE_FrameContents, &panel, nullptr);
        painter->setClipRect(r);
        painter->fillRect(option.rect, index.data().value<QColor>());
    }
}
Beispiel #15
0
/*!
 * \internal
 */
void HacLed::paintEvent(QPaintEvent * )
{
    QPainter p(this);
    QColor bgColor = palette().background().color();

    if (d->shape==Circular) {
        int sidesize = qMin(width(), height());
        p.setRenderHint(QPainter::Antialiasing);
        int rad = sidesize*0.45;
        QRect r = rect().adjusted((width()-sidesize)/2, (height()-sidesize)/2, -(width()-sidesize)/2, -(height()-sidesize)/2);
        QRadialGradient grad(rect().center(), rad, rect().center()-QPoint(sidesize*0.1, sidesize*0.1) );
        grad.setColorAt(0.0, palette().color(QPalette::Light));
        grad.setColorAt(0.75, isChecked() ? d->color : bgColor);
        p.setBrush(grad);
        QPen pe = p.pen();
        pe.setWidth(d->width);
        pe.setColor(palette().color(QPalette::Foreground));
        p.setPen(pe);

        p.drawEllipse(r.adjusted(d->width,d->width,-d->width,-d->width));
    } else { /*if (d->shape == Rectangular)*/
        QStyleOptionFrame opt;
        opt.initFrom(this);
        opt.lineWidth = d->width;
        opt.midLineWidth = d->width;
        if (d->shape==RectangularRaised)
            opt.state |= QStyle::State_Raised;
        else if (d->shape==RectangularSunken)
            opt.state |= QStyle::State_Sunken;
        QBrush br(isChecked() ? d->color : bgColor);
        if (d->shape==RectangularPlain)
            qDrawPlainRect(&p, opt.rect, opt.palette.foreground().color(), d->width, &br);
        else
            qDrawShadePanel(&p, opt.rect, opt.palette, d->shape==RectangularSunken, d->width, &br);
    }
}
Beispiel #16
0
void Swatch::paintEvent(QPaintEvent* event)
{
    QSize rowcols = p->rowcols();
    if ( rowcols.isEmpty() )
        return;

    QSizeF color_size = p->actualColorSize(rowcols);
    QPixmap alpha_pattern(detail::alpha_pixmap());
    QPen penEmptyBorder = p->border;
    QColor colorEmptyBorder = p->border.color();
    colorEmptyBorder.setAlpha(56);
    penEmptyBorder.setColor(colorEmptyBorder);
    QPainter painter(this);

    QStyleOptionFrame panel;
    panel.initFrom(this);
    panel.lineWidth = 1;
    panel.midLineWidth = 0;
    panel.state |= QStyle::State_Sunken;
    style()->drawPrimitive(QStyle::PE_Frame, &panel, &painter, this);
    QRect r = style()->subElementRect(QStyle::SE_FrameContents, &panel, this);
    painter.setClipRect(r);

    int count = p->palette.count();
        painter.setPen(p->border);
    for ( int y = 0, i = 0; i < count; y++ )
    {
        for ( int x = 0; x < rowcols.width() && i < count; x++, i++ )
        {
            if(p->palette.colorAt(i) == p->emptyColor)
            {
              painter.setBrush(Qt::NoBrush);
              painter.setPen(penEmptyBorder);
              painter.drawRect(p->indexRect(i, rowcols, color_size));
              continue;
            }
            painter.setBrush(alpha_pattern);
            painter.drawRect(p->indexRect(i, rowcols, color_size));
            painter.setBrush(p->palette.colorAt(i));
            painter.drawRect(p->indexRect(i, rowcols, color_size));
        }
    }

    painter.setClipping(false);

    if ( p->drop_index != -1 )
    {
        QRectF drop_area = p->indexRect(p->drop_index, rowcols, color_size);
        if ( p->drop_overwrite )
        {
            painter.setBrush(p->drop_color);
            painter.setPen(QPen(Qt::gray));
            painter.drawRect(drop_area);
        }
        else if ( rowcols.width() == 1 )
        {
            // 1 column => vertical style
            painter.setPen(QPen(p->drop_color, 2));
            painter.setBrush(Qt::transparent);
            painter.drawLine(drop_area.topLeft(), drop_area.topRight());
        }
        else
        {
            painter.setPen(QPen(p->drop_color, 2));
            painter.setBrush(Qt::transparent);
            painter.drawLine(drop_area.topLeft(), drop_area.bottomLeft());
            // Draw also on the previous line when the first item of a line is selected
            if ( p->drop_index % rowcols.width() == 0 && p->drop_index != 0 )
            {
                drop_area = p->indexRect(p->drop_index-1, rowcols, color_size);
                drop_area.translate(color_size.width(), 0);
                painter.drawLine(drop_area.topLeft(), drop_area.bottomLeft());
            }
        }
    }

    if ( p->selected != -1 )
    {
        QRectF rect = p->indexRect(p->selected, rowcols, color_size);
        painter.setBrush(Qt::transparent);
        painter.setPen(QPen(Qt::darkGray, 2));
        painter.drawRect(rect);
        painter.setPen(p->selection);
        painter.drawRect(rect);
    }
}
static QBitmap qwtBorderMask( const QWidget *canvas, const QSize &size )
{
    const QRect r( 0, 0, size.width(), size.height() );

    QPainterPath borderPath;

    ( void )QMetaObject::invokeMethod(
        const_cast< QWidget *>( canvas ), "borderPath", Qt::DirectConnection,
        Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) );

    if ( borderPath.isEmpty() )
    {
        if ( canvas->contentsRect() == canvas->rect() )
            return QBitmap();

        QBitmap mask( size );
        mask.fill( Qt::color0 );

        QPainter painter( &mask );
        painter.fillRect( canvas->contentsRect(), Qt::color1 );

        return mask;
    }

    QImage image( size, QImage::Format_ARGB32_Premultiplied );
    image.fill( Qt::color0 );

    QPainter painter( &image );
    painter.setClipPath( borderPath );
    painter.fillRect( r, Qt::color1 );

    // now erase the frame

    painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );

    if ( canvas->testAttribute(Qt::WA_StyledBackground ) )
    {
        QStyleOptionFrame opt;
        opt.initFrom(canvas);
        opt.rect = r;
        canvas->style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, canvas );
    }
    else
    {
        const QVariant borderRadius = canvas->property( "borderRadius" );
        const QVariant frameWidth = canvas->property( "frameWidth" );

        if ( borderRadius.type() == QVariant::Double
                && frameWidth.type() == QVariant::Int )
        {
            const double br = borderRadius.toDouble();
            const int fw = frameWidth.toInt();

            if ( br > 0.0 && fw > 0 )
            {
                painter.setPen( QPen( Qt::color1, fw ) );
                painter.setBrush( Qt::NoBrush );
                painter.setRenderHint( QPainter::Antialiasing, true );

                painter.drawPath( borderPath );
            }
        }
    }

    painter.end();

    const QImage mask = image.createMaskFromColor(
                            QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );

    return QBitmap::fromImage( mask );
}
void QwtPlotCanvas::drawCanvas( QPainter *painter, bool withBackground ) 
{
    bool hackStyledBackground = false;

    if ( withBackground && testAttribute( Qt::WA_StyledBackground ) 
        && testPaintAttribute( HackStyledBackground ) )
    {
        // Antialiasing rounded borders is done by
        // inserting pixels with colors between the 
        // border color and the color on the canvas,
        // When the border is painted before the plot items
        // these colors are interpolated for the canvas
        // and the plot items need to be clipped excluding
        // the anialiased pixels. In situations, where
        // the plot items fill the area at the rounded
        // borders this is noticeable.
        // The only way to avoid these annoying "artefacts"
        // is to paint the border on top of the plot items.

        if ( d_data->styleSheet.hasBorder &&
            !d_data->styleSheet.borderPath.isEmpty() )
        {
            // We have a border with at least one rounded corner
            hackStyledBackground = true;
        }
    }

    if ( withBackground )
    {
        painter->save();

        if ( testAttribute( Qt::WA_StyledBackground ) )
        {
            if ( hackStyledBackground )
            {
                // paint background without border

                painter->setPen( Qt::NoPen );
                painter->setBrush( d_data->styleSheet.background.brush ); 
                painter->setBrushOrigin( d_data->styleSheet.background.origin );
                painter->setClipPath( d_data->styleSheet.borderPath );
                painter->drawRect( contentsRect() );
            }
            else
            {
                qwtDrawStyledBackground( this, painter );
            }
        }
        else if ( autoFillBackground() )
        {
            painter->setPen( Qt::NoPen );
            painter->setBrush( palette().brush( backgroundRole() ) );

            if ( d_data->borderRadius > 0.0 && ( rect() == frameRect() ) )
            {
                if ( frameWidth() > 0 )
                {
                    painter->setClipPath( borderPath( rect() ) );
                    painter->drawRect( rect() );
                }
                else
                {
                    painter->setRenderHint( QPainter::Antialiasing, true );
                    painter->drawPath( borderPath( rect() ) );
                }
            }
            else
            {
                painter->drawRect( rect() );
            }
        }

        painter->restore();
    }

    painter->save();

    if ( !d_data->styleSheet.borderPath.isEmpty() )
    {
        painter->setClipPath( 
            d_data->styleSheet.borderPath, Qt::IntersectClip );
    }
    else
    {
        if ( d_data->borderRadius > 0.0 )
            painter->setClipPath( borderPath( frameRect() ), Qt::IntersectClip );
        else
            painter->setClipRect( contentsRect(), Qt::IntersectClip );
    }

    plot()->drawCanvas( painter );

    painter->restore();

    if ( withBackground && hackStyledBackground )
    {
        // Now paint the border on top
        QStyleOptionFrame opt;
        opt.initFrom(this);
        style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, this);
    }
}
Beispiel #19
0
void ChartWidget::draw_frame(QPainter& painter) const
{
    QStyleOptionFrame option;
    option.initFrom(this);
    style()->drawPrimitive(QStyle::PE_Frame, &option, &painter, this);
}
Beispiel #20
0
void LcdWidget::paintEvent( QPaintEvent* )
{
	QPainter p( this );

	QSize cellSize( m_cellWidth, m_cellHeight );

	QRect cellRect( 0, 0, m_cellWidth, m_cellHeight );

	int margin = 1;  // QStyle::PM_DefaultFrameWidth;
	//int lcdWidth = m_cellWidth * m_numDigits + (margin*m_marginWidth)*2;

//	p.translate( width() / 2 - lcdWidth / 2, 0 ); 
	p.save();

	p.translate( margin, margin );

	// Left Margin
	p.drawPixmap( cellRect, *m_lcdPixmap, 
			QRect( QPoint( charsPerPixmap*m_cellWidth, 
				isEnabled()?0:m_cellHeight ), 
			cellSize ) );

	p.translate( m_marginWidth, 0 );

	// Padding
	for( int i=0; i < m_numDigits - m_display.length(); i++ ) 
	{
		p.drawPixmap( cellRect, *m_lcdPixmap, 
			QRect( QPoint( 10 * m_cellWidth, isEnabled()?0:m_cellHeight) , cellSize ) );
		p.translate( m_cellWidth, 0 );
	}

	// Digits
	for( int i=0; i < m_display.length(); i++ ) 
	{
		int val = m_display[i].digitValue();
		if( val < 0 ) 
		{
			if( m_display[i] == '-' )
				val = 11;
			else
				val = 10;
		}
		p.drawPixmap( cellRect, *m_lcdPixmap,
				QRect( QPoint( val*m_cellWidth, 
					isEnabled()?0:m_cellHeight ),
				cellSize ) );
		p.translate( m_cellWidth, 0 );
	}

	// Right Margin
	p.drawPixmap( QRect( 0, 0, m_marginWidth-1, m_cellHeight ), *m_lcdPixmap, 
			QRect( charsPerPixmap*m_cellWidth, isEnabled()?0:m_cellHeight,
				m_cellWidth / 2, m_cellHeight ) );


	p.restore();

	// Border
	QStyleOptionFrame opt;
	opt.initFrom( this );
	opt.state = QStyle::State_Sunken;
	opt.rect = QRect( 0, 0, m_cellWidth * m_numDigits + (margin+m_marginWidth)*2 - 1,
			m_cellHeight + (margin*2) );

	style()->drawPrimitive( QStyle::PE_Frame, &opt, &p, this );

	p.resetTransform();

	// Label
	if( !m_label.isEmpty() )
	{
		p.setFont( pointSizeF( p.font(), 6.5 ) );
		p.setPen( QColor( 64, 64, 64 ) );
		p.drawText( width() / 2 -
				p.fontMetrics().width( m_label ) / 2 + 1,
						height(), m_label );
		p.setPen( QColor( 255, 255, 255 ) );
		p.drawText( width() / 2 -
				p.fontMetrics().width( m_label ) / 2,
						height() - 1, m_label );
	}

}