Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ColorPicker Class Reference

#include <wizard.h>

Inheritance diagram for ColorPicker:

Public Types

enum  Mode { Hue, Saturation, Gamma }
 

Public Slots

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

Signals

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

Public Member Functions

 ColorPicker (Mode m)
 
 ~ColorPicker ()
 

Protected Member Functions

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

Private Types

enum  { foff = 3, coff = 4 }
 

Private Member Functions

int y2hue (int y)
 
int y2sat (int y)
 
int y2gam (int y)
 
int hue2y (int hue)
 
int sat2y (int sat)
 
int gam2y (int gamma)
 
void setHue (int v)
 
void setSat (int v)
 
void setGam (int v)
 

Private Attributes

QPixmap * m_pix
 
Mode m_mode
 
int m_gam
 
int m_hue
 
int m_sat
 

Detailed Description

Definition at line 62 of file wizard.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
foff 
coff 

Definition at line 83 of file wizard.h.

83 { foff = 3, coff = 4 }; //frame and contents offset
Enumerator
Hue 
Saturation 
Gamma 

Definition at line 66 of file wizard.h.

Constructor & Destructor Documentation

ColorPicker::ColorPicker ( Mode  m)

Definition at line 313 of file wizard.cpp.

314 {
315  m_hue = 220;
316  m_gam = 100;
317  m_sat = 100;
318  m_mode = m;
319  m_pix = 0;
320 }
int m_gam
Definition: wizard.h:96
Mode m_mode
Definition: wizard.h:95
int m_hue
Definition: wizard.h:97
int m_sat
Definition: wizard.h:98
QPixmap * m_pix
Definition: wizard.h:94
ColorPicker::~ColorPicker ( )

Definition at line 322 of file wizard.cpp.

323 {
324  delete m_pix;
325 }
QPixmap * m_pix
Definition: wizard.h:94

Member Function Documentation

int ColorPicker::gam2y ( int  gamma)
private

Definition at line 454 of file wizard.cpp.

455 {
456  int d = height() - 2*coff - 1;
457  return coff + (240-g)*d/200;
458 }
static constexpr double g
Definition: Units.h:144
int ColorPicker::hue2y ( int  hue)
private

Definition at line 430 of file wizard.cpp.

431 {
432  int d = height() - 2*coff - 1;
433  return coff + v*d/359;
434 }
void ColorPicker::mouseMoveEvent ( QMouseEvent *  m)
protected

Definition at line 371 of file wizard.cpp.

372 {
373  if (m_mode==Hue) setHue(y2hue(m->y()));
374  else if (m_mode==Saturation) setSat(y2sat(m->y()));
375  else setGam(y2gam(m->y()));
376 }
void setHue(int v)
Definition: wizard.cpp:385
void setSat(int v)
Definition: wizard.cpp:394
Mode m_mode
Definition: wizard.h:95
int y2gam(int y)
Definition: wizard.cpp:448
int y2sat(int y)
Definition: wizard.cpp:436
int y2hue(int y)
Definition: wizard.cpp:424
void setGam(int v)
Definition: wizard.cpp:403
void ColorPicker::mousePressEvent ( QMouseEvent *  m)
protected

Definition at line 378 of file wizard.cpp.

379 {
380  if (m_mode==Hue) setHue(y2hue(m->y()));
381  else if (m_mode==Saturation) setSat(y2sat(m->y()));
382  else setGam(y2gam(m->y()));
383 }
void setHue(int v)
Definition: wizard.cpp:385
void setSat(int v)
Definition: wizard.cpp:394
Mode m_mode
Definition: wizard.h:95
int y2gam(int y)
Definition: wizard.cpp:448
int y2sat(int y)
Definition: wizard.cpp:436
int y2hue(int y)
Definition: wizard.cpp:424
void setGam(int v)
Definition: wizard.cpp:403
void ColorPicker::newHsv ( int  h,
int  s,
int  g 
)
signal
void ColorPicker::paintEvent ( QPaintEvent *  )
protected

Definition at line 327 of file wizard.cpp.

