Ejemplo n.º 1
1
void HudWindow::resizeEvent(QResizeEvent* event)
{
    Q_UNUSED(event);

    if (desktopCompositingEnabled)
    {
        // Pre-draw the window drop shadow.  It only needs to be drawn upon
        // resize.  We do this because applying a blur effect to the drop
        // shadow is computationally expensive.

        // First, draw the shadow, using a pleasant gradient.
        QLinearGradient shadowGradient;
        shadowGradient.setStart(rect().width() / 2, 0.0);
        shadowGradient.setFinalStop(rect().width() / 2, rect().height());
        shadowGradient.setColorAt(0.0, QColor(0, 0, 0, 20));
        shadowGradient.setColorAt(1.0, QColor(0, 0, 0, 200));

        QImage unblurredImage
            (
                rect().width(),
                rect().height(),
                QImage::Format_ARGB32_Premultiplied
            );
        unblurredImage.fill(Qt::transparent);

        QPainter painter(&unblurredImage);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setPen(QPen(Qt::NoPen));
        painter.setBrush(QBrush(shadowGradient));
        painter.drawRoundedRect(rect().adjusted(10, 10, -10, -8), 5, 5);
        painter.end();

        // Now we need to blur the shadow onto its final destination image,
        // dropShadowImg, which will be drawn on the next paintEvent().
        //
        dropShadowImg = QImage
            (
                rect().width(),
                rect().height(),
                QImage::Format_ARGB32_Premultiplied
            );
        dropShadowImg.fill(Qt::transparent);

        painter.begin(&dropShadowImg);
        painter.setRenderHint(QPainter::Antialiasing);

        // Note that the blur only applies to the alpha channel.
        qt_blurImage(&painter, unblurredImage, 20, true, true);
        painter.end();
    }
}
Ejemplo n.º 2
0
void ViewProfileScale::paintHue ()
{
  // Create two spectrums:
  // 1) one spectrum from red to green
  // 2) another from green to blue
  QLinearGradient gradient (QPointF (0.0,
                                     height() / 2.0),
                            QPointF (width (),
                                     height () / 2.0));
  gradient.setColorAt (0.0000, Qt::red);
  gradient.setColorAt (0.3333, Qt::green);
  gradient.setColorAt (0.6666, Qt::blue);
  gradient.setColorAt (1.0000, Qt::red);

  QPainter painter (this);
  painter.setPen (Qt::NoPen);

  QBrush brush (gradient);

  painter.setBrush (brush);
  painter.drawRect (0,
                    0,
                    rect().width (),
                    rect().height ());
}
Ejemplo n.º 3
0
        void GraphWidget::_drawLines()
        {
			int width = this->widget->width();
			int height = this->widget->height();
			QList<float>::iterator it = this->_values.begin();
			QList<float>::iterator itEnd = --this->_values.end();
			this->_painter.fillRect(this->_image.rect(), QBrush(Qt::white));
			QPainterPath path;
			int pos = width - this->_values.size();
			while (pos < 0)
			{
				this->_values.removeLast();
				pos = width - this->_values.size();
			}
			path.moveTo(pos, height);
            for (; it != itEnd && width > pos; --itEnd, ++pos)
				path.lineTo(pos, height - static_cast<int>(*itEnd * height / this->_highest_value));
			path.lineTo(pos, height - static_cast<int>(*itEnd * height / this->_highest_value));
			path.lineTo(pos + height, height);
			path.closeSubpath();

			QLinearGradient grad;
			grad.setColorAt(0, QColor(0, 250, 0));
			grad.setColorAt(1, QColor(0, 75, 0));
			grad.setStart(0, 0);
			grad.setFinalStop(0, height);
			this->_painter.setBrush(QBrush(grad));
			this->_painter.drawPath(path);
        }
Ejemplo n.º 4
0
/**
 * Décrit le façon de dessiner l'élément sur la scène
 *
 * @brief   Item_Ope::paint(QPainter *pPainter, const QStyleOptionGraphicsItem * option, QWidget * widget)
 * @param   pPainter    le pinceau servant à dessiner sur la scène
 * @param   option      Option sur le dessin (pas utile dans notre cas)
 * @param   widget      Pointer vers le widget sur lequel l'item sera peint (pas utile dans notre cas)
 * @see     Item
 */
