Commit b0266cb8 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Port to QTextBrowser

Summary:
This ports away from the KHTML dependency. Note that QTextBrowser
does not support CSS pseudo class selectors, which means that the
hover property cannot be set for CSS elements. Thus the results view
is changed such that the light-gray background is not bound to the
hovering of a mouse courser but is applied to every odd line.

Reviewers: yurchor

Reviewed By: yurchor

Subscribers: yurchor, kde-edu

Tags: #kde_edu

Maniphest Tasks: T11574

Differential Revision: https://phabricator.kde.org/D25437
parent 585e660e
......@@ -18,14 +18,14 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
find_package(Qt5 ${QT_REQUIRED_VERSION} REQUIRED COMPONENTS Core Widgets)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Archive
Completion
Config
ConfigWidgets
Completion
Config
ConfigWidgets
CoreAddons
Crash
DocTools
I18n
KHtml
DocTools
I18n
KIO
Notifications
XmlGui)
include(KDEInstallDirs)
......
......@@ -16,12 +16,12 @@ set(kiten_bin_SRCS
wordtype.cpp
)
ki18n_wrap_ui(kiten_bin_SRCS
configdictselect.ui
configfont.ui
configlearn.ui
configsearching.ui
configsorting.ui
)
configdictselect.ui
configfont.ui
configlearn.ui
configsearching.ui
configsorting.ui
)
kconfig_add_kcfg_files( kiten_bin_SRCS kitenconfig.kcfgc)
file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../data/pics/*-apps-kiten.png")
......@@ -30,13 +30,14 @@ ecm_add_app_icon(kiten_bin_SRCS ICONS ${ICONS_SRCS})
add_executable(kiten_bin ${kiten_bin_SRCS})
set_target_properties(kiten_bin PROPERTIES OUTPUT_NAME kiten IMPORT_PREFIX bin_)
target_link_libraries(kiten_bin
target_link_libraries(kiten_bin
KF5::Archive
KF5::ConfigWidgets
KF5::Crash
KF5::I18n
KF5::KHtml
KF5::KIOCore
KF5::Notifications
KF5::XmlGui
kiten)
install( TARGETS kiten_bin ${INSTALL_TARGETS_DEFAULT_ARGS} )
......
......@@ -28,7 +28,6 @@
#include <KConfig>
#include <KConfigGui>
#include <KEditToolBar>
#include <KHTMLView>
#include <KLocalizedString>
#include <KProcess>
#include <KShortcutsDialog>
......@@ -102,7 +101,7 @@ Kiten::Kiten( QWidget *parent, const char *name )
detachedView = new ResultsView( NULL, "detachedView" );
*/
setCentralWidget( _mainView->widget() );
setCentralWidget( _mainView );
setupActions();
// Be sure to create this manager before creating the GUI
......@@ -132,7 +131,7 @@ Kiten::Kiten( QWidget *parent, const char *name )
this, &Kiten::searchClipboard );
connect(_inputManager, &SearchStringInput::search, this, &Kiten::searchFromEdit);
connect( _mainView->view()->verticalScrollBar(), &QAbstractSlider::valueChanged,
connect( _mainView->verticalScrollBar(), &QAbstractSlider::valueChanged,
this, &Kiten::setCurrentScrollValue );
/* We need to know when to reload our dictionaries if the user updated them. */
connect(_dictionaryUpdateManager, &DictionaryUpdateManager::updateFinished, this, &Kiten::loadDictionaries);
......@@ -310,7 +309,7 @@ void Kiten::finishInit()
void Kiten::focusResultsView()
{
_mainView->view()->setFocus();
_mainView->verticalScrollBar()->setFocus();
}
// This function is run on program window close.
......
......@@ -22,28 +22,18 @@
*****************************************************************************/
#include "resultsview.h"
#include "kitenconfig.h"
#include <KColorScheme>
#include <KHTMLView>
/* Needed by ResultsView only */
#include <QScrollBar>
ResultsView::ResultsView( QWidget *parent, const char *name )
: KHTMLPart( parent, parent )
: QTextBrowser( parent )
, _scrollValue( 0 )
{
////////setReadOnly(true);
/* TODO: configurably underlined links */
// setLinkUnderline(false); //KDE4 CHANGE
////////basicMode = false;
// don't let ktextbrowser internally handle link clicks
////////setNotifyClick(true);
connect( view(), &KHTMLView::finishedLayout,
this, &ResultsView::doScroll );
setOpenLinks( false );
connect(this, &QTextBrowser::anchorClicked, this, [=](const QUrl &url){
emit urlClicked( url.toString() );
});
}
/**
......@@ -59,33 +49,12 @@ void ResultsView::append( const QString &text )
*/
void ResultsView::clear()
{
_printText = QLatin1String("");
}
QString ResultsView::deLinkify( const DOM::Node &node )
{
//TODO: make this function more flexible (ie, accept non-link-content as
//well.)
QString word;
for ( long unsigned int i = 0; i < node.childNodes().length(); ++i )
{
if ( node.childNodes().item(i).nodeName() != "a" )
{
return QString();
}
if ( ! node.childNodes().item(i).hasChildNodes() )
{
return QString();
}
word += node.childNodes().item(i).childNodes().item( 0 ).nodeValue().string();
}
return word;
_printText.clear();
}
void ResultsView::doScroll()
{
view()->verticalScrollBar()->setValue(_scrollValue);
verticalScrollBar()->setValue(_scrollValue);
}
/**
......@@ -93,12 +62,8 @@ void ResultsView::doScroll()
*/
void ResultsView::flush()
{
begin();
setUserStyleSheet( generateCSS() );
write( _printText );
end();
//KDE4 CHANGE setCursorPosition( 0, 0 );
////////ensureCursorVisible();
const QString content = QString("<head><style>%1</style></head><body>%2</body>").arg(generateCSS()).arg(_printText);
setHtml( content );
}
QString ResultsView::generateCSS()
......@@ -117,7 +82,7 @@ QString ResultsView::generateCSS()
"a:visited {color: %5} "
"a:hover {color: %6 } "
"a:active {color: %6}"
".Entry:hover { background-color: %10 }"
".odd { background-color: %10 }"
"query { color: %6 }" )
.arg( scheme.foreground().color().name() )
.arg( scheme.foreground( KColorScheme::InactiveText ).color().name() )
......@@ -199,14 +164,9 @@ void ResultsView::setBasicMode( bool yes )
*/
void ResultsView::setContents( const QString &text )
{
begin();
setUserStyleSheet( generateCSS() );
write( text );
end();
qDebug() << "Set CSS to " << generateCSS();
//KDE4 CHANGE setCursorPosition( 0,0 );
////////ensureCursorVisible();
const QString content = QString("<head><style>%1</style></head><body>%2</body>").arg(generateCSS()).arg(text);
setHtml( content );
// qDebug() << "Set HTML to " << content;
}
void ResultsView::setLaterScrollValue( int scrollValue )
......@@ -214,16 +174,4 @@ void ResultsView::setLaterScrollValue( int scrollValue )
this->_scrollValue = scrollValue;
}
bool ResultsView::urlSelected( const QString &url,
int button,
int state,
const QString &_target,
const KParts::OpenUrlArguments& args,
const KParts::BrowserArguments& browserArgs )
{
//qDebug() << nodeUnderMouse().parentNode().parentNode().parentNode().toHTML();
emit urlClicked( url );
return KHTMLPart::urlSelected( url, button, state, _target, args, browserArgs );
}
......@@ -24,14 +24,14 @@
#define RESULTSVIEW_H
#include <QAction>
#include <KHTMLPart>
#include <QTextBrowser>
#include "entry.h"
class KActionCollection;
class KActionMenu;
class ResultsView : public KHTMLPart
class ResultsView : public QTextBrowser
{
Q_OBJECT
......@@ -55,14 +55,7 @@ class ResultsView : public KHTMLPart
void urlClicked( const QString& );
protected:
QString deLinkify( const DOM::Node &);
QString generateCSS();
bool urlSelected( const QString &url
, int button
, int state
, const QString &_target
, const KParts::OpenUrlArguments& args = KParts::OpenUrlArguments()
, const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments() ) override;
private slots:
void doScroll();
......
......@@ -177,7 +177,8 @@ QString EntryList::toHTML( unsigned int start, unsigned int length ) const
if( length-- > 0 )
{
result += QStringLiteral( "<div class=\"Entry\" index=\"%1\" dict=\"%2\">%3</div>" )
result += QStringLiteral( "<div class=\"%1\" index=\"%2\" dict=\"%3\">%4</div>" )
.arg( i % 2 == 0 ? "Entry" : "Entry odd" )
.arg( QString::number( i ) )
.arg( entry->getDictName() )
.arg( entry->toHTML() );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment