当前位置: 首页>>代码示例>>C++>>正文


C++ QBrush::gradient方法代码示例

本文整理汇总了C++中QBrush::gradient方法的典型用法代码示例。如果您正苦于以下问题:C++ QBrush::gradient方法的具体用法?C++ QBrush::gradient怎么用?C++ QBrush::gradient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QBrush的用法示例。


在下文中一共展示了QBrush::gradient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void DiagramSettings::Private::changeBackgroundColor()
{
    if ( m_chart && m_chart->coordinatePlane() && m_chart->coordinatePlane()->diagram() )
    {
        BackgroundAttributes bat = m_chart->coordinatePlane()->backgroundAttributes();
        bat.setVisible( true );
        ui->visibleBtn->setChecked( true );

        if ( ui->color->isChecked() )
        {

            QBrush setBrush = bat.brush();
            const QColor color = QColorDialog::getColor( setBrush.color(), qq, tr( "Choose new color" ) );
            if ( !color.isValid() )
                return;
            bat.setBrush( color );
            QPalette palette = ui->diagramBackground->palette();
            palette.setBrush( QPalette::Button, color );
            ui->diagramBackground->setPalette( palette );
        }
        else if ( ui->textureBtn->isChecked() )
        {
            //QBrush setBrush = m_chart->coordinatePlane()->diagram()->brush( index );
            QImage texture;

            const QString filename = QFileDialog::getOpenFileName( qq, tr( "Choose Texture" ), QString(), tr( "Images (*.png *.xpm *.jpg)" ) );
            if ( filename.isEmpty() )
                return;
            texture = QImage( filename );
            bat.setBrush( texture );
            QPalette palette = ui->diagramBackground->palette();
            palette.setBrush( QPalette::Button, QBrush( texture ) );
            ui->diagramBackground->setPalette( palette );
        }
        else
        {
            QBrush setBrush = bat.brush();
            QGradient grad;
            QLinearGradient lGrad;
            lGrad.setColorAt( 0, Qt::black );
            lGrad.setColorAt( 1, setBrush.color() );
            grad = lGrad;

            if ( setBrush.gradient() )
                grad = *setBrush.gradient();
            const QGradient &color = GradientDialog::getGradient( grad, qq, tr( "Choose new color" ) );
            bat.setBrush( color );
            QPalette palette = ui->diagramBackground->palette();
            palette.setBrush( QPalette::Button, QBrush( color ) );
            ui->diagramBackground->setPalette( palette );
        }
        bat.setVisible( true );
        m_chart->coordinatePlane()->setBackgroundAttributes( bat );
        qq->update();
    }
}
开发者ID:KDE,项目名称:kdiagram,代码行数:56,代码来源:diagramsettings.cpp

示例2: flipBrush

QBrush DBrushAdjuster::flipBrush(const QBrush &brush, Qt::Orientation o)
{
	QBrush brush1(brush);
	if(brush.gradient())
	{
		QGradient grad = DGradientAdjuster::flipGradient( brush.gradient(), o );
		brush1 = QBrush(grad);
	}
	else if(!brush.texture().isNull())
	{
	}
	return brush1;
}
开发者ID:BackupTheBerlios,项目名称:adresis-svn,代码行数:13,代码来源:dbrushadjuster.cpp

示例3: saveOdfGradientStyle

