/*************************************************************************** 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. * * * ***************************************************************************/ #include "main.h" #include "piecewidget.h" #include "kpuzzle.h" #include "kpuzzlegame.h" #include #include #include /* Constructor */ CPieceWidget::CPieceWidget(QWidget *parent) : QWidget(parent) { _game = NULL; } /* Destructor */ CPieceWidget::~CPieceWidget() { } /* Return a pixmap of the current piece, appropiately turned. */ QPixmap* CPieceWidget::currentPiece() const { return _game->currentPieceTurned(); } /* Rectangle in which the piece should be drawn * (necessary for centering the piece). */ QRect CPieceWidget::getPieceDrawRect() const { QSize sz = _game->pieceSizeDisp(); QSize own = this->size(); own -= sz; own /= 2; QRect rct(own.width(),own.height(),sz.width(),sz.height()); return rct; } /* Paint the widget. */ void CPieceWidget::paintEvent(QPaintEvent*) { /* The piece pixmap returned by currentPiece * is already appropiately turned. */ bitBlt(this,0,0,currentPiece(),0,0,_game->pieceSizeDisp().width(), _game->pieceSizeDisp().height()); } /* The slot for the "Next Piece" button under * this widget. */ void CPieceWidget::slotNextClicked() { if (_game->setNextPiece()) update(); } /* The slot for the "Previous Piece" button over * this widget. */ void CPieceWidget::slotPrevClicked() { if (_game->setPrevPiece()) update(); } /* The slot for the first "Turn" button to the * left of this widget. */ void CPieceWidget::slotTurn1Clicked() { /* The user may set whether this button should * turn or flip the piece. */ if (KGlobal::config()->readBoolEntry("TurnPiecesAround", SV_TURN_PIECES_AROUND)) _game->turnCW(); else _game->changeLRTurn(); update(); } /* The slot for the second "Turn" button to the * left of this widget. */ void CPieceWidget::slotTurn2Clicked() { if (KGlobal::config()->readBoolEntry("TurnPiecesAround", SV_TURN_PIECES_AROUND)) _game->turnCCW(); else _game->changeUDTurn(); update(); }