1
/**********************************************************************
2
NumerationItem - Numeration Item, part of the Periodic Table Graphics View
5
Copyright (C) 2007-2009 by Marcus D. Hanwell
6
Some portions (C) 2010 by Konstantin Tokarev
7
Copyright (C) 2010 by Etienne Rebetez
9
This file is part of the Avogadro molecular editor project.
10
For more information, see <http://avogadro.openmolecules.net/>
12
Kalzium is free software; you can redistribute it and/or modify
13
it under the terms of the GNU Lesser General Public License as published by
14
the Free Software Foundation; either version 2.1 of the License, or
15
(at your option) any later version.
17
Avogadro is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
GNU General Public License for more details.
22
You should have received a copy of the GNU General Public License
23
along with this program; if not, write to the Free Software
24
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27
**********************************************************************/
29
#include "numerationitem.h"
35
#include <QStyleOption>
37
#include <QFontMetrics>
40
#include "kalziumnumerationtype.h"
42
NumerationItem::NumerationItem(int xPosition) : m_width(40), m_height(20),
43
m_xPosition(xPosition)
45
setNumerationType( Prefs::numeration() );
48
NumerationItem::~NumerationItem()
52
QRectF NumerationItem::boundingRect() const
54
return QRectF(0, 0, m_width, m_height);
57
QPainterPath NumerationItem::shape() const
60
path.addRect(0, 0, m_width, m_height);
64
void NumerationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
67
QLinearGradient grad(QPointF(0, 0), QPointF(0, m_height));
68
grad.setColorAt(0,m_color);
69
grad.setColorAt(1,m_color.darker());
70
painter->setBrush(grad);
71
pen.setColor(m_color.dark(1000));
74
QRectF rect(0, 0, m_width, m_height);
75
painter->drawRoundedRect(rect, m_width / 10, m_width / 10);
76
painter->drawText(rect, Qt::AlignCenter, m_numeration);
79
void NumerationItem::setNumerationType(int type)
81
type == 0 ? m_color = QColor(Qt::transparent) : m_color = QColor(Qt::white);
83
m_numeration = KalziumNumerationTypeFactory::instance()->build( type )->item( m_xPosition );
88
#include "numerationitem.moc"