Debian Codegraph @

src/documentview.h

raw symbols SCIP
1 /*
2 Copyright (C) 2010 Andres Cabrera
3 [email protected]
4
5 This file is part of CsoundQt.
6
7 CsoundQt is free software; you can redistribute it
8 and/or modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 CsoundQt is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with Csound; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA
21 */
22
23 #ifndef DOCUMENTVIEW_H
24 #define DOCUMENTVIEW_H
25
26 #include <QtWidgets>
27 #include <QtPrintSupport/QPrinter>
28 #include <QtPrintSupport/QPrintDialog>
29
30 #include "baseview.h"
31
32 #include <QKeyEvent> // For syntax menu class
33 #include <QPair>
34
35 class MySyntaxMenu: public QMenu
36 {
37 Q_OBJECT
38 public:
39 MySyntaxMenu(QWidget * parent);
40 ~MySyntaxMenu();
41
42 bool insertComplete; // Whether to insert full text or only opcode name
43
44 protected:
45 virtual void keyPressEvent(QKeyEvent * event);
46
47 signals:
48 void keyPressed(QString text); // Used to send both pressed keys and full opcode text to be pasted
49 };
50
51 class HoverWidget :
52 public QWidget
53 {
54 Q_OBJECT
55 public:
56 HoverWidget(QWidget *parent);
57 ~HoverWidget() {}
58
59 protected:
60 void mousePressEvent(QMouseEvent *ev);
61
62 };
63
64 class DocumentView : public BaseView
65 {
66 Q_OBJECT
67 public:
68 DocumentView(QWidget * parent, OpEntryParser *opcodeTree = 0);
69 ~DocumentView();
70
71 void insertText(QString text, int section = -1);
72 void setAutoComplete(bool autoComplete, int delay = 0);
73 void setAutoParameterMode(bool autoParameterMode);
74 void setViewMode(int mode);
75
76 // TODO add all text inputs here as below
77
78 QString getSelectedText(int section = -1);
79
80 // These two should be used with care as they are only here in case
81 // Widgets are being edited in text format. In most cases, you want to
82 // get the widgets Text from the widget layout object
83 QString getMacWidgetsText(); // With tags including presets
84 QString getWidgetsText(); // With tags including presets, in new xml format
85 int getViewMode();
86
87 QString wordUnderCursor();
88 QString lineUnderCursor();
89 QString getActiveSection();
90 QString getActiveText();
91 int currentLineNumber();
92 bool isModified();
93 bool childHasFocus();
94 void print(QPrinter *printer);
95
96
97 bool matchLeftParenthesis(QTextBlock currentBlock, int i, int numLeftParentheses);
98 bool matchRightParenthesis(QTextBlock currentBlock, int index, int numRightParentheses);
99 void createParenthesisSelection(int pos, bool paired=true);
100 void setParsedUDOs(QStringList udos);
101 Highlighter* getHighlighter() { return &m_highlighter; }
102 void gotoLineDialog();
103 void markCurrentPosition();
104 const QStringList getAllWords();
105
106
107 public slots:
108 void setModified(bool mod = true);
109 void syntaxCheck();
110 void textChanged();
111 void escapePressed();
112 void finishParameterMode();
113 void exitParameterMode();
114 void indentNewLine();
115 void findReplace();
116 void getToIn(); // chnget/chnset to invalue/outvalue
117 void inToGet(); // invalue/outvalue to chnget/chnset
118 void insertAutoCompleteText();
119 void findString(QString query = QString());
120 void evaluate();
121 void updateContext();
122 void updateOrcContext(QString orc);
123 void nextParameter();
124 void prevParameter();
125 void showHoverText();
126 void hideHoverText();
127 void updateHoverText(int x, int y, QString text);
128 void createContextMenu(QPoint pos);
129 void autoCompleteAtCursor();
130
131 void showOrc(bool);
132 void showScore(bool);
133 void showOptions(bool);
134 void showFileB(bool);
135 void showOther(bool);
136 void showOtherCsd(bool);
137 void showWidgetEdit(bool);
138 void showAppEdit(bool);
139
140 void cut();
141 void copy();
142 void paste();
143 void undo();
144 void redo();
145 void comment();
146 void uncomment();
147 void indent();
148 void unindent();
149 void killLine();
150 void killToEnd();
151
152 void markErrorLines(QList<QPair<int, QString> > lines);
153 void unmarkErrorLines();
154 void jumpToLine(int line, bool mark=true);
155 void goBackToPreviousPosition();
156 void gotoNextLine();
157 void opcodeFromMenu();
158
159
160 void insertChn_k(QString channel);
161
162
163 protected:
164 virtual void contextMenuEvent(QContextMenuEvent *event);
165
166 private:
167 QString changeToChnget(QString text);
168 QString changeToInvalue(QString text);
169
170 MySyntaxMenu *syntaxMenu;
171
172 HoverWidget *m_hoverWidget;
173 QLabel *m_hoverText;
174 QString m_currentOpcodeText;
175 //QPair<int, int> m_parenspos;
176
177 bool m_isModified;
178 bool m_autoComplete;
179 int m_autoCompleteDelay = 150;
180 QTimer* m_autoCompleteTimer = nullptr;
181 bool m_autoParameterMode;
182 bool errorMarked;
183 bool internalChange; // to let popoup opcode completion know if text change was internal
184 QTextEdit * m_currentEditor;
185
186 bool lastCaseSensitive; // These last three are for search and replace
187 QString lastSearch;
188 QString lastReplace;
189 QStringList m_localVariables;
190 QStringList m_globalVariables;
191 QTime m_lastWordsUpdate;
192 QStringList m_allWords;
193 int m_lastCursorPosition;
194 QStringList m_longOptions = {
195 "syntax-check-only", "control-rate=", "messagelevel=",
196 "env:", "dither", "sched", "omacro:", "smacro:",
197 "verbose", "sample-accurate", "realtime",
198 "nchnls=", "nchnls_i=", "sinesize", "daemon",
199 "port=", "use-system-sr", "ksmps=",
200 "limiter", "udp-echo", "opcode-dir="
201 };
202 QStringList m_longOptions2 = {"rtmidi", "rtaudio"};
203
204 // QTime m_lastContextUpdate;
205
206 QList<int> cursorPositions;
207
208 enum {
209 ORC_CONTEXT = 0,
210 SCO_CONTEXT,
211 OPTIONS_CONTEXT,
212 PYTHON_CONTEXT,
213 NO_CONTEXT
214 };
215 int m_currentContext;
216 int m_oldCursorPosition; // if necessary to move back, like after evaluateSection
217
218 private slots:
219 void destroySyntaxMenu();
220 void opcodeHelp();
221 void restoreCursorPosition();
222
223 signals:
224 void opcodeSyntaxSignal(QString syntax); // Report syntax of opcode under cursor
225 void setHelp(); // Request execute open opcode help action
226 void contentsChanged();
227 void closeExtraPanels();
228 void evaluate(QString code);
229 void newLineAndColumn(int line, int column);
230
231 };
232
233 #endif // DOCUMENTVIEW_H