/***************************************************************************
                          kradioeduca.cpp  -  description
                             -------------------
    begin                : Wed Sep 6 2000
    copyright            : (C) 2000 by Javier Campos Morales
    email                : javi_c@ctv.es
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "kradioeduca.h"
#include "kradioeduca.moc"
#include <qpainter.h>
#include <qstyle.h>

KRadioEduca::KRadioEduca(QWidget *parent, const char *name ) : QRadioButton(parent,name)
{
doc=0;
}

KRadioEduca::~KRadioEduca()
{
delete doc;
}

#if QT_VERSION < 300
static int extraWidth( int gs )
{
    if ( gs == Qt::MotifStyle )
	return 8;
    else
	return 6;
}
#endif

/** reimpl */
void KRadioEduca::drawButtonLabel( QPainter *p)
{
    int x, y, w, h;
    int extra_width, indicator_width;
#if QT_VERSION < 300
    GUIStyle gs = style().guiStyle();
    QSize sz = style().indicatorSize();
    extra_width = extraWidth( gs );
    indicator_width = sz.width();
#else
    extra_width = 8;
    indicator_width = style().pixelMetric(QStyle::PM_ExclusiveIndicatorWidth, 0);
#endif
    y = 0;
    x = indicator_width + extra_width; //###
    w = width() - x;
    h = height();

     QRect cr(x,y,w,h);

	doc = new QSimpleRichText( text(), font() );
	doc->setWidth( 10 );

	doc->setWidth(p, cr.width() );
	int rw = doc->widthUsed() + extra_width;
	int rh = doc->height();
	int xo = 0;
	int yo = 0;

	this->resize( this->width(), rh);

  yo = (cr.height()-rh)/2;
#if QT_VERSION < 300
	if ( style() == WindowsStyle && !isEnabled() ) {
#else
	if ( !isEnabled() ) {
#endif
	    QColorGroup cg = colorGroup();
	    cg.setColor( QColorGroup::Text, cg.light() );
	    doc->draw(p, cr.x()+xo+1, cr.y()+yo+1, cr, cg, 0);
	}
	doc->draw(p, cr.x()+xo, cr.y()+yo, cr, colorGroup(), 0);

    if ( hasFocus() ) {
//	QRect br = style().itemRect( p, x, y, rw, rh+yo,
//				   AlignLeft|AlignVCenter|ShowPrefix,
//				   isEnabled(),
//				   pixmap(), text().visual() );
	QRect br(x,y,rw,rh+yo);

	br.setLeft( br.left()-3 );
	br.setRight( br.right()+2 );
	br.setTop( br.top()-2 );
	br.setBottom( br.bottom()+2);
	br = br.intersect( QRect(0,0,rw, rh+yo ) );
#if QT_VERSION < 300
	style().drawFocusRect(p, br, colorGroup());
#else
        style().drawPrimitive( QStyle::PE_FocusRect, p, br, colorGroup());
#endif
    }
}