QString KoOdfGraphicStyles::saveOdfGradientStyle(KoGenStyles &mainStyles, const QBrush &brush)
{
    KoGenStyle gradientStyle;
    if (brush.style() == Qt::RadialGradientPattern) {
        const QRadialGradient *gradient = static_cast<const QRadialGradient*>(brush.gradient());
        gradientStyle = KoGenStyle(KoGenStyle::RadialGradientStyle /*no family name*/);
        gradientStyle.addAttributePercent("svg:cx", gradient->center().x() * 100);
        gradientStyle.addAttributePercent("svg:cy", gradient->center().y() * 100);
        gradientStyle.addAttributePercent("svg:r",  gradient->radius() * 100);
        gradientStyle.addAttributePercent("svg:fx", gradient->focalPoint().x() * 100);
        gradientStyle.addAttributePercent("svg:fy", gradient->focalPoint().y() * 100);
    } else if (brush.style() == Qt::LinearGradientPattern) {
        const QLinearGradient *gradient = static_cast<const QLinearGradient*>(brush.gradient());
        gradientStyle = KoGenStyle(KoGenStyle::LinearGradientStyle /*no family name*/);
        gradientStyle.addAttributePercent("svg:x1", gradient->start().x() * 100);
        gradientStyle.addAttributePercent("svg:y1", gradient->start().y() * 100);
        gradientStyle.addAttributePercent("svg:x2", gradient->finalStop().x() * 100);
        gradientStyle.addAttributePercent("svg:y2", gradient->finalStop().y() * 100);
    } else if (brush.style() == Qt::ConicalGradientPattern) {
        const QConicalGradient * gradient = static_cast<const QConicalGradient*>(brush.gradient());
        gradientStyle = KoGenStyle(KoGenStyle::ConicalGradientStyle /*no family name*/);
        gradientStyle.addAttributePercent("svg:cx", gradient->center().x() * 100);
        gradientStyle.addAttributePercent("svg:cy", gradient->center().y() * 100);
        gradientStyle.addAttribute("draw:angle", QString("%1").arg(gradient->angle()));
    }
    const QGradient * gradient = brush.gradient();
    if (gradient->spread() == QGradient::RepeatSpread)
        gradientStyle.addAttribute("svg:spreadMethod", "repeat");
    else if (gradient->spread() == QGradient::ReflectSpread)
        gradientStyle.addAttribute("svg:spreadMethod", "reflect");
    else
        gradientStyle.addAttribute("svg:spreadMethod", "pad");

    if (! brush.transform().isIdentity()) {
        gradientStyle.addAttribute("svg:gradientTransform", saveTransformation(brush.transform()));
    }

    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly);
    KoXmlWriter elementWriter(&buffer);    // TODO pass indentation level

    // save stops
    QGradientStops stops = gradient->stops();
    Q_FOREACH (const QGradientStop & stop, stops) {
        elementWriter.startElement("svg:stop");
        elementWriter.addAttribute("svg:offset", QString("%1").arg(stop.first));
        elementWriter.addAttribute("svg:stop-color", stop.second.name());
        if (stop.second.alphaF() < 1.0)
            elementWriter.addAttribute("svg:stop-opacity", QString("%1").arg(stop.second.alphaF()));
        elementWriter.endElement();
    }
开发者ID:ChrisJong,项目名称:krita,代码行数:51,代码来源:KoOdfGraphicStyles.cpp

示例4: brush

QBrush FillTab::brush(QBrush b) const {

  QColor this_color = colorDirty() ? color() : b.color();
  Qt::BrushStyle this_style = styleDirty() ? style() : b.style();

  if (useGradientDirty()) {
    // Apply / unapply gradient
    if (useGradient()) {
      b = QBrush(gradient());
    } else {
      b.setColor(this_color);
      b.setStyle(this_style);
    }
  } else {
    // Leave gradient but make other changes.
    QGradient this_gradient;
    if (const QGradient *grad = b.gradient()) {
      if (gradientDirty()) {
        this_gradient = gradient();
      } else {
        this_gradient = *grad;
      }
      b = QBrush(this_gradient);
    } else {
      b.setColor(this_color);
      b.setStyle(this_style);
    }
  }

  return b;
}
开发者ID:Kst-plot,项目名称:kst-subversion-archive,代码行数:31,代码来源:filltab.cpp

示例5: paint

void DCellViewItemDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
	Q_ASSERT(index.isValid());
	const QAbstractItemModel *model = index.model();
	Q_ASSERT(model);
	
	QVariant value;

	QStyleOptionViewItem opt = option;

    	// do layout
	QImage img = qvariant_cast<QImage>(model->data(index,Qt::DisplayRole));
	
	if( ! img.isNull() )
	{
		painter->drawImage(opt.rect, img);
	}
	
	// draw the background color
	value = model->data(index, Qt::BackgroundColorRole);
	if (value.isValid()/* && qvariant_cast<QBrush>(value).isValid()*/)
	{
		QBrush brush = qvariant_cast<QBrush>(value);
		
		if ( brush.gradient() )
		{
			QGradient newGradient = DGradientAdjuster::adjustGradient( brush.gradient(), option.rect);
			painter->fillRect(option.rect, QBrush(newGradient));
		}
		else
		{
			painter->fillRect(option.rect, brush);
		}
	}
	
	
	// Selection!
	if (option.showDecorationSelected && (option.state & QStyle::State_Selected))
	{
		QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
		
		painter->save();
		painter->setPen(QPen(option.palette.brush(cg, QPalette::Highlight), 3));
		painter->drawRect(option.rect.adjusted(1,1,-2,-2));
		painter->restore();
	}
}
开发者ID:BackupTheBerlios,项目名称:khess-svn,代码行数:47,代码来源:dcellview.cpp

