Esempio n. 1
0
    void ShadowWindow::paintEvent(QPaintEvent * /*e*/)
    {
        QRect origin = rect();

        QRect right = QRect(QPoint(origin.width() - ShadowWidth_, origin.y() + ShadowWidth_ + 1), QPoint(origin.width(), origin.height() - ShadowWidth_ - 1));
        QRect left = QRect(QPoint(origin.x(), origin.y() + ShadowWidth_ + 1), QPoint(origin.x() + ShadowWidth_, origin.height() - ShadowWidth_ - 1));
        QRect top = QRect(QPoint(origin.x() + ShadowWidth_ + 1, origin.y()), QPoint(origin.width() - ShadowWidth_ - 1, origin.y() + ShadowWidth_));
        QRect bottom = QRect(QPoint(origin.x() + ShadowWidth_ + 1, origin.height() - ShadowWidth_), QPoint(origin.width() - ShadowWidth_ - 1, origin.height()));

        QRect topLeft = QRect(origin.topLeft(), QPoint(origin.x() + ShadowWidth_, origin.y() + ShadowWidth_));
        QRect topRight = QRect(QPoint(origin.width() - ShadowWidth_, origin.y()), QPoint(origin.width(), origin.y() + ShadowWidth_));
        QRect bottomLeft = QRect(QPoint(origin.x(), origin.height() - ShadowWidth_), QPoint(origin.x() + ShadowWidth_, origin.height()));
        QRect bottomRight = QRect(QPoint(origin.width() - ShadowWidth_, origin.height() - ShadowWidth_), origin.bottomRight());

        QPainter p(this);

        QRect body = origin;
        body.setX(origin.x() + ShadowWidth_);
        body.setY(origin.y() + ShadowWidth_);
        body.setWidth(origin.width() - ShadowWidth_ * 2);
        body.setHeight(origin.height() - ShadowWidth_ * 2);
        p.fillRect(body, Brush_);

        QLinearGradient lg = QLinearGradient(right.topLeft(), right.topRight());
        setGradientColor(lg);
        p.fillRect(right, QBrush(lg));

        lg = QLinearGradient(left.topRight(), left.topLeft());
        setGradientColor(lg);
        p.fillRect(left, QBrush(lg));

        lg = QLinearGradient(top.bottomLeft(), top.topLeft());
        setGradientColor(lg);
        p.fillRect(top, QBrush(lg));

        lg = QLinearGradient(bottom.topLeft(), bottom.bottomLeft());
        setGradientColor(lg);
        p.fillRect(bottom, QBrush(lg));

        QRadialGradient g = QRadialGradient(topLeft.bottomRight(), ShadowWidth_);
        setGradientColor(g);
        p.fillRect(topLeft, QBrush(g));

        g = QRadialGradient(topRight.bottomLeft(), ShadowWidth_);
        setGradientColor(g);
        p.fillRect(topRight, QBrush(g));

        g = QRadialGradient(bottomLeft.topRight(), ShadowWidth_);
        setGradientColor(g);
        p.fillRect(bottomLeft, QBrush(g));

        g = QRadialGradient(bottomRight.topLeft(), ShadowWidth_);
        setGradientColor(g);
        p.fillRect(bottomRight, QBrush(g));
    }
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();
}
Esempio n. 3
0
void tst_QBrush::operator_eq_eq_data()
{
    QTest::addColumn<QBrush>("brush1");
    QTest::addColumn<QBrush>("brush2");
    QTest::addColumn<bool>("isEqual");

    QLinearGradient lg(10, 10, 100, 100);
    lg.setColorAt(0, Qt::red);
    lg.setColorAt(0.5, Qt::blue);
    lg.setColorAt(1, Qt::green);

    QTest::newRow("black vs black") << QBrush(Qt::black) << QBrush(Qt::black) << true;
    QTest::newRow("black vs blue") << QBrush(Qt::black) << QBrush(Qt::blue) << false;

    QTest::newRow("red vs no") << QBrush(Qt::red) << QBrush(Qt::NoBrush) << false;
    QTest::newRow("no vs no") << QBrush(Qt::NoBrush) << QBrush(Qt::NoBrush) << true;

    QTest::newRow("lg vs same lg") << QBrush(lg) << QBrush(lg) << true;
    QTest::newRow("lg vs diff lg") << QBrush(lg) << QBrush(QLinearGradient(QPoint(0, 0), QPoint(1, 1)))
                                   << false;

    QTest::newRow("rad vs con") << QBrush(QRadialGradient(0, 0, 0, 0, 0)) << QBrush(QConicalGradient(0, 0, 0)) << false;

    QBrush b1(lg);
    QBrush b2(lg);
    b1.setTransform(QTransform().scale(2, 2));
    QTest::newRow("lg with transform vs same lg") << b1 << b2 << false;

    b2.setTransform(QTransform().scale(2, 2));
    QTest::newRow("lg w/transform vs same lg w/same transform") << b1 << b2 << true;

}
Esempio n. 4
0
void GradientRenderer::paint(QPainter *p)
{
    QPolygonF pts = m_hoverPoints->points();

    QGradient g;

    if (m_gradientType == Qt::LinearGradientPattern) {
        g = QLinearGradient(pts.at(0), pts.at(1));

    } else if (m_gradientType == Qt::RadialGradientPattern) {
        g = QRadialGradient(pts.at(0), qMin(width(), height()) / 3.0, pts.at(1));

    } else {
        QLineF l(pts.at(0), pts.at(1));
        qreal angle = l.angle(QLineF(0, 0, 1, 0));
        if (l.dy() > 0)
            angle = 360 - angle;
        g = QConicalGradient(pts.at(0), angle);
    }

    for (int i=0; i<m_stops.size(); ++i)
        g.setColorAt(m_stops.at(i).first, m_stops.at(i).second);

    g.setSpread(m_spread);

    p->setBrush(g);
    p->setPen(Qt::NoPen);

    p->drawRect(rect());

}
Esempio n. 5
0
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();
}
WSOverlayScreenShotAnimation::WSOverlayScreenShotAnimation()
{
	setVisible(false);

	const HostInfo& info = HostBase::instance()->getInfo();
	int width = info.displayWidth;
	int height = info.displayHeight;

	setPos(width/2, height/2);

	int r = qMin(width, height);
	r = r/2;

	m_boundingRect = QRectF(-width/2, -height/2, width, height);
    m_gradient = QRadialGradient(0, 0, r, 0, 0);

	QGradientStops stops;
	stops.append(QGradientStop(0, QColor(0xFF,0xFF,0xFF,0xFF)));
	stops.append(QGradientStop(0.15, QColor(0xFF, 0xFF, 0xFF, 0xC0)));
	stops.append(QGradientStop(0.5, QColor(0xFF, 0xFF ,0xD0, 0xF0)));
	stops.append(QGradientStop(0.75, QColor(0xFF, 0xFF, 0xD0, 0x0F)));
	stops.append(QGradientStop(1.0,  QColor(0xFF, 0xFF, 0xD0, 0x00)));
	m_gradient.setStops(stops);

	connect(WindowServer::instance(), SIGNAL(signalAboutToTakeScreenShot()),
			SLOT(stop()));
	connect(WindowServer::instance(), SIGNAL(signalTookScreenShot()),
			SLOT(start()));
}
Esempio n. 7
0
QGradient GradientRangeEditor::gradient() const
{
	QGradient g;

	switch( gradientType )
	{
		case QGradient::LinearGradient:
			g = QLinearGradient( _startPoint, _endPoint );
			break;

		case QGradient::RadialGradient:
		{
			QLineF l( _startPoint, _endPoint );
			if( l.length() > 0.5 )
				l.setLength( 0.5 - 0.001 );
			g = QRadialGradient( l.p1(), 0.5, l.p2() );
			break;
		}

		default:
			g = QConicalGradient( _startPoint, angle() );
			break;
	}

	g.setStops( stops );
	g.setSpread( spreadType );
	return g;
}
Esempio n. 8
0
void KNProgressSlider::paintEvent(QPaintEvent *event)
{
    KNAbstractSlider::paintEvent(event);
    //Initial painter.
    QPainter painter(this);
    //Set antialiasing.
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setRenderHint(QPainter::TextAntialiasing, true);
    painter.setRenderHint(QPainter::SmoothPixmapTransform, true);

    //Using background opacity to draw the slider background.
    painter.setOpacity(m_backOpacity);

    //Set no pen
    painter.setPen(Qt::NoPen);

    //Draw central rects.
    painter.setBrush(m_rectColor);
    painter.drawRect(m_glowWidth,
                     m_glowWidth+m_spacing,
                     width()-(m_glowWidth<<1),
                     m_sliderHeight);

    //If range is not 0, draw the button.
    if(range()>0)
    {
        //Restore the opacity.
        painter.setOpacity(1.0);

        //Get the current position.
        int positionLeft=percentage()*(float)(width()-m_buttonSize);
        //Paint the rect.
        painter.setBrush(m_buttonColor);
        painter.drawRect(m_glowWidth,
                         m_glowWidth+m_spacing,
                         positionLeft,
                         m_sliderHeight);


        //Draw the circle button.
        painter.save();
        //Calculate position.
        painter.translate(positionLeft,
                          m_spacing);
        //Set the gradient.
        int buttonCenter=m_glowWidth+(m_sliderHeight>>1);
        QRadialGradient buttonGradient=QRadialGradient(QPointF(buttonCenter, buttonCenter),
                                                       buttonCenter,
                                                       QPointF(buttonCenter, buttonCenter));
        buttonGradient.setColorAt(0, QColor(255,255,255,200));
        buttonGradient.setColorAt(1, QColor(255,255,255,0));
        painter.setBrush(buttonGradient);
        painter.drawEllipse(0,0,height(),height());
        //Set the color.
        painter.setBrush(m_backgroundColor);
        painter.drawEllipse(m_glowWidth-1, m_glowWidth-1, m_sliderHeight+2, m_sliderHeight+2);
        //Restore transform.
        painter.restore();
    }
Esempio n. 9
0
void Power::resizePainter()
{

    h = this->size().height() - framed;//开关矩形高度
    pieR = h/2;//开关两边半圆半径
    w = this->size().width() - framed - pieR*2;//开关矩形宽度
    if(checked)
        rd = 0;
    else
        rd = w;
    //外框矩形
    wRect = QRect(0,0,this->size().width(),this->size().height());
    round = wRect.height()/2;
    //开关矩形
    rect = QRect(framed/2 + pieR,framed/2,w,h);
    //开关半圆弧
    pieON = QPoint(rect.x() + w,rect.y() + pieR);
    pieOFF =  QPoint(rect.x(),rect.y() + pieR);

    //开启的渐变颜色  自己DIY
    linearON = QLinearGradient(rect.topLeft(),rect.bottomLeft());
    linearON.setColorAt(0,QColor(159, 55, 2));
    linearON.setColorAt(0.2,QColor(223, 89, 0));
    linearON.setColorAt(0.5,QColor(235, 97, 0));
    linearON.setColorAt(0.8,QColor(233, 89, 0));
    linearON.setColorAt(1,QColor(159, 55, 2));

    radialON = QRadialGradient(pieON,pieR);
    radialON.setColorAt(0,QColor(235, 97, 0));
    radialON.setColorAt(0.55,QColor(233, 89, 0));
    radialON.setColorAt(1,QColor(159, 55, 2));

    //关闭按钮的渐变颜色
    linearOFF = QLinearGradient(rect.topLeft(),rect.bottomLeft());
    linearOFF.setColorAt(0,QColor(56, 56, 56));
    linearOFF.setColorAt(0.2,QColor(85, 85, 85));
    linearOFF.setColorAt(0.5,QColor(93, 93, 93));
    linearOFF.setColorAt(0.8,QColor(85, 85, 85));
    linearOFF.setColorAt(1,QColor(56, 56, 56));

    radialOFF = QRadialGradient(pieOFF,pieR);
    radialOFF.setColorAt(0,QColor(93, 93, 93));
    radialOFF.setColorAt(0.6,QColor(85, 85, 85));
    radialOFF.setColorAt(1,QColor(56, 56, 56));

}
Esempio n. 10
0
EmbedWidget::EmbedWidget(QWidget *parent)
    : QX11EmbedWidget(parent)
{
    gradient = QRadialGradient(100, 100, 90, 60, 60);
    gradient.setColorAt(0.0, Qt::white);
    gradient.setColorAt(0.9, QColor(192, 192, 255));
    gradient.setColorAt(1.0, QColor(0, 32, 64));
}
CQJCanvasRadialGradient::
CQJCanvasRadialGradient(CJavaScript *js, double x1, double y1, double r1,
                        double x2, double y2, double r2) :
 CJObj(js, CQJCanvasRadialGradientType::instance(js))
{
  objType_->addObjFunction(js, "addColorStop", objType_);

  rg_ = QRadialGradient(x2, y2, r2, x1, y1, r1);
}
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);
}
Esempio n. 13
0
void tst_QBrush::stream_data()
{
    QTest::addColumn<QBrush>("brush");

    QLinearGradient lg(10, 10, 100, 100);
    lg.setColorAt(0, Qt::red);
    lg.setColorAt(0.5, Qt::blue);
    lg.setColorAt(1, Qt::green);

    QTest::newRow("black") << QBrush(Qt::black);
    QTest::newRow("red") << QBrush(Qt::red);
    QTest::newRow("no") << QBrush(Qt::NoBrush);
    QTest::newRow("lg") << QBrush(lg);
    QTest::newRow("rad") << QBrush(QRadialGradient(0, 0, 0, 0, 0));
    QTest::newRow("con") << QBrush(QConicalGradient(0, 0, 0));
}
Esempio n. 14
0
void ZLamp::Dimension()
{
  // Bezel width
  bezelWidth = bezelRect.height()/12;

  // Lamp bounding rectangle
  lampRect=bezelRect.adjusted(bezelWidth, bezelWidth, -bezelWidth, -bezelWidth);

  // Bezel shading
  bezelGradient = QLinearGradient(bezelRect.topRight(), bezelRect.bottomLeft());
  bezelGradient.setColorAt(0.0, QColor(Qt::darkGray));
  bezelGradient.setColorAt(1.0, QColor(Qt::black));

  lampRadius = bezelWidth * lampRect.width()/bezelRect.width();

  // Lamp "Bright spot"
  lampGradient = QRadialGradient(lampRect.center(), 2);
  lampGradient.setSpread(QGradient::ReflectSpread);

  lampFont = QFont("Arial", lampRect.height()*0.6, QFont::DemiBold);
}
Esempio n. 15
0
void StyleLoader::loadComposite(QRadialGradient& value)
{
	int coordinateMode;
	int spread;
	QPointF center;
	QPointF focal;
	double radius;
	QGradientStops stopPoints;

	load("coordinateMode", coordinateMode);
	load("spread", spread);
	load("centerPoint", center);
	load("focalPoint", focal);
	load("radius", radius);
	load("stopPoints", stopPoints);

	value = QRadialGradient(center, radius, focal);
	value.setSpread((QGradient::Spread) spread);
	value.setCoordinateMode((QGradient::CoordinateMode) coordinateMode);
	value.setStops(stopPoints);
}
Esempio n. 16
0
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));
}
StyleWidget::StyleWidget(QWidget *parent)
        : QWidget(parent)
{
    solid = new RenderArea(new QBrush(Qt::SolidPattern));
    dense1 = new RenderArea(new QBrush(Qt::Dense1Pattern));
    dense2 = new RenderArea(new QBrush(Qt::Dense2Pattern));
    dense3 = new RenderArea(new QBrush(Qt::Dense3Pattern));
    dense4 = new RenderArea(new QBrush(Qt::Dense4Pattern));
    dense5 = new RenderArea(new QBrush(Qt::Dense5Pattern));
    dense6 = new RenderArea(new QBrush(Qt::Dense6Pattern));
    dense7 = new RenderArea(new QBrush(Qt::Dense7Pattern));
    no = new RenderArea(new QBrush(Qt::NoBrush));
    hor = new RenderArea(new QBrush(Qt::HorPattern));
    ver = new RenderArea(new QBrush(Qt::VerPattern));
    cross = new RenderArea(new QBrush(Qt::CrossPattern));
    bdiag = new RenderArea(new QBrush(Qt::BDiagPattern));
    fdiag = new RenderArea(new QBrush(Qt::FDiagPattern));
    diagCross = new RenderArea(new QBrush(Qt::DiagCrossPattern));
    linear = new RenderArea(new QBrush(QLinearGradient()));
    radial = new RenderArea(new QBrush(QRadialGradient()));
    conical = new RenderArea(new QBrush(QConicalGradient()));
    texture = new RenderArea(new QBrush(QPixmap("qt-logo.png")));

    solidLabel = new QLabel("Qt::SolidPattern");
    dense1Label = new QLabel("Qt::Dense1Pattern");
    dense2Label = new QLabel("Qt::Dense2Pattern");
    dense3Label = new QLabel("Qt::Dense3Pattern");
    dense4Label = new QLabel("Qt::Dense4Pattern");
    dense5Label = new QLabel("Qt::Dense5Pattern");
    dense6Label = new QLabel("Qt::Dense6Pattern");
    dense7Label = new QLabel("Qt::Dense7Pattern");
    noLabel = new QLabel("Qt::NoPattern");
    horLabel = new QLabel("Qt::HorPattern");
    verLabel = new QLabel("Qt::VerPattern");
    crossLabel = new QLabel("Qt::CrossPattern");
    bdiagLabel = new QLabel("Qt::BDiagPattern");
    fdiagLabel = new QLabel("Qt::FDiagPattern");
    diagCrossLabel = new QLabel("Qt::DiagCrossPattern");
    linearLabel = new QLabel("Qt::LinearGradientPattern");
    radialLabel = new QLabel("Qt::RadialGradientPattern");
    conicalLabel = new QLabel("Qt::ConicalGradientPattern");
    textureLabel = new QLabel("Qt::TexturePattern");

    QGridLayout *layout = new QGridLayout;
    layout->addWidget(solid, 0, 0);
    layout->addWidget(dense1, 0, 1);
    layout->addWidget(dense2, 0, 2);
    layout->addWidget(solidLabel, 1, 0);
    layout->addWidget(dense1Label, 1, 1);
    layout->addWidget(dense2Label, 1, 2);

    layout->addWidget(dense3, 2, 0 );
    layout->addWidget(dense4, 2, 1);
    layout->addWidget(dense5, 2, 2);
    layout->addWidget(dense3Label, 3, 0);
    layout->addWidget(dense4Label, 3, 1);
    layout->addWidget(dense5Label, 3, 2);

    layout->addWidget(dense6, 4, 0);
    layout->addWidget(dense7, 4, 1);
    layout->addWidget(no, 4, 2);
    layout->addWidget(dense6Label, 5, 0);
    layout->addWidget(dense7Label, 5, 1);
    layout->addWidget(noLabel, 5, 2);

    layout->addWidget(hor, 6, 0);
    layout->addWidget(ver, 6, 1);
    layout->addWidget(cross, 6, 2);
    layout->addWidget(horLabel, 7, 0);
    layout->addWidget(verLabel, 7, 1);
    layout->addWidget(crossLabel, 7, 2);

    layout->addWidget(bdiag, 8, 0);
    layout->addWidget(fdiag, 8, 1);
    layout->addWidget(diagCross, 8, 2);
    layout->addWidget(bdiagLabel, 9, 0);
    layout->addWidget(fdiagLabel, 9, 1);
    layout->addWidget(diagCrossLabel, 9, 2);

    layout->addWidget(linear, 10, 0);
    layout->addWidget(radial, 10, 1);
    layout->addWidget(conical, 10, 2);
    layout->addWidget(linearLabel, 11, 0);
    layout->addWidget(radialLabel, 11, 1);
    layout->addWidget(conicalLabel, 11, 2);

    layout->addWidget(texture, 12, 0, 1, 3);
    layout->addWidget(textureLabel, 13, 0, 1, 3);

    setLayout(layout);

    QPalette newPalette = palette();
    newPalette.setColor(QPalette::Window, Qt::white);
    setPalette(newPalette);

    setWindowTitle(tr("Brush Styles"));
    resize(430, 605);
}
Esempio n. 18
0
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!                       */
    }

}
Esempio n. 19
0
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();
}
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
    bool ok;
    QGradient gradient = QtGradientDialog::getGradient(&ok, QRadialGradient(), this);
    if (ok) {
        // the user clicked OK and gradient is set to the gradient the user selected
    } else {
        // the user canceled the dialog; gradient is set to the initial
        // value, in this case radial gradient
    }
