1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-23 03:53:53 +00:00
openmw/apps/opencs/view/world/scriptedit.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

149 lines
3.3 KiB
C++
Raw Normal View History

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