diff --git a/CMakeLists.txt b/CMakeLists.txt index dc7d2ca..4691cbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,65 +1,66 @@ project(kalgebra) cmake_minimum_required(VERSION 2.8.12) find_package(ECM 1.7.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${ECM_MODULE_PATH}) find_package(Qt5 5.2 REQUIRED NO_MODULE COMPONENTS Qml Quick Xml Svg PrintSupport Test) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(ECMInstallIcons) include(FeatureSummary) include(ECMAddAppIcon) find_package(Analitza5 REQUIRED) set(MOBILE_BACKEND "kde" CACHE STRING "Backend to install, currently. Check /mobile/plugins/widgets/*") include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) set(CURSES_NEED_NCURSES TRUE) find_package(Curses) find_package(Readline) set_package_properties(Readline PROPERTIES TYPE OPTIONAL PURPOSE "Allows KAlgebra to provide a console interface." URL "http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html") set_package_properties(Curses PROPERTIES TYPE OPTIONAL PURPOSE "Allows KAlgebra to provide a console interface." URL "http://www.gnu.org/software/ncurses/") add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) +add_definitions(-DQT_NO_CAST_TO_ASCII) find_package(KF5I18n ${KF5_VERSION} REQUIRED) find_package(KF5 ${KF5_VERSION} OPTIONAL_COMPONENTS ConfigWidgets WidgetsAddons KIO DocTools) find_package(Qt5WebEngineWidgets) if(KF5DocTools_FOUND AND Qt5WebEngineWidgets_FOUND AND KF5ConfigWidgets_FOUND AND KF5WidgetsAddons_FOUND AND KF5KIO_FOUND AND NOT CMAKE_SYSTEM MATCHES Android*) add_subdirectory(src) add_subdirectory(plasmoids) endif() add_subdirectory(icons) add_subdirectory(mobile) if(READLINE_FOUND AND CURSES_FOUND) add_subdirectory(calgebra) endif() if(KF5DocTools_FOUND) add_subdirectory(utils) add_custom_target(commandsdoc ${CMAKE_CURRENT_BINARY_DIR}/utils/docbook_analitzacommands commands.docbook DEPENDS docbook_analitzacommands WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc/ COMMENT "Generating commands docbook information" ) add_subdirectory(doc) endif() install(FILES org.kde.kalgebra.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/consolehtml.cpp b/src/consolehtml.cpp index 4c2e4e4..4d86014 100644 --- a/src/consolehtml.cpp +++ b/src/consolehtml.cpp @@ -1,243 +1,243 @@ /************************************************************************************* * Copyright (C) 2007 by Aleix Pol * * * * 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 "consolehtml.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include static QUrl temporaryPath() { QTemporaryFile temp(QStringLiteral("consolelog")); temp.open(); temp.close(); temp.setAutoRemove(false); return QUrl::fromLocalFile(temp.fileName()); } static QUrl retrieve(const QUrl& remoteUrl) { const QUrl path = temporaryPath(); KIO::CopyJob* job=KIO::copyAs(remoteUrl, path); job->exec(); return path; } class ConsolePage : public QWebEnginePage { public: ConsolePage(ConsoleHtml* parent) : QWebEnginePage(parent), m_console(parent) {} bool acceptNavigationRequest(const QUrl &url, NavigationType /*type*/, bool /*isMainFrame*/) override { m_console->openClickedUrl(url); return false; } ConsoleHtml* m_console; }; ConsoleHtml::ConsoleHtml(QWidget *parent) : QWebEngineView(parent) , m_model(new ConsoleModel(this)) { connect(m_model.data(), &ConsoleModel::updateView, this, &ConsoleHtml::updateView); connect(m_model.data(), &ConsoleModel::operationSuccessful, this, &ConsoleHtml::includeOperation); setPage(new ConsolePage(this)); } ConsoleHtml::~ConsoleHtml() { qDeleteAll(m_options); } void ConsoleHtml::openClickedUrl(const QUrl& url) { QUrlQuery query(url); QString id =query.queryItemValue(QStringLiteral("id")); QString exp=query.queryItemValue(QStringLiteral("func")); if(id=="copy") { emit paste(exp); } else foreach(InlineOptions* opt, m_options) { if(opt->id() == id) { opt->triggerOption(Analitza::Expression(exp, false)); } } } bool ConsoleHtml::addOperation(const Analitza::Expression& e, const QString& input) { return m_model->addOperation(e, input); } ConsoleModel::ConsoleMode ConsoleHtml::mode() const { return m_model->mode(); } void ConsoleHtml::setMode(ConsoleModel::ConsoleMode newMode) { m_model->setMode(newMode); } Analitza::Analyzer* ConsoleHtml::analitza() { return m_model->analyzer(); } bool ConsoleHtml::loadScript(const QUrl& path) { return m_model->loadScript(path.isLocalFile() ? path : retrieve(path)); } bool ConsoleHtml::saveScript(const QUrl & path) const { const QUrl savePath=path.isLocalFile() ? path : temporaryPath(); bool correct = m_model->saveScript(savePath); if(!path.isLocalFile()) { KIO::CopyJob* job=KIO::move(savePath, path); correct=job->exec(); } return correct; } bool ConsoleHtml::saveLog(const QUrl & path) const { const QUrl savePath=path.isLocalFile() ? path : temporaryPath(); bool correct = m_model->saveLog(savePath); if(!path.isLocalFile()) { KIO::CopyJob* job=KIO::move(savePath, path); correct=job->exec(); } return correct; } void ConsoleHtml::includeOperation(const Analitza::Expression& /*e*/, const Analitza::Expression& res) { m_optionsString.clear(); if (res.isCorrect()) { Analitza::Analyzer lambdifier(m_model->variables()); lambdifier.setExpression(res); Analitza::Expression lambdaexp = lambdifier.dependenciesToLambda(); lambdifier.setExpression(lambdaexp); foreach(InlineOptions* opt, m_options) { if(opt->matchesExpression(lambdaexp)) { QUrl url(QStringLiteral("/query")); QUrlQuery query(url); query.addQueryItem(QStringLiteral("id"), opt->id()); query.addQueryItem(QStringLiteral("func"), lambdaexp.toString()); url.setQuery(query); m_optionsString += i18n(" %2", url.toString(), opt->caption()); } } if(!m_optionsString.isEmpty()) { m_optionsString = "
"+i18n("Options: %1", m_optionsString)+"
"; } } } void ConsoleHtml::updateView() { QByteArray code; code += "\n"; code += "\n\n\t :) \n"; code += m_model->css(); code += "\n"; auto log = m_model->htmlLog(); const auto newEntry = log.takeLast(); foreach(const QString &entry, log) - code += "

" + entry + "

\n"; + code += "

" + entry.toUtf8() + "

\n"; code += m_optionsString.toUtf8(); if (newEntry.startsWith("
    ")) code += newEntry; else code += "

    " + newEntry + "

    \n"; code += ""; page()->setHtml(code); emit changed(); QObject* o = new QObject; connect(this, &QWebEngineView::loadFinished, o, [this, o](){ page()->runJavaScript(QStringLiteral("window.scrollTo(0, document.body.scrollHeight);")); delete o; }); } void ConsoleHtml::copy() const { QApplication::clipboard()->setText(selectedText()); } void ConsoleHtml::contextMenuEvent(QContextMenuEvent* ev) { QMenu popup; if(hasSelection()) { popup.addAction(KStandardAction::copy(this, SLOT(copy()), &popup)); QAction *act=new QAction(QIcon::fromTheme(QStringLiteral("edit-paste")), i18n("Paste \"%1\" to input", selectedText()), &popup); connect(act, SIGNAL(triggered()), SLOT(paste())); popup.addAction(act); popup.addSeparator(); } popup.addAction(KStandardAction::clear(this, SLOT(clear()), &popup)); popup.exec(ev->pos()); } void ConsoleHtml::clear() { m_model->clear(); updateView(); } void ConsoleHtml::modifyVariable(const QString& name, const Analitza::Expression& exp) { m_model->variables()->modify(name, exp); } void ConsoleHtml::removeVariable(const QString & name) { m_model->variables()->remove(name); } void ConsoleHtml::paste() { emit paste(selectedText()); }