示例6: mapBrush

QBrush DBrushAdjuster::mapBrush(const QBrush &brush, const QMatrix &matrix  )
{
	QBrush brush1(brush);
	if(brush.gradient())
	{
		QGradient grad = DGradientAdjuster::mapGradient( brush.gradient(), matrix );
		brush1 = QBrush(grad);
	}
	else if(!brush.texture().isNull())
	{
		QPixmap p(brush.texture());
		p = p.transformed(matrix , Qt::SmoothTransformation );
		brush1.setTexture( p );
	}
	
	
	return brush1;
}
开发者ID:BackupTheBerlios,项目名称:adresis-svn,代码行数:18,代码来源:dbrushadjuster.cpp

示例7: saveDialogDefaultsBrush

void saveDialogDefaultsBrush(const QString &group_name, const QBrush &b) {
  // Save the brush
  dialogDefaults().setValue(group_name+"/fillBrushColor", QVariant(b.color()).toString());
  dialogDefaults().setValue(group_name+"/fillBrushStyle", QVariant((int)b.style()).toString());
  dialogDefaults().setValue(group_name+"/fillBrushUseGradient", QVariant(bool(b.gradient())).toString());
  if (b.gradient()) {
    QString stopList;
    foreach(const QGradientStop &stop, b.gradient()->stops()) {
      qreal point = (qreal)stop.first;
      QColor color = (QColor)stop.second;

      stopList += QString::number(point);
      stopList += ',';
      stopList += color.name();
      stopList += ',';
    }
     dialogDefaults().setValue(group_name+"/fillBrushGradient", stopList);
   }
开发者ID:Kst-plot,项目名称:kst,代码行数:18,代码来源:dialogdefaults.cpp

示例8: adjustBrush

QBrush DBrushAdjuster::adjustBrush(const QBrush &brush, const QRect &rect )
{
	QBrush brush1(brush);
	if(brush.gradient())
	{
		QGradient grad = DGradientAdjuster::adjustGradient( brush.gradient(), rect );
		brush1 = QBrush(grad);
	}
	else if(!brush.texture().isNull())
	{
		QPixmap p = (brush.texture()/*.toImage ()*/);
		int offset= 0;
		QRect br = p.rect();
		QMatrix matrix;
		
		float sx = 1, sy = 1;
		if ( rect.width() < br.width() )
		{
			sx = static_cast<float>(rect.width()-offset) / static_cast<float>(br.width());
		}
		if ( rect.height() < br.height() )
		{
			sy = static_cast<float>(rect.height()-offset) / static_cast<float>(br.height());
		}
	
		float factor = qMin(sx, sy);
		matrix.scale(sx, sy);
		p = p.transformed(matrix ,Qt::SmoothTransformation );
	
		matrix.reset();
	
		QPointF pos = br.topLeft();
	
		float tx = offset/2-pos.x(), ty = offset/2-pos.y();
	
		matrix.translate(tx, ty);
		p = p.transformed(matrix ,Qt::SmoothTransformation );
		
// 		brush1 = QBrush(p);
		brush1.setTexture (  p );
	}
	return brush1;
}
开发者ID:BackupTheBerlios,项目名称:adresis-svn,代码行数:43,代码来源:dbrushadjuster.cpp

示例9: setColor

void KTColorPalette::setColor(const QBrush& brush)
{
	QColor color = brush.color();
	
	if(color.isValid())
	{
		if(m_type == Gradient)
		{
			m_gradientManager->setCurrentColor(color);
		}
		if(m_displayValueColor && m_outlineAndFillColors && m_colorPicker && m_nameColor && m_luminancePicker)
		{
			
			
			m_colorPicker->setCol(color.hue(), color.saturation ());
			if(m_type == Solid)
			{
				m_outlineAndFillColors->setCurrentColor(color);
			}
			m_nameColor->setText(color.name ());
			m_luminancePicker->setCol(color.hue(), color.saturation(), color.value());
			m_containerPalette->setColor( brush );
			m_displayValueColor->setColor(color);
		}
		
	}
	else if(brush.gradient())
	{
		
		QGradient gradient(*brush.gradient());
		changeBrushType(tr("Gradient"));

		m_containerPalette->setColor(gradient);
		m_outlineAndFillColors->setCurrentColor(gradient);
		if( sender () != m_gradientManager )
		{
			m_gradientManager->setGradient(gradient);
		}
		
	}
	emit brushChanged( m_outlineAndFillColors->foreground(),m_outlineAndFillColors->background() );
	
}
开发者ID:BackupTheBerlios,项目名称:ktoon-svn,代码行数:43,代码来源:ktcolorpalette.cpp

示例10: paintEvent

    virtual void paintEvent(QPaintEvent* event) {
        QPainter painter(this);
        painter.setClipRect(event->rect());

        if (m_stroke) {
            m_checkerPainter.paint(painter, rect());
            const KoShapeStroke * line = dynamic_cast<const KoShapeStroke*>(m_stroke);
            if (line) {
                painter.setPen(Qt::NoPen);
                QBrush brush = line->lineBrush();
                if (brush.gradient()) {
                    QGradient * defGradient = KoGradientHelper::defaultGradient(brush.gradient()->type(), brush.gradient()->spread(), brush.gradient()->stops());
                    QBrush brush(*defGradient);
                    delete defGradient;
                    painter.setBrush(brush);
                    painter.setPen(Qt::NoPen);
                    painter.drawRect(rect());
                } else if (brush.style() == Qt::TexturePattern) {
                    painter.fillRect(rect(), brush);
                } else {
                    painter.fillRect(rect(), QBrush(line->color()));
                }
            } else {
                painter.setFont(KGlobalSettings::smallestReadableFont());
                painter.setBrush(Qt::black);
                painter.setPen(Qt::black);
                painter.drawText(rect(), Qt::AlignCenter, i18nc("The style has a custom stroking", "Custom"));
            }
        } else {
            painter.setFont(KGlobalSettings::smallestReadableFont());
            painter.setBrush(Qt::black);
            painter.setPen(Qt::black);
            painter.drawText(rect(), Qt::AlignCenter, i18nc("The style has no stroking", "None"));
        }

        painter.end();

        //QPushButton::paintEvent( event );
    }
开发者ID:foren197316,项目名称:calligra,代码行数:39,代码来源:KarbonSmallStylePreview.cpp

示例11: fillBackground

static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, QRectF gradientRect = QRectF())//copy from QPlainTextEditor from 4.8.1
{
    p->save();
    if (brush.style() >= Qt::LinearGradientPattern && brush.style() <= Qt::ConicalGradientPattern) {
        if (!gradientRect.isNull()) {
            QTransform m = QTransform::fromTranslate(gradientRect.left(), gradientRect.top());
            m.scale(gradientRect.width(), gradientRect.height());
            brush.setTransform(m);
            const_cast<QGradient *>(brush.gradient())->setCoordinateMode(QGradient::LogicalMode);
        }
    } else {
        p->setBrushOrigin(rect.topLeft());
    }
    p->fillRect(rect, brush);
    p->restore();
}
开发者ID:3rdpaw,项目名称:MdCharm,代码行数:16,代码来源:baseeditor.cpp