void Item_Ope::paint(QPainter *pPainter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
    this->GererSelection(pPainter) ;
    this->sTexte = this->pInstRepresentee->toString() ;

    //Définition du dégradé dans l'item
    qreal           top             (this->rect.top()) ;
    QPointF         PremierPoint    (0, top) ;
    QPointF         SecondPoint     (0, -top) ;
    QLinearGradient grad            (PremierPoint, SecondPoint) ;
    QColor          PremiereCouleur (0x98, 0xFE, 0x98, 0xFF) ;
    QColor          SecondeCouleur  (0x62, 0xBA, 0x62, 0xFF) ;
    grad.setColorAt(0, PremiereCouleur) ;
    grad.setColorAt(1, SecondeCouleur) ;

    //Définition du brush pour appliquer le dégradé
    QBrush brush    (grad) ;

    //Dessin de l'item
    pPainter->setBrush(brush);
    pPainter->drawRect(rect);

    pPainter->setPen(QPen());
    pPainter->drawText(rect, sTexte, QTextOption(Qt::AlignCenter));
}
void KisGradientBenchmark::benchmarkGradient()
{
    KoColor fg(m_colorSpace);
    KoColor bg(m_colorSpace);
    fg.fromQColor(Qt::blue);
    bg.fromQColor(Qt::black);
    
    QBENCHMARK
    {
        QLinearGradient grad;
        grad.setColorAt(0, Qt::white);
        grad.setColorAt(1.0, Qt::red);
        KoAbstractGradient* kograd = KoStopGradient::fromQGradient(&grad);
        Q_ASSERT(kograd);
        KisGradientPainter fillPainter(m_device);
        //setupPainter(&fillPainter);
        fillPainter.setGradient(kograd);

        fillPainter.beginTransaction(kundo2_noi18n("Gradient Fill"));

        //fillPainter.setProgress(updater->startSubtask());
        fillPainter.setOpacity(OPACITY_OPAQUE_U8);
        // default
        fillPainter.setCompositeOp(COMPOSITE_OVER);
        fillPainter.setGradientShape(KisGradientPainter::GradientShapeBiLinear);
        fillPainter.paintGradient(QPointF(0,0), QPointF(3000,3000), KisGradientPainter::GradientRepeatNone, true, false, 0, 0, GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT);

        fillPainter.deleteTransaction();
    }
    
    // uncomment this to see the output
    QImage out = m_device->convertToQImage(m_colorSpace->profile(),0,0,GMP_IMAGE_WIDTH,GMP_IMAGE_HEIGHT);
    out.save("fill_output.png");
}
Ejemplo n.º 6
0
/**
 * Décrit le façon de dessiner l'élément sur la scène
 *
 * @brief   Item_Rout::paint(QPainter *pPainter, const QStyleOptionGraphicsItem * option, QWidget * widget)
 * @param   pPainter    le pinceau servant à dessiner sur la scène
 * @param   option      Option sur le dessin (pas utile dans notre cas)
 * @param   widget      Pointer vers le widget sur lequel l'item sera peint (pas utile dans notre cas)
 * @see     Item
 */
