src/GradientRenderer.cpp

Go to the documentation of this file.
00001 #include "GradientRenderer.h"
00002 
00003 GradientRenderer::GradientRenderer(QWidget *parent): QWidget(parent)
00004 {
00005     printf("creating GradientRenderer\n");
00006 
00007 //HACK: NOT EDITABLE - only show Gradient
00008 //    m_hoverPoints = new HoverPoints(this, HoverPoints::CircleShape);
00009 //    m_hoverPoints->setPointSize(QSize(0, 0));
00010 //    m_hoverPoints->setConnectionType(HoverPoints::NoConnection);
00011 //    m_hoverPoints->setEditable(false);
00012 //
00013 //    QVector<QPointF> points;
00014 //    //points << QPointF(100, 100) << QPointF(200, 200);
00015 //    points << QPointF(0, sizeHint().height()/2) << QPointF(sizeHint().width(), sizeHint().height()/2);
00016 //    m_hoverPoints->setPoints(points);
00017 
00018     m_spread = QGradient::PadSpread;
00019     m_gradientType = Qt::LinearGradientPattern;
00020 }
00021 
00022 void GradientRenderer::paintEvent(QPaintEvent *event)
00023 {
00024   QPainter painter;
00025   painter.begin(this);
00026     painter.setRenderHint(QPainter::Antialiasing);
00027     paint(&painter);
00028   painter.end();
00029 }
00030 
00031 void GradientRenderer::setGradientStops(const QGradientStops &stops)
00032 {
00033     m_stops = stops;
00034     update();
00035 }
00036 
00037 
00038 void GradientRenderer::paint(QPainter *p)
00039 {
00040     QPalette pal = palette(); 
00041     pal.setBrush( backgroundRole(), QBrush(QColor( Qt::black )) );
00042     setAutoFillBackground( true ); 
00043     setPalette( pal );
00044   
00045     QPolygonF pts;// = m_hoverPoints->points();
00046 
00047     // start and stop of gradient
00048     pts << QPointF(0.0, (float) rect().height() / 2) << QPointF((float) rect().width(), (float) rect().height() / 2);
00049 
00050     QGradient g;
00051 
00052     //if (m_gradientType == Qt::LinearGradientPattern) 
00053     //{
00054         g = QLinearGradient(pts.at(0), pts.at(1));
00055     //} 
00056     //else if (m_gradientType == Qt::RadialGradientPattern) 
00057     //{
00058     //    QLineF line(pts.at(0), pts.at(1));
00059     //    if (line.length() > 132)
00060     //        line.setLength(132);
00061     //    g = QRadialGradient(line.p1(), qMin(width(), height()) / 3.0, line.p2());
00062     //} else {
00063     //    QLineF l(pts.at(0), pts.at(1));
00064     //    double angle = l.angle(QLineF(0, 0, 1, 0));
00065     //    if (l.dy() > 0)
00066     //        angle = 360 - angle;
00067     //    g = QConicalGradient(pts.at(0), angle);
00068     //}
00069 
00070     for (int i=0; i<m_stops.size(); ++i)
00071     {
00072       g.setColorAt( m_stops.at(i).first, m_stops.at(i).second );
00073     }
00074 
00075     g.setSpread(m_spread);
00076 
00077     p->setBrush(g);
00078     p->setPen(Qt::NoPen);
00079 
00080     p->drawRect(rect());
00081 }

Generated on Mon Dec 10 18:18:11 2007 for VisLU by  doxygen 1.5.4