/*
 * Copyright (c) 2010 Nokia Corporation.
 */

#include "imagewidget.h"
#include "imageloader.h"
#include <QDebug>

ImageWidget::ImageWidget(QString path, QWidget *parent) :
    QWidget(parent)
{
    m_path = path;
    m_imageLoader = new ImageLoader(this);
    setContextMenuPolicy(Qt::NoContextMenu);
}

ImageWidget::~ImageWidget()
{
}

void ImageWidget::resizeEvent(QResizeEvent *e)
{
    QWidget::resizeEvent(e);
    m_pixmap = m_imageLoader->loadImage(m_path,size());
}

void ImageWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    if (!m_pixmap.isNull()) {
        QSize pixSize = m_pixmap.size();
        painter.drawPixmap((size().width()-pixSize.width())/2,
                           (size().height()-pixSize.height())/2
                           ,m_pixmap);
    }
}

