/***************************************************************************
 *   Copyright (C) 2004 by Hans Oischinger                                 *
 *   hans.oischinger@kdemail.net                                           *
 *                                                                         *
 *   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 Steet, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ***************************************************************************/
#include "rgbselwidgetimpl.h"

// KDE
#include <kselect.h>
#include <knuminput.h>

RGBSelWidgetImpl::RGBSelWidgetImpl(QWidget* parent, const char* name, WFlags fl)
: RGBSelWidget(parent,name,fl)
{
  m_currentColor = new QColor();
  connect(gradSelRed, SIGNAL(valueChanged(int)), this, SLOT(recalcColor()));
  connect(gradSelGreen, SIGNAL(valueChanged(int)), this, SLOT(recalcColor()));
  connect(gradSelBlue, SIGNAL(valueChanged(int)), this, SLOT(recalcColor()));
}

RGBSelWidgetImpl::~RGBSelWidgetImpl()
{
}


//  KSelector is really missing a slotSetValue or something
//  until then we need those three slots here:

void RGBSelWidgetImpl::slotSpinBoxGreenValChanged( int i )
{
  gradSelGreen->setValue(i);
}

void RGBSelWidgetImpl::slotSpinBoxRedValChanged( int i )
{
  gradSelRed->setValue(i);
}

void RGBSelWidgetImpl::slotSpinBoxBlueValChanged( int i )
{
  gradSelBlue->setValue(i);
}

void RGBSelWidgetImpl::recalcColor()
{
  QColor rgb(gradSelRed->value(), gradSelGreen->value(), gradSelBlue->value());
  if ( rgb != *m_currentColor )
  {
    emit(valueChanged(rgb));
    *m_currentColor = rgb;
  }
}

QColor RGBSelWidgetImpl::value( ) const
{
  return QColor(gradSelRed->value(), gradSelGreen->value(), gradSelBlue->value());
}

void RGBSelWidgetImpl::setValue( const QColor & c )
{
   spinBoxRed->setValue(c.red());
   spinBoxGreen->setValue(c.green());
   spinBoxBlue->setValue(c.blue());
}



#include "rgbselwidgetimpl.moc"