328 {
329  int w = width() - 5;
330 
331  QRect r(0, foff, w, height() - 2*foff);
332  int wi = r.width() - 2;
333  int hi = r.height() - 2;
334  if (!m_pix || m_pix->height() != hi || m_pix->width() != wi)
335  {
336  delete m_pix;
337  QImage img(wi, hi, QImage::Format_RGB32);
338  int y;
339  uint *pixel = (uint *) img.scanLine(0);
340  for (y = 0; y < hi; y++)
341  {
342  const uint *end = pixel + wi;
343  int yh = y2hue(y+coff);
344  int ys = y2sat(y+coff);
345  int yg = y2gam(y+coff);
346  while (pixel < end)
347  {
348  QColor c;
349  c.setHsv(yh, ys, (int)(255*pow(0.7,yg/100.0)));
350  *pixel = c.rgb();
351  ++pixel;
352  }
353  }
354  m_pix = new QPixmap(QPixmap::fromImage(img));
355  }
356  QPainter p(this);
357  p.drawPixmap(1, coff, *m_pix);
358  const QPalette &g = palette();
359  qDrawShadePanel(&p, r, g, true);
360  p.setPen(g.foreground().color());
361  p.setBrush(g.foreground());
362  QPolygon a;
363  int y = m_mode==Hue ? hue2y(m_hue) :
365  gam2y(m_gam);
366  a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
367  p.eraseRect(w, 0, 5, height());
368  p.drawPolygon(a);
369 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
int hue2y(int hue)
Definition: wizard.cpp:430
static constexpr double g
Definition: Units.h:144
int m_gam
Definition: wizard.h:96
constexpr T pow(T x)
Definition: pow.h:72
Mode m_mode
Definition: wizard.h:95
int sat2y(int sat)
Definition: wizard.cpp:442
const double a
int y2gam(int y)
Definition: wizard.cpp:448
p
Definition: test.py:223
int m_hue
Definition: wizard.h:97
int m_sat
Definition: wizard.h:98
QPixmap * m_pix
Definition: wizard.h:94
static Color palette[]
Definition: image.cpp:156
static constexpr double ys
Definition: Units.h:103
int y2sat(int y)
Definition: wizard.cpp:436
unsigned uint
Definition: qglobal.h:351
int gam2y(int gamma)
Definition: wizard.cpp:454
int y2hue(int y)
Definition: wizard.cpp:424
int ColorPicker::sat2y ( int  sat)
private

Definition at line 442 of file wizard.cpp.

443 {
444  int d = height() - 2*coff - 1;
445  return coff + (255-v)*d/255;
446 }
void ColorPicker::setCol ( int  h,
int  s,
int  g 
)
slot

Definition at line 412 of file wizard.cpp.

413 {
414  if (m_hue!=h || m_sat!=s || m_gam!=g)
415  {
416  m_hue = h;
417  m_sat = s;
418  m_gam = g;
419  delete m_pix; m_pix=0;
420  repaint();
421  }
422 }
static constexpr double g
Definition: Units.h:144
int m_gam
Definition: wizard.h:96
int m_hue
Definition: wizard.h:97
int m_sat
Definition: wizard.h:98
QPixmap * m_pix
Definition: wizard.h:94
static QCString * s
Definition: config.cpp:1042
void ColorPicker::setGam ( int  v)
private

Definition at line 403 of file wizard.cpp.

404 {
405  if (g==m_gam) return;
406  m_gam = qMax(40,qMin(g,240));
407  delete m_pix; m_pix=0;
408  repaint();
409  emit newHsv(m_hue,m_sat,m_gam);
410 }
static constexpr double g
Definition: Units.h:144
int m_gam
Definition: wizard.h:96
int m_hue
Definition: wizard.h:97
int m_sat
Definition: wizard.h:98
QPixmap * m_pix
Definition: wizard.h:94
void newHsv(int h, int s, int g)
void ColorPicker::setHue ( int  v)
private

Definition at line 385 of file wizard.cpp.

386 {
387  if (h==m_hue) return;
388  m_hue = qMax(0,qMin(h,359));
389  delete m_pix; m_pix=0;
390  repaint();
391  emit newHsv(m_hue,m_sat,m_gam);
392 }
int m_gam
Definition: wizard.h:96
int m_hue
Definition: wizard.h:97
int m_sat
Definition: wizard.h:98
QPixmap * m_pix
Definition: wizard.h:94
void newHsv(int h, int s, int g)
void ColorPicker::setSat ( int  v)
private

Definition at line 394 of file wizard.cpp.

395 {
396  if (s==m_sat) return;
397  m_sat = qMax(0,qMin(s,255));
398  delete m_pix; m_pix=0;
399  repaint();
400  emit newHsv(m_hue,m_sat,m_gam);
401 }
int m_gam
Definition: wizard.h:96
int m_hue
Definition: wizard.h:97
int m_sat
Definition: wizard.h:98
QPixmap * m_pix
Definition: wizard.h:94
void newHsv(int h, int s, int g)
static QCString * s
Definition: config.cpp:1042
int ColorPicker::y2gam ( int  y)
private

Definition at line 448 of file wizard.cpp.

449 {
450  int d = height() - 2*coff - 1;
451  return m_mode==Gamma ? 240 - (y - coff)*200/d : m_gam;
452 }
int m_gam
Definition: wizard.h:96
Mode m_mode
Definition: wizard.h:95
int ColorPicker::y2hue ( int  y)
private

Definition at line 424 of file wizard.cpp.

425 {
426  int d = height() - 2*coff - 1;
427  return m_mode==Hue ? (y - coff)*359/d : m_hue;
428 }
Mode m_mode
Definition: wizard.h:95
int m_hue
Definition: wizard.h:97
int ColorPicker::y2sat ( int  y)
private

Definition at line 436 of file wizard.cpp.

437 {
438  int d = height() - 2*coff - 1;
439  return m_mode==Saturation ? 255 - (y - coff)*255/d : m_sat;
440 }
Mode m_mode
Definition: wizard.h:95
int m_sat
Definition: wizard.h:98

Member Data Documentation

int ColorPicker::m_gam
private

Definition at line 96 of file wizard.h.

int ColorPicker::m_hue
private

Definition at line 97 of file wizard.h.

Mode ColorPicker::m_mode
private

Definition at line 95 of file wizard.h.

QPixmap* ColorPicker::m_pix
private

Definition at line 94 of file wizard.h.

int ColorPicker::m_sat
private

Definition at line 98 of file wizard.h.


The documentation for this class was generated from the following files: