diff --git a/CMakeLists.txt b/CMakeLists.txt index 7379dab2..4d66350b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,123 +1,122 @@ cmake_minimum_required(VERSION 3.5) # KDE Application Version, managed by release script set(KDE_APPLICATIONS_VERSION_MAJOR "19") set(KDE_APPLICATIONS_VERSION_MINOR "11") set(KDE_APPLICATIONS_VERSION_MICRO "70") set(KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") project(kalzium VERSION ${KDE_APPLICATIONS_VERSION}) set(QT_MIN_VERSION "5.9.0") set(KF5_MIN_VERSION "5.42.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${kalzium_SOURCE_DIR}/cmake/modules) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(FeatureSummary) include(ECMInstallIcons) include(ECMMarkNonGuiExecutable) include(CheckIncludeFiles) include(ECMSetupVersion) find_package(Gettext REQUIRED) find_package(PythonInterp REQUIRED) find_package(PkgConfig) find_package(OpenBabel2) find_package(AvogadroLibs) find_package(Eigen3) find_package(OCaml) find_package(Libfacile) pkg_check_modules(CHEMICAL_MIME_DATA chemical-mime-data) check_include_files(ieeefp.h HAVE_IEEEFP_H) # create configuration file set(HAVE_FACILE ${LIBFACILE_FOUND}) set(HAVE_OPENBABEL2 ${OPENBABEL2_FOUND}) set(HAVE_EIGEN ${EIGEN3_FOUND}) set(HAVE_AVOGADRO ${AvogadroLibs_FOUND}) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config-kalzium.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kalzium.h ) include_directories(${AvogadroLibs_INCLUDE_DIRS}) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Core Gui Script Svg Widgets Xml ) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Archive Config CoreAddons DocTools I18n - KHtml Parts Plotting Solid UnitConversion WidgetsAddons ) ecm_setup_version("5.0.0" VARIABLE_PREFIX KALZIUMLIB ) -# search packages used by KDE +# search packages used by KDE if(WIN32) find_package(KDEWIN32 REQUIRED) # detect oxygen icon dir at configure time based on KDEDIRS - there may be different package installation locations #execute_process(COMMAND "${KDE4_KDECONFIG_EXECUTABLE}" --path icon OUTPUT_VARIABLE _dir #ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) #file(TO_CMAKE_PATH "${_dir}" __dir) #find_path(KDE4_ICON_DIR oxygen PATHS # ${__dir}) # message(STATUS "using oxygen application icons from ${KDE4_ICON_DIR}") else(WIN32) # set (KDE4_ICON_DIR ${CMAKE_INSTALL_PREFIX}/share/icons) endif(WIN32) add_definitions( -DQT_NO_URL_CAST_FROM_STRING ) #include_directories (${QDBUS_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES} libscience) if(MSVC) # for correctly linking openbabel: # see http://www.mail-archive.com/openbabel-devel@lists.sourceforge.net/msg01975.html add_definitions(-DUSING_DYNAMIC_LIBS) endif(MSVC) if (OPENBABEL2_FOUND AND AvogadroLibs_FOUND AND EIGEN3_FOUND) find_package(Qt5OpenGL ${QT_MIN_VERSION} REQUIRED) find_package(KF5NewStuff REQUIRED) # avoid compilerwarnings about redefinitions # todo: use check_function_exits() ? message(STATUS "Kalzium molecular editor enabled") if (WIN32) add_definitions(-DHAVE_SNPRINTF -DHAVE_STRCASECMP -DHAVE_STRNCASECMP) endif (WIN32) add_subdirectory(compoundviewer) else (OPENBABEL2_FOUND AND AvogadroLibs_FOUND AND EIGEN3_FOUND) message(STATUS "Kalzium molecular editor disabled") endif (OPENBABEL2_FOUND AND AvogadroLibs_FOUND AND EIGEN3_FOUND) add_subdirectory(doc) add_subdirectory(src) add_subdirectory(data) # add_subdirectory(plasmoid) add_subdirectory(libscience) # add_subdirectory(qml) install(FILES org.kde.kalzium.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/data/htmlview/CMakeLists.txt b/data/htmlview/CMakeLists.txt index ce8a30ce..003a18ee 100644 --- a/data/htmlview/CMakeLists.txt +++ b/data/htmlview/CMakeLists.txt @@ -1,9 +1,8 @@ FILE(GLOB HTMLVIEW_ICONS "*.png") -install( FILES +install( FILES ${HTMLVIEW_ICONS} - icons.svg - style.css + icons.svg DESTINATION ${DATA_INSTALL_DIR}/kalzium/data/htmlview ) diff --git a/data/htmlview/characteristics.png b/data/htmlview/characteristics.png deleted file mode 100644 index db7afa34..00000000 Binary files a/data/htmlview/characteristics.png and /dev/null differ diff --git a/data/htmlview/header.png b/data/htmlview/header.png deleted file mode 100644 index 56eb9596..00000000 Binary files a/data/htmlview/header.png and /dev/null differ diff --git a/data/htmlview/style.css b/data/htmlview/style.css deleted file mode 100644 index c5876920..00000000 --- a/data/htmlview/style.css +++ /dev/null @@ -1,93 +0,0 @@ -body -{ - font-family:'arial'; -} - -/* The outer div */ -div.chemdata -{ - border: 1px solid rgb(50,80,150); - overflow:visible; -} - -/* The header div */ -div.chemdata div -{ - background-image:url('header.png'); -} - -/* The table inside the header div */ -div.chemdata div table -{ - margin:0px; - width:100%; - color:rgb(240,240,240); - font-weight:bold; -} - -/* The td inside the header table */ -div.chemdata div table td -{ - padding-left:4px; -} - -/* The second td inside the header table */ -div.chemdata div table td+td -{ - font-size:80%; -} - -/* The third td inside the header table */ -div.chemdata div table td+td+td -{ - text-align:right; - font-size:80%; -} - -table.header -{ - table-layout:fixed; -} - -/* The link color inside the header table */ -table.header a -{ - color: rgb(240,240,240); -} - -/* The table containing the characterstics */ -table.characterstics -{ - background-color: white; - background-image:url('characteristics.png'); - background-repeat:repeat-y; - width:100%; -} - -/* The td's inside the characterstics-table */ -table.characterstics td -{ - padding:3px; - padding-left:5px; - vertical-align:middle; - text-align:center; -} - -/* The second td inside the characterstics-table (text) */ -table.characterstics td+td -{ - text-align:left; -} - -table.isotopes td -{ - border-left:1px #000000 solid; - border-bottom:1px #000000 solid; -} - -table.isotopes -{ - border-right:1px #000000 solid; - border-top:1px #000000 solid; -} - diff --git a/libscience/isotopeparser.h b/libscience/isotopeparser.h index 19333622..6fd56bf4 100644 --- a/libscience/isotopeparser.h +++ b/libscience/isotopeparser.h @@ -1,51 +1,51 @@ /*************************************************************************** copyright : (C) 2005 by Carsten Niehaus email : cniehaus@kde.org ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef ISOTOPEPARSER_H #define ISOTOPEPARSER_H #include #include #include #include "libkdeedu_science_export.h" class Isotope; /** * @author Carsten Niehaus */ class SCIENCE_EXPORT IsotopeParser : public QXmlDefaultHandler { public: /** * Constructor */ IsotopeParser(); - ~IsotopeParser(); + ~IsotopeParser() override; bool startElement(const QString &, const QString &localName, const QString &, const QXmlAttributes &attrs) override; bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName) override; bool characters(const QString &ch) override; QList getIsotopes(); private: class Private; Private *const d; }; #endif // ISOTOPEPARSER_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46332315..88177dbe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,205 +1,210 @@ include_directories( ${CMAKE_SOURCE_DIR}/libscience/ ../compoundviewer tools calculator psetable isotopetable ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) ecm_setup_version(${KDE_APPLICATIONS_VERSION} VARIABLE_PREFIX KALZIUM VERSION_HEADER kalzium_version.h) ########### next target ############### # The tools can only be built when OpenBabel2 is found. # The moleculeviewer needs not only OpenBabel2 but also Eigen2 and Avogadro, # so there is a nested if-check. if (OPENBABEL2_FOUND) set(kalziumtools_SRCS tools/obconverter.cpp ) ki18n_wrap_ui(kalziumtools_SRCS tools/obconverterwidget.ui ) include_directories(SYSTEM ${OPENBABEL2_INCLUDE_DIR}) if (EIGEN3_FOUND AND AvogadroLibs_FOUND) #include(${Avogadro_USE_FILE}) set(kalziumtools_SRCS ${kalziumtools_SRCS} tools/moleculeview.cpp ../compoundviewer/kalziumglwidget.cpp ) ki18n_wrap_ui(kalziumtools_SRCS tools/moleculeviewerwidget.ui ) include_directories(${EIGEN3_INCLUDE_DIR}) endif (EIGEN3_FOUND AND AvogadroLibs_FOUND) endif (OPENBABEL2_FOUND) ## Kalzium calculator files set(kalziumtools_SRCS ${kalziumtools_SRCS} calculator/calculator.cpp calculator/nuclearCalculator.cpp calculator/gasCalculator.cpp calculator/concCalculator.cpp calculator/titrationCalculator.cpp # calculator/massCalculator.cpp ) ki18n_wrap_ui(kalziumtools_SRCS calculator/calculator.ui calculator/nuclearCalculator.ui calculator/gasCalculator.ui calculator/concCalculator.ui calculator/settings_calc.ui calculator/titrationCalculator.ui # calculator/massCalculator.ui ) set(kalzium_SRCS ${kalziumtools_SRCS} isotopetable/informationitem.cpp isotopetable/isotopeguideview.cpp isotopetable/isotopeitem.cpp isotopetable/isotopescene.cpp isotopetable/isotopetabledialog.cpp isotopetable/isotopeview.cpp psetable/elementitem.cpp psetable/numerationitem.cpp psetable/periodictableview.cpp psetable/periodictablescene.cpp psetable/periodictablestates.cpp psetable/statemachine.cpp kalzium.cpp main.cpp detailinfodlg.cpp tablesdialog.cpp detailedgraphicaloverview.cpp orbitswidget.cpp elementdataviewer.cpp molcalcwidget.cpp gradientwidget_impl.cpp kalziumdataobject.cpp kalziumutils.cpp kalziumgradienttype.cpp kalziumnumerationtype.cpp kalziumelementproperty.cpp kalziumschemetype.cpp kalziumunitcombobox.cpp unitsettingsdialog.cpp search.cpp searchwidget.cpp rsdialog.cpp legendwidget.cpp exportdialog.cpp tableinfowidget.cpp spectrumviewimpl.cpp spectrumwidget.cpp kdeeduglossary.cpp ) if (LIBFACILE_FOUND) include(CMakeOCamlInstructions.cmake) set(kalzium_SRCS ${kalzium_SRCS} eqchemview.cpp ${CMAKE_CURRENT_BINARY_DIR}/solver.o ${CMAKE_CURRENT_BINARY_DIR}/modwrap.o ) ki18n_wrap_ui(kalzium_SRCS equationview.ui ) endif (LIBFACILE_FOUND) ki18n_wrap_ui(kalzium_SRCS isotopetable/isotopedialog.ui settings_colors.ui plotsetupwidget.ui molcalcwidgetbase.ui spectrumview.ui settings_gradients.ui rswidget.ui gradientwidget.ui exportdialog.ui ) kconfig_add_kcfg_files(kalzium_SRCS prefs.kcfgc ) #kde4_add_app_icon(kalzium_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/hi*-app-kalzium.png") add_executable(kalzium ${kalzium_SRCS}) target_link_libraries(kalzium + KF5::Completion + KF5::ConfigWidgets + KF5::ItemViews + KF5::KIOWidgets KF5::Plotting - KF5::KHtml + KF5::Service + KF5::TextWidgets KF5::UnitConversion - KF5::ItemViews + KF5::XmlGui Qt5::Script Qt5::Svg science ) if (OPENBABEL2_FOUND) target_link_libraries(kalzium ${OPENBABEL2_LIBRARIES}) if (EIGEN3_FOUND AND AvogadroLibs_FOUND) target_link_libraries(kalzium KF5::NewStuff Qt5::OpenGL compoundviewer AvogadroQtGui AvogadroQtOpenGL AvogadroQtPlugins ) endif (EIGEN3_FOUND AND AvogadroLibs_FOUND) endif (OPENBABEL2_FOUND) if (LIBFACILE_FOUND) link_directories(${OCAMLC_DIR}) set(CMAKE_LIBRARY_PATH ${OCAMLC_DIR}) set(kalzium_EXTRA_LIBS) find_library(OCAML_ASMRUN_LIBRARY NAMES asmrun) if (OCAML_ASMRUN_LIBRARY) set(kalzium_EXTRA_LIBS ${kalzium_EXTRA_LIBS} ${OCAML_ASMRUN_LIBRARY}) endif (OCAML_ASMRUN_LIBRARY) find_library(OCAML_STR_LIBRARY NAMES str) if (OCAML_STR_LIBRARY) set(kalzium_EXTRA_LIBS ${kalzium_EXTRA_LIBS} ${OCAML_STR_LIBRARY}) endif (OCAML_STR_LIBRARY) find_library(OCAML_NUMS_LIBRARY NAMES nums) if (OCAML_NUMS_LIBRARY) set(kalzium_EXTRA_LIBS ${kalzium_EXTRA_LIBS} ${OCAML_NUMS_LIBRARY}) endif (OCAML_NUMS_LIBRARY) target_link_libraries(kalzium ${kalzium_EXTRA_LIBS} m ${CMAKE_DL_LIBS}) endif (LIBFACILE_FOUND) install(TARGETS kalzium ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install(PROGRAMS org.kde.kalzium.desktop org.kde.kalzium_cml.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) install(FILES kalzium.kcfg DESTINATION ${KCFG_INSTALL_DIR}) install(FILES kalziumui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kalzium) install(FILES kalzium.knsrc DESTINATION ${CONFIG_INSTALL_DIR}) ecm_install_icons(ICONS 16-apps-kalzium.png 22-apps-kalzium.png 32-apps-kalzium.png 48-apps-kalzium.png 64-apps-kalzium.png 128-apps-kalzium.png sc-apps-kalzium.svgz DESTINATION ${KDE_INSTALL_ICONDIR} THEME hicolor ) diff --git a/src/detailinfodlg.cpp b/src/detailinfodlg.cpp index 5ee57092..b9626a27 100644 --- a/src/detailinfodlg.cpp +++ b/src/detailinfodlg.cpp @@ -1,637 +1,603 @@ /*************************************************************************** begin : Tue Apr 8 2003 copyright : (C) 2003, 2004, 2005, 2006 by Carsten Niehaus email : cniehaus@kde.org ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "detailinfodlg.h" #include "detailedgraphicaloverview.h" #include "element.h" #include "isotope.h" #include "kalziumdataobject.h" #include "kalziumutils.h" #include "orbitswidget.h" #include "prefs.h" #include "psetables.h" #include "spectrumviewimpl.h" #include #include #include #include #include #include #include #include #include #include +#include #include -#include -#include #include #include -#include -#include #include #include #include #include DetailedInfoDlg::DetailedInfoDlg(int el, QWidget *parent) : KPageDialog(parent), m_tableTyp(0) { setFaceType(List); buttonBox()->clear(); buttonBox()->addButton(QDialogButtonBox::Close); buttonBox()->addButton(QDialogButtonBox::Help); const QString nextButtonIconSource = (layoutDirection() == Qt::LeftToRight) ? "arrow-right" : "arrow-left"; QPushButton *nextButton = new QPushButton(QIcon::fromTheme(nextButtonIconSource), i18nc("Next element", "Next"), this); nextButton->setToolTip(i18n("Goes to the next element")); const QString prevButtonIconSource = (layoutDirection() == Qt::LeftToRight) ? "arrow-left" : "arrow-right"; QPushButton *prevButton = new QPushButton(QIcon::fromTheme(prevButtonIconSource), i18nc("Previous element", "Previous"), this); prevButton->setToolTip(i18n("Goes to the previous element")); buttonBox()->addButton(prevButton, QDialogButtonBox::ActionRole); buttonBox()->addButton(nextButton, QDialogButtonBox::ActionRole); resize(820, 580); m_baseHtml = QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("data/htmlview/"), QStandardPaths::LocateDirectory); m_baseHtml2 = QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("data/hazardsymbols/"), QStandardPaths::LocateDirectory); //X m_picsdir = QStandardPaths::locate(QStandardPaths::DataLocation, "elempics/") + "elempics/"; //X m_picsdir = QFileInfo(m_picsdir).absolutePath(); // creating the tabs but not the contents, as that will be done when setting the element createContent(); m_actionCollection = new KActionCollection(this); KStandardAction::quit(this, SLOT(close()), m_actionCollection); connect(prevButton, &QPushButton::clicked, this, &DetailedInfoDlg::showPreviousElement); connect(nextButton, &QPushButton::clicked, this, &DetailedInfoDlg::showNextElement); connect(buttonBox(), &QDialogButtonBox::helpRequested, this, &DetailedInfoDlg::slotHelp); // setting the element and updating the whole dialog setElement(el); } DetailedInfoDlg::~DetailedInfoDlg() { qDeleteAll(m_htmlpages); } void DetailedInfoDlg::setElement(int el) { Element *element = KalziumDataObject::instance()->element(el); if (!element) { return; } m_element = element; m_elementNumber = el; emit elementChanged(m_elementNumber); reloadContent(); /* enableButton(User1, true); user2Button->setEnabled(true); if (m_elementNumber == 1) { user2Button->setEnabled(false); } else if (m_elementNumber == KalziumDataObject::instance()->numberOfElements()) { user1Button->setEnabled(false); }*/ } // void DetailedInfoDlg::setOverviewBackgroundColor(const QColor &bgColor) // { // // dTab->setBackgroundColor(bgColor); // } void DetailedInfoDlg::setTableType(int tableTyp) { m_tableTyp = tableTyp; } -KHTMLPart* DetailedInfoDlg::addHTMLTab(const QString& title, const QString& icontext, const QString& iconname) +QTextBrowser* DetailedInfoDlg::addHTMLTab(const QString& title, const QString& icontext, const QString& iconname) { QWidget* frame = new QWidget(this); KPageWidgetItem *item = addPage(frame, title); item->setHeader(icontext); item->setIcon(QIcon::fromTheme(iconname)); QVBoxLayout *layout = new QVBoxLayout(frame); layout->setContentsMargins(0, 0, 0, 0); - - KHTMLPart *w = new KHTMLPart(frame, frame); - w->setJScriptEnabled(false); - w->setJavaEnabled(false); - w->setMetaRefreshEnabled(false); - w->setPluginsEnabled(false); - connect(w->browserExtension(), &KParts::BrowserExtension::openUrlRequest, this, &DetailedInfoDlg::slotLinkClicked); - layout->addWidget(w->view()); - - return w; + QTextBrowser *browser = new QTextBrowser(frame); + browser->setOpenExternalLinks(true); + layout->addWidget(browser); + return browser; } -void DetailedInfoDlg::fillHTMLTab(KHTMLPart* htmlpart, const QString& htmlcode) +void DetailedInfoDlg::fillHTMLTab(QTextBrowser *browser, const QString& htmlcode) { - if (!htmlpart) { + if (!browser) { return; } - - htmlpart->begin(); - htmlpart->write(htmlcode); - - // set the background color of the document to match that of the dialog - DOM::HTMLElement element = htmlpart->htmlDocument().body(); - if (element.tagName() == "body") { - const QColor backgroundColor = palette().window().color(); - ((DOM::HTMLBodyElement)element).setBgColor(backgroundColor.name()); - } - - htmlpart->end(); + browser->setHtml(htmlcode); } QString DetailedInfoDlg::getHtml(DATATYPE type) { - QString html = - "" - "Chemical data" - "" - "" - "
" - "
" + m_element->dataAsString(ChemicalDataObject::symbol) + "" - + createWikiLink(m_element->dataAsString(ChemicalDataObject::name)) + "" - + i18n("Block: %1", m_element->dataAsString(ChemicalDataObject::periodTableBlock)) + - "
" - ""; + QString html = "
"; switch (type) { case MISC: { // discovery date and discoverers html.append(""); // origin of the name QString nameorigin = m_element->dataAsString(ChemicalDataObject::nameOrigin); if (!nameorigin.isEmpty()) { html.append(""); } //X if (m_element->artificial() || m_element->radioactive()) { //X html.append(""); //X } break; } case ISOTOPES: { html.append(""); break; } case DATA: { // melting point html.append(""); // boiling point html.append(""); // electro affinity html.append(""); //Electronic configuration html.append(""); // covalent radius html.append(""); // van der Waals radius html.append(""); // mass html.append(""); // 1st ionization energy html.append(""); // electro negativity html.append(""); // Oxidation numbers html.append(""); break; } case EXTRA: { //Wikipedia.org // html.append (""); //http://education.jlab.org/itselemental/ele001.html html.append (""); // FIXME only works with english locals html.append (""); //chemipedia.org //html.append(""); //physics.nist.gov //html.append(""); } } html += QLatin1String("
\"icon\"/"); html += KalziumUtils::prettyUnit(m_element, ChemicalDataObject::date); QString discoverers = m_element->dataAsString(ChemicalDataObject::discoverers); if (!discoverers.isEmpty()) { discoverers = discoverers.replace(';', QLatin1String(", ")); html += "
" + i18n("It was discovered by %1.", discoverers); } html.append("
\"icon\"/"); html.append(i18n("Origin of the name:
%1", nameorigin)); html.append("
\"icon\"/"); //X if (!m_element->radioactive()) { //X html.append(i18n("This element is artificial")); //X } else if (!m_element->artificial()) { //X html.append(i18n("This element is radioactive")); //X } else { //X html.append(i18n("This element is radioactive and artificial")); //X } //X html.append("
"); html.append(isotopeTable()); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Melting Point"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::meltingpoint)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Boiling Point"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::boilingpoint)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Electron Affinity"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::electronAffinity)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Electronic configuration"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::electronicConfiguration)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Covalent Radius"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::radiusCovalent)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("van der Waals Radius"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::radiusVDW)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Atomic mass"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::mass)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Ionization energy"), i18n("First Ionization energy"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::ionization)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Electronegativity"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::electronegativityPauling)); html.append("
\"icon\"/"); html.append(createWikiLink(i18n("Oxidation states"))); html.append(""); html.append(KalziumUtils::prettyUnit(m_element, ChemicalDataObject::oxidation)); html.append("
\"icon\"/"); html.append ("
"); html.append (createWikiLink(m_element->dataAsString(ChemicalDataObject::name), i18nc("Link to element's Wikipedia page, %1 is localized language name", "Wikipedia (%1)", QLocale().nativeLanguageName()))); html.append ("
"); - html.append ("dataAsString(ChemicalDataObject::atomicNumber), 3, '0')); html.append (".html"); html.append ("\" target=\"_blank\" > "); html.append ("Jefferson Lab"); html.append (""); html.append ("
"); - html.append ("dataAsString(ChemicalDataObject::name).toLower()); // hydrogen } html.append ("\" target=\"_blank\" >"); html.append ("Webelements"); html.append ("
\"icon\"/"); //html.append("
\"icon\"/"); //html.append("
"); return html; } QString DetailedInfoDlg::isotopeTable() const { QList list = KalziumDataObject::instance()->isotopes(m_elementNumber); QString html; - - html = QStringLiteral("
"); - html += i18n("Isotope-Table"); - html += QLatin1String("
"); + html = QStringLiteral(""); + html += QLatin1String(""); foreach (Isotope *isotope, list) { html.append(""); } html += QLatin1String("
"); html += i18n("Mass"); - html += QLatin1String(""); + html += QLatin1String(""); html += i18n("Neutrons"); - html += QLatin1String(""); + html += QLatin1String(""); html += i18n("Percentage"); - html += QLatin1String(""); + html += QLatin1String(""); html += i18n("Half-life period"); - html += QLatin1String(""); + html += QLatin1String(""); html += i18n("Energy and Mode of Decay"); - html += QLatin1String(""); + html += QLatin1String(""); html += i18n("Spin and Parity"); - html += QLatin1String(""); + html += QLatin1String(""); html += i18n("Magnetic Moment"); - html += QLatin1String("
"); if (isotope->mass() > 0.0) { html.append(i18n("%1 u", isotope->mass())); } html.append(""); html.append(QString::number(((isotope)->nucleons() - (isotope)->parentElementNumber()))); html.append(""); if (!(isotope)->abundance().isEmpty()) { html.append(i18nc("this can for example be '24%'", "%1%", (isotope)->abundance())); } html.append(""); if ((isotope)->halflife() > 0.0) { - html.append(i18nc("The first argument is the value, the second is the unit. For example '17 s' for '17 seconds',.", "%1 %2", (isotope)->halflife(), (isotope)->halflifeUnit())); + html.append(i18nc("The first argument is the value, the second is the unit. For example '17 s' for '17 seconds',.", "%1 %2", + (isotope)->halflife(), (isotope)->halflifeUnit())); } html.append(""); if ((isotope)->alphalikeliness() > 0.0) { if ((isotope)->alphadecay() > 0.0) { html.append(i18n("%1 MeV", (isotope)->alphadecay())); } html.append(i18n(" %1", QChar(945))); if ((isotope)->alphalikeliness() < 100.0) { html.append(i18n("(%1%)", (isotope)->alphalikeliness())); } if ((isotope)->betaminuslikeliness() > 0.0 || (isotope)->betapluslikeliness() > 0.0 || (isotope)->eclikeliness() > 0.0) { html.append(i18n(", ")); } } if ((isotope)->betaminuslikeliness() > 0.0) { if ((isotope)->betaminusdecay() > 0.0) { html.append(i18n("%1 MeV", (isotope)->betaminusdecay())); } html.append(i18n(" %1-", QChar(946))); if ((isotope)->betaminuslikeliness() < 100.0) { html.append(i18n("(%1%)", (isotope)->betaminuslikeliness())); } if ((isotope)->betapluslikeliness() > 0.0 || (isotope)->eclikeliness() > 0.0) { html.append(i18n(", ")); } } if ((isotope)->betapluslikeliness() > 0.0) { if ((isotope)->betaplusdecay() > 0.0) { html.append(i18n("%1 MeV", (isotope)->betaplusdecay())); } html.append(i18n(" %1+", QChar(946))); if ((isotope)->betapluslikeliness() == (isotope)->eclikeliness()) { if ((isotope)->ecdecay() > 0.0) { html.append(i18n("%1 MeV", (isotope)->ecdecay())); } html.append(i18nc("Acronym of Electron Capture"," EC")); } if ((isotope)->betapluslikeliness() < 100.0) { html.append(i18n("(%1%)", (isotope)->betapluslikeliness())); } html += ' '; } if ((isotope)->eclikeliness() > 0.0) { if ((isotope)->ecdecay() > 0.0) { html.append(i18n("%1 MeV", (isotope)->ecdecay())); } html.append(i18nc("Acronym of Electron Capture"," EC")); if ((isotope)->eclikeliness() < 100.0) { html.append(i18n("(%1%)", (isotope)->eclikeliness())); } } html.append(""); html.append((isotope)->spin()); html.append(""); if (!(isotope)->magmoment().isEmpty()) { html.append(i18n("%1 %2n", (isotope)->magmoment(), QChar(956))); } html.append("
"); return html; } void DetailedInfoDlg::createContent() { KPageWidgetItem *item = nullptr; // Removed the overview Tab, because its an Dockwidget and doesn't show much information. // overview tab // QWidget *m_pOverviewTab = new QWidget(); // item = addPage(m_pOverviewTab, i18n("Overview")); // item->setHeader(i18n("Overview")); // item->setIcon(QIcon("overview")); // QVBoxLayout *overviewLayout = new QVBoxLayout(m_pOverviewTab); // overviewLayout->setContentsMargins(0, 0, 0, 0); // dTab = new DetailedGraphicalOverview(m_pOverviewTab); // dTab->setObjectName("DetailedGraphicalOverview"); // overviewLayout->addWidget(dTab); //X // picture tab //X QWidget *m_pPictureTab = new QWidget(); //X item = addPage(m_pPictureTab, i18n("Picture")); //X item->setHeader(i18n("What does this element look like?")); //X item->setIcon(QIcon("elempic")); //X QVBoxLayout *mainLayout = new QVBoxLayout(m_pPictureTab); //X mainLayout->setContentsMargins(0, 0, 0, 0); //X piclabel = new QLabel(m_pPictureTab); //X piclabel->setMinimumSize(400, 350); //X mainLayout->addWidget(piclabel); // html tab m_htmlpages[QStringLiteral("new")] = addHTMLTab(i18n("Data Overview"), i18n("Data Overview"), QStringLiteral("applications-science")); // atomic model tab QWidget *m_pModelTab = new QWidget(this); item = addPage(m_pModelTab, i18n("Atom Model")); item->setHeader(i18n("Atom Model")); item->setIcon(QIcon::fromTheme(QStringLiteral("orbits"))); QVBoxLayout *modelLayout = new QVBoxLayout(m_pModelTab); modelLayout->setContentsMargins(0, 0, 0, 0); wOrbits = new OrbitsWidget(m_pModelTab); modelLayout->addWidget(wOrbits); // html tabs m_htmlpages[QStringLiteral("isotopes")] = addHTMLTab(i18n("Isotopes"), i18n("Isotopes"), QStringLiteral("isotopemap")); m_htmlpages[QStringLiteral("misc")] = addHTMLTab(i18n("Miscellaneous"), i18n("Miscellaneous"), QStringLiteral("misc")); - // spectrum widget tab QWidget *m_pSpectrumTab = new QWidget(this); item = addPage(m_pSpectrumTab, i18n("Spectrum")); item->setHeader(i18n("Spectrum")); item->setIcon(QIcon::fromTheme(QStringLiteral("spectrum"))); QVBoxLayout *spectrumLayout = new QVBoxLayout(m_pSpectrumTab); spectrumLayout->setContentsMargins(0, 0, 0, 0); m_spectrumStack = new QStackedWidget(m_pSpectrumTab); spectrumLayout->addWidget(m_spectrumStack); m_spectrumview = new SpectrumViewImpl(m_spectrumStack); m_spectrumview->setObjectName(QStringLiteral("spectrumwidget")); m_spectrumStack->addWidget(m_spectrumview); m_spectrumLabel = new QLabel(m_spectrumStack); m_spectrumStack->addWidget(m_spectrumLabel); // html extra tab m_htmlpages[QStringLiteral("extra")] = addHTMLTab(i18n("Extra information"), i18n("Extra Information"), QStringLiteral("applications-internet")); } void DetailedInfoDlg::reloadContent() { // reading the most common data const QString element_name = m_element->dataAsString(ChemicalDataObject::name); -// const QString element_symbol = m_element->dataAsString(ChemicalDataObject::symbol); + const QString element_symbol = m_element->dataAsString(ChemicalDataObject::symbol); + const QString element_block = m_element->dataAsString(ChemicalDataObject::periodTableBlock); // updating caption - setWindowTitle(i18nc("For example Carbon (6)", "%1 (%2)", element_name, m_elementNumber)); - - // updating overview tab -// dTab->setElement(m_elementNumber); + setWindowTitle(i18nc("For example: [C] Carbon (6 - Block p)", "[%1] %2 (%3 - Block %4)", + element_symbol, element_name, m_elementNumber, element_block)); //X // updating picture tab //X QString picpath = m_picsdir + element_symbol + ".jpg"; //X if (QFile::exists(picpath)) { //X QImage img(picpath, "JPEG"); //X img = img.scaled(400, 400, Qt::KeepAspectRatio); //X piclabel->setPixmap(QPixmap::fromImage(img)); //X } else { //X piclabel->setText(i18n("No picture of %1 found.", element_name)); //X } // updating atomic model tab wOrbits->setElementNumber(m_elementNumber); /* wOrbits->setWhatsThis( i18n("Here you can see the atomic hull of %1. %2 has the configuration %3.") .arg(m_element->dataAsString(ChemicalDataObject::name)) .arg(m_element->dataAsString(ChemicalDataObject::name)) .arg(""));//m_element->parsedOrbits())); */ // updating html tabs fillHTMLTab(m_htmlpages[QStringLiteral("new")], getHtml(DATA)); fillHTMLTab(m_htmlpages[QStringLiteral("misc")], getHtml(MISC)); fillHTMLTab(m_htmlpages[QStringLiteral("isotopes")], getHtml(ISOTOPES)); fillHTMLTab(m_htmlpages[QStringLiteral("extra")], getHtml(EXTRA)); Spectrum * spec = KalziumDataObject::instance()->spectrum(m_elementNumber); // updating spectrum widget if (spec) { m_spectrumview->setSpectrum(spec); m_spectrumStack->setCurrentWidget(m_spectrumview); } else { m_spectrumLabel->setText(i18n("No spectrum of %1 found.", element_name)); m_spectrumStack->setCurrentWidget(m_spectrumLabel); } } QString DetailedInfoDlg::createWikiLink(QString link) { return createWikiLink(link, link); } QString DetailedInfoDlg::createWikiLink(QString link, QString displayString) { QString html; QString language(QLocale().uiLanguages().first()); //Wikipedia.org - html.append (" "); html.append (displayString); html.append (""); - // Example from the comment "http://en.wikipedia.org/wiki/hydrogen" + // Example from the comment "https://en.wikipedia.org/wiki/hydrogen" - return html; + return html; } void DetailedInfoDlg::slotLinkClicked(const QUrl &url) { if (url.isEmpty() || !url.isValid()) { return; } KRun::runUrl(url, QStringLiteral("text/html"), this, KRun::RunFlags(), QString(), QByteArray()); } void DetailedInfoDlg::slotHelp() { //TODO fix this stuff... #if 0 QString chapter = "infodialog_overview"; switch (activePageIndex()) { case 0: chapter = "infodialog_overview"; break; case 1: chapter = "infodialog_orbits"; break; case 2: chapter = "infodialog_chemical"; break; case 3: chapter = "infodialog_energies"; break; case 4: chapter = "infodialog_misc"; break; case 5: chapter = "infodialog_spectrum"; break; case 6: chapter = "infodialog_warnings"; break; } #endif KHelpClient::invokeHelp(QStringLiteral("info-dlg.html#infodialog_spectrum"), QStringLiteral("kalzium")); } void DetailedInfoDlg::showNextElement() { setElement(pseTables::instance()->getTabletype(m_tableTyp)->nextOf(m_elementNumber)); } void DetailedInfoDlg::showPreviousElement() { setElement(pseTables::instance()->getTabletype(m_tableTyp)->previousOf(m_elementNumber)); } diff --git a/src/detailinfodlg.h b/src/detailinfodlg.h index c6e43c4d..0d2cedc8 100644 --- a/src/detailinfodlg.h +++ b/src/detailinfodlg.h @@ -1,141 +1,142 @@ /*************************************************************************** begin : Tue Apr 2 20:43:44 2002 UTC copyright : (C) 2003, 2004, 2005, 2006 by Carsten Niehaus email : cniehaus@kde.org ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef DETAILINFODLG_H #define DETAILINFODLG_H #include #include #include class DetailedGraphicalOverview; class Element; class OrbitsWidget; class SpectrumViewImpl; +class KActionCollection; class QLabel; class QStackedWidget; -class KActionCollection; +class QTextBrowser; class KHTMLPart; /** * @brief The dialog which shows all available information of an element * @author Carsten Niehaus */ class DetailedInfoDlg : public KPageDialog { Q_OBJECT public: explicit DetailedInfoDlg(int el, QWidget *parent = nullptr); ~DetailedInfoDlg(); void setElement(int el); // void setOverviewBackgroundColor(const QColor &bgColor); void setTableType(int ktt); /** * add to the numbers @return the beatified string */ QString beautifyOrbitalString(const QString& orbits); private: enum DATATYPE { MISC = 0, ISOTOPES, DATA, /** m_htmlpages; + QMap m_htmlpages; int m_tableTyp; /** * Create the initial set of tabs. Used it *ONLY* once in the * constructor. */ void createContent(); void reloadContent(); QString getHtml(DATATYPE); QString m_baseHtml; QString m_baseHtml2; //X QString m_picsdir; /** * Add a new HTML page to the dialog. * * @param title The title of the tab, appears above the htmlview * @param icontext The name of the tab, appears belov or instead * of the icon * @param iconname The name of the icon * @returns the pointer to the resulting KHTMLPart, needed for * writing HTML code on it */ - KHTMLPart* addHTMLTab(const QString& title, const QString& icontext, const QString& iconname); + QTextBrowser* addHTMLTab(const QString& title, const QString& icontext, const QString& iconname); /** * Change the HTML code in an HTML page. * - * @param htmlpart the KHTMLPart to edit + * @param browser the QTextBrowser to edit * @param htmlcode the HTML code to display */ - void fillHTMLTab(KHTMLPart* htmlpart, const QString& htmlcode); + void fillHTMLTab(QTextBrowser *browser, const QString& htmlcode); /** * Creates a localized link to Wikipedia. * http://en.wikipedia.org/wiki/link" * @param link the link inside wikipedia * @param displayString the displayed string to click on. */ QString createWikiLink(QString link, QString displayString); /// overloaded function to add link as the displayed String QString createWikiLink(QString link); private slots: void slotLinkClicked(const QUrl &url); void showNextElement(); void showPreviousElement(); /** * invoke the help of the correct chapter */ virtual void slotHelp(); signals: void elementChanged(int); }; #endif // DETAILINFODLG_H diff --git a/src/kalzium.cpp b/src/kalzium.cpp index fb63d256..f205f79d 100644 --- a/src/kalzium.cpp +++ b/src/kalzium.cpp @@ -1,648 +1,647 @@ /*************************************************************************** copyright : (C) 2003-2007 by Carsten Niehaus email : cniehaus@kde.org ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "kalzium.h" #include #include #include "prefs.h" #include "ui_settings_colors.h" #include "ui_settings_gradients.h" #include "ui_settings_calc.h" #include "detailinfodlg.h" #include "detailedgraphicaloverview.h" #include "gradientwidget_impl.h" #include "kalziumdataobject.h" #include "kalziumnumerationtype.h" #include "kalziumschemetype.h" #include "kalziumgradienttype.h" #include "legendwidget.h" #include "exportdialog.h" #include "search.h" #include "searchwidget.h" #include "tableinfowidget.h" #include "psetables.h" #include #ifdef HAVE_FACILE #include "eqchemview.h" #endif #ifdef HAVE_OPENBABEL2 #if defined(HAVE_EIGEN) && defined(HAVE_AVOGADRO) #include "tools/moleculeview.h" #include #endif #include "tools/obconverter.h" #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #define IDS_ELEMENTINFO 7 Kalzium::Kalzium() : KXmlGuiWindow(nullptr) { setObjectName(QStringLiteral("KalziumMainWindow")); // Init pointers with null m_infoDialog = nullptr; m_isotopeDialog = nullptr; m_elementDataPlotter = nullptr; m_tablesDialog = nullptr; m_rsDialog = nullptr; m_calculator = nullptr; m_exportDialog = nullptr; m_glossarydlg = nullptr; m_elementInfo = nullptr; // reading the elements from file KalziumDataObject::instance(); Search *newsearch = new Search(); KalziumDataObject::instance()->setSearch(newsearch); // Main pse-Table Tablewidget QWidget *pseTempWidget = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(pseTempWidget); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(2); SearchWidget *searchWidget = new SearchWidget(pseTempWidget); searchWidget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum)); // Creating the periodic table m_periodicTable = new PeriodicTableView(pseTempWidget); // Connecting the search to the periodic table connect(newsearch, &Search::searchChanged, KalziumElementProperty::instance(), &KalziumElementProperty::propertyChanged); connect(newsearch, &Search::searchReset, KalziumElementProperty::instance(), &KalziumElementProperty::propertyChanged); layout->addWidget(searchWidget); layout->addWidget(m_periodicTable); setCentralWidget(pseTempWidget); connect(m_periodicTable->pseScene(), &PeriodicTableScene::elementChanged, this, &Kalzium::openInformationDialog); connect(m_periodicTable->pseScene(), &PeriodicTableScene::elementHovered, this, &Kalzium::elementHover); connect(this, &Kalzium::numerationChanged, m_periodicTable, &PeriodicTableView::numerationChange); // layouting setupSidebars(); setupActions(); setupStatusBar(); } void Kalzium::setupActions() { export_action = actionCollection()->add(QStringLiteral("file_exporter")); export_action->setText(i18n("&Export Data...")); connect(export_action, &QAction::triggered, this, &Kalzium::slotShowExportDialog); // the action for switching look: color schemes and gradients QStringList schemes = KalziumElementProperty::instance()->schemeList(); /*KalziumSchemeTypeFactory::instance()->schemes();*/ QStringList gradients = KalziumElementProperty::instance()->gradientList(); // the action for switching look: schemes look_action_schemes = actionCollection()->add(QStringLiteral("view_look_onlyschemes")); look_action_schemes->setText(i18n("&Scheme")); look_action_schemes->setItems(schemes); look_action_schemes->setToolBarMode(KSelectAction::MenuMode); look_action_schemes->setToolButtonPopupMode(QToolButton::InstantPopup); connect(look_action_schemes, SIGNAL(triggered(int)), this, SLOT(slotSwitchtoLookScheme(int))); // the action for switching look: gradients look_action_gradients = actionCollection()->add(QStringLiteral("view_look_onlygradients")); look_action_gradients->setText(i18n("&Gradients")); look_action_gradients->setItems(gradients); look_action_gradients->setToolBarMode(KSelectAction::MenuMode); look_action_gradients->setToolButtonPopupMode(QToolButton::InstantPopup); connect(look_action_gradients, SIGNAL(triggered(int)), this, SLOT(slotSwitchtoLookGradient(int))); // the action for switching tables QStringList table_schemes = pseTables::instance()->tables(); table_action = actionCollection()->add(QStringLiteral("view_table")); table_action->setText(i18n("&Tables")); table_action->setItems(table_schemes); table_action->setCurrentItem(Prefs::table()); connect(table_action, SIGNAL(triggered(int)), this, SLOT(slotSwitchtoTable(int))); // the actions for switching numeration numeration_action = actionCollection()->add(QStringLiteral("view_numerationtype")); numeration_action->setText(i18n("&Numeration")); numeration_action->setItems(KalziumNumerationTypeFactory::instance()->numerations()); numeration_action->setCurrentItem(Prefs::numeration()); connect(numeration_action, SIGNAL(triggered(int)), this, SLOT(slotSwitchtoNumeration(int))); // tools actions m_pPlotAction = actionCollection()->addAction(QStringLiteral("tools_plotdata")); m_pPlotAction->setText(i18n("&Plot Data...")); m_pPlotAction->setIcon(QIcon::fromTheme(QStringLiteral("plot"))); connect(m_pPlotAction, &QAction::triggered, this, &Kalzium::slotPlotData); // calculator actions m_pcalculator = actionCollection()->addAction(QStringLiteral("tools_calculate")); m_pcalculator->setText(i18n("Perform &Calculations...")); m_pcalculator->setIcon(QIcon::fromTheme(QStringLiteral("calculate"))); m_pcalculator->setWhatsThis(i18nc("WhatsThis Help", "This is the calculator, it performs basic chemical calculations.")); connect(m_pcalculator, &QAction::triggered, this, &Kalzium::showCalculator); m_pIsotopeTableAction= actionCollection()->addAction(QStringLiteral("tools_isotopetable")); m_pIsotopeTableAction->setText(i18n("&Isotope Table...")); m_pIsotopeTableAction->setIcon(QIcon::fromTheme(QStringLiteral("isotopemap"))); m_pIsotopeTableAction->setWhatsThis(i18nc("WhatsThis Help", "This table shows all of the known isotopes of the chemical elements.")); connect(m_pIsotopeTableAction, &QAction::triggered, this, &Kalzium::slotIsotopeTable); m_pGlossaryAction = actionCollection()->addAction(QStringLiteral("tools_glossary")); m_pGlossaryAction->setText(i18n("&Glossary...")); m_pGlossaryAction->setIcon(QIcon::fromTheme(QStringLiteral("glossary"))); connect(m_pGlossaryAction, &QAction::triggered, this, &Kalzium::slotGlossary); m_pRSAction = actionCollection()->addAction(QStringLiteral("tools_rs")); m_pRSAction->setText(i18n("&R/S Phrases...")); m_pRSAction->setIcon(QIcon::fromTheme(QStringLiteral("kalzium_rs"))); connect(m_pRSAction, &QAction::triggered, this, &Kalzium::slotRS); m_pOBConverterAction = actionCollection()->addAction(QStringLiteral("tools_obconverter")); m_pOBConverterAction->setText(i18n("Convert chemical files...")); m_pOBConverterAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy"))); m_pOBConverterAction->setWhatsThis(i18nc("WhatsThis Help", "With this tool, you can convert files containing chemical data between various file formats.")); connect(m_pOBConverterAction, &QAction::triggered, this, &Kalzium::slotOBConverter); #ifndef HAVE_OPENBABEL2 m_pOBConverterAction->setEnabled(false); #endif m_pMoleculesviewer = actionCollection()->addAction(QStringLiteral("tools_moleculeviewer")); m_pMoleculesviewer->setText(i18n("Molecular Editor...")); m_pMoleculesviewer->setIcon(QIcon::fromTheme(QStringLiteral("kalzium_molviewer"))); m_pMoleculesviewer->setWhatsThis(i18nc("WhatsThis Help", "This tool allows you to view and edit 3D molecular structures.")); connect(m_pMoleculesviewer, &QAction::triggered, this, &Kalzium::slotMoleculeviewer); #if !defined(HAVE_OPENBABEL2) || !defined(HAVE_EIGEN) || !defined(HAVE_AVOGADRO) m_pMoleculesviewer->setEnabled(false); #endif m_pTables = actionCollection()->addAction(QStringLiteral("tools_tables")); m_pTables->setText(i18n("&Tables...")); m_pTables->setIcon(QIcon::fromTheme(QStringLiteral("kalzium_tables"))); m_pTables->setWhatsThis(i18nc("WhatsThis Help", "This will open a dialog with listings of symbols and numbers related to chemistry.")); connect(m_pTables, &QAction::triggered, this, &Kalzium::slotTables); // other period view options m_pLegendAction = m_legendDock->toggleViewAction(); actionCollection()->addAction(QStringLiteral("view_legend"), m_pLegendAction); m_pLegendAction->setIcon(QIcon::fromTheme(QStringLiteral("legend"))); m_pLegendAction->setWhatsThis(i18nc("WhatsThis Help", "This will show or hide the legend for the periodic table.")); m_SidebarAction = m_dockWin->toggleViewAction(); actionCollection()->addAction(QStringLiteral("view_sidebar"), m_SidebarAction); m_SidebarAction->setIcon(QIcon::fromTheme(QStringLiteral("sidebar"))); m_SidebarAction->setWhatsThis(i18nc("WhatsThis Help", "This will show or hide a sidebar with additional information and a set of tools.")); m_SidebarAction = m_tableDock->toggleViewAction(); actionCollection()->addAction(QStringLiteral("view_tablebar"), m_SidebarAction); m_SidebarAction->setIcon(QIcon::fromTheme(QStringLiteral("kalzium_tables"))); m_SidebarAction->setWhatsThis(i18nc("WhatsThis Help", "This will show or hide a sidebar with additional information about the table.")); // the standard actions actionCollection()->addAction(QStringLiteral("saveAs"), KStandardAction::saveAs(this, SLOT(slotExportTable()), actionCollection())); KStandardAction::preferences(this, SLOT(showSettingsDialog()), actionCollection()); actionCollection()->addAction(QStringLiteral("quit"), KStandardAction::quit(qApp, SLOT(quit()), actionCollection())); m_legendWidget->LockWidget(); slotSwitchtoLookGradient(KalziumElementProperty::instance()->gradientId()); slotSwitchtoLookScheme(KalziumElementProperty::instance()->schemeId()); slotSwitchtoNumeration(Prefs::numeration()); slotSwitchtoTable(Prefs::table()); m_legendWidget->UnLockWidget(); m_legendWidget->updateContent(); // set the shell's ui resource file setXMLFile(QStringLiteral("kalziumui.rc")); setupGUI(); } void Kalzium::setupSidebars() { setDockNestingEnabled(true); m_legendWidget = new LegendWidget(this); m_legendDock = new QDockWidget(i18n("Legend"), this); m_legendDock->setObjectName(QStringLiteral("kalzium-legend")); m_legendDock->setFeatures(QDockWidget::AllDockWidgetFeatures); m_legendDock->setWidget(m_legendWidget); connect(m_legendDock, &QDockWidget::dockLocationChanged, m_legendWidget, &LegendWidget::setDockArea); connect(m_legendWidget, &LegendWidget::elementMatched, m_periodicTable, &PeriodicTableView::slotSelectAdditionalElement); connect(m_legendWidget, &LegendWidget::resetElementMatch, m_periodicTable, &PeriodicTableView::slotUnSelectElements); m_TableInfoWidget = new TableInfoWidget(this); m_tableDock = new QDockWidget(i18n("Table Information"), this); m_tableDock->setWidget(m_TableInfoWidget); m_tableDock->setObjectName(QStringLiteral("kalzium-tableinfo")); m_tableDock->setFeatures(QDockWidget::AllDockWidgetFeatures); m_dockWin = new QDockWidget(i18n("Information"), this); m_dockWin->setObjectName(QStringLiteral("kalzium-sidebar")); m_dockWin->setFeatures(QDockWidget::AllDockWidgetFeatures); m_dockWin->setMinimumWidth(250); m_toolbox = new QToolBox(m_dockWin); m_dockWin->setWidget(m_toolbox); m_detailWidget = new DetailedGraphicalOverview(m_toolbox); m_detailWidget->setObjectName(QStringLiteral("DetailedGraphicalOverview")); m_detailWidget->setMinimumSize(200, m_detailWidget->minimumSize().height()); m_toolbox->addItem(m_detailWidget, QIcon::fromTheme(QStringLiteral("overview")), i18n("Overview")); m_gradientWidget = new GradientWidgetImpl(m_toolbox); m_gradientWidget->setObjectName(QStringLiteral("viewtWidget")); connect(m_gradientWidget, &GradientWidgetImpl::gradientValueChanged, KalziumElementProperty::instance(), &KalziumElementProperty::setSliderValue); connect(m_gradientWidget->scheme_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSwitchtoLookScheme(int))); connect(m_gradientWidget->gradient_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSwitchtoLookGradient(int))); m_toolbox->addItem(m_gradientWidget, QIcon::fromTheme(QStringLiteral("statematter")), i18n("View")); addDockWidget(Qt::LeftDockWidgetArea, m_dockWin); addDockWidget(Qt::BottomDockWidgetArea, m_tableDock, Qt::Horizontal); addDockWidget(Qt::BottomDockWidgetArea, m_legendDock, Qt::Horizontal); m_tableDock->setVisible(false); } void Kalzium::slotExportTable() { QString fileName = QFileDialog::getSaveFileName(this, i18n("Save Kalzium's Table In"), QString(), i18n("Image files (*.png *.xpm *.jpg *.svg)")); if (fileName.endsWith(QLatin1String(".svg"))) { m_periodicTable->generateSvg(fileName); } else { QPixmap pix = m_periodicTable->grab(); pix.save(fileName); } } void Kalzium::slotGlossary() { if (!m_glossarydlg) { // creating the glossary dialog and loading the glossaries we have m_glossarydlg = new GlossaryDialog(this); m_glossarydlg->setObjectName(QStringLiteral("glossary")); QString dir = QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("data/"), QStandardPaths::LocateDirectory); dir = QFileInfo(dir).absolutePath(); QString picturepath = dir + "/bg.jpg"; QUrl u = QUrl::fromLocalFile(dir + "/knowledge.xml"); Glossary *g = new Glossary(u); g->setName(i18n("Knowledge")); g->setBackgroundPicture(picturepath); m_glossarydlg->addGlossary(g, true); u = QUrl::fromLocalFile(dir + "/tools.xml"); g = new Glossary(u, dir + "/toolpics/"); g->setName(i18n("Tools")); g->setBackgroundPicture(picturepath); m_glossarydlg->addGlossary(g, true); } m_glossarydlg->show(); } void Kalzium::slotRS() { if (!m_rsDialog) { m_rsDialog = new RSDialog(this); } m_rsDialog->show(); } void Kalzium::slotOBConverter() { #ifdef HAVE_OPENBABEL2 KOpenBabel * d = new KOpenBabel(this); d->setAttribute(Qt::WA_DeleteOnClose); d->show(); #endif } MoleculeDialog *Kalzium::slotMoleculeviewer() { #if defined(HAVE_OPENBABEL2) && defined(HAVE_EIGEN) && defined(HAVE_AVOGADRO) if (!QGLFormat::hasOpenGL()) { QMessageBox::critical(Q_NULLPTR, i18n("Kalzium Error"), i18n("This system does not support OpenGL.")); return nullptr; } MoleculeDialog * d = new MoleculeDialog(this); d->show(); return d; #if 0 KPluginLoader loader("libkalziumglpart"); KPluginFactory* factory = loader.factory(); if (factory) { KParts::ReadOnlyPart *part = 0; part = static_cast(factory->create(this, "KalziumGLPart")); part->widget()->show(); } #endif #endif return nullptr; } void Kalzium::slotTables() { if (!m_tablesDialog) { m_tablesDialog = new TablesDialog(this); } m_tablesDialog->show(); } void Kalzium::slotIsotopeTable() { if (!m_isotopeDialog) { m_isotopeDialog = new IsotopeTableDialog(this); } m_isotopeDialog->show(); } void Kalzium::slotPlotData() { if (!m_elementDataPlotter) { m_elementDataPlotter = new ElementDataViewer(this); } m_elementDataPlotter->show(); } void Kalzium::showCalculator() { if (!m_calculator) { m_calculator = new calculator(this); } m_calculator -> show(); } void Kalzium::slotSwitchtoTable(int index) { m_periodicTable->slotChangeTable(index); m_TableInfoWidget->setTableType(index); if (m_infoDialog) { m_infoDialog->setTableType(m_periodicTable->table()); } Prefs::setTable(index); Prefs::self()->save(); } void Kalzium::slotSwitchtoNumeration(int index) { emit numerationChanged(index); Prefs::setNumeration(index); Prefs::self()->save(); } void Kalzium::slotSwitchtoLookGradient(int which) { qDebug() << "slotSwitchtoLookGradient Kalzium"; KalziumElementProperty::instance()->setGradient(which); look_action_gradients->blockSignals(true); m_gradientWidget->gradient_combo->blockSignals(true); look_action_gradients->setCurrentItem(which); m_gradientWidget->gradient_combo->setCurrentIndex(which); look_action_gradients->blockSignals(false); m_gradientWidget->gradient_combo->blockSignals(false); m_gradientWidget->slotGradientChanged(); m_legendWidget->updateContent(); } void Kalzium::slotSwitchtoLookScheme(int which) { qDebug() << "slotSwitchtoLookScheme Kalzium"; KalziumElementProperty::instance()->setScheme(which); m_gradientWidget->scheme_combo->blockSignals(true); look_action_schemes->blockSignals(true); look_action_schemes->setCurrentItem(which); m_gradientWidget->scheme_combo->setCurrentIndex(which); look_action_schemes->blockSignals(false); m_gradientWidget->scheme_combo->blockSignals(false); m_legendWidget->updateContent(); } void Kalzium::showSettingsDialog() { if (KConfigDialog::showDialog(QStringLiteral("settings"))) { return; } //KConfigDialog didn't find an instance of this dialog, so lets create it : KConfigDialog *dialog = new KConfigDialog(this,QStringLiteral("settings"), Prefs::self()); // colors page Ui_setupColors ui_colors; QWidget *w_colors = new QWidget(this); w_colors->setObjectName(QStringLiteral("colors_page")); ui_colors.setupUi(w_colors); dialog->addPage(w_colors, i18n("Schemes"), QStringLiteral("preferences-desktop-color")); // gradients page Ui_setupGradients ui_gradients; QWidget *w_gradients = new QWidget(this); w_gradients->setObjectName(QStringLiteral("gradients_page")); ui_gradients.setupUi(w_gradients); dialog->addPage(w_gradients, i18n("Gradients"), QStringLiteral("preferences-desktop-color")); // units page m_unitsDialog = new UnitSettingsDialog(this); m_unitsDialog->setObjectName(QStringLiteral("units_page")); dialog->addPage(m_unitsDialog, i18n("Units"), QStringLiteral("system-run")); Ui_setupCalc ui_calc; QWidget *w_calc = new QWidget(this); ui_calc.setupUi(w_calc); dialog->addPage(w_calc, i18n("Calculator"), QStringLiteral("accessories-calculator")); connect(dialog, &KConfigDialog::settingsChanged, this, &Kalzium::slotUpdateSettings); connect(dialog, &KConfigDialog::settingsChanged, m_gradientWidget, &GradientWidgetImpl::slotGradientChanged); dialog->show(); } void Kalzium::slotUpdateSettings() { Prefs::setLengthUnit(m_unitsDialog->getLenghtUnitId()); Prefs::setEnergiesUnit(m_unitsDialog->getEnergyUnitId()); Prefs::setTemperatureUnit(m_unitsDialog->getTemperatureUnitId()); Prefs::self()->save(); /*This slot function calls change the color of pse elements immediately after prefs change*/ slotSwitchtoLookGradient(Prefs::colorgradientbox()); slotSwitchtoLookScheme(Prefs::colorschemebox()); } void Kalzium::slotShowExportDialog() { if (!m_exportDialog) { m_exportDialog = new ExportDialog(this); } m_exportDialog->show(); } void Kalzium::setupStatusBar() { QStatusBar *statusBar = new QStatusBar(this); setStatusBar(statusBar); m_elementInfo = new QLabel(QLatin1String("")); m_elementInfo->setAlignment(Qt::AlignRight); statusBar->addWidget(m_elementInfo, 1); statusBar->show(); } void Kalzium::elementHover(int num) { // extractIconicInformationAboutElement(num); Element *e = KalziumDataObject::instance()->element(num); m_elementInfo->setText(i18nc("For example: \"Carbon (6), Mass: 12.0107 u\"", "%1 (%2), Mass: %3 u", e->dataAsString(ChemicalDataObject::name), e->dataAsString(ChemicalDataObject::atomicNumber), e->dataAsString(ChemicalDataObject::mass))); qDebug() << "change item in status bar"; m_detailWidget->setElement(num); } // FIXME What is that function for? Does not seem to do anything useful... yet? void Kalzium::extractIconicInformationAboutElement(int elementNumber) { QString setname = QStringLiteral("school"); QString pathname = QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("data/iconsets/"), QStandardPaths::LocateDirectory); pathname = QFileInfo(pathname).absolutePath(); QString filename = pathname + setname + '/' + "iconinformation.txt"; QFile file(filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } QString infoline; QTextStream in(&file); while (!in.atEnd()) { QString tmp = in.readLine(); if (tmp.startsWith(QString::number(elementNumber))) { infoline = tmp; } } QString realText = QStringLiteral("Moin dies ist ein test!"); //X QString realText = infoline.remove(QRegExp("\\d+ ")); } void Kalzium::openInformationDialog(int number) { if (m_infoDialog) { m_infoDialog->setElement(number); } else { m_infoDialog = new DetailedInfoDlg(number, this); // Remove the selection when this dialog finishes or hides. connect(m_infoDialog, &DetailedInfoDlg::elementChanged, m_periodicTable, &PeriodicTableView::slotSelectOneElement); connect(m_infoDialog, &DetailedInfoDlg::elementChanged, this, &Kalzium::elementHover); } m_infoDialog->setTableType(m_periodicTable->table()); m_infoDialog->show(); } Kalzium::~Kalzium() { delete m_periodicTable; delete m_infoDialog; delete m_TableInfoWidget; delete m_legendWidget; delete m_gradientWidget; delete m_dockWin; delete m_legendDock; delete m_tableDock; } void Kalzium::loadMolecule(const QString &moleculeFile) { #if defined(HAVE_OPENBABEL2) && defined(HAVE_EIGEN) && defined(HAVE_AVOGADRO) MoleculeDialog *d = slotMoleculeviewer(); if (d) { d->loadMolecule(moleculeFile); } #endif } QSize Kalzium::sizeHint() const { return QSize(700, 500); } diff --git a/src/kdeeduglossary.cpp b/src/kdeeduglossary.cpp index 91cb1679..3df03775 100644 --- a/src/kdeeduglossary.cpp +++ b/src/kdeeduglossary.cpp @@ -1,550 +1,540 @@ /*************************************************************************** * Copyright (C) 2005, 2006 by Carsten Niehaus * * Copyright (C) 2005 - 2007 by Pino Toscano * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "kdeeduglossary.h" #include #include -#include -#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include #include #include static const int FirstLetterRole = 0x00b00a00; static const int GlossaryTreeItemType = QTreeWidgetItem::UserType + 1; class GlossaryTreeItem : public QTreeWidgetItem { public: GlossaryTreeItem(Glossary * g, GlossaryItem * gi) : QTreeWidgetItem(GlossaryTreeItemType), m_g(g), m_gi(gi) { setText(0, m_gi->name()); } Glossary *glossary() const { return m_g; } GlossaryItem *glossaryItem() const { return m_gi; } private: Glossary *m_g; GlossaryItem *m_gi; }; struct GlossaryInfo { GlossaryInfo(Glossary* g) : glossary(g), folded(true) { } Glossary *glossary; bool folded; }; class GlossaryDialog::Private { public: Private(GlossaryDialog *qq) : q(qq) { } ~Private() { QList::ConstIterator it = m_glossaries.constBegin(); QList::ConstIterator itEnd = m_glossaries.constEnd(); for (; it != itEnd; ++it) { delete (*it).glossary; } delete m_htmlpart; } void rebuildTree(); QTreeWidgetItem* createItem(const GlossaryInfo& gi) const; QTreeWidgetItem* findTreeWithLetter(const QChar& l, QTreeWidgetItem* item) const; // slots void itemActivated(QTreeWidgetItem * item, int column); - // The user clicked on a href. Find and display the right item - void displayItem(const QUrl &url, const KParts::OpenUrlArguments& arguments, - const KParts::BrowserArguments &browserArguments); GlossaryDialog *q; QList< GlossaryInfo > m_glossaries; - KHTMLPart *m_htmlpart; + QTextBrowser *m_htmlpart; QTreeWidget *m_glosstree; KTreeWidgetSearchLine *m_search; QString m_htmlbasestring; KActionCollection* m_actionCollection; }; Glossary::Glossary(const QUrl &url, const QString& path) { init(url, path); } Glossary::Glossary() { init(QUrl(), QString()); } Glossary::~Glossary() { qDeleteAll(m_itemlist); } void Glossary::init(const QUrl &url, const QString& path) { // setting a generic name for a new glossary m_name = i18n("Glossary"); setPicturePath(path); if (!url.isEmpty()) { QDomDocument doc(QStringLiteral("document")); if (loadLayout(doc, url)) { setItemlist(readItems(doc)); if (!m_picturepath.isEmpty()) { fixImagePath(); } } } } bool Glossary::loadLayout(QDomDocument &Document, const QUrl &url) { QFile layoutFile(url.path()); if (!layoutFile.exists()) { qDebug() << "no such file: " << layoutFile.fileName(); return false; } if (!layoutFile.open(QIODevice::ReadOnly)) { return false; } // check if document is well-formed if (!Document.setContent(&layoutFile)) { qDebug() << "wrong xml of " << layoutFile.fileName(); layoutFile.close(); return false; } layoutFile.close(); return true; } bool Glossary::isEmpty() const { return m_itemlist.count() == 0; } void Glossary::setName(const QString& name) { if (name.isEmpty()) { return; } m_name = name; } void Glossary::setPicturePath(const QString& path) { if (path.isEmpty()) { return; } m_picturepath = path; } void Glossary::setBackgroundPicture(const QString& filename) { if (filename.isEmpty()) { return; } m_backgroundpicture = filename; } void Glossary::fixImagePath() { QString imgtag = ""; QRegExp exp("\\[img\\]([^[]+)\\[/img\\]"); foreach (GlossaryItem * item, m_itemlist) { QString tmp = item->desc(); while (exp.indexIn(tmp) > -1) { tmp = tmp.replace(exp, imgtag); } item->setDesc(tmp); } } QList Glossary::readItems(QDomDocument &itemDocument) { QList list; QDomNodeList itemList; QDomNodeList refNodeList; QDomElement itemElement; QStringList reflist; itemList = itemDocument.elementsByTagName(QStringLiteral("item")); const uint num = itemList.count(); for (uint i = 0; i < num; ++i) { reflist.clear(); GlossaryItem *item = new GlossaryItem(); - itemElement = (const QDomElement&) itemList.item(i).toElement(); + itemElement = itemList.item(i).toElement(); QDomNode nameNode = itemElement.namedItem(QStringLiteral("name")); QDomNode descNode = itemElement.namedItem(QStringLiteral("desc")); QString picName = itemElement.namedItem(QStringLiteral("picture")).toElement().text(); - QDomElement refNode = (const QDomElement&) itemElement.namedItem(QStringLiteral("references")).toElement(); + QDomElement refNode = itemElement.namedItem(QStringLiteral("references")).toElement(); QString desc = i18n(descNode.toElement().text().toUtf8().constData()); if (!picName.isEmpty()) { - desc.prepend("[img]" + picName + "[/img][brclear][br]"); + desc.prepend("[br][img]" + picName + "[/img][brclear][br]"); } item->setName(i18n(nameNode.toElement().text().toUtf8().constData())); desc = desc.replace(QLatin1String("[b]"), QLatin1String("")); desc = desc.replace(QLatin1String("[/b]"), QLatin1String("")); desc = desc.replace(QLatin1String("[i]"), QLatin1String("")); desc = desc.replace(QLatin1String("[/i]"), QLatin1String("")); desc = desc.replace(QLatin1String("[sub]"), QLatin1String("")); desc = desc.replace(QLatin1String("[/sub]"), QLatin1String("")); desc = desc.replace(QLatin1String("[sup]"), QLatin1String("")); desc = desc.replace(QLatin1String("[/sup]"), QLatin1String("")); desc = desc.replace(QLatin1String("[br]"), QLatin1String("
")); desc = desc.replace(QLatin1String("[brclear]"), QLatin1String("
")); item->setDesc(desc); refNodeList = refNode.elementsByTagName(QStringLiteral("refitem")); for (int it = 0; it < refNodeList.count(); ++it) { reflist << i18n(refNodeList.item(it).toElement().text().toUtf8().constData()); } item->setRef(reflist); list.append(item); } return list; } void Glossary::addItem(GlossaryItem* item) { m_itemlist.append(item); } QList Glossary::itemlist()const { return m_itemlist; } void Glossary::clear() { m_itemlist.clear(); } QString Glossary::name()const { return m_name; } void Glossary::setItemlist(QList list) { m_itemlist = list; } QString Glossary::picturePath()const { return m_picturepath; } QString Glossary::backgroundPicture()const { return m_backgroundpicture; } GlossaryDialog::GlossaryDialog(QWidget *parent) : QDialog(parent), d(new Private(this)) { setWindowTitle(i18n("Glossary")); //this string will be used for all items. If a backgroundpicture should //be used call Glossary::setBackgroundPicture(). d->m_htmlbasestring = QStringLiteral(""); QWidget *main = new QWidget(this); QVBoxLayout *vbox = new QVBoxLayout(main); setLayout(vbox); vbox->setContentsMargins(0, 0, 0, 0); QHBoxLayout *hbox = new QHBoxLayout(); d->m_search = new KTreeWidgetSearchLine(main); d->m_search->setObjectName(QStringLiteral("search-line")); hbox->addWidget(d->m_search); vbox->addLayout(hbox); setFocusProxy(d->m_search); QSplitter *vs = new QSplitter(main); vbox->addWidget(vs); d->m_glosstree = new QTreeWidget(vs); d->m_glosstree->setObjectName(QStringLiteral("treeview")); d->m_glosstree->setHeaderLabel(QStringLiteral("entries")); d->m_glosstree->header()->hide(); d->m_glosstree->setRootIsDecorated(true); d->m_search->addTreeWidget(d->m_glosstree); - d->m_htmlpart = new KHTMLPart(vs); + d->m_htmlpart = new QTextBrowser(vs); + d->m_htmlpart->setOpenLinks(false); - connect(d->m_htmlpart->browserExtension(), SIGNAL(openUrlRequestDelayed(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)), - this, SLOT(displayItem(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments))); connect(d->m_glosstree, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(itemActivated(QTreeWidgetItem*,int))); + connect(d->m_htmlpart, &QTextBrowser::anchorClicked, this, [=](const QUrl &link){ + // using the "path" part of a qurl as reference + QString myurl = link.path().toLower(); + QTreeWidgetItemIterator it(this->d->m_glosstree); + while (*it) { + if ((*it)->type() == GlossaryTreeItemType && (*it)->text(0).toLower() == myurl) { + // force the item to be selected + this->d->m_glosstree->setCurrentItem(*it); + // display its content + emit this->d->itemActivated((*it), 0); + break; + } else { + ++it; + } + } + }); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); connect(buttonBox, &QDialogButtonBox::rejected, this, &GlossaryDialog::reject); buttonBox->button(QDialogButtonBox::Close)->setDefault(true); vbox->addWidget(buttonBox); resize(800, 400); } GlossaryDialog::~GlossaryDialog() { delete d; } void GlossaryDialog::keyPressEvent(QKeyEvent* e) { if (e->key() == Qt::Key_Return) { e->ignore(); } QDialog::keyPressEvent(e); } -void GlossaryDialog::Private::displayItem(const QUrl &url, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &) -{ - // using the "path" part of a qurl as reference - QString myurl = url.path().toLower(); - - QTreeWidgetItemIterator it(m_glosstree); - while (*it) { - if ((*it)->type() == GlossaryTreeItemType && (*it)->text(0).toLower() == myurl) { - // force the item to be selected - m_glosstree->setCurrentItem(*it); - // display its content - itemActivated((*it), 0); - break; - } else { - ++it; - } - } -} - void GlossaryDialog::Private::rebuildTree() { m_glosstree->clear(); QList< GlossaryInfo >::ConstIterator it = m_glossaries.constBegin(); QList< GlossaryInfo >::ConstIterator itEnd = m_glossaries.constEnd(); for (; it != itEnd; ++it) { m_glosstree->addTopLevelItem(createItem(*it)); } } QTreeWidgetItem* GlossaryDialog::Private::createItem(const GlossaryInfo& gi) const { Glossary *glossary = gi.glossary; bool folded = gi.folded; QTreeWidgetItem *main = new QTreeWidgetItem(); main->setText(0, glossary->name()); main->setFlags(Qt::ItemIsEnabled); foreach (GlossaryItem *item, glossary->itemlist()) { if (folded) { QChar thisletter = item->name().toUpper().at(0); QTreeWidgetItem *thisletteritem = findTreeWithLetter(thisletter, main); if (!thisletteritem) { thisletteritem = new QTreeWidgetItem(main); thisletteritem->setText(0, QString(thisletter)); thisletteritem->setFlags(Qt::ItemIsEnabled); thisletteritem->setData(0, FirstLetterRole, thisletter); } thisletteritem->addChild(new GlossaryTreeItem(glossary, item)); } else { main->addChild(new GlossaryTreeItem(glossary, item)); } } return main; } void GlossaryDialog::addGlossary(Glossary* newgloss, bool folded) { if (!newgloss || newgloss->isEmpty()) { return; } GlossaryInfo gi(newgloss); gi.folded = folded; d->m_glossaries.append(gi); d->m_glosstree->addTopLevelItem(d->createItem(gi)); d->m_glosstree->sortItems(0, Qt::AscendingOrder); } QTreeWidgetItem* GlossaryDialog::Private::findTreeWithLetter(const QChar& l, QTreeWidgetItem* item) const { int count = item->childCount(); for (int i = 0; i < count; ++i) { QTreeWidgetItem *itemchild = item->child(i); if (itemchild->data(0, FirstLetterRole).toChar() == l) { return itemchild; } } return nullptr; } void GlossaryDialog::Private::itemActivated(QTreeWidgetItem * item, int column) { Q_UNUSED(column) if (!item || item->type() != GlossaryTreeItemType) { return; } GlossaryTreeItem *glosstreeitem = static_cast(item); GlossaryItem *glossitem = glosstreeitem->glossaryItem(); QString html; QString bg_picture = glosstreeitem->glossary()->backgroundPicture(); if (!bg_picture.isEmpty()) { html = " background=\"file://" + bg_picture + "\""; } html = m_htmlbasestring.arg(html); - html += glossitem->toHtml() + ""; + html += "
" + glossitem->toHtml() + "
"; - m_htmlpart->begin(); - m_htmlpart->write(html); - m_htmlpart->end(); + m_htmlpart->setHtml(html); } void GlossaryItem::setRef(const QStringList& s) { m_ref = s; m_ref.sort(); } QString GlossaryItem::toHtml() const { - QString code = "

