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