2014-02-15 17:55:18 +01:00
|
|
|
#ifndef SCRIPTEDIT_H
|
|
|
|
#define SCRIPTEDIT_H
|
|
|
|
|
2015-04-29 20:24:17 +10:00
|
|
|
#include <QFont>
|
2014-09-01 10:52:10 +02:00
|
|
|
#include <QPlainTextEdit>
|
2023-01-10 22:12:13 +04:00
|
|
|
#include <QRegularExpression>
|
2014-08-22 12:49:34 +02:00
|
|
|
#include <QTimer>
|
2017-04-27 16:31:45 +12:00
|
|
|
#include <QVector>
|
2015-04-28 23:07:42 +10:00
|
|
|
#include <QWidget>
|
2014-02-15 20:49:09 +01:00
|
|
|
|
2022-10-19 19:02:00 +02:00
|
|
|
#include <string>
|
|
|
|
|
2014-02-15 20:49:09 +01:00
|
|
|
#include "../../model/world/universalid.hpp"
|
2014-02-15 19:52:40 +01:00
|
|
|
|
2014-08-24 17:56:20 +02:00
|
|
|
#include "scripthighlighter.hpp"
|
|
|
|
|
2022-10-19 19:02:00 +02:00
|
|
|
class QAction;
|
|
|
|
class QContextMenuEvent;
|
|
|
|
class QDragEnterEvent;
|
|
|
|
class QDragMoveEvent;
|
|
|
|
class QDropEvent;
|
|
|
|
class QEvent;
|
|
|
|
class QObject;
|
|
|
|
class QPaintEvent;
|
|
|
|
class QRect;
|
|
|
|
class QResizeEvent;
|
|
|
|
|
|
|
|
namespace CSMPrefs
|
|
|
|
{
|
|
|
|
class Setting;
|
|
|
|
}
|
2014-02-15 17:55:18 +01:00
|
|
|
|
2014-02-16 09:51:33 +01:00
|
|
|
namespace CSMDoc
|
|
|
|
{
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
2014-02-15 17:55:18 +01:00
|
|
|
namespace CSVWorld
|
|
|
|
{
|
2015-04-28 23:07:42 +10:00
|
|
|
class LineNumberArea;
|
|
|
|
|
2016-01-28 06:28:31 -05:00
|
|
|
/// \brief Editor for scripts.
|
2014-09-01 10:52:10 +02:00
|
|
|
class ScriptEdit : public QPlainTextEdit
|
2014-02-15 17:55:18 +01:00
|
|
|
{
|
2014-02-15 19:52:40 +01:00
|
|
|
Q_OBJECT
|
2014-08-21 14:50:13 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2014-08-21 14:50:13 +02:00
|
|
|
class ChangeLock
|
|
|
|
{
|
|
|
|
ScriptEdit& mEdit;
|
|
|
|
|
|
|
|
ChangeLock(const ChangeLock&);
|
|
|
|
ChangeLock& operator=(const ChangeLock&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
ChangeLock(ScriptEdit& edit);
|
|
|
|
~ChangeLock();
|
2017-04-27 16:31:45 +12:00
|
|
|
};
|
2015-05-16 10:18:11 +02:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
friend class ChangeLock;
|
2015-05-29 22:20:43 +10:00
|
|
|
|
2014-08-21 14:50:13 +02:00
|
|
|
private:
|
|
|
|
int mChangeLocked;
|
|
|
|
ScriptHighlighter* mHighlighter;
|
2014-08-22 12:49:34 +02:00
|
|
|
QTimer mUpdateTimer;
|
2015-04-29 20:24:17 +10:00
|
|
|
bool mShowLineNum;
|
|
|
|
LineNumberArea* mLineNumberArea;
|
2015-05-01 06:08:04 +10:00
|
|
|
QFont mDefaultFont;
|
|
|
|
QFont mMonoFont;
|
2016-04-17 06:54:31 -04:00
|
|
|
int mTabCharCount;
|
2017-04-28 19:57:49 +12:00
|
|
|
bool mMarkOccurrences;
|
2017-04-27 16:31:45 +12:00
|
|
|
QAction* mCommentAction;
|
|
|
|
QAction* mUncommentAction;
|
2014-08-21 14:50:13 +02:00
|
|
|
|
2014-08-24 17:56:20 +02:00
|
|
|
protected:
|
|
|
|
bool event(QEvent* event) override;
|
2014-02-15 19:52:40 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2014-08-21 14:50:13 +02:00
|
|
|
ScriptEdit(const CSMDoc::Document& document, ScriptHighlighter::Mode mode, QWidget* parent);
|
|
|
|
|
2015-04-28 23:07:42 +10:00
|
|
|
/// Should changes to the data be ignored (i.e. not cause updated)?
|
2022-09-22 21:26:05 +03:00
|
|
|
///
|
2015-04-28 23:07:42 +10:00
|
|
|
/// \note This mechanism is used to avoid infinite update recursions
|
2015-04-29 20:24:17 +10:00
|
|
|
bool isChangeLocked() const;
|
2015-04-28 23:07:42 +10:00
|
|
|
|
|
|
|
void lineNumberAreaPaintEvent(QPaintEvent* event);
|
|
|
|
int lineNumberAreaWidth();
|
2015-04-29 20:24:17 +10:00
|
|
|
void showLineNum(bool show);
|
2015-04-28 23:07:42 +10:00
|
|
|
|
2015-05-16 10:18:11 +02:00
|
|
|
protected:
|
2020-10-16 22:18:54 +04:00
|
|
|
void resizeEvent(QResizeEvent* e) override;
|
2015-04-28 23:07:42 +10:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void contextMenuEvent(QContextMenuEvent* event) override;
|
2017-04-25 16:12:59 +12:00
|
|
|
|
2014-02-15 19:52:40 +01:00
|
|
|
private:
|
2014-02-15 20:49:09 +01:00
|
|
|
QVector<CSMWorld::UniversalId::Type> mAllowedTypes;
|
2014-02-16 09:51:33 +01:00
|
|
|
const CSMDoc::Document& mDocument;
|
2023-01-12 22:49:23 +01:00
|
|
|
const QRegularExpression mWhiteListQuotes;
|
2016-01-28 06:28:31 -05:00
|
|
|
|
2014-02-16 09:51:33 +01:00
|
|
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
2014-02-15 20:49:09 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void dropEvent(QDropEvent* event) override;
|
2014-02-15 17:55:18 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
void dragMoveEvent(QDragMoveEvent* event) override;
|
2014-02-15 17:55:18 +01:00
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
bool stringNeedsQuote(const std::string& id) const;
|
2014-02-16 18:41:42 +01:00
|
|
|
|
2014-02-17 08:58:55 +01:00
|
|
|
/// \brief Set tab width for script editor.
|
|
|
|
void setTabWidth();
|
2014-08-22 12:49:34 +02:00
|
|
|
|
2016-04-07 07:45:33 -04:00
|
|
|
/// \brief Turn line wrapping in script editor on or off.
|
|
|
|
/// \param wrap Whether or not to wrap lines.
|
2016-04-17 06:54:31 -04:00
|
|
|
void wrapLines(bool wrap);
|
2016-04-07 07:45:33 -04:00
|
|
|
|
2016-01-28 06:28:31 -05:00
|
|
|
private slots:
|
|
|
|
|
2014-08-22 12:49:34 +02:00
|
|
|
/// \brief Update editor when related setting is changed.
|
2016-01-28 06:28:31 -05:00
|
|
|
/// \param setting Setting that was changed.
|
2014-08-22 12:49:34 +02:00
|
|
|
void settingChanged(const CSMPrefs::Setting* setting);
|
|
|
|
|
2016-01-28 06:28:31 -05:00
|
|
|
void idListChanged();
|
2015-12-12 14:49:16 +01:00
|
|
|
|
2014-08-22 12:49:34 +02:00
|
|
|
void updateHighlighting();
|
|
|
|
|
|
|
|
void updateLineNumberAreaWidth(int newBlockCount);
|
2015-04-28 23:07:42 +10:00
|
|
|
|
|
|
|
void updateLineNumberArea(const QRect&, int);
|
2015-05-29 22:20:43 +10:00
|
|
|
|
2015-04-28 23:07:42 +10:00
|
|
|
void markOccurrences();
|
2017-04-28 19:28:05 +12:00
|
|
|
|
2017-04-25 16:12:59 +12:00
|
|
|
void commentSelection();
|
|
|
|
|
|
|
|
void uncommentSelection();
|
2015-04-28 23:07:42 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
class LineNumberArea : public QWidget
|
|
|
|
{
|
|
|
|
ScriptEdit* mScriptEdit;
|
|
|
|
|
|
|
|
public:
|
|
|
|
LineNumberArea(ScriptEdit* editor);
|
2020-10-16 22:18:54 +04:00
|
|
|
QSize sizeHint() const override;
|
2015-04-28 23:07:42 +10:00
|
|
|
|
2015-05-16 10:18:11 +02:00
|
|
|
protected:
|
2020-10-16 22:18:54 +04:00
|
|
|
void paintEvent(QPaintEvent* event) override;
|
2014-02-15 17:55:18 +01:00
|
|
|
};
|
|
|
|
}
|
2015-03-11 10:54:45 -04:00
|
|
|
#endif // SCRIPTEDIT_H
|