/***************************************************************************
 *   Copyright (C) 2008 by Ian Reinhart Geiser                             *
 *   geiseri@yahoo.com                                                     *
 *                                                                         *
 *   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 "displayframe.h"
#include <QPainter>
#include <QKeyEvent>
#include <QCursor>
#include <QApplication>
#include <QProcess>

DisplayFrame::DisplayFrame(QWidget *parent)
 : QWidget(parent)
{
	setWindowState( Qt::WindowFullScreen|Qt::WindowActive );
	QApplication::setOverrideCursor( QCursor( Qt::BlankCursor ) );
}

DisplayFrame::~DisplayFrame()
{
}

void DisplayFrame::paintEvent(QPaintEvent * event)
{
        QPainter painter(this);
        painter.fillRect(rect(), Qt::black);

	if( !m_image.isNull() )
	{
		QPoint pt = -(m_image.rect().center() - rect().center());
		painter.drawPixmap(pt,m_image);
	}
	else
        {
                painter.setPen( QPen(Qt::white, 6, Qt::DashDotLine, Qt::RoundCap ) );
	        painter.setRenderHint(QPainter::Antialiasing, true);
                painter.drawLine( 0,0, width(), height() );
                painter.drawLine( width(), 0, 0, height() );
        }
}

void DisplayFrame::setImage(const QPixmap & theValue)
{
	m_image = theValue.scaled( rect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
	update();
}

void DisplayFrame::keyPressEvent(QKeyEvent * event)
{
	switch( event->key() )
	{
		case Qt::Key_Escape:
			close();
		break;
		case Qt::Key_F5:
			qDebug("switch");
		break;
		case Qt::Key_PageDown:
			qDebug("before");
		break;
		case Qt::Key_PageUp:
			qDebug("after");
		break;
		case Qt::Key_B:
			qDebug("full");
		break;
		default:
			qDebug("Key %x", event->key() );
		break;
	};
}



