File indexing completed on 2025-02-02 04:11:27

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #ifndef SCRIPTCONSOLE_H
0008 #define SCRIPTCONSOLE_H
0009 
0010 #include <memory>
0011 #include <QWidget>
0012 
0013 #include "plugin/executor.hpp"
0014 
0015 namespace glaxnimate::gui {
0016 
0017 class PluginUiDialog;
0018 
0019 class ScriptConsole : public QWidget, public plugin::Executor
0020 {
0021     Q_OBJECT
0022 
0023 public:
0024     ScriptConsole(QWidget* parent = nullptr);
0025     ~ScriptConsole();
0026 
0027     bool execute(const plugin::Plugin& plugin, const plugin::PluginScript& script, const QVariantList& in_args) override;
0028     QVariant get_global(const QString& name) override;
0029     void set_global(const QString& name, const QVariant& value);
0030 
0031     PluginUiDialog* create_dialog(const QString& ui_file) const;
0032 
0033     void clear_contexts();
0034     void clear_output();
0035     void save_settings();
0036 
0037 protected:
0038     void changeEvent ( QEvent* e ) override;
0039 
0040 public Q_SLOTS:
0041     void run_snippet(const QString& source);
0042 
0043 private Q_SLOTS:
0044     void console_commit(const QString& command);
0045     void console_clear();
0046 
0047 Q_SIGNALS:
0048     void error(const QString& plugin, const QString& message);
0049 
0050 private:
0051     class Private;
0052     std::unique_ptr<Private> d;
0053 };
0054 
0055 } // namespace glaxnimate::gui
0056 
0057 #endif // SCRIPTCONSOLE_H