File indexing completed on 2022-11-29 18:11:59

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