1 /* 2 KBlackBox - A simple game inspired by an emacs module 3 4 SPDX-FileCopyrightText: 1999-2000 Robert Cimrman <cimrman3@students.zcu.cz> 5 SPDX-FileCopyrightText: 2007 Nicolas Roffet <nicolas-kde@roffet.com> 6 7 SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 10 #ifndef KBBGRAPHICSITEMSET_H 11 #define KBBGRAPHICSITEMSET_H 12 13 14 15 class QGraphicsScene; 16 #include <QList> 17 18 19 class KBBItemWithPosition; 20 21 22 23 /** 24 * @brief Set of graphic items with positions 25 */ 26 class KBBGraphicsItemSet 27 { 28 public: 29 explicit KBBGraphicsItemSet(QGraphicsScene* scene); 30 ~KBBGraphicsItemSet(); 31 32 33 static const int NO_INDEX = -1; 34 35 /** 36 * @brief A position of an item (anyone of them) 37 */ 38 int anyItemPosition(); 39 40 /** 41 * @brief Number of items 42 */ 43 int count() const; 44 45 /** 46 * @brief Remove all items 47 */ 48 void clear(); 49 50 /** 51 * If an element is not visible, it is not contained. 52 * @return false if the element is not contained or contained but not visible. 53 */ 54 bool containsVisible(int position); 55 56 /** 57 * @brief Insert an item in the list 58 * 59 * @param item Item to insert. It must have a position: a box position or a border position. 60 */ 61 void insert(KBBItemWithPosition* item); 62 63 /** 64 * @brief Return the item at the given position 65 * 66 * @param position Position of the item. 67 */ 68 KBBItemWithPosition* item(int position); 69 70 /** 71 * @brief Remove item at given position 72 * 73 * @param position Position of the item to be removed. 74 */ 75 void remove(int position); 76 77 /** 78 * @brief Change the visibility of an element 79 */ 80 void setVisible(const int position, const bool visible); 81 82 83 private: 84 bool contains(int position); 85 int indexOf(int position); 86 87 QGraphicsScene* m_scene; 88 QList<KBBItemWithPosition*> m_items; 89 }; 90 91 #endif // KBBGRAPHICSITEMSET_H 92