2012-07-02 19:15:37 +02:00
|
|
|
//=============================================================================
|
|
|
|
// 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__
|
|
|
|
|
2012-07-06 14:21:05 +02:00
|
|
|
#include "globals.h"
|
|
|
|
|
2012-07-03 09:20:53 +02:00
|
|
|
class JSHighlighter;
|
|
|
|
|
2012-07-02 19:15:37 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// QmlEdit
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
class QmlEdit : public QPlainTextEdit {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
QWidget* lineNumberArea;
|
2012-07-03 09:20:53 +02:00
|
|
|
JSHighlighter* hl;
|
2012-07-06 14:21:05 +02:00
|
|
|
ScoreState mscoreState;
|
|
|
|
|
|
|
|
virtual void focusInEvent(QFocusEvent*);
|
|
|
|
virtual void focusOutEvent(QFocusEvent*);
|
|
|
|
void move(QTextCursor::MoveOperation op);
|
2012-07-02 19:15:37 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void updateLineNumberAreaWidth(int);
|
|
|
|
void highlightCurrentLine();
|
|
|
|
void updateLineNumberArea(const QRect&, int);
|
2012-07-06 14:21:05 +02:00
|
|
|
void startOfLine() { move(QTextCursor::StartOfLine); }
|
|
|
|
void endOfLine() { move(QTextCursor::EndOfLine); }
|
|
|
|
void upLine() { move(QTextCursor::Up); }
|
|
|
|
void downLine() { move(QTextCursor::Down); }
|
|
|
|
void right() { move(QTextCursor::Right); }
|
|
|
|
void left() { move(QTextCursor::Left); }
|
|
|
|
void rightWord() { move(QTextCursor::NextWord); }
|
|
|
|
void leftWord() { move(QTextCursor::StartOfWord); }
|
2012-07-02 19:15:37 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent*);
|
|
|
|
|
|
|
|
public:
|
|
|
|
QmlEdit(QWidget* parent = 0);
|
2012-07-03 09:20:53 +02:00
|
|
|
~QmlEdit();
|
2012-07-02 19:15:37 +02:00
|
|
|
void lineNumberAreaPaintEvent(QPaintEvent*);
|
|
|
|
int lineNumberAreaWidth();
|
2012-07-03 09:20:53 +02:00
|
|
|
enum ColorComponent { Normal, Comment, Number, String, Operator, Identifier,
|
|
|
|
Keyword, BuiltIn, Marker };
|
2012-07-02 19:15:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// 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; }
|
|
|
|
};
|
|
|
|
|
2012-07-03 09:20:53 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// JSBlockData
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
class JSBlockData : public QTextBlockUserData {
|
|
|
|
public:
|
|
|
|
QList<int> bracketPositions;
|
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// JSHighlighter
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
class JSHighlighter : public QSyntaxHighlighter {
|
2012-07-05 14:31:03 +02:00
|
|
|
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);
|
|
|
|
|
2012-07-03 09:20:53 +02:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2012-07-02 19:15:37 +02:00
|
|
|
#endif
|
|
|
|
|