void Item_Rout::paint(QPainter *pPainter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
    this->GererSelection(pPainter) ;
    this->sTexte = this->pInstRepresentee->toString() ;

    //Définition du dégradé
    qreal           top             (this->rect.top()) ;
    qreal           left            (this->rect.left()) ;
    QPointF         PremierPoint    (0, top) ;
    QPointF         SecondPoint     (0, -top) ;
    QLinearGradient grad            (PremierPoint, SecondPoint) ;
    QColor          PremiereCouleur (0xFF, 0xD5, 0x98, 0xFF) ;
    QColor          SecondeCouleur  (0xF3, 0xA6, 0x62, 0xFF) ;
    grad.setColorAt(0, PremiereCouleur);
    grad.setColorAt(1, SecondeCouleur);

    //Définition du brush
    QBrush brush(grad);
    pPainter->setBrush(brush);

    //Dessin de l'item
    QPointF OriginePrem (left*(7.0/8.0), top) ;
    QPointF FinPrem     (left*(7.0/8.0), -top) ;
    QPointF OrigineSec  (-left*(7.0/8.0), top) ;
    QPointF FinSec      (-left*(7.0/8.0), -top) ;
    pPainter->drawRect(rect);
    pPainter->drawLine(OriginePrem, FinPrem);
    pPainter->drawLine(OrigineSec, FinSec);

    pPainter->setPen(QPen());
    pPainter->drawText(rect, sTexte, QTextOption(Qt::AlignCenter));
}
Ejemplo n.º 7
0
void PlaylistItemDelegate::paintActiveOverlay(QPainter *painter, const QRect &line) const {
    static QLinearGradient linearGradient;
    static bool initialized = false;

    if (!initialized) {
        QPalette palette;
        QColor highlightColor = palette.color(QPalette::Highlight);
        QColor backgroundColor = palette.color(QPalette::Base);
        const float animation = 0.4;
        const int gradientRange = 16;

        QColor color2 = QColor::fromHsv(
                    highlightColor.hue(),
                    (int) (backgroundColor.saturation() * (1.0f - animation) + highlightColor.saturation() * animation),
                    (int) (backgroundColor.value() * (1.0f - animation) + highlightColor.value() * animation)
                    );
        QColor color1 = QColor::fromHsv(
                    color2.hue(),
                    qMax(color2.saturation() - gradientRange, 0),
                    qMin(color2.value() + gradientRange, 255)
                    );

        linearGradient = QLinearGradient(0, 0, 0, THUMB_HEIGHT);
        linearGradient.setColorAt(0.0, color1);
        linearGradient.setColorAt(1.0, color2);
        initialized = true;
    }

    painter->fillRect(line, linearGradient);
}
Ejemplo n.º 8
0
QLinearGradient* getLinearGradient(const CLLinearGradient* linear, const CLBoundingBox* bounds, const CLRenderResolver* resolver)
{
  double x1 = bounds->getPosition().getX() + linear->getXPoint1().getAbsoluteValue()  + (linear->getXPoint1().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth());
  double y1 = bounds->getPosition().getY() + linear->getYPoint1().getAbsoluteValue()  + (linear->getYPoint1().getRelativeValue() / 100.0 * bounds->getDimensions().getHeight());
  double x2 = bounds->getPosition().getX() + linear->getXPoint2().getAbsoluteValue()  + (linear->getXPoint2().getRelativeValue() / 100.0 * bounds->getDimensions().getWidth());
  double y2 = bounds->getPosition().getY() + linear->getYPoint2().getAbsoluteValue()  + (linear->getYPoint2().getRelativeValue() / 100.0 * bounds->getDimensions().getHeight());

  QLinearGradient* result = new QLinearGradient(x1, y1, x2, y2);

  switch (linear->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 < linear->getNumGradientStops(); ++i)
    {
      const CLGradientStop* stop = linear->getGradientStop(i);
      result->setColorAt(stop->getOffset().getAbsoluteValue() + stop->getOffset().getRelativeValue() / 100.0, getColor(stop->getStopColor(), resolver));
    }

  return result;
}
Ejemplo n.º 9
0
void Button::paintEvent(QPaintEvent *event)
{
    QWidget::paintEvent(event);
    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing, true);

    QRect roundedRect(event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height());

    QPainterPath path(QPoint(roundedRect.left(), roundedRect.top() + d->topLeftRadius));
    path.quadTo(roundedRect.left(), roundedRect.top(), roundedRect.left() + d->topLeftRadius, roundedRect.top());
    path.lineTo(roundedRect.right() - d->topRightRadius, roundedRect.top());
    path.quadTo(roundedRect.right(), roundedRect.top(), roundedRect.right(), roundedRect.top()
                + d->topRightRadius);
    path.lineTo(roundedRect.right(), roundedRect.bottom() - d->bottomRightRadius);
    path.quadTo(roundedRect.right(), roundedRect.bottom(), roundedRect.right() -
                d->bottomRightRadius, roundedRect.bottom());
    path.lineTo(roundedRect.left() + d->bottomLeftRadius, roundedRect.bottom());
    path.quadTo(roundedRect.left(), roundedRect.bottom(), roundedRect.left(), roundedRect.bottom()
                - d->bottomLeftRadius);
    path.closeSubpath();

    QLinearGradient gradient;
    if(!d->pressed)
    {
        gradient = d->gradient;
    }
    if(d->pressed || (d->checked && d->checkable))
    {
        gradient = d->pressedGradient;
    }
    if(!isEnabled())
    {
        gradient = QLinearGradient(QPoint(0, 0), QPoint(0, height()));
        gradient.setColorAt(0, QColor(230, 230, 230));
        gradient.setColorAt(1, QColor(200, 200, 200));
    }
    gradient.setStart(QPoint(0, 0));
    gradient.setFinalStop(QPoint(0, height()));
    p.fillPath(path, QBrush(gradient));

    p.setPen(QColor(d->borderColor));
    p.drawPath(path);
    p.setPen(QColor(d->textColor));

    if(d->icon.isNull())
    {
        if(d->checked && d->checkable && !d->checkedText.isEmpty())
            p.drawText(roundedRect, Qt::AlignCenter, d->checkedText);
        if(!d->checkable || !d->checked || d->checkedText.isEmpty())
            p.drawText(roundedRect, Qt::AlignCenter, d->text);
    }
    else
    {
        if(d->checked && d->checkable && !d->checkedIcon.isNull())
               d->checkedIcon.paint(&p, roundedRect, Qt::AlignCenter);
        if(!d->checkable || !d->checked || d->checkedIcon.isNull())
            d->icon.paint(&p, roundedRect.x()+4, roundedRect.y()+4, roundedRect.width()-8
                          , roundedRect.height()-8,  Qt::AlignCenter);
    }
}
Ejemplo n.º 10
0
void MainWindow::setupCustomPlot()
{
    ui->customplot->xAxis->setRange(LEFTBOUND, RIGHTBOUND);
    ui->customplot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
    ui->customplot->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical);

    //backgroundcolor
    QLinearGradient plotGrad;
    plotGrad.setStart(0,0);
    plotGrad.setFinalStop(0,350);
    plotGrad.setColorAt(0,QColor(80,80,80));
    plotGrad.setColorAt(1,QColor(50,50,50));
    ui->customplot->setBackground(plotGrad);
    //

    ui->customplot->xAxis->setBasePen(QPen(Qt::white, 1));
    ui->customplot->yAxis->setBasePen(QPen(Qt::white, 1));
    ui->customplot->xAxis->setTickPen(QPen(Qt::white, 1));
    ui->customplot->yAxis->setTickPen(QPen(Qt::white, 1));
    ui->customplot->xAxis->setSubTickPen(QPen(Qt::white, 1));
    ui->customplot->yAxis->setSubTickPen(QPen(Qt::white, 1));
    ui->customplot->xAxis->setTickLabelColor(Qt::white);
    ui->customplot->yAxis->setTickLabelColor(Qt::white);

    ui->customplot->xAxis->grid()->setPen(QPen(QColor(140,140,140), 1, Qt::DotLine));
    ui->customplot->yAxis->grid()->setPen(QPen(QColor(140,140,140), 1, Qt::DotLine));
    ui->customplot->xAxis->grid()->setSubGridPen(QPen(QColor(80,80,80), 1, Qt::DotLine));
    ui->customplot->yAxis->grid()->setSubGridPen(QPen(QColor(80,80,80), 1, Qt::DotLine));
    ui->customplot->xAxis->grid()->setSubGridVisible(true);
    ui->customplot->yAxis->grid()->setSubGridVisible(true);

    ui->customplot->xAxis->setLabelColor(Qt::white);
    ui->customplot->yAxis->setLabelColor(Qt::white);
}
Ejemplo n.º 11
0
void DkTransferToolBar::loadSettings() {

    QSettings& settings = Settings::instance().getSettings();
    settings.beginGroup("Pseudo Color");

    int gSize = settings.beginReadArray("oldGradients");

    for (int idx = 0; idx < gSize; idx++) {
        settings.setArrayIndex(idx);

        QVector<QGradientStop> stops;
        int sSize = settings.beginReadArray("gradient");

        for (int sIdx = 0; sIdx < sSize; sIdx++) {
            settings.setArrayIndex(sIdx);

            QGradientStop s;
            s.first = settings.value("posRGBA", 0).toFloat();
            s.second = QColor::fromRgba(settings.value("colorRGBA", QColor().rgba()).toInt());
            qDebug() << "pos: " << s.first << " col: " << s.second;
            stops.append(s);
        }
        settings.endArray();

        QLinearGradient g;
        g.setStops(stops);
        oldGradients.append(g);
    }

    settings.endArray();
    settings.endGroup();
}
Ejemplo n.º 12
0
void QProg::paintBorder()
{
    //int m_sizeW= 90;
    //int m_sizeH= 470;
    QPainter painter(this);
    painter.setWindow(0, 0, m_sizeW, m_sizeH);
    painter.setRenderHint(QPainter::Antialiasing);
    
    int m_linGradY = 40;
    //QLinearGradient linGrad(5, 40, 15, 40);
    // QLinearGradient linGrad(36, 5, 5, 15);
    QLinearGradient linGrad (40, m_sizeH-7, 40, m_sizeH-18);
    //QLinearGradient linGrad(m_sizeH, 5, m_sizeH, 15);
    linGrad.setColorAt(0, Qt::white);
    linGrad.setColorAt(1, Qt::black);
    linGrad.setSpread(QGradient::PadSpread);
    painter.setBrush(linGrad);
    QRectF border(5, 5, m_sizeW-10, m_sizeH-10);
    //QRectF border(0, 0, m_sizeW-10, m_sizeH);
    painter.drawRoundRect(border, 20, 5);

    // value rect
    painter.setBrush(QColor(70, 70, 70));
    QRectF value(nValueRectX, nValueRectY, m_sizeW/1.3, m_sizeH/15);
    painter.drawRoundRect(value, 15);

}
Ejemplo n.º 13
0
/**
 * Décrit le façon de dessiner l'élément sur la scène
 *
 * @brief   Item_Tempo::paint(QPainter *pPainter, const QStyleOptionGraphicsItem * option, QWidget * widget)
 * @param   pPainter    le pinceau servant à dessiner sur la scène
 * @param   option      Option sur le dessin (pas utile dans notre cas)
 * @param   widget      Pointer vers le widget sur lequel l'item sera peint (pas utile dans notre cas)
 * @see     Item
 */
