/*************************************************************************** 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 KPUZZLEWIDGET_H #define KPUZZLEWIDGET_H #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include class KGameWidget; class KPuzzleGame; class CPieceWidget; class CPicview; /* These are global game pixmaps. Before any function uses one, it has to * call useGamePixmap(int) to ensure the pixmap is available. */ #define GP_BIGLOGO 0x1 #define GP_PAUSE 0x2 #define GP_WIN 0x4 #define GP_LOSE 0x8 #define GP_LOGO 0x10 #define GP_BACKGROUND 0x20 /* The central widget of this application. It is created and used by the * KPuzzle widget class. */ class KPuzzleView : public QWidget { Q_OBJECT public: /* Constructor */ KPuzzleView(QWidget *parent = 0, const char *name = 0); /* Destructor */ virtual ~KPuzzleView(); /* Data */ public: /* Some actions which need to be accessible after the * creation of the corresponding menu entries. */ KAction*& actSave() { return _actSave; } KAction*& actSaveAs() { return _actSaveAs; } KAction*& actTerminate() { return _actTerminate; } KAction*& actShowLarge() { return _actShowLarge; } KAction*& actShowMainPixmap() { return _actShowMainPixmap; } KAction*& actPause() { return _actPause; } KAction*& actHighscores() { return _actHighscores; } /* Game status, little more than a shortcut for game()->status() */ int status(); /* Subwidget showing the elapsed time */ QLCDNumber* time() { return _time; } /* Picture viewers - subwidgets showing a small version * of the current picture. */ CPicview* picview() { return _picview; } CPicview* fullview() { return _fullview; } /* The main playing area. */ KGameWidget* gameWidget() { return _gameWidget; } /* The piece selection widget. */ CPieceWidget* pieceWidget() { return _pieceWidget; } /* The application object. */ KPuzzleGame* game() { return _game; } /* XXX */ void setLargePxm(QPixmap* p) { if (_largePxm) delete _largePxm; _largePxm = p; } /* Load game pixmaps. May have visible effect on slower computers */ void useGamePixmap(int which); /* Unload game pixmaps. May have visible effect on slower computers */ void freeGamePixmap(int which); protected: /* Some actions which need to be accessible after the * creation of the corresponding menu entries. */ KAction* _actSave; KAction* _actSaveAs; KAction* _actTerminate; KAction* _actShowLarge; KAction* _actShowMainPixmap; KAction* _actPause; KAction* _actHighscores; /* All the subwidgets of this central widget. */ KGameWidget* _gameWidget; QPushButton* _bLeft; QPushButton* _bRight; QPushButton* _bUp; QPushButton* _bDown; CPieceWidget* _pieceWidget; QPushButton* _bNextPiece; QPushButton* _bPrevPiece; QPushButton* _bTurn1; QPushButton* _bTurn2; CPicview* _picview; CPicview* _fullview; QLCDNumber* _score; QLCDNumber* _time; /* The application object. */ KPuzzleGame* _game; /* XXX */ QPixmap* _largePxm; /* The game pixmaps. Any function wishing to use them must call * useGamePixmap(int) first to ensure that these pixmaps are loaded. */ QPixmap* _logoPxm; QPixmap* _bigLogoPxm; QPixmap* _winPxm; QPixmap* _losePxm; QPixmap* _pausePxm; QPixmap* _backgroundPxm; /* XXX */ int _usedGamePixmaps; /* Implementation */ public: /* Update game widget & piece widget */ void updateAll(); /* Change the status of the moving buttons, these are the buttons * used to change the visible part of the playing area */ void updateButtons(bool b1,bool b2,bool b3,bool b4); /* Show/hide a message on the status bar */ void showStatusMsg(const QString s) { emit sigChangeStatusbar(s); } void hideStatusMsg() { ((KMainWindow*) parentWidget())->statusBar()->clear(); } /* Show (hide) all subwidgets if s is true (false). This is used * when the entire widget area is used to show a picture. */ void showAll(bool s); /* Show (hide) background pixmap if s is true (false). */ void showBackground(bool s); /* Changes the status of menu items. enable must be an or-ed * combination of the MI_* constants defined in main.h. */ void enableMenuItems(int enable); /* Create all subwidgets. */ void createPlayground(KPuzzleGame* g,bool unbearable); /* Destroy all subwidgets. */ void destroyPlayground(); /* Resets all game widgets and objects to the current status of the _game. * To be called from switchCurrentGame. */ void resetAll(); protected: /* Paint this widget. */ virtual void paintEvent(QPaintEvent* e); /* Process a mousePressEvent. */ virtual void mousePressEvent(QMouseEvent* e); /* Create a new game structure. */ KPuzzleGame* createNewGame(); /* Create a new game structure suitable for * a loaded game. */ KPuzzleGame* createLoadedGame(); /* Put a game structure into use. */ void switchCurrentGame(KPuzzleGame* ng); signals: /* Emitted to show a text on the status bar */ void sigChangeStatusbar(const QString&); public slots: /* Menu slots. */ void slotNewGame(); void slotOpenGame(); /* Called when the game should clean up, save highscores etc. */ void slotTerm(int reason); /* Called when the game object must be destroyed. */ void slotGameIsDone(); protected slots: /* Slot called on startup after the basic work is done. * Loads the background pixmap, which may theoretically * take some time. */ void slotLoadBackgroundPixmap(); }; #endif /* KPUZZLEVIEW_H */