1
/***************************************************************************
2
* Copyright (C) 2005, 2006, 2007, 2008 by Carsten Niehaus *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20
***************************************************************************/
23
#include "isotopeitem.h"
24
#include "isotopescene.h"
29
#include <QGraphicsSceneMouseEvent>
31
#include <QStyleOptionGraphicsItem>
35
IsotopeItem::IsotopeItem( Isotope * i, qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent)
36
: QAbstractGraphicsShapeItem(parent)
38
m_rect = QRectF( 0, 0, width, height );
42
m_type = getType( m_isotope );
47
b = QBrush( Qt::red );
50
b = QBrush( Qt::blue );
53
b = QBrush( Qt::green );
56
b = QBrush( Qt::yellow );
59
b = QBrush( Qt::white );
62
b = QBrush( Qt::lightGray );
65
b = QBrush( Qt::darkGray );
70
m_symbolFont = QFont( "Arial", 3 ,QFont::Bold );
71
m_otherFont = QFont( "Arial", 1 ,QFont::Bold );
73
setFlag(QGraphicsItem::ItemIsMovable, false);
74
setFlag(QGraphicsItem::ItemIsSelectable, false);
75
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
77
setToolTip( i18n("Isotope of Element %1 (%2)", m_isotope->parentElementNumber(), m_isotope->parentElementSymbol() ) );
80
void IsotopeItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget )
84
const qreal lod = option->levelOfDetailFromTransform( painter->worldTransform() );
86
painter->setPen( pen() );
88
painter->setPen( Qt::NoPen );
89
painter->setBrush( brush() );
90
painter->drawRect( m_rect );
93
// FIXME: Get rid of magic numbers and rather dynamically calculate them
94
QRectF r1( m_rect.translated( 0.0, 2.5 ) );
96
painter->setFont( m_symbolFont );
97
painter->drawText( r1, Qt::AlignHCenter | Qt::TextDontClip, m_isotope->parentElementSymbol() );//, s->parentElementNumber()
100
QRectF r2( m_rect.topLeft() + QPointF( 1.0, 0.5 ), m_rect.size() / 2.0 );
101
QRectF r3( m_rect.topLeft() + QPointF( 6.0, 0.5 ) , m_rect.size() / 2.0 );
103
painter->setFont( m_otherFont );
104
painter->drawText( r2, Qt::AlignHCenter | Qt::TextDontClip, QString::number( m_isotope->parentElementNumber() ) );
105
painter->drawText( r3, Qt::AlignHCenter | Qt::TextDontClip, QString::number( m_isotope->nucleons() ) );
110
IsotopeItem::IsotopeType IsotopeItem::getType( Isotope * isotope )
112
//TODO Here I need a clever way to find out *what* to return.
113
if (isotope->alphalikeliness() > 60.0 )
114
return IsotopeItem::alpha;
115
if (isotope->betaminuslikeliness() > 60.0 )
116
return IsotopeItem::bminus;
117
if (isotope->betapluslikeliness() > 60.0 )
118
return IsotopeItem::bminus;
119
if (isotope->eclikeliness() > 60.0 )
120
return IsotopeItem::ec;
122
return IsotopeItem::stable;
125
void IsotopeItem::mousePressEvent( QGraphicsSceneMouseEvent * event )
127
if (event->button() != Qt::RightButton) {
132
IsotopeScene *scene2 = static_cast<IsotopeScene*>(scene());
133
scene2->updateContextHelp( this );