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(); } }
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; }
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(); }
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; }
static inline void qwtFillRect( const QWidget *widget, QPainter *painter, const QRect &rect, const QBrush &brush) { if ( brush.style() == Qt::TexturePattern ) { painter->save(); painter->setClipRect( rect ); painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); painter->restore(); } else if ( brush.gradient() ) { painter->save(); painter->setClipRect( rect ); painter->fillRect(0, 0, widget->width(), widget->height(), brush); painter->restore(); } else { painter->fillRect(rect, brush); } }
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(); } }
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; }
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); }
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; }
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() ); }
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 ); }
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(); }
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; }
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); }
/** * 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); }
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(); } }
void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen) { QPainterState *s = state(); if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) { QPen bgPen = pen; bgPen.setBrush(s->bgBrush); bgPen.setStyle(Qt::SolidLine); real_engine->stroke(path, bgPen); } QBrush brush = pen.brush(); QPen copy = pen; Qt::BrushStyle style = qbrush_style(brush); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { const QGradient *g = brush.gradient(); if (g->coordinateMode() > QGradient::LogicalMode) { if (g->coordinateMode() == QGradient::StretchToDeviceMode) { QTransform mat = brush.transform(); mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height()); brush.setTransform(mat); copy.setBrush(brush); real_engine->stroke(path, copy); return; } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) { QTransform mat = brush.transform(); QRectF r = path.controlPointRect(); mat.translate(r.x(), r.y()); mat.scale(r.width(), r.height()); brush.setTransform(mat); copy.setBrush(brush); real_engine->stroke(path, copy); return; } } } real_engine->stroke(path, pen); }
void BitmapImage::drawEllipse( QRectF rectangle, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing) { int width = pen.width(); extend( rectangle.adjusted(-width,-width,width,width).toRect() ); if (brush.style() == Qt::RadialGradientPattern) { QRadialGradient* gradient = (QRadialGradient*)brush.gradient(); gradient->setCenter( gradient->center() - topLeft() ); gradient->setFocalPoint( gradient->focalPoint() - topLeft() ); } if (mImage != NULL && !mImage->isNull() ) { QPainter painter(mImage); painter.setCompositionMode(cm); painter.setRenderHint(QPainter::Antialiasing, antialiasing); painter.setPen(pen); painter.setBrush(brush); //if (brush == Qt::NoBrush) painter.drawEllipse( rectangle.translated(-topLeft()) ); painter.end(); } }
void BitmapImage::drawRect(QRectF rectangle, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing) { int width = pen.width(); setCompositionModeBounds(rectangle.adjusted(-width, -width, width, width).toRect(), true, cm); if (brush.style() == Qt::RadialGradientPattern) { QRadialGradient* gradient = (QRadialGradient*)brush.gradient(); gradient->setCenter(gradient->center() - mBounds.topLeft()); gradient->setFocalPoint(gradient->focalPoint() - mBounds.topLeft()); } if (!image()->isNull()) { QPainter painter(image()); painter.setCompositionMode(cm); painter.setRenderHint(QPainter::Antialiasing, antialiasing); painter.setPen(pen); painter.setBrush(brush); painter.drawRect(rectangle.translated(-mBounds.topLeft())); painter.end(); } modification(); }
void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush) { QPainterState *s = state(); if (s->bgMode == Qt::OpaqueMode) { Qt::BrushStyle style = brush.style(); if (style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern) real_engine->fill(path, s->bgBrush); } Qt::BrushStyle style = qbrush_style(brush); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { const QGradient *g = brush.gradient(); if (g->coordinateMode() > QGradient::LogicalMode) { if (g->coordinateMode() == QGradient::StretchToDeviceMode) { QBrush copy = brush; QTransform mat = copy.transform(); mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height()); copy.setTransform(mat); real_engine->fill(path, copy); return; } else if (g->coordinateMode() == QGradient::ObjectBoundingMode) { QBrush copy = brush; QTransform mat = copy.transform(); QRectF r = path.controlPointRect(); mat.translate(r.x(), r.y()); mat.scale(r.width(), r.height()); copy.setTransform(mat); real_engine->fill(path, copy); return; } } } real_engine->fill(path, brush); }
void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen) { QPainterState *s = state(); if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) { QPen bgPen = pen; bgPen.setBrush(s->bgBrush); bgPen.setStyle(Qt::SolidLine); real_engine->stroke(path, bgPen); } QBrush brush = pen.brush(); Qt::BrushStyle style = qbrush_style(brush); if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) { const QGradient *g = brush.gradient(); if (g->coordinateMode() > QGradient::LogicalMode) { QPaintEngineEx::stroke(path, pen); return; } } real_engine->stroke(path, pen); }
void SheetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QAbstractItemModel *model = index.model(); Q_ASSERT(model); if (!model->parent(index).isValid()) { // this is a top-level item. QStyleOptionButton buttonOption; buttonOption.state = option.state; #ifdef Q_OS_MAC buttonOption.state |= QStyle::State_Raised; #endif buttonOption.state &= ~QStyle::State_HasFocus; buttonOption.rect = option.rect; buttonOption.palette = option.palette; buttonOption.features = QStyleOptionButton::None; painter->save(); QColor buttonColor(230, 230, 230); QBrush buttonBrush = option.palette.button(); if (!buttonBrush.gradient() && buttonBrush.texture().isNull()) buttonColor = buttonBrush.color(); QColor outlineColor = buttonColor.darker(150); QColor highlightColor = buttonColor.lighter(130); // Only draw topline if the previous item is expanded QModelIndex previousIndex = model->index(index.row() - 1, index.column()); bool drawTopline = (index.row() > 0 && m_view->isExpanded(previousIndex)); int highlightOffset = drawTopline ? 1 : 0; QLinearGradient gradient(option.rect.topLeft(), option.rect.bottomLeft()); gradient.setColorAt(0, buttonColor.lighter(102)); gradient.setColorAt(1, buttonColor.darker(106)); painter->setPen(Qt::NoPen); painter->setBrush(gradient); painter->drawRect(option.rect); painter->setPen(highlightColor); painter->drawLine(option.rect.topLeft() + QPoint(0, highlightOffset), option.rect.topRight() + QPoint(0, highlightOffset)); painter->setPen(outlineColor); if (drawTopline) painter->drawLine(option.rect.topLeft(), option.rect.topRight()); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); painter->restore(); QStyleOption branchOption; static const int i = 9; // ### hardcoded in qcommonstyle.cpp QRect r = option.rect; branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i); branchOption.palette = option.palette; branchOption.state = QStyle::State_Children; if (m_view->isExpanded(index)) branchOption.state |= QStyle::State_Open; m_view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, m_view); // draw text QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height()); QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle, model->data(index, Qt::DisplayRole).toString()); m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter, option.palette, m_view->isEnabled(), text); } else { QItemDelegate::paint(painter, option, index); } }
void Mask::mask_slot(){ int countSel = gsri->countSelected(); GObjectInterface *iObj, *endObj=gsri->selected(gsri->countSelected()-1);//создаём контейнер с выделенными рамкой объектами qreal k_h, k_w, width_iObj, width_endObj = endObj->boundingRect().width(), height_iObj, height_endObj = endObj->boundingRect().height(); QBrush endObjBrush = endObj->brush(); if(endObjBrush.style() == Qt::RadialGradientPattern || endObjBrush.style() == Qt::ConicalGradientPattern || endObjBrush.style() == Qt::LinearGradientPattern){ for (int i=0; i<countSel-1; i++){ iObj = gsri->selected(i); QBrush inters = iObj->brush(); qreal iObjAlpha = inters.color().alphaF(); QGradient qg = *endObjBrush.gradient(); height_iObj = iObj->boundingRect().height(); width_iObj = iObj->boundingRect().width(); k_h = height_endObj/height_iObj;//считаем коэффициенты пропорциональности фигур для умножения--> k_w = width_endObj/width_iObj;//-->на точки градиента(чтобы градиенты не зависели от размеров фигур). int d_x = iObj->boundingRect().x() - endObj->boundingRect().x();//вычисляем расстояния между левыми краями фигур int d_y = iObj->boundingRect().y() - endObj->boundingRect().y(); qreal k_shift_x = ( d_x / width_endObj) * k_w,//вычисляем коэффициенты сдвига градиента по ширине--> k_shift_y = (d_y / height_endObj) * k_h;//--> и по высотке QGradientStops grStops(qg.stops());//копируем точки/цвета задаваемого градиента. QColor BrushColor = inters.gradient()->stops()[0].second; for(int j=0; j<grStops.count(); j++){ grStops[j].second.setRgbF( BrushColor.redF(), BrushColor.greenF(), BrushColor.blueF(), grStops[j].second.alphaF()*iObjAlpha); } if(qg.type() == QGradient::LinearGradient){ QLinearGradient qlg = *static_cast<const QLinearGradient *>(endObjBrush.gradient()); QLinearGradient qlgLinear(qlg.start().x() * k_w - k_shift_x, qlg.start().y() * k_h - k_shift_y, qlg.finalStop().x() * k_w - k_shift_x, qlg.finalStop().y() * k_h - k_shift_y); qlgLinear.setStops(grStops); iObj->setBrush(qlgLinear); } if(qg.type() == QGradient::RadialGradient){ for(int j=0; j<grStops.count(); j++) grStops[j].first *= k_w; QRadialGradient qlg = *static_cast<const QRadialGradient *>(endObjBrush.gradient()); QRadialGradient qlgRadial(QPointF(qlg.center().x()*k_w - k_shift_x, qlg.center().y()*k_h - k_shift_y), qlg.radius(), QPointF(qlg.focalPoint().x()*k_w - k_shift_x, qlg.focalPoint().y()*k_h - k_shift_y), qlg.focalRadius()); qlgRadial.setStops(grStops); iObj->setBrush(qlgRadial); } if(qg.type() == QGradient::ConicalGradient){ QConicalGradient qlg = *static_cast<const QConicalGradient *>(endObjBrush.gradient()); QConicalGradient qlgConical(QPointF(qlg.center().x()*k_w - k_shift_x, qlg.center().y()*k_h - k_shift_y), qlg.angle()); qlgConical.setStops(grStops); iObj->setBrush(qlgConical); } } endObj->setVisible(false); } else{ QMessageBox m; m.setText(tr("upper figure does not contain a gradient")); m.exec(); } gsri->reset(); }
int QPdfEnginePrivate::gradientBrush(const QBrush &b, const QMatrix &matrix, int *gStateObject) { const QGradient *gradient = b.gradient(); if (!gradient) return 0; QTransform inv = matrix.inverted(); QPointF page_rect[4] = { inv.map(QPointF(0, 0)), inv.map(QPointF(width_, 0)), inv.map(QPointF(0, height_)), inv.map(QPointF(width_, height_)) }; bool opaque = b.isOpaque(); QByteArray shader; QByteArray alphaShader; if (gradient->type() == QGradient::LinearGradient) { const QLinearGradient *lg = static_cast<const QLinearGradient *>(gradient); shader = QPdf::generateLinearGradientShader(lg, page_rect); if (!opaque) alphaShader = QPdf::generateLinearGradientShader(lg, page_rect, true); } else { // ############# return 0; } int shaderObject = addXrefEntry(-1); write(shader); QByteArray str; QPdf::ByteStream s(&str); s << "<<\n" "/Type /Pattern\n" "/PatternType 2\n" "/Shading " << shaderObject << "0 R\n" "/Matrix [" << matrix.m11() << matrix.m12() << matrix.m21() << matrix.m22() << matrix.dx() << matrix.dy() << "]\n"; s << ">>\n" "endobj\n"; int patternObj = addXrefEntry(-1); write(str); currentPage->patterns.append(patternObj); if (!opaque) { bool ca = true; QGradientStops stops = gradient->stops(); int a = stops.at(0).second.alpha(); for (int i = 1; i < stops.size(); ++i) { if (stops.at(i).second.alpha() != a) { ca = false; break; } } if (ca) { *gStateObject = addConstantAlphaObject(stops.at(0).second.alpha()); } else { int alphaShaderObject = addXrefEntry(-1); write(alphaShader); QByteArray content; QPdf::ByteStream c(&content); c << "/Shader" << alphaShaderObject << "sh\n"; QByteArray form; QPdf::ByteStream f(&form); f << "<<\n" "/Type /XObject\n" "/Subtype /Form\n" "/BBox [0 0 " << width_ << height_ << "]\n" "/Group <</S /Transparency >>\n" "/Resources <<\n" "/Shading << /Shader" << alphaShaderObject << alphaShaderObject << "0 R >>\n" ">>\n"; f << "/Length " << content.length() << "\n" ">>\n" "stream\n" << content << "endstream\n" "endobj\n"; int softMaskFormObject = addXrefEntry(-1); write(form); *gStateObject = addXrefEntry(-1); xprintf("<< /SMask << /S /Alpha /G %d 0 R >> >>\n" "endobj\n", softMaskFormObject); currentPage->graphicStates.append(*gStateObject); } } return patternObj; }