//! [0]


//! [1]
    bool detailsVisible;
    QColor::Spec spec;
    QGradient gradient;

    QtGradientDialog dlg(this);
Esempio n. 21
0
LensDialog::LensDialog(QWidget* parent, ScribusDoc *doc) : QDialog(parent)
{
	setupUi(this);
	buttonRemove->setEnabled(false);
	setModal(true);
	buttonZoomOut->setIcon(QIcon(loadIcon("16/zoom-out.png")));
	buttonZoomI->setIcon(QIcon(loadIcon("16/zoom-in.png")));

	PageItem *currItem;
	double gx, gy, gh, gw;
	doc->m_Selection->setGroupRect();
	doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
	uint selectedItemCount = doc->m_Selection->count();
	QStack<PageItem*> groupStack;
	QStack<QGraphicsPathItem*> groupStack2;
	QStack<PageItem*> groupStack3;
	groupStack2.push(0);
	for (uint i = 0; i < selectedItemCount; ++i)
	{
		currItem = doc->m_Selection->itemAt(i);
		FPointArray path = currItem->PoLine;
		QPainterPath pp;
		if (currItem->itemType() == PageItem::PolyLine)
			pp = path.toQPainterPath(false);
		else
			pp = path.toQPainterPath(true);
		origPath.append(pp);
		QGraphicsPathItem* pItem = new QGraphicsPathItem(pp, groupStack2.top());
		if (groupStack2.top() == 0)
		{
			scene.addItem(pItem);
			pItem->setPos(currItem->xPos() - gx, currItem->yPos() - gy);
			pItem->rotate(currItem->rotation());
		}
		else
		{
			PageItem* parent = groupStack3.top();
			QMatrix mm;
			mm.rotate(-parent->rotation());
			mm.translate(-parent->xPos(), -parent->yPos());
			pItem->setPos(mm.map(QPointF(currItem->xPos(), currItem->yPos())));
		}
		pItem->setZValue(i);
		origPathItem.append(pItem);
		if (((currItem->fillColor() == CommonStrings::None) && (currItem->GrType == 0)) || (currItem->controlsGroup()))
			pItem->setBrush(Qt::NoBrush);
		else
		{
			if (currItem->GrType != 0)
			{
				if (currItem->GrType != 8)
				{
					QGradient pat;
					double x1 = currItem->GrStartX;
					double y1 = currItem->GrStartY;
					double x2 = currItem->GrEndX;
					double y2 = currItem->GrEndY;
					switch (currItem->GrType)
					{
						case 1:
						case 2:
						case 3:
						case 4:
						case 6:
							pat = QLinearGradient(x1, y1,  x2, y2);
							break;
						case 5:
						case 7:
							pat = QRadialGradient(x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)), x1, y1);
							break;
					}
					QList<VColorStop*> colorStops = currItem->fill_gradient.colorStops();
					QColor qStopColor;
					for( int offset = 0 ; offset < colorStops.count() ; offset++ )
					{
						qStopColor = colorStops[ offset ]->color;
						int h, s, v, sneu, vneu;
						int shad = colorStops[offset]->shade;
						qStopColor.getHsv(&h, &s, &v);
						sneu = s * shad / 100;
						vneu = 255 - ((255 - v) * shad / 100);
						qStopColor.setHsv(h, sneu, vneu);
						qStopColor.setAlphaF(colorStops[offset]->opacity);
						pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor);
					}
					pItem->setBrush(pat);
				}
				else if ((currItem->GrType == 8) && (!currItem->pattern().isEmpty()) && (doc->docPatterns.contains(currItem->pattern())))
				{
					double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation;
					currItem->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
					QMatrix qmatrix;
					qmatrix.translate(patternOffsetX, patternOffsetY);
					qmatrix.rotate(patternRotation);
					qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0);
					QImage pat = *doc->docPatterns[currItem->pattern()].getPattern();
					QBrush brush = QBrush(pat);
					brush.setMatrix(qmatrix);
					pItem->setBrush(brush);
				}
			}
			else
			{
				QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->fillColor()], doc, currItem->fillShade());
				paint.setAlphaF(1.0 - currItem->fillTransparency());
				pItem->setBrush(paint);
			}
		}
		if ((currItem->lineColor() == CommonStrings::None) || (currItem->controlsGroup()))
			pItem->setPen(Qt::NoPen);
		else
		{
			QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->lineColor()], doc, currItem->lineShade());
			paint.setAlphaF(1.0 - currItem->lineTransparency());
			pItem->setPen(QPen(paint, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin()));
		}
		if (currItem->controlsGroup())
		{
			groupStack.push(currItem->groupsLastItem);
			groupStack2.push(pItem);
			groupStack3.push(currItem);
			pItem->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
		}
		if (groupStack.count() != 0)
		{
			while (currItem == groupStack.top())
			{
				groupStack3.pop();
				groupStack2.pop();
				groupStack.pop();
				if (groupStack.count() == 0)
					break;
			}
		}
	}

	previewWidget->setRenderHint(QPainter::Antialiasing);
	previewWidget->setScene(&scene);
	isFirst = true;
	addLens();
	connect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
	connect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
	connect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double)));
	connect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double)));
	connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addLens()));
	connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removeLens()));
	connect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens()));
	connect(buttonZoomI, SIGNAL(clicked()), this, SLOT(doZoomIn()));
	connect(buttonZoomOut, SIGNAL(clicked()), this, SLOT(doZoomOut()));
	connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
	connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
	connect(&scene, SIGNAL(selectionChanged()), this, SLOT(selectionHasChanged()));
}
Esempio n. 22
0
    }
}

QColor RobotBase::m_directionLineColor=QColor(98, 228, 238);

QColor RobotBase::directionLineColor()
{
    return m_directionLineColor;
}

void RobotBase::setDirectionLineColor(const QColor &detectLineColor)
{
    m_directionLineColor = detectLineColor;
}

QRadialGradient RobotBase::m_detectRadiusGradient=QRadialGradient();

void RobotBase::initialRobotPatameters()
{
    //Initial the detected radius gradient.
    m_detectRadiusGradient.setRadius(m_detectRadius);
    m_detectRadiusGradient.setColorAt(0, QColor(0,0,0,0));
    m_detectRadiusGradient.setColorAt(0.6, QColor(0,0,0,0));
    m_detectRadiusGradient.setColorAt(1, m_detectRadiusColor);

    //Initial the enemy detected radius gradient.
    m_enemyRadiusGradient.setRadius(m_detectRadius);
    m_enemyRadiusGradient.setColorAt(0, QColor(0,0,0,0));
    m_enemyRadiusGradient.setColorAt(0.6, QColor(0,0,0,0));
    m_enemyRadiusGradient.setColorAt(1, m_enemyRadiusColor);
}