QColorLuminancePicker Class Reference

Inheritance diagram for QColorLuminancePicker:

Inheritance graph
[legend]
Collaboration diagram for QColorLuminancePicker:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 650 of file qcolordialog.cpp.

Public Slots

void setCol (int h, int s, int v)
void setCol (int h, int s)

Signals

void newHsv (int h, int s, int v)

Public Member Functions

 QColorLuminancePicker (QWidget *parent=0)
 ~QColorLuminancePicker ()

Protected Member Functions

void paintEvent (QPaintEvent *)
void mouseMoveEvent (QMouseEvent *)
void mousePressEvent (QMouseEvent *)

Private Types

enum  

Private Member Functions

int y2val (int y)
int val2y (int val)
void setVal (int v)

Private Attributes

int val
int hue
int sat
QPixmappix


Member Enumeration Documentation

anonymous enum [private]

Definition at line 670 of file qcolordialog.cpp.

00670 { foff = 3, coff = 4 }; //frame and contents offset


Constructor & Destructor Documentation

QColorLuminancePicker::QColorLuminancePicker ( QWidget parent = 0  ) 

Definition at line 695 of file qcolordialog.cpp.

References hue, pix, sat, and val.

00696     :QWidget(parent)
00697 {
00698     hue = 100; val = 100; sat = 100;
00699     pix = 0;
00700     //    setAttribute(WA_NoErase, true);
00701 }

QColorLuminancePicker::~QColorLuminancePicker (  ) 

Definition at line 703 of file qcolordialog.cpp.

References pix.

00704 {
00705     delete pix;
00706 }


Member Function Documentation

void QColorLuminancePicker::setCol ( int  h,
int  s,
int  v 
) [slot]

Definition at line 768 of file qcolordialog.cpp.

References hue, pix, QWidget::repaint(), sat, and val.

Referenced by QColorDialogPrivate::_q_newColorTypedIn(), QColorDialogPrivate::_q_newHsv(), and setCol().

00769 {
00770     val = v;
00771     hue = h;
00772     sat = s;
00773     delete pix; pix=0;
00774     repaint();
00775 }

void QColorLuminancePicker::setCol ( int  h,
int  s 
) [slot]

Definition at line 728 of file qcolordialog.cpp.

References emit, newHsv(), setCol(), and val.

00729 {
00730     setCol(h, s, val);
00731     emit newHsv(h, s, val);
00732 }

void QColorLuminancePicker::newHsv ( int  h,
int  s,
int  v 
) [signal]

Referenced by setCol(), and setVal().

void QColorLuminancePicker::paintEvent ( QPaintEvent  )  [protected, virtual]

This event handler can be reimplemented in a subclass to receive paint events which are passed in the event parameter.

A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.

Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example.

Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). repaint() does not permit this optimization, so we suggest using update() whenever possible.

When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background.

The background can be set using setBackgroundRole() and setPalette().

From Qt 4.0, QWidget automatically double-buffers its painting, so there's no need to write double-buffering code in paintEvent() to avoid flicker.

Note: Under X11 it is possible to toggle the global double buffering by calling qt_x11_set_global_double_buffer(). Example usage:

See also:
event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, {Analog Clock Example}

Reimplemented from QWidget.

Definition at line 734 of file qcolordialog.cpp.

References a, c, coff, foff, QImage::Format_RGB32, QPixmap::fromImage(), g, QWidget::height(), QPixmap::height(), QRect::height(), hue, p, QWidget::palette(), pix, qDrawShadePanel(), QWidget::QPixmap, QRgb, sat, QImage::setPixel(), val, val2y(), w, QRect::width(), QPixmap::width(), QWidget::width(), QWidget::x(), QWidget::y(), and y2val().

