Skip to content
Permalink
Browse files

Port away from KHTML

Summary:
- Port glossary to QTextBrowser: Straight forward part with just exchanging KHTML functionality with
QTextBrowser, resulting in same results.
- Port detailed information to QTextBrowser: Visual changes are small. This change also puts the general information
into the header to avoid visual inconsistencies between different
pages.
- Remove KHTML Dependency: This patch also makes all implicit KF5 dependencies visible that
were pulled in via KHTML.

Reviewers: #kde_edu, apol, yurchor

Reviewed By: yurchor

Subscribers: yurchor, aacid, kde-edu

Tags: #kde_edu

Maniphest Tasks: T11572

Differential Revision: https://phabricator.kde.org/D23830
  • Loading branch information
cordlandwehr committed Sep 10, 2019
1 parent f17872c commit 43e1ed49d2d0eab1aa71da86665f9ba0c867b4de
@@ -62,7 +62,6 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
CoreAddons
DocTools
I18n
KHtml
Parts
Plotting
Solid
@@ -74,7 +73,7 @@ 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
@@ -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 )


Binary file not shown.
BIN -256 Bytes data/htmlview/header.png
Binary file not shown.

This file was deleted.

@@ -33,7 +33,7 @@ class SCIENCE_EXPORT IsotopeParser : public QXmlDefaultHandler
* Constructor
*/
IsotopeParser();
~IsotopeParser();
~IsotopeParser() override;
bool startElement(const QString &, const QString &localName, const QString &,
const QXmlAttributes &attrs) override;

@@ -138,10 +138,15 @@ kconfig_add_kcfg_files(kalzium_SRCS prefs.kcfgc )
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
@@ -35,14 +35,11 @@
#include <QLocale>
#include <QStackedWidget>
#include <QStandardPaths>
#include <QTextBrowser>
#include <QUrl>

#include <dom/html_base.h>
#include <dom/html_document.h>
#include <KActionCollection>
#include <KConfig>
#include <KHTMLPart>
#include <KHTMLView>
#include <KHelpClient>
#include <KPageDialog>
#include <KPageWidgetModel>
@@ -130,58 +127,31 @@ 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 =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
"<html><head><title>Chemical data</title>"
"<link rel=\"stylesheet\" type=\"text/css\" href=\"file://" + m_baseHtml + "style.css\" />"
"<base href=\"" + m_baseHtml + "\"/></head><body>"
"<div class=\"chemdata\"><div><table summary=\"header\" class=\"header\">"
"<tr><td>" + m_element->dataAsString(ChemicalDataObject::symbol) + "</td><td>"
+ createWikiLink(m_element->dataAsString(ChemicalDataObject::name)) + "</td><td>"
+ i18n("Block: %1", m_element->dataAsString(ChemicalDataObject::periodTableBlock)) +
"</td></tr></table></div>"
"<table summary=\"characteristics\" class=\"characterstics\">";
QString html = "<table width=\"100%\" summary=\"characteristics\">";

switch (type) {
case MISC:
@@ -305,7 +275,7 @@ QString DetailedInfoDlg::getHtml(DATATYPE type)

//http://education.jlab.org/itselemental/ele001.html
html.append ("<tr><td>");
html.append ("<a href=\"http://"); // http://
html.append ("<a href=\"https://"); // https://
html.append ("education.jlab.org/itselemental/ele");
html.append (QStringLiteral("%1").arg(m_element->dataAsString(ChemicalDataObject::atomicNumber), 3, '0'));
html.append (".html");
@@ -316,7 +286,7 @@ QString DetailedInfoDlg::getHtml(DATATYPE type)

// FIXME only works with english locals
html.append ("<tr><td>");
html.append ("<a href=\"http://"); // http://
html.append ("<a href=\"https://"); // https://
html.append ("www.webelements.com/");
if (QLocale().uiLanguages().first().startsWith(QLatin1String("en"))) {
html.append (m_element->dataAsString(ChemicalDataObject::name).toLower()); // hydrogen
@@ -346,24 +316,21 @@ QString DetailedInfoDlg::isotopeTable() const
QList<Isotope*> list = KalziumDataObject::instance()->isotopes(m_elementNumber);

QString html;

html = QStringLiteral("<table class=\"isotopes\" cellspacing=\"0\"><tr><td colspan=\"7\">");
html += i18n("Isotope-Table");
html += QLatin1String("</tr></td><tr><td><b>");
html = QStringLiteral("<table cellspacing=\"0\" border=\"1\" cellpadding=\"3\" style=\"border-style: solid;\"><tr><th>");
html += i18n("Mass");
html += QLatin1String("</b></td><td><b>");
html += QLatin1String("</th><th>");
html += i18n("Neutrons");
html += QLatin1String("</b></td><td><b>");
html += QLatin1String("</th><th>");
html += i18n("Percentage");
html += QLatin1String("</b></td><td><b>");
html += QLatin1String("</th><th>");
html += i18n("Half-life period");
html += QLatin1String("</b></td><td><b>");
html += QLatin1String("</th><th>");
html += i18n("Energy and Mode of Decay");
html += QLatin1String("</b></td><td><b>");
html += QLatin1String("</th><th>");
html += i18n("Spin and Parity");
html += QLatin1String("</b></td><td><b>");
html += QLatin1String("</th><th>");
html += i18n("Magnetic Moment");
html += QLatin1String("</b></td></tr>");
html += QLatin1String("</th></tr>");

foreach (Isotope *isotope, list) {
html.append("<tr><td align=\"right\">");
@@ -378,7 +345,8 @@ QString DetailedInfoDlg::isotopeTable() const
}
html.append("</td><td>");
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("</td><td>");
if ((isotope)->alphalikeliness() > 0.0) {
@@ -490,7 +458,6 @@ void DetailedInfoDlg::createContent()
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"));
@@ -514,13 +481,12 @@ 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";
@@ -573,16 +539,16 @@ QString DetailedInfoDlg::createWikiLink(QString link, QString displayString)
QString language(QLocale().uiLanguages().first());

//Wikipedia.org
html.append ("<a href=\"http://"); // http://
html.append ("<a href=\"https://"); // https://
html.append (language.split('-').at(0)); // en.
html.append (".wikipedia.org/wiki/"); // wikipedia.org
html.append (link); // /hydrogen
html.append ("\" target=\"_blank\" > ");
html.append (displayString);
html.append ("</a>");
// 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)
@@ -26,9 +26,10 @@ class Element;
class OrbitsWidget;
class SpectrumViewImpl;

class KActionCollection;
class QLabel;
class QStackedWidget;
class KActionCollection;
class QTextBrowser;
class KHTMLPart;

/**
@@ -77,7 +78,7 @@ class DetailedInfoDlg : public KPageDialog
DetailedGraphicalOverview *dTab;
//X QLabel *piclabel;
OrbitsWidget *wOrbits;
QMap<QString, KHTMLPart*> m_htmlpages;
QMap<QString, QTextBrowser*> m_htmlpages;

int m_tableTyp;

@@ -104,14 +105,14 @@ class DetailedInfoDlg : public KPageDialog
* @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.
@@ -61,7 +61,6 @@
#include <KActionCollection>
#include <KConfigDialog>
#include <KLocalizedString>
#include <KParts/Part>
#include <KPluginLoader>
#include <KSelectAction>
#include <KServiceTypeTrader>

0 comments on commit 43e1ed4

Please sign in to comment.
You can’t perform that action at this time.