File indexing completed on 2024-04-21 03:41:42
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 <QTabWidget> 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(0); 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_tabwidget = new QTabWidget(m_dockWin); 0269 m_tabwidget->setDocumentMode(true); 0270 m_tabwidget->tabBar()->setExpanding(true); 0271 m_dockWin->setWidget(m_tabwidget); 0272 0273 m_detailWidget = new DetailedGraphicalOverview(m_tabwidget); 0274 m_detailWidget->setObjectName(QStringLiteral("DetailedGraphicalOverview")); 0275 m_detailWidget->setMinimumSize(200, m_detailWidget->minimumSize().height()); 0276 0277 m_tabwidget->addTab(m_detailWidget, QIcon::fromTheme(QStringLiteral("overview")), i18n("Overview")); 0278 0279 m_gradientWidget = new GradientWidgetImpl(m_tabwidget); 0280 m_gradientWidget->setObjectName(QStringLiteral("viewtWidget")); 0281 0282 connect(m_gradientWidget, &GradientWidgetImpl::gradientValueChanged, KalziumElementProperty::instance(), &KalziumElementProperty::setSliderValue); 0283 connect(m_gradientWidget->scheme_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSwitchtoLookScheme(int))); 0284 connect(m_gradientWidget->gradient_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSwitchtoLookGradient(int))); 0285 0286 m_tabwidget->addTab(m_gradientWidget, QIcon::fromTheme(QStringLiteral("statematter")), i18n("View")); 0287 0288 addDockWidget(Qt::LeftDockWidgetArea, m_dockWin); 0289 addDockWidget(Qt::BottomDockWidgetArea, m_tableDock, Qt::Horizontal); 0290 addDockWidget(Qt::BottomDockWidgetArea, m_legendDock, Qt::Horizontal); 0291 0292 m_tableDock->setVisible(false); 0293 } 0294 0295 void Kalzium::slotExportTable() 0296 { 0297 const QString fileName = QFileDialog::getSaveFileName(this, i18n("Save Kalzium's Table In"), QString(), i18n("Image files (*.png *.xpm *.jpg *.svg)")); 0298 0299 if (fileName.endsWith(QLatin1String(".svg"))) { 0300 m_periodicTable->generateSvg(fileName); 0301 } else { 0302 QPixmap pix = m_periodicTable->grab(); 0303 pix.save(fileName); 0304 } 0305 } 0306 0307 void Kalzium::slotGlossary() 0308 { 0309 if (!m_glossarydlg) { 0310 // creating the glossary dialog and loading the glossaries we have 0311 m_glossarydlg = new GlossaryDialog(this); 0312 m_glossarydlg->setObjectName(QStringLiteral("glossary")); 0313 QString dir = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("data/"), QStandardPaths::LocateDirectory); 0314 dir = QFileInfo(dir).absolutePath(); 0315 const QString picturepath = dir + QStringLiteral("/bg.jpg"); 0316 QUrl u = QUrl::fromLocalFile(dir + "/knowledge.xml"); 0317 auto g = new Glossary(u); 0318 g->setName(i18n("Knowledge")); 0319 g->setBackgroundPicture(picturepath); 0320 m_glossarydlg->addGlossary(g, true); 0321 u = QUrl::fromLocalFile(dir + "/tools.xml"); 0322 g = new Glossary(u, dir + "/toolpics/"); 0323 g->setName(i18n("Tools")); 0324 g->setBackgroundPicture(picturepath); 0325 m_glossarydlg->addGlossary(g, true); 0326 } 0327 0328 m_glossarydlg->show(); 0329 } 0330 0331 void Kalzium::slotRS() 0332 { 0333 if (!m_rsDialog) { 0334 m_rsDialog = new RSDialog(this); 0335 } 0336 m_rsDialog->show(); 0337 } 0338 0339 void Kalzium::slotOBConverter() 0340 { 0341 #ifdef HAVE_OPENBABEL 0342 KOpenBabel *d = new KOpenBabel(this); 0343 d->setAttribute(Qt::WA_DeleteOnClose); 0344 d->show(); 0345 #endif 0346 } 0347 0348 MoleculeDialog *Kalzium::slotMoleculeviewer() 0349 { 0350 #if defined(HAVE_OPENBABEL) && defined(HAVE_EIGEN) && defined(HAVE_AVOGADRO) 0351 0352 if (!QGLFormat::hasOpenGL()) { 0353 QMessageBox::critical(Q_NULLPTR, i18n("Kalzium Error"), i18n("This system does not support OpenGL.")); 0354 return nullptr; 0355 } 0356 0357 MoleculeDialog *d = new MoleculeDialog(this); 0358 d->show(); 0359 return d; 0360 #endif 0361 return nullptr; 0362 } 0363 0364 void Kalzium::slotTables() 0365 { 0366 if (!m_tablesDialog) { 0367 m_tablesDialog = new TablesDialog(this); 0368 } 0369 m_tablesDialog->show(); 0370 } 0371 0372 void Kalzium::slotIsotopeTable() 0373 { 0374 if (!m_isotopeDialog) { 0375 m_isotopeDialog = new IsotopeTableDialog(this); 0376 connect(Prefs::self(), &Prefs::isotopeTableModeChanged, m_isotopeDialog, &IsotopeTableDialog::updateMode); 0377 } 0378 m_isotopeDialog->show(); 0379 } 0380 0381 void Kalzium::slotPlotData() 0382 { 0383 if (!m_elementDataPlotter) { 0384 m_elementDataPlotter = new ElementDataViewer(this); 0385 } 0386 m_elementDataPlotter->show(); 0387 } 0388 0389 void Kalzium::showCalculator() 0390 { 0391 if (!m_calculator) { 0392 m_calculator = new calculator(this); 0393 } 0394 m_calculator->show(); 0395 } 0396 0397 void Kalzium::slotSwitchtoTable(int index) 0398 { 0399 m_periodicTable->slotChangeTable(index); 0400 m_TableInfoWidget->setTableType(index); 0401 0402 if (m_infoDialog) { 0403 m_infoDialog->setTableType(m_periodicTable->table()); 0404 } 0405 Prefs::setTable(index); 0406 Prefs::self()->save(); 0407 } 0408 0409 void Kalzium::slotSwitchtoNumeration(int index) 0410 { 0411 Q_EMIT numerationChanged(index); 0412 Prefs::setNumeration(index); 0413 Prefs::self()->save(); 0414 } 0415 0416 void Kalzium::slotSwitchtoLookGradient(int which) 0417 { 0418 qCDebug(KALZIUM_LOG) << "slotSwitchtoLookGradient Kalzium"; 0419 0420 KalziumElementProperty::instance()->setGradient(which); 0421 0422 look_action_gradients->blockSignals(true); 0423 m_gradientWidget->gradient_combo->blockSignals(true); 0424 0425 look_action_gradients->setCurrentItem(which); 0426 m_gradientWidget->gradient_combo->setCurrentIndex(which); 0427 0428 look_action_gradients->blockSignals(false); 0429 m_gradientWidget->gradient_combo->blockSignals(false); 0430 0431 m_gradientWidget->slotGradientChanged(); 0432 0433 m_legendWidget->updateContent(); 0434 } 0435 0436 void Kalzium::slotSwitchtoLookScheme(int which) 0437 { 0438 qCDebug(KALZIUM_LOG) << "slotSwitchtoLookScheme Kalzium"; 0439 0440 KalziumElementProperty::instance()->setScheme(which); 0441 0442 m_gradientWidget->scheme_combo->blockSignals(true); 0443 look_action_schemes->blockSignals(true); 0444 0445 look_action_schemes->setCurrentItem(which); 0446 m_gradientWidget->scheme_combo->setCurrentIndex(which); 0447 0448 look_action_schemes->blockSignals(false); 0449 m_gradientWidget->scheme_combo->blockSignals(false); 0450 0451 m_legendWidget->updateContent(); 0452 } 0453 0454 void Kalzium::showSettingsDialog() 0455 { 0456 if (KalziumConfigDialog::showDialog(QStringLiteral("settings"))) { 0457 return; 0458 } 0459 0460 // KalziumConfigDialog didn't find an instance of this dialog, so lets create it : 0461 m_configDialog = new KalziumConfigDialog(this, QStringLiteral("settings"), Prefs::self()); 0462 0463 connect(m_configDialog, &KalziumConfigDialog::settingsChanged, this, &Kalzium::slotUpdateSettings); 0464 connect(m_configDialog, &KalziumConfigDialog::settingsChanged, m_gradientWidget, &GradientWidgetImpl::slotGradientChanged); 0465 0466 m_configDialog->show(); 0467 } 0468 0469 void Kalzium::slotUpdateSettings() 0470 { 0471 /*This slot function calls change the color of pse elements immediately after prefs change*/ 0472 slotSwitchtoLookGradient(Prefs::colorgradientbox()); 0473 slotSwitchtoLookScheme(Prefs::colorschemebox()); 0474 } 0475 0476 void Kalzium::slotShowExportDialog() 0477 { 0478 if (!m_exportDialog) { 0479 m_exportDialog = new ExportDialog(this); 0480 } 0481 m_exportDialog->show(); 0482 } 0483 0484 void Kalzium::setupStatusBar() 0485 { 0486 auto statusBar = new QStatusBar(this); 0487 setStatusBar(statusBar); 0488 0489 m_elementInfo = new QLabel(QLatin1String("")); 0490 m_elementInfo->setAlignment(Qt::AlignRight); 0491 statusBar->addWidget(m_elementInfo, 1); 0492 statusBar->show(); 0493 } 0494 0495 void Kalzium::elementHover(int num) 0496 { 0497 // extractIconicInformationAboutElement(num); 0498 Element *e = KalziumDataObject::instance()->element(num); 0499 m_elementInfo->setText(i18nc("For example: \"Carbon (6), Mass: 12.0107 u\"", 0500 "%1 (%2), Mass: %3 u", 0501 e->dataAsString(ChemicalDataObject::name), 0502 e->dataAsString(ChemicalDataObject::atomicNumber), 0503 e->dataAsString(ChemicalDataObject::mass))); 0504 qCDebug(KALZIUM_LOG) << "change item in status bar"; 0505 0506 m_detailWidget->setElement(num); 0507 } 0508 0509 // FIXME What is that function for? Does not seem to do anything useful... yet? 0510 void Kalzium::extractIconicInformationAboutElement(int elementNumber) 0511 { 0512 const QString setname = QStringLiteral("school"); 0513 QString pathname = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("data/iconsets/"), QStandardPaths::LocateDirectory); 0514 pathname = QFileInfo(pathname).absolutePath(); 0515 const QString filename = pathname + setname + '/' + "iconinformation.txt"; 0516 0517 QFile file(filename); 0518 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 0519 return; 0520 } 0521 0522 QString infoline; 0523 0524 QTextStream in(&file); 0525 while (!in.atEnd()) { 0526 QString tmp = in.readLine(); 0527 if (tmp.startsWith(QString::number(elementNumber))) { 0528 infoline = tmp; 0529 } 0530 } 0531 0532 QString realText = QStringLiteral("Moin dies ist ein test!"); 0533 // X QString realText = infoline.remove(QRegularExpression("\\d+ ")); 0534 } 0535 0536 void Kalzium::openInformationDialog(int number) 0537 { 0538 if (m_infoDialog) { 0539 m_infoDialog->setElement(number); 0540 } else { 0541 m_infoDialog = new DetailedInfoDlg(number, this); 0542 0543 // Remove the selection when this dialog finishes or hides. 0544 connect(m_infoDialog, &DetailedInfoDlg::elementChanged, m_periodicTable, &PeriodicTableView::slotSelectOneElement); 0545 connect(m_infoDialog, &DetailedInfoDlg::elementChanged, this, &Kalzium::elementHover); 0546 } 0547 0548 m_infoDialog->setTableType(m_periodicTable->table()); 0549 m_infoDialog->show(); 0550 } 0551 0552 Kalzium::~Kalzium() 0553 { 0554 delete m_periodicTable; 0555 delete m_infoDialog; 0556 delete m_TableInfoWidget; 0557 delete m_legendWidget; 0558 delete m_gradientWidget; 0559 0560 delete m_dockWin; 0561 delete m_legendDock; 0562 delete m_tableDock; 0563 } 0564 0565 void Kalzium::loadMolecule(const QString &moleculeFile) 0566 { 0567 #if defined(HAVE_OPENBABEL) && defined(HAVE_EIGEN) && defined(HAVE_AVOGADRO) 0568 MoleculeDialog *d = slotMoleculeviewer(); 0569 if (d) { 0570 d->loadMolecule(moleculeFile); 0571 } 0572 #endif 0573 } 0574 0575 QSize Kalzium::sizeHint() const 0576 { 0577 return {700, 500}; 0578 } 0579 0580 #include "moc_kalzium.cpp"