JKQtExtras
a library of useful Qt widgets and tools
All Classes Namespaces Functions Variables Enumerations Enumerator Properties Modules Pages
JKQTEColorSlider Class Reference

a QSlider that allows to choose a color hue More...

#include <jkqtecolorslider.h>

Inheritance diagram for JKQTEColorSlider:
Collaboration diagram for JKQTEColorSlider:

Public Types

enum  IndicatorStyle {
  FixedColorDoubleArrowIndicator =0,
  FixedColorCircleIndicator,
  SelectedColorDoubleArrowIndicator,
  SelectedColorCircleIndicator
}
 available modes for the slider More...
 
enum  SliderMode {
  GreySlider =0,
  GraySlider =GreySlider,
  RedSlider,
  GreenSlider,
  BlueSlider,
  HueSlider,
  SaturationSlider,
  ValueSlider,
  TransparencySlider,
  AlphaSlider =TransparencySlider
}
 available modes for the slider More...
 

Public Slots

void setBaseColor (QColor baseColor)
 sets the currently set base color that is modified by the slider More...
 
void setSliderMode (SliderMode mode)
 sets the currently set color/slider mode More...
 

Signals

void colorChanged (QColor color)
 emitted when the slider moves, the color is based on the baseColor(), modified by the slider value More...
 

Public Member Functions

 JKQTEColorSlider (Qt::Orientation orientation, QWidget *parent=nullptr)
 
 JKQTEColorSlider (QWidget *parent=nullptr)
 
 JKQTEColorSlider (SliderMode mode, Qt::Orientation orientation, QWidget *parent=nullptr)
 
 JKQTEColorSlider (SliderMode mode, QWidget *parent=nullptr)
 
QColor baseColor () const
 returns the currently set base color that is modified by the slider More...
 
QBrush & indicatorBrush ()
 returns the QBrush used to draw the indicator More...
 
const QBrush & indicatorBrush () const
 returns the QBrush used to draw the indicator More...
 
QPen & indicatorPen ()
 returns the QPen used to draw the indicator More...
 
const QPen & indicatorPen () const
 returns the QPen used to draw the indicator More...
 
IndicatorStyle indicatorStyle () const
 style of the indicator More...
 
virtual QSize minimumSizeHint () const override
 
QColor modifiedColor () const
 takes the color baseColor() and applies the value of the slider to the color More...
 
QColor modifiedColor (QColor colorIn) const
 takes the color colorIn and applies the value of the slider to the color More...
 
void setIndicatorBrush (const QBrush &b)
 sets the QBrush used to draw the indicator More...
 
void setIndicatorPen (const QPen &p)
 sets the QPen used to draw the indicator More...
 
void setIndicatorStyle (IndicatorStyle s)
 sets the style of the indicator More...
 
virtual QSize sizeHint () const override
 
SliderMode sliderMode () const
 returns the currently set color/slider mode More...
 

Protected Slots

void baseSliderChanged (int value)
 

Protected Member Functions

virtual void paintEvent (QPaintEvent *ev) override
 paints the slider More...
 

Static Protected Member Functions

static QColor defaultBaseColor (SliderMode mode)
 returns the default base color for a given slider mode More...
 

Protected Attributes

QColor m_baseColor
 currently set base color that is modified by the slider More...
 
QBrush m_indicatorBrush
 QBrush used to draw the indicator More...
 
QPen m_indicatorPen
 QPen used to draw the indicator More...
 
IndicatorStyle m_indicatorStyle
 style of the indicator More...
 
SliderMode m_mode
 currently set color/slider mode More...
 

Properties

QColor baseColor
 
QBrush indicatorBrush
 
QPen indicatorPen
 
IndicatorStyle IndicatorStyle
 
SliderMode sliderMode
 

Detailed Description

a QSlider that allows to choose a color hue

Horizontal Hue-Slider:

Vertical Hue Slider:

Basic usage is simple:

JKQTEColorSlider* slider=new JKQTEColorSlider(Qt::Horizontal, wid);
lay->addRow("JKQTEColorSlider, horizontal, HueSlider:", slider);

Base Color Mode

Especially when building a color-chooser, you need to combine several sliders. That then define a color together. To support such modes, the slider can use a "base color" i.e. an input color which is then modified and output again. The following functions support this mode:

Here is an example of how to use this feature:

