Debian Codegraph @

avogadro/qtgui/elementitem_p.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_QTGUI_ELEMENTITEM_P_H
7 #define AVOGADRO_QTGUI_ELEMENTITEM_P_H
8
9 #include <QtWidgets/QGraphicsItem>
10
11 namespace Avogadro {
12 namespace QtGui {
13
14 /**
15 * @class ElementItem
16 * @internal
17 * @author Marcus D. Hanwell
18 * @brief An element item, intended to display a single element.
19 *
20 * This class implements a QGraphicsItem for displaying single elements in a
21 * periodic table. It currently allows the setting of the proton number and
22 * gets all other information from OpenBabel.
23 */
24 class ElementItem : public QGraphicsItem
25 {
26 public:
27 /**
28 * Constructor. Should be called with the element number for this item. The
29 * constructor uses setData to set the element number using the key 0. This
30 * is then used by PeriodicTable to figure out which element was clicked on.
31 */
32 ElementItem(int elementNumber = 0);
33 ~ElementItem() override;
34
35 /**
36 * @return the bounding rectangle of the element item.
37 */
38 QRectF boundingRect() const override;
39
40 /**
41 * @return the painter path which is also a rectangle in this case.
42 */
43 QPainterPath shape() const override;
44
45 /**
46 * This is where most of the action takes place. The element box is drawn
47 * along with its symbol.
48 */
49 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
50 QWidget* widget) override;
51
52 private:
53 /** Indicates if element is well-formed (e.g., has non-empty symbol). */
54 bool m_valid;
55
56 /** The element numbers symbol. */
57 QString m_symbol;
58
59 /**
60 * The color of the element which will also be used as the background color
61 * for the item box.
62 */
63 QColor m_color;
64
65 /**
66 * Width and height of the elements.
67 */
68 int m_width, m_height;
69
70 /**
71 * The proton number of the item - all other attributes are derived from this.
72 */
73 int m_element;
74 };
75
76 } // End namespace QtGui
77 } // End namespace Avogadro
78
79 #endif // AVOGADRO_QTGUI_ELEMENTITEM_P_H