File indexing completed on 2024-04-21 04:02:02
0001 /* 0002 KBlackBox - A simple game inspired by an emacs module 0003 0004 SPDX-FileCopyrightText: 1999-2000 Robert Cimrman <cimrman3@students.zcu.cz> 0005 SPDX-FileCopyrightText: 2007 Nicolas Roffet <nicolas-kde@roffet.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #ifndef KBBGRAPHICSITEMSET_H 0011 #define KBBGRAPHICSITEMSET_H 0012 0013 0014 0015 class QGraphicsScene; 0016 #include <QList> 0017 0018 0019 class KBBItemWithPosition; 0020 0021 0022 0023 /** 0024 * @brief Set of graphic items with positions 0025 */ 0026 class KBBGraphicsItemSet 0027 { 0028 public: 0029 explicit KBBGraphicsItemSet(QGraphicsScene* scene); 0030 ~KBBGraphicsItemSet(); 0031 0032 0033 static const int NO_INDEX = -1; 0034 0035 /** 0036 * @brief A position of an item (anyone of them) 0037 */ 0038 int anyItemPosition(); 0039 0040 /** 0041 * @brief Number of items 0042 */ 0043 int count() const; 0044 0045 /** 0046 * @brief Remove all items 0047 */ 0048 void clear(); 0049 0050 /** 0051 * If an element is not visible, it is not contained. 0052 * @return false if the element is not contained or contained but not visible. 0053 */ 0054 bool containsVisible(int position); 0055 0056 /** 0057 * @brief Insert an item in the list 0058 * 0059 * @param item Item to insert. It must have a position: a box position or a border position. 0060 */ 0061 void insert(KBBItemWithPosition* item); 0062 0063 /** 0064 * @brief Return the item at the given position 0065 * 0066 * @param position Position of the item. 0067 */ 0068 KBBItemWithPosition* item(int position); 0069 0070 /** 0071 * @brief Remove item at given position 0072 * 0073 * @param position Position of the item to be removed. 0074 */ 0075 void remove(int position); 0076 0077 /** 0078 * @brief Change the visibility of an element 0079 */ 0080 void setVisible(const int position, const bool visible); 0081 0082 0083 private: 0084 bool contains(int position); 0085 int indexOf(int position); 0086 0087 QGraphicsScene* m_scene; 0088 QList<KBBItemWithPosition*> m_items; 0089 }; 0090 0091 #endif // KBBGRAPHICSITEMSET_H