Warning, file /education/kalzium/src/psetable/numerationitem.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     NumerationItem - Numeration Item, part of the Periodic Table Graphics View
0003     for Kalzium
0004 
0005     SPDX-FileCopyrightText: 2007-2009 Marcus D. Hanwell <marcus@cryos.org>
0006     SPDX-FileContributor: 2010 Konstantin Tokarev
0007     SPDX-FileCopyrightText: 2010 Etienne Rebetez <etienne.rebetez@oberwallis.ch>
0008 
0009     This file is part of the Avogadro molecular editor project.
0010     For more information, see <https://avogadro.cc/>
0011 
0012     SPDX-License-Identifier: LGPL-2.1-or-later
0013 */
0014 
0015 #include "numerationitem.h"
0016 
0017 #include <prefs.h>
0018 
0019 #include "kalzium_debug.h"
0020 #include <QFont>
0021 #include <QPainter>
0022 #include <QStyleOption>
0023 
0024 #include <KLocalizedString>
0025 
0026 #include "kalziumnumerationtype.h"
0027 
0028 NumerationItem::NumerationItem(int xPosition)
0029     : m_width(40)
0030     , m_height(20)
0031     , m_xPosition(xPosition)
0032 {
0033     setNumerationType(Prefs::numeration());
0034 }
0035 
0036 NumerationItem::~NumerationItem() = default;
0037 
0038 QRectF NumerationItem::boundingRect() const
0039 {
0040     return QRectF(0, 0, m_width, m_height);
0041 }
0042 
0043 QPainterPath NumerationItem::shape() const
0044 {
0045     QPainterPath path;
0046     path.addRect(0, 0, m_width, m_height);
0047     return path;
0048 }
0049 
0050 void NumerationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
0051 {
0052     QPen pen;
0053     QLinearGradient grad(QPointF(0, 0), QPointF(0, m_height));
0054     grad.setColorAt(0, m_color);
0055     grad.setColorAt(1, m_color.darker());
0056     painter->setBrush(grad);
0057     pen.setColor(m_color.darker(1000));
0058     painter->setPen(pen);
0059 
0060     QRectF rect(0, 0, m_width, m_height);
0061     painter->drawRoundedRect(rect, m_width / 10, m_width / 10);
0062     painter->drawText(rect, Qt::AlignCenter, m_numeration);
0063 }
0064 
0065 void NumerationItem::setNumerationType(int type)
0066 {
0067     type == 0 ? m_color = QColor(Qt::transparent) : m_color = QColor(Qt::white);
0068 
0069     m_numeration = KalziumNumerationTypeFactory::instance()->build(type)->item(m_xPosition);
0070 
0071     update();
0072 }