File indexing completed on 2024-04-14 03:40:17

0001 /*
0002     SPDX-FileCopyrightText: 2005-2006 Pino Toscano <toscano.pino@tiscali.it>
0003     SPDX-FileCopyrightText: 2003-2006 Carsten Niehaus <cniehaus@kde.org>
0004     SPDX-FileCopyrightText: 2007-2009 Marcus D. Hanwell <marcus@cryos.org>
0005     SPDX-FileCopyrightText: 2010-2011 Etienne Rebetez <etienne.rebetez@oberwallis.ch>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef PERIODICTABLEVIEW_H
0011 #define PERIODICTABLEVIEW_H
0012 
0013 #include <QGraphicsView>
0014 
0015 #include "elementitem.h"
0016 #include "numerationitem.h"
0017 #include "periodictablescene.h"
0018 #include "periodictablestates.h"
0019 
0020 /**
0021  * @class PeriodicTableView
0022  * In this class the periodic table of elements is created.
0023  * It provides slots to change the tables and accessing the element properties
0024  * @short Base class and creation for the pse System
0025  * @author Carsten Niehaus
0026  * @author Marcus D. Hanwell
0027  * @author Etienne Rebetez
0028  *
0029  */
0030 
0031 class PeriodicTableView : public QGraphicsView
0032 {
0033     Q_OBJECT
0034 public:
0035     explicit PeriodicTableView(QWidget *parent = nullptr);
0036     ~PeriodicTableView() override;
0037 
0038     /**
0039      * Returns the qgraphicsscene
0040      */
0041     PeriodicTableScene *pseScene() const;
0042 
0043     /**
0044      * Returns the current id of the pse-table.
0045      * The id is the same as the menu and the pse list from the pseTables class.
0046      */
0047     int table() const;
0048 
0049     /**
0050      * Generates and saves the pse as svg in the given filename.
0051      * @param filename filename of the destination.
0052      */
0053     void generateSvg(const QString &filename);
0054 
0055 Q_SIGNALS:
0056     /**
0057      * Is emitted when the pse table is changed.
0058      */
0059     void tableChanged(int tableTyp);
0060     /**
0061      * Is emitted when the numeration of the pse table is changed.
0062      */
0063     void numerationChange(int num);
0064 
0065 public Q_SLOTS:
0066     /**
0067      * Change the pse table to the given id.
0068      * @param newtable id of the pse table.
0069      */
0070     void slotChangeTable(int newtable);
0071     /**
0072      * fits the pse in the qGraphicsView.
0073      */
0074     void fitPseInView();
0075     /**
0076      * One Element can be selected with this function.
0077      * The selection is only a graphical feedback for the user.
0078      * @param element number of the element.
0079      */
0080     void slotSelectOneElement(int element);
0081     /**
0082      * Selects an Element.
0083      * @param element number of the element.
0084      */
0085     void slotSelectAdditionalElement(int element);
0086     /**
0087      * Unselects all elements
0088      */
0089     void slotUnSelectElements();
0090 
0091 private:
0092     QList<ElementItem *> createElementItems() const;
0093     QList<NumerationItem *> createNumerationItems() const;
0094 
0095     void setBiggerSceneRect();
0096 
0097     int m_currentTableInex;
0098     static int const RESIZE_SCENE_TIMEOUT = 2200;
0099 
0100     PeriodicTableScene *m_tableScene;
0101 
0102     PeriodicTableStates *m_tableStates;
0103 
0104 protected:
0105     /**
0106      * Generic event handler, currently defaults to calling parent class
0107      * (included for future compatibility)
0108      */
0109     bool event(QEvent *e) override;
0110 
0111     /**
0112      * is called every time the view is resized.
0113      */
0114     void resizeEvent(QResizeEvent *event) override;
0115 };
0116 
0117 #endif // PERIODICTABLEVIEW_H