File indexing completed on 2024-12-08 06:28:03
0001 /* 0002 ElementItem - Element Item, part of the Periodic Table Graphics View for 0003 Kalzium 0004 0005 SPDX-FileCopyrightText: 2007-2009 Marcus D. Hanwell <marcus@cryos.org> 0006 SPDX-FileCopyrightText: 2010 Etienne Rebetez <etienne.rebetez@oberwallis.ch> 0007 0008 This file is part of the Avogadro molecular editor project. 0009 For more information, see <https://avogadro.cc/> 0010 0011 SPDX-License-Identifier: LGPL-2.1-or-later 0012 */ 0013 0014 #ifndef ELEMENTITEM_H 0015 #define ELEMENTITEM_H 0016 0017 #include <QGraphicsItem> 0018 0019 #include "kalziumdataobject.h" 0020 #include "kalziumelementproperty.h" 0021 #include <chemicaldataobject.h> 0022 0023 /** 0024 * @class ElementItem 0025 * @author Marcus D. Hanwell, Etienne Rebetez 0026 * @brief An element item, intended to display a single element. 0027 * 0028 * This class implements a QGraphicsItem for displaying single elements in a 0029 * perdiodic table. It currently allows the setting of the proton number. 0030 * All other information come frome the kalziumElementProperty class. 0031 */ 0032 class ElementItem : public QGraphicsObject 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 /** 0038 * Constructor. Should be called with the element number for this item. The 0039 * constructor uses setData to set the element number using the key 0. This 0040 * is then used by PeriodicTable to figure out which element was clicked on. 0041 */ 0042 explicit ElementItem(KalziumElementProperty *property, int elementNumber = 0); 0043 0044 /** 0045 * Destructor. 0046 */ 0047 ~ElementItem() override; 0048 0049 /** 0050 * @return the bounding rectangle of the element item. 0051 */ 0052 QRectF boundingRect() const override; 0053 0054 /** 0055 * @return the painter path which is also a rectangle in this case. 0056 */ 0057 QPainterPath shape() const override; 0058 0059 /** 0060 * This is where most of the action takes place. The element box is drawn 0061 * along with its symbol. 0062 */ 0063 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 0064 0065 public Q_SLOTS: 0066 void redraw(); 0067 0068 private: 0069 QString getCurrentElementValue(); 0070 0071 /** 0072 * Width of the elements. 0073 */ 0074 int m_width; 0075 0076 /** 0077 * Height of the elements. 0078 */ 0079 int m_height; 0080 0081 /** 0082 * The proton number of the item - all other attributes are derived from this. 0083 */ 0084 int m_element; 0085 0086 /** 0087 * The element numbers symbol. 0088 */ 0089 QString m_symbol; 0090 0091 /** 0092 * The color of the element which will also be used as the background color 0093 * for the item box. 0094 */ 0095 QBrush m_brush; 0096 0097 QColor m_textColor; 0098 0099 QColor m_borderColor; 0100 0101 QString m_textValue; 0102 0103 KalziumElementProperty *m_property; 0104 0105 bool m_hovered = false; 0106 0107 protected: 0108 void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; 0109 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; 0110 }; 0111 0112 #endif // ELEMENTITEM_H