/***************************************************************************
                           qpicturelabel.cpp
                           -------------------
    copyright            : (C) 2004 by Jos van den Oever
    email                : jos@vandenoever.info
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "qpicturelabel.h"

#include <qpainter.h>
//Added by qt3to4:
#include <QPaintEvent>
#include <Q3Frame>

QPictureLabel::QPictureLabel(QWidget* parent, const char* name, Qt::WFlags f)
	: Q3Frame(parent, name, f) {
}
void
QPictureLabel::setPicture(const Q3Picture &p) {
	pict = p;
	update();
}
void
QPictureLabel::paintEvent(QPaintEvent *) {
	double mindim;
	QPainter paint(this);
	QRect r = pict.boundingRect();

	if (width() < height()) {
		mindim = width();
	} else {
		mindim = height();
	}
	// draw a bit smaller than what fits
	paint.translate(width()*0.1, height()*0.1);
	mindim *= 0.8;
	paint.scale(mindim/double(r.width()-1), mindim/double(r.height()-1));
	paint.drawPicture(-r.x(), -r.y(), pict);
	paint.drawRect(0,0,r.width(),r.height());
}