" + m_name + "

" + m_desc + parseReferences(); + QString code = "

" + m_name + "

" + "

" + m_desc + "

" + parseReferences(); return code; } QString GlossaryItem::parseReferences() const { if (m_ref.isEmpty()) { return QString(); } QString htmlcode = "

" + i18n("References") + "

    "; static QString basehref = QStringLiteral("
  • %3
  • "); foreach (const QString& ref, m_ref) { htmlcode += basehref.arg(QUrl::toPercentEncoding(ref), i18n("Go to '%1'", ref), ref); } htmlcode += QLatin1String("
"); return htmlcode; } void GlossaryItem::setName(const QString& s) { m_name = s; } void GlossaryItem::setDesc(const QString& s) { m_desc = s; } void GlossaryItem::setPictures(const QString& s) { m_pic = QStringList(s); } QString GlossaryItem::name() const { return m_name; } QString GlossaryItem::desc() const { return m_desc; } QStringList GlossaryItem::ref() const { return m_ref; } QStringList GlossaryItem::pictures() const { return m_pic; } #include "moc_kdeeduglossary.cpp" diff --git a/src/kdeeduglossary.h b/src/kdeeduglossary.h index 117e17b0..fd46e4f3 100644 --- a/src/kdeeduglossary.h +++ b/src/kdeeduglossary.h @@ -1,241 +1,239 @@ /*************************************************************************** * Copyright (C) 2005, 2006 by Carsten Niehaus * * Copyright (C) 2005 - 2007 by Pino Toscano * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef KDEEDUGLOSSARY_H #define KDEEDUGLOSSARY_H #include #include class QDomDocument; class GlossaryItem; /** * @class Glossary * @author Carsten Niehaus * @author Pino Toscano * * This class stores all items to be displayed. It also * has access-methods to the items */ class Glossary { public: /** * Creates a new glossary and add contents from an XML file. * Use isEmpty() to know if any items were loaded. * * @param url the path of the file to load * @param path the path of the pictures */ explicit Glossary(const QUrl& url, const QString& path = QString()); /** * Creates a new empty glossary */ Glossary(); virtual ~Glossary(); /** * add the item @p item to the glossary */ void addItem(GlossaryItem* item); QList itemlist()const; /** * clear the Glossary */ void clear(); /** * does this glossary have items? */ bool isEmpty() const; /** * Every glossary can have a name. It will be * set to @p name */ void setName(const QString& name); /** * @returns the name of the glossary */ QString name()const; /** * sets the internal list of items to @p list */ void setItemlist(QList list); /** * Every glossaryitem can show pictures. [img src="foo.png] * will look for the file foo.png in the path defined by * @p path */ void setPicturePath(const QString& path); QString picturePath()const; /** * defines which picture to use as the background * of the htmlview. The dialog * will use the file specific by the @p filename */ void setBackgroundPicture(const QString& filename); /** * @return the picture used as the background in * this background */ QString backgroundPicture()const; protected: void init(const QUrl& url, const QString& path); private: /** * This methods parses the given XML code. It will extract * the information of the items and return them as a * QList */ virtual QList readItems(QDomDocument &itemDocument); QString m_backgroundpicture; /** * replaces the [img]-pseudocode with valid HTML. The path where * the pictures are stored will be used for pictures */ void fixImagePath(); /** * the path in which pictures of the glossary will be searched */ QString m_picturepath; /** * Load the layout from an XML file. * * @param doc The QDomDocument which will contain the read XML * contents. * @param url The path of the file to load * * @return a bool indicating whether the loading of the XML was * successful or not */ bool loadLayout(QDomDocument& doc, const QUrl& url); QList m_itemlist; /** * the name of the glossary */ QString m_name; }; /** * @class GlossaryItem * @author Carsten Niehaus * * A GlossaryItem stores the information of the content of * the item and its name. Furthermore, every item can have * a number of pictures or references associated to it. * These are stored as QStringLists. */ class GlossaryItem { public: GlossaryItem() {} ~GlossaryItem() {} void setName(const QString& s); void setDesc(const QString& s); /** * Set the references for the current GlossaryItem to * @p s. * There's no need to sort the list before, as they * will be sorted automatically */ void setRef(const QStringList& s); void setPictures(const QString& s); QString name() const; QString desc() const; QStringList ref() const; QStringList pictures() const; /** * @return the formatted HTML code for current item. */ QString toHtml() const; /** * This method parses the references. * @return the HTML code with the references as HTML links */ QString parseReferences() const; private: QString m_name; QString m_desc; QStringList m_ref; QStringList m_pic; }; /** * @class GlossaryDialog * @author Pino Toscano * @author Carsten Niehaus */ class GlossaryDialog : public QDialog { Q_OBJECT public: /** * Creates a new dialog for a glossary. * * @param parent the parent of the new dialog */ explicit GlossaryDialog(QWidget *parent = nullptr); ~GlossaryDialog() override; /** * Add a new glossary. * * @param newgloss the new glossary to add * @param folded whether to fold the various items in subtrees depending on the * first letter of every item */ void addGlossary(Glossary* newgloss, bool folded = true); protected: void keyPressEvent(QKeyEvent*) override; private: class Private; Private * const d; Q_PRIVATE_SLOT(d, void itemActivated(QTreeWidgetItem *, int)) - Q_PRIVATE_SLOT(d, void displayItem(const QUrl &, const KParts::OpenUrlArguments &, - const KParts::BrowserArguments &)) }; #endif // KDEEDUGLOSSARY_H