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

ksquares

  • sources
  • kde-4.14
  • kdegames
  • ksquares
  • src
gameboardscene.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006 by Matthew Williams <matt@milliams.com> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  ***************************************************************************/
9 
10 #ifndef GAMEBOARDSCENE_H
11 #define GAMEBOARDSCENE_H
12 
13 #include <QGraphicsScene>
14 
15 class QGraphicsEllipseItem;
16 class msg;
17 
27 class GameBoardScene : public QGraphicsScene
28 {
29  Q_OBJECT
30 
31  public:
38  GameBoardScene(int newWidth, int newHeight, QObject *parent = 0);
40  ~GameBoardScene();
45  const QSize minimumSizeHint() const;
46 
47  void acknowledgeMove(int x1, int y1, int x2, int y2);
48 
49  public slots:
55  void drawLine(int index, const QColor &colour);
60  void highlightLine(int index);
66  void drawSquare(int index, const QColor &colour);
68  void enableEvents() {acceptEvents = true;}
70  void disableEvents() {acceptEvents = false;}
71 
72  protected:
78  QList<QGraphicsEllipseItem*> getTwoNearestPoints(const QPointF &pos) const;
79 
85  bool isLineAlready(const QList<QGraphicsEllipseItem*> &pointPair) const;
90  void addLineToIndex(const QList<QGraphicsEllipseItem*> &pointPair);
91 
92  //conversion functions
98  int indexFromPointPair(const QList<QGraphicsEllipseItem*> &pointPair) const; //given a pointPair, returns the index of the line between them. If not a valid line, returns -1
104  QLineF lineFromIndex(int index) const; //all external calls will need to be passed through this to convert to local coords
105 
107  QGraphicsLineItem* indicatorLine;
108 
110  QList<bool> lineList; //Just kept in sync with the KSquaresGame one
111 
113  int QGraphicsEllipseItemType;
115  int width;
117  int height;
119  int spacing;
121  bool acceptEvents;
122 
123  //event handlers
124  //void mousePressEvent (QGraphicsSceneMouseEvent* mouseEvent);
125  void mouseReleaseEvent (QGraphicsSceneMouseEvent* mouseEvent);
126  void mouseMoveEvent (QGraphicsSceneMouseEvent* mouseEvent);
127 
128  signals:
130  void lineDrawn(int);
131 };
132 
133 #endif // GAMEBOARDSCENE_H
GameBoardScene::acknowledgeMove
void acknowledgeMove(int x1, int y1, int x2, int y2)
Definition: gameboardscene.cpp:247
GameBoardScene::spacing
int spacing
Pixel spacing for standard zoom.
Definition: gameboardscene.h:119
GameBoardScene::disableEvents
void disableEvents()
enables mouse events
Definition: gameboardscene.h:70
QGraphicsScene
GameBoardScene
Scene for displaying the game board.
Definition: gameboardscene.h:27
GameBoardScene::lineDrawn
void lineDrawn(int)
Emits the index of the closet (undrawn) line when a click is detected.
GameBoardScene::highlightLine
void highlightLine(int index)
Draw a temporary halo behind a line.
Definition: gameboardscene.cpp:93
GameBoardScene::QGraphicsEllipseItemType
int QGraphicsEllipseItemType
QGraphicsEllipseItem::type()
Definition: gameboardscene.h:113
GameBoardScene::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
Definition: gameboardscene.cpp:254
QPointF
GameBoardScene::indicatorLine
QGraphicsLineItem * indicatorLine
Moves to show where the next line will be drawn.
Definition: gameboardscene.h:107
GameBoardScene::lineList
QList< bool > lineList
A local list of lines (non-canon)
Definition: gameboardscene.h:110
GameBoardScene::height
int height
Height of the board.
Definition: gameboardscene.h:117
GameBoardScene::minimumSizeHint
const QSize minimumSizeHint() const
The smallest the view can be when 'auto-zoom' is off.
Definition: gameboardscene.cpp:215
QObject
QGraphicsLineItem
QGraphicsSceneMouseEvent
QList
QColor
QLineF
GameBoardScene::drawLine
void drawLine(int index, const QColor &colour)
Add the line to the scene so it shows up in the view.
Definition: gameboardscene.cpp:82
QSize
GameBoardScene::width
int width
Width of the board.
Definition: gameboardscene.h:115
GameBoardScene::indexFromPointPair
int indexFromPointPair(const QList< QGraphicsEllipseItem * > &pointPair) const
Takes a pair of QGraphicsEllipseItems and finds the index that relates to the line that's between the...
Definition: gameboardscene.cpp:107
GameBoardScene::addLineToIndex
void addLineToIndex(const QList< QGraphicsEllipseItem * > &pointPair)
Adds the line to the index for a specified pair of points.
Definition: gameboardscene.cpp:185
GameBoardScene::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
Definition: gameboardscene.cpp:226
GameBoardScene::GameBoardScene
GameBoardScene(int newWidth, int newHeight, QObject *parent=0)
Create a new gameboard scene with the appropriate size.
Definition: gameboardscene.cpp:21
GameBoardScene::getTwoNearestPoints
QList< QGraphicsEllipseItem * > getTwoNearestPoints(const QPointF &pos) const
Given a single location in the scene, gives the two nearest QGraphicsEllipseItem. ...
Definition: gameboardscene.cpp:194
GameBoardScene::~GameBoardScene
~GameBoardScene()
Destructor.
Definition: gameboardscene.cpp:76
GameBoardScene::lineFromIndex
QLineF lineFromIndex(int index) const
Takes a line-index and returns a QLineF located at that position.
Definition: gameboardscene.cpp:147
GameBoardScene::isLineAlready
bool isLineAlready(const QList< QGraphicsEllipseItem * > &pointPair) const
Given a pair of points, returns whether there is already a line there.
Definition: gameboardscene.cpp:176
GameBoardScene::enableEvents
void enableEvents()
disables mouse events
Definition: gameboardscene.h:68
GameBoardScene::drawSquare
void drawSquare(int index, const QColor &colour)
Fill a box to show it is owned be a particular player.
Definition: gameboardscene.cpp:100
QObject::parent
QObject * parent() const
QGraphicsEllipseItem
GameBoardScene::acceptEvents
bool acceptEvents
This property holds whether mouse events are enabled for this widget.
Definition: gameboardscene.h:121
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ksquares

Skip menu "ksquares"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

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