/***************************************************************************
 *   Copyright (C) 2005 by Ian Reinhart Geiser                             *
 *   geiseri@sourcextreme.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.             *
 ***************************************************************************/

#ifndef DHW_WIDGET_H
#define DHW_WIDGET_H
#include <QFrame>
#include <QPixmap>

class QRubberBand;
class DHWPage;
class QTimer;
class DHWWidget : public QFrame
{
	Q_OBJECT
	Q_PROPERTY( int currentLayer READ currentLayer WRITE setCurrentLayer )
	Q_PROPERTY( bool antialias READ antialias WRITE setAntialias )
	Q_PROPERTY( QRect selection READ selection )

	public:
		DHWWidget( QWidget *parent = 0);
		~DHWWidget();

		void setPage( DHWPage *page );
		DHWPage *page();

		int currentLayer() const;
		void setCurrentLayer( int currentLayer);

		bool antialias() const;
		void setAntialias( bool aa );
		QRect selection() const;

		void resetSelection();

	private slots:
		void updateImage( bool fast = false );
protected:
		virtual void paintEvent ( QPaintEvent * event );
		virtual void mouseMoveEvent ( QMouseEvent * event );
		virtual void mousePressEvent ( QMouseEvent * event );
		virtual void mouseReleaseEvent ( QMouseEvent * event );
		virtual void keyPressEvent ( QKeyEvent * event );
		virtual void resizeEvent( QResizeEvent * event );
	private:
		QImage m_cacheImage;
		void updateCorners();
		DHWPage *mPage;
		int mCurrentLayer;
		bool mAntialiased;
		QRubberBand *mRubberBand;
		QPoint mStartPoint;
		bool mInDrag;
		QTimer *mRepaintTimer;
};
#endif

