1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#ifndef __QML_EDIT_H__
#define __QML_EDIT_H__
#include "globals.h"
namespace Ms {
class JSHighlighter;
//---------------------------------------------------------
// QmlEdit
//---------------------------------------------------------
class QmlEdit : public QPlainTextEdit {
Q_OBJECT
QWidget* lineNumberArea;
JSHighlighter* hl;
ScoreState mscoreState;
QString pickBuffer;
virtual void focusInEvent(QFocusEvent*);
virtual void focusOutEvent(QFocusEvent*);
void move(QTextCursor::MoveOperation);
virtual void keyPressEvent(QKeyEvent*);
void tab();
void autoIndent();
private slots:
void updateLineNumberAreaWidth(int);
void highlightCurrentLine();
void updateLineNumberArea(const QRect&, int);
void startOfLine() { move(QTextCursor::StartOfLine); }
void endOfLine() { move(QTextCursor::EndOfLine); }
void upLine() { move(QTextCursor::Up); }
void downLine();
void right() { move(QTextCursor::Right); }
void left() { move(QTextCursor::Left); }
void rightWord() { move(QTextCursor::NextWord); }
void start() { move(QTextCursor::Start); }
void end() { move(QTextCursor::End); }
void leftWord();
void pick();
void put();
void delLine();
void delWord();
protected:
void resizeEvent(QResizeEvent*);
public:
QmlEdit(QWidget* parent = 0);
~QmlEdit();
void lineNumberAreaPaintEvent(QPaintEvent*);
int lineNumberAreaWidth();
enum ColorComponent { Normal, Comment, Number, String, Operator, Identifier,
Keyword, BuiltIn, Marker };
};
//---------------------------------------------------------
// LineNumberArea
//---------------------------------------------------------
class LineNumberArea : public QWidget {
Q_OBJECT
QmlEdit* editor;
QSize sizeHint() const {
return QSize(editor->lineNumberAreaWidth(), 0);
}
void paintEvent(QPaintEvent* event) {
editor->lineNumberAreaPaintEvent(event);
}
public:
LineNumberArea(QmlEdit* parent) : QWidget(parent) { editor = parent; }
};
//---------------------------------------------------------
// JSBlockData
//---------------------------------------------------------
class JSBlockData : public QTextBlockUserData {
public:
QList<int> bracketPositions;
};
//---------------------------------------------------------
// JSHighlighter
//---------------------------------------------------------
class JSHighlighter : public QSyntaxHighlighter {
QSet<QString> m_keywords;
QSet<QString> m_knownIds;
QHash<QmlEdit::ColorComponent, QColor> m_colors;
QString m_markString;
Qt::CaseSensitivity m_markCaseSensitivity;
protected:
void highlightBlock(const QString &text);
public:
JSHighlighter(QTextDocument *parent = 0);
void setColor(QmlEdit::ColorComponent component, const QColor &color);
void mark(const QString &str, Qt::CaseSensitivity caseSensitivity);
QStringList keywords() const;
void setKeywords(const QStringList &keywords);
};
} // namespace Ms
#endif
|