• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kblackbox

kbbscalablegraphicwidget.h

Go to the documentation of this file.
00001 //
00002 // KBlackBox
00003 //
00004 // A simple game inspired by an emacs module
00005 //
00006 /***************************************************************************
00007  *   Copyright (c) 1999-2000, Robert Cimrman                               *
00008  *   cimrman3@students.zcu.cz                                              *
00009  *                                                                         *
00010  *   Copyright (c) 2007, Nicolas Roffet                                    *
00011  *   nicolas-kde@roffet.com                                                *
00012  *                                                                         *
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   (at your option) any later version.                                   *
00018  *                                                                         *
00019  *   This program is distributed in the hope that it will be useful,       *
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022  *   GNU General Public License for more details.                          *
00023  *                                                                         *
00024  *   You should have received a copy of the GNU General Public License     *
00025  *   along with this program; if not, write to the                         *
00026  *   Free Software Foundation, Inc.,                                       *
00027  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA               *
00028  ***************************************************************************/
00029 
00030 
00031 
00032 #ifndef KBBSCALABLEGRAPHICWIDGET_H
00033 #define KBBSCALABLEGRAPHICWIDGET_H
00034 
00035 
00036 class QAction;
00037 class QGraphicsScene;
00038 #include <QGraphicsView>
00039 class QResizeEvent;
00040 
00041 
00042 class KGameLCD;
00043 class KGamePopupItem;
00044 class KPushButton;
00045 
00046 
00047 class KBBBallsOnBoard;
00048 class KBBGameDoc;
00049 class KBBGraphicsItem;
00050 class KBBGraphicsItemBallRepository;
00051 class KBBGraphicsItemBlackBox;
00052 class KBBGraphicsItemCursor;
00053 class KBBGraphicsItemRay;
00054 class KBBGraphicsItemSet;
00055 class KBBThemeManager;
00056 
00057 
00058 
00062 class KBBScalableGraphicWidget : public QGraphicsView
00063 {
00064     Q_OBJECT
00065 
00066     public:
00074         static int const BORDER_SIZE = 50;
00075 
00081         static int const RATIO = 25;
00082 
00089         enum itemType {
00090             background=0,
00091             informationBackground=1,
00092             blackbox=2,
00093             blackboxGrid=3,
00094             tutorialMarker=4,
00095             markerNothing=5,
00096             solutionRay=6,
00097             playerRay=7,
00098             resultBackground=8,
00099             resultBackgroundHighlight=9,
00100             resultReflection=10,
00101             resultHit=11,
00102             resultText=12,
00103             solutionBall=13,
00104             playerBall=14,
00105             unsureBall=15,
00106             wrongPlayerBall=16,
00107             rightPlayerBall=17,
00108             interactionInfoDeflection=18,
00109             interactionInfoHit=19,
00110             interactionInfoNothing=20,
00111             interactionInfoReflection=21,
00112             interactionInfoReflectionSym=22,
00113             laser0=23,
00114             laser90=24,
00115             laser180=25,
00116             laser270=26,
00117             cursor=27
00118         };
00119         
00120         
00124         explicit KBBScalableGraphicWidget(KBBGameDoc* gameDoc, KBBThemeManager* themeManager, QAction* done);
00125         ~KBBScalableGraphicWidget();
00126 
00127 
00128         void addBall(int boxPosition);
00129         void addBall(int boxPosition, int outsidePosition);
00130         void addBallUnsure(const int boxPosition);
00131         void addMarkerNothing(const int boxPosition);
00132         void drawRay(const int borderPosition);
00133         void mouseBorderClick(const int borderPosition);
00134         void mouseBoxClick(const Qt::MouseButton button, int boxPosition);
00135         int moveBall(const int boxPositionFrom, const int boxPositionTo);
00136         int moveMarkerNothing(const int boxPositionFrom, const int boxPositionTo);
00137         void newGame(int columns, int rows, int ballNumber);
00138 
00145         void popupText(const QString& text, int time = 5000);
00146 
00147         int positionAfterMovingBall(const int boxPositionFrom, const int boxPositionTo) const;
00148 
00149         void setPause(bool state);
00150         void removeAllBalls();
00151         void removeBall(const int boxPosition);
00152         void removeRay();
00153         void resizeEvent(QResizeEvent*);
00154         QGraphicsScene* scene();
00155         void setScore(int score);
00156 
00163         void solve(const bool continueGame);
00164 
00165 
00166     public slots:
00167         void cursorAtNewPosition(int borderPosition);
00168         void keyboardEnter();
00169         void keyboardMoveDown();
00170         void keyboardMoveLeft();
00171         void keyboardMoveRight();
00172         void keyboardMoveUp();
00173         void keyboardSpace();
00174 
00175 
00176     protected:
00177         void drawBackground(QPainter* painter, const QRectF&);
00178 
00179 
00180     private:
00186         static int const MINIMUM_SIZE = 250;
00187 
00188         static int const OFFSET_DONE_BUTTON = 12;
00189 
00190         void fillBallsOutside();
00191         void removeMarkerNothing(const int boxPosition);
00192         void setBallUnsure(const int boxPosition, const bool unsure);
00193         void setInputAccepted(bool inputAccepted);
00194         void switchBall();
00195         void switchMarker();
00196         void updateDoneButton();
00197         void useLaser(const int incomingPosition);
00198         
00199         
00200         // Graphics items
00201         KBBGraphicsItemBlackBox* m_blackbox;
00202         KBBGraphicsItemSet* m_balls;
00203         KBBGraphicsItemSet* m_ballsSolution;
00204         KBBGraphicsItemSet* m_ballsUnsure;
00205         KBBGraphicsItemCursor* m_cursor;
00206         KBBGraphicsItemBallRepository* m_ballRepository;
00207         KBBGraphicsItemSet* m_lasers;
00208         KBBGraphicsItemSet* m_markersNothing;
00209         KBBGraphicsItemSet* m_rayResults;
00210         KBBGraphicsItemRay* m_playerRay;
00211         KBBGraphicsItemRay* m_solutionRay;
00212         
00213         
00220         QRectF m_rectBackground;
00221         
00222         // Various member variables
00223         int m_ballNumber;
00224         KBBBallsOnBoard* m_boardBalls;
00225         KBBBallsOnBoard* m_boardBallsPlaced;
00226         int m_columns;
00227         QAction* m_doneAction;
00228         KPushButton* m_doneButton;
00229         KBBGameDoc* m_gameDoc;
00230         KGamePopupItem* m_infoScore;
00231         bool m_inputAccepted;
00232         bool m_pause;
00233         int m_rayNumber;
00234         
00235         int m_rows;
00236         QGraphicsScene* m_scene; //TODO: Remove it because scene() already gives it back.
00237         KGameLCD* m_score;
00238         KBBThemeManager* m_themeManager;
00239 };
00240 
00241 #endif // KBBSCALABLEGRAPHICWIDGET_H

kblackbox

Skip menu "kblackbox"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal