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

0001 /*
0002     SPDX-FileCopyrightText: 2003-2007 Carsten Niehaus <cniehaus@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "kalzium.h"
0007 
0008 #include "detailedgraphicaloverview.h"
0009 #include "detailinfodlg.h"
0010 #include "exportdialog.h"
0011 #include "gradientwidget_impl.h"
0012 #include "kalziumdataobject.h"
0013 #include "kalziumgradienttype.h"
0014 #include "kalziumnumerationtype.h"
0015 #include "kalziumschemetype.h"
0016 #include "legendwidget.h"
0017 #include "prefs.h"
0018 #include "psetables.h"
0019 #include "search.h"
0020 #include "searchwidget.h"
0021 #include "tableinfowidget.h"
0022 #include <config-kalzium.h>
0023 #include <element.h>
0024 #include <kdeeduglossary.h>
0025 
0026 #ifdef HAVE_FACILE
0027 #include "eqchemview.h"
0028 #endif
0029 
0030 #ifdef HAVE_OPENBABEL
0031 #if defined(HAVE_EIGEN) && defined(HAVE_AVOGADRO)
0032 #include "tools/moleculeview.h"
0033 #include <QGLFormat>
0034 #endif
0035 #include "tools/obconverter.h"
0036 #endif
0037 
0038 #include <QDockWidget>
0039 #include <QFileDialog>
0040 #include <QIcon>
0041 #include <QMessageBox>
0042 #include <QRegularExpression>
0043 #include <QStandardPaths>
0044 #include <QStatusBar>
0045 #include <QToolBox>
0046 #include <QUrl>
0047 
0048 #include <KActionCollection>
0049 #include <KLocalizedString>
0050 #include <KSelectAction>
0051 #include <KStandardAction>
0052 
0053 #define IDS_ELEMENTINFO 7
0054 
0055 Kalzium::Kalzium()
0056     : KXmlGuiWindow(nullptr)
0057 {
0058     setObjectName(QStringLiteral("KalziumMainWindow"));
0059 
0060     // Init pointers with null
0061     m_infoDialog = nullptr;
0062     m_isotopeDialog = nullptr;
0063     m_elementDataPlotter = nullptr;
0064     m_tablesDialog = nullptr;
0065     m_rsDialog = nullptr;
0066     m_calculator = nullptr;
0067     m_exportDialog = nullptr;
0068     m_glossarydlg = nullptr;
0069     m_elementInfo = nullptr;
0070 
0071     // reading the elements from file
0072     KalziumDataObject::instance();
0073 
0074     auto newsearch = new Search();
0075     KalziumDataObject::instance()->setSearch(newsearch);
0076 
0077     // Main pse-Table Tablewidget
0078     auto pseTempWidget = new QWidget(this);
0079     auto layout = new QVBoxLayout(pseTempWidget);
0080     layout->setContentsMargins(0, 0, 0, 0);
0081     layout->setSpacing(2);
0082 
0083     auto searchWidget = new SearchWidget(pseTempWidget);
0084     searchWidget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum));
0085 
0086     // Creating the periodic table
0087     m_periodicTable = new PeriodicTableView(pseTempWidget);
0088 
0089     // Connecting the search to the periodic table
0090     connect(newsearch, &Search::searchChanged, KalziumElementProperty::instance(), &KalziumElementProperty::propertyChanged);
0091     connect(newsearch, &Search::searchReset, KalziumElementProperty::instance(), &KalziumElementProperty::propertyChanged);
0092 
0093     layout->addWidget(searchWidget);
0094     layout->addWidget(m_periodicTable);
0095 
0096     setCentralWidget(pseTempWidget);
0097 
0098     connect(m_periodicTable->pseScene(), &PeriodicTableScene::elementChanged, this, &Kalzium::openInformationDialog);
0099     connect(m_periodicTable->pseScene(), &PeriodicTableScene::elementHovered, this, &Kalzium::elementHover);
0100     connect(this, &Kalzium::numerationChanged, m_periodicTable, &PeriodicTableView::numerationChange);
0101 
0102     // layouting
0103     setupSidebars();
0104     setupActions();
0105 
0106     setupStatusBar();
0107 }
0108 
0109 void Kalzium::setupActions()
0110 {
0111     export_action = actionCollection()->add<QAction>(QStringLiteral("file_exporter"));
0112     export_action->setText(i18n("&Export Data..."));
0113     connect(export_action, &QAction::triggered, this, &Kalzium::slotShowExportDialog);
0114 
0115     // the action for switching look: color schemes and gradients
0116     QStringList schemes = KalziumElementProperty::instance()->schemeList(); /*KalziumSchemeTypeFactory::instance()->schemes();*/
0117     QStringList gradients = KalziumElementProperty::instance()->gradientList();
0118 
0119     // the action for switching look: schemes
0120     look_action_schemes = actionCollection()->add<KSelectAction>(QStringLiteral("view_look_onlyschemes"));
0121     look_action_schemes->setText(i18n("&Scheme"));
0122     look_action_schemes->setItems(schemes);
0123     look_action_schemes->setToolBarMode(KSelectAction::MenuMode);
0124     look_action_schemes->setToolButtonPopupMode(QToolButton::InstantPopup);
0125     connect(look_action_schemes, &KSelectAction::indexTriggered, this, &Kalzium::slotSwitchtoLookScheme);
0126 
0127     // the action for switching look: gradients
0128     look_action_gradients = actionCollection()->add<KSelectAction>(QStringLiteral("view_look_onlygradients"));
0129     look_action_gradients->setText(i18n("&Gradients"));
0130     look_action_gradients->setItems(gradients);
0131     look_action_gradients->setToolBarMode(KSelectAction::MenuMode);
0132     look_action_gradients->setToolButtonPopupMode(QToolButton::InstantPopup);
0133     connect(look_action_gradients, &KSelectAction::indexTriggered, this, &Kalzium::slotSwitchtoLookGradient);
0134 
0135     // the action for switching tables
0136     QStringList table_schemes = pseTables::instance()->tables();
0137     table_action = actionCollection()->add<KSelectAction>(QStringLiteral("view_table"));
0138     table_action->setText(i18n("&Tables"));
0139     table_action->setItems(table_schemes);
0140     table_action->setCurrentItem(Prefs::table());
0141     connect(table_action, &KSelectAction::indexTriggered, this, &Kalzium::slotSwitchtoTable);
0142 
0143     // the actions for switching numeration
0144     numeration_action = actionCollection()->add<KSelectAction>(QStringLiteral("view_numerationtype"));
0145     numeration_action->setText(i18n("&Numeration"));
0146     numeration_action->setItems(KalziumNumerationTypeFactory::instance()->numerations());
0147     numeration_action->setCurrentItem(Prefs::numeration());
0148     connect(numeration_action, SIGNAL(indexTriggered(int)), this, SLOT(slotSwitchtoNumeration(int)));
0149 
0150     // tools actions
0151     m_pPlotAction = actionCollection()->addAction(QStringLiteral("tools_plotdata"));
0152     m_pPlotAction->setText(i18n("&Plot Data..."));
0153     m_pPlotAction->setIcon(QIcon::fromTheme(QStringLiteral("plot")));
0154     connect(m_pPlotAction, &QAction::triggered, this, &Kalzium::slotPlotData);
0155 
0156     // calculator actions
0157     m_pcalculator = actionCollection()->addAction(QStringLiteral("tools_calculate"));
0158     m_pcalculator->setText(i18n("Perform &Calculations..."));
0159     m_pcalculator->setIcon(QIcon::fromTheme(QStringLiteral("calculate")));
0160     m_pcalculator->setWhatsThis(i18nc("WhatsThis Help", "This is the calculator, it performs basic chemical calculations."));
0161     connect(m_pcalculator, &QAction::triggered, this, &Kalzium::showCalculator);
0162 
0163     m_pIsotopeTableAction = actionCollection()->addAction(QStringLiteral("tools_isotopetable"));
0164     m_pIsotopeTableAction->setText(i18n("&Isotope Table..."));
0165     m_pIsotopeTableAction->setIcon(QIcon::fromTheme(QStringLiteral("isotopemap")));
0166     m_pIsotopeTableAction->setWhatsThis(i18nc("WhatsThis Help", "This table shows all of the known isotopes of the chemical elements."));
0167     connect(m_pIsotopeTableAction, &QAction::triggered, this, &Kalzium::slotIsotopeTable);
0168 
0169     m_pGlossaryAction = actionCollection()->addAction(QStringLiteral("tools_glossary"));
0170     m_pGlossaryAction->setText(i18n("&Glossary..."));
0171     m_pGlossaryAction->setIcon(QIcon::fromTheme(QStringLiteral("glossary")));
0172     connect(m_pGlossaryAction, &QAction::triggered, this, &Kalzium::slotGlossary);
0173 
0174     m_pRSAction = actionCollection()->addAction(QStringLiteral("tools_rs"));
0175     m_pRSAction->setText(i18n("&R/S Phrases..."));
0176     m_pRSAction->setIcon(QIcon::fromTheme(QStringLiteral("kalzium_rs")));
0177     connect(m_pRSAction, &QAction::triggered, this, &Kalzium::slotRS);
0178 
0179     m_pOBConverterAction = actionCollection()->addAction(QStringLiteral("tools_obconverter"));
0180     m_pOBConverterAction->setText(i18n("Convert chemical files..."));
0181     m_pOBConverterAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
0182     m_pOBConverterAction->setWhatsThis(i18nc("WhatsThis Help", "With this tool, you can convert files containing chemical data between various file formats."));
0183     connect(m_pOBConverterAction, &QAction::triggered, this, &Kalzium::slotOBConverter);
0184 #ifndef HAVE_OPENBABEL
0185     m_pOBConverterAction->setEnabled(false);
0186 #endif
0187 
0188     m_pMoleculesviewer = actionCollection()->addAction(QStringLiteral("tools_moleculeviewer"));
0189     m_pMoleculesviewer->setText(i18n("Molecular Editor..."));
0190     m_pMoleculesviewer->setIcon(QIcon::fromTheme(QStringLiteral("kalzium_molviewer")));
0191     m_pMoleculesviewer->setWhatsThis(i18nc("WhatsThis Help", "This tool allows you to view and edit 3D molecular structures."));
0192     connect(m_pMoleculesviewer, &QAction::triggered, this, &Kalzium::slotMoleculeviewer);
0193 #if !defined(HAVE_OPENBABEL) || !defined(HAVE_EIGEN) || !defined(HAVE_AVOGADRO)
0194     m_pMoleculesviewer->setEnabled(false);
0195 #endif
0196 
0197     m_pTables = actionCollection()->addAction(QStringLiteral("tools_tables"));
0198     m_pTables->setText(i18n("&Tables..."));
0199     m_pTables->setIcon(QIcon::fromTheme(QStringLiteral("kalzium_tables")));
0200     m_pTables->setWhatsThis(i18nc("WhatsThis Help", "This will open a dialog with listings of symbols and numbers related to chemistry."));
0201 
0202     connect(m_pTables, &QAction::triggered, this, &Kalzium::slotTables);
0203 
0204     // other period view options
0205     m_pLegendAction = m_legendDock->toggleViewAction();
0206     actionCollection()->addAction(QStringLiteral("view_legend"), m_pLegendAction);
0207     m_pLegendAction->setIcon(QIcon::fromTheme(QStringLiteral("legend")));
0208     m_pLegendAction->setWhatsThis(i18nc("WhatsThis Help", "This will show or hide the legend for the periodic table."));
0209 
0210     m_SidebarAction = m_dockWin->toggleViewAction();
0211     actionCollection()->addAction(QStringLiteral("view_sidebar"), m_SidebarAction);
0212     m_SidebarAction->setIcon(QIcon::fromTheme(QStringLiteral("sidebar")));
0213     m_SidebarAction->setWhatsThis(i18nc("WhatsThis Help", "This will show or hide a sidebar with additional information and a set of tools."));
0214 
0215     m_SidebarAction = m_tableDock->toggleViewAction();
0216     actionCollection()->addAction(QStringLiteral("view_tablebar"), m_SidebarAction);
0217     m_SidebarAction->setIcon(QIcon::fromTheme(QStringLiteral("kalzium_tables")));
0218     m_SidebarAction->setWhatsThis(i18nc("WhatsThis Help", "This will show or hide a sidebar with additional information about the table."));
0219 
0220     // the standard actions
0221     actionCollection()->addAction(QStringLiteral("saveAs"), KStandardAction::saveAs(this, SLOT(slotExportTable()), actionCollection()));
0222 
0223     KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollection());
0224 
0225     actionCollection()->addAction(QStringLiteral("quit"), KStandardAction::quit(qApp, SLOT(quit()), actionCollection()));
0226 
0227     m_legendWidget->LockWidget();
0228 
0229     slotSwitchtoLookGradient(KalziumElementProperty::instance()->gradientId());
0230     slotSwitchtoLookScheme(KalziumElementProperty::instance()->schemeId());
0231 
0232     slotSwitchtoNumeration(Prefs::numeration());
0233     slotSwitchtoTable(Prefs::table());
0234 
0235     m_legendWidget->UnLockWidget();
0236     m_legendWidget->updateContent();
0237 
0238     // set the shell's ui resource file
0239     setXMLFile(QStringLiteral("kalziumui.rc"));
0240     setupGUI();
0241 }
0242 
0243 void Kalzium::setupSidebars()
0244 {
0245     setDockNestingEnabled(true);
0246 
0247     m_legendWidget = new LegendWidget(this);
0248     m_legendDock = new QDockWidget(i18n("Legend"), this);
0249     m_legendDock->setObjectName(QStringLiteral("kalzium-legend"));
0250     m_legendDock->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
0251     m_legendDock->setWidget(m_legendWidget);
0252 
0253     connect(m_legendDock, &QDockWidget::dockLocationChanged, m_legendWidget, &LegendWidget::setDockArea);
0254     connect(m_legendWidget, &LegendWidget::elementMatched, m_periodicTable, &PeriodicTableView::slotSelectAdditionalElement);
0255     connect(m_legendWidget, &LegendWidget::resetElementMatch, m_periodicTable, &PeriodicTableView::slotUnSelectElements);
0256 
0257     m_TableInfoWidget = new TableInfoWidget(this);
0258     m_tableDock = new QDockWidget(i18n("Table Information"), this);
0259     m_tableDock->setWidget(m_TableInfoWidget);
0260     m_tableDock->setObjectName(QStringLiteral("kalzium-tableinfo"));
0261     m_tableDock->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
0262 
0263     m_dockWin = new QDockWidget(i18n("Information"), this);
0264     m_dockWin->setObjectName(QStringLiteral("kalzium-sidebar"));
0265     m_dockWin->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
0266     m_dockWin->setMinimumWidth(250);
0267 
0268     m_toolbox = new QToolBox(m_dockWin);
0269     m_dockWin->setWidget(m_toolbox);
0270 
0271     m_detailWidget = new DetailedGraphicalOverview(m_toolbox);
0272     m_detailWidget->setObjectName(QStringLiteral("DetailedGraphicalOverview"));
0273     m_detailWidget->setMinimumSize(200, m_detailWidget->minimumSize().height());
0274 
0275     m_toolbox->addItem(m_detailWidget, QIcon::fromTheme(QStringLiteral("overview")), i18n("Overview"));
0276 
0277     m_gradientWidget = new GradientWidgetImpl(m_toolbox);
0278     m_gradientWidget->setObjectName(QStringLiteral("viewtWidget"));
0279 
0280     connect(m_gradientWidget, &GradientWidgetImpl::gradientValueChanged, KalziumElementProperty::instance(), &KalziumElementProperty::setSliderValue);
0281     connect(m_gradientWidget->scheme_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSwitchtoLookScheme(int)));
0282     connect(m_gradientWidget->gradient_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSwitchtoLookGradient(int)));
0283 
0284     m_toolbox->addItem(m_gradientWidget, QIcon::fromTheme(QStringLiteral("statematter")), i18n("View"));
0285 
0286     addDockWidget(Qt::LeftDockWidgetArea, m_dockWin);
0287     addDockWidget(Qt::BottomDockWidgetArea, m_tableDock, Qt::Horizontal);
0288     addDockWidget(Qt::BottomDockWidgetArea, m_legendDock, Qt::Horizontal);
0289 
0290     m_tableDock->setVisible(false);
0291 }
0292 
0293 void Kalzium::slotExportTable()
0294 {
0295     const QString fileName = QFileDialog::getSaveFileName(this, i18n("Save Kalzium's Table In"), QString(), i18n("Image files (*.png *.xpm *.jpg *.svg)"));
0296 
0297     if (fileName.endsWith(QLatin1String(".svg"))) {
0298         m_periodicTable->generateSvg(fileName);
0299     } else {
0300         QPixmap pix = m_periodicTable->grab();
0301         pix.save(fileName);
0302     }
0303 }
0304 
0305 void Kalzium::slotGlossary()
0306 {
0307     if (!m_glossarydlg) {
0308         // creating the glossary dialog and loading the glossaries we have
0309         m_glossarydlg = new GlossaryDialog(this);
0310         m_glossarydlg->setObjectName(QStringLiteral("glossary"));
0311         QString dir = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("data/"), QStandardPaths::LocateDirectory);
0312         dir = QFileInfo(dir).absolutePath();
0313         const QString picturepath = dir + QStringLiteral("/bg.jpg");
0314         QUrl u = QUrl::fromLocalFile(dir + "/knowledge.xml");
0315         auto g = new Glossary(u);
0316         g->setName(i18n("Knowledge"));
0317         g->setBackgroundPicture(picturepath);
0318         m_glossarydlg->addGlossary(g, true);
0319         u = QUrl::fromLocalFile(dir + "/tools.xml");
0320         g = new Glossary(u, dir + "/toolpics/");
0321         g->setName(i18n("Tools"));
0322         g->setBackgroundPicture(picturepath);
0323         m_glossarydlg->addGlossary(g, true);
0324     }
0325 
0326     m_glossarydlg->show();
0327 }
0328 
0329 void Kalzium::slotRS()
0330 {
0331     if (!m_rsDialog) {
0332         m_rsDialog = new RSDialog(this);
0333     }
0334     m_rsDialog->show();
0335 }
0336 
0337 void Kalzium::slotOBConverter()
0338 {
0339 #ifdef HAVE_OPENBABEL
0340     KOpenBabel *d = new KOpenBabel(this);
0341     d->setAttribute(Qt::WA_DeleteOnClose);
0342     d->show();
0343 #endif
0344 }
0345 
0346 MoleculeDialog *Kalzium::slotMoleculeviewer()
0347 {
0348 #if defined(HAVE_OPENBABEL) && defined(HAVE_EIGEN) && defined(HAVE_AVOGADRO)
0349 
0350     if (!QGLFormat::hasOpenGL()) {
0351         QMessageBox::critical(Q_NULLPTR, i18n("Kalzium Error"), i18n("This system does not support OpenGL."));
0352         return nullptr;
0353     }
0354 
0355     MoleculeDialog *d = new MoleculeDialog(this);
0356     d->show();
0357     return d;
0358 
0359 #if 0
0360     KPluginLoader loader("libkalziumglpart");
0361     KPluginFactory* factory = loader.factory();
0362 
0363     if (factory) {
0364         KParts::ReadOnlyPart *part = 0;
0365         part = static_cast<KParts::ReadOnlyPart*>(factory->create(this, "KalziumGLPart"));
0366 
0367         part->widget()->show();
0368     }
0369 #endif
0370 #endif
0371     return nullptr;
0372 }
0373 
0374 void Kalzium::slotTables()
0375 {
0376     if (!m_tablesDialog) {
0377         m_tablesDialog = new TablesDialog(this);
0378     }
0379     m_tablesDialog->show();
0380 }
0381 
0382 void Kalzium::slotIsotopeTable()
0383 {
0384     if (!m_isotopeDialog) {
0385         m_isotopeDialog = new IsotopeTableDialog(this);
0386         connect(Prefs::self(), &Prefs::isotopeTableModeChanged, m_isotopeDialog, &IsotopeTableDialog::updateMode);
0387     }
0388     m_isotopeDialog->show();
0389 }
0390 
0391 void Kalzium::slotPlotData()
0392 {
0393     if (!m_elementDataPlotter) {
0394         m_elementDataPlotter = new ElementDataViewer(this);
0395     }
0396     m_elementDataPlotter->show();
0397 }
0398 
0399 void Kalzium::showCalculator()
0400 {
0401     if (!m_calculator) {
0402         m_calculator = new calculator(this);
0403     }
0404     m_calculator->show();
0405 }
0406 
0407 void Kalzium::slotSwitchtoTable(int index)
0408 {
0409     m_periodicTable->slotChangeTable(index);
0410     m_TableInfoWidget->setTableType(index);
0411 
0412     if (m_infoDialog) {
0413         m_infoDialog->setTableType(m_periodicTable->table());
0414     }
0415     Prefs::setTable(index);
0416     Prefs::self()->save();
0417 }
0418 
0419 void Kalzium::slotSwitchtoNumeration(int index)
0420 {
0421     Q_EMIT numerationChanged(index);
0422     Prefs::setNumeration(index);
0423     Prefs::self()->save();
0424 }
0425 
0426 void Kalzium::slotSwitchtoLookGradient(int which)
0427 {
0428     qCDebug(KALZIUM_LOG) << "slotSwitchtoLookGradient Kalzium";
0429 
0430     KalziumElementProperty::instance()->setGradient(which);
0431 
0432     look_action_gradients->blockSignals(true);
0433     m_gradientWidget->gradient_combo->blockSignals(true);
0434 
0435     look_action_gradients->setCurrentItem(which);
0436     m_gradientWidget->gradient_combo->setCurrentIndex(which);
0437 
0438     look_action_gradients->blockSignals(false);
0439     m_gradientWidget->gradient_combo->blockSignals(false);
0440 
0441     m_gradientWidget->slotGradientChanged();
0442 
0443     m_legendWidget->updateContent();
0444 }
0445 
0446 void Kalzium::slotSwitchtoLookScheme(int which)
0447 {
0448     qCDebug(KALZIUM_LOG) << "slotSwitchtoLookScheme Kalzium";
0449 
0450     KalziumElementProperty::instance()->setScheme(which);
0451 
0452     m_gradientWidget->scheme_combo->blockSignals(true);
0453     look_action_schemes->blockSignals(true);
0454 
0455     look_action_schemes->setCurrentItem(which);
0456     m_gradientWidget->scheme_combo->setCurrentIndex(which);
0457 
0458     look_action_schemes->blockSignals(false);
0459     m_gradientWidget->scheme_combo->blockSignals(false);
0460 
0461     m_legendWidget->updateContent();
0462 }
0463 
0464 void Kalzium::showSettingsDialog()
0465 {
0466     if (KalziumConfigDialog::showDialog(QStringLiteral("settings"))) {
0467         return;
0468     }
0469 
0470     // KalziumConfigDialog didn't find an instance of this dialog, so lets create it :
0471     m_configDialog = new KalziumConfigDialog(this, QStringLiteral("settings"), Prefs::self());
0472 
0473     connect(m_configDialog, &KalziumConfigDialog::settingsChanged, this, &Kalzium::slotUpdateSettings);
0474     connect(m_configDialog, &KalziumConfigDialog::settingsChanged, m_gradientWidget, &GradientWidgetImpl::slotGradientChanged);
0475 
0476     m_configDialog->show();
0477 }
0478 
0479 void Kalzium::slotUpdateSettings()
0480 {
0481     /*This slot function calls change the color of pse elements immediately after prefs change*/
0482     slotSwitchtoLookGradient(Prefs::colorgradientbox());
0483     slotSwitchtoLookScheme(Prefs::colorschemebox());
0484 }
0485 
0486 void Kalzium::slotShowExportDialog()
0487 {
0488     if (!m_exportDialog) {
0489         m_exportDialog = new ExportDialog(this);
0490     }
0491     m_exportDialog->show();
0492 }
0493 
0494 void Kalzium::setupStatusBar()
0495 {
0496     auto statusBar = new QStatusBar(this);
0497     setStatusBar(statusBar);
0498 
0499     m_elementInfo = new QLabel(QLatin1String(""));
0500     m_elementInfo->setAlignment(Qt::AlignRight);
0501     statusBar->addWidget(m_elementInfo, 1);
0502     statusBar->show();
0503 }
0504 
0505 void Kalzium::elementHover(int num)
0506 {
0507     //     extractIconicInformationAboutElement(num);
0508     Element *e = KalziumDataObject::instance()->element(num);
0509     m_elementInfo->setText(i18nc("For example: \"Carbon (6), Mass: 12.0107 u\"",
0510                                  "%1 (%2), Mass: %3 u",
0511                                  e->dataAsString(ChemicalDataObject::name),
0512                                  e->dataAsString(ChemicalDataObject::atomicNumber),
0513                                  e->dataAsString(ChemicalDataObject::mass)));
0514     qCDebug(KALZIUM_LOG) << "change item in status bar";
0515 
0516     m_detailWidget->setElement(num);
0517 }
0518 
0519 // FIXME What is that function for? Does not seem to do anything useful... yet?
0520 void Kalzium::extractIconicInformationAboutElement(int elementNumber)
0521 {
0522     const QString setname = QStringLiteral("school");
0523     QString pathname = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("data/iconsets/"), QStandardPaths::LocateDirectory);
0524     pathname = QFileInfo(pathname).absolutePath();
0525     const QString filename = pathname + setname + '/' + "iconinformation.txt";
0526 
0527     QFile file(filename);
0528     if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
0529         return;
0530     }
0531 
0532     QString infoline;
0533 
0534     QTextStream in(&file);
0535     while (!in.atEnd()) {
0536         QString tmp = in.readLine();
0537         if (tmp.startsWith(QString::number(elementNumber))) {
0538             infoline = tmp;
0539         }
0540     }
0541 
0542     QString realText = QStringLiteral("Moin dies ist ein test!");
0543     // X         QString realText = infoline.remove(QRegularExpression("\\d+ "));
0544 }
0545 
0546 void Kalzium::openInformationDialog(int number)
0547 {
0548     if (m_infoDialog) {
0549         m_infoDialog->setElement(number);
0550     } else {
0551         m_infoDialog = new DetailedInfoDlg(number, this);
0552 
0553         // Remove the selection when this dialog finishes or hides.
0554         connect(m_infoDialog, &DetailedInfoDlg::elementChanged, m_periodicTable, &PeriodicTableView::slotSelectOneElement);
0555         connect(m_infoDialog, &DetailedInfoDlg::elementChanged, this, &Kalzium::elementHover);
0556     }
0557 
0558     m_infoDialog->setTableType(m_periodicTable->table());
0559     m_infoDialog->show();
0560 }
0561 
0562 Kalzium::~Kalzium()
0563 {
0564     delete m_periodicTable;
0565     delete m_infoDialog;
0566     delete m_TableInfoWidget;
0567     delete m_legendWidget;
0568     delete m_gradientWidget;
0569 
0570     delete m_dockWin;
0571     delete m_legendDock;
0572     delete m_tableDock;
0573 }
0574 
0575 void Kalzium::loadMolecule(const QString &moleculeFile)
0576 {
0577 #if defined(HAVE_OPENBABEL) && defined(HAVE_EIGEN) && defined(HAVE_AVOGADRO)
0578     MoleculeDialog *d = slotMoleculeviewer();
0579     if (d) {
0580         d->loadMolecule(moleculeFile);
0581     }
0582 #endif
0583 }
0584 
0585 QSize Kalzium::sizeHint() const
0586 {
0587     return {700, 500};
0588 }