QGroupBox* grp=new QGroupBox("RGB chooser");
QGridLayout* layGrp=new QGridLayout;
grp->setLayout(layGrp);
JKQTEColorSlider* sliderR=new JKQTEColorSlider(Qt::Horizontal, grp);
layGrp->addWidget(sliderR, 0,0);
JKQTEColorSlider* sliderG=new JKQTEColorSlider(Qt::Horizontal, grp);
layGrp->addWidget(sliderG, 1,0);
JKQTEColorSlider* sliderB=new JKQTEColorSlider(Qt::Horizontal, grp);
layGrp->addWidget(sliderB, 2,0);
connect(sliderR, SIGNAL(colorChanged(QColor)), sliderG, SLOT(setBaseColor(QColor)));
connect(sliderG, SIGNAL(colorChanged(QColor)), sliderB, SLOT(setBaseColor(QColor)));

Member Enumeration Documentation

◆ IndicatorStyle

available modes for the slider

the appearance and the range of the slider depend on this

Enumerator
FixedColorDoubleArrowIndicator 

draws two inward pointing triangles as indicator, filled with indicatorBrush()

FixedColorCircleIndicator 

draws a circle as indicator, filled with indicatorBrush()

SelectedColorDoubleArrowIndicator 

draws two inward pointing triangles as indicator, filled with the current color

SelectedColorCircleIndicator 

draws a circle as indicator, filled with the current color

◆ SliderMode

available modes for the slider

the appearance and the range of the slider depend on this

Enumerator
GreySlider 

the slider modifies the grey color channel

GraySlider 

the slider modifies the grey color channel

RedSlider 

the slider modifies the red color channel

GreenSlider 

the slider modifies the green color channel

BlueSlider 

the slider modifies the blue color channel

HueSlider 

the slider modifies the hue color channel (from HSV color model)

SaturationSlider 

the slider modifies the saturation color channel (from HSV color model)

ValueSlider 

the slider modifies the value color channel (from HSV color model)

TransparencySlider 

the slider modifies the transparency color channel

AlphaSlider 

the slider modifies the transparency color channel

Constructor & Destructor Documentation

◆ JKQTEColorSlider() [1/4]

JKQTEColorSlider::JKQTEColorSlider ( QWidget *  parent = nullptr)
explicit

◆ JKQTEColorSlider() [2/4]

JKQTEColorSlider::JKQTEColorSlider ( Qt::Orientation  orientation,
QWidget *  parent = nullptr 
)
explicit

◆ JKQTEColorSlider() [3/4]

JKQTEColorSlider::JKQTEColorSlider ( SliderMode  mode,
QWidget *  parent = nullptr 
)
explicit

◆ JKQTEColorSlider() [4/4]

JKQTEColorSlider::JKQTEColorSlider ( SliderMode  mode,
Qt::Orientation  orientation,
QWidget *  parent = nullptr 
)
explicit

Member Function Documentation

◆ baseColor()

QColor JKQTEColorSlider::baseColor ( ) const

returns the currently set base color that is modified by the slider

See also
Base Color Mode baseColor(), setBaseColor(), modifiedColor(), colorChanged()

◆ baseSliderChanged

void JKQTEColorSlider::baseSliderChanged ( int  value)
protectedslot

◆ colorChanged

void JKQTEColorSlider::colorChanged ( QColor  color)
signal

emitted when the slider moves, the color is based on the baseColor(), modified by the slider value

See also
Base Color Mode baseColor(), setBaseColor(), modifiedColor(), colorChanged()

◆ defaultBaseColor()

static QColor JKQTEColorSlider::defaultBaseColor ( SliderMode  mode)
staticprotected

returns the default base color for a given slider mode

◆ indicatorBrush() [1/2]

QBrush& JKQTEColorSlider::indicatorBrush ( )

returns the QBrush used to draw the indicator

◆ indicatorBrush() [2/2]

const QBrush& JKQTEColorSlider::indicatorBrush ( ) const

returns the QBrush used to draw the indicator

◆ indicatorPen() [1/2]

QPen& JKQTEColorSlider::indicatorPen ( )

returns the QPen used to draw the indicator

◆ indicatorPen() [2/2]

const QPen& JKQTEColorSlider::indicatorPen ( ) const

returns the QPen used to draw the indicator

◆ indicatorStyle()

IndicatorStyle JKQTEColorSlider::indicatorStyle ( ) const

style of the indicator

◆ minimumSizeHint()

virtual QSize JKQTEColorSlider::minimumSizeHint ( ) const
overridevirtual

