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