ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ColorButton Class Reference

#include <src/ckb/colorbutton.h>

+ Inheritance diagram for ColorButton:
+ Collaboration diagram for ColorButton:

Signals

void colorChanged (QColor newColor)
 

Public Member Functions

 ColorButton (QWidget *parent=0, bool allowAlpha=false)
 
const QColor & color () const
 
void color (const QColor &newColor)
 
bool allowAlpha () const
 
void allowAlpha (bool newAllowAlpha)
 
bool setLabel () const
 
void setLabel (bool newSetLabel)
 
bool bigIcons () const
 
void bigIcons (bool newBigIcons)
 

Private Slots

void pickColor ()
 

Private Member Functions

void updateImage ()
 

Private Attributes

QColor _color
 
bool _alpha
 
bool _setLabel
 
bool _bigIcons
 

Detailed Description

Definition at line 6 of file colorbutton.h.

Constructor & Destructor Documentation

ColorButton::ColorButton ( QWidget parent = 0,
bool  allowAlpha = false 
)
explicit

Definition at line 5 of file colorbutton.cpp.

References pickColor(), and updateImage().

5  :
6  QPushButton(parent), _alpha(allowAlpha), _setLabel(true), _bigIcons(false)
7 {
8  setAutoDefault(false);
9  setDefault(false);
10  updateImage();
11  // Pick color on click (use queued connection so that any on_*_clicked() events can be processed first)
12  connect(this, SIGNAL(clicked()), this, SLOT(pickColor()), Qt::QueuedConnection);
13 }
void pickColor()
Definition: colorbutton.cpp:60
bool allowAlpha() const
Definition: colorbutton.h:17
bool _bigIcons
Definition: colorbutton.h:34
void updateImage()
Definition: colorbutton.cpp:32
bool _setLabel
Definition: colorbutton.h:34

+ Here is the call graph for this function:

Member Function Documentation

bool ColorButton::allowAlpha ( ) const
inline

Definition at line 17 of file colorbutton.h.

References _alpha.

Referenced by KPerfWidget::KPerfWidget(), and MPerfWidget::MPerfWidget().

17 { return _alpha; }

+ Here is the caller graph for this function:

void ColorButton::allowAlpha ( bool  newAllowAlpha)

Definition at line 22 of file colorbutton.cpp.

References _alpha, and updateImage().

22  {
23  _alpha = newAllowAlpha;
24  updateImage();
25 }
void updateImage()
Definition: colorbutton.cpp:32

+ Here is the call graph for this function:

bool ColorButton::bigIcons ( ) const
inline

Definition at line 23 of file colorbutton.h.

References _bigIcons.

Referenced by KPerfWidget::KPerfWidget(), and MPerfWidget::MPerfWidget().

23 { return _bigIcons; }
bool _bigIcons
Definition: colorbutton.h:34

+ Here is the caller graph for this function:

void ColorButton::bigIcons ( bool  newBigIcons)

Definition at line 27 of file colorbutton.cpp.

References _bigIcons, and updateImage().

27  {
28  _bigIcons = newBigIcons;
29  updateImage();
30 }
bool _bigIcons
Definition: colorbutton.h:34
void updateImage()
Definition: colorbutton.cpp:32

+ Here is the call graph for this function:

const QColor& ColorButton::color ( ) const
inline
void ColorButton::color ( const QColor &  newColor)

Definition at line 15 of file colorbutton.cpp.

References _alpha, _color, and updateImage().

15  {
16  _color = newColor;
17  if(!_alpha)
18  _color.setAlpha(255);
19  updateImage();
20 }
QColor _color
Definition: colorbutton.h:33
void updateImage()
Definition: colorbutton.cpp:32

+ Here is the call graph for this function:

void ColorButton::colorChanged ( QColor  newColor)
signal

Definition at line 132 of file moc_colorbutton.cpp.

Referenced by pickColor().