00735 {
00736     int w = width() - 5;
00737 
00738     QRect r(0, foff, w, height() - 2*foff);
00739     int wi = r.width() - 2;
00740     int hi = r.height() - 2;
00741     if (!pix || pix->height() != hi || pix->width() != wi) {
00742         delete pix;
00743         QImage img(wi, hi, QImage::Format_RGB32);
00744         int y;
00745         for (y = 0; y < hi; y++) {
00746             QColor c;
00747             c.setHsv(hue, sat, y2val(y+coff));
00748             QRgb r = c.rgb();
00749             int x;
00750             for (x = 0; x < wi; x++)
00751                 img.setPixel(x, y, r);
00752         }
00753         pix = new QPixmap(QPixmap::fromImage(img));
00754     }
00755     QPainter p(this);
00756     p.drawPixmap(1, coff, *pix);
00757     const QPalette &g = palette();
00758     qDrawShadePanel(&p, r, g, true);
00759     p.setPen(g.foreground().color());
00760     p.setBrush(g.foreground());
00761     QPolygon a;
00762     int y = val2y(val);
00763     a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
00764     p.eraseRect(w, 0, 5, height());
00765     p.drawPolygon(a);
00766 }

Here is the call graph for this function:

void QColorLuminancePicker::mouseMoveEvent ( QMouseEvent m  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget.

If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.

QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.

See also:
setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented from QWidget.

Definition at line 708 of file qcolordialog.cpp.

References m, setVal(), and y2val().

00709 {
00710     setVal(y2val(m->y()));
00711 }

Here is the call graph for this function:

void QColorLuminancePicker::mousePressEvent ( QMouseEvent m  )  [protected, virtual]

This event handler, for event event, can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

See also:
mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent, {Scribble Example}

Reimplemented from QWidget.

Definition at line 712 of file qcolordialog.cpp.

References m, setVal(), and y2val().

00713 {
00714     setVal(y2val(m->y()));
00715 }

Here is the call graph for this function:

int QColorLuminancePicker::y2val ( int  y  )  [private]

Definition at line 683 of file qcolordialog.cpp.

References coff, d, and QWidget::height().

Referenced by mouseMoveEvent(), mousePressEvent(), and paintEvent().

00684 {
00685     int d = height() - 2*coff - 1;
00686     return 255 - (y - coff)*255/d;
00687 }

Here is the call graph for this function:

int QColorLuminancePicker::val2y ( int  val  )  [private]

Definition at line 689 of file qcolordialog.cpp.

References coff, d, and QWidget::height().

Referenced by paintEvent().

00690 {
00691     int d = height() - 2*coff - 1;
00692     return coff + (255-v)*d/255;
00693 }

Here is the call graph for this function:

void QColorLuminancePicker::setVal ( int  v  )  [private]

Definition at line 717 of file qcolordialog.cpp.

References emit, hue, newHsv(), pix, qMax(), qMin(), QWidget::repaint(), sat, and val.

Referenced by mouseMoveEvent(), and mousePressEvent().

00718 {
00719     if (val == v)
00720         return;
00721     val = qMax(0, qMin(v,255));
00722     delete pix; pix=0;
00723     repaint();
00724     emit newHsv(hue, sat, val);
00725 }

Here is the call graph for this function:


Member Data Documentation

int QColorLuminancePicker::val [private]

Definition at line 671 of file qcolordialog.cpp.

Referenced by paintEvent(), QColorLuminancePicker(), setCol(), and setVal().

int QColorLuminancePicker::hue [private]

Definition at line 672 of file qcolordialog.cpp.

Referenced by paintEvent(), QColorLuminancePicker(), setCol(), and setVal().

int QColorLuminancePicker::sat [private]

Definition at line 673 of file qcolordialog.cpp.

Referenced by paintEvent(), QColorLuminancePicker(), setCol(), and setVal().

QPixmap* QColorLuminancePicker::pix [private]

Definition at line 679 of file qcolordialog.cpp.

Referenced by paintEvent(), QColorLuminancePicker(), setCol(), setVal(), and ~QColorLuminancePicker().


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