00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ko_gray_widget.h"
00021
00022 #include <qlayout.h>
00023 #include <qhbox.h>
00024 #include <qlabel.h>
00025 #include <qspinbox.h>
00026 #include <qcolor.h>
00027
00028 #include <kdebug.h>
00029
00030 #include <koFrameButton.h>
00031 #include <koColorSlider.h>
00032 #include <kcolordialog.h>
00033
00034 KoGrayWidget::KoGrayWidget(QWidget *parent, const char *name) : super(parent, name)
00035 {
00036 m_ColorButton = new KDualColorButton(this);
00037 Q_CHECK_PTR(m_ColorButton);
00038
00039 m_ColorButton -> setFixedSize(m_ColorButton->sizeHint());
00040 QGridLayout *mGrid = new QGridLayout(this, 3, 5, 5, 2);
00041
00042
00043 mSlider = new KoColorSlider(this);
00044 mSlider->setFocusPolicy( QWidget::ClickFocus );
00045 mSlider->setMaximumHeight(20);
00046 mSlider->slotSetRange(0, 255);
00047 mSlider->slotSetColor1(QColor(255, 255, 255));
00048 mSlider->slotSetColor2(QColor(0, 0, 0));
00049
00050
00051 mLabel = new QLabel("K:", this);
00052 mLabel->setFixedWidth(12);
00053 mLabel->setFixedHeight(20);
00054
00055
00056 mIn = new QSpinBox(0, 255, 1, this);
00057 mIn->setFixedWidth(50);
00058 mIn->setFixedHeight(20);
00059 mIn->setFocusPolicy( QWidget::ClickFocus );
00060
00061 mGrid->addMultiCellWidget(m_ColorButton, 0, 3, 0, 0, Qt::AlignTop);
00062 mGrid->addWidget(mLabel, 0, 1);
00063 mGrid->addMultiCellWidget(mSlider, 0, 0, 2, 3);
00064 mGrid->addWidget(mIn, 0, 4);
00065
00066 connect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
00067 connect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
00068
00069
00070 connect(mSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChanged(int)));
00071
00072
00073 connect(mIn, SIGNAL(valueChanged(int)), this, SLOT(slotChanged(int)));
00074 }
00075
00076 void KoGrayWidget::slotChanged(int v)
00077 {
00078 v = 255 - v;
00079
00080 if (m_ColorButton->current() == KDualColorButton::Foreground){
00081 slotFGColorSelected( QColor( v, v, v));
00082 }
00083 else{
00084 slotBGColorSelected( QColor( v, v, v));
00085 }
00086 }
00087
00088 void KoGrayWidget::setFgColor(const QColor & c)
00089 {
00090 blockSignals(true);
00091 slotFGColorSelected(c);
00092 blockSignals(false);
00093 }
00094
00095 void KoGrayWidget::setBgColor(const QColor & c)
00096 {
00097 blockSignals(true);
00098 slotBGColorSelected(c);
00099 blockSignals(false);
00100 }
00101
00102 void KoGrayWidget::update(const QColor & fgColor, const QColor & bgColor)
00103 {
00104
00105 m_fgColor = fgColor;
00106 m_bgColor = bgColor;
00107
00108 QColor color = (m_ColorButton->current() == KDualColorButton::Foreground)? m_fgColor : m_bgColor;
00109
00110 disconnect(mSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChanged(int)));
00111 disconnect(mIn, SIGNAL(valueChanged(int)), this, SLOT(slotChanged(int)));
00112
00113 mIn->blockSignals(true);
00114 mSlider->blockSignals(true);
00115 double v = color.red() + color.green() + color.blue();
00116 v /= 3.0;
00117 v = 255.0 - v;
00118 mIn->setValue(static_cast<int>(v));
00119 mSlider->slotSetValue(static_cast<int>(v));
00120 mIn->blockSignals(false);
00121 mSlider->blockSignals(false);
00122
00123 connect(mSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChanged(int)));
00124 connect(mIn, SIGNAL(valueChanged(int)), this, SLOT(slotChanged(int)));
00125 }
00126
00127 void KoGrayWidget::slotFGColorSelected(const QColor& c)
00128 {
00129 m_fgColor = c;
00130
00131 disconnect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
00132 m_ColorButton->setForeground( m_fgColor );
00133 connect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
00134
00135 emit sigFgColorChanged(m_fgColor);
00136 }
00137
00138 void KoGrayWidget::slotBGColorSelected(const QColor& c)
00139 {
00140 m_bgColor = c;
00141
00142 disconnect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
00143 m_ColorButton->setBackground( m_bgColor );
00144 connect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
00145
00146 emit sigBgColorChanged(m_bgColor);
00147 }
00148
00149 void KoGrayWidget::currentChanged(KDualColorButton::DualColor s)
00150 {
00151 if(s == KDualColorButton::Foreground)
00152 slotFGColorSelected(m_ColorButton->currentColor());
00153 else
00154 slotBGColorSelected(m_ColorButton->currentColor());
00155 }
00156
00157 #include "ko_gray_widget.moc"