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

kblackbox

  • sources
  • kde-4.12
  • kdegames
  • kblackbox
kbbgraphicsitemset.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 "kbbgraphicsitemset.h"
31 
32 
33 
34 #include <QGraphicsScene>
35 
36 
37 #include "kbbgraphicsitem.h"
38 #include "kbbitemwithposition.h"
39 
40 
41 
42 //
43 // Constructor / Destructor
44 //
45 
46 KBBGraphicsItemSet::KBBGraphicsItemSet(QGraphicsScene* scene)
47 {
48  m_scene = scene;
49 }
50 
51 
52 KBBGraphicsItemSet::~KBBGraphicsItemSet()
53 {
54  clear();
55 }
56 
57 
58 
59 //
60 // Public
61 //
62 
63 int KBBGraphicsItemSet::anyItemPosition()
64 {
65  if (m_items.count()>0)
66  return m_items.last()->position();
67  else
68  return NO_INDEX;
69 }
70 
71 
72 int KBBGraphicsItemSet::count() const
73 {
74  return m_items.count();
75 }
76 
77 
78 void KBBGraphicsItemSet::clear()
79 {
80  while (m_items.count()>0) {
81  remove(m_items.last()->position());
82  }
83 }
84 
85 
86 bool KBBGraphicsItemSet::contains(int position)
87 {
88  return (indexOf(position)!=NO_INDEX);
89 }
90 
91 
92 bool KBBGraphicsItemSet::containsVisible(int position)
93 {
94  int i = indexOf(position);
95 
96  if (i!=NO_INDEX) {
97  if(dynamic_cast<KBBGraphicsItem*>(m_items[i]))
98  return ((dynamic_cast<KBBGraphicsItem*>(m_items[i]))->isVisible());
99  else
100  return true;
101  } else
102  return false;
103 }
104 
105 
106 void KBBGraphicsItemSet::insert(KBBItemWithPosition* item)
107 {
108  if (contains(item->position()))
109  // We want to avoid duplicated item on a given position.
110  item->cleanDelete();
111  else
112  m_items.append(item);
113 }
114 
115 
116 KBBItemWithPosition* KBBGraphicsItemSet::item(int position)
117 {
118  KBBItemWithPosition* r = NULL;
119 
120  for (int i=0;i<m_items.count();i++)
121  if (m_items[i]->position()==position)
122  r = m_items[i];
123  return r;
124 }
125 
126 
127 void KBBGraphicsItemSet::remove(int position)
128 {
129  int i = indexOf(position);
130 
131  if (i!=NO_INDEX) {
132  m_items[i]->cleanDelete();
133  m_scene->update();
134  m_items.removeAt(i);
135  }
136 }
137 
138 
139 void KBBGraphicsItemSet::setVisible(const int position, const bool visible)
140 {
141  int i = indexOf(position);
142 
143  if (i!=NO_INDEX) {
144  if(dynamic_cast<KBBGraphicsItem*>(m_items[i]))
145  (dynamic_cast<KBBGraphicsItem*>(m_items[i]))->setVisible(visible);
146  }
147 }
148 
149 
150 
151 //
152 // Private
153 //
154 
155 int KBBGraphicsItemSet::indexOf(int position)
156 {
157  for(int i=0;i<m_items.count();i++)
158  if (m_items[i]->position()==position)
159  return i;
160 
161  return NO_INDEX;
162 }
kbbgraphicsitem.h
KBBGraphicsItemSet::count
int count() const
Number of items.
Definition: kbbgraphicsitemset.cpp:72
KBBGraphicsItemSet::containsVisible
bool containsVisible(int position)
If an element is not visible, it is not contained.
Definition: kbbgraphicsitemset.cpp:92
KBBGraphicsItem
Graphic item of the scalable graphic widget.
Definition: kbbgraphicsitem.h:44
KBBGraphicsItemSet::remove
void remove(int position)
Remove item at given position.
Definition: kbbgraphicsitemset.cpp:127
KBBGraphicsItemSet::anyItemPosition
int anyItemPosition()
A position of an item (anyone of them)
Definition: kbbgraphicsitemset.cpp:63
KBBGraphicsItemSet::KBBGraphicsItemSet
KBBGraphicsItemSet(QGraphicsScene *scene)
Definition: kbbgraphicsitemset.cpp:46
KBBItemWithPosition
Item with position.
Definition: kbbitemwithposition.h:37
KBBGraphicsItemSet::item
KBBItemWithPosition * item(int position)
Return the item at the given position.
Definition: kbbgraphicsitemset.cpp:116
KBBGraphicsItemSet::clear
void clear()
Remove all items.
Definition: kbbgraphicsitemset.cpp:78
KBBItemWithPosition::position
virtual int position()=0
KBBGraphicsItemSet::insert
void insert(KBBItemWithPosition *item)
Insert an item in the list.
Definition: kbbgraphicsitemset.cpp:106
KBBGraphicsItemSet::setVisible
void setVisible(const int position, const bool visible)
Change the visibility of an element.
Definition: kbbgraphicsitemset.cpp:139
KBBItemWithPosition::cleanDelete
virtual void cleanDelete()
Destructor for dependent QGraphicsItem Some QGraphicsItem s needs to delete other dependent QGraphics...
Definition: kbbitemwithposition.cpp:45
kbbitemwithposition.h
KBBGraphicsItemSet::NO_INDEX
static const int NO_INDEX
Definition: kbbgraphicsitemset.h:53
KBBGraphicsItemSet::~KBBGraphicsItemSet
~KBBGraphicsItemSet()
Definition: kbbgraphicsitemset.cpp:52
kbbgraphicsitemset.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:44:09 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