~ubuntu-branches/ubuntu/precise/kalzium/precise

« back to all changes in this revision

Viewing changes to src/psetable/elementitem.h

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-03 12:28:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110703122858-q1yyxncs89e4w0hs
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 ElementItem - Element Item, part of the Periodic Table Graphics View for
 
3
 Kalzium
 
4
 
 
5
 Copyright (C) 2007-2009 by Marcus D. Hanwell
 
6
 Copyright (C) 2010 by Etienne Rebetez
 
7
 
 
8
 This file is part of the Avogadro molecular editor project.
 
9
 For more information, see <http://avogadro.openmolecules.net/>
 
10
 
 
11
 Kalzium is free software; you can redistribute it and/or modify
 
12
 it under the terms of the GNU Lesser General Public License as published by
 
13
 the Free Software Foundation; either version 2.1 of the License, or
 
14
 (at your option) any later version.
 
15
 
 
16
 Kalzium is distributed in the hope that it will be useful,
 
17
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 GNU General Public License for more details.
 
20
 
 
21
 You should have received a copy of the GNU General Public License
 
22
 along with this program; if not, write to the Free Software
 
23
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
24
 02110-1301, USA.
 
25
 **********************************************************************/
 
26
 
 
27
#ifndef ELEMENTITEM_P_H
 
28
#define ELEMENTITEM_P_H
 
29
 
 
30
#include <QGraphicsItem>
 
31
#include "kalziumdataobject.h"
 
32
#include "kalziumelementproperty.h"
 
33
 
 
34
#include <chemicaldataobject.h>
 
35
 
 
36
  /**
 
37
   * @class ElementItem
 
38
   * @author Marcus D. Hanwell, Etienne Rebetez
 
39
   * @brief An element item, intended to display a single element.
 
40
   *
 
41
   * This class implements a QGraphicsItem for displaying single elements in a
 
42
   * perdiodic table. It currently allows the setting of the proton number.
 
43
   * All other information come frome the kalziumElementProperty class.
 
44
   */
 
45
  class ElementItem : public QGraphicsObject
 
46
  {
 
47
    Q_OBJECT
 
48
 
 
49
  public:
 
50
    /**
 
51
     * Constructor. Should be called with the element number for this item. The
 
52
     * constructor uses setData to set the element number using the key 0. This
 
53
     * is then used by PeriodicTable to figure out which element was clicked on.
 
54
     */
 
55
    ElementItem(KalziumElementProperty *property, int elementNumber = 0);
 
56
 
 
57
    /**
 
58
     * Destructor.
 
59
     */
 
60
    ~ElementItem();
 
61
 
 
62
    /**
 
63
     * @return the bounding rectangle of the element item.
 
64
     */
 
65
    QRectF boundingRect() const;
 
66
 
 
67
    /**
 
68
     * @return the painter path which is also a rectangle in this case.
 
69
     */
 
70
    QPainterPath shape() const;
 
71
 
 
72
    /**
 
73
     * This is where most of the action takes place. The element box is drawn
 
74
     * along with its symbol.
 
75
     */
 
76
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
 
77
               QWidget *widget);
 
78
 
 
79
  public Q_SLOTS:
 
80
    void redraw();
 
81
 
 
82
  private:
 
83
    QString getCurrentElementValue();
 
84
 
 
85
    /**
 
86
     * Width and height of the elements.
 
87
     */
 
88
    int m_width, m_height;
 
89
    /**
 
90
     * The proton number of the item - all other attributes are derived from this.
 
91
     */
 
92
    int m_element;
 
93
 
 
94
    /**
 
95
     * The element numbers symbol.
 
96
     */
 
97
    QString m_symbol;
 
98
 
 
99
    /**
 
100
     * The color of the element which will also be used as the background color
 
101
     * for the item box.
 
102
     */
 
103
    QBrush m_brush;
 
104
 
 
105
    QColor m_textColor;
 
106
 
 
107
    QColor m_borderColor;
 
108
 
 
109
    QString m_textValue;
 
110
 
 
111
    KalziumElementProperty *m_property;
 
112
 
 
113
  protected:
 
114
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
 
115
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
 
116
  };
 
117
 
 
118
 
 
119
#endif // ELEMENTITEM_P_H