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

« back to all changes in this revision

Viewing changes to src/psetable/numerationitem.cpp

  • 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
 NumerationItem - Numeration Item, part of the Periodic Table Graphics View
 
3
 for Kalzium
 
4
 
 
5
 Copyright (C) 2007-2009 by Marcus D. Hanwell
 
6
 Some portions (C) 2010  by Konstantin Tokarev
 
7
 Copyright (C) 2010      by Etienne Rebetez
 
8
 
 
9
 This file is part of the Avogadro molecular editor project.
 
10
 For more information, see <http://avogadro.openmolecules.net/>
 
11
 
 
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.
 
16
 
 
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.
 
21
 
 
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
 
25
 02110-1301, USA.
 
26
 
 
27
 **********************************************************************/
 
28
 
 
29
#include "numerationitem.h"
 
30
 
 
31
#include <prefs.h>
 
32
#include <klocale.h>
 
33
 
 
34
#include <QPainter>
 
35
#include <QStyleOption>
 
36
#include <QFont>
 
37
#include <QFontMetrics>
 
38
#include <QDebug>
 
39
 
 
40
#include "kalziumnumerationtype.h"
 
41
 
 
42
NumerationItem::NumerationItem(int xPosition) : m_width(40), m_height(20),
 
43
        m_xPosition(xPosition)
 
44
{
 
45
    setNumerationType( Prefs::numeration() );
 
46
}
 
47
 
 
48
NumerationItem::~NumerationItem()
 
49
{
 
50
}
 
51
 
 
52
QRectF NumerationItem::boundingRect() const
 
53
{
 
54
    return QRectF(0, 0, m_width, m_height);
 
55
}
 
56
 
 
57
QPainterPath NumerationItem::shape() const
 
58
{
 
59
    QPainterPath path;
 
60
    path.addRect(0, 0, m_width, m_height);
 
61
    return path;
 
62
}
 
63
 
 
64
void NumerationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
 
65
{
 
66
    QPen pen;
 
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));
 
72
    painter->setPen(pen);
 
73
 
 
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);
 
77
}
 
78
 
 
79
void NumerationItem::setNumerationType(int type)
 
80
{
 
81
   type == 0 ? m_color = QColor(Qt::transparent) : m_color = QColor(Qt::white);
 
82
 
 
83
   m_numeration = KalziumNumerationTypeFactory::instance()->build( type )->item( m_xPosition );
 
84
 
 
85
   update();
 
86
}
 
87
 
 
88
#include "numerationitem.moc"