00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ko_hsv_widget.h"
00021 #include "ko_color_wheel.h"
00022
00023 #include <kselect.h>
00024 #include <qlayout.h>
00025 #include <qhbox.h>
00026 #include <qlabel.h>
00027 #include <qspinbox.h>
00028 #include <qtooltip.h>
00029 #include <koFrameButton.h>
00030 #include <koColorSlider.h>
00031 #include <kcolordialog.h>
00032 #include <kdualcolorbutton.h>
00033 #include <koColor.h>
00034 #include <kdebug.h>
00035 #include <klocale.h>
00036
00037 KoHSVWidget::KoHSVWidget(QWidget *parent, const char *name) : super(parent, name)
00038 {
00039 m_ColorButton = new KDualColorButton(this);
00040 m_ColorButton -> setFixedSize(m_ColorButton->sizeHint());
00041
00042 QGridLayout *mGrid = new QGridLayout(this, 5, 7, 5, 2);
00043 m_colorwheel = new KoColorWheel(this);
00044 m_colorwheel->setFixedSize( 120, 120);
00045 m_VSelector = new KValueSelector(Qt::Vertical, this);
00046 m_VSelector-> setFixedSize( 30, 120);
00047
00048
00049 mHLabel = new QLabel("H:", this);
00050 mHLabel->setFixedSize(12, 20);
00051 mSLabel = new QLabel("S:", this);
00052 mSLabel->setFixedSize(12, 20);
00053 mVLabel = new QLabel("V:", this);
00054 mVLabel->setFixedSize(12, 20);
00055
00056
00057 mHIn = new QSpinBox(0, 359, 1, this);
00058 mHIn->setFixedSize(50, 20);
00059 mHIn->setFocusPolicy( QWidget::ClickFocus );
00060 QToolTip::add( mHIn, i18n( "Hue" ) );
00061
00062 mSIn = new QSpinBox(0, 255, 1, this);
00063 mSIn->setFixedSize(50, 20);
00064 mSIn->setFocusPolicy( QWidget::ClickFocus );
00065 QToolTip::add( mSIn, i18n( "Saturation" ) );
00066
00067 mVIn = new QSpinBox(0, 255, 1, this);
00068 mVIn->setFixedSize(50, 20);
00069 mVIn->setFocusPolicy( QWidget::ClickFocus );
00070 QToolTip::add( mVIn, i18n( "Value (brightness)" ) );
00071
00072 mGrid->addMultiCellWidget(m_ColorButton, 0, 0, 0, 1, Qt::AlignTop);
00073
00074 mGrid->addWidget(mHLabel, 1, 0);
00075 mGrid->addWidget(mSLabel, 2, 0);
00076 mGrid->addWidget(mVLabel, 3, 0);
00077
00078 mGrid->addMultiCellWidget(m_colorwheel, 0, 3, 2, 4);
00079
00080 mGrid->addWidget(mHIn, 1, 1);
00081 mGrid->addWidget(mSIn, 2, 1);
00082 mGrid->addWidget(mVIn, 3, 1);
00083
00084 mGrid->addMultiCellWidget(m_VSelector, 0, 3, 5, 5);
00085
00086
00087 connect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
00088 connect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
00089 connect(m_ColorButton, SIGNAL(currentChanged(KDualColorButton::DualColor)), this, SLOT(currentChanged(KDualColorButton::DualColor)));
00090
00091 connect(m_VSelector, SIGNAL(valueChanged(int)), this, SLOT(slotVChanged(int)));
00092 connect(m_colorwheel, SIGNAL(valueChanged(const KoColor&)), this, SLOT(slotWheelChanged(const KoColor&)));
00093
00094
00095 connect(mHIn, SIGNAL(valueChanged(int)), this, SLOT(slotHChanged(int)));
00096 connect(mSIn, SIGNAL(valueChanged(int)), this, SLOT(slotSChanged(int)));
00097 connect(mVIn, SIGNAL(valueChanged(int)), this, SLOT(slotVChanged(int)));
00098
00099
00100 m_autovalue = true;
00101
00102 update(Qt::black, Qt::white);
00103 }
00104
00105 void KoHSVWidget::slotHChanged(int h)
00106 {
00107
00108 if (m_ColorButton->current() == KDualColorButton::Foreground){
00109 m_fgColor.setHSV(h, m_fgColor.S(), m_fgColor.V());
00110 changedFgColor();
00111 }
00112 else{
00113 m_bgColor.setHSV(h, m_bgColor.S(), m_bgColor.V());
00114 changedBgColor();
00115 }
00116 }
00117
00118 void KoHSVWidget::slotSChanged(int s)
00119 {
00120
00121 if (m_ColorButton->current() == KDualColorButton::Foreground){
00122 m_fgColor.setHSV(m_fgColor.H(), s, m_fgColor.V());
00123 changedFgColor();
00124 }
00125 else{
00126 m_bgColor.setHSV(m_bgColor.H(), s, m_bgColor.V());
00127 changedBgColor();
00128 }
00129 }
00130
00131 void KoHSVWidget::slotVChanged(int v)
00132 {
00133
00134 m_autovalue = false;
00135 if (m_ColorButton->current() == KDualColorButton::Foreground){
00136 m_fgColor.setHSV(m_fgColor.H(), m_fgColor.S(), v);
00137 changedFgColor();
00138 }
00139 else{
00140 m_bgColor.setHSV(m_bgColor.H(), m_bgColor.S(), v);
00141 changedBgColor();
00142 }
00143 }
00144
00145 void KoHSVWidget::slotWheelChanged(const KoColor& c)
00146 {
00147
00148 if (m_ColorButton->current() == KDualColorButton::Foreground){
00149 if(m_autovalue)
00150 m_fgColor.setHSV(c.H(), c.S(), 255);
00151 else
00152 m_fgColor.setHSV(c.H(), c.S(), m_fgColor.V());
00153 changedFgColor();
00154 }
00155 else{
00156 if(m_autovalue)
00157 m_bgColor.setHSV(c.H(), c.S(), 255);
00158 else
00159 m_bgColor.setHSV(c.H(), c.S(), m_bgColor.V());
00160 changedBgColor();
00161 }
00162 }
00163
00164
00165 void KoHSVWidget::setFgColor(const QColor & c)
00166 {
00167
00168 blockSignals(true);
00169 slotFGColorSelected(c);
00170 blockSignals(false);
00171 }
00172
00173 void KoHSVWidget::setBgColor(const QColor & c)
00174 {
00175
00176 blockSignals(true);
00177 slotBGColorSelected(c);
00178 blockSignals(false);
00179 }
00180
00181 void KoHSVWidget::changedFgColor()
00182 {
00183
00184 disconnect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
00185 m_ColorButton->setForeground( m_fgColor.color() );
00186 connect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
00187
00188 update( m_fgColor, m_bgColor);
00189
00190 emit sigFgColorChanged(m_fgColor.color());
00191 }
00192
00193 void KoHSVWidget::changedBgColor()
00194 {
00195
00196 disconnect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
00197 m_ColorButton->setBackground( m_bgColor.color() );
00198 connect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
00199
00200 update(m_fgColor, m_bgColor );
00201
00202 emit sigBgColorChanged(m_bgColor.color());
00203 }
00204
00205 void KoHSVWidget::update(const KoColor & fgColor, const KoColor & bgColor)
00206 {
00207
00208 mHIn->blockSignals(true);
00209 mSIn->blockSignals(true);
00210 mVIn->blockSignals(true);
00211 m_VSelector->blockSignals(true);
00212 m_colorwheel->blockSignals(true);
00213
00214
00215 m_fgColor = fgColor;
00216 m_bgColor = bgColor;
00217
00218 KoColor color = (m_ColorButton->current() == KDualColorButton::Foreground)? m_fgColor : m_bgColor;
00219
00220 int h = color.H();
00221 int s = color.S();
00222 int v = color.V();
00223
00224 mHIn->setValue(h);
00225 mSIn->setValue(s);
00226 mVIn->setValue(v);
00227
00228 m_VSelector->setHue(h);
00229 m_VSelector->setSaturation(s);
00230 m_VSelector->setValue(v);
00231 m_VSelector->updateContents();
00232
00233 m_colorwheel->slotSetValue(color);
00234
00235 mHIn->blockSignals(false);
00236 mSIn->blockSignals(false);
00237 mVIn->blockSignals(false);
00238 m_VSelector->blockSignals(false);
00239 m_VSelector->repaint(false);
00240 m_colorwheel->blockSignals(false);
00241 }
00242
00243 void KoHSVWidget::slotFGColorSelected(const QColor& c)
00244 {
00245
00246 m_fgColor = KoColor(c);
00247
00248 changedFgColor();
00249 }
00250
00251 void KoHSVWidget::slotBGColorSelected(const QColor& c)
00252 {
00253
00254 m_bgColor = KoColor(c);
00255
00256 changedBgColor();
00257 }
00258
00259 void KoHSVWidget::currentChanged(KDualColorButton::DualColor s)
00260 {
00261
00262 if(s == KDualColorButton::Foreground)
00263 slotFGColorSelected(m_ColorButton->currentColor());
00264 else
00265 slotBGColorSelected(m_ColorButton->currentColor());
00266 }
00267
00268 #include "ko_hsv_widget.moc"