• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kblackbox

  • kde-4.x
  • kdegames
  • kblackbox
kbbscalablegraphicwidget.h
Go to the documentation of this file.
1 //
2 // KBlackBox
3 //
4 // A simple game inspired by an emacs module
5 //
6 /***************************************************************************
7  * Copyright (c) 1999-2000, Robert Cimrman *
8  * cimrman3@students.zcu.cz *
9  * *
10  * Copyright (c) 2007, Nicolas Roffet *
11  * nicolas-kde@roffet.com *
12  * *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the *
26  * Free Software Foundation, Inc., *
27  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
28  ***************************************************************************/
29 
30 
31 
32 #ifndef KBBSCALABLEGRAPHICWIDGET_H
33 #define KBBSCALABLEGRAPHICWIDGET_H
34 
35 
36 class QAction;
37 class QGraphicsScene;
38 #include <QGraphicsView>
39 class QLCDNumber;
40 class QResizeEvent;
41 
42 
43 class KGamePopupItem;
44 class QPushButton;
45 
46 
47 class KBBBallsOnBoard;
48 class KBBGameDoc;
49 class KBBGraphicsItem;
50 class KBBGraphicsItemBallRepository;
51 class KBBGraphicsItemBlackBox;
52 class KBBGraphicsItemCursor;
53 class KBBGraphicsItemRay;
54 class KBBGraphicsItemSet;
55 class KBBThemeManager;
56 
57 
58 
62 class KBBScalableGraphicWidget : public QGraphicsView
63 {
64  Q_OBJECT
65 
66  public:
74  static int const BORDER_SIZE = 50;
75 
81  static int const RATIO = 25;
82 
89  enum itemType {
90  background=0,
91  informationBackground=1,
92  blackbox=2,
93  blackboxGrid=3,
94  tutorialMarker=4,
95  markerNothing=5,
96  solutionRay=6,
97  playerRay=7,
98  resultBackground=8,
99  resultBackgroundHighlight=9,
100  resultReflection=10,
101  resultHit=11,
102  resultText=12,
103  solutionBall=13,
104  playerBall=14,
105  unsureBall=15,
106  wrongPlayerBall=16,
107  rightPlayerBall=17,
108  interactionInfoDeflection=18,
109  interactionInfoHit=19,
110  interactionInfoNothing=20,
111  interactionInfoReflection=21,
112  interactionInfoReflectionSym=22,
113  laser0=23,
114  laser90=24,
115  laser180=25,
116  laser270=26,
117  cursor=27
118  };
119 
120 
124  explicit KBBScalableGraphicWidget(KBBGameDoc* gameDoc, KBBThemeManager* themeManager, QAction* done);
125  ~KBBScalableGraphicWidget();
126 
127 
128  void addBall(int boxPosition);
129  void addBall(int boxPosition, int outsidePosition);
130  void addBallUnsure(const int boxPosition);
131  void addMarkerNothing(const int boxPosition);
132  void drawRay(const int borderPosition);
133  void mouseBorderClick(const int borderPosition);
134  void mouseBoxClick(const Qt::MouseButton button, int boxPosition);
135  int moveBall(const int boxPositionFrom, const int boxPositionTo);
136  int moveMarkerNothing(const int boxPositionFrom, const int boxPositionTo);
137  void newGame(int columns, int rows, int ballNumber);
138 
145  void popupText(const QString& text, int time = 5000);
146 
147  int positionAfterMovingBall(const int boxPositionFrom, const int boxPositionTo) const;
148 
149  void setPause(bool state);
150  void removeAllBalls();
151  void removeBall(const int boxPosition);
152  void removeRay();
153  void resizeEvent(QResizeEvent*) Q_DECL_OVERRIDE;
154  QGraphicsScene* scene();
155  void setScore(int score);
156 
163  void solve(const bool continueGame);
164 
165  void toggleCursor();
166 
167  public slots:
168  void cursorOff();
169  void hoverMovePosition(int newPosition);
170  void cursorAtNewPosition(int borderPosition);
171  void keyboardEnter();
172  void keyboardMoveDown();
173  void keyboardMoveLeft();
174  void keyboardMoveRight();
175  void keyboardMoveUp();
176  void keyboardSpace();
177 
178 
179  protected:
180  void drawBackground(QPainter* painter, const QRectF&) Q_DECL_OVERRIDE;
181 
182 
183  private:
189  static int const MINIMUM_SIZE = 250;
190 
191  static int const OFFSET_DONE_BUTTON = 12;
192 
193  void fillBallsOutside();
194  void removeMarkerNothing(const int boxPosition);
195  void setBallUnsure(const int boxPosition, const bool unsure);
196  void setInputAccepted(bool inputAccepted);
197  void switchBall();
198  void switchMarker();
199  void updateDoneButton();
200  void useLaser(const int incomingPosition);
201 
202 
203  // Graphics items
204  KBBGraphicsItemBlackBox* m_blackbox;
205  KBBGraphicsItemSet* m_balls;
206  KBBGraphicsItemSet* m_ballsSolution;
207  KBBGraphicsItemSet* m_ballsUnsure;
208  KBBGraphicsItemCursor* m_cursor;
209  KBBGraphicsItemBallRepository* m_ballRepository;
210  KBBGraphicsItemSet* m_lasers;
211  KBBGraphicsItemSet* m_markersNothing;
212  KBBGraphicsItemSet* m_rayResults;
213  KBBGraphicsItemRay* m_playerRay;
214  KBBGraphicsItemRay* m_solutionRay;
215 
216 
223  QRectF m_rectBackground;
224 
225  // Various member variables
226  int m_ballNumber;
227  KBBBallsOnBoard* m_boardBalls;
228  KBBBallsOnBoard* m_boardBallsPlaced;
229  int m_columns;
230  QAction* m_doneAction;
231  QPushButton* m_doneButton;
232  KBBGameDoc* m_gameDoc;
233  KGamePopupItem* m_infoScore;
234  bool m_inputAccepted;
235  bool m_pause;
236  int m_rayNumber;
237 
238  int m_rows;
239  QGraphicsScene* m_scene; //TODO: Remove it because scene() already gives it back.
240  QLCDNumber* m_score;
241  KBBThemeManager* m_themeManager;
242  bool m_cursorFollowsMouse; //enable cursor following
243 };
244 
245 #endif // KBBSCALABLEGRAPHICWIDGET_H
KBBScalableGraphicWidget::solutionBall
Definition: kbbscalablegraphicwidget.h:103
QResizeEvent
KBBScalableGraphicWidget::mouseBorderClick
void mouseBorderClick(const int borderPosition)
Definition: kbbscalablegraphicwidget.cpp:203
KBBScalableGraphicWidget::addMarkerNothing
void addMarkerNothing(const int boxPosition)
Definition: kbbscalablegraphicwidget.cpp:181
KBBScalableGraphicWidget::laser180
Definition: kbbscalablegraphicwidget.h:115
QGraphicsScene
KBBScalableGraphicWidget::removeRay
void removeRay()
Definition: kbbscalablegraphicwidget.cpp:373
QWidget::cursor
QCursor cursor() const
KBBScalableGraphicWidget::moveBall
int moveBall(const int boxPositionFrom, const int boxPositionTo)
Definition: kbbscalablegraphicwidget.cpp:222
KBBScalableGraphicWidget::cursorOff
void cursorOff()
Definition: kbbscalablegraphicwidget.cpp:622
KBBGraphicsItem
Graphic item of the scalable graphic widget.
Definition: kbbgraphicsitem.h:44
KBBScalableGraphicWidget::keyboardMoveUp
void keyboardMoveUp()
Definition: kbbscalablegraphicwidget.cpp:471
KBBScalableGraphicWidget::scene
QGraphicsScene * scene()
Definition: kbbscalablegraphicwidget.cpp:380
KBBGraphicsItemSet
Set of graphic items with positions.
Definition: kbbgraphicsitemset.h:46
KBBScalableGraphicWidget::keyboardMoveDown
void keyboardMoveDown()
Definition: kbbscalablegraphicwidget.cpp:447
KBBScalableGraphicWidget::interactionInfoReflection
Definition: kbbscalablegraphicwidget.h:111
KBBScalableGraphicWidget
Scalable graphic central widget for KBlackBox.
Definition: kbbscalablegraphicwidget.h:62
KBBScalableGraphicWidget::cursorAtNewPosition
void cursorAtNewPosition(int borderPosition)
Definition: kbbscalablegraphicwidget.cpp:418
KBBScalableGraphicWidget::hoverMovePosition
void hoverMovePosition(int newPosition)
Definition: kbbscalablegraphicwidget.cpp:604
KBBGraphicsItemBlackBox
The black box in the scalable graphic widget.
Definition: kbbgraphicsitemblackbox.h:52
KBBScalableGraphicWidget::addBallUnsure
void addBallUnsure(const int boxPosition)
Definition: kbbscalablegraphicwidget.cpp:174
KBBScalableGraphicWidget::markerNothing
Definition: kbbscalablegraphicwidget.h:95
KBBScalableGraphicWidget::setScore
void setScore(int score)
Definition: kbbscalablegraphicwidget.cpp:386
KBBScalableGraphicWidget::playerBall
Definition: kbbscalablegraphicwidget.h:104
KBBScalableGraphicWidget::resultBackground
Definition: kbbscalablegraphicwidget.h:98
KBBScalableGraphicWidget::moveMarkerNothing
int moveMarkerNothing(const int boxPositionFrom, const int boxPositionTo)
Definition: kbbscalablegraphicwidget.cpp:242
KBBGameDoc
Game document (Logical board)
Definition: kbbgamedoc.h:56
KBBScalableGraphicWidget::drawRay
void drawRay(const int borderPosition)
Definition: kbbscalablegraphicwidget.cpp:192
KBBScalableGraphicWidget::solutionRay
Definition: kbbscalablegraphicwidget.h:96
KBBScalableGraphicWidget::informationBackground
Definition: kbbscalablegraphicwidget.h:91
KBBGraphicsItemRay
Ray on the scalable graphic widget of KBlackBox.
Definition: kbbgraphicsitemray.h:52
KBBScalableGraphicWidget::drawBackground
void drawBackground(QPainter *painter, const QRectF &) Q_DECL_OVERRIDE
Definition: kbbscalablegraphicwidget.cpp:494
KBBScalableGraphicWidget::interactionInfoHit
Definition: kbbscalablegraphicwidget.h:109
KBBScalableGraphicWidget::unsureBall
Definition: kbbscalablegraphicwidget.h:105
KBBScalableGraphicWidget::toggleCursor
void toggleCursor()
Definition: kbbscalablegraphicwidget.cpp:614
KBBScalableGraphicWidget::KBBScalableGraphicWidget
KBBScalableGraphicWidget(KBBGameDoc *gameDoc, KBBThemeManager *themeManager, QAction *done)
Constructor.
Definition: kbbscalablegraphicwidget.cpp:67
QPainter
KBBScalableGraphicWidget::tutorialMarker
Definition: kbbscalablegraphicwidget.h:94
KBBScalableGraphicWidget::resizeEvent
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE
Definition: kbbscalablegraphicwidget.cpp:325
KBBScalableGraphicWidget::rightPlayerBall
Definition: kbbscalablegraphicwidget.h:107
KBBScalableGraphicWidget::BORDER_SIZE
static int const BORDER_SIZE
Distance between the black box and the widget border.
Definition: kbbscalablegraphicwidget.h:74
KBBScalableGraphicWidget::keyboardMoveLeft
void keyboardMoveLeft()
Definition: kbbscalablegraphicwidget.cpp:455
KBBScalableGraphicWidget::playerRay
Definition: kbbscalablegraphicwidget.h:97
QString
KBBScalableGraphicWidget::setPause
void setPause(bool state)
Definition: kbbscalablegraphicwidget.cpp:313
KBBScalableGraphicWidget::popupText
void popupText(const QString &text, int time=5000)
Message to display.
Definition: kbbscalablegraphicwidget.cpp:293
KBBScalableGraphicWidget::positionAfterMovingBall
int positionAfterMovingBall(const int boxPositionFrom, const int boxPositionTo) const
Definition: kbbscalablegraphicwidget.cpp:304
KBBScalableGraphicWidget::blackbox
Definition: kbbscalablegraphicwidget.h:92
KBBScalableGraphicWidget::mouseBoxClick
void mouseBoxClick(const Qt::MouseButton button, int boxPosition)
Definition: kbbscalablegraphicwidget.cpp:211
KBBScalableGraphicWidget::resultText
Definition: kbbscalablegraphicwidget.h:102
KBBGraphicsItemCursor
"Cursor" on the scalable graphic widget
Definition: kbbgraphicsitemcursor.h:44
KBBScalableGraphicWidget::blackboxGrid
Definition: kbbscalablegraphicwidget.h:93
KBBScalableGraphicWidget::interactionInfoNothing
Definition: kbbscalablegraphicwidget.h:110
KBBScalableGraphicWidget::resultHit
Definition: kbbscalablegraphicwidget.h:101
KBBScalableGraphicWidget::laser90
Definition: kbbscalablegraphicwidget.h:114
KBBScalableGraphicWidget::interactionInfoDeflection
Definition: kbbscalablegraphicwidget.h:108
KBBScalableGraphicWidget::removeAllBalls
void removeAllBalls()
Definition: kbbscalablegraphicwidget.cpp:352
KBBScalableGraphicWidget::interactionInfoReflectionSym
Definition: kbbscalablegraphicwidget.h:112
KBBScalableGraphicWidget::keyboardEnter
void keyboardEnter()
Definition: kbbscalablegraphicwidget.cpp:435
QRectF
KBBScalableGraphicWidget::RATIO
static int const RATIO
Width and height of a single square on the black box.
Definition: kbbscalablegraphicwidget.h:81
QAction
KBBScalableGraphicWidget::keyboardSpace
void keyboardSpace()
Definition: kbbscalablegraphicwidget.cpp:479
KBBScalableGraphicWidget::~KBBScalableGraphicWidget
~KBBScalableGraphicWidget()
Definition: kbbscalablegraphicwidget.cpp:131
KBBScalableGraphicWidget::keyboardMoveRight
void keyboardMoveRight()
Definition: kbbscalablegraphicwidget.cpp:463
KBBScalableGraphicWidget::addBall
void addBall(int boxPosition)
Definition: kbbscalablegraphicwidget.cpp:151
QLCDNumber
QPushButton
KBBGraphicsItemBallRepository
The balls the player has to place.
Definition: kbbgraphicsitemballrepository.h:45
KBBThemeManager
Theme manager of the scalable graphic widget.
Definition: kbbthememanager.h:51
KBBScalableGraphicWidget::solve
void solve(const bool continueGame)
display the solution
Definition: kbbscalablegraphicwidget.cpp:392
KBBScalableGraphicWidget::laser270
Definition: kbbscalablegraphicwidget.h:116
KBBScalableGraphicWidget::newGame
void newGame(int columns, int rows, int ballNumber)
Definition: kbbscalablegraphicwidget.cpp:252
KBBScalableGraphicWidget::background
Definition: kbbscalablegraphicwidget.h:90
QGraphicsView
KBBScalableGraphicWidget::resultBackgroundHighlight
Definition: kbbscalablegraphicwidget.h:99
KBBScalableGraphicWidget::laser0
Definition: kbbscalablegraphicwidget.h:113
KBBScalableGraphicWidget::resultReflection
Definition: kbbscalablegraphicwidget.h:100
KBBScalableGraphicWidget::itemType
itemType
Every graphic items.
Definition: kbbscalablegraphicwidget.h:89
KBBScalableGraphicWidget::wrongPlayerBall
Definition: kbbscalablegraphicwidget.h:106
KBBBallsOnBoard
Set of balls (or various objects) with positions on the board.
Definition: kbbballsonboard.h:62
KBBScalableGraphicWidget::removeBall
void removeBall(const int boxPosition)
Definition: kbbscalablegraphicwidget.cpp:360
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Thu Feb 14 2019 22:24:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kblackbox

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

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal