WaitingDialog::WaitingDialog(QWidget *parent) : QDialog(parent), ui(new Ui::WaitingDialog) { ui->setupUi(this); m_rot = 0; QGraphicsScene* scene = new QGraphicsScene(); ui->graphicsView->setScene(scene); QRect rect(0,0,50,50); m_startPoint = QPoint(0,ui->graphicsView->rect().size().height()/2); m_endPoint = QPoint(ui->graphicsView->rect().size().width(),ui->graphicsView->rect().size().height()/2); QRadialGradient rg = QRadialGradient(10,10,45.0); QColor mcol(Qt::blue); mcol.setAlpha(255); rg.setColorAt(0.0,Qt::white); mcol.setBlue(mcol.blue()-15); rg.setColorAt(0.5,mcol); mcol.setBlue(mcol.blue()+15); rg.setColorAt(1.0,mcol); QPen pen(mcol); QPixmap pm(rect.size()+QSize(1,1)); pm.fill(Qt::transparent); QPainter p(&pm); p.setBackgroundMode(Qt::TransparentMode); p.setBrush(rg); p.setPen(pen); p.drawEllipse(rect); m_ellipse = new MyItem(pm); m_ellipse->setPos(m_startPoint); ui->graphicsView->scene()->addItem(m_ellipse); m_anim = new QPropertyAnimation(m_ellipse,"pos"); connect(m_anim,SIGNAL(finished()),this,SLOT(animFinished())); m_anim->setEasingCurve(QEasingCurve::OutBounce); m_anim->setStartValue(m_startPoint); m_anim->setEndValue(m_endPoint); m_anim->setDuration(2000); m_anim->setLoopCount(1); m_anim->start(); m_timer = new QTimer(this); connect(m_timer,SIGNAL(timeout()),this,SLOT(timeout())); m_timer->setInterval(100); #if defined(Q_OS_SYMBIAN) this->showMaximized(); #else this->show(); #endif m_timer->start(); }
void EditorMagnifierItem::updateMask() { QRectF current = getRect(); QSize box = QSize( current.width(), current.width() ); // reupdate our mask if (m_imgMask.size() != box) { int radius = box.width() / 2; int ring = radius - 10; m_imgMask = QPixmap(box); m_imgMask.fill(Qt::transparent); QRadialGradient g; g.setCenter(radius, radius); g.setFocalPoint(radius, radius); g.setRadius(radius); g.setColorAt( 1.0, QColor(255, 255, 255, 0) ); g.setColorAt( 0.5, QColor(128, 128, 128, 255) ); QPainter mask(&m_imgMask); mask.setRenderHint(QPainter::Antialiasing); mask.setCompositionMode(QPainter::CompositionMode_Source); mask.setBrush(g); mask.setPen(Qt::NoPen); mask.drawRect( m_imgMask.rect() ); mask.setBrush( QColor(Qt::transparent) ); mask.drawEllipse(g.center(), ring, ring); mask.end(); } }
int MailTreeDelegate::DrawMessageActionIcons (QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index, int height) const { if (Mode_ != MailListMode::Normal) return 0; if (option.state & QStyle::State_MouseOver) return 0; const auto& actionsVar = index.data (MailModel::MailRole::MessageActions); if (actionsVar.isNull ()) return 0; auto actionInfos = actionsVar.value<QList<MessageListActionInfo>> (); if (actionInfos.isEmpty ()) return 0; std::reverse (actionInfos.begin (), actionInfos.end ()); if (ActionsHintsBalls_) height -= Padding * 2; painter->save (); painter->setRenderHint (QPainter::Antialiasing); painter->setPen (Qt::NoPen); auto rect = option.rect; rect.setLeft (rect.right () - height - Padding); rect.setSize ({ height, height }); rect.moveTop (rect.top () + Padding); for (const auto& item : actionInfos) { if (item.Flags_ & MessageListActionFlag::AlwaysPresent) continue; if (ActionsHintsBalls_) { QRadialGradient gradient; gradient.setCoordinateMode (QGradient::ObjectBoundingMode); gradient.setFocalPoint ({ 0.3, 0.3 }); gradient.setCenter ({ 0.5, 0.5 }); gradient.setRadius (0.5); gradient.setColorAt (0, item.ReprColor_.lighter (200)); gradient.setColorAt (1, item.ReprColor_.darker (120)); painter->setBrush (gradient); painter->drawEllipse (rect); } else item.Icon_.paint (painter, rect); rect.moveLeft (rect.left () - height - Padding); } painter->restore (); return option.rect.right () - rect.right (); }
void PreviewWidget::drawShadow(QPainter &painter, QRectF rect) { // Shadow width int width = qBound(4, int(qMax(rect.height(), rect.width())) / 100, 7); painter.save(); painter.setClipRect(rect.adjusted(0, 0, width, width)); QColor lightColor = this->palette().color(QPalette::Background); QColor darkColor = lightColor.darker(160); QRectF shadowRect = rect.adjusted(0, 0, width, width); QLinearGradient lg; lg.setColorAt(0.0, darkColor); lg.setColorAt(1.0, lightColor); QRadialGradient rg; rg.setColorAt(0, darkColor); rg.setColorAt(1, lightColor); rg.setRadius(width); // Right lg.setStart(QPointF(rect.right(), rect.center().y())); lg.setFinalStop(QPointF(shadowRect.right(), rect.center().y())); painter.fillRect(rect.right(), rect.top() + width, width, rect.height() - width, lg); // Bottom lg.setStart(rect.center().x(), rect.bottom()); lg.setFinalStop(rect.center().x(), rect.bottom() + width); painter.fillRect(rect.left() + width, rect.bottom(), rect.width() - width, width, lg); //TopRight QPointF p; p = rect.bottomRight(); rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.right(), rect.bottom(), width, width, rg); // BottomRight p = rect.topRight(); p.ry() += width; rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.right(), rect.top(), width, width, rg); //BottomLeft p = rect.bottomLeft(); p.rx() += width; rg.setCenter(p); rg.setFocalPoint(p); painter.fillRect(rect.left(), rect.bottom(), width, width, rg); painter.restore(); }
//! //! Paints the graphics item into a graphics view. //! //! \param painter The object to use for painting. //! \param option Style options for painting the graphics item. //! \param widget The widget into which to paint the graphics item. //! void PinGraphicsItem::paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /* = 0 */ ) { const QColor penColor (30, 30, 30); QRadialGradient radialGradient (rect().center(), 5); radialGradient.setColorAt(1, m_color.darker(200)); radialGradient.setColorAt(0, m_color); // set the brush QBrush brush; if (isEnabled()) if (m_hovered && m_clicked) radialGradient.setColorAt(0.5, m_color.lighter(100)); else if (m_hovered || m_clicked) radialGradient.setColorAt(0.5, m_color.lighter(100)); else radialGradient.setColorAt(0.5, m_color.darker(150)); else brush = Qt::NoBrush; // paint the pin brush = QBrush(radialGradient); painter->setRenderHint(QPainter::Antialiasing); painter->setPen(QPen(QBrush(penColor), 1)); painter->setBrush(brush); painter->drawEllipse(rect().center(), 5, 5); // check if the parameter the pin represents is a parameter group //if (m_abstractParameter && m_abstractParameter->isGroup()) { // painter->setPen(QPen(penColor)); // painter->setBrush(QBrush(QColor(Qt::black))); // painter->setRenderHint(QPainter::Antialiasing); // if (m_abstractParameter->getName().isEmpty()) { // // draw two dots for parameter roots // painter->drawEllipse(rect().center() + QPointF(-2, 0.5), 1, 1); // painter->drawEllipse(rect().center() + QPointF(2, 0.5), 1, 1); // } else // // draw one dot for other parameter groups // painter->drawEllipse(rect().center(), 1, 1); //} if (m_isGroup) { painter->setPen(QPen(penColor)); painter->setBrush(QBrush(QColor(Qt::black))); painter->setRenderHint(QPainter::Antialiasing); if (m_isRootGroup) { // draw two dots for parameter roots painter->drawEllipse(rect().center() + QPointF(-2, 0.5), 1, 1); painter->drawEllipse(rect().center() + QPointF(2, 0.5), 1, 1); } else // draw one dot for other parameter groups painter->drawEllipse(rect().center(), 1, 1); } }
void DashBar::repaint(QPainter &painter){ float v; float min = qMin(value1,value2); float max = qMax(value1,value2); int size = orientation == Qt::Horizontal? width-10 : height-10; QRadialGradient gradient; QPen pen(Qt::black); pen.setWidth(1); painter.save(); painter.setRenderHint(QPainter::Antialiasing); painter.translate(x,y); gradient = QRadialGradient(QPointF(0,0), qSqrt(width*width+height*height)*2, QPointF(0,0)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawRect(0,0,width, height); gradient = QRadialGradient(QPointF(width,height), qSqrt(width*width+height*height)*2, QPointF(width,height)); gradient.setColorAt(0, QColor(88,88,88)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawRect(5,5,width-10,height-10); painter.setBrush(Qt::white); painter.setPen(Qt::white); if(value>max)value = max; if(value<min)value = min; v = (max-value)/(max-min)*size; for(int i=0; i<size; i+=4){ if(i>size*0.4f){ painter.setPen(i>=v || isSelected? Qt::green : QColor(Qt::green).darker()); }else if(i>=size*0.1f && i<=size*0.4f){ painter.setPen(i>=v || isSelected? Qt::yellow : QColor(Qt::yellow).darker()); }else{ painter.setPen(i>=v || isSelected? Qt::red : QColor(Qt::red).darker()); } if(orientation == Qt::Horizontal){ //Orizzontale painter.drawLine(width-6-i,6,width-6-i,height-6); //Linee verticali }else{ painter.drawLine(6,6+i,width-6,6+i); } } painter.restore(); }
void Highlight::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QColor pen_color = pen.color(); painter->setPen(pen); if(time < total_time ){ //don't want to keep adding them past animation length int expected_num_rings = (int)ceil(frequency * time); if( expected_num_rings > rings.length()){ rings.append(time); } //velocity= 200.0 - (time*total_time*2.0);//pretty cool //velocity= 200.0*(1.0-done_ratio);//pretty cool, about the same //frequency = 3.0*(1.0-done_ratio);//pretty cool for(int i=0; i<rings.length(); i++){ //qreal dist = diameter + ( velocity * (time - rings.at(i))); qreal t = (time - rings.at(i)); qreal dist = diameter + ( velocity * t ) + (0.5 * -5.0 * t*t); //qDebug() << "dist:" << dist << " outerDiameter:" << outerDiameter; QRectF s(x()-dist/2.0, y()-dist/2.0,dist,dist); QRectF r = mapRectFromScene(x()-dist/2.0, y()-dist/2.0,dist,dist); pen.setWidth(20.0+50.0* dist/outerDiameter); QRadialGradient radialGrad; radialGrad.setCenter(r.center()); radialGrad.setFocalPoint(r.center()); radialGrad.setCenterRadius(r.width()/2.0+pen.widthF()/2.0); radialGrad.setFocalRadius(r.width()/2.0-pen.widthF()/2.0); /* not entirely sure I get it, but I think focal radius * needs to be either the center of the pen or its inner edge * while center radius is the outer edge. */ QColor green(0,255,0,255); QColor yellow(255,255,0,255); /* pen_color.setAlphaF(1.0-(dist/outerDiameter)); //surface waves don't inverse square */ green.setAlphaF(1.0-(dist/outerDiameter)); yellow.setAlphaF((1.0-(dist/outerDiameter))); radialGrad.setColorAt(.0, yellow ); radialGrad.setColorAt( .5, green ); radialGrad.setColorAt(1, yellow ); brush = QBrush(radialGrad); pen.setBrush(brush); painter->setPen(pen); painter->drawEllipse(r); } } }
void BrushEngine::paint(const QPointF& point, float pressure) { QPainter painter(eraser > 50 ? canvasItem->getPixmap() : canvasBuffer->getPixmap()); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(Qt::NoPen); if (eraser > 50) { painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); } color.setAlpha(qRound(255 * flow / 100.0)); QColor pressureColor = color; pressureColor.setAlpha(qRound(color.alpha() * pressure)); QColor alphaColor = color; alphaColor.setAlpha(0); QRadialGradient radialGradient; radialGradient.setRadius(size / 2.0); radialGradient.setColorAt(0, pressureColor); radialGradient.setColorAt(1, alphaColor); radialGradient.setColorAt(hardness / 100.0, pressureColor); painter.setBrush(QBrush(radialGradient)); if (startPoint.isNull()) { startPoint = QPointF(point); lastPoint = QPointF(point); topleft = QPoint(0, 0); bottomright = QPoint(canvasBuffer->getPixmap()->width(), canvasBuffer->getPixmap()->height()); paintDab(point, painter); } else { qreal length = qSqrt(qPow(lastPoint.x() - point.x(), 2) + qPow(lastPoint.y() - point.y(), 2)); qreal delta = size * spacing / 2.0 / 100.0; if (length >= delta) { int dabs = qRound(length / delta); qreal angle = qAtan2(point.x() - lastPoint.x(), point.y() - lastPoint.y()); qreal deltaX = delta * qSin(angle); qreal deltaY = delta * qCos(angle); QPointF betweenPoint; for (int i = 1; i <= dabs; i++) { qreal x = lastPoint.x() + deltaX * i + (10000 - qrand() % 20000) / 10000.0 * size * jitter / 100; qreal y = lastPoint.y() + deltaY * i + (10000 - qrand() % 20000) / 10000.0 * size * jitter / 100; betweenPoint = QPointF(x, y); paintDab(betweenPoint, painter); } lastPoint = betweenPoint; } } }
void PainterWidget::updateBrush() { QRadialGradient g; g.setCenter(brush_size/2, brush_size/2); g.setFocalPoint(brush_size/2, brush_size/2); g.setRadius(brush_size/2); g.setColorAt(1.0, Qt::black); g.setColorAt(0, QColor(100,100,100)); QImage mask(brush_size, brush_size,QImage::Format_RGB32); mask.fill(qRgb(0,0,0)); QPainter painter2(&mask); painter2.fillRect(mask.rect(), g); painter2.end(); soft_brush = QImage(brush_size, brush_size,QImage::Format_RGB32); soft_brush.fill(brush_color.rgb()); soft_brush.setAlphaChannel(mask); }
void ConvertDialogTest::convert_filter_gradient() { EffectsScrollArea *effectsScrollArea = convertDialog->effectsScrollArea; QGroupBox *filterGroupBox = effectsScrollArea->filterGroupBox; filterGroupBox->setChecked(true); QRadioButton *filterGradientRadioButton = effectsScrollArea->filterGradientRadioButton; filterGradientRadioButton->setChecked(true); QRadialGradient gradient = QRadialGradient(QPoint(1, 2), 2.5); gradient.setColorAt(0.0, Qt::green); gradient.setColorAt(1.0, Qt::red); BrushFrame *filterBrushFrame = effectsScrollArea->filterBrushFrame; filterBrushFrame->setBrush(gradient); convertDialog->convert(); SharedInformation *sharedInfo = convertDialog->sharedInfo; EffectsConfiguration conf = sharedInfo->effectsConfiguration(); QCOMPARE(conf.getFilterType(), int(Gradient)); QCOMPARE(conf.getFilterBrush(), QBrush(gradient)); }
KoShape * KoEllipseShapeFactory::createDefaultShape() const { KoEllipseShape * ellipse = new KoEllipseShape(); ellipse->setBorder( new KoLineBorder( 1.0 ) ); ellipse->setShapeId( KoPathShapeId ); QRadialGradient * gradient = new QRadialGradient( QPointF(50,50), 50.0, QPointF(25,25) ); gradient->setColorAt( 0.0, Qt::white ); gradient->setColorAt( 1.0, Qt::green ); ellipse->setBackground( new KoGradientBackground( gradient ) ); return ellipse; }
void Point::paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * /*widget*/ ) { QRadialGradient gradient ( 0.0, 0.0, _radius ); // If we are selected, use a lighter color. if ( option->state & QStyle::State_Sunken ) { gradient.setColorAt ( 0, QColor ( Qt::yellow ).light ( 120 ) ); gradient.setColorAt ( 1, QColor ( Qt::darkYellow ).light ( 120 ) ); painter->setPen ( QPen ( Qt::red, 0 ) ); } else { gradient.setColorAt ( 0, Qt::yellow ); gradient.setColorAt ( 1, Qt::darkYellow ); painter->setPen ( QPen ( Qt::black, 0 ) ); } painter->setBrush ( gradient ); const double diameter ( _radius * 2 ); painter->drawEllipse ( -_radius, -_radius, diameter, diameter); }
KoShape *EllipseShapeFactory::createDefaultShape(KoDocumentResourceManager *) const { EllipseShape *ellipse = new EllipseShape(); ellipse->setStroke(new KoShapeStroke(1.0)); ellipse->setShapeId(KoPathShapeId); QRadialGradient *gradient = new QRadialGradient(QPointF(0.5,0.5), 0.5, QPointF(0.25,0.25)); gradient->setCoordinateMode(QGradient::ObjectBoundingMode); gradient->setColorAt(0.0, Qt::white); gradient->setColorAt(1.0, Qt::green); ellipse->setBackground(new KoGradientBackground(gradient)); return ellipse; }
SpaceObjectSun::SpaceObjectSun(int x, int y) : SpaceObject(x, y, SO_TYPE_SUN) { mPixmap->fill(Qt::transparent); QPainter p(mPixmap); QRadialGradient rd; rd.setCenter(40, 40); rd.setRadius(40); rd.setFocalPoint(40, 40); rd.setColorAt(0, QColor(0xFF, 0xFF, 0xDD, 0xFF)); rd.setColorAt(0.45, QColor(0xFF, 0xFF, 0xDD, 0xFF)); rd.setColorAt(0.55, QColor(0xFF, 0xFF, 0x33, 0xFF)); rd.setColorAt(0.6, QColor("#FF9900")); rd.setColorAt(1, QColor( 0, 0, 0, 0x00 )); p.setPen(Qt::NoPen); p.setBrush( rd ); p.drawEllipse(0, 0, 80, 80); }
void dot::paint ( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { Q_UNUSED ( widget ); painter->setPen ( Qt::NoPen ); painter->setBrush ( Qt::darkGray ); painter->drawEllipse ( -1, -1, 5, 5 ); QRadialGradient gradient ( -3, -3, 10 ); if( this->isSelected() ) { if ( option->state & QStyle::State_Sunken ) { gradient.setCenter ( 3, 3 ); gradient.setFocalPoint ( 3, 3 ); gradient.setColorAt ( 1, QColor ( Qt::green ).light ( 100 ) ); gradient.setColorAt ( 0, QColor ( Qt::darkGreen ).light ( 100 ) ); } else { gradient.setColorAt ( 0, Qt::green ); gradient.setColorAt ( 1, Qt::darkGreen ); } } else { if ( option->state & QStyle::State_Sunken ) { gradient.setCenter ( 3, 3 ); gradient.setFocalPoint ( 3, 3 ); gradient.setColorAt ( 1, QColor ( Qt::yellow ).light ( 100 ) ); gradient.setColorAt ( 0, QColor ( Qt::darkYellow ).light ( 100 ) ); } else { gradient.setColorAt ( 0, Qt::yellow ); gradient.setColorAt ( 1, Qt::darkYellow ); } } painter->setBrush ( gradient ); painter->setPen ( QPen ( Qt::black, 0 ) ); painter->drawEllipse ( -2, -2, 6, 6 ); painter->scale ( 1.0,-1.0 ); painter->setFont(QFont("Arial", 14)); painter->drawText(0,10,message); }
QRadialGradient* getRadialGradient(const CLRadialGradient* radial, const CLBoundingBox* bounds, const CLRenderResolver* resolver) { double cx = bounds->getPosition().getX() + radial->getCenterX().getAbsoluteValue() + radial->getCenterX().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth(); double cy = bounds->getPosition().getY() + radial->getCenterY().getAbsoluteValue() + radial->getCenterY().getRelativeValue() / 100.0 * bounds->getDimensions().getHeight(); double fx = bounds->getPosition().getX() + radial->getFocalPointX().getAbsoluteValue() + radial->getFocalPointX().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth(); double fy = bounds->getPosition().getY() + radial->getFocalPointY().getAbsoluteValue() + radial->getFocalPointY().getRelativeValue() / 100.0 * bounds->getDimensions().getHeight(); double r = radial->getRadius().getAbsoluteValue() + radial->getRadius().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth(); QRadialGradient* result = new QRadialGradient(cx, cy, r, fx, fy); switch (radial->getSpreadMethod()) { case CLGradientBase::REFLECT: result->setSpread(QGradient::ReflectSpread); break; case CLGradientBase::REPEAT: result->setSpread(QGradient::RepeatSpread); break; case CLGradientBase::PAD: result->setSpread(QGradient::PadSpread); break; default: break; } for (size_t i = 0; i < radial->getNumGradientStops(); ++i) { const CLGradientStop* stop = radial->getGradientStop(i); result->setColorAt(stop->getOffset().getAbsoluteValue() + stop->getOffset().getRelativeValue() / 100.0, getColor(stop->getStopColor(), resolver)); } return result; }
void LedIndicator::paintEvent(QPaintEvent *event) { qreal realSize = qMin(width(), height()); QRadialGradient gradient; QPainter painter(this); QPen pen(Qt::black); pen.setWidth(1); painter.setRenderHint(QPainter::Antialiasing); painter.translate(width()/2, height()/2); painter.scale(realSize/scaledSize, realSize/scaledSize); gradient = QRadialGradient (QPointF(-500,-500), 1500, QPointF(-500,-500)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawEllipse(QPointF(0,0), 500, 500); gradient = QRadialGradient (QPointF(500,500), 1500, QPointF(500,500)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawEllipse(QPointF(0,0), 450, 450); painter.setPen(pen); if( isDown() ) { gradient = QRadialGradient (QPointF(-500,-500), 1500, QPointF(-500,-500)); gradient.setColorAt(0, onColor1); gradient.setColorAt(1, onColor2); } else { gradient = QRadialGradient (QPointF(500,500), 1500, QPointF(500,500)); gradient.setColorAt(0, offColor1); gradient.setColorAt(1, offColor2); } painter.setBrush(gradient); painter.drawEllipse(QPointF(0,0), 400, 400); }
QPixmap PostEffect::generateFuzzyRect(const QSize& size, const QColor& color, int radius) { QPixmap pix(size); const QColor transparent(0, 0, 0, 0); pix.fill(transparent); QPainter painter(&pix); painter.setRenderHint(QPainter::Antialiasing, true); // Fill middle painter.fillRect(pix.rect().adjusted(radius, radius, -radius, -radius), color); // Corners QRadialGradient gradient; gradient.setColorAt(0, color); gradient.setColorAt(1, transparent); gradient.setRadius(radius); QPoint center; // Top Left center = QPoint(radius, radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(0, 0, radius, radius, gradient); // Top right center = QPoint(size.width() - radius, radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(center.x(), 0, radius, radius, gradient); // Bottom left center = QPoint(radius, size.height() - radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(0, center.y(), radius, radius, gradient); // Bottom right center = QPoint(size.width() - radius, size.height() - radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(center.x(), center.y(), radius, radius, gradient); // Borders QLinearGradient linearGradient; linearGradient.setColorAt(0, color); linearGradient.setColorAt(1, transparent); // Top linearGradient.setStart(0, radius); linearGradient.setFinalStop(0, 0); painter.fillRect(radius, 0, size.width() - 2 * radius, radius, linearGradient); // Bottom linearGradient.setStart(0, size.height() - radius); linearGradient.setFinalStop( 0, size.height() ); painter.fillRect(radius, int( linearGradient.start().y() ), size.width() - 2 * radius, radius, linearGradient); // Left linearGradient.setStart(radius, 0); linearGradient.setFinalStop(0, 0); painter.fillRect(0, radius, radius, size.height() - 2 * radius, linearGradient); // Right linearGradient.setStart(size.width() - radius, 0); linearGradient.setFinalStop(size.width(), 0); painter.fillRect(int( linearGradient.start().x() ), radius, radius, size.height() - 2 * radius, linearGradient); return pix; }
void LightMaps::paintEvent(QPaintEvent *event) { QPainter p; p.begin(this); m_normalMap->render(&p, event->rect()); p.setPen(Qt::black); p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap, "Map data CCBYSA 2009 OpenStreetMap.org contributors"); p.end(); if (zoomed) { int dim = qMin(width(), height()); int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3); int radius = magnifierSize / 2; int ring = radius - 15; QSize box = QSize(magnifierSize, magnifierSize); // reupdate our mask if (maskPixmap.size() != box) { maskPixmap = QPixmap(box); maskPixmap.fill(Qt::transparent); QRadialGradient g; g.setCenter(radius, radius); g.setFocalPoint(radius, radius); g.setRadius(radius); g.setColorAt(1.0, QColor(255, 255, 255, 0)); g.setColorAt(0.5, QColor(128, 128, 128, 255)); QPainter mask(&maskPixmap); mask.setRenderHint(QPainter::Antialiasing); mask.setCompositionMode(QPainter::CompositionMode_Source); mask.setBrush(g); mask.setPen(Qt::NoPen); mask.drawRect(maskPixmap.rect()); mask.setBrush(QColor(Qt::transparent)); mask.drawEllipse(g.center(), ring, ring); mask.end(); } QPoint center = dragPos - QPoint(0, radius); center = center + QPoint(0, radius / 2); QPoint corner = center - QPoint(radius, radius); QPoint xy = center * 2 - QPoint(radius, radius); // only set the dimension to the magnified portion if (zoomPixmap.size() != box) { zoomPixmap = QPixmap(box); zoomPixmap.fill(Qt::lightGray); } if (true) { QPainter p(&zoomPixmap); p.translate(-xy); m_largeMap->render(&p, QRect(xy, box)); p.end(); } QPainterPath clipPath; clipPath.addEllipse(center, ring, ring); QPainter p(this); p.setRenderHint(QPainter::Antialiasing); p.setClipPath(clipPath); p.drawPixmap(corner, zoomPixmap); p.setClipping(false); p.drawPixmap(corner, maskPixmap); p.setPen(Qt::gray); p.drawPath(clipPath); } if (invert) { QPainter p(this); p.setCompositionMode(QPainter::CompositionMode_Difference); p.fillRect(event->rect(), Qt::white); p.end(); } }
void AbstractDiagram::paintMarker( QPainter* painter, const MarkerAttributes& markerAttributes, const QBrush& brush, const QPen& pen, const QPointF& pos, const QSizeF& maSize ) { const QPen oldPen( painter->pen() ); // Pen is used to paint 4Pixels - 1 Pixel - Ring and FastCross types. // make sure to use the brush color - see above in those cases. const bool isFourPixels = (markerAttributes.markerStyle() == MarkerAttributes::Marker4Pixels); if( isFourPixels || (markerAttributes.markerStyle() == MarkerAttributes::Marker1Pixel) ){ // for high-performance point charts with tiny point markers: painter->setPen( PrintingParameters::scalePen( QPen( brush.color().light() ) ) ); if( isFourPixels ){ const qreal x = pos.x(); const qreal y = pos.y(); painter->drawLine( QPointF(x-1.0,y-1.0), QPointF(x+1.0,y-1.0) ); painter->drawLine( QPointF(x-1.0,y), QPointF(x+1.0,y) ); painter->drawLine( QPointF(x-1.0,y+1.0), QPointF(x+1.0,y+1.0) ); } painter->drawPoint( pos ); }else{ const PainterSaver painterSaver( painter ); // we only a solid line surrounding the markers QPen painterPen( pen ); painterPen.setStyle( Qt::SolidLine ); painter->setPen( PrintingParameters::scalePen( painterPen ) ); painter->setBrush( brush ); painter->setRenderHint ( QPainter::Antialiasing ); painter->translate( pos ); switch ( markerAttributes.markerStyle() ) { case MarkerAttributes::MarkerCircle: { if ( markerAttributes.threeD() ) { QRadialGradient grad; grad.setCoordinateMode( QGradient::ObjectBoundingMode ); QColor drawColor = brush.color(); grad.setCenter( 0.5, 0.5 ); grad.setRadius( 1.0 ); grad.setFocalPoint( 0.35, 0.35 ); grad.setColorAt( 0.00, drawColor.lighter( 150 ) ); grad.setColorAt( 0.20, drawColor ); grad.setColorAt( 0.50, drawColor.darker( 150 ) ); grad.setColorAt( 0.75, drawColor.darker( 200 ) ); grad.setColorAt( 0.95, drawColor.darker( 250 ) ); grad.setColorAt( 1.00, drawColor.darker( 200 ) ); QBrush newBrush( grad ); newBrush.setMatrix( brush.matrix() ); painter->setBrush( newBrush ); } painter->drawEllipse( QRectF( 0 - maSize.height()/2, 0 - maSize.width()/2, maSize.height(), maSize.width()) ); } break; case MarkerAttributes::MarkerSquare: { QRectF rect( 0 - maSize.width()/2, 0 - maSize.height()/2, maSize.width(), maSize.height() ); painter->drawRect( rect ); break; } case MarkerAttributes::MarkerDiamond: { QVector <QPointF > diamondPoints; QPointF top, left, bottom, right; top = QPointF( 0, 0 - maSize.height()/2 ); left = QPointF( 0 - maSize.width()/2, 0 ); bottom = QPointF( 0, maSize.height()/2 ); right = QPointF( maSize.width()/2, 0 ); diamondPoints << top << left << bottom << right; painter->drawPolygon( diamondPoints ); break; } // both handled on top of the method: case MarkerAttributes::Marker1Pixel: case MarkerAttributes::Marker4Pixels: break; case MarkerAttributes::MarkerRing: { painter->setPen( PrintingParameters::scalePen( QPen( brush.color() ) ) ); painter->setBrush( Qt::NoBrush ); painter->drawEllipse( QRectF( 0 - maSize.height()/2, 0 - maSize.width()/2, maSize.height(), maSize.width()) ); break; } case MarkerAttributes::MarkerCross: { // Note: Markers can have outline, // so just drawing two rects is NOT the solution here! const qreal w02 = maSize.width() * 0.2; const qreal w05 = maSize.width() * 0.5; const qreal h02 = maSize.height()* 0.2; const qreal h05 = maSize.height()* 0.5; QVector <QPointF > crossPoints; QPointF p[12]; p[ 0] = QPointF( -w02, -h05 ); p[ 1] = QPointF( w02, -h05 ); p[ 2] = QPointF( w02, -h02 ); p[ 3] = QPointF( w05, -h02 ); p[ 4] = QPointF( w05, h02 ); p[ 5] = QPointF( w02, h02 ); p[ 6] = QPointF( w02, h05 ); p[ 7] = QPointF( -w02, h05 ); p[ 8] = QPointF( -w02, h02 ); p[ 9] = QPointF( -w05, h02 ); p[10] = QPointF( -w05, -h02 ); p[11] = QPointF( -w02, -h02 ); for( int i=0; i<12; ++i ) crossPoints << p[i]; crossPoints << p[0]; painter->drawPolygon( crossPoints ); break; } case MarkerAttributes::MarkerFastCross: { QPointF left, right, top, bottom; left = QPointF( -maSize.width()/2, 0 ); right = QPointF( maSize.width()/2, 0 ); top = QPointF( 0, -maSize.height()/2 ); bottom= QPointF( 0, maSize.height()/2 ); painter->setPen( PrintingParameters::scalePen( QPen( brush.color() ) ) ); painter->drawLine( left, right ); painter->drawLine( top, bottom ); break; } case MarkerAttributes::NoMarker: break; default: Q_ASSERT_X ( false, "paintMarkers()", "Type item does not match a defined Marker Type." ); } } painter->setPen( oldPen ); }
void QNeedleIndicator::drawBackground(void) { int side = qMin(width(), height()); /* Keep side size an even number by trunkating odd pixel */ side &= ~0x01; QRadialGradient gradient; QPainter painter(this); QPen pen(Qt::black); pen.setWidth(1); /* Initialize painter */ painter.setRenderHint(QPainter::Antialiasing); painter.translate(width() / 2, height() / 2); painter.scale(side / 256.0, side / 256.0); painter.setPen(pen); /* Draw external circle */ gradient = QRadialGradient (QPointF(-128,-128), 384, QPointF(-128,-128)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(pen); painter.setBrush(QBrush(gradient)); painter.drawEllipse(QPoint(0,0),125,125); /* Draw inner circle */ gradient = QRadialGradient(QPointF(128,128), 384, QPointF(128,128)); gradient.setColorAt(0, QColor(224,224,224)); gradient.setColorAt(1, QColor(28,28,28)); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(gradient)); painter.drawEllipse(QPoint(0,0),118,118); /* Draw inner shield */ gradient = QRadialGradient (QPointF(-128,-128), 384, QPointF(-128,-128)); gradient.setColorAt(0, QColor(255,255,255)); gradient.setColorAt(1, QColor(224,224,224)); painter.setBrush(gradient); painter.setPen(Qt::NoPen); painter.drawEllipse(QPoint(0,0), 115, 115); painter.setPen(pen); painter.setBrush(Qt::black); painter.drawPoint(0,0); int line = 10; /* FIX #1 */ /* Draw scale majorTicks using coords rotation */ painter.save(); painter.setBrush(Qt::black); painter.rotate(start_angle); /* initial angle (first tick) */ painter.setBrush(QBrush(Qt::black)); qreal t_rot = stop_angle/(minorTicks*(majorTicks-1)+majorTicks-1); for(int i = 0; i < (minorTicks)*(majorTicks-1)+majorTicks; i++) { if( minorTicks ) { if( i%(int)(minorTicks+1) == 0 ) painter.drawLine(QPoint(105,0), QPoint(105-line, 0)); else painter.drawLine(QPoint(105,0), QPoint(105-line/3, 0)); } else { painter.drawLine(QPoint(105,0), QPoint(105-line, 0)); } painter.rotate(t_rot); } painter.restore(); /* Draw scale numbers using vector rotation */ /* x' = xcos(a)-ysin(a) */ /* y' = xsin(a)-ycos(a) */ painter.save(); qreal rotation = (start_angle/360)*2*M_PI; /* Initial rotation */ painter.setFont(digitFont); for(int i = 0; i < majorTicks; i++) { QPointF point((70*cos(rotation)), 70*sin(rotation)); /* calculate digit coords */ QString value = QString().sprintf(scaleFormat.constData(), min+(qreal)i*step); /* convert digit to string */ QSize size = painter.fontMetrics().size(Qt::TextSingleLine, value); /* get string size in px */ point.rx() -= size.width()/2; /* center-align string (horiz) */ point.ry() += size.height()/4; /* center-align string (vert) */ painter.drawText(point, value); //painter.drawPoint(point); rotation+=rot_rad; /* go to next tick */ } painter.restore(); /* Draw meter label */ if( label.size() ) { painter.setFont(labelFont); QSize size = painter.fontMetrics().size(Qt::TextSingleLine, label); QPointF point; point.rx() -= size.width()/2; /* center-align string (horiz) */ point.ry() += size.height()/4 + labelOffset; /* shift down, below needle */ painter.drawText(point, label); /* blop! */ } }
void Ckeyb::drawPressed(QImage *_img) { if (keyPressedList.isEmpty()) { return; } keyPressing.lock(); QMapIterator<int, quint64> i(keyPressedList); keyPressing.unlock(); while (i.hasNext()) { i.next(); QRect _rect = getKey(i.key()).Rect; _rect.setCoords(_rect.x()*pPC->internalImageRatio, _rect.y()*pPC->internalImageRatio, (_rect.x()+_rect.width())*pPC->internalImageRatio, (_rect.y()+_rect.height())*pPC->internalImageRatio); int _m = qMin(_rect.width(), _rect.height())*.25; _rect+= QMargins(_m,_m,_m,_m); int dim = qMax(_rect.width(), _rect.height()); int magnifierSize = dim * 2; int radius = magnifierSize / 2; int ring = radius - 15; QSize box = QSize(magnifierSize, magnifierSize); QPixmap maskPixmap; maskPixmap = QPixmap(box); maskPixmap.fill(Qt::transparent); QRadialGradient g; g.setCenter(radius, radius); g.setFocalPoint(radius, radius); g.setRadius(radius); g.setColorAt(1.0, QColor(64, 64, 64, 0)); g.setColorAt(0.5, QColor(0, 0, 0, 255)); QPainter mask(&maskPixmap); mask.setRenderHint(QPainter::Antialiasing); mask.setCompositionMode(QPainter::CompositionMode_Source); mask.setBrush(g); mask.setPen(Qt::NoPen); mask.drawRect(maskPixmap.rect()); mask.setBrush(QColor(Qt::transparent)); mask.drawEllipse(g.center(), ring, ring); mask.end(); QPoint center = _rect.center() - QPoint(0, radius); center = center + QPoint(0, radius / 2); QPoint corner = center - QPoint(radius, radius); QPoint xy = center * 2 - QPoint(radius, radius); // only set the dimension to the magnified portion QPixmap zoomPixmap = QPixmap(box); zoomPixmap.fill(Qt::lightGray); QPainter pz(&zoomPixmap); // pz.translate(-xy); QRect target=QRect(QPoint(0,0),box); pz.drawImage(target, *_img,_rect); pz.end(); QPainterPath clipPath; clipPath.addEllipse(center, ring, ring); QPainter p(_img); p.setRenderHint(QPainter::Antialiasing); p.setClipPath(clipPath); p.drawPixmap(corner, zoomPixmap); p.setClipping(false); p.drawPixmap(corner, maskPixmap); p.setPen(Qt::gray); p.drawPath(clipPath); p.end(); } }
/** * 重绘 * 实现只出现垂直滚动条的重载的画图事件处理方法。 * */ void TaskBallMapWidget::paintEvent(QPaintEvent * event ) { // qLogx()<< __FUNCTION__ <<this->mBallBit.size()<<this->mBallMap.size()<<this->mCurrentTaskId; QBrush brush(QColor(0, 0, 0)); //依靠currtaskid 判断是否需要重绘 if (this->mCurrentTaskId < 0) { return; } if (this->mBallBit.size() <= 0) { qLogx()<<__FUNCTION__<<QString("No bit set,"); // leave the widget raw clear return; } //计算图象应该具有的宽度,splitter是以线性变化,而图形则必须以非线性变化,需要对取到的窗口宽度进行圆整 int width = this->mp->size().width() - 20 ; if (width % (this->mBallRadius*2) != 0 ) { width = ( (width / (this->mBallRadius*2)) ) * ( this->mBallRadius * 2) ; } else { width = (width / (this->mBallRadius*2)) * ( this->mBallRadius * 2) ; } //窗口的高度。 int height = this->mBallMap.height() ; if (width != this->mBallMap.width()) { //qLogx()<< "change to width:" << width ; //需要改变图象大小。宽度 this->mBallMap = QImage(width , this->mBallMap.height() , QImage::Format_ARGB32_Premultiplied); //this->mBallMap = this->mBallMap.scaledToWidth( width ) ; //this->resize(width,height); this->setFixedWidth( width ); } if (this->mBallBit.size() != (width/(this->mBallRadius*2)) * (height/(this->mBallRadius*2))) { height = (this->mBallRadius*2) * (this->mBallBit.size())/((width/(this->mBallRadius*2))); if (height % (this->mBallRadius*2) != 0 ) { height = ( 1+ (height / (this->mBallRadius*2)) ) * ( this->mBallRadius * 2); } else { height = ( height / (this->mBallRadius*2) ) * ( this->mBallRadius * 2); } //qLogx()<< "change to height: " << height ; //需要改变图象大小。高度。 //this->mBallMap = this->mBallMap.scaledToHeight( (this->mCurrentLength / (this->mBlockSize))/((width/(this->mBallRadius*2)) ) * ( this->mBallRadius*2 )); this->mBallMap = QImage(width, height, QImage::Format_ARGB32_Premultiplied); //this->mBallMap = this->mBallMap.scaledToHeight(height); //this->resize(width,height); this->setFixedHeight(height); //设置本窗口构件的大小,使得外层的滚动构件能适当的添加或者删除滚动条。 } // ball ball 48 0 // 0 true 600 0 // qLogx()<<__FUNCTION__<<this->mBallBit.size()<<this->mBallMap.isNull()<<width<<height; if (this->mBallMap.isNull()) { /* if not check, show this error: QPainter::begin: Paint device returned engine == 0, type: 3 QPainter::setRenderHint: Painter must be active to set rendering hints QPainter::setBrush: Painter not active QPainter::drawRects: Painter not active QPainter::setBrush: Painter not active QPainter::setBrush: Painter not actiev */ // this->mBallMap = QImage(mp->width(), mp->height(), QImage::Format_ARGB32_Premultiplied); return; } QPainter imgp(&this->mBallMap) ; imgp.setRenderHint(QPainter::Antialiasing, true); imgp.setBrush(brush) ; imgp.drawRect(0, 0, this->mBallMap.width(), this->mBallMap.height()); //更改前景颜色。 brush.setColor(QColor(0,255,0)); imgp.setBrush(brush); ////////// QRadialGradient radgrad ; //梯度法 imgp.setBrush(radgrad) ; int row = 0 , col = 0 ; //当前行,列 int mrow , mcol ; //最大行,列 int srow , scol ; //当前球块所在行,列。 mcol = width / (this->mBallRadius*2) ; mrow = this->mBallBit.size() % mcol == 0 ? (this->mBallBit.size() / mcol) : (this->mBallBit.size() / mcol + 1); int mtb = this->mBallBit.size(); //所有球的个数。 // qLogx()<<"rows:"<<mrow<<"cols:"<<mcol; for (int row = 0; row < mrow; row++) { int sballno; for (int col=0; col < mcol ; col ++) { int bx, by, bw, bh; sballno = row * mcol + col; //本球块在整个文件块中的序号。 if (sballno >= this->mBallBit.size()) { break; } if (this->mBallBit.testBit(sballno) == false) { continue; } bx = col * this->mBallRadius * 2; //本求块的右上角X值。 by = row * this->mBallRadius * 2; //本求块的右上角Y值。 //qLogx()<<"x,y,w"<<bx<<by<<(this->mBallRadius*2); radgrad.setCenter(bx+this->mBallRadius, by + this->mBallRadius); //梯度参数设置 radgrad.setRadius(this->mBallRadius * 2 ); radgrad.setFocalPoint(bx+this->mBallRadius/2,by+this->mBallRadius/2); radgrad.setColorAt(0.0,QColor(255,255,255)); radgrad.setColorAt(0.5,QColor(0,255,0)); radgrad.setColorAt(1.0,QColor(0,0,0)); imgp.setBrush(radgrad); imgp.drawEllipse(bx,by,this->mBallRadius*2 , this->mBallRadius*2); } } //输出到屏幕。 QPainter scrp(this); scrp.drawImage(0, 0, this->mBallMap); }
void GroupBoxWidget::paintEvent(QPaintEvent * /*event*/) { // skip the rest of the painting if no text if (m_titleText.isEmpty()) return; // draw hovering QPainter p(this); if (m_hoverValue > 0 && (m_checkValue == 0.0 || m_checkValue == 1.0)) { QRadialGradient rg = m_checkValue == 1.0 ? QRadialGradient(0.5, 0.2, 0.8) : QRadialGradient(0.5, 1.0, 1.5); QColor startColor(Qt::white); startColor.setAlpha((int)(255.0 * m_hoverValue)); rg.setColorAt(0.0, startColor); rg.setColorAt(1.0, Qt::transparent); rg.setColorAt(0.0, startColor); rg.setColorAt(1.0, Qt::transparent); rg.setCoordinateMode(QGradient::ObjectBoundingMode); p.fillRect(0, 0, width(), height() - m_checkValue * (height() - 12) , rg); } // draw left/right lines if (m_borderFlags & 0x0001) p.fillRect(0, 0, 1, height(), QColor(230, 230, 230)); if (m_borderFlags & 0x0002) p.fillRect(width() - 1, 0, 1, height(), Qt::white); // precalc text position and move painter QStyle * ss = m_checkable ? style() : 0; int indW = ss ? ss->pixelMetric(QStyle::PM_IndicatorWidth, 0, 0) : 0; int indH = ss ? ss->pixelMetric(QStyle::PM_IndicatorHeight, 0, 0) : 0; p.save(); p.setFont(m_titleFont); QFontMetrics metrics(m_titleFont); QRect textRect = metrics.boundingRect(m_titleText); // int textHeight = textRect.height(); int dx = 0; if (m_checkValue < 1.0) { qreal x1 = -textRect.top() + 2, x2 = (width() - textRect.width() - indW - 4) / 2; qreal y1 = height() - 2, //height() + textRect.width()) / 2, y2 = -textRect.top(); p.translate(x1 + m_checkValue * (x2 - x1), y1 + m_checkValue * (y2 - y1)); p.rotate(m_checkValue * 90 - 90); } else p.translate((width() - textRect.width() - indW - 4) / 2, -textRect.top()); // draw checkbox indicator if (m_checkable && indW && indH) { QStyleOptionButton opt; opt.state = QStyle::State_Enabled; int styleOffset = (textRect.height() - indH) / 2; opt.rect = QRect(0, -indH + 4 - styleOffset, indW, indH); dx = indW + 4; opt.state |= m_checked ? QStyle::State_On : QStyle::State_Off; if (underMouse()) opt.state |= QStyle::State_MouseOver; //p.setRenderHints(QPainter::Antialiasing); style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &p, this); } // draw text p.drawText(dx, 0, m_titleText); p.restore(); }
QPixmap ThumbBarDock::generateFuzzyRect(const QSize& size, const QColor& color, int radius) { QPixmap pix(size); pix.fill(Qt::transparent); QPainter painter(&pix); painter.setRenderHint(QPainter::Antialiasing, true); // Draw corners ---------------------------------- QRadialGradient gradient; gradient.setColorAt(1, Qt::transparent); gradient.setColorAt(0, color); gradient.setRadius(radius); QPoint center; // Top Left center = QPoint(radius, radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(0, 0, radius, radius, gradient); // Top right center = QPoint(size.width() - radius, radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(center.x(), 0, radius, radius, gradient); // Bottom left center = QPoint(radius, size.height() - radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(0, center.y(), radius, radius, gradient); // Bottom right center = QPoint(size.width() - radius, size.height() - radius); gradient.setCenter(center); gradient.setFocalPoint(center); painter.fillRect(center.x(), center.y(), radius, radius, gradient); // Draw borders ---------------------------------- QLinearGradient linearGradient; linearGradient.setColorAt(1, Qt::transparent); linearGradient.setColorAt(0, color); // Top linearGradient.setStart(0, radius); linearGradient.setFinalStop(0, 0); painter.fillRect(radius, 0, size.width() - 2*radius, radius, linearGradient); // Bottom linearGradient.setStart(0, size.height() - radius); linearGradient.setFinalStop(0, size.height()); painter.fillRect(radius, int(linearGradient.start().y()), size.width() - 2*radius, radius, linearGradient); // Left linearGradient.setStart(radius, 0); linearGradient.setFinalStop(0, 0); painter.fillRect(0, radius, radius, size.height() - 2*radius, linearGradient); // Right linearGradient.setStart(size.width() - radius, 0); linearGradient.setFinalStop(size.width(), 0); painter.fillRect(int(linearGradient.start().x()), radius, radius, size.height() - 2*radius, linearGradient); return pix; }
//! [7] void TabletCanvas::updateBrush(QTabletEvent *event) { int hue, saturation, value, alpha; myColor.getHsv(&hue, &saturation, &value, &alpha); int vValue = int(((event->yTilt() + 60.0) / 120.0) * 255); int hValue = int(((event->xTilt() + 60.0) / 120.0) * 255); //! [7] //! [8] switch (alphaChannelType) { case AlphaPressure: myColor.setAlpha(int(event->pressure() * 255.0)); break; case AlphaTilt: myColor.setAlpha(maximum(abs(vValue - 127), abs(hValue - 127))); break; default: myColor.setAlpha(255); } //! [8] //! [9] switch (colorSaturationType) { case SaturationVTilt: myColor.setHsv(hue, vValue, value, alpha); break; case SaturationHTilt: myColor.setHsv(hue, hValue, value, alpha); break; case SaturationPressure: myColor.setHsv(hue, int(event->pressure() * 255.0), value, alpha); break; default: ; } //! [9] //! [10] switch (lineWidthType) { case LineWidthPressure: myPen.setWidthF(event->pressure() * 10 + 1); break; case LineWidthTilt: myPen.setWidthF(maximum(abs(vValue - 127), abs(hValue - 127)) / 12); break; default: myPen.setWidthF(1); } //! [10] //! [11] if (event->pointerType() == QTabletEvent::Eraser) { myBrush.setColor(Qt::white); myPen.setColor(Qt::white); myPen.setWidthF(event->pressure() * 10*factor + 1); } else { QRadialGradient grad; grad.setColorAt(0,myColor); grad.setColorAt(0.5,myColor); QColor colr2(myColor); colr2.setAlpha(0); grad.setColorAt(1.0,colr2); myBrush = QBrush(grad); myBrush.setColor(myColor); myPen.setBrush(grad); } }