You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
275 lines
8.4 KiB
275 lines
8.4 KiB
15 years ago
|
/*
|
||
|
* Copyright (c) 1999 Matthias Elter (me@kde.org)
|
||
|
* Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "ko_hsv_widget.h"
|
||
|
#include "ko_color_wheel.h"
|
||
|
|
||
12 years ago
|
#include <tdeselect.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqhbox.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqspinbox.h>
|
||
|
#include <tqtooltip.h>
|
||
15 years ago
|
#include <koFrameButton.h>
|
||
|
#include <koColorSlider.h>
|
||
|
#include <kcolordialog.h>
|
||
|
#include <kdualcolorbutton.h>
|
||
|
#include <koColor.h>
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
13 years ago
|
KoHSVWidget::KoHSVWidget(TQWidget *parent, const char *name) : super(parent, name)
|
||
15 years ago
|
{
|
||
|
m_ColorButton = new KDualColorButton(this);
|
||
13 years ago
|
m_ColorButton -> setFixedSize(m_ColorButton->sizeHint());
|
||
15 years ago
|
|
||
14 years ago
|
TQGridLayout *mGrid = new TQGridLayout(this, 5, 7, 5, 2);
|
||
15 years ago
|
m_colorwheel = new KoColorWheel(this);
|
||
|
m_colorwheel->setFixedSize( 120, 120);
|
||
|
m_VSelector = new KValueSelector(Qt::Vertical, this);
|
||
|
m_VSelector-> setFixedSize( 30, 120);
|
||
|
|
||
|
/* setup slider labels */
|
||
14 years ago
|
mHLabel = new TQLabel("H:", this);
|
||
15 years ago
|
mHLabel->setFixedSize(12, 20);
|
||
14 years ago
|
mSLabel = new TQLabel("S:", this);
|
||
15 years ago
|
mSLabel->setFixedSize(12, 20);
|
||
14 years ago
|
mVLabel = new TQLabel("V:", this);
|
||
15 years ago
|
mVLabel->setFixedSize(12, 20);
|
||
|
|
||
|
/* setup spin box */
|
||
14 years ago
|
mHIn = new TQSpinBox(0, 359, 1, this);
|
||
15 years ago
|
mHIn->setFixedSize(50, 20);
|
||
14 years ago
|
mHIn->setFocusPolicy( TQ_ClickFocus );
|
||
|
TQToolTip::add( mHIn, i18n( "Hue" ) );
|
||
15 years ago
|
|
||
14 years ago
|
mSIn = new TQSpinBox(0, 255, 1, this);
|
||
15 years ago
|
mSIn->setFixedSize(50, 20);
|
||
14 years ago
|
mSIn->setFocusPolicy( TQ_ClickFocus );
|
||
|
TQToolTip::add( mSIn, i18n( "Saturation" ) );
|
||
15 years ago
|
|
||
14 years ago
|
mVIn = new TQSpinBox(0, 255, 1, this);
|
||
15 years ago
|
mVIn->setFixedSize(50, 20);
|
||
14 years ago
|
mVIn->setFocusPolicy( TQ_ClickFocus );
|
||
|
TQToolTip::add( mVIn, i18n( "Value (brightness)" ) );
|
||
15 years ago
|
|
||
14 years ago
|
mGrid->addMultiCellWidget(m_ColorButton, 0, 0, 0, 1, TQt::AlignTop);
|
||
15 years ago
|
|
||
|
mGrid->addWidget(mHLabel, 1, 0);
|
||
|
mGrid->addWidget(mSLabel, 2, 0);
|
||
|
mGrid->addWidget(mVLabel, 3, 0);
|
||
|
|
||
|
mGrid->addMultiCellWidget(m_colorwheel, 0, 3, 2, 4);
|
||
|
|
||
|
mGrid->addWidget(mHIn, 1, 1);
|
||
|
mGrid->addWidget(mSIn, 2, 1);
|
||
|
mGrid->addWidget(mVIn, 3, 1);
|
||
|
|
||
|
mGrid->addMultiCellWidget(m_VSelector, 0, 3, 5, 5);
|
||
|
|
||
|
|
||
14 years ago
|
connect(m_ColorButton, TQT_SIGNAL(fgChanged(const TQColor &)), this, TQT_SLOT(slotFGColorSelected(const TQColor &)));
|
||
|
connect(m_ColorButton, TQT_SIGNAL(bgChanged(const TQColor &)), this, TQT_SLOT(slotBGColorSelected(const TQColor &)));
|
||
|
connect(m_ColorButton, TQT_SIGNAL(currentChanged(KDualColorButton::DualColor)), this, TQT_SLOT(currentChanged(KDualColorButton::DualColor)));
|
||
15 years ago
|
|
||
14 years ago
|
connect(m_VSelector, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotVChanged(int)));
|
||
|
connect(m_colorwheel, TQT_SIGNAL(valueChanged(const KoColor&)), this, TQT_SLOT(slotWheelChanged(const KoColor&)));
|
||
15 years ago
|
|
||
|
/* connect spin box */
|
||
14 years ago
|
connect(mHIn, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotHChanged(int)));
|
||
|
connect(mSIn, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSChanged(int)));
|
||
|
connect(mVIn, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotVChanged(int)));
|
||
15 years ago
|
|
||
13 years ago
|
//setFixedSize(mGrid -> minimumSize());
|
||
15 years ago
|
m_autovalue = true; // So on the initial selection of h or v, s gets set to 255.
|
||
|
|
||
14 years ago
|
update(TQt::black, TQt::white);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KoHSVWidget::slotHChanged(int h)
|
||
|
{
|
||
|
//kdDebug() << "H changed: " << h << endl;
|
||
|
if (m_ColorButton->current() == KDualColorButton::Foreground){
|
||
|
m_fgColor.setHSV(h, m_fgColor.S(), m_fgColor.V());
|
||
|
changedFgColor();
|
||
|
}
|
||
|
else{
|
||
|
m_bgColor.setHSV(h, m_bgColor.S(), m_bgColor.V());
|
||
|
changedBgColor();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KoHSVWidget::slotSChanged(int s)
|
||
|
{
|
||
|
//kdDebug() << "S changed: " << s << endl;
|
||
|
if (m_ColorButton->current() == KDualColorButton::Foreground){
|
||
|
m_fgColor.setHSV(m_fgColor.H(), s, m_fgColor.V());
|
||
|
changedFgColor();
|
||
|
}
|
||
|
else{
|
||
|
m_bgColor.setHSV(m_bgColor.H(), s, m_bgColor.V());
|
||
|
changedBgColor();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KoHSVWidget::slotVChanged(int v)
|
||
|
{
|
||
|
//kdDebug() << "V changed: " << v << ", setting autovalue to false " << endl;
|
||
|
m_autovalue = false;
|
||
|
if (m_ColorButton->current() == KDualColorButton::Foreground){
|
||
|
m_fgColor.setHSV(m_fgColor.H(), m_fgColor.S(), v);
|
||
|
changedFgColor();
|
||
|
}
|
||
|
else{
|
||
|
m_bgColor.setHSV(m_bgColor.H(), m_bgColor.S(), v);
|
||
|
changedBgColor();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KoHSVWidget::slotWheelChanged(const KoColor& c)
|
||
|
{
|
||
|
//kdDebug() << "Wheel changed: " << c.color() << endl;
|
||
|
if (m_ColorButton->current() == KDualColorButton::Foreground){
|
||
|
if(m_autovalue)
|
||
|
m_fgColor.setHSV(c.H(), c.S(), 255);
|
||
|
else
|
||
|
m_fgColor.setHSV(c.H(), c.S(), m_fgColor.V());
|
||
|
changedFgColor();
|
||
|
}
|
||
|
else{
|
||
|
if(m_autovalue)
|
||
|
m_bgColor.setHSV(c.H(), c.S(), 255);
|
||
|
else
|
||
|
m_bgColor.setHSV(c.H(), c.S(), m_bgColor.V());
|
||
|
changedBgColor();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KoHSVWidget::setFgColor(const TQColor & c)
|
||
15 years ago
|
{
|
||
|
//kdDebug() << "setFGColor " << c << endl;
|
||
|
blockSignals(true);
|
||
|
slotFGColorSelected(c);
|
||
|
blockSignals(false);
|
||
|
}
|
||
|
|
||
14 years ago
|
void KoHSVWidget::setBgColor(const TQColor & c)
|
||
15 years ago
|
{
|
||
|
//kdDebug() << "setBgColor " << c << endl;
|
||
|
blockSignals(true);
|
||
|
slotBGColorSelected(c);
|
||
|
blockSignals(false);
|
||
|
}
|
||
|
|
||
|
void KoHSVWidget::changedFgColor()
|
||
|
{
|
||
|
//kdDebug() << "ChangedFgColor\n";
|
||
14 years ago
|
disconnect(m_ColorButton, TQT_SIGNAL(fgChanged(const TQColor &)), this, TQT_SLOT(slotFGColorSelected(const TQColor &)));
|
||
15 years ago
|
m_ColorButton->setForeground( m_fgColor.color() );
|
||
14 years ago
|
connect(m_ColorButton, TQT_SIGNAL(fgChanged(const TQColor &)), this, TQT_SLOT(slotFGColorSelected(const TQColor &)));
|
||
15 years ago
|
|
||
|
update( m_fgColor, m_bgColor);
|
||
|
|
||
|
emit sigFgColorChanged(m_fgColor.color());
|
||
|
}
|
||
|
|
||
|
void KoHSVWidget::changedBgColor()
|
||
|
{
|
||
|
//kdDebug() << "changedBgColor()\n";
|
||
14 years ago
|
disconnect(m_ColorButton, TQT_SIGNAL(bgChanged(const TQColor &)), this, TQT_SLOT(slotBGColorSelected(const TQColor &)));
|
||
15 years ago
|
m_ColorButton->setBackground( m_bgColor.color() );
|
||
14 years ago
|
connect(m_ColorButton, TQT_SIGNAL(bgChanged(const TQColor &)), this, TQT_SLOT(slotBGColorSelected(const TQColor &)));
|
||
15 years ago
|
|
||
|
update(m_fgColor, m_bgColor );
|
||
|
|
||
|
emit sigBgColorChanged(m_bgColor.color());
|
||
|
}
|
||
|
|
||
|
void KoHSVWidget::update(const KoColor & fgColor, const KoColor & bgColor)
|
||
|
{
|
||
|
|
||
|
mHIn->blockSignals(true);
|
||
|
mSIn->blockSignals(true);
|
||
|
mVIn->blockSignals(true);
|
||
|
m_VSelector->blockSignals(true);
|
||
|
m_colorwheel->blockSignals(true);
|
||
|
|
||
|
//kdDebug() << "update. FG: " << fgColor.color() << ", bg: " << bgColor.color() << endl;
|
||
|
m_fgColor = fgColor;
|
||
|
m_bgColor = bgColor;
|
||
|
|
||
|
KoColor color = (m_ColorButton->current() == KDualColorButton::Foreground)? m_fgColor : m_bgColor;
|
||
|
|
||
|
int h = color.H();
|
||
|
int s = color.S();
|
||
|
int v = color.V();
|
||
|
|
||
|
mHIn->setValue(h);
|
||
|
mSIn->setValue(s);
|
||
|
mVIn->setValue(v);
|
||
|
|
||
|
m_VSelector->setHue(h);
|
||
|
m_VSelector->setSaturation(s);
|
||
|
m_VSelector->setValue(v);
|
||
|
m_VSelector->updateContents();
|
||
|
|
||
|
m_colorwheel->slotSetValue(color);
|
||
|
|
||
|
mHIn->blockSignals(false);
|
||
|
mSIn->blockSignals(false);
|
||
|
mVIn->blockSignals(false);
|
||
|
m_VSelector->blockSignals(false);
|
||
13 years ago
|
m_VSelector->repaint(false);
|
||
15 years ago
|
m_colorwheel->blockSignals(false);
|
||
|
}
|
||
|
|
||
14 years ago
|
void KoHSVWidget::slotFGColorSelected(const TQColor& c)
|
||
15 years ago
|
{
|
||
|
//kdDebug() << "slotFGColorSelected " << c << endl;
|
||
|
m_fgColor = KoColor(c);
|
||
|
|
||
|
changedFgColor();
|
||
|
}
|
||
|
|
||
14 years ago
|
void KoHSVWidget::slotBGColorSelected(const TQColor& c)
|
||
15 years ago
|
{
|
||
|
//kdDebug() << "slotBGColorSelected()" << c << endl;
|
||
|
m_bgColor = KoColor(c);
|
||
|
|
||
|
changedBgColor();
|
||
|
}
|
||
|
|
||
|
void KoHSVWidget::currentChanged(KDualColorButton::DualColor s)
|
||
|
{
|
||
|
//kdDebug() << "currentChanged\n";
|
||
|
if(s == KDualColorButton::Foreground)
|
||
|
slotFGColorSelected(m_ColorButton->currentColor());
|
||
|
else
|
||
|
slotBGColorSelected(m_ColorButton->currentColor());
|
||
|
emit sigModeChanged( s );
|
||
|
}
|
||
|
|
||
|
void KoHSVWidget::setMode(KDualColorButton::DualColor s)
|
||
|
{
|
||
|
m_ColorButton->setCurrent( s );
|
||
|
}
|
||
|
|
||
|
#include "ko_hsv_widget.moc"
|