File indexing completed on 2024-12-01 06:32:54

0001 /*
0002     SPDX-FileCopyrightText: 2007, 2008 Carsten Niehaus <cniehaus@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef ISOTOPEITEM_H
0008 #define ISOTOPEITEM_H
0009 
0010 #include <QFont>
0011 #include <QGraphicsRectItem>
0012 
0013 class Isotope;
0014 
0015 /**
0016  * The class represents the items which is drawn on the QGraphicsScene. Each such item represents on
0017  * Isotope.
0018  * @author Carsten Niehaus
0019  */
0020 class IsotopeItem : public QAbstractGraphicsShapeItem
0021 {
0022 public:
0023     /**
0024      * there are several types of decay for an isotope.
0025      */
0026     enum IsotopeType { alpha, ec, multiple, bplus, bminus, unknown, stable };
0027 
0028     enum { Type = UserType + 1 };
0029 
0030     /**
0031      * @param isotope The Isotope represented
0032      */
0033     IsotopeItem(Isotope *isotope, qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = nullptr);
0034 
0035     /**
0036      * @return the Isotope the item represents
0037      */
0038     Isotope *isotope() const
0039     {
0040         return m_isotope;
0041     }
0042 
0043     QRectF boundingRect() const override
0044     {
0045         return m_rect;
0046     }
0047 
0048     /**
0049      * @return the Type of the item
0050      */
0051     int type() const override
0052     {
0053         return Type;
0054     }
0055 
0056     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0057 
0058 private:
0059     IsotopeType m_type;
0060     Isotope *m_isotope;
0061     QRectF m_rect;
0062     QFont m_symbolFont;
0063     QFont m_otherFont;
0064 
0065     /**
0066      * @return the IsotopeType of the Isotope
0067      */
0068     static IsotopeType getType(Isotope *);
0069 
0070 protected:
0071     void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
0072     void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
0073 };
0074 
0075 #endif // ISOTOPEITEM_H