◆ modifiedColor() [1/2]

QColor JKQTEColorSlider::modifiedColor ( ) const

takes the color baseColor() and applies the value of the slider to the color

See also
Base Color Mode baseColor(), setBaseColor(), baseColor(), colorChanged()

◆ modifiedColor() [2/2]

QColor JKQTEColorSlider::modifiedColor ( QColor  colorIn) const

takes the color colorIn and applies the value of the slider to the color

◆ paintEvent()

virtual void JKQTEColorSlider::paintEvent ( QPaintEvent *  ev)
overrideprotectedvirtual

paints the slider

◆ setBaseColor

void JKQTEColorSlider::setBaseColor ( QColor  baseColor)
slot

sets the currently set base color that is modified by the slider

See also
Base Color Mode baseColor(), baseColor(), modifiedColor(), colorChanged()

◆ setIndicatorBrush()

void JKQTEColorSlider::setIndicatorBrush ( const QBrush &  b)

sets the QBrush used to draw the indicator

◆ setIndicatorPen()

void JKQTEColorSlider::setIndicatorPen ( const QPen &  p)

sets the QPen used to draw the indicator

◆ setIndicatorStyle()

void JKQTEColorSlider::setIndicatorStyle ( IndicatorStyle  s)

sets the style of the indicator

◆ setSliderMode

void JKQTEColorSlider::setSliderMode ( SliderMode  mode)
slot

sets the currently set color/slider mode

The appearance and the range of the slider depend on this

Note
This also changes the range of the slider!
See also
SliderMode sliderMode()

◆ sizeHint()

virtual QSize JKQTEColorSlider::sizeHint ( ) const
overridevirtual

◆ sliderMode()

SliderMode JKQTEColorSlider::sliderMode ( ) const

returns the currently set color/slider mode

The appearance and the range of the slider depend on this

See also
SliderMode setSliderMode()

Member Data Documentation

◆ m_baseColor

QColor JKQTEColorSlider::m_baseColor
protected

currently set base color that is modified by the slider

See also
Base Color Mode baseColor(), baseColor(), modifiedColor(), colorChanged()

◆ m_indicatorBrush

QBrush JKQTEColorSlider::m_indicatorBrush
protected

QBrush used to draw the indicator

◆ m_indicatorPen

QPen JKQTEColorSlider::m_indicatorPen
protected

QPen used to draw the indicator

◆ m_indicatorStyle

IndicatorStyle JKQTEColorSlider::m_indicatorStyle
protected

style of the indicator

◆ m_mode

SliderMode JKQTEColorSlider::m_mode
protected

currently set color/slider mode

Property Documentation

◆ baseColor

QColor JKQTEColorSlider::baseColor
readwrite

◆ indicatorBrush

QBrush JKQTEColorSlider::indicatorBrush
readwrite

◆ indicatorPen

QPen JKQTEColorSlider::indicatorPen
readwrite

◆ IndicatorStyle

◆ sliderMode

SliderMode JKQTEColorSlider::sliderMode
readwrite

The documentation for this class was generated from the following file:
JKQTEColorSlider::FixedColorDoubleArrowIndicator
@ FixedColorDoubleArrowIndicator
Definition: jkqtecolorslider.h:89
JKQTEColorSlider::setSliderMode
void setSliderMode(SliderMode mode)
sets the currently set color/slider mode
JKQTEColorSlider::setIndicatorStyle
void setIndicatorStyle(IndicatorStyle s)
sets the style of the indicator
JKQTEColorSlider::GreenSlider
@ GreenSlider
Definition: jkqtecolorslider.h:75
JKQTEColorSlider::BlueSlider
@ BlueSlider
Definition: jkqtecolorslider.h:76
JKQTEColorSlider::setBaseColor
void setBaseColor(QColor baseColor)
sets the currently set base color that is modified by the slider
JKQTEColorSlider
a QSlider that allows to choose a color hue
Definition: jkqtecolorslider.h:60
JKQTEColorSlider::colorChanged
void colorChanged(QColor color)
emitted when the slider moves, the color is based on the baseColor(), modified by the slider value
JKQTEColorSlider::HueSlider
@ HueSlider
Definition: jkqtecolorslider.h:77
JKQTEColorSlider::JKQTEColorSlider
JKQTEColorSlider(QWidget *parent=nullptr)
JKQTEColorSlider::RedSlider
@ RedSlider
Definition: jkqtecolorslider.h:74