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

kblackbox

  • sources
  • kde-4.14
  • kdegames
  • kblackbox
kbbgraphicsitemball.cpp
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 #include "kbbgraphicsitemball.h"
31 
32 
33 
34 #include <QGraphicsSceneHoverEvent>
35 #include <QTimer>
36 
37 
38 #include "kbbgraphicsiteminteractioninfo.h"
39 #include "kbbgraphicsitemonbox.h"
40 #include "kbbscalablegraphicwidget.h"
41 #include "kbbthememanager.h"
42 
43 
44 
45 //
46 // Constructor / Destructor
47 //
48 
49 KBBGraphicsItemBall::KBBGraphicsItemBall(KBBScalableGraphicWidget::itemType itemType, KBBScalableGraphicWidget* parent, KBBThemeManager* themeManager, int boxPosition, int columns, int rows) : KBBGraphicsItemOnBox( itemType, parent, themeManager, boxPosition, columns, rows)
50 {
51  m_timer = NULL;
52  m_ballType = itemType;
53  m_themeManager = themeManager;
54 
55  setAcceptsHoverEvents(true);
56 
57  for (int i=0; i<8;i++)
58  m_interactionInfos[i] = NULL;
59 }
60 
61 
62 KBBGraphicsItemBall::~KBBGraphicsItemBall()
63 {
64  removeInteractionInfos();
65 }
66 
67 
68 
69 //
70 // Private slots
71 //
72 
73 void KBBGraphicsItemBall::showInteractions()
74 {
75  delete m_timer;
76  m_timer = NULL;
77 
78  const int offsetX[8] = {0, 1, 2, 2, 2, 1, 0, 0};
79  const int offsetY[8] = {0, 0, 0, 1, 2, 2, 2, 1};
80  qreal posX;
81  qreal posY;
82 
83  // General interactions for every balls:
84  for (int i=0; i<8;i++) {
85  posX = x() - KBBScalableGraphicWidget::RATIO/2 + offsetX[i]*KBBScalableGraphicWidget::RATIO;
86  posY = y() - KBBScalableGraphicWidget::RATIO/2 + offsetY[i]*KBBScalableGraphicWidget::RATIO;
87  KBBScalableGraphicWidget::itemType type = KBBScalableGraphicWidget::interactionInfoDeflection;
88  if (i%2 == 1)
89  type = KBBScalableGraphicWidget::interactionInfoHit;
90  m_interactionInfos[i] = new KBBGraphicsItemInteractionInfo(m_widget, m_themeManager, type, posX, posY, i*45 );
91  }
92 
93  // If the ball is on a border:
94  const KBBScalableGraphicWidget::itemType r = KBBScalableGraphicWidget::interactionInfoReflection;
95  const KBBScalableGraphicWidget::itemType rS = KBBScalableGraphicWidget::interactionInfoReflectionSym;
96  if (position()<m_columns) {
97  m_interactionInfos[0]->setType(r);
98  m_interactionInfos[2]->setType(rS);
99  }
100  if (position()>=m_columns*(m_rows-1)) {
101  m_interactionInfos[4]->setType(r);
102  m_interactionInfos[6]->setType(rS);
103  }
104  if (position()%m_columns == 0) {
105  m_interactionInfos[6]->setType(r);
106  m_interactionInfos[0]->setType(rS);
107  }
108  if (position()%m_columns == (m_columns-1)) {
109  m_interactionInfos[2]->setType(r);
110  m_interactionInfos[4]->setType(rS);
111  }
112 
113  // If the ball is on a corner:
114  const KBBScalableGraphicWidget::itemType n = KBBScalableGraphicWidget::interactionInfoNothing;
115  if (position()==0)
116  m_interactionInfos[0]->setType(n);
117  if (position()==m_columns-1)
118  m_interactionInfos[2]->setType(n);
119  if (position()==m_rows*m_columns-1)
120  m_interactionInfos[4]->setType(n);
121  if (position()==(m_rows-1)*m_columns)
122  m_interactionInfos[6]->setType(n);
123 }
124 
125 
126 
127 //
128 // Private
129 //
130 
131 void KBBGraphicsItemBall::hoverEnterEvent (QGraphicsSceneHoverEvent*)
132 {
133  if (m_timer==NULL) {
134  m_timer = new QTimer(this);
135  connect(m_timer, SIGNAL(timeout()), this, SLOT(showInteractions()));
136  m_timer->start(TIME_TO_WAIT_BEFORE_SHOWING_INTERACTIONS);
137  }
138 }
139 
140 
141 void KBBGraphicsItemBall::hoverLeaveEvent (QGraphicsSceneHoverEvent*)
142 {
143  delete m_timer;
144  m_timer = NULL;
145  removeInteractionInfos();
146 }
147 
148 
149 void KBBGraphicsItemBall::removeInteractionInfos()
150 {
151  for (int i=0; i<8;i++) {
152  delete m_interactionInfos[i];
153  m_interactionInfos[i] = NULL;
154  }
155 }
156 
157 #include "kbbgraphicsitemball.moc"
QGraphicsItem::x
qreal x() const
QGraphicsItem::y
qreal y() const
KBBGraphicsItemOnBox
Item on the box on the scalable graphic widget.
Definition: kbbgraphicsitemonbox.h:50
kbbgraphicsitemonbox.h
KBBScalableGraphicWidget::interactionInfoReflection
Definition: kbbscalablegraphicwidget.h:111
KBBScalableGraphicWidget
Scalable graphic central widget for KBlackBox.
Definition: kbbscalablegraphicwidget.h:62
QGraphicsSvgItem::type
virtual int type() const
KBBGraphicsItemBall::KBBGraphicsItemBall
KBBGraphicsItemBall(KBBScalableGraphicWidget::itemType itemType, KBBScalableGraphicWidget *parent, KBBThemeManager *themeManager, int boxPosition, int columns, int rows)
Constructor.
Definition: kbbgraphicsitemball.cpp:49
kbbgraphicsitemball.h
KBBGraphicsItemOnBox::m_widget
KBBScalableGraphicWidget * m_widget
Definition: kbbgraphicsitemonbox.h:67
kbbgraphicsiteminteractioninfo.h
QTimer
KBBGraphicsItemOnBox::position
int position()
Definition: kbbgraphicsitemonbox.cpp:71
KBBScalableGraphicWidget::interactionInfoHit
Definition: kbbscalablegraphicwidget.h:109
kbbscalablegraphicwidget.h
QGraphicsSceneHoverEvent
KBBGraphicsItemInteractionInfo
Interaction information around a ball on the scalable graphic widget.
Definition: kbbgraphicsiteminteractioninfo.h:50
KBBScalableGraphicWidget::interactionInfoNothing
Definition: kbbscalablegraphicwidget.h:110
KBBScalableGraphicWidget::interactionInfoDeflection
Definition: kbbscalablegraphicwidget.h:108
KBBScalableGraphicWidget::interactionInfoReflectionSym
Definition: kbbscalablegraphicwidget.h:112
QGraphicsItem::setAcceptsHoverEvents
void setAcceptsHoverEvents(bool enabled)
KBBGraphicsItemOnBox::m_columns
int m_columns
Definition: kbbgraphicsitemonbox.h:68
KBBScalableGraphicWidget::RATIO
static int const RATIO
Width and height of a single square on the black box.
Definition: kbbscalablegraphicwidget.h:81
QTimer::start
void start(int msec)
KBBGraphicsItemBall::TIME_TO_WAIT_BEFORE_SHOWING_INTERACTIONS
static const int TIME_TO_WAIT_BEFORE_SHOWING_INTERACTIONS
Definition: kbbgraphicsitemball.h:55
KBBThemeManager
Theme manager of the scalable graphic widget.
Definition: kbbthememanager.h:51
KBBGraphicsItemBall::~KBBGraphicsItemBall
~KBBGraphicsItemBall()
Definition: kbbgraphicsitemball.cpp:62
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KBBGraphicsItemOnBox::m_rows
int m_rows
Definition: kbbgraphicsitemonbox.h:69
KBBGraphicsItemInteractionInfo::setType
void setType(KBBScalableGraphicWidget::itemType type)
Definition: kbbgraphicsiteminteractioninfo.cpp:57
KBBScalableGraphicWidget::itemType
itemType
Every graphic items.
Definition: kbbscalablegraphicwidget.h:89
kbbthememanager.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:20 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