示例12: loadStyle

bool KGradientBackground::loadStyle(KOdfLoadingContext &context, const QSizeF &shapeSize)
{
    Q_D(KGradientBackground);
    KOdfStyleStack &styleStack = context.styleStack();
    if (! styleStack.hasProperty(KOdfXmlNS::draw, "fill"))
        return false;

    QString fillStyle = styleStack.property(KOdfXmlNS::draw, "fill");
    if (fillStyle == "gradient") {
        QBrush brush = KOdf::loadOdfGradientStyle(styleStack, context.stylesReader(), shapeSize);
        const QGradient * gradient = brush.gradient();
        if (gradient) {
            d->gradient = KFlake::cloneGradient(gradient);
            d->matrix = brush.transform();
            return true;
        }
    }
    return false;
}
开发者ID:KDE,项目名称:koffice,代码行数:19,代码来源:KGradientBackground.cpp

示例13: DrawRect

void MythYUVAPainter::DrawRect(const QRect &area, const QBrush &fillBrush,
                               const QPen &linePen, int alpha)
{
    QBrush brush(fillBrush);

    switch (fillBrush.style())
    {
    case Qt::LinearGradientPattern:
    case Qt::RadialGradientPattern:
    case Qt::ConicalGradientPattern:
        {
        QGradient gradient = *fillBrush.gradient();
        QGradientStops stops = gradient.stops();
        for (QGradientStops::iterator it = stops.begin(); it != stops.end(); ++it)
        {
            it->second = rgb_to_yuv(it->second);
            it->second.setAlpha(alpha);
        }
        gradient.setStops(stops);
        brush = gradient;
        }
        break;
    default:
        brush.setColor(rgb_to_yuv(brush.color()));
        break;
    }

    QPen pen(linePen);
    pen.setColor(rgb_to_yuv(pen.color()));

    // We pull an image here, in the hopes that when DrawRect
    // pulls an image this will still be in the cache and have
    // the right properties.
    MythImage *im = GetImageFromRect(area, 0, 0, brush, pen);
    if (im)
    {
        im->SetToYUV();
        im->DecrRef();
        im = NULL;
    }

    MythQImagePainter::DrawRect(area, brush, pen, alpha);
}
开发者ID:JGunning,项目名称:OpenAOL-TV,代码行数:43,代码来源:mythpainter_yuva.cpp

示例14: saveBrushToXMI

    /**
     * Saves the brush info as xmi into the DOM element \a qElement.
     *
     * @param qDoc The QDomDocument object pointing to the xmi document.
     *
     * @param qElement The element into which the pen, brush and font
     *                 info should be saved.
     *
     * @param brush The QBrush whose details should be saved.
     */
    void saveBrushToXMI(QDomDocument &qDoc, QDomElement &qElement,
                        const QBrush& brush)
    {
        QDomElement brushElement = qDoc.createElement(QLatin1String("brush"));

        brushElement.setAttribute(QLatin1String("style"), (quint8)brush.style());
        brushElement.setAttribute(QLatin1String("color"), brush.color().name());

        if(brush.style() == Qt::TexturePattern) {
            savePixmapToXMI(qDoc, brushElement, brush.texture());
        }
        else if(brush.style() == Qt::LinearGradientPattern
                || brush.style() == Qt::RadialGradientPattern
                || brush.style() == Qt::ConicalGradientPattern) {
            saveGradientToXMI(qDoc, brushElement, brush.gradient());
        }

        //TODO: Check if transform of this brush needs to be saved.
        qElement.appendChild(brushElement);
    }
开发者ID:KDE,项目名称:umbrello,代码行数:30,代码来源:widget_utils.cpp

示例15: paint

void TCellViewItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
    Q_ASSERT(index.isValid());
    const QAbstractItemModel *model = index.model();
    Q_ASSERT(model);

    QVariant value;

    QStyleOptionViewItem opt = option;

    // do layout
    QImage img = qvariant_cast<QImage>(model->data(index,Qt::DisplayRole));

    if (! img.isNull())
        painter->drawImage(opt.rect, img);

    // draw the background color
    value = model->data(index, Qt::BackgroundColorRole);

    if (value.isValid()) {
        QBrush brush = qvariant_cast<QBrush>(value);
        if (brush.gradient()) {
            QMatrix m;
            m.translate(option.rect.topLeft().x(), option.rect.topLeft().y());
            m.scale((float)(option.rect.width())/100.0 , (float)(option.rect.height())/100.0);
            brush.setMatrix(m);
            painter->fillRect(option.rect, brush);
        } else {
            painter->fillRect(option.rect, brush);
        }
    }

    // Selection!
    if (option.showDecorationSelected && (option.state & QStyle::State_Selected)) {
        QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
        painter->save();
        painter->setPen(QPen(option.palette.brush(cg, QPalette::Highlight), 3));
        painter->drawRect(option.rect.adjusted(1,1,-2,-2));
        painter->restore();
    }
}
开发者ID:hpsaturn,项目名称:tupi,代码行数:41,代码来源:tcellview.cpp


注:本文中的QBrush::gradient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。