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 <QFont>
0020 #include <QPainter>
0021 #include <QStyleOption>
0022 
0023 #include <KLocalizedString>
0024 
0025 #include "kalziumnumerationtype.h"
0026 
0027 NumerationItem::NumerationItem(int xPosition)
0028     : m_width(40)
0029     , m_height(20)
0030     , m_xPosition(xPosition)
0031 {
0032     setNumerationType(Prefs::numeration());
0033 }
0034 
0035 NumerationItem::~NumerationItem() = default;
0036 
0037 QRectF NumerationItem::boundingRect() const
0038 {
0039     return QRectF(0, 0, m_width, m_height);
0040 }
0041 
0042 QPainterPath NumerationItem::shape() const
0043 {
0044     QPainterPath path;
0045     path.addRect(0, 0, m_width, m_height);
0046     return path;
0047 }
0048 
0049 void NumerationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
0050 {
0051     QPen pen;
0052     QLinearGradient grad(QPointF(0, 0), QPointF(0, m_height));
0053     grad.setColorAt(0, m_color);
0054     grad.setColorAt(1, m_color.darker());
0055     painter->setBrush(grad);
0056     pen.setColor(m_color.darker(1000));
0057     painter->setPen(pen);
0058 
0059     QRectF rect(0, 0, m_width, m_height);
0060     painter->drawRoundedRect(rect, m_width / 10, m_width / 10);
0061     painter->drawText(rect, Qt::AlignCenter, m_numeration);
0062 }
0063 
0064 void NumerationItem::setNumerationType(int type)
0065 {
0066     type == 0 ? m_color = QColor(Qt::transparent) : m_color = QColor(Qt::white);
0067 
0068     m_numeration = KalziumNumerationTypeFactory::instance()->build(type)->item(m_xPosition);
0069 
0070     update();
0071 }