/***************************************************************************
 *   Copyright (C) 2004 by Christian Hubinger                              *
 *   e9806056@student.tuwien.ac.at                                         *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "kfbuttongroup.h"

// QT includes
#include <qbutton.h>
#include <qcolor.h>
#include <qpainter.h>
#include <qpixmap.h>
#include <qimage.h>

// KDE includes
#include <kdebug.h>

KFButtonGroup::KFButtonGroup(QWidget *parent, const char *name)
		: QVButtonGroup(parent, name) {
	m_childWidgets = new QPtrList<QButton>;	
}


KFButtonGroup::~KFButtonGroup() {}

int KFButtonGroup::insert ( QButton * button, int id/* = -1*/ ) {
	m_childWidgets->append( button );
	return QButtonGroup::insert ( button, id );
}

void KFButtonGroup::setPaletteBackgroundPixmap( const QPixmap& bg ) {
	kdDebug() << "KFButtonGroup::setPaletteBackgroundPixmap( const QPixmap& bg )" << endl;
	QPtrListIterator<QButton> it( *m_childWidgets );
	while ( it.current() ) {
		QButton *wid = *it;
		++it;
		setChildBackground( wid, bg );
	}
	
	QVButtonGroup::setPaletteBackgroundPixmap( bg );
}

void KFButtonGroup::setFont( const QFont & new_font ) {
	kdDebug() << "KFButtonGroup::setFont( const QFont & new_font )" << endl;
	QVButtonGroup::setFont( new_font );
	QPtrListIterator<QButton> it( *m_childWidgets );
	while ( it.current() ) {
		QButton *wid = *it;
		++it;
		wid->setFont( new_font );
	}
}

void KFButtonGroup::setPaletteForegroundColor( const QColor& new_color ) {
	kdDebug() << "KFButtonGroup::setPaletteForegroundColor( const QColor& new_color )" << endl;
	QVButtonGroup::setPaletteForegroundColor( new_color );
	QPtrListIterator<QButton> it( *m_childWidgets );
	while ( it.current() ) {
		QButton *wid = *it;
		++it;
		wid->setPaletteForegroundColor( new_color );
	}
}

void KFButtonGroup::setChildBackground( QWidget *child, QPixmap pic ) {
	QImage base ( width(), height(), 32 );
	base = pic.convertToImage();
	
	QImage tmpimage( base.copy(  child->x(), child->y(), child->width(), child->height() ) );
		
	QPixmap pix;
	pix.convertFromImage( tmpimage, AutoColor );
	child->setPaletteBackgroundPixmap( pix );
}



#include "kfbuttongroup.moc"
