Debian Codegraph @

src/texteditor.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 TEXTEDITOR_H
24 #define TEXTEDITOR_H
25
26 #include <QTextEdit>
27 #include <QAction>
28
29 class TextEditor : public QTextEdit
30 {
31 Q_OBJECT
32 public:
33 TextEditor(QWidget *parent = 0);
34
35 void setTabIndents(bool indents) {m_tabIndents = indents;}
36 void setParameterMode(bool on) {m_parameterMode = on; setCursorWidth(on ? 8 : 1);}
37 bool getParameterMode() {return m_parameterMode;}
38 int getLastKey() {return m_lastkey;}
39
40
41 protected:
42 virtual void keyPressEvent (QKeyEvent * event);
43 virtual void mouseReleaseEvent(QMouseEvent * e);
44 // virtual void dropEvent(QDropEvent *event); // See note on code
45 // virtual void dragEnterEvent(QDragEnterEvent *event);
46 // virtual void dragMoveEvent(QDragMoveEvent *event);
47
48 bool m_tabIndents;
49 bool m_parameterMode;
50 bool m_commaTyped;
51 int m_lastkey;
52
53
54 signals:
55 void showParameterInfo();
56 void escapePressed();
57 void enterPressed();
58 void arrowPressed();
59 void tabPressed();
60 void backtabPressed();
61 void newLine();
62 void requestIndent();
63 void requestUnindent();
64 void requestParameterModeExit();
65 void mouseReleased();
66 };
67
68 class LineNumberArea;
69
70 class TextEditLineNumbers : public TextEditor
71 {
72 Q_OBJECT
73 public:
74 TextEditLineNumbers(QWidget *parent = 0);
75 int getAreaWidth();
76 void setLineAreaVisible(bool visible);
77 bool lineAreaVisble() {return m_lineAreaVisble;}
78 QAction *toggleAction;
79 void setLineAreaColors(QColor foreground, QColor background);
80
81 public slots:
82 void markDebugLine(int line);
83 void unmarkDebugLine(int line);
84 void setCurrentDebugLine(int line);
85
86 protected:
87 void resizeEvent(QResizeEvent *e);
88
89 private:
90 LineNumberArea *lineNumberArea;
91 bool m_lineAreaVisble;
92 // padding between line number area and editor (in pixels)
93 int m_editorPadding;
94 QVector<int> m_debugLines;
95
96 private slots:
97 void updateLineArea(int);
98 void updateLineArea();
99 };
100
101 class LineNumberArea : public QWidget
102 {
103 Q_OBJECT
104
105 public:
106 LineNumberArea(TextEditLineNumbers *editor) : QWidget(editor) {
107 codeEditor = editor;
108 m_currentDebugLine = -1;
109 m_lineNumbersSizeFactor = 1;
110 m_padding = 8;
111 m_background = QColor("#A0A0A0");
112 m_foreground = QColor("#303030");
113
114 }
115 void setDebugLines(QVector<int> debugLines) {m_debugLines = debugLines;}
116 void setCurrentDebugLine(int line) {m_currentDebugLine = line;}
117 void setLineNumberSizeScaling(qreal factor) {m_lineNumbersSizeFactor = factor;}
118 qreal lineNumberSizeScaling() { return m_lineNumbersSizeFactor; }
119 int padding() { return m_padding; }
120 void setColors(QColor foreground, QColor background) {
121 m_foreground = foreground;
122 m_background = background;
123 }
124
125 protected:
126 void paintEvent(QPaintEvent *event);
127
128 private:
129 QVector<int> m_debugLines;
130 int m_currentDebugLine;
131 int m_padding;
132 double m_lineNumbersSizeFactor;
133 QColor m_background;
134 QColor m_foreground;
135 TextEditLineNumbers *codeEditor;
136 };
137
138 #endif // TEXTEDITOR_H