File indexing completed on 2022-11-29 18:38:54

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 KBBGRAPHICSITEMRAYRESULT_H
0011 #define KBBGRAPHICSITEMRAYRESULT_H
0012 
0013 
0014 
0015 class QGraphicsScene;
0016 class QGraphicsSvgItem;
0017 
0018 
0019 #include "kbbgraphicsitem.h"
0020 #include "kbbgraphicsitemborder.h"
0021 #include "kbbitemwithposition.h"
0022 class KBBScalableGraphicWidget;
0023 class KBBThemeManager;
0024 
0025 
0026 
0027 /**
0028  * @brief Result of a laser ray shoot in the black box
0029  *
0030  * There 3 kinds of ray results:
0031  *   - HIT: if the laser ray hits a ball in the black box by entering at the considered position.
0032  *   - REFLECTION: if the laser ray exits the black box at the entrance point.
0033  *   - A number to display both positions where the laser ray entered and exited the black box. Both positions are opposite positions of each other and belong together.
0034  */
0035 class KBBGraphicsItemRayResult : public KBBGraphicsItemBorder, public KBBGraphicsItem, public KBBItemWithPosition
0036 {
0037     public:
0038         KBBGraphicsItemRayResult(KBBScalableGraphicWidget* parent, KBBThemeManager* themeManager, QGraphicsScene* scene, const int borderPosition, const int columns, const int rows, const int rayNumber);
0039 
0040 
0041         /**
0042          * @brief Destructor of the class and dependent object
0043          * Call this methode to destroy simultaneously this QGraphicsItem and all other dependent QGraphicsItems: The number or the sign.
0044          */
0045         void cleanDelete() override;
0046 
0047         /**
0048          * @brief Highlight the item
0049          * 
0050          * Usually used when the mouse goes over the item or over the opposite item.
0051          */
0052         void highlight(bool state) override;
0053 
0054         /**
0055          * @brief Highlight the item and the opposite one
0056          */
0057         void highlightBoth(bool state) override;
0058 
0059         /**
0060          * @brief Get the border position
0061          */
0062         int position() override;
0063 
0064         /**
0065          * @brief Define the opposite "ray result" item
0066          * 
0067          * Used if the result is not a HIT and not a REFLECTION. In the other case, the opoosite is the item itself and this method doesn't need to be called.
0068          * @param opposite Correspondent item with the same "number".
0069          */
0070         void setOpposite(KBBGraphicsItemRayResult* opposite);
0071 
0072         /**
0073          * @brief Set the pause state
0074          */
0075         void setPause(bool state) override;
0076 
0077 
0078     private:
0079         void hoverEnterEvent (QGraphicsSceneHoverEvent*) override;
0080         void hoverLeaveEvent (QGraphicsSceneHoverEvent*) override;
0081         
0082         QString m_elementIdResultBackground;
0083         QString m_elementIdResultBackgroundHighlight;
0084         QGraphicsSvgItem* m_notNumber;
0085         QGraphicsSimpleTextItem* m_number;
0086         KBBGraphicsItemRayResult* m_opposite;
0087         bool m_pause;
0088         QGraphicsScene* m_scene;
0089         KBBScalableGraphicWidget* m_widget;
0090 };
0091 
0092 #endif // KBBGRAPHICSITEMRAYRESULT_H