133 {
134  void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
135  QMetaObject::activate(this, &staticMetaObject, 0, _a);
136 }

+ Here is the caller graph for this function:

void ColorButton::pickColor ( )
privateslot

Definition at line 60 of file colorbutton.cpp.

References _alpha, _color, colorChanged(), and updateImage().

Referenced by ColorButton().

60  {
61  QColor newColor = QColorDialog::getColor(_color, this, QString(), QColorDialog::ColorDialogOptions(_alpha ? QColorDialog::ShowAlphaChannel : 0));
62  if(newColor.isValid()){
63  _color = newColor;
64  updateImage();
65  emit colorChanged(_color);
66  }
67 }
QColor _color
Definition: colorbutton.h:33
void colorChanged(QColor newColor)
void updateImage()
Definition: colorbutton.cpp:32

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ColorButton::setLabel ( ) const
inline

Definition at line 20 of file colorbutton.h.

References _setLabel.

Referenced by KPerfWidget::KPerfWidget(), and MPerfWidget::MPerfWidget().

20 { return _setLabel; }
bool _setLabel
Definition: colorbutton.h:34

+ Here is the caller graph for this function:

void ColorButton::setLabel ( bool  newSetLabel)
inline

Definition at line 21 of file colorbutton.h.

References _setLabel.

21 { _setLabel = newSetLabel; }
bool _setLabel
Definition: colorbutton.h:34
void ColorButton::updateImage ( )
private

Definition at line 32 of file colorbutton.cpp.

References _alpha, _bigIcons, _color, and _setLabel.

Referenced by allowAlpha(), bigIcons(), color(), ColorButton(), and pickColor().

32  {
33  if(!_color.isValid()){
34  setIcon(QIcon());
35  if(_setLabel)
36  setText("Change color...");
37  return;
38  }
39  const int w = 24, h = _bigIcons ? 24 : 12;
40  QImage image(w, h, QImage::Format_RGB888);
41  QPainter painter(&image);
42  painter.setPen(Qt::NoPen);
43  painter.fillRect(0, 0, w, h, QColor(0, 0, 0));
44  if(_alpha && _color.alpha() != 255){
45  painter.fillRect(1, 1, w / 2 - 1, h / 2 - 1, QColor(255, 255, 255));
46  painter.fillRect(w / 2, 1, w / 2 - 1, h / 2 - 1, QColor(192, 192, 192));
47  painter.fillRect(1, h / 2, w / 2 - 1, h / 2 - 1, QColor(192, 192, 192));
48  painter.fillRect(w / 2, h / 2, w / 2 - 1, h / 2 - 1, QColor(255, 255, 255));
49  }
50  painter.fillRect(1, 1, w - 2, h - 2, _color);
51  setIcon(QIcon(QPixmap::fromImage(image)));
52  if(_setLabel){
53  QString text = QString(" (%1, %2, %3)").arg(_color.red()).arg(_color.green()).arg(_color.blue());
54  if(_alpha)
55  text += QString(", %4%").arg(QString::number(_color.alphaF() * 100., 'f', 0));
56  setText(text);
57  }
58 }
QColor _color
Definition: colorbutton.h:33
bool _bigIcons
Definition: colorbutton.h:34
bool _setLabel
Definition: colorbutton.h:34

+ Here is the caller graph for this function:

Field Documentation

bool ColorButton::_alpha
private

Definition at line 34 of file colorbutton.h.

Referenced by allowAlpha(), color(), pickColor(), and updateImage().

bool ColorButton::_bigIcons
private

Definition at line 34 of file colorbutton.h.

Referenced by bigIcons(), and updateImage().

QColor ColorButton::_color
private

Definition at line 33 of file colorbutton.h.

Referenced by color(), pickColor(), and updateImage().

bool ColorButton::_setLabel
private

Definition at line 34 of file colorbutton.h.

Referenced by setLabel(), and updateImage().


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