void Item_Tempo::paint(QPainter *pPainter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
    this->GererSelection(pPainter) ;
    this->sTexte = this->pInstRepresentee->toString() ;

    //Définition du dégradé
    qreal           top             (this->rect.top()) ;
    QPointF         PremierPoint    (0, top) ;
    QPointF         SecondPoint     (0, -top) ;
    QLinearGradient grad            (PremierPoint, SecondPoint) ;
    QColor          PremiereCouleur (0x5E, 0xC1, 0xFF, 0xFF) ;
    QColor          SecondeCouleur  (0x22, 0xAA, 0xFF, 0xFF) ;
    grad.setColorAt(0, PremiereCouleur) ;
    grad.setColorAt(1, SecondeCouleur) ;

    //Définition du brush
    QBrush brush(grad) ;
    pPainter->setBrush(brush) ;

    //Dessin de l'item
    qreal   Rayon           (-top) ;
    QPointF Centre          (0, 0) ;
    QRectF  RectTexte       (top, top, -2*top, -2*top) ;

    pPainter->drawEllipse(Centre, Rayon, Rayon) ;

    pPainter->setPen(QPen());
    pPainter->drawText(RectTexte, sTexte, QTextOption(Qt::AlignCenter)) ;
}
Ejemplo n.º 14
0
//---------------------------------------------------------------
void LonLatGrid::drawLabel(QPainter &pnt, const Projection *proj,
				double value, int i, int j)
{
    int   a,b,c,d;
    QString label;
	QColor couleur(10,10,10);

    label = label.sprintf("%g", value);

    QPen penText(couleur);
    QFont fontText = Font::getFont(FONT_LonLatGridLabel);
    QFontMetrics fmet(fontText);
    QRect rect = fmet.boundingRect(label);
    pnt.setPen(penText);
    pnt.setFont(fontText);

	// use a gradient, because it's a bug sometimes with solid pattern (black background)
	QLinearGradient gradient;
    int r = 255;
	gradient.setColorAt(0, QColor(r,r,r, 170));
	gradient.setColorAt(1, QColor(r,r,r, 170));
    pnt.setBrush(gradient);

    //---------------------------------------------------------
    // Ecrit le label
    //---------------------------------------------------------
	
// 	rect = fmet.boundingRect(label);
// 	rect.moveTo((a+c)/2-rect.width()/2, (b+d)/2-rect.height()/2);
// 	pnt.drawRect(rect.x()-1, rect.y(), rect.width()+2, fmet.ascent()+2);
// 	pnt.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter, label);

}
Ejemplo n.º 15
0
void SurfaceGraph::enableInterpModel(bool enable)
{
    if (enable){
        this->nn=n;
        this->mm=m;
        m_InterpSeries->setDrawMode(QSurface3DSeries::DrawSurfaceAndWireframe);
        m_InterpSeries->setFlatShadingEnabled(true);
        m_graph->axisX()->setLabelFormat("%.2f");
        m_graph->axisZ()->setLabelFormat("%.2f");
        m_graph->axisX()->setRange(xMin, xMax);
        m_graph->axisY()->setAutoAdjustRange(true);
        m_graph->axisZ()->setRange(zMin, zMax);
        m_graph->axisX()->setLabelAutoRotation(30);
        m_graph->axisY()->setLabelAutoRotation(90);
        m_graph->axisZ()->setLabelAutoRotation(30);
        m_graph->removeSeries(m_InterpSeries);
        m_graph->removeSeries(m_InitPlotSeries);
        m_graph->removeSeries(m_ResidSeries);
        m_graph->addSeries(m_InterpSeries);
        m_graph->activeTheme()->setType(Q3DTheme::ThemePrimaryColors);
        QLinearGradient gr;
        gr.setColorAt(0.0, Qt::green);
        m_graph->seriesList().at(0)->setBaseGradient(gr);
        m_graph->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient);
        m_rangeMinX=xMin;
        m_rangeMinZ=zMin;
        m_stepX=(xMax-xMin)/double(skolkoX-1);
        m_stepZ=(zMax-zMin)/double(skolkoZ-1);
        kolichestvo=1;
    }
}
Ejemplo n.º 16
0
void StylePainterMobile::drawProgress(const QRect& rect, double progress, bool leftToRight, bool animated, bool vertical) const
{
    const int horizontalBorder = (vertical ? rect.width() / 4 : 0);
    const int verticalBorder = (vertical ? 0 : rect.height() / 4);
    const QRect targetRect = rect.adjusted(horizontalBorder, verticalBorder, -horizontalBorder, -verticalBorder);

    QPixmap result;
    QSize imageSize = sizeForPainterScale(targetRect);
    if (vertical)
        qSwap(imageSize.rheight(), imageSize.rwidth());
    KeyIdentifier id;
    id.type = KeyIdentifier::Progress;
    id.width = imageSize.width();
    id.height = imageSize.height();
    id.trait1 = animated;
    id.trait2 = (!animated && !leftToRight);
    id.trait3 = progress * 100;
    if (!findCachedControl(id, &result)) {
        if (imageSize.isNull())
            return;
        result = QPixmap(imageSize);
        result.fill(Qt::transparent);
        QPainter painter(&result);
        painter.setRenderHint(QPainter::Antialiasing);
        QRect progressRect(QPoint(0, 0), imageSize);
        qreal radius = radiusFactor * progressRect.height();
        painter.setBrush(Qt::NoBrush);
        painter.setPen(borderPen());
        progressRect.adjust(1, 1, -1, -1);
        painter.drawRoundedRect(progressRect, radius, radius);
        progressRect.adjust(1, 1, -1, -1);
        if (animated) {
            const int right = progressRect.right();
            const int startPos = right * (1 - progressBarChunkPercentage) * 2 * fabs(progress - 0.5);
            progressRect.setWidth(progressBarChunkPercentage * right);
            progressRect.moveLeft(startPos);
        } else {
            progressRect.setWidth(progress * progressRect.width());
            if (!leftToRight)
                progressRect.moveRight(imageSize.width() - 2);
        }
        if (progressRect.width() > 0) {
            QLinearGradient gradient;
            gradient.setStart(progressRect.bottomLeft());
            gradient.setFinalStop(progressRect.topLeft());
            gradient.setColorAt(0.0, highlightColor);
            gradient.setColorAt(1.0, highlightColor.lighter());
            painter.setBrush(gradient);
            painter.setPen(Qt::NoPen);
            radius = radiusFactor * progressRect.height();
            painter.drawRoundedRect(progressRect, radius, radius);
        }
        insertIntoCache(id, result);
    }
    QTransform transform;
    transform.rotate(-90);
    painter->drawPixmap(targetRect, vertical ? result.transformed(transform) : result);
}
Ejemplo n.º 17
0
void AutoCompletionDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    QStyledItemDelegate::paint(painter,option,index);
    const QString tag = index.data(Qt::UserRole).toString();
    if (!tag.isEmpty()) {
        painter->save();
        painter->setRenderHint(QPainter::Antialiasing, true);
        painter->setClipRect(option.rect);
        static bool init = false;
        static QFont f;
        static QLinearGradient g;
        if (!init) {
            f = painter->font();
            f.setBold(true);
            f.setPointSize(f.pointSize()-1);
            g = QLinearGradient(QPointF(0, 0), QPointF(0, option.rect.height()-4));
            QColor col = QApplication::palette().color(QPalette::Highlight);
            col.setAlpha(125);
            g.setColorAt(0, col);
            col.setAlpha(175);
            g.setColorAt(1, col);
            init = true;
        }
        static QFontMetrics m(f);
        static int height    = m.height();
        int rectHeight = option.rect.height();
        int leftOver = (rectHeight-height);
        int padding   = leftOver/2 >= 4 ? 2: 0;
        int topMargin = (leftOver-2*padding)/2;
        painter->setFont(f);
        const int width = m.width(tag);
        const int x = option.rect.x()+option.rect.width()-width-RIGHT_MARGIN-rectHeight/2;
        painter->setBrush(g);
        painter->setPen(Qt::NoPen);
        QRect rect(x,
                   option.rect.y()+topMargin,
                   width,
                   height+2*padding);
        painter->drawRect(rect);
        painter->setClipRect(x-rectHeight/2,option.rect.y(),rectHeight/2,rectHeight);
        painter->drawEllipse(QRect(
                                 x-(height+2*padding)/2,
                                 option.rect.y()+topMargin,
                                 (height+2*padding),
                                 (height+2*padding)));
        painter->setClipRect(x+width,option.rect.y(),option.rect.height(),option.rect.height());
        painter->drawEllipse(QRect(
                                 x+width-(height+2*padding)/2,
                                 option.rect.y()+topMargin,
                                 (height+2*padding),
                                 (height+2*padding)));
        painter->setPen(QApplication::palette().base().color());
        painter->setClipping(false);
        painter->drawText(rect,Qt::AlignHCenter|Qt::AlignVCenter,tag);
        painter->restore();
    }
}
Ejemplo n.º 18
0
void
QTMStyle::drawControl (ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const {
  switch (element) {
#if 0
    case CE_MenuItem:
      if (const QStyleOptionMenuItem *mi =
          qstyleoption_cast<const QStyleOptionMenuItem *> (option)) {
        QStyleOptionMenuItem mi2(*mi);
        mi2.text= QString ("pippo");
        baseStyle()->drawControl (element, &mi2, painter, widget);
        break;
      }
#endif

    case CE_ToolBar: {
#ifdef UNIFIED_TOOLBAR
      if ((widget) &&  (widget->windowTitle() == "mode toolbar"))  {

          // For unified tool bars, draw nothing.
          if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(widget->window())) {
            if ((mainWindow->unifiedTitleAndToolBarOnMac()) && 
                (widget->parent()->objectName() != "central widget"))
              break;
          }

          //QColor mainWindowGradientBeginActive (150, 150, 150);
          //QColor mainWindowGradientBegin (200, 200, 200);
          //QColor mainWindowGradientEnd (232, 232, 232);

          QColor mainWindowGradientBeginActive (222, 222, 222);
          QColor mainWindowGradientEndActive (202, 202, 202);
          QColor mainWindowGradientBegin (236, 236, 236);
          QColor mainWindowGradientEnd (226, 226, 226);
  
          if (widget->window()->isActiveWindow())
            mainWindowGradientBegin = mainWindowGradientBeginActive;
          if (widget->window()->isActiveWindow())
            mainWindowGradientEnd = mainWindowGradientEndActive;

          // draw background gradient
          QLinearGradient linearGrad;
          if (option->state & State_Horizontal)
            linearGrad = QLinearGradient(0, option->rect.top(), 0, option->rect.bottom());
          else
            linearGrad = QLinearGradient(option->rect.left(), 0,  option->rect.right(), 0);
          
          linearGrad.setColorAt(0, mainWindowGradientBegin);
          linearGrad.setColorAt(1, mainWindowGradientEnd);
          painter->fillRect(option->rect, linearGrad);
        }
#endif // UNIFIED_TOOLBAR
    } break;
      
    default:
      baseStyle()->drawControl (element, option, painter, widget);
  }
}
Ejemplo n.º 19
0
void testShapedGradientPainterImpl(const QPolygonF &selectionPolygon,
                                   const QString &testName,
                                   const QPolygonF &selectionErasePolygon = QPolygonF())
{
    const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
    KisPaintDeviceSP dev = new KisPaintDevice(cs);

    QRect imageRect(0,0,300,300);

    KisSelectionSP selection = new KisSelection();
    KisPixelSelectionSP pixelSelection = selection->pixelSelection();

    KisPainter selPainter(pixelSelection);
    selPainter.setFillStyle(KisPainter::FillStyleForegroundColor);
    selPainter.setPaintColor(KoColor(Qt::white, pixelSelection->colorSpace()));
    selPainter.paintPolygon(selectionPolygon);

    if (!selectionErasePolygon.isEmpty()) {
        selPainter.setCompositeOp(COMPOSITE_ERASE);
        selPainter.setPaintColor(KoColor(Qt::white, pixelSelection->colorSpace()));
        selPainter.paintPolygon(selectionErasePolygon);
    }

    selPainter.end();

    pixelSelection->invalidateOutlineCache();

    pixelSelection->convertToQImage(0, imageRect).save("sgt_selection.png");

    QLinearGradient testGradient;
    testGradient.setColorAt(0.0, Qt::white);
    testGradient.setColorAt(0.5, Qt::green);
    testGradient.setColorAt(1.0, Qt::black);
    testGradient.setSpread(QGradient::ReflectSpread);
    QScopedPointer<KoStopGradient> gradient(
        KoStopGradient::fromQGradient(&testGradient));

    KisGradientPainter gc(dev, selection);
    gc.setGradient(gradient.data());
    gc.setGradientShape(KisGradientPainter::GradientShapePolygonal);

    gc.paintGradient(selectionPolygon.boundingRect().topLeft(),
                     selectionPolygon.boundingRect().bottomRight(),
                     KisGradientPainter::GradientRepeatNone,
                     0,
                     false,
                     imageRect.x(),
                     imageRect.y(),
                     imageRect.width(),
                     imageRect.height());

    QVERIFY(TestUtil::checkQImageExternal(dev->convertToQImage(0, imageRect),
                                          "shaped_gradient",
                                          "fill",
                                          testName, 1, 1, 0));
}
Ejemplo n.º 20
0
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();
    }
}
Ejemplo n.º 21
0
QGradient GradientDialog::gradient() const
{
    QLinearGradient gradient;
    gradient.setStart( 0, 0 );
    gradient.setStart( 1, 0 );
    gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
    Q_FOREACH( const QGradientStop &stop, d->m_gradient )
        gradient.setColorAt( stop.first, stop.second );
    return gradient;
}
Ejemplo n.º 22
0
  Scene2D::Scene2D(Device* d, QObject* parent) : QGraphicsScene(parent) {
    d_ = d;
    myTextColor = Qt::black;
    //startTimer(100);

    QLinearGradient gradient = QLinearGradient(QPointF(), QPointF(5000, 5000));
    gradient.setColorAt(0, QColor(45, 197, 255, 76));
    gradient.setColorAt(1.0, QColor(0, 0, 0, 76));
    //setBackgroundBrush(gradient);
    setBackgroundBrush(Qt::white);
  }
Ejemplo n.º 23
0
void KarbonGradientWidget::paintEvent(QPaintEvent*)
{
    int w = width() - 4;  // available width for gradient and points
    int h = height() - 7; // available height for gradient and points
    int ph = colorStopBorder_height + 2; // point marker height
    int gh = h - ph;       // gradient area height

    QPainter painter(this);

    QLinearGradient gradient;
    gradient.setStart(QPointF(2, 2));
    gradient.setFinalStop(QPointF(width() - 2, 2));
    gradient.setStops(m_stops);

    m_checkerPainter.paint(painter, QRectF(2, 2, w, gh));

    painter.setBrush(QBrush(gradient));
    painter.drawRect(QRectF(2, 2, w, gh));

    painter.setBrush(QBrush());
    painter.setPen(palette().light().color());

    // light frame around widget
    QRect frame(1, 1, width() - 2, height() - 2);
    painter.drawRect(frame);

    // light line between gradient and point area
    painter.drawLine(QLine(QPoint(1, 3 + gh), QPoint(width() - 1, 3 + gh)));

    painter.setPen(palette().dark().color());
    // left-top frame around widget
    painter.drawLine(QPoint(), QPoint(0, height() - 1));
    painter.drawLine(QPoint(), QPoint(width() - 1, 0));

    // right-bottom from around gradient
    painter.drawLine(QPoint(width() - 2, 2), QPoint(width() - 2, 2 + gh));
    painter.drawLine(QPoint(width() - 2, 2 + gh), QPoint(2, 2 + gh));

    // upper line around point area
    painter.drawLine(QPoint(1, height() - 3 - ph), QPoint(width() - 1, height() - 3 - ph));

    // right-bottom line around point area
    painter.drawLine(QPoint(width() - 2, height() - ph - 1), QPoint(width() - 2, height() - 2));
    painter.drawLine(QPoint(width() - 2, height() - 2), QPoint(2, height() - 2));

    m_pntArea.setRect(2, height() - ph - 2, w, ph);
    painter.fillRect(m_pntArea.x(), m_pntArea.y(), m_pntArea.width(), m_pntArea.height(), palette().window().color());

    painter.setClipRect(m_pntArea.x(), m_pntArea.y(), m_pntArea.width(), m_pntArea.height());
    painter.translate(m_pntArea.x(), m_pntArea.y());

    foreach(const QGradientStop & stop, m_stops)
    paintColorStop(painter, (int)(stop.first * m_pntArea.width()), stop.second);
}
Ejemplo n.º 24
0
void ScrollingContextualView::paintEvent(QPaintEvent *e) {
    Q_UNUSED(e);

    QPainter painter(this);
    QRect rect = visibleRegion().boundingRect();

    QLinearGradient shadow;
    shadow.setFinalStop(0, 20);
    shadow.setColorAt(0, QColor(0x00, 0x00, 0x00, 48));
    shadow.setColorAt(1, QColor(0x00, 0x00, 0x00, 0));
    painter.fillRect(rect.x(), rect.y(), rect.width(), 20, QBrush(shadow));
}
Ejemplo n.º 25
0
void KoResourceItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
    if( ! index.isValid() )
        return;

    KoResource * resource = static_cast<KoResource*>( index.internalPointer() );
    if (!resource)
        return;

    painter->save();

    if (option.state & QStyle::State_Selected)
        painter->fillRect( option.rect, option.palette.highlight() );

    QRect innerRect = option.rect.adjusted( 2, 1, -2, -1 );

    KoAbstractGradient * gradient = dynamic_cast<KoAbstractGradient*>( resource );
    if (gradient) {
        QGradient * g = gradient->toQGradient();

        QLinearGradient paintGradient;
        paintGradient.setStops( g->stops() );
        paintGradient.setStart( innerRect.topLeft() );
        paintGradient.setFinalStop( innerRect.topRight() );

        m_checkerPainter.paint( *painter, innerRect );
        painter->fillRect( innerRect, QBrush( paintGradient ) );

        delete g;
    }
    else {
        QImage thumbnail = index.data( Qt::DecorationRole ).value<QImage>();

        QSize imageSize = thumbnail.size();

        if(imageSize.height() > innerRect.height() || imageSize.width() > innerRect.width()) {
            qreal scaleW = static_cast<qreal>( innerRect.width() ) / static_cast<qreal>( imageSize.width() );
            qreal scaleH = static_cast<qreal>( innerRect.height() ) / static_cast<qreal>( imageSize.height() );

            qreal scale = qMin( scaleW, scaleH );

            int thumbW = static_cast<int>( imageSize.width() * scale );
            int thumbH = static_cast<int>( imageSize.height() * scale );
            thumbnail = thumbnail.scaled( thumbW, thumbH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
        }
        painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
        if (thumbnail.hasAlphaChannel()) {
            painter->fillRect(innerRect, Qt::white); // no checkers, they are confusing with patterns.
        }
        painter->fillRect( innerRect, QBrush(thumbnail) );
    }
    painter->restore();
}
Ejemplo n.º 26
0
void GradientDialog::Private::updateGradientDisplay()
{
    QLinearGradient gradient;
    gradient.setStart( 0, 0 );
    gradient.setStart( 1, 0 );
    gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
    Q_FOREACH( const QGradientStop &stop, m_gradient )
        gradient.setColorAt( stop.first, stop.second );
    QPalette palette = ui->gradientDisplay->palette();
    palette.setBrush( QPalette::Background, gradient );
    ui->gradientDisplay->setPalette( palette );
}
Ejemplo n.º 27
0
void SSlider::paintEvent(QPaintEvent*) {

	// This whole function is suboptimal
	QPainter painter(this);

	painter.setRenderHints(QPainter::Antialiasing);

	auto widthActual = ((width()-20-30)/maximum())*maximum();
	mWidthActual = widthActual;
	auto xActual = 10+(width()-20-widthActual)/2;
	mXActual = xActual;
	auto jump = widthActual/maximum();
	mJump = jump;

	auto xpos = (jump*value())+xActual;
	cursor = new QRectF(xpos,0,mControlSize,mControlSize);
	QRectF pilot(xActual,0, widthActual+mControlSize, mControlSize);
	painter.setPen(QPen(QColor("#161616")));
	painter.setBrush(QBrush(QColor("#240128")));
	painter.drawRoundedRect(pilot, mHalfWidth,mHalfWidth);
	QRectF highlight;

	auto startX = mStart*mJump+mXActual;
	if(xpos == startX) {
		highlight.setRect(0,0,0,0);
	} else if(xpos > startX) {
		highlight.setRect(startX,0, xpos+mControlSize-startX, mControlSize);
	} else {
		highlight.setRect(xpos,0, startX-(xpos)+mControlSize, mControlSize);
	}

	painter.setBrush(QBrush(QColor("#6E047C")));

	QLinearGradient gradient;
	gradient.setStart(highlight.width() / 2, 0);
	gradient.setFinalStop(highlight.width() / 2, highlight.height());

	gradient.setColorAt(0, "#B64FC4");
	gradient.setColorAt(1, "#6E047C");
	painter.setBrush(QBrush(gradient));
	painter.drawRoundedRect(highlight, mHalfWidth,mHalfWidth);

	if(mGrabbed) {
		painter.setBrush(QBrush(QColor("#D24CE3")));
	} else {
		painter.setBrush(QBrush(QColor("#8E06A0")));
	}

	painter.setPen(QPen(QColor("#52015B")));
	painter.drawEllipse(*cursor);
	painter.setPen(QPen(QColor("#B1B7E6")));
}
Ejemplo n.º 28
0
QLinearGradient KCategoryDrawer::linearG ( const QStyleOption &option, const QColor col ) const 
{

    QLinearGradient gradient = QLinearGradient(option.rect.topLeft(),
                             			   option.rect.bottomRight());

    gradient.setColorAt(option.direction == Qt::LeftToRight ? 0
                                                            : 1, col);
    gradient.setColorAt(option.direction == Qt::LeftToRight ? 1
                                                            : 0, Qt::transparent);

    return gradient;
}
Ejemplo n.º 29
0
void
InfoBar::resizeEvent( QResizeEvent* e )
{
    QWidget::resizeEvent( e );

    QLinearGradient gradient = QLinearGradient( contentsRect().topLeft(), contentsRect().bottomRight() );
    gradient.setColorAt( 0.0, QColor( 100, 100, 100 ) );
    gradient.setColorAt( 1.0, QColor( 63, 63, 63 ) );

    QPalette p = palette();
    p.setBrush( QPalette::Window, QBrush( gradient ) );
    setPalette( p );
}
void ContextPaneWidgetRectangle::onGradientClicked()
{
    if (ui->colorGradient->isChecked()) {
        m_hasGradient = true;
        QLinearGradient gradient;
        QGradientStops stops;
        stops.append(QGradientStop(0, ui->colorColorButton->convertedColor()));
        stops.append(QGradientStop(1, Qt::white));
        gradient.setStops(stops);
        ui->gradientLine->setEnabled(true);
        ui->gradientLine->setGradient(gradient);
    }
}