File indexing completed on 2022-09-27 12:24:10

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