File indexing completed on 2024-04-28 07:28:48
0001 /************************************************************************************* 0002 * Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 #ifndef CONSOLE_H 0020 #define CONSOLE_H 0021 0022 #include <QWebEngineView> 0023 #include <QWidget> 0024 0025 #include "consolemodel.h" 0026 #include <analitza/analyzer.h> 0027 0028 class ConsoleModel; 0029 0030 class InlineOptions 0031 { 0032 public: 0033 virtual ~InlineOptions() 0034 { 0035 } 0036 0037 virtual QString id() const = 0; 0038 virtual QString caption() const = 0; 0039 virtual bool matchesExpression(const Analitza::Expression &exp) const = 0; 0040 virtual void triggerOption(const Analitza::Expression &exp) = 0; 0041 }; 0042 0043 /** 0044 * The Console widget is able to receive an operation, solve it and show the value. 0045 * It also is able to load scripts and save logs. 0046 * @author Aleix Pol Gonzalez 0047 */ 0048 0049 class ConsoleHtml : public QWebEngineView 0050 { 0051 Q_OBJECT 0052 public: 0053 /** Constructor. Creates a console widget. */ 0054 ConsoleHtml(QWidget *parent = nullptr); 0055 0056 /** Destructor. */ 0057 ~ConsoleHtml() override; 0058 0059 /** Retrieves a pointer to the Analitza calculator associated. */ 0060 Analitza::Analyzer *analitza(); 0061 0062 /** Sets a @p newMode console mode. */ 0063 void setMode(ConsoleModel::ConsoleMode newMode); 0064 0065 /** Retrieves the console mode. */ 0066 ConsoleModel::ConsoleMode mode() const; 0067 0068 void addOptionsObserver(InlineOptions *opt) 0069 { 0070 m_options += opt; 0071 } 0072 0073 void contextMenuEvent(QContextMenuEvent *ev) override; 0074 0075 public Q_SLOTS: 0076 /** Adds the operation defined by the expression @p e. */ 0077 bool addOperation(const Analitza::Expression &e, const QString &input); 0078 0079 /** Loads a script from @p path. */ 0080 bool loadScript(const QUrl &path); 0081 0082 /** Save a script yo @p path. */ 0083 bool saveScript(const QUrl &path) const; 0084 0085 /** Saves a log to @p path. */ 0086 bool saveLog(const QUrl &path) const; 0087 0088 /** Flushes the contents. */ 0089 void clear(); 0090 0091 /** Copies the selected text to the clipboard */ 0092 void copy() const; 0093 0094 void openClickedUrl(const QUrl &url); 0095 0096 void setActualUrl(const QUrl &url); 0097 0098 Q_SIGNALS: 0099 /** Emits a notification that tells that the widget status. */ 0100 void status(const QString &msg); 0101 0102 /** Emits that something has changed. */ 0103 void changed(); 0104 0105 /** Emits the selected code to be pasted somewhere */ 0106 void paste(const QString &code); 0107 0108 private Q_SLOTS: 0109 void modifyVariable(const QString &name, const Analitza::Expression &exp); 0110 void removeVariable(const QString &name); 0111 void paste(); 0112 0113 private: 0114 void includeOperation(const Analitza::Expression &expression, const Analitza::Expression &result); 0115 void updateView(); 0116 0117 QString m_optionsString; 0118 QUrl m_actualUrl; 0119 QList<InlineOptions *> m_options; 0120 QScopedPointer<ConsoleModel> m_model; 0121 }; 0122 0123 #endif