GradientEditor Class Reference

#include <gradients.h>

Inheritance diagram for GradientEditor:

Inheritance graph
[legend]
Collaboration diagram for GradientEditor:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 70 of file gradients.h.

Public Slots

void pointsUpdated ()

Signals

void gradientStopsChanged (const QGradientStops &stops)

Public Member Functions

 GradientEditor (QWidget *parent)
void setGradientStops (const QGradientStops &stops)

Private Attributes

ShadeWidgetm_red_shade
ShadeWidgetm_green_shade
ShadeWidgetm_blue_shade
ShadeWidgetm_alpha_shade


Constructor & Destructor Documentation

GradientEditor::GradientEditor ( QWidget parent  ) 

Definition at line 157 of file gradients.cpp.

References QBoxLayout::addWidget(), ShadeWidget::ARGBShade, ShadeWidget::BlueShade, QObject::connect(), ShadeWidget::GreenShade, m_alpha_shade, m_blue_shade, m_green_shade, m_red_shade, pointsUpdated(), ShadeWidget::RedShade, QLayout::setMargin(), QLayout::setSpacing(), SIGNAL, and SLOT.

00158     : QWidget(parent)
00159 {
00160     QVBoxLayout *vbox = new QVBoxLayout(this);
00161     vbox->setSpacing(1);
00162     vbox->setMargin(1);
00163 
00164     m_red_shade = new ShadeWidget(ShadeWidget::RedShade, this);
00165     m_green_shade = new ShadeWidget(ShadeWidget::GreenShade, this);
00166     m_blue_shade = new ShadeWidget(ShadeWidget::BlueShade, this);
00167     m_alpha_shade = new ShadeWidget(ShadeWidget::ARGBShade, this);
00168 
00169     vbox->addWidget(m_red_shade);
00170     vbox->addWidget(m_green_shade);
00171     vbox->addWidget(m_blue_shade);
00172     vbox->addWidget(m_alpha_shade);
00173 
00174     connect(m_red_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
00175     connect(m_green_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
00176     connect(m_blue_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
00177     connect(m_alpha_shade, SIGNAL(colorsChanged()), this, SLOT(pointsUpdated()));
00178 }

Here is the call graph for this function:


Member Function Documentation

void GradientEditor::setGradientStops ( const QGradientStops stops  ) 

Definition at line 231 of file gradients.cpp.

References QVector< T >::at(), QWidget::height(), i, m_alpha_shade, m_blue_shade, m_green_shade, m_red_shade, QWidget::pos(), qAlpha(), qBlue(), qGreen(), qRed(), QRgb, set_shade_points(), QVector< T >::size(), and QWidget::width().

Referenced by GradientWidget::setDefault().

00232 {
00233     QPolygonF pts_red, pts_green, pts_blue, pts_alpha;
00234 
00235     double h_red = m_red_shade->height();
00236     double h_green = m_green_shade->height();
00237     double h_blue = m_blue_shade->height();
00238     double h_alpha = m_alpha_shade->height();
00239 
00240     for (int i=0; i<stops.size(); ++i) {
00241         double pos = stops.at(i).first;
00242         QRgb color = stops.at(i).second.rgba();
00243         pts_red << QPointF(pos * m_red_shade->width(), h_red - qRed(color) * h_red / 255);
00244         pts_green << QPointF(pos * m_green_shade->width(), h_green - qGreen(color) * h_green / 255);
00245         pts_blue << QPointF(pos * m_blue_shade->width(), h_blue - qBlue(color) * h_blue / 255);
00246         pts_alpha << QPointF(pos * m_alpha_shade->width(), h_alpha - qAlpha(color) * h_alpha / 255);
00247     }
00248 
00249     set_shade_points(pts_red, m_red_shade);
00250     set_shade_points(pts_green, m_green_shade);
00251     set_shade_points(pts_blue, m_blue_shade);
00252     set_shade_points(pts_alpha, m_alpha_shade);
00253 
00254 }

Here is the call graph for this function:

void GradientEditor::pointsUpdated (  )  [slot]

Definition at line 187 of file gradients.cpp.

References QVector< T >::at(), QVector< T >::begin(), ShadeWidget::colorAt(), emit, QVector< T >::end(), gradientStopsChanged(), i, m_alpha_shade, m_blue_shade, m_green_shade, m_red_shade, ShadeWidget::points(), qSort(), ShadeWidget::setGradientStops(), QVector< T >::size(), w, QWidget::width(), QPointF::x(), QWidget::x(), and x_less_than().

Referenced by GradientEditor().

00188 {
00189     double w = m_alpha_shade->width();
00190 
00191     QGradientStops stops;
00192 
00193     QPolygonF points;
00194 
00195     points += m_red_shade->points();
00196     points += m_green_shade->points();
00197     points += m_blue_shade->points();
00198     points += m_alpha_shade->points();
00199 
00200     qSort(points.begin(), points.end(), x_less_than);
00201 
00202     for (int i=0; i<points.size(); ++i) {
00203         double x = int(points.at(i).x());
00204         if (i < points.size() - 1 && x == points.at(i+1).x())
00205             continue;
00206         QColor color((0x00ff0000 & m_red_shade->colorAt(int(x))) >> 16,
00207                      (0x0000ff00 & m_green_shade->colorAt(int(x))) >> 8,
00208                      (0x000000ff & m_blue_shade->colorAt(int(x))),
00209                      (0xff000000 & m_alpha_shade->colorAt(int(x))) >> 24);
00210 
00211         if (x / w > 1)
00212             return;
00213 
00214         stops << QGradientStop(x / w, color);
00215     }
00216 
00217     m_alpha_shade->setGradientStops(stops);
00218 
00219     emit gradientStopsChanged(stops);
00220 }

void GradientEditor::gradientStopsChanged ( const QGradientStops stops  )  [signal]

Referenced by pointsUpdated().


Member Data Documentation

ShadeWidget* GradientEditor::m_red_shade [private]

Definition at line 85 of file gradients.h.

Referenced by GradientEditor(), pointsUpdated(), and setGradientStops().

ShadeWidget* GradientEditor::m_green_shade [private]

Definition at line 86 of file gradients.h.

Referenced by GradientEditor(), pointsUpdated(), and setGradientStops().

ShadeWidget* GradientEditor::m_blue_shade [private]

Definition at line 87 of file gradients.h.

Referenced by GradientEditor(), pointsUpdated(), and setGradientStops().

ShadeWidget* GradientEditor::m_alpha_shade [private]

Definition at line 88 of file gradients.h.

Referenced by GradientEditor(), pointsUpdated(), and setGradientStops().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 15:01:52 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1