File indexing completed on 2022-10-04 13:46:50

0001 /*
0002     SPDX-FileCopyrightText: 2005, 2006, 2007 Carsten Niehaus <cniehaus@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef MOLCALCWIDGET_H
0008 #define MOLCALCWIDGET_H
0009 
0010 #include "ui_molcalcwidgetbase.h"
0011 #include <QWidget>
0012 
0013 #include "moleculeparser.h"
0014 
0015 class QTimer;
0016 class QKeyEvent;
0017 
0018 /**
0019  * This widget calculates mass for molecules.
0020  *
0021  * @author Carsten Niehaus
0022  * @author Pino Toscano
0023  * @author Inge Wallin
0024  * @author Kashyap R Puranik
0025  */
0026 class MolcalcWidget : public QWidget
0027 {
0028     Q_OBJECT
0029 public:
0030     /**
0031      * Constructor
0032      * @param parent parent widget
0033      */
0034     explicit MolcalcWidget(QWidget *parent = nullptr);
0035     void hideExtra();
0036     ~MolcalcWidget() override;
0037 
0038 protected Q_SLOTS:
0039     void slotCalculate();
0040 
0041 protected:
0042     void keyPressEvent(QKeyEvent *e) override;
0043 
0044 private Q_SLOTS:
0045     void clear();
0046     void addAlias();
0047 
0048 private:
0049     /**
0050      * @return the HTML code of an element symbol and its
0051      * subscripted amount. Eg: Mg<sub>2</sub>
0052      */
0053     QString compositionString(ElementCountMap &_map);
0054 
0055     /**
0056      * This methods gathers all the data and updates the
0057      * contents of the widget.
0058      */
0059     void updateUI();
0060 
0061     Ui_MolcalcWidgetBase ui;
0062 
0063     QTimer *m_timer = nullptr;
0064 
0065 private:
0066     MoleculeParser *m_parser = nullptr;
0067     QSet<QString> m_aliasList;
0068     double m_mass;
0069     bool m_validInput;
0070     ElementCountMap m_elementMap;
0071 };
0072 
0073 #endif // MOLCALCWIDGET_H