/*************************************************************************** Description : KPuzzle - A KDE Jigsaw Puzzle Game Version : 0.2 Copyright : (C) 2000-2001 by Michael Wand EMail : mwand@gmx.de ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef PICVIEW_H #define PICVIEW_H #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include // #define PICVIEW_WIDTH 150.0 // #define PICVIEW_HEIGHT 100.0 #define PICVIEW_WIDTH 132.0 #define PICVIEW_HEIGHT 99.0 /* The CPicView class encapsulates a small widget which shows a miniature * version of the puzzle pixmap; either the complete pixmap or the pixmap as * the player has put it together to the moment is shown. */ class CPicview : public QWidget { Q_OBJECT public: /* Constructor. Parent is the KPuzzleView object. */ CPicview(QWidget *parent); /* Destructor */ virtual ~CPicview(); /* Data */ public: protected: /* Return the size of the pixmap this widget shows */ QSize pixmapSize() { return _pixmap->size(); } /* Size of the game pixmap */ QSize gamePixmapSize() { return _gamePixmapSize; } /* The pixmap the widget shows may be "padded" to fit * into a 4:3 frame. This is the real size, relevant for * translating mouse events etc. */ QSize realPixmapSize() { return _realPixmapSize; } /* The area shown in the game widget, transformed to the * coordinates of *this* widget. During the game, this * widget shows the vRect by a white dashed line. */ QRect vRect() { return QRect(_vRectTopLeft,_vRectSize); } /* Convent a position in this widget to a position on * the game pixmap. This is essentially a scaling. */ QPoint translate2GamePixmap(QPoint p); /* Convent a position on the game pixmap to a position in * this widget. This is essentially a scaling. */ QPoint translateFromGamePixmap(QPoint p); /* The ratio between the size of the game pixmap and the size of this widget. */ float scaleX() { return (float) realPixmapSize().width() / gamePixmapSize().width(); } float scaleY() { return (float) realPixmapSize().height() / gamePixmapSize().height(); } /* The pixmap this widget shows. */ QPixmap* _pixmap; /* The area shown in the game widget, transformed to the * coordinates of *this* widget. */ QPoint _vRectTopLeft; QSize _vRectSize; QSize _gamePixmapSize; QSize _realPixmapSize; /* Implementation */ public: /* Update the pixmap this widget is showing. */ void updatePixmap(QPixmap* p,QRect udRect); /* Update the pixmap this widget is showing. This function * is used when the player has correctly placed a piece. */ void addPiece(QPixmap* piece,QPoint pos); protected: /* Paint this widget. */ virtual void paintEvent(QPaintEvent* e); /* Mouse events. */ virtual void mouseMoveEvent(QMouseEvent* e); virtual void mousePressEvent(QMouseEvent* e); virtual void mouseReleaseEvent(QMouseEvent* e); /* Coordinate transformation */ virtual QPoint DPtoLP(QPoint p); public slots: /* Called when the area of the game pixmap visible in the * KGameWidget changes. Implies the change of the * _vRect variables. */ void slotChangeViewPos(QPoint pos); signals: /* Emitted when the user has clicked this widget, which signifies * the visible area of the game pixmap should change. */ void sigChangeViewPos(QPoint pos); }; #endif /* PICVIEW_H */