view command-window.h @ 17:2ddf3fe6fa33

initial attempt at using separate thread for interpreter
author John W. Eaton <jwe@octave.org>
date Tue, 28 May 2019 18:27:18 -0400
parents b652a5528fb1
children
line wrap: on
line source

#if ! defined (calc_command_window_h)
#define calc_command_window_h 1

#include <string>

#include <QTextDocument>
#include <QTextEdit>
#if defined (CALC_USE_INTERPRETER_THREAD)
#  include <QThread>
#endif

#include "qt-interpreter.h"

namespace calc
{
  class command_window : public QTextEdit
  {
    Q_OBJECT

  public:

    static command_window *the_command_window;

    command_window (QWidget *p = nullptr);

    ~command_window (void);

    // Accept an input line, parse and possibly execute it.

    void accept_line (const std::string& line);

    // Handle EOF on input.

    void eof (void);

    // Redisplay current command line.

    void insert_at_end (const std::string& text);

    void emit_error (const std::string& msg);

    void emit_result (double value);

  signals:

    void input_char_available (int key);

    void accept_line_signal (const QString& line);

    void eof_signal (void);

    void redisplay_signal (void);

  public slots:

    void handle_input_char (int key);

    void handle_error (const QString& msg);

    void handle_result (double value);

    void redisplay (void);

  protected:

    void keyPressEvent (QKeyEvent *event);

    int do_arrow_key (int arrow_key);

    // Retrieve a command from the history list and insert it on the
    // current command.

    void history (bool up);

    void erase_line (void);

    void insert_at_cursor (const std::string& text);

    void insert_line (const std::string& prompt, const std::string& line);

    int set_mark (void);

    void insert_result (double value);

    void scroll_to_bottom (void);

#if defined (CALC_USE_INTERPRETER_THREAD)
    QThread m_interpreter_thread;
#endif

    // Child widgets:

    QTextDocument *m_buffer;

    calc::qt_interpreter *m_interpreter;

    int beg_mark;
    int prompt_mark;
  };
}

#endif