author | llornkcor <llornkcor> | 2002-10-31 20:10:52 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-10-31 20:10:52 (UTC) |
commit | ab5a63544deead5206ca47ff8bf94123aa032281 (patch) (unidiff) | |
tree | b28514032d605dc28a5bffbd6918066c81fff74f | |
parent | 16d3fac9169e400f5542ca0e3aa993cc5c5db574 (diff) | |
download | opie-ab5a63544deead5206ca47ff8bf94123aa032281.zip opie-ab5a63544deead5206ca47ff8bf94123aa032281.tar.gz opie-ab5a63544deead5206ca47ff8bf94123aa032281.tar.bz2 |
no wrap and horz scroll should work, thanks to console
-rw-r--r-- | core/apps/embeddedkonsole/TEHistory.h | 6 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/TEScreen.h | 14 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/TEWidget.cpp | 5 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/TEmulation.h | 7 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/konsole.cpp | 90 | ||||
-rw-r--r-- | core/apps/embeddedkonsole/konsole.h | 1 |
6 files changed, 83 insertions, 40 deletions
diff --git a/core/apps/embeddedkonsole/TEHistory.h b/core/apps/embeddedkonsole/TEHistory.h index 8339ec6..11eb150 100644 --- a/core/apps/embeddedkonsole/TEHistory.h +++ b/core/apps/embeddedkonsole/TEHistory.h | |||
@@ -1,75 +1,75 @@ | |||
1 | /* -------------------------------------------------------------------------- */ | 1 | /* -------------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [TEHistory.H] History Buffer */ | 3 | /* [TEHistory.H] History Buffer */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* */ | 10 | /* */ |
11 | /* -------------------------------------------------------------------------- */ | 11 | /* -------------------------------------------------------------------------- */ |
12 | /* */ | 12 | /* */ |
13 | /* Ported Konsole to Qt/Embedded */ | 13 | /* Ported Konsole to Qt/Embedded */ |
14 | /* */ | 14 | /* */ |
15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
16 | /* */ | 16 | /* */ |
17 | /* -------------------------------------------------------------------------- */ | 17 | /* -------------------------------------------------------------------------- */ |
18 | 18 | ||
19 | #ifndef TEHISTORY_H | 19 | #ifndef TEHISTORY_H |
20 | #define TEHISTORY_H | 20 | #define TEHISTORY_H |
21 | 21 | ||
22 | #include "TECommon.h" | 22 | #include "TECommon.h" |
23 | 23 | ||
24 | /* | 24 | /* |
25 | An extendable tmpfile(1) based buffer. | 25 | An extendable tmpfile(1) based buffer. |
26 | */ | 26 | */ |
27 | class HistoryBuffer | 27 | class HistoryBuffer |
28 | { | 28 | { |
29 | public: | 29 | public: |
30 | HistoryBuffer(); | 30 | HistoryBuffer(); |
31 | ~HistoryBuffer(); | 31 | ~HistoryBuffer(); |
32 | 32 | ||
33 | public: | 33 | public: |
34 | void setScroll(bool on); | 34 | void setScroll(bool on); |
35 | bool hasScroll(); | 35 | bool hasScroll(); |
36 | 36 | ||
37 | public: | 37 | public: |
38 | void add(const unsigned char* bytes, int len); | 38 | void add(const unsigned char* bytes, int len); |
39 | void get(unsigned char* bytes, int len, int loc); | 39 | void get(unsigned char* bytes, int len, int loc); |
40 | int len(); | 40 | int len(); |
41 | 41 | ||
42 | private: | 42 | private: |
43 | int ion; | 43 | int ion; |
44 | int length; | 44 | int length; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | class HistoryScroll | 47 | class HistoryScroll |
48 | { | 48 | { |
49 | public: | 49 | public: |
50 | HistoryScroll(); | 50 | HistoryScroll(); |
51 | ~HistoryScroll(); | 51 | ~HistoryScroll(); |
52 | 52 | ||
53 | public: | 53 | public: |
54 | void setScroll(bool on); | 54 | void setScroll(bool on); |
55 | bool hasScroll(); | 55 | bool hasScroll(); |
56 | 56 | ||
57 | public: // access to history | 57 | public: // access to history |
58 | int getLines(); | 58 | int getLines(); |
59 | int getLineLen(int lineno); | 59 | int getLineLen(int lineno); |
60 | void getCells(int lineno, int colno, int count, ca res[]); | 60 | void getCells(int lineno, int colno, int count, ca res[]); |
61 | 61 | ||
62 | public: // backward compatibility (obsolete) | 62 | public: // backward compatibility (obsolete) |
63 | ca getCell(int lineno, int colno) { ca res; getCells(lineno,colno,1,&res); return res; } | 63 | ca getCell(int lineno, int colno) { ca res; getCells(lineno,colno,1,&res); return res; } |
64 | 64 | ||
65 | public: // adding lines. | 65 | public: // adding lines. |
66 | void addCells(ca a[], int count); | 66 | void addCells(ca a[], int count); |
67 | void addLine(); | 67 | void addLine(); |
68 | 68 | ||
69 | private: | 69 | private: |
70 | int startOfLine(int lineno); | 70 | int startOfLine(int lineno); |
71 | HistoryBuffer index; // lines Row(int) | 71 | HistoryBuffer index; // lines Row(int) |
72 | HistoryBuffer cells; // text Row(ca) | 72 | HistoryBuffer cells; // text Row(ca) |
73 | }; | 73 | }; |
74 | 74 | ||
75 | #endif // TEHISTORY_H | 75 | #endif // TEHISTORY_H |
diff --git a/core/apps/embeddedkonsole/TEScreen.h b/core/apps/embeddedkonsole/TEScreen.h index ba47ee5..a28f7c5 100644 --- a/core/apps/embeddedkonsole/TEScreen.h +++ b/core/apps/embeddedkonsole/TEScreen.h | |||
@@ -1,259 +1,267 @@ | |||
1 | /* -------------------------------------------------------------------------- */ | 1 | /* -------------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [te_screen.h] Screen Data Type */ | 3 | /* [te_screen.h] Screen Data Type */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* */ | 10 | /* */ |
11 | /* -------------------------------------------------------------------------- */ | 11 | /* -------------------------------------------------------------------------- */ |
12 | /* */ | 12 | /* */ |
13 | /* Ported Konsole to Qt/Embedded */ | 13 | /* Ported Konsole to Qt/Embedded */ |
14 | /* */ | 14 | /* */ |
15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
16 | /* */ | 16 | /* */ |
17 | /* -------------------------------------------------------------------------- */ | 17 | /* -------------------------------------------------------------------------- */ |
18 | 18 | ||
19 | #ifndef TESCREEN_H | 19 | #ifndef TESCREEN_H |
20 | #define TESCREEN_H | 20 | #define TESCREEN_H |
21 | 21 | ||
22 | /*! \file | 22 | /*! \file |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "TECommon.h" | 25 | #include "TECommon.h" |
26 | #include "TEHistory.h" | 26 | #include "TEHistory.h" |
27 | 27 | ||
28 | #define MODE_Origin 0 | 28 | #define MODE_Origin 0 |
29 | #define MODE_Wrap 1 | 29 | #define MODE_Wrap 1 |
30 | #define MODE_Insert 2 | 30 | #define MODE_Insert 2 |
31 | #define MODE_Screen 3 | 31 | #define MODE_Screen 3 |
32 | #define MODE_Cursor 4 | 32 | #define MODE_Cursor 4 |
33 | #define MODE_NewLine 5 | 33 | #define MODE_NewLine 5 |
34 | #define MODES_SCREEN 6 | 34 | #define MODES_SCREEN 6 |
35 | 35 | ||
36 | /*! | 36 | /*! |
37 | */ | 37 | */ |
38 | struct ScreenParm | 38 | struct ScreenParm |
39 | { | 39 | { |
40 | int mode[MODES_SCREEN]; | 40 | int mode[MODES_SCREEN]; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | 43 | ||
44 | class TEScreen | 44 | class TEScreen |
45 | { | 45 | { |
46 | public: | 46 | public: |
47 | TEScreen(int lines, int columns); | 47 | TEScreen(int lines, int columns); |
48 | ~TEScreen(); | 48 | ~TEScreen(); |
49 | 49 | ||
50 | public: // these are all `Screen' operations | 50 | public: // these are all `Screen' operations |
51 | // | 51 | // |
52 | // VT100/2 Operations ------------------ | 52 | // VT100/2 Operations ------------------ |
53 | // | 53 | // |
54 | // Cursor Movement | 54 | // Cursor Movement |
55 | // | 55 | // |
56 | void cursorUp (int n); | 56 | void cursorUp (int n); |
57 | void cursorDown (int n); | 57 | void cursorDown (int n); |
58 | void cursorLeft (int n); | 58 | void cursorLeft (int n); |
59 | void cursorRight (int n); | 59 | void cursorRight (int n); |
60 | void setCursorY (int y); | 60 | void setCursorY (int y); |
61 | void setCursorX (int x); | 61 | void setCursorX (int x); |
62 | void setCursorYX (int y, int x); | 62 | void setCursorYX (int y, int x); |
63 | void setMargins (int t, int b); | 63 | void setMargins (int t, int b); |
64 | // | 64 | // |
65 | // Cursor Movement with Scrolling | 65 | // Cursor Movement with Scrolling |
66 | // | 66 | // |
67 | void NewLine (); | 67 | void NewLine (); |
68 | void NextLine (); | 68 | void NextLine (); |
69 | void index (); | 69 | void index (); |
70 | void reverseIndex(); | 70 | void reverseIndex(); |
71 | // | 71 | // |
72 | void Return (); | 72 | void Return (); |
73 | void BackSpace (); | 73 | void BackSpace (); |
74 | void Tabulate (); | 74 | void Tabulate (); |
75 | // | 75 | // |
76 | // Editing | 76 | // Editing |
77 | // | 77 | // |
78 | void eraseChars (int n); | 78 | void eraseChars (int n); |
79 | void deleteChars (int n); | 79 | void deleteChars (int n); |
80 | void insertChars (int n); | 80 | void insertChars (int n); |
81 | void deleteLines (int n); | 81 | void deleteLines (int n); |
82 | void insertLines (int n); | 82 | void insertLines (int n); |
83 | // | 83 | // |
84 | // ------------------------------------- | 84 | // ------------------------------------- |
85 | // | 85 | // |
86 | void clearTabStops(); | 86 | void clearTabStops(); |
87 | void changeTabStop(bool set); | 87 | void changeTabStop(bool set); |
88 | // | 88 | // |
89 | void resetMode (int n); | 89 | void resetMode (int n); |
90 | void setMode (int n); | 90 | void setMode (int n); |
91 | void saveMode (int n); | 91 | void saveMode (int n); |
92 | void restoreMode (int n); | 92 | void restoreMode (int n); |
93 | // | 93 | // |
94 | void saveCursor (); | 94 | void saveCursor (); |
95 | void restoreCursor(); | 95 | void restoreCursor(); |
96 | // | 96 | // |
97 | // ------------------------------------- | 97 | // ------------------------------------- |
98 | // | 98 | // |
99 | void clearEntireScreen(); | 99 | void clearEntireScreen(); |
100 | void clearToEndOfScreen(); | 100 | void clearToEndOfScreen(); |
101 | void clearToBeginOfScreen(); | 101 | void clearToBeginOfScreen(); |
102 | // | 102 | // |
103 | void clearEntireLine(); | 103 | void clearEntireLine(); |
104 | void clearToEndOfLine(); | 104 | void clearToEndOfLine(); |
105 | void clearToBeginOfLine(); | 105 | void clearToBeginOfLine(); |
106 | // | 106 | // |
107 | void helpAlign (); | 107 | void helpAlign (); |
108 | // | 108 | // |
109 | // ------------------------------------- | 109 | // ------------------------------------- |
110 | // | 110 | // |
111 | void setRendition (int rendition); | 111 | void setRendition (int rendition); |
112 | void resetRendition(int rendition); | 112 | void resetRendition(int rendition); |
113 | void setForeColor (int fgcolor); | 113 | void setForeColor (int fgcolor); |
114 | void setBackColor (int bgcolor); | 114 | void setBackColor (int bgcolor); |
115 | // | 115 | // |
116 | void setDefaultRendition(); | 116 | void setDefaultRendition(); |
117 | void setForeColorToDefault(); | 117 | void setForeColorToDefault(); |
118 | void setBackColorToDefault(); | 118 | void setBackColorToDefault(); |
119 | // | 119 | // |
120 | // ------------------------------------- | 120 | // ------------------------------------- |
121 | // | 121 | // |
122 | BOOL getMode (int n); | 122 | BOOL getMode (int n); |
123 | // | 123 | // |
124 | // only for report cursor position | 124 | // only for report cursor position |
125 | // | 125 | // |
126 | int getCursorX(); | 126 | int getCursorX(); |
127 | int getCursorY(); | 127 | int getCursorY(); |
128 | // | 128 | // |
129 | // ------------------------------------- | 129 | // ------------------------------------- |
130 | // | 130 | // |
131 | void clear(); | 131 | void clear(); |
132 | void home(); | 132 | void home(); |
133 | void reset(); | 133 | void reset(); |
134 | // | 134 | // |
135 | void ShowCharacter(unsigned short c); | 135 | void ShowCharacter(unsigned short c); |
136 | // | 136 | // |
137 | void resizeImage(int new_lines, int new_columns); | 137 | void resizeImage(int new_lines, int new_columns); |
138 | // | 138 | // |
139 | ca* getCookedImage(); | 139 | ca* getCookedImage(); |
140 | 140 | ||
141 | /*! return the number of lines. */ | 141 | /*! return the number of lines. */ |
142 | int getLines() { return lines; } | 142 | int getLines() { return lines; } |
143 | |||
143 | /*! return the number of columns. */ | 144 | /*! return the number of columns. */ |
144 | int getColumns() { return columns; } | 145 | int getColumns() { return columns; } |
145 | 146 | ||
146 | /*! set the position of the history cursor. */ | 147 | /*! set the position of the history cursor. */ |
147 | void setHistCursor(int cursor); | 148 | void setHistCursor(int cursor); |
148 | /*! return the position of the history cursor. */ | 149 | /*! return the position of the history cursor. */ |
149 | int getHistCursor(); | 150 | int getHistCursor(); |
150 | 151 | ||
152 | /*! set the position of the horizontal cursor. */ | ||
153 | void setHorzCursor(int cursor); | ||
154 | /*! return the position of the horizontal cursor. */ | ||
155 | int getHorzCursor(); | ||
156 | |||
151 | int getHistLines (); | 157 | int getHistLines (); |
152 | void setScroll(bool on); | 158 | void setScroll(bool on); |
153 | bool hasScroll(); | 159 | bool hasScroll(); |
154 | 160 | ||
155 | // | 161 | // |
156 | // Selection | 162 | // Selection |
157 | // | 163 | // |
158 | void setSelBeginXY(const int x, const int y); | 164 | void setSelBeginXY(const int x, const int y); |
159 | void setSelExtentXY(const int x, const int y); | 165 | void setSelExtentXY(const int x, const int y); |
160 | void clearSelection(); | 166 | void clearSelection(); |
161 | QString getSelText(const BOOL preserve_line_breaks); | 167 | QString getSelText(const BOOL preserve_line_breaks); |
162 | 168 | ||
163 | void checkSelection(int from, int to); | 169 | void checkSelection(int from, int to); |
164 | 170 | ||
165 | private: // helper | 171 | private: // helper |
166 | 172 | ||
167 | void clearImage(int loca, int loce, char c); | 173 | void clearImage(int loca, int loce, char c); |
168 | void moveImage(int dst, int loca, int loce); | 174 | void moveImage(int dst, int loca, int loce); |
169 | 175 | ||
170 | void scrollUp(int from, int i); | 176 | void scrollUp(int from, int i); |
171 | void scrollDown(int from, int i); | 177 | void scrollDown(int from, int i); |
172 | 178 | ||
173 | void addHistLine(); | 179 | void addHistLine(); |
174 | 180 | ||
175 | void initTabStops(); | 181 | void initTabStops(); |
176 | 182 | ||
177 | void effectiveRendition(); | 183 | void effectiveRendition(); |
178 | void reverseRendition(ca* p); | 184 | void reverseRendition(ca* p); |
179 | 185 | ||
180 | private: | 186 | private: |
181 | 187 | ||
182 | /* | 188 | /* |
183 | The state of the screen is more complex as one would | 189 | The state of the screen is more complex as one would |
184 | expect first. The screem does really do part of the | 190 | expect first. The screem does really do part of the |
185 | emulation providing state informations in form of modes, | 191 | emulation providing state informations in form of modes, |
186 | margins, tabulators, cursor etc. | 192 | margins, tabulators, cursor etc. |
187 | 193 | ||
188 | Even more unexpected are variables to save and restore | 194 | Even more unexpected are variables to save and restore |
189 | parts of the state. | 195 | parts of the state. |
190 | */ | 196 | */ |
191 | 197 | ||
192 | // screen image ---------------- | 198 | // screen image ---------------- |
193 | 199 | ||
194 | int lines; | 200 | int lines; |
195 | int columns; | 201 | int columns; |
196 | ca *image; // [lines][columns] | 202 | ca *image; // [lines][columns] |
197 | 203 | ||
198 | // history buffer --------------- | 204 | // history buffer --------------- |
199 | 205 | ||
200 | int histCursor; // display position relative to start of the history buffer | 206 | int histCursor; // display position relative to start of the history buffer |
201 | HistoryScroll hist; | 207 | HistoryScroll hist; |
208 | |||
209 | int horzCursor; | ||
202 | 210 | ||
203 | // cursor location | 211 | // cursor location |
204 | 212 | ||
205 | int cuX; | 213 | int cuX; |
206 | int cuY; | 214 | int cuY; |
207 | 215 | ||
208 | // cursor color and rendition info | 216 | // cursor color and rendition info |
209 | 217 | ||
210 | UINT8 cu_fg; // foreground | 218 | UINT8 cu_fg; // foreground |
211 | UINT8 cu_bg; // background | 219 | UINT8 cu_bg; // background |
212 | UINT8 cu_re; // rendition | 220 | UINT8 cu_re; // rendition |
213 | 221 | ||
214 | // margins ---------------- | 222 | // margins ---------------- |
215 | 223 | ||
216 | int tmargin; // top margin | 224 | int tmargin; // top margin |
217 | int bmargin; // bottom margin | 225 | int bmargin; // bottom margin |
218 | 226 | ||
219 | // states ---------------- | 227 | // states ---------------- |
220 | 228 | ||
221 | ScreenParm currParm; | 229 | ScreenParm currParm; |
222 | 230 | ||
223 | // ---------------------------- | 231 | // ---------------------------- |
224 | 232 | ||
225 | bool* tabstops; | 233 | bool* tabstops; |
226 | 234 | ||
227 | // selection ------------------- | 235 | // selection ------------------- |
228 | 236 | ||
229 | int sel_begin; // The first location selected. | 237 | int sel_begin; // The first location selected. |
230 | int sel_TL; // TopLeft Location. | 238 | int sel_TL; // TopLeft Location. |
231 | int sel_BR; // Bottom Right Location. | 239 | int sel_BR; // Bottom Right Location. |
232 | 240 | ||
233 | // effective colors and rendition ------------ | 241 | // effective colors and rendition ------------ |
234 | 242 | ||
235 | UINT8 ef_fg; // These are derived from | 243 | UINT8 ef_fg; // These are derived from |
236 | UINT8 ef_bg; // the cu_* variables above | 244 | UINT8 ef_bg; // the cu_* variables above |
237 | UINT8 ef_re; // to speed up operation | 245 | UINT8 ef_re; // to speed up operation |
238 | 246 | ||
239 | // | 247 | // |
240 | // save cursor, rendition & states ------------ | 248 | // save cursor, rendition & states ------------ |
241 | // | 249 | // |
242 | 250 | ||
243 | // cursor location | 251 | // cursor location |
244 | 252 | ||
245 | int sa_cuX; | 253 | int sa_cuX; |
246 | int sa_cuY; | 254 | int sa_cuY; |
247 | 255 | ||
248 | // rendition info | 256 | // rendition info |
249 | 257 | ||
250 | UINT8 sa_cu_re; | 258 | UINT8 sa_cu_re; |
251 | UINT8 sa_cu_fg; | 259 | UINT8 sa_cu_fg; |
252 | UINT8 sa_cu_bg; | 260 | UINT8 sa_cu_bg; |
253 | 261 | ||
254 | // modes | 262 | // modes |
255 | 263 | ||
256 | ScreenParm saveParm; | 264 | ScreenParm saveParm; |
257 | }; | 265 | }; |
258 | 266 | ||
259 | #endif // TESCREEN_H | 267 | #endif // TESCREEN_H |
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp index c10c7a8..60021f4 100644 --- a/core/apps/embeddedkonsole/TEWidget.cpp +++ b/core/apps/embeddedkonsole/TEWidget.cpp | |||
@@ -1,1407 +1,1406 @@ | |||
1 | /* ------------------------------------------------------------------------ */ | 1 | /* ------------------------------------------------------------------------ */ |
2 | /* */ | 2 | /* */ |
3 | /* [TEWidget.C] Terminal Emulation Widget */ | 3 | /* [TEWidget.C] Terminal Emulation Widget */ |
4 | /* */ | 4 | /* */ |
5 | /* ------------------------------------------------------------------------ */ | 5 | /* ------------------------------------------------------------------------ */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* */ | 10 | /* */ |
11 | /* ------------------------------------------------------------------------ */ | 11 | /* ------------------------------------------------------------------------ */ |
12 | /* */ | 12 | /* */ |
13 | /* Ported Konsole to Qt/Embedded */ | 13 | /* Ported Konsole to Qt/Embedded */ |
14 | /* */ | 14 | /* */ |
15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
16 | /* */ | 16 | /* */ |
17 | /* -------------------------------------------------------------------------- */ | 17 | /* -------------------------------------------------------------------------- */ |
18 | /*! \class TEWidget | 18 | /*! \class TEWidget |
19 | 19 | ||
20 | \brief Visible screen contents | 20 | \brief Visible screen contents |
21 | 21 | ||
22 | This class is responsible to map the `image' of a terminal emulation to the | 22 | This class is responsible to map the `image' of a terminal emulation to the |
23 | display. All the dependency of the emulation to a specific GUI or toolkit is | 23 | display. All the dependency of the emulation to a specific GUI or toolkit is |
24 | localized here. Further, this widget has no knowledge about being part of an | 24 | localized here. Further, this widget has no knowledge about being part of an |
25 | emulation, it simply work within the terminal emulation framework by exposing | 25 | emulation, it simply work within the terminal emulation framework by exposing |
26 | size and key events and by being ordered to show a new image. | 26 | size and key events and by being ordered to show a new image. |
27 | 27 | ||
28 | <ul> | 28 | <ul> |
29 | <li> The internal image has the size of the widget (evtl. rounded up) | 29 | <li> The internal image has the size of the widget (evtl. rounded up) |
30 | <li> The external image used in setImage can have any size. | 30 | <li> The external image used in setImage can have any size. |
31 | <li> (internally) the external image is simply copied to the internal | 31 | <li> (internally) the external image is simply copied to the internal |
32 | when a setImage happens. During a resizeEvent no painting is done | 32 | when a setImage happens. During a resizeEvent no painting is done |
33 | a paintEvent is expected to follow anyway. | 33 | a paintEvent is expected to follow anyway. |
34 | </ul> | 34 | </ul> |
35 | 35 | ||
36 | \sa TEScreen \sa Emulation | 36 | \sa TEScreen \sa Emulation |
37 | */ | 37 | */ |
38 | 38 | ||
39 | /* FIXME: | 39 | /* FIXME: |
40 | - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent | 40 | - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent |
41 | - 'font_a' not used in mouse events | 41 | - 'font_a' not used in mouse events |
42 | - add destructor | 42 | - add destructor |
43 | */ | 43 | */ |
44 | 44 | ||
45 | /* TODO | 45 | /* TODO |
46 | - evtl. be sensitive to `paletteChange' while using default colors. | 46 | - evtl. be sensitive to `paletteChange' while using default colors. |
47 | - set different 'rounding' styles? I.e. have a mode to show clipped chars? | 47 | - set different 'rounding' styles? I.e. have a mode to show clipped chars? |
48 | */ | 48 | */ |
49 | 49 | ||
50 | // #include "config.h" | 50 | // #include "config.h" |
51 | #include "TEWidget.h" | 51 | #include "TEWidget.h" |
52 | #include "session.h" | 52 | #include "session.h" |
53 | #include <qpe/config.h> | 53 | #include <qpe/config.h> |
54 | 54 | ||
55 | #include <qpe/resource.h> | 55 | #include <qpe/resource.h> |
56 | #include <qpe/sound.h> | 56 | #include <qpe/sound.h> |
57 | 57 | ||
58 | #ifdef QWS | 58 | #ifdef QWS |
59 | #include <qpe/qcopenvelope_qws.h> | 59 | #include <qpe/qcopenvelope_qws.h> |
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | #include <qcursor.h> | 62 | #include <qcursor.h> |
63 | #include <qregexp.h> | 63 | #include <qregexp.h> |
64 | #include <qpainter.h> | 64 | #include <qpainter.h> |
65 | #include <qclipboard.h> | 65 | #include <qclipboard.h> |
66 | #include <qstyle.h> | 66 | #include <qstyle.h> |
67 | #include <qfile.h> | 67 | #include <qfile.h> |
68 | #include <qdragobject.h> | 68 | #include <qdragobject.h> |
69 | 69 | ||
70 | #include <stdio.h> | 70 | #include <stdio.h> |
71 | #include <stdlib.h> | 71 | #include <stdlib.h> |
72 | #include <unistd.h> | 72 | #include <unistd.h> |
73 | #include <ctype.h> | 73 | #include <ctype.h> |
74 | #include <sys/stat.h> | 74 | #include <sys/stat.h> |
75 | #include <sys/types.h> | 75 | #include <sys/types.h> |
76 | #include <signal.h> | 76 | #include <signal.h> |
77 | 77 | ||
78 | #include <assert.h> | 78 | #include <assert.h> |
79 | 79 | ||
80 | // #include "TEWidget.moc" | 80 | // #include "TEWidget.moc" |
81 | //#include <kapp.h> | 81 | //#include <kapp.h> |
82 | //#include <kcursor.h> | 82 | //#include <kcursor.h> |
83 | //#include <kurl.h> | 83 | //#include <kurl.h> |
84 | //#include <kdebug.h> | 84 | //#include <kdebug.h> |
85 | //#include <klocale.h> | 85 | //#include <klocale.h> |
86 | 86 | ||
87 | #define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) | 87 | #define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) |
88 | #define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } | 88 | #define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } |
89 | 89 | ||
90 | #define loc(X,Y) ((Y)*columns+(X)) | 90 | #define loc(X,Y) ((Y)*columns+(X)) |
91 | 91 | ||
92 | //FIXME: the rim should normally be 1, 0 only when running in full screen mode. | 92 | //FIXME: the rim should normally be 1, 0 only when running in full screen mode. |
93 | #define rimX 0 // left/right rim width | 93 | #define rimX 0 // left/right rim width |
94 | #define rimY 0 // top/bottom rim high | 94 | #define rimY 0 // top/bottom rim high |
95 | 95 | ||
96 | #define SCRWIDTH 16 // width of the scrollbar | 96 | #define SCRWIDTH 16 // width of the scrollbar |
97 | 97 | ||
98 | #define yMouseScroll 1 | 98 | #define yMouseScroll 1 |
99 | // scroll increment used when dragging selection at top/bottom of window. | 99 | // scroll increment used when dragging selection at top/bottom of window. |
100 | 100 | ||
101 | /* ------------------------------------------------------------------------- */ | 101 | /* ------------------------------------------------------------------------- */ |
102 | /* */ | 102 | /* */ |
103 | /* Colors */ | 103 | /* Colors */ |
104 | /* */ | 104 | /* */ |
105 | /* ------------------------------------------------------------------------- */ | 105 | /* ------------------------------------------------------------------------- */ |
106 | 106 | ||
107 | //FIXME: the default color table is in session.C now. | 107 | //FIXME: the default color table is in session.C now. |
108 | // We need a way to get rid of this one, here. | 108 | // We need a way to get rid of this one, here. |
109 | static const ColorEntry base_color_table[TABLE_COLORS] = | 109 | static const ColorEntry base_color_table[TABLE_COLORS] = |
110 | // The following are almost IBM standard color codes, with some slight | 110 | // The following are almost IBM standard color codes, with some slight |
111 | // gamma correction for the dim colors to compensate for bright X screens. | 111 | // gamma correction for the dim colors to compensate for bright X screens. |
112 | // It contains the 8 ansiterm/xterm colors in 2 intensities. | 112 | // It contains the 8 ansiterm/xterm colors in 2 intensities. |
113 | { | 113 | { |
114 | // Fixme: could add faint colors here, also. | 114 | // Fixme: could add faint colors here, also. |
115 | // normal | 115 | // normal |
116 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback | 116 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback |
117 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red | 117 | ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red |
118 | ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow | 118 | ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow |
119 | ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta | 119 | ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta |
120 | ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White | 120 | ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White |
121 | // intensiv | 121 | // intensiv |
122 | ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), | 122 | ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), |
123 | ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), | 123 | ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), |
124 | ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), | 124 | ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), |
125 | ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), | 125 | ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), |
126 | ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) | 126 | ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) |
127 | }; | 127 | }; |
128 | 128 | ||
129 | /* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) | 129 | /* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) |
130 | 130 | ||
131 | Code 0 1 2 3 4 5 6 7 | 131 | Code 0 1 2 3 4 5 6 7 |
132 | ----------- ------- ------- ------- ------- ------- ------- ------- ------- | 132 | ----------- ------- ------- ------- ------- ------- ------- ------- ------- |
133 | ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White | 133 | ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White |
134 | IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White | 134 | IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White |
135 | */ | 135 | */ |
136 | 136 | ||
137 | QColor TEWidget::getDefaultBackColor() | 137 | QColor TEWidget::getDefaultBackColor() |
138 | { | 138 | { |
139 | return color_table[DEFAULT_BACK_COLOR].color; | 139 | return color_table[DEFAULT_BACK_COLOR].color; |
140 | } | 140 | } |
141 | 141 | ||
142 | const ColorEntry* TEWidget::getColorTable() const | 142 | const ColorEntry* TEWidget::getColorTable() const |
143 | { | 143 | { |
144 | return color_table; | 144 | return color_table; |
145 | } | 145 | } |
146 | 146 | ||
147 | const ColorEntry* TEWidget::getdefaultColorTable() const | 147 | const ColorEntry* TEWidget::getdefaultColorTable() const |
148 | { | 148 | { |
149 | return base_color_table; | 149 | return base_color_table; |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | ||
153 | const QPixmap *TEWidget::backgroundPixmap() | 153 | const QPixmap *TEWidget::backgroundPixmap() |
154 | { | 154 | { |
155 | static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); | 155 | static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); |
156 | const QPixmap *pm = bg; | 156 | const QPixmap *pm = bg; |
157 | return pm; | 157 | return pm; |
158 | } | 158 | } |
159 | 159 | ||
160 | void TEWidget::setColorTable(const ColorEntry table[]) | 160 | void TEWidget::setColorTable(const ColorEntry table[]) |
161 | { | 161 | { |
162 | for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; | 162 | for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; |
163 | 163 | ||
164 | const QPixmap* pm = backgroundPixmap(); | 164 | const QPixmap* pm = backgroundPixmap(); |
165 | if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); | 165 | if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); |
166 | update(); | 166 | update(); |
167 | } | 167 | } |
168 | 168 | ||
169 | //FIXME: add backgroundPixmapChanged. | 169 | //FIXME: add backgroundPixmapChanged. |
170 | 170 | ||
171 | /* ------------------------------------------------------------------------- */ | 171 | /* ------------------------------------------------------------------------- */ |
172 | /* */ | 172 | /* */ |
173 | /* Font */ | 173 | /* Font */ |
174 | /* */ | 174 | /* */ |
175 | /* ------------------------------------------------------------------------- */ | 175 | /* ------------------------------------------------------------------------- */ |
176 | 176 | ||
177 | /* | 177 | /* |
178 | The VT100 has 32 special graphical characters. The usual vt100 extended | 178 | The VT100 has 32 special graphical characters. The usual vt100 extended |
179 | xterm fonts have these at 0x00..0x1f. | 179 | xterm fonts have these at 0x00..0x1f. |
180 | 180 | ||
181 | QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals | 181 | QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals |
182 | come in here as proper unicode characters. | 182 | come in here as proper unicode characters. |
183 | 183 | ||
184 | We treat non-iso10646 fonts as VT100 extended and do the requiered mapping | 184 | We treat non-iso10646 fonts as VT100 extended and do the requiered mapping |
185 | from unicode to 0x00..0x1f. The remaining translation is then left to the | 185 | from unicode to 0x00..0x1f. The remaining translation is then left to the |
186 | QCodec. | 186 | QCodec. |
187 | */ | 187 | */ |
188 | 188 | ||
189 | // assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. | 189 | // assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. |
190 | 190 | ||
191 | unsigned short vt100_graphics[32] = | 191 | unsigned short vt100_graphics[32] = |
192 | { // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 | 192 | { // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 |
193 | 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, | 193 | 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, |
194 | 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, | 194 | 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, |
195 | 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, | 195 | 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, |
196 | 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 | 196 | 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 |
197 | }; | 197 | }; |
198 | 198 | ||
199 | static QChar vt100extended(QChar c) | 199 | static QChar vt100extended(QChar c) |
200 | { | 200 | { |
201 | switch (c.unicode()) | 201 | switch (c.unicode()) |
202 | { | 202 | { |
203 | case 0x25c6 : return 1; | 203 | case 0x25c6 : return 1; |
204 | case 0x2592 : return 2; | 204 | case 0x2592 : return 2; |
205 | case 0x2409 : return 3; | 205 | case 0x2409 : return 3; |
206 | case 0x240c : return 4; | 206 | case 0x240c : return 4; |
207 | case 0x240d : return 5; | 207 | case 0x240d : return 5; |
208 | case 0x240a : return 6; | 208 | case 0x240a : return 6; |
209 | case 0x00b0 : return 7; | 209 | case 0x00b0 : return 7; |
210 | case 0x00b1 : return 8; | 210 | case 0x00b1 : return 8; |
211 | case 0x2424 : return 9; | 211 | case 0x2424 : return 9; |
212 | case 0x240b : return 10; | 212 | case 0x240b : return 10; |
213 | case 0x2518 : return 11; | 213 | case 0x2518 : return 11; |
214 | case 0x2510 : return 12; | 214 | case 0x2510 : return 12; |
215 | case 0x250c : return 13; | 215 | case 0x250c : return 13; |
216 | case 0x2514 : return 14; | 216 | case 0x2514 : return 14; |
217 | case 0x253c : return 15; | 217 | case 0x253c : return 15; |
218 | case 0xf800 : return 16; | 218 | case 0xf800 : return 16; |
219 | case 0xf801 : return 17; | 219 | case 0xf801 : return 17; |
220 | case 0x2500 : return 18; | 220 | case 0x2500 : return 18; |
221 | case 0xf803 : return 19; | 221 | case 0xf803 : return 19; |
222 | case 0xf804 : return 20; | 222 | case 0xf804 : return 20; |
223 | case 0x251c : return 21; | 223 | case 0x251c : return 21; |
224 | case 0x2524 : return 22; | 224 | case 0x2524 : return 22; |
225 | case 0x2534 : return 23; | 225 | case 0x2534 : return 23; |
226 | case 0x252c : return 24; | 226 | case 0x252c : return 24; |
227 | case 0x2502 : return 25; | 227 | case 0x2502 : return 25; |
228 | case 0x2264 : return 26; | 228 | case 0x2264 : return 26; |
229 | case 0x2265 : return 27; | 229 | case 0x2265 : return 27; |
230 | case 0x03c0 : return 28; | 230 | case 0x03c0 : return 28; |
231 | case 0x2260 : return 29; | 231 | case 0x2260 : return 29; |
232 | case 0x00a3 : return 30; | 232 | case 0x00a3 : return 30; |
233 | case 0x00b7 : return 31; | 233 | case 0x00b7 : return 31; |
234 | } | 234 | } |
235 | return c; | 235 | return c; |
236 | } | 236 | } |
237 | 237 | ||
238 | static QChar identicalMap(QChar c) | 238 | static QChar identicalMap(QChar c) |
239 | { | 239 | { |
240 | return c; | 240 | return c; |
241 | } | 241 | } |
242 | 242 | ||
243 | void TEWidget::fontChange(const QFont &) | 243 | void TEWidget::fontChange(const QFont &) |
244 | { | 244 | { |
245 | QFontMetrics fm(font()); | 245 | QFontMetrics fm(font()); |
246 | font_h = fm.height(); | 246 | font_h = fm.height(); |
247 | font_w = fm.maxWidth(); | 247 | font_w = fm.maxWidth(); |
248 | font_a = fm.ascent(); | 248 | font_a = fm.ascent(); |
249 | //printf("font_h: %d\n",font_h); | 249 | //printf("font_h: %d\n",font_h); |
250 | //printf("font_w: %d\n",font_w); | 250 | //printf("font_w: %d\n",font_w); |
251 | //printf("font_a: %d\n",font_a); | 251 | //printf("font_a: %d\n",font_a); |
252 | //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); | 252 | //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); |
253 | //printf("rawname: %s\n",font().rawName().ascii()); | 253 | //printf("rawname: %s\n",font().rawName().ascii()); |
254 | fontMap = | 254 | fontMap = |
255 | #if QT_VERSION < 300 | 255 | #if QT_VERSION < 300 |
256 | strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") | 256 | strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") |
257 | ? vt100extended | 257 | ? vt100extended |
258 | : | 258 | : |
259 | #endif | 259 | #endif |
260 | identicalMap; | 260 | identicalMap; |
261 | propagateSize(); | 261 | propagateSize(); |
262 | update(); | 262 | update(); |
263 | } | 263 | } |
264 | 264 | ||
265 | void TEWidget::setVTFont(const QFont& f) | 265 | void TEWidget::setVTFont(const QFont& f) |
266 | { | 266 | { |
267 | QFrame::setFont(f); | 267 | QFrame::setFont(f); |
268 | } | 268 | } |
269 | 269 | ||
270 | QFont TEWidget::getVTFont() { | 270 | QFont TEWidget::getVTFont() { |
271 | return font(); | 271 | return font(); |
272 | } | 272 | } |
273 | 273 | ||
274 | void TEWidget::setFont(const QFont &) | 274 | void TEWidget::setFont(const QFont &) |
275 | { | 275 | { |
276 | // ignore font change request if not coming from konsole itself | 276 | // ignore font change request if not coming from konsole itself |
277 | } | 277 | } |
278 | 278 | ||
279 | /* ------------------------------------------------------------------------- */ | 279 | /* ------------------------------------------------------------------------- */ |
280 | /* */ | 280 | /* */ |
281 | /* Constructor / Destructor */ | 281 | /* Constructor / Destructor */ |
282 | /* */ | 282 | /* */ |
283 | /* ------------------------------------------------------------------------- */ | 283 | /* ------------------------------------------------------------------------- */ |
284 | 284 | ||
285 | TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) | 285 | TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) |
286 | { | 286 | { |
287 | #ifndef QT_NO_CLIPBOARD | 287 | #ifndef QT_NO_CLIPBOARD |
288 | cb = QApplication::clipboard(); | 288 | cb = QApplication::clipboard(); |
289 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), | 289 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), |
290 | this, SLOT(onClearSelection()) ); | 290 | this, SLOT(onClearSelection()) ); |
291 | #endif | 291 | #endif |
292 | 292 | ||
293 | scrollbar = new QScrollBar(this); | 293 | scrollbar = new QScrollBar(this); |
294 | scrollbar->setCursor( arrowCursor ); | 294 | scrollbar->setCursor( arrowCursor ); |
295 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 295 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
296 | 296 | ||
297 | hScrollbar = new QScrollBar(this); | 297 | hScrollbar = new QScrollBar(this); |
298 | hScrollbar->setCursor( arrowCursor ); | 298 | hScrollbar->setCursor( arrowCursor ); |
299 | hScrollbar->setOrientation(QScrollBar::Horizontal); | 299 | hScrollbar->setOrientation(QScrollBar::Horizontal); |
300 | hScrollbar->setMaximumHeight(16); | 300 | hScrollbar->setMaximumHeight(16); |
301 | 301 | ||
302 | connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); | 302 | connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); |
303 | 303 | ||
304 | Config cfg("Konsole"); | 304 | Config cfg("Konsole"); |
305 | cfg.setGroup("ScrollBar"); | 305 | cfg.setGroup("ScrollBar"); |
306 | switch( cfg.readNumEntry("Position",2)){ | 306 | switch( cfg.readNumEntry("Position",2)){ |
307 | case 0: | 307 | case 0: |
308 | scrollLoc = SCRNONE; | 308 | scrollLoc = SCRNONE; |
309 | break; | 309 | break; |
310 | case 1: | 310 | case 1: |
311 | scrollLoc = SCRLEFT; | 311 | scrollLoc = SCRLEFT; |
312 | break; | 312 | break; |
313 | case 2: | 313 | case 2: |
314 | scrollLoc = SCRRIGHT; | 314 | scrollLoc = SCRRIGHT; |
315 | break; | 315 | break; |
316 | }; | 316 | }; |
317 | 317 | ||
318 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); | 318 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); |
319 | 319 | ||
320 | blinkT = new QTimer(this); | 320 | blinkT = new QTimer(this); |
321 | connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); | 321 | connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); |
322 | // blinking = FALSE; | 322 | // blinking = FALSE; |
323 | blinking = TRUE; | 323 | blinking = TRUE; |
324 | 324 | ||
325 | resizing = FALSE; | 325 | resizing = FALSE; |
326 | actSel = 0; | 326 | actSel = 0; |
327 | image = 0; | 327 | image = 0; |
328 | lines = 1; | 328 | lines = 1; |
329 | columns = 1; | 329 | columns = 1; |
330 | font_w = 1; | 330 | font_w = 1; |
331 | font_h = 1; | 331 | font_h = 1; |
332 | font_a = 1; | 332 | font_a = 1; |
333 | word_selection_mode = FALSE; | 333 | word_selection_mode = FALSE; |
334 | hposition = 0; | 334 | hposition = 0; |
335 | 335 | vcolumns = 0; | |
336 | |||
336 | setMouseMarks(TRUE); | 337 | setMouseMarks(TRUE); |
337 | setVTFont( QFont("fixed") ); | 338 | setVTFont( QFont("fixed") ); |
338 | setColorTable(base_color_table); // init color table | 339 | setColorTable(base_color_table); // init color table |
339 | 340 | ||
340 | qApp->installEventFilter( this ); //FIXME: see below | 341 | qApp->installEventFilter( this ); //FIXME: see below |
341 | // KCursor::setAutoHideCursor( this, true ); | 342 | // KCursor::setAutoHideCursor( this, true ); |
342 | 343 | ||
343 | // Init DnD //////////////////////////////////////////////////////////////// | 344 | // Init DnD //////////////////////////////////////////////////////////////// |
344 | currentSession = NULL; | 345 | currentSession = NULL; |
345 | // setAcceptDrops(true); // attempt | 346 | // setAcceptDrops(true); // attempt |
346 | // m_drop = new QPopupMenu(this); | 347 | // m_drop = new QPopupMenu(this); |
347 | // m_drop->insertItem( QString("Paste"), 0); | 348 | // m_drop->insertItem( QString("Paste"), 0); |
348 | // m_drop->insertItem( QString("cd"), 1); | 349 | // m_drop->insertItem( QString("cd"), 1); |
349 | // connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); | 350 | // connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); |
350 | 351 | ||
351 | // we need focus so that the auto-hide cursor feature works | 352 | // we need focus so that the auto-hide cursor feature works |
352 | setFocus(); | 353 | setFocus(); |
353 | setFocusPolicy( WheelFocus ); | 354 | setFocusPolicy( WheelFocus ); |
354 | } | 355 | } |
355 | 356 | ||
356 | //FIXME: make proper destructor | 357 | //FIXME: make proper destructor |
357 | // Here's a start (David) | 358 | // Here's a start (David) |
358 | TEWidget::~TEWidget() | 359 | TEWidget::~TEWidget() |
359 | { | 360 | { |
360 | qApp->removeEventFilter( this ); | 361 | qApp->removeEventFilter( this ); |
361 | if (image) free(image); | 362 | if (image) free(image); |
362 | } | 363 | } |
363 | 364 | ||
364 | /* ------------------------------------------------------------------------- */ | 365 | /* ------------------------------------------------------------------------- */ |
365 | /* */ | 366 | /* */ |
366 | /* Display Operations */ | 367 | /* Display Operations */ |
367 | /* */ | 368 | /* */ |
368 | /* ------------------------------------------------------------------------- */ | 369 | /* ------------------------------------------------------------------------- */ |
369 | 370 | ||
370 | /*! | 371 | /*! |
371 | attributed string draw primitive | 372 | attributed string draw primitive |
372 | */ | 373 | */ |
373 | 374 | ||
374 | void TEWidget::drawAttrStr(QPainter &paint, QRect rect, | 375 | void TEWidget::drawAttrStr(QPainter &paint, QRect rect, |
375 | QString& str, ca attr, BOOL pm, BOOL clear) | 376 | QString& str, ca attr, BOOL pm, BOOL clear) |
376 | { | 377 | { |
377 | if (pm && color_table[attr.b].transparent) | 378 | if (pm && color_table[attr.b].transparent) |
378 | { | 379 | { |
379 | paint.setBackgroundMode( TransparentMode ); | 380 | paint.setBackgroundMode( TransparentMode ); |
380 | if (clear) erase(rect); | 381 | if (clear) erase(rect); |
381 | } | 382 | } |
382 | else | 383 | else |
383 | { | 384 | { |
384 | if (blinking) | 385 | if (blinking) |
385 | paint.fillRect(rect, color_table[attr.b].color); | 386 | paint.fillRect(rect, color_table[attr.b].color); |
386 | else | 387 | else |
387 | { | 388 | { |
388 | paint.setBackgroundMode( OpaqueMode ); | 389 | paint.setBackgroundMode( OpaqueMode ); |
389 | paint.setBackgroundColor( color_table[attr.b].color ); | 390 | paint.setBackgroundColor( color_table[attr.b].color ); |
390 | } | 391 | } |
391 | } | 392 | } |
392 | 393 | ||
393 | if (color_table[attr.f].bold) | 394 | if (color_table[attr.f].bold) |
394 | paint.setPen(QColor( 0x8F, 0x00, 0x00 )); | 395 | paint.setPen(QColor( 0x8F, 0x00, 0x00 )); |
395 | else | 396 | else |
396 | paint.setPen(color_table[attr.f].color); | 397 | paint.setPen(color_table[attr.f].color); |
397 | 398 | ||
398 | paint.drawText(rect.x(),rect.y()+font_a, str); | 399 | paint.drawText(rect.x(),rect.y()+font_a, str); |
399 | 400 | ||
400 | if (attr.r & RE_UNDERLINE) | 401 | if (attr.r & RE_UNDERLINE) |
401 | paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); | 402 | paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); |
402 | } | 403 | } |
403 | 404 | ||
404 | /*! | 405 | /*! |
405 | The image can only be set completely. | 406 | The image can only be set completely. |
406 | 407 | ||
407 | The size of the new image may or may not match the size of the widget. | 408 | The size of the new image may or may not match the size of the widget. |
408 | */ | 409 | */ |
409 | 410 | ||
410 | void TEWidget::setImage(const ca* const newimg, int lines, int columns) | 411 | void TEWidget::setImage(const ca* const newimg, int lines, int columns) |
411 | { int y,x,len; | 412 | { int y,x,len; |
412 | const QPixmap* pm = backgroundPixmap(); | 413 | const QPixmap* pm = backgroundPixmap(); |
413 | QPainter paint; | 414 | QPainter paint; |
414 | setUpdatesEnabled(FALSE); | 415 | setUpdatesEnabled(FALSE); |
415 | paint.begin( this ); | 416 | paint.begin( this ); |
416 | HCNT("setImage"); | 417 | HCNT("setImage"); |
417 | 418 | ||
418 | QPoint tL = contentsRect().topLeft(); | 419 | QPoint tL = contentsRect().topLeft(); |
419 | int tLx = tL.x(); | 420 | int tLx = tL.x(); |
420 | int tLy = tL.y(); | 421 | int tLy = tL.y(); |
421 | hasBlinker = FALSE; | 422 | hasBlinker = FALSE; |
422 | 423 | ||
423 | int cf = -1; // undefined | 424 | int cf = -1; // undefined |
424 | int cb = -1; // undefined | 425 | int cb = -1; // undefined |
425 | int cr = -1; // undefined | 426 | int cr = -1; // undefined |
426 | 427 | ||
427 | int lins = QMIN(this->lines, QMAX(0,lines )); | 428 | int lins = QMIN(this->lines, QMAX(0,lines )); |
428 | int cols = QMIN(this->columns,QMAX(0,columns)); | 429 | int cols = QMIN(this->columns,QMAX(0,columns)); |
429 | QChar *disstrU = new QChar[cols]; | 430 | QChar *disstrU = new QChar[cols]; |
430 | for (y = 0; y < lins; y++) { | 431 | for (y = 0; y < lins; y++) { |
431 | const ca* lcl = &image[y*this->columns]; | 432 | const ca* lcl = &image[y*this->columns]; |
432 | const ca* const ext = &newimg[y*columns]; | 433 | const ca* const ext = &newimg[y*columns]; |
433 | if (!resizing) // not while resizing, we're expecting a paintEvent | 434 | if (!resizing) // not while resizing, we're expecting a paintEvent |
434 | for (x = 0; x < cols; x++) | 435 | for (x = 0; x < cols; x++) |
435 | { | 436 | { |
436 | hasBlinker |= (ext[x].r & RE_BLINK); | 437 | hasBlinker |= (ext[x].r & RE_BLINK); |
437 | if (ext[x] != lcl[x]) | 438 | if (ext[x] != lcl[x]) |
438 | { | 439 | { |
439 | cr = ext[x].r; | 440 | cr = ext[x].r; |
440 | cb = ext[x].b; | 441 | cb = ext[x].b; |
441 | if (ext[x].f != cf) cf = ext[x].f; | 442 | if (ext[x].f != cf) cf = ext[x].f; |
442 | int lln = cols - x; | 443 | int lln = cols - x; |
443 | disstrU[0] = fontMap(ext[x+0].c); | 444 | disstrU[0] = fontMap(ext[x+0].c); |
444 | for (len = 1; len < lln; len++) | 445 | for (len = 1; len < lln; len++) |
445 | { | 446 | { |
446 | if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || | 447 | if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || |
447 | ext[x+len] == lcl[x+len] ) | 448 | ext[x+len] == lcl[x+len] ) |
448 | break; | 449 | break; |
449 | disstrU[len] = fontMap(ext[x+len].c); | 450 | disstrU[len] = fontMap(ext[x+len].c); |
450 | } | 451 | } |
451 | QString unistr(disstrU,len); | 452 | QString unistr(disstrU,len); |
452 | drawAttrStr(paint, | 453 | drawAttrStr(paint, |
453 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), | 454 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), |
454 | unistr, ext[x], pm != NULL, true); | 455 | unistr, ext[x], pm != NULL, true); |
455 | x += len - 1; | 456 | x += len - 1; |
456 | } | 457 | } |
457 | } | 458 | } |
458 | // finally, make `image' become `newimg'. | 459 | // finally, make `image' become `newimg'. |
459 | memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); | 460 | memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); |
460 | } | 461 | } |
461 | drawFrame( &paint ); | 462 | drawFrame( &paint ); |
462 | paint.end(); | 463 | paint.end(); |
463 | setUpdatesEnabled(TRUE); | 464 | setUpdatesEnabled(TRUE); |
464 | if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms | 465 | if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms |
465 | if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } | 466 | if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } |
466 | delete [] disstrU; | 467 | delete [] disstrU; |
467 | } | 468 | } |
468 | 469 | ||
469 | // paint Event //////////////////////////////////////////////////// | 470 | // paint Event //////////////////////////////////////////////////// |
470 | 471 | ||
471 | /*! | 472 | /*! |
472 | The difference of this routine vs. the `setImage' is, | 473 | The difference of this routine vs. the `setImage' is, |
473 | that the drawing does not include a difference analysis | 474 | that the drawing does not include a difference analysis |
474 | between the old and the new image. Instead, the internal | 475 | between the old and the new image. Instead, the internal |
475 | image is used and the painting bound by the PaintEvent box. | 476 | image is used and the painting bound by the PaintEvent box. |
476 | */ | 477 | */ |
477 | 478 | ||
478 | void TEWidget::paintEvent( QPaintEvent* pe ) | 479 | void TEWidget::paintEvent( QPaintEvent* pe ) |
479 | { | 480 | { |
480 | 481 | ||
481 | //{ static int cnt = 0; printf("paint %d\n",cnt++); } | 482 | //{ static int cnt = 0; printf("paint %d\n",cnt++); } |
482 | const QPixmap* pm = backgroundPixmap(); | 483 | const QPixmap* pm = backgroundPixmap(); |
483 | QPainter paint; | 484 | QPainter paint; |
484 | setUpdatesEnabled(FALSE); | 485 | setUpdatesEnabled(FALSE); |
485 | paint.begin( this ); | 486 | paint.begin( this ); |
486 | paint.setBackgroundMode( TransparentMode ); | 487 | paint.setBackgroundMode( TransparentMode ); |
487 | HCNT("paintEvent"); | 488 | HCNT("paintEvent"); |
488 | 489 | ||
489 | // Note that the actual widget size can be slightly larger | 490 | // Note that the actual widget size can be slightly larger |
490 | // that the image (the size is truncated towards the smaller | 491 | // that the image (the size is truncated towards the smaller |
491 | // number of characters in `resizeEvent'. The paint rectangle | 492 | // number of characters in `resizeEvent'. The paint rectangle |
492 | // can thus be larger than the image, but less then the size | 493 | // can thus be larger than the image, but less then the size |
493 | // of one character. | 494 | // of one character. |
494 | 495 | ||
495 | QRect rect = pe->rect().intersect(contentsRect()); | 496 | QRect rect = pe->rect().intersect(contentsRect()); |
496 | 497 | ||
497 | QPoint tL = contentsRect().topLeft(); | 498 | QPoint tL = contentsRect().topLeft(); |
498 | int tLx = tL.x(); | 499 | int tLx = tL.x(); |
499 | int tLy = tL.y(); | 500 | int tLy = tL.y(); |
500 | 501 | ||
501 | int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); | 502 | int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); |
502 | int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); | 503 | int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); |
503 | int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); | 504 | int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); |
504 | int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); | 505 | int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); |
505 | 506 | ||
506 | /* | 507 | /* |
507 | printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, | 508 | printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, |
508 | rect.left(), rect.right(), rect.top(), rect.bottom()); | 509 | rect.left(), rect.right(), rect.top(), rect.bottom()); |
509 | */ | 510 | */ |
510 | 511 | ||
511 | // if (pm != NULL && color_table[image->b].transparent) | 512 | // if (pm != NULL && color_table[image->b].transparent) |
512 | // erase(rect); | 513 | // erase(rect); |
513 | // BL: I have no idea why we need this, and it breaks the refresh. | 514 | // BL: I have no idea why we need this, and it breaks the refresh. |
514 | 515 | ||
515 | QChar *disstrU = new QChar[columns]; | 516 | QChar *disstrU = new QChar[columns]; |
516 | for (int y = luy; y <= rly; y++) | 517 | for (int y = luy; y <= rly; y++) |
517 | for (int x = lux; x <= rlx; x++) | 518 | for (int x = lux; x <= rlx; x++) |
518 | { | 519 | { |
519 | int len = 1; | 520 | int len = 1; |
520 | disstrU[0] = fontMap(image[loc(x,y)].c); | 521 | disstrU[0] = fontMap(image[loc(x,y)].c); |
521 | int cf = image[loc(x,y)].f; | 522 | int cf = image[loc(x,y)].f; |
522 | int cb = image[loc(x,y)].b; | 523 | int cb = image[loc(x,y)].b; |
523 | int cr = image[loc(x,y)].r; | 524 | int cr = image[loc(x,y)].r; |
524 | while (x+len <= rlx && | 525 | while (x+len <= rlx && |
525 | image[loc(x+len,y)].f == cf && | 526 | image[loc(x+len,y)].f == cf && |
526 | image[loc(x+len,y)].b == cb && | 527 | image[loc(x+len,y)].b == cb && |
527 | image[loc(x+len,y)].r == cr ) | 528 | image[loc(x+len,y)].r == cr ) |
528 | { | 529 | { |
529 | disstrU[len] = fontMap(image[loc(x+len,y)].c); | 530 | disstrU[len] = fontMap(image[loc(x+len,y)].c); |
530 | len += 1; | 531 | len += 1; |
531 | } | 532 | } |
532 | QString unistr(disstrU,len); | 533 | QString unistr(disstrU,len); |
533 | drawAttrStr(paint, | 534 | drawAttrStr(paint, |
534 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), | 535 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), |
535 | unistr, image[loc(x,y)], pm != NULL, false); | 536 | unistr, image[loc(x,y)], pm != NULL, false); |
536 | x += len - 1; | 537 | x += len - 1; |
537 | } | 538 | } |
538 | delete [] disstrU; | 539 | delete [] disstrU; |
539 | drawFrame( &paint ); | 540 | drawFrame( &paint ); |
540 | paint.end(); | 541 | paint.end(); |
541 | setUpdatesEnabled(TRUE); | 542 | setUpdatesEnabled(TRUE); |
542 | } | 543 | } |
543 | 544 | ||
544 | void TEWidget::blinkEvent() | 545 | void TEWidget::blinkEvent() |
545 | { | 546 | { |
546 | blinking = !blinking; | 547 | blinking = !blinking; |
547 | repaint(FALSE); | 548 | repaint(FALSE); |
548 | } | 549 | } |
549 | 550 | ||
550 | /* ------------------------------------------------------------------------- */ | 551 | /* ------------------------------------------------------------------------- */ |
551 | /* */ | 552 | /* */ |
552 | /* Resizing */ | 553 | /* Resizing */ |
553 | /* */ | 554 | /* */ |
554 | /* ------------------------------------------------------------------------- */ | 555 | /* ------------------------------------------------------------------------- */ |
555 | 556 | ||
556 | void TEWidget::resizeEvent(QResizeEvent* ev) | 557 | void TEWidget::resizeEvent(QResizeEvent* ev) |
557 | { | 558 | { |
558 | // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); | 559 | // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); |
559 | //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); | 560 | //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); |
560 | //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); | 561 | //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); |
561 | //printf("curren: %d,%d\n",width(),height()); | 562 | //printf("curren: %d,%d\n",width(),height()); |
562 | HCNT("resizeEvent"); | 563 | HCNT("resizeEvent"); |
563 | 564 | ||
564 | // see comment in `paintEvent' concerning the rounding. | 565 | // see comment in `paintEvent' concerning the rounding. |
565 | //FIXME: could make a routine here; check width(),height() | 566 | //FIXME: could make a routine here; check width(),height() |
566 | assert(ev->size().width() == width()); | 567 | assert(ev->size().width() == width()); |
567 | assert(ev->size().height() == height()); | 568 | assert(ev->size().height() == height()); |
568 | 569 | ||
569 | propagateSize(); | 570 | propagateSize(); |
570 | } | 571 | } |
571 | 572 | ||
572 | void TEWidget::propagateSize() | 573 | void TEWidget::propagateSize() |
573 | { | 574 | { |
574 | ca* oldimg = image; | 575 | ca* oldimg = image; |
575 | int oldlin = lines; | 576 | int oldlin = lines; |
576 | int oldcol = columns; | 577 | int oldcol = columns; |
577 | makeImage(); | 578 | makeImage(); |
578 | // we copy the old image to reduce flicker | 579 | // we copy the old image to reduce flicker |
579 | int lins = QMIN(oldlin,lines); | 580 | int lins = QMIN(oldlin,lines); |
580 | int cols = QMIN(oldcol,columns); | 581 | int cols = QMIN(oldcol,columns); |
581 | if (oldimg) | 582 | if (oldimg) |
582 | { | 583 | { |
583 | for (int lin = 0; lin < lins; lin++) | 584 | for (int lin = 0; lin < lins; lin++) |
584 | memcpy((void*)&image[columns*lin], | 585 | memcpy((void*)&image[columns*lin], |
585 | (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); | 586 | (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); |
586 | free(oldimg); //FIXME: try new,delete | 587 | free(oldimg); //FIXME: try new,delete |
587 | } | 588 | } |
588 | else | 589 | else |
589 | clearImage(); | 590 | clearImage(); |
590 | 591 | ||
591 | //NOTE: control flows from the back through the chest right into the eye. | 592 | //NOTE: control flows from the back through the chest right into the eye. |
592 | // `emu' will call back via `setImage'. | 593 | // `emu' will call back via `setImage'. |
593 | 594 | ||
594 | resizing = TRUE; | 595 | resizing = TRUE; |
595 | emit changedImageSizeSignal(lines, columns); // expose resizeEvent | 596 | emit changedImageSizeSignal(lines, columns); // expose resizeEvent |
596 | resizing = FALSE; | 597 | resizing = FALSE; |
597 | } | 598 | } |
598 | 599 | ||
599 | /* ------------------------------------------------------------------------- */ | 600 | /* ------------------------------------------------------------------------- */ |
600 | /* */ | 601 | /* */ |
601 | /* Scrollbar */ | 602 | /* Scrollbar */ |
602 | /* */ | 603 | /* */ |
603 | /* ------------------------------------------------------------------------- */ | 604 | /* ------------------------------------------------------------------------- */ |
604 | 605 | ||
605 | void TEWidget::scrollChanged(int) { | 606 | void TEWidget::scrollChanged(int) { |
606 | emit changedHistoryCursor(scrollbar->value()); //expose | 607 | emit changedHistoryCursor(scrollbar->value()); //expose |
607 | } | 608 | } |
608 | 609 | ||
609 | void TEWidget::hScrollChanged(int loc) { | 610 | void TEWidget::hScrollChanged(int loc) { |
610 | hposition = loc; | 611 | hposition = loc; |
611 | propagateSize(); | 612 | propagateSize(); |
612 | update(); | 613 | update(); |
613 | 614 | ||
614 | // emit changedHorzCursor( hScrollbar->value()); //expose | 615 | // emit changedHorzCursor( hScrollbar->value()); //expose |
615 | } | 616 | } |
616 | 617 | ||
617 | void TEWidget::setScroll(int cursor, int slines) | 618 | void TEWidget::setScroll(int cursor, int slines) |
618 | { | 619 | { |
619 | disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 620 | disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
620 | scrollbar->setRange(0,slines); | 621 | scrollbar->setRange(0,slines); |
621 | scrollbar->setSteps(1,lines); | 622 | scrollbar->setSteps(1,lines); |
622 | scrollbar->setValue(cursor); | 623 | scrollbar->setValue(cursor); |
623 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 624 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
624 | } | 625 | } |
625 | 626 | ||
626 | void TEWidget::setScrollbarLocation(int loc) | 627 | void TEWidget::setScrollbarLocation(int loc) |
627 | { | 628 | { |
628 | if (scrollLoc == loc) return; // quickly | 629 | if (scrollLoc == loc) return; // quickly |
629 | scrollLoc = loc; | 630 | scrollLoc = loc; |
630 | propagateSize(); | 631 | propagateSize(); |
631 | update(); | 632 | update(); |
632 | } | 633 | } |
633 | 634 | ||
634 | /* ------------------------------------------------------------------------- */ | 635 | /* ------------------------------------------------------------------------- */ |
635 | /* */ | 636 | /* */ |
636 | /* Mouse */ | 637 | /* Mouse */ |
637 | /* */ | 638 | /* */ |
638 | /* ------------------------------------------------------------------------- */ | 639 | /* ------------------------------------------------------------------------- */ |
639 | 640 | ||
640 | /*! | 641 | /*! |
641 | Three different operations can be performed using the mouse, and the | 642 | Three different operations can be performed using the mouse, and the |
642 | routines in this section serve all of them: | 643 | routines in this section serve all of them: |
643 | 644 | ||
644 | 1) The press/release events are exposed to the application | 645 | 1) The press/release events are exposed to the application |
645 | 2) Marking (press and move left button) and Pasting (press middle button) | 646 | 2) Marking (press and move left button) and Pasting (press middle button) |
646 | 3) The right mouse button is used from the configuration menu | 647 | 3) The right mouse button is used from the configuration menu |
647 | 648 | ||
648 | NOTE: During the marking process we attempt to keep the cursor within | 649 | NOTE: During the marking process we attempt to keep the cursor within |
649 | the bounds of the text as being displayed by setting the mouse position | 650 | the bounds of the text as being displayed by setting the mouse position |
650 | whenever the mouse has left the text area. | 651 | whenever the mouse has left the text area. |
651 | 652 | ||
652 | Two reasons to do so: | 653 | Two reasons to do so: |
653 | 1) QT does not allow the `grabMouse' to confine-to the TEWidget. | 654 | 1) QT does not allow the `grabMouse' to confine-to the TEWidget. |
654 | Thus a `XGrapPointer' would have to be used instead. | 655 | Thus a `XGrapPointer' would have to be used instead. |
655 | 2) Even if so, this would not help too much, since the text area | 656 | 2) Even if so, this would not help too much, since the text area |
656 | of the TEWidget is normally not identical with it's bounds. | 657 | of the TEWidget is normally not identical with it's bounds. |
657 | 658 | ||
658 | The disadvantage of the current handling is, that the mouse can visibly | 659 | The disadvantage of the current handling is, that the mouse can visibly |
659 | leave the bounds of the widget and is then moved back. Because of the | 660 | leave the bounds of the widget and is then moved back. Because of the |
660 | current construction, and the reasons mentioned above, we cannot do better | 661 | current construction, and the reasons mentioned above, we cannot do better |
661 | without changing the overall construction. | 662 | without changing the overall construction. |
662 | */ | 663 | */ |
663 | 664 | ||
664 | /*! | 665 | /*! |
665 | */ | 666 | */ |
666 | 667 | ||
667 | void TEWidget::mousePressEvent(QMouseEvent* ev) | 668 | void TEWidget::mousePressEvent(QMouseEvent* ev) |
668 | { | 669 | { |
669 | //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); | 670 | //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); |
670 | if ( !contentsRect().contains(ev->pos()) ) return; | 671 | if ( !contentsRect().contains(ev->pos()) ) return; |
671 | QPoint tL = contentsRect().topLeft(); | 672 | QPoint tL = contentsRect().topLeft(); |
672 | int tLx = tL.x(); | 673 | int tLx = tL.x(); |
673 | int tLy = tL.y(); | 674 | int tLy = tL.y(); |
674 | 675 | ||
675 | word_selection_mode = FALSE; | 676 | word_selection_mode = FALSE; |
676 | 677 | ||
677 | //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); | 678 | //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); |
678 | if ( ev->button() == LeftButton) | 679 | if ( ev->button() == LeftButton) |
679 | { | 680 | { |
680 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 681 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
681 | 682 | ||
682 | if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; | 683 | if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; |
683 | 684 | ||
684 | if (mouse_marks || (ev->state() & ShiftButton)) | 685 | if (mouse_marks || (ev->state() & ShiftButton)) |
685 | { | 686 | { |
686 | emit clearSelectionSignal(); | 687 | emit clearSelectionSignal(); |
687 | iPntSel = pntSel = pos; | 688 | iPntSel = pntSel = pos; |
688 | actSel = 1; // left mouse button pressed but nothing selected yet. | 689 | actSel = 1; // left mouse button pressed but nothing selected yet. |
689 | grabMouse( /*crossCursor*/ ); // handle with care! | 690 | grabMouse( /*crossCursor*/ ); // handle with care! |
690 | } | 691 | } |
691 | else | 692 | else |
692 | { | 693 | { |
693 | emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button | 694 | emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button |
694 | } | 695 | } |
695 | } | 696 | } |
696 | if ( ev->button() == MidButton ) | 697 | if ( ev->button() == MidButton ) |
697 | { | 698 | { |
698 | emitSelection(); | 699 | emitSelection(); |
699 | } | 700 | } |
700 | if ( ev->button() == RightButton ) // Configure | 701 | if ( ev->button() == RightButton ) // Configure |
701 | { | 702 | { |
702 | emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); | 703 | emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); |
703 | } | 704 | } |
704 | } | 705 | } |
705 | 706 | ||
706 | void TEWidget::mouseMoveEvent(QMouseEvent* ev) | 707 | void TEWidget::mouseMoveEvent(QMouseEvent* ev) |
707 | { | 708 | { |
708 | // for auto-hiding the cursor, we need mouseTracking | 709 | // for auto-hiding the cursor, we need mouseTracking |
709 | if (ev->state() == NoButton ) return; | 710 | if (ev->state() == NoButton ) return; |
710 | 711 | ||
711 | if (actSel == 0) return; | 712 | if (actSel == 0) return; |
712 | 713 | ||
713 | // don't extend selection while pasting | 714 | // don't extend selection while pasting |
714 | if (ev->state() & MidButton) return; | 715 | if (ev->state() & MidButton) return; |
715 | 716 | ||
716 | //if ( !contentsRect().contains(ev->pos()) ) return; | 717 | //if ( !contentsRect().contains(ev->pos()) ) return; |
717 | QPoint tL = contentsRect().topLeft(); | 718 | QPoint tL = contentsRect().topLeft(); |
718 | int tLx = tL.x(); | 719 | int tLx = tL.x(); |
719 | int tLy = tL.y(); | 720 | int tLy = tL.y(); |
720 | int scroll = scrollbar->value(); | 721 | int scroll = scrollbar->value(); |
721 | // int hScroll = hScrollbar->value(); | 722 | // int hScroll = hScrollbar->value(); |
722 | 723 | ||
723 | // we're in the process of moving the mouse with the left button pressed | 724 | // we're in the process of moving the mouse with the left button pressed |
724 | // the mouse cursor will kept catched within the bounds of the text in | 725 | // the mouse cursor will kept catched within the bounds of the text in |
725 | // this widget. | 726 | // this widget. |
726 | 727 | ||
727 | // Adjust position within text area bounds. See FIXME above. | 728 | // Adjust position within text area bounds. See FIXME above. |
728 | QPoint pos = ev->pos(); | 729 | QPoint pos = ev->pos(); |
729 | if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); | 730 | if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); |
730 | if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); | 731 | if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); |
731 | if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); | 732 | if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); |
732 | if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); | 733 | if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); |
733 | // check if we produce a mouse move event by this | 734 | // check if we produce a mouse move event by this |
734 | if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); | 735 | if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); |
735 | 736 | ||
736 | if ( pos.y() == tLy+bY+lines*font_h-1 ) | 737 | if ( pos.y() == tLy+bY+lines*font_h-1 ) |
737 | { | 738 | { |
738 | scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward | 739 | scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward |
739 | } | 740 | } |
740 | if ( pos.y() == tLy+bY ) | 741 | if ( pos.y() == tLy+bY ) |
741 | { | 742 | { |
742 | scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback | 743 | scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback |
743 | } | 744 | } |
744 | 745 | ||
745 | QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); | 746 | QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); |
746 | QPoint ohere; | 747 | QPoint ohere; |
747 | bool swapping = FALSE; | 748 | bool swapping = FALSE; |
748 | 749 | ||
749 | if ( word_selection_mode ) | 750 | if ( word_selection_mode ) |
750 | { | 751 | { |
751 | // Extend to word boundaries | 752 | // Extend to word boundaries |
752 | int i; | 753 | int i; |
753 | int selClass; | 754 | int selClass; |
754 | 755 | ||
755 | bool left_not_right = ( here.y() < iPntSel.y() || | 756 | bool left_not_right = ( here.y() < iPntSel.y() || |
756 | here.y() == iPntSel.y() && here.x() < iPntSel.x() ); | 757 | here.y() == iPntSel.y() && here.x() < iPntSel.x() ); |
757 | bool old_left_not_right = ( pntSel.y() < iPntSel.y() || | 758 | bool old_left_not_right = ( pntSel.y() < iPntSel.y() || |
758 | pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); | 759 | pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); |
759 | swapping = left_not_right != old_left_not_right; | 760 | swapping = left_not_right != old_left_not_right; |
760 | 761 | ||
761 | // Find left (left_not_right ? from here : from start) | 762 | // Find left (left_not_right ? from here : from start) |
762 | QPoint left = left_not_right ? here : iPntSel; | 763 | QPoint left = left_not_right ? here : iPntSel; |
763 | i = loc(left.x(),left.y()); | 764 | i = loc(left.x(),left.y()); |
764 | selClass = charClass(image[i].c); | 765 | selClass = charClass(image[i].c); |
765 | while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) | 766 | while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) |
766 | { i--; left.rx()--; } | 767 | { i--; left.rx()--; } |
767 | 768 | ||
768 | // Find left (left_not_right ? from start : from here) | 769 | // Find left (left_not_right ? from start : from here) |
769 | QPoint right = left_not_right ? iPntSel : here; | 770 | QPoint right = left_not_right ? iPntSel : here; |
770 | i = loc(right.x(),right.y()); | 771 | i = loc(right.x(),right.y()); |
771 | selClass = charClass(image[i].c); | 772 | selClass = charClass(image[i].c); |
772 | while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) | 773 | while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) |
773 | { i++; right.rx()++; } | 774 | { i++; right.rx()++; } |
774 | 775 | ||
775 | // Pick which is start (ohere) and which is extension (here) | 776 | // Pick which is start (ohere) and which is extension (here) |
776 | if ( left_not_right ) | 777 | if ( left_not_right ) |
777 | { | 778 | { |
778 | here = left; ohere = right; | 779 | here = left; ohere = right; |
779 | } | 780 | } |
780 | else | 781 | else |
781 | { | 782 | { |
782 | here = right; ohere = left; | 783 | here = right; ohere = left; |
783 | } | 784 | } |
784 | } | 785 | } |
785 | 786 | ||
786 | if (here == pntSel && scroll == scrollbar->value()) return; // not moved | 787 | if (here == pntSel && scroll == scrollbar->value()) return; // not moved |
787 | 788 | ||
788 | if ( word_selection_mode ) { | 789 | if ( word_selection_mode ) { |
789 | if ( actSel < 2 || swapping ) { | 790 | if ( actSel < 2 || swapping ) { |
790 | emit beginSelectionSignal( ohere.x(), ohere.y() ); | 791 | emit beginSelectionSignal( ohere.x(), ohere.y() ); |
791 | } | 792 | } |
792 | } else if ( actSel < 2 ) { | 793 | } else if ( actSel < 2 ) { |
793 | emit beginSelectionSignal( pntSel.x(), pntSel.y() ); | 794 | emit beginSelectionSignal( pntSel.x(), pntSel.y() ); |
794 | } | 795 | } |
795 | 796 | ||
796 | actSel = 2; // within selection | 797 | actSel = 2; // within selection |
797 | pntSel = here; | 798 | pntSel = here; |
798 | emit extendSelectionSignal( here.x(), here.y() ); | 799 | emit extendSelectionSignal( here.x(), here.y() ); |
799 | } | 800 | } |
800 | 801 | ||
801 | void TEWidget::mouseReleaseEvent(QMouseEvent* ev) | 802 | void TEWidget::mouseReleaseEvent(QMouseEvent* ev) |
802 | { | 803 | { |
803 | //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); | 804 | //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); |
804 | if ( ev->button() == LeftButton) | 805 | if ( ev->button() == LeftButton) |
805 | { | 806 | { |
806 | if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); | 807 | if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); |
807 | preserve_line_breaks = TRUE; | 808 | preserve_line_breaks = TRUE; |
808 | actSel = 0; | 809 | actSel = 0; |
809 | 810 | ||
810 | //FIXME: emits a release event even if the mouse is | 811 | //FIXME: emits a release event even if the mouse is |
811 | // outside the range. The procedure used in `mouseMoveEvent' | 812 | // outside the range. The procedure used in `mouseMoveEvent' |
812 | // applies here, too. | 813 | // applies here, too. |
813 | 814 | ||
814 | QPoint tL = contentsRect().topLeft(); | 815 | QPoint tL = contentsRect().topLeft(); |
815 | int tLx = tL.x(); | 816 | int tLx = tL.x(); |
816 | int tLy = tL.y(); | 817 | int tLy = tL.y(); |
817 | 818 | ||
818 | if (!mouse_marks && !(ev->state() & ShiftButton)) | 819 | if (!mouse_marks && !(ev->state() & ShiftButton)) |
819 | emit mouseSignal( 3, // release | 820 | emit mouseSignal( 3, // release |
820 | (ev->x()-tLx-blX)/font_w + 1, | 821 | (ev->x()-tLx-blX)/font_w + 1, |
821 | (ev->y()-tLy-bY)/font_h + 1 ); | 822 | (ev->y()-tLy-bY)/font_h + 1 ); |
822 | releaseMouse(); | 823 | releaseMouse(); |
823 | } | 824 | } |
824 | } | 825 | } |
825 | 826 | ||
826 | void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) | 827 | void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) |
827 | { | 828 | { |
828 | if ( ev->button() != LeftButton) return; | 829 | if ( ev->button() != LeftButton) return; |
829 | 830 | ||
830 | QPoint tL = contentsRect().topLeft(); | 831 | QPoint tL = contentsRect().topLeft(); |
831 | int tLx = tL.x(); | 832 | int tLx = tL.x(); |
832 | int tLy = tL.y(); | 833 | int tLy = tL.y(); |
833 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 834 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
834 | 835 | ||
835 | // pass on double click as two clicks. | 836 | // pass on double click as two clicks. |
836 | if (!mouse_marks && !(ev->state() & ShiftButton)) | 837 | if (!mouse_marks && !(ev->state() & ShiftButton)) |
837 | { | 838 | { |
838 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button | 839 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button |
839 | emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release | 840 | emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release |
840 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button | 841 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button |
841 | return; | 842 | return; |
842 | } | 843 | } |
843 | 844 | ||
844 | 845 | ||
845 | emit clearSelectionSignal(); | 846 | emit clearSelectionSignal(); |
846 | QPoint bgnSel = pos; | 847 | QPoint bgnSel = pos; |
847 | QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 848 | QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
848 | int i = loc(bgnSel.x(),bgnSel.y()); | 849 | int i = loc(bgnSel.x(),bgnSel.y()); |
849 | iPntSel = bgnSel; | 850 | iPntSel = bgnSel; |
850 | 851 | ||
851 | word_selection_mode = TRUE; | 852 | word_selection_mode = TRUE; |
852 | 853 | ||
853 | // find word boundaries... | 854 | // find word boundaries... |
854 | int selClass = charClass(image[i].c); | 855 | int selClass = charClass(image[i].c); |
855 | { | 856 | { |
856 | // set the start... | 857 | // set the start... |
857 | int x = bgnSel.x(); | 858 | int x = bgnSel.x(); |
858 | while ( x > 0 && charClass(image[i-1].c) == selClass ) | 859 | while ( x > 0 && charClass(image[i-1].c) == selClass ) |
859 | { i--; x--; } | 860 | { i--; x--; } |
860 | bgnSel.setX(x); | 861 | bgnSel.setX(x); |
861 | emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); | 862 | emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); |
862 | 863 | ||
863 | // set the end... | 864 | // set the end... |
864 | i = loc( endSel.x(), endSel.y() ); | 865 | i = loc( endSel.x(), endSel.y() ); |
865 | x = endSel.x(); | 866 | x = endSel.x(); |
866 | while( x < columns-1 && charClass(image[i+1].c) == selClass ) | 867 | while( x < columns-1 && charClass(image[i+1].c) == selClass ) |
867 | { i++; x++ ; } | 868 | { i++; x++ ; } |
868 | endSel.setX(x); | 869 | endSel.setX(x); |
869 | actSel = 2; // within selection | 870 | actSel = 2; // within selection |
870 | emit extendSelectionSignal( endSel.x(), endSel.y() ); | 871 | emit extendSelectionSignal( endSel.x(), endSel.y() ); |
871 | emit endSelectionSignal(preserve_line_breaks); | 872 | emit endSelectionSignal(preserve_line_breaks); |
872 | preserve_line_breaks = TRUE; | 873 | preserve_line_breaks = TRUE; |
873 | } | 874 | } |
874 | } | 875 | } |
875 | 876 | ||
876 | void TEWidget::focusInEvent( QFocusEvent * ) | 877 | void TEWidget::focusInEvent( QFocusEvent * ) |
877 | { | 878 | { |
878 | 879 | ||
879 | // do nothing, to prevent repainting | 880 | // do nothing, to prevent repainting |
880 | } | 881 | } |
881 | 882 | ||
882 | 883 | ||
883 | void TEWidget::focusOutEvent( QFocusEvent * ) | 884 | void TEWidget::focusOutEvent( QFocusEvent * ) |
884 | { | 885 | { |
885 | // do nothing, to prevent repainting | 886 | // do nothing, to prevent repainting |
886 | } | 887 | } |
887 | 888 | ||
888 | bool TEWidget::focusNextPrevChild( bool next ) | 889 | bool TEWidget::focusNextPrevChild( bool next ) |
889 | { | 890 | { |
890 | if (next) | 891 | if (next) |
891 | return false; // This disables changing the active part in konqueror | 892 | return false; // This disables changing the active part in konqueror |
892 | // when pressing Tab | 893 | // when pressing Tab |
893 | return QFrame::focusNextPrevChild( next ); | 894 | return QFrame::focusNextPrevChild( next ); |
894 | } | 895 | } |
895 | 896 | ||
896 | 897 | ||
897 | int TEWidget::charClass(char ch) const | 898 | int TEWidget::charClass(char ch) const |
898 | { | 899 | { |
899 | // This might seem like overkill, but imagine if ch was a Unicode | 900 | // This might seem like overkill, but imagine if ch was a Unicode |
900 | // character (Qt 2.0 QChar) - it might then be sensible to separate | 901 | // character (Qt 2.0 QChar) - it might then be sensible to separate |
901 | // the different language ranges, etc. | 902 | // the different language ranges, etc. |
902 | 903 | ||
903 | if ( isspace(ch) ) return ' '; | 904 | if ( isspace(ch) ) return ' '; |
904 | 905 | ||
905 | static const char *word_characters = ":@-./_~"; | 906 | static const char *word_characters = ":@-./_~"; |
906 | if ( isalnum(ch) || strchr(word_characters, ch) ) | 907 | if ( isalnum(ch) || strchr(word_characters, ch) ) |
907 | return 'a'; | 908 | return 'a'; |
908 | 909 | ||
909 | // Everything else is weird | 910 | // Everything else is weird |
910 | return 1; | 911 | return 1; |
911 | } | 912 | } |
912 | 913 | ||
913 | void TEWidget::setMouseMarks(bool on) | 914 | void TEWidget::setMouseMarks(bool on) |
914 | { | 915 | { |
915 | mouse_marks = on; | 916 | mouse_marks = on; |
916 | setCursor( mouse_marks ? ibeamCursor : arrowCursor ); | 917 | setCursor( mouse_marks ? ibeamCursor : arrowCursor ); |
917 | } | 918 | } |
918 | 919 | ||
919 | /* ------------------------------------------------------------------------- */ | 920 | /* ------------------------------------------------------------------------- */ |
920 | /* */ | 921 | /* */ |
921 | /* Clipboard */ | 922 | /* Clipboard */ |
922 | /* */ | 923 | /* */ |
923 | /* ------------------------------------------------------------------------- */ | 924 | /* ------------------------------------------------------------------------- */ |
924 | 925 | ||
925 | #undef KeyPress | 926 | #undef KeyPress |
926 | 927 | ||
927 | void TEWidget::emitSelection() | 928 | void TEWidget::emitSelection() |
928 | // Paste Clipboard by simulating keypress events | 929 | // Paste Clipboard by simulating keypress events |
929 | { | 930 | { |
930 | #ifndef QT_NO_CLIPBOARD | 931 | #ifndef QT_NO_CLIPBOARD |
931 | QString text = QApplication::clipboard()->text(); | 932 | QString text = QApplication::clipboard()->text(); |
932 | if ( ! text.isNull() ) | 933 | if ( ! text.isNull() ) |
933 | { | 934 | { |
934 | text.replace(QRegExp("\n"), "\r"); | 935 | text.replace(QRegExp("\n"), "\r"); |
935 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); | 936 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); |
936 | emit keyPressedSignal(&e); // expose as a big fat keypress event | 937 | emit keyPressedSignal(&e); // expose as a big fat keypress event |
937 | emit clearSelectionSignal(); | 938 | emit clearSelectionSignal(); |
938 | } | 939 | } |
939 | #endif | 940 | #endif |
940 | } | 941 | } |
941 | 942 | ||
942 | void TEWidget::emitText(QString text) | 943 | void TEWidget::emitText(QString text) |
943 | { | 944 | { |
944 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); | 945 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); |
945 | emit keyPressedSignal(&e); // expose as a big fat keypress event | 946 | emit keyPressedSignal(&e); // expose as a big fat keypress event |
946 | } | 947 | } |
947 | 948 | ||
948 | void TEWidget::pasteClipboard( ) | 949 | void TEWidget::pasteClipboard( ) |
949 | { | 950 | { |
950 | emitSelection(); | 951 | emitSelection(); |
951 | } | 952 | } |
952 | 953 | ||
953 | void TEWidget::setSelection(const QString& t) | 954 | void TEWidget::setSelection(const QString& t) |
954 | { | 955 | { |
955 | #ifndef QT_NO_CLIPBOARD | 956 | #ifndef QT_NO_CLIPBOARD |
956 | // Disconnect signal while WE set the clipboard | 957 | // Disconnect signal while WE set the clipboard |
957 | QObject *cb = QApplication::clipboard(); | 958 | QObject *cb = QApplication::clipboard(); |
958 | QObject::disconnect( cb, SIGNAL(dataChanged()), | 959 | QObject::disconnect( cb, SIGNAL(dataChanged()), |
959 | this, SLOT(onClearSelection()) ); | 960 | this, SLOT(onClearSelection()) ); |
960 | 961 | ||
961 | QApplication::clipboard()->setText(t); | 962 | QApplication::clipboard()->setText(t); |
962 | 963 | ||
963 | QObject::connect( cb, SIGNAL(dataChanged()), | 964 | QObject::connect( cb, SIGNAL(dataChanged()), |
964 | this, SLOT(onClearSelection()) ); | 965 | this, SLOT(onClearSelection()) ); |
965 | #endif | 966 | #endif |
966 | } | 967 | } |
967 | 968 | ||
968 | void TEWidget::onClearSelection() | 969 | void TEWidget::onClearSelection() |
969 | { | 970 | { |
970 | emit clearSelectionSignal(); | 971 | emit clearSelectionSignal(); |
971 | } | 972 | } |
972 | 973 | ||
973 | /* ------------------------------------------------------------------------- */ | 974 | /* ------------------------------------------------------------------------- */ |
974 | /* */ | 975 | /* */ |
975 | /* Keyboard */ | 976 | /* Keyboard */ |
976 | /* */ | 977 | /* */ |
977 | /* ------------------------------------------------------------------------- */ | 978 | /* ------------------------------------------------------------------------- */ |
978 | 979 | ||
979 | //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' | 980 | //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' |
980 | // due to a bug in `QT' or the ignorance of the author to prevent | 981 | // due to a bug in `QT' or the ignorance of the author to prevent |
981 | // repaint events being emitted to the screen whenever one leaves | 982 | // repaint events being emitted to the screen whenever one leaves |
982 | // or reenters the screen to/from another application. | 983 | // or reenters the screen to/from another application. |
983 | // | 984 | // |
984 | // Troll says one needs to change focusInEvent() and focusOutEvent(), | 985 | // Troll says one needs to change focusInEvent() and focusOutEvent(), |
985 | // which would also let you have an in-focus cursor and an out-focus | 986 | // which would also let you have an in-focus cursor and an out-focus |
986 | // cursor like xterm does. | 987 | // cursor like xterm does. |
987 | 988 | ||
988 | // for the auto-hide cursor feature, I added empty focusInEvent() and | 989 | // for the auto-hide cursor feature, I added empty focusInEvent() and |
989 | // focusOutEvent() so that update() isn't called. | 990 | // focusOutEvent() so that update() isn't called. |
990 | // For auto-hide, we need to get keypress-events, but we only get them when | 991 | // For auto-hide, we need to get keypress-events, but we only get them when |
991 | // we have focus. | 992 | // we have focus. |
992 | 993 | ||
993 | void TEWidget::doScroll(int lines) | 994 | void TEWidget::doScroll(int lines) |
994 | { | 995 | { |
995 | scrollbar->setValue(scrollbar->value()+lines); | 996 | scrollbar->setValue(scrollbar->value()+lines); |
996 | } | 997 | } |
997 | 998 | ||
998 | void TEWidget::doHScroll(int lines) { | 999 | void TEWidget::doHScroll(int lines) { |
999 | hScrollbar->setValue( hScrollbar->value()+lines); | 1000 | hScrollbar->setValue( hScrollbar->value()+lines); |
1000 | } | 1001 | } |
1001 | 1002 | ||
1002 | bool TEWidget::eventFilter( QObject *obj, QEvent *e ) | 1003 | bool TEWidget::eventFilter( QObject *obj, QEvent *e ) |
1003 | { | 1004 | { |
1004 | if ( (e->type() == QEvent::Accel || | 1005 | if ( (e->type() == QEvent::Accel || |
1005 | e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { | 1006 | e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { |
1006 | static_cast<QKeyEvent *>( e )->ignore(); | 1007 | static_cast<QKeyEvent *>( e )->ignore(); |
1007 | return true; | 1008 | return true; |
1008 | } | 1009 | } |
1009 | if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) | 1010 | if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) |
1010 | return FALSE; // not us | 1011 | return FALSE; // not us |
1011 | if ( e->type() == QEvent::Wheel) { | 1012 | if ( e->type() == QEvent::Wheel) { |
1012 | QApplication::sendEvent(scrollbar, e); | 1013 | QApplication::sendEvent(scrollbar, e); |
1013 | } | 1014 | } |
1014 | 1015 | ||
1015 | #ifdef FAKE_CTRL_AND_ALT | 1016 | #ifdef FAKE_CTRL_AND_ALT |
1016 | static bool control = FALSE; | 1017 | static bool control = FALSE; |
1017 | static bool alt = FALSE; | 1018 | static bool alt = FALSE; |
1018 | // qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); | 1019 | // qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); |
1019 | bool dele=FALSE; | 1020 | bool dele=FALSE; |
1020 | if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { | 1021 | if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { |
1021 | QKeyEvent* ke = (QKeyEvent*)e; | 1022 | QKeyEvent* ke = (QKeyEvent*)e; |
1022 | bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); | 1023 | bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); |
1023 | switch (ke->key()) { | 1024 | switch (ke->key()) { |
1024 | case Key_F9: // let this be "Control" | 1025 | case Key_F9: // let this be "Control" |
1025 | control = keydown; | 1026 | control = keydown; |
1026 | e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); | 1027 | e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); |
1027 | dele=TRUE; | 1028 | dele=TRUE; |
1028 | break; | 1029 | break; |
1029 | case Key_F13: // let this be "Alt" | 1030 | case Key_F13: // let this be "Alt" |
1030 | alt = keydown; | 1031 | alt = keydown; |
1031 | e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); | 1032 | e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); |
1032 | dele=TRUE; | 1033 | dele=TRUE; |
1033 | break; | 1034 | break; |
1034 | default: | 1035 | default: |
1035 | if ( control ) { | 1036 | if ( control ) { |
1036 | int a = toupper(ke->ascii())-64; | 1037 | int a = toupper(ke->ascii())-64; |
1037 | if ( a >= 0 && a < ' ' ) { | 1038 | if ( a >= 0 && a < ' ' ) { |
1038 | e = new QKeyEvent(e->type(), ke->key(), | 1039 | e = new QKeyEvent(e->type(), ke->key(), |
1039 | a, ke->state()|ControlButton, QChar(a,0)); | 1040 | a, ke->state()|ControlButton, QChar(a,0)); |
1040 | dele=TRUE; | 1041 | dele=TRUE; |
1041 | } | 1042 | } |
1042 | } | 1043 | } |
1043 | if ( alt ) { | 1044 | if ( alt ) { |
1044 | e = new QKeyEvent(e->type(), ke->key(), | 1045 | e = new QKeyEvent(e->type(), ke->key(), |
1045 | ke->ascii(), ke->state()|AltButton, ke->text()); | 1046 | ke->ascii(), ke->state()|AltButton, ke->text()); |
1046 | dele=TRUE; | 1047 | dele=TRUE; |
1047 | } | 1048 | } |
1048 | } | 1049 | } |
1049 | } | 1050 | } |
1050 | #endif | 1051 | #endif |
1051 | 1052 | ||
1052 | if ( e->type() == QEvent::KeyPress ) { | 1053 | if ( e->type() == QEvent::KeyPress ) { |
1053 | QKeyEvent* ke = (QKeyEvent*)e; | 1054 | QKeyEvent* ke = (QKeyEvent*)e; |
1054 | actSel=0; // Key stroke implies a screen update, so TEWidget won't | 1055 | actSel=0; // Key stroke implies a screen update, so TEWidget won't |
1055 | // know where the current selection is. | 1056 | // know where the current selection is. |
1056 | 1057 | ||
1057 | // qDebug("key pressed is 0x%x, state %d",ke->key(), ke->state()); | 1058 | // qDebug("key pressed is 0x%x, state %d",ke->key(), ke->state()); |
1058 | 1059 | ||
1059 | if( ke->state() == ShiftButton && ke->key() == Key_Tab) { | 1060 | if( ke->state() == ShiftButton && ke->key() == Key_Tab) { |
1060 | //lets hardcode this sucker | 1061 | //lets hardcode this sucker |
1061 | 1062 | ||
1062 | // qDebug("key pressed 2 is 0x%x",ke->key()); | 1063 | // qDebug("key pressed 2 is 0x%x",ke->key()); |
1063 | emitText("\\"); // expose | 1064 | emitText("\\"); // expose |
1064 | } | 1065 | } |
1065 | else if( ke->state() == ControlButton && ke->key() == Key_V) { | 1066 | else if( ke->state() == ControlButton && ke->key() == Key_V) { |
1066 | pasteClipboard(); | 1067 | pasteClipboard(); |
1067 | } | 1068 | } |
1068 | else | 1069 | else |
1069 | emit keyPressedSignal(ke); // expose | 1070 | emit keyPressedSignal(ke); // expose |
1070 | ke->accept(); | 1071 | ke->accept(); |
1071 | #ifdef FAKE_CTRL_AND_ALT | 1072 | #ifdef FAKE_CTRL_AND_ALT |
1072 | if ( dele ) delete e; | 1073 | if ( dele ) delete e; |
1073 | #endif | 1074 | #endif |
1074 | return true; // stop the event | 1075 | return true; // stop the event |
1075 | } | 1076 | } |
1076 | if ( e->type() == QEvent::Enter ) { | 1077 | if ( e->type() == QEvent::Enter ) { |
1077 | QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), | 1078 | QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), |
1078 | this, SLOT(onClearSelection()) ); | 1079 | this, SLOT(onClearSelection()) ); |
1079 | } | 1080 | } |
1080 | if ( e->type() == QEvent::Leave ) { | 1081 | if ( e->type() == QEvent::Leave ) { |
1081 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), | 1082 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), |
1082 | this, SLOT(onClearSelection()) ); | 1083 | this, SLOT(onClearSelection()) ); |
1083 | } | 1084 | } |
1084 | return QFrame::eventFilter( obj, e ); | 1085 | return QFrame::eventFilter( obj, e ); |
1085 | } | 1086 | } |
1086 | 1087 | ||
1087 | /* ------------------------------------------------------------------------- */ | 1088 | /* ------------------------------------------------------------------------- */ |
1088 | /* */ | 1089 | /* */ |
1089 | /* Frame */ | 1090 | /* Frame */ |
1090 | /* */ | 1091 | /* */ |
1091 | /* ------------------------------------------------------------------------- */ | 1092 | /* ------------------------------------------------------------------------- */ |
1092 | 1093 | ||
1093 | void TEWidget::frameChanged() | 1094 | void TEWidget::frameChanged() |
1094 | { | 1095 | { |
1095 | propagateSize(); | 1096 | propagateSize(); |
1096 | update(); | 1097 | update(); |
1097 | } | 1098 | } |
1098 | 1099 | ||
1099 | /* ------------------------------------------------------------------------- */ | 1100 | /* ------------------------------------------------------------------------- */ |
1100 | /* */ | 1101 | /* */ |
1101 | /* Sound */ | 1102 | /* Sound */ |
1102 | /* */ | 1103 | /* */ |
1103 | /* ------------------------------------------------------------------------- */ | 1104 | /* ------------------------------------------------------------------------- */ |
1104 | 1105 | ||
1105 | void TEWidget::Bell() | 1106 | void TEWidget::Bell() |
1106 | { | 1107 | { |
1107 | //#ifdef QT_QWS_CUSTOM | 1108 | //#ifdef QT_QWS_CUSTOM |
1108 | //# ifndef QT_NO_COP | 1109 | //# ifndef QT_NO_COP |
1109 | QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); | 1110 | QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); |
1110 | //# endif | 1111 | //# endif |
1111 | //#else | 1112 | //#else |
1112 | //# ifndef QT_NO_SOUND | 1113 | //# ifndef QT_NO_SOUND |
1113 | // QSound::play(Resource::findSound("alarm")); | 1114 | // QSound::play(Resource::findSound("alarm")); |
1114 | //# endif | 1115 | //# endif |
1115 | //#endif | 1116 | //#endif |
1116 | 1117 | ||
1117 | // QApplication::beep(); | 1118 | // QApplication::beep(); |
1118 | } | 1119 | } |
1119 | 1120 | ||
1120 | /* ------------------------------------------------------------------------- */ | 1121 | /* ------------------------------------------------------------------------- */ |
1121 | /* */ | 1122 | /* */ |
1122 | /* Auxiluary */ | 1123 | /* Auxiluary */ |
1123 | /* */ | 1124 | /* */ |
1124 | /* ------------------------------------------------------------------------- */ | 1125 | /* ------------------------------------------------------------------------- */ |
1125 | 1126 | ||
1126 | void TEWidget::clearImage() | 1127 | void TEWidget::clearImage() |
1127 | // initialize the image | 1128 | // initialize the image |
1128 | // for internal use only | 1129 | // for internal use only |
1129 | { | 1130 | { |
1130 | for (int y = 0; y < lines; y++) | 1131 | for (int y = 0; y < lines; y++) |
1131 | for (int x = 0; x < columns; x++) | 1132 | for (int x = 0; x < columns; x++) |
1132 | { | 1133 | { |
1133 | image[loc(x,y)].c = 0xff; //' '; | 1134 | image[loc(x,y)].c = 0xff; //' '; |
1134 | image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; | 1135 | image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; |
1135 | image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; | 1136 | image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; |
1136 | image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; | 1137 | image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; |
1137 | } | 1138 | } |
1138 | } | 1139 | } |
1139 | 1140 | ||
1140 | // Create Image /////////////////////////////////////////////////////// | 1141 | // Create Image /////////////////////////////////////////////////////// |
1141 | 1142 | ||
1142 | void TEWidget::calcGeometry() | 1143 | void TEWidget::calcGeometry() |
1143 | { | 1144 | { |
1144 | int showhscrollbar = 1; | 1145 | int showhscrollbar = 1; |
1145 | int hwidth = 0; | 1146 | int hwidth = 0; |
1146 | int dcolumns; | 1147 | int dcolumns; |
1147 | Config cfg("Konsole"); | 1148 | Config cfg("Konsole"); |
1148 | cfg.setGroup("ScrollBar"); | 1149 | cfg.setGroup("ScrollBar"); |
1149 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); | 1150 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); |
1150 | 1151 | ||
1151 | if(vcolumns == 0) showhscrollbar = 0; | 1152 | if(vcolumns == 0) showhscrollbar = 0; |
1152 | if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); | 1153 | if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); |
1153 | 1154 | ||
1154 | scrollbar->resize(QApplication::style().scrollBarExtent().width(), | 1155 | scrollbar->resize(QApplication::style().scrollBarExtent().width(), |
1155 | contentsRect().height() - hwidth); | 1156 | contentsRect().height() - hwidth); |
1156 | 1157 | ||
1157 | switch(scrollLoc) { | 1158 | switch(scrollLoc) { |
1158 | case SCRNONE : | 1159 | case SCRNONE : |
1159 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; | 1160 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; |
1160 | dcolumns = columns; | 1161 | dcolumns = columns; |
1161 | if(vcolumns) columns = vcolumns; | 1162 | if(vcolumns) columns = vcolumns; |
1162 | blX = (contentsRect().width() - (columns*font_w) ) / 2; | 1163 | blX = (contentsRect().width() - (columns*font_w) ) / 2; |
1163 | if(showhscrollbar) | 1164 | if(showhscrollbar) |
1164 | blX = -hposition * font_w; | 1165 | blX = -hposition * font_w; |
1165 | brX = blX; | 1166 | brX = blX; |
1166 | scrollbar->hide(); | 1167 | scrollbar->hide(); |
1167 | break; | 1168 | break; |
1168 | case SCRLEFT : | 1169 | case SCRLEFT : |
1169 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1170 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1170 | dcolumns = columns; | 1171 | dcolumns = columns; |
1171 | if(vcolumns) columns = vcolumns; | 1172 | if(vcolumns) columns = vcolumns; |
1172 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1173 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1173 | if(showhscrollbar) | 1174 | if(showhscrollbar) |
1174 | brX = -hposition * font_w; | 1175 | brX = -hposition * font_w; |
1175 | blX = brX + scrollbar->width(); | 1176 | blX = brX + scrollbar->width(); |
1176 | scrollbar->move(contentsRect().topLeft()); | 1177 | scrollbar->move(contentsRect().topLeft()); |
1177 | scrollbar->show(); | 1178 | scrollbar->show(); |
1178 | break; | 1179 | break; |
1179 | case SCRRIGHT: | 1180 | case SCRRIGHT: |
1180 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1181 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1181 | dcolumns = columns; | 1182 | dcolumns = columns; |
1182 | if(vcolumns) columns = vcolumns; | 1183 | if(vcolumns) columns = vcolumns; |
1183 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1184 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1184 | if(showhscrollbar) | 1185 | if(showhscrollbar) |
1185 | blX = -hposition * font_w; | 1186 | blX = -hposition * font_w; |
1186 | brX = blX; | 1187 | brX = blX; |
1187 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); | 1188 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); |
1188 | scrollbar->show(); | 1189 | scrollbar->show(); |
1189 | break; | 1190 | break; |
1190 | } | 1191 | } |
1191 | //FIXME: support 'rounding' styles | 1192 | //FIXME: support 'rounding' styles |
1192 | lines = ( contentsRect().height() - 2 * rimY ) / font_h; | 1193 | lines = ( contentsRect().height() - 2 * rimY ) / font_h; |
1193 | bY = (contentsRect().height() - (lines *font_h)) / 2; | 1194 | bY = (contentsRect().height() - (lines *font_h)) / 2; |
1194 | 1195 | ||
1195 | if(showhscrollbar == 1) { | 1196 | if(showhscrollbar == 1) { |
1196 | hScrollbar->resize(contentsRect().width() - hwidth, hwidth); | 1197 | hScrollbar->resize(contentsRect().width() - hwidth, hwidth); |
1197 | hScrollbar->setRange(0, vcolumns - dcolumns); | 1198 | hScrollbar->setRange(0, vcolumns - dcolumns); |
1198 | 1199 | ||
1199 | QPoint p = contentsRect().bottomLeft(); | 1200 | QPoint p = contentsRect().bottomLeft(); |
1200 | hScrollbar->move(QPoint(p.x(), p.y() - hwidth)); | 1201 | hScrollbar->move(QPoint(p.x(), p.y() - hwidth)); |
1201 | hScrollbar->show(); | 1202 | hScrollbar->show(); |
1202 | } | 1203 | } |
1203 | else hScrollbar->hide(); | 1204 | else hScrollbar->hide(); |
1204 | 1205 | ||
1205 | if(showhscrollbar == 1) { | 1206 | if(showhscrollbar == 1) { |
1206 | lines = lines - (hwidth / font_h) - 1; | 1207 | lines = lines - (hwidth / font_h) - 1; |
1207 | if(lines < 1) lines = 1; | 1208 | if(lines < 1) lines = 1; |
1208 | } | 1209 | } |
1209 | 1210 | ||
1210 | /*//FIXME: set rimX == rimY == 0 when running in full screen mode. | 1211 | /*//FIXME: set rimX == rimY == 0 when running in full screen mode. |
1211 | Config cfg("Konsole"); | 1212 | Config cfg("Konsole"); |
1212 | cfg.setGroup("ScrollBar"); | 1213 | cfg.setGroup("ScrollBar"); |
1213 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); | 1214 | useHorzScroll=cfg.readBoolEntry("HorzScroll",0); |
1214 | 1215 | ||
1215 | scrollbar->resize( QApplication::style().scrollBarExtent().width(), | 1216 | scrollbar->resize( QApplication::style().scrollBarExtent().width(), |
1216 | contentsRect().height()); | 1217 | contentsRect().height()); |
1217 | qDebug("font_w %d", font_w); | 1218 | qDebug("font_w %d", font_w); |
1218 | switch(scrollLoc) | 1219 | switch(scrollLoc) |
1219 | { | 1220 | { |
1220 | case SCRNONE : | 1221 | case SCRNONE : |
1221 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; | 1222 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; |
1222 | blX = (contentsRect().width() - (columns*font_w) ) / 2; | 1223 | blX = (contentsRect().width() - (columns*font_w) ) / 2; |
1223 | brX = blX; | 1224 | brX = blX; |
1224 | scrollbar->hide(); | 1225 | scrollbar->hide(); |
1225 | break; | 1226 | break; |
1226 | case SCRLEFT : | 1227 | case SCRLEFT : |
1227 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1228 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1228 | if(useHorzScroll) columns = columns * (font_w/2); | 1229 | if(useHorzScroll) columns = columns * (font_w/2); |
1229 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1230 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1230 | blX = brX + scrollbar->width(); | 1231 | blX = brX + scrollbar->width(); |
1231 | scrollbar->move(contentsRect().topLeft()); | 1232 | scrollbar->move(contentsRect().topLeft()); |
1232 | scrollbar->show(); | 1233 | scrollbar->show(); |
1233 | break; | 1234 | break; |
1234 | case SCRRIGHT: | 1235 | case SCRRIGHT: |
1235 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width() ) / font_w; | 1236 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width() ) / font_w; |
1236 | if(useHorzScroll) columns = columns * (font_w/2); | 1237 | if(useHorzScroll) columns = columns * (font_w/2); |
1237 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1238 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1238 | if(useHorzScroll) { | 1239 | if(useHorzScroll) { |
1239 | brX = blX =2; | 1240 | brX = blX =2; |
1240 | } else { | 1241 | } else { |
1241 | brX=blX; | 1242 | brX=blX; |
1242 | } | 1243 | } |
1243 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0) ); | 1244 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0) ); |
1244 | scrollbar->show(); | 1245 | scrollbar->show(); |
1245 | break; | 1246 | break; |
1246 | } | 1247 | } |
1247 | 1248 | ||
1248 | if( !scrollbar->isHidden()) | 1249 | if( !scrollbar->isHidden()) |
1249 | hScrollbar->resize( contentsRect().width()-SCRWIDTH, QApplication::style() | 1250 | hScrollbar->resize( contentsRect().width()-SCRWIDTH, QApplication::style() |
1250 | .scrollBarExtent().height()); | 1251 | .scrollBarExtent().height()); |
1251 | else | 1252 | else |
1252 | hScrollbar->resize( contentsRect().width(), QApplication::style() | 1253 | hScrollbar->resize( contentsRect().width(), QApplication::style() |
1253 | .scrollBarExtent().height()); | 1254 | .scrollBarExtent().height()); |
1254 | 1255 | ||
1255 | hScrollbar->move( 0, contentsRect().height() - SCRWIDTH); | 1256 | hScrollbar->move( 0, contentsRect().height() - SCRWIDTH); |
1256 | 1257 | ||
1257 | 1258 | ||
1258 | if(useHorzScroll) { | 1259 | if(useHorzScroll) { |
1259 | hScrollbar->show(); | 1260 | hScrollbar->show(); |
1260 | lines = ( (contentsRect().height() - SCRWIDTH) - 2 * rimY ) / font_h; | 1261 | lines = ( (contentsRect().height() - SCRWIDTH) - 2 * rimY ) / font_h; |
1261 | bY = ((contentsRect().height() - SCRWIDTH) - (lines *font_h)) / 2; | 1262 | bY = ((contentsRect().height() - SCRWIDTH) - (lines *font_h)) / 2; |
1262 | } else { | 1263 | } else { |
1263 | hScrollbar->hide(); | 1264 | hScrollbar->hide(); |
1264 | lines = (contentsRect().height() - 2 * rimY ) / font_h; | 1265 | lines = (contentsRect().height() - 2 * rimY ) / font_h; |
1265 | bY = (contentsRect().height() - (lines *font_h)) / 2; | 1266 | bY = (contentsRect().height() - (lines *font_h)) / 2; |
1266 | } | 1267 | } |
1267 | */ | 1268 | */ |
1268 | //FIXME: support 'rounding' styles | 1269 | //FIXME: support 'rounding' styles |
1269 | } | 1270 | } |
1270 | 1271 | ||
1271 | void TEWidget::makeImage() | 1272 | void TEWidget::makeImage() |
1272 | //FIXME: rename 'calcGeometry? | 1273 | //FIXME: rename 'calcGeometry? |
1273 | { | 1274 | { |
1274 | calcGeometry(); | 1275 | calcGeometry(); |
1275 | image = (ca*) malloc(lines*columns*sizeof(ca)); | 1276 | image = (ca*) malloc(lines*columns*sizeof(ca)); |
1276 | clearImage(); | 1277 | clearImage(); |
1277 | } | 1278 | } |
1278 | 1279 | ||
1279 | // calculate the needed size | 1280 | // calculate the needed size |
1280 | QSize TEWidget::calcSize(int cols, int lins) const | 1281 | QSize TEWidget::calcSize(int cols, int lins) const |
1281 | { | 1282 | { |
1282 | int frw = width() - contentsRect().width(); | 1283 | int frw = width() - contentsRect().width(); |
1283 | int frh = height() - contentsRect().height(); | 1284 | int frh = height() - contentsRect().height(); |
1284 | int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); | 1285 | int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); |
1285 | return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); | 1286 | return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); |
1286 | } | 1287 | } |
1287 | 1288 | ||
1288 | QSize TEWidget::sizeHint() const | 1289 | QSize TEWidget::sizeHint() const |
1289 | { | 1290 | { |
1290 | return size(); | 1291 | return size(); |
1291 | } | 1292 | } |
1292 | 1293 | ||
1293 | void TEWidget::styleChange(QStyle &) | 1294 | void TEWidget::styleChange(QStyle &) |
1294 | { | 1295 | { |
1295 | propagateSize(); | 1296 | propagateSize(); |
1296 | } | 1297 | } |
1297 | 1298 | ||
1298 | #ifndef QT_NO_DRAGANDDROP | 1299 | #ifndef QT_NO_DRAGANDDROP |
1299 | 1300 | ||
1300 | /* --------------------------------------------------------------------- */ | 1301 | /* --------------------------------------------------------------------- */ |
1301 | /* */ | 1302 | /* */ |
1302 | /* Drag & Drop */ | 1303 | /* Drag & Drop */ |
1303 | /* */ | 1304 | /* */ |
1304 | /* --------------------------------------------------------------------- */ | 1305 | /* --------------------------------------------------------------------- */ |
1305 | 1306 | ||
1306 | 1307 | ||
1307 | void TEWidget::dragEnterEvent(QDragEnterEvent* e) | 1308 | void TEWidget::dragEnterEvent(QDragEnterEvent* e) |
1308 | { | 1309 | { |
1309 | e->accept(QTextDrag::canDecode(e) || | 1310 | e->accept(QTextDrag::canDecode(e) || |
1310 | QUriDrag::canDecode(e)); | 1311 | QUriDrag::canDecode(e)); |
1311 | } | 1312 | } |
1312 | 1313 | ||
1313 | void TEWidget::dropEvent(QDropEvent* event) | 1314 | void TEWidget::dropEvent(QDropEvent* event) |
1314 | { | 1315 | { |
1315 | // The current behaviour when url(s) are dropped is | 1316 | // The current behaviour when url(s) are dropped is |
1316 | // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd | 1317 | // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd |
1317 | // * in all other cases, just paste | 1318 | // * in all other cases, just paste |
1318 | // (for non-local ones, or for a list of URLs, 'cd' is nonsense) | 1319 | // (for non-local ones, or for a list of URLs, 'cd' is nonsense) |
1319 | QStrList strlist; | 1320 | QStrList strlist; |
1320 | int file_count = 0; | 1321 | int file_count = 0; |
1321 | dropText = ""; | 1322 | dropText = ""; |
1322 | bool bPopup = true; | 1323 | bool bPopup = true; |
1323 | 1324 | ||
1324 | if(QUriDrag::decode(event, strlist)) { | 1325 | if(QUriDrag::decode(event, strlist)) { |
1325 | if (strlist.count()) { | 1326 | if (strlist.count()) { |
1326 | for(const char* p = strlist.first(); p; p = strlist.next()) { | 1327 | for(const char* p = strlist.first(); p; p = strlist.next()) { |
1327 | if(file_count++ > 0) { | 1328 | if(file_count++ > 0) { |
1328 | dropText += " "; | 1329 | dropText += " "; |
1329 | bPopup = false; // more than one file, don't popup | 1330 | bPopup = false; // more than one file, don't popup |
1330 | } | 1331 | } |
1331 | 1332 | ||
1332 | /* | 1333 | /* |
1333 | KURL url(p); | 1334 | KURL url(p); |
1334 | if (url.isLocalFile()) { | 1335 | if (url.isLocalFile()) { |
1335 | dropText += url.path(); // local URL : remove protocol | 1336 | dropText += url.path(); // local URL : remove protocol |
1336 | } | 1337 | } |
1337 | else { | 1338 | else { |
1338 | dropText += url.prettyURL(); | 1339 | dropText += url.prettyURL(); |
1339 | bPopup = false; // a non-local file, don't popup | 1340 | bPopup = false; // a non-local file, don't popup |
1340 | } | 1341 | } |
1341 | */ | 1342 | */ |
1342 | 1343 | ||
1343 | } | 1344 | } |
1344 | 1345 | ||
1345 | if (bPopup) | 1346 | if (bPopup) |
1346 | // m_drop->popup(pos() + event->pos()); | 1347 | // m_drop->popup(pos() + event->pos()); |
1347 | m_drop->popup(mapToGlobal(event->pos())); | 1348 | m_drop->popup(mapToGlobal(event->pos())); |
1348 | else | 1349 | else |
1349 | { | 1350 | { |
1350 | if (currentSession) { | 1351 | if (currentSession) { |
1351 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1352 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1352 | } | 1353 | } |
1353 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; | 1354 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; |
1354 | } | 1355 | } |
1355 | } | 1356 | } |
1356 | } | 1357 | } |
1357 | else if(QTextDrag::decode(event, dropText)) { | 1358 | else if(QTextDrag::decode(event, dropText)) { |
1358 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; | 1359 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; |
1359 | if (currentSession) { | 1360 | if (currentSession) { |
1360 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1361 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1361 | } | 1362 | } |
1362 | // Paste it | 1363 | // Paste it |
1363 | } | 1364 | } |
1364 | } | 1365 | } |
1365 | #endif | 1366 | #endif |
1366 | 1367 | ||
1367 | 1368 | ||
1368 | void TEWidget::drop_menu_activated(int item) | 1369 | void TEWidget::drop_menu_activated(int item) |
1369 | { | 1370 | { |
1370 | #ifndef QT_NO_DRAGANDDROP | 1371 | #ifndef QT_NO_DRAGANDDROP |
1371 | switch (item) | 1372 | switch (item) |
1372 | { | 1373 | { |
1373 | case 0: // paste | 1374 | case 0: // paste |
1374 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1375 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1375 | // KWM::activate((Window)this->winId()); | 1376 | // KWM::activate((Window)this->winId()); |
1376 | break; | 1377 | break; |
1377 | case 1: // cd ... | 1378 | case 1: // cd ... |
1378 | currentSession->getEmulation()->sendString("cd "); | 1379 | currentSession->getEmulation()->sendString("cd "); |
1379 | struct stat statbuf; | 1380 | struct stat statbuf; |
1380 | if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) | 1381 | if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) |
1381 | { | 1382 | { |
1382 | if ( !S_ISDIR(statbuf.st_mode) ) | 1383 | if ( !S_ISDIR(statbuf.st_mode) ) |
1383 | { | 1384 | { |
1384 | /* | 1385 | /* |
1385 | KURL url; | 1386 | KURL url; |
1386 | url.setPath( dropText ); | 1387 | url.setPath( dropText ); |
1387 | dropText = url.directory( true, false ); // remove filename | 1388 | dropText = url.directory( true, false ); // remove filename |
1388 | */ | 1389 | */ |
1389 | } | 1390 | } |
1390 | } | 1391 | } |
1391 | dropText.replace(QRegExp(" "), "\\ "); // escape spaces | 1392 | dropText.replace(QRegExp(" "), "\\ "); // escape spaces |
1392 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1393 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1393 | currentSession->getEmulation()->sendString("\n"); | 1394 | currentSession->getEmulation()->sendString("\n"); |
1394 | // KWM::activate((Window)this->winId()); | 1395 | // KWM::activate((Window)this->winId()); |
1395 | break; | 1396 | break; |
1396 | } | 1397 | } |
1397 | #endif | 1398 | #endif |
1398 | } | 1399 | } |
1399 | 1400 | ||
1400 | void TEWidget::setWrapAt(int columns) | 1401 | void TEWidget::setWrapAt(int columns) |
1401 | { | 1402 | { |
1402 | vcolumns = columns; | 1403 | vcolumns = columns; |
1403 | propagateSize(); | 1404 | propagateSize(); |
1404 | update(); | 1405 | update(); |
1405 | } | 1406 | } |
1406 | |||
1407 | |||
diff --git a/core/apps/embeddedkonsole/TEmulation.h b/core/apps/embeddedkonsole/TEmulation.h index ec15e7a..bf43f11 100644 --- a/core/apps/embeddedkonsole/TEmulation.h +++ b/core/apps/embeddedkonsole/TEmulation.h | |||
@@ -1,117 +1,118 @@ | |||
1 | /* -------------------------------------------------------------------------- */ | 1 | /* -------------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [emulation.h] Fundamental Terminal Emulation */ | 3 | /* [emulation.h] Fundamental Terminal Emulation */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* */ | 10 | /* */ |
11 | /* -------------------------------------------------------------------------- */ | 11 | /* -------------------------------------------------------------------------- */ |
12 | /* */ | 12 | /* */ |
13 | /* Ported Konsole to Qt/Embedded */ | 13 | /* Ported Konsole to Qt/Embedded */ |
14 | /* */ | 14 | /* */ |
15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
16 | /* */ | 16 | /* */ |
17 | /* -------------------------------------------------------------------------- */ | 17 | /* -------------------------------------------------------------------------- */ |
18 | 18 | ||
19 | #ifndef EMULATION_H | 19 | #ifndef EMULATION_H |
20 | #define EMULATION_H | 20 | #define EMULATION_H |
21 | 21 | ||
22 | #include "TEWidget.h" | 22 | #include "TEWidget.h" |
23 | #include "TEScreen.h" | 23 | #include "TEScreen.h" |
24 | #include <qtimer.h> | 24 | #include <qtimer.h> |
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include <qtextcodec.h> | 26 | #include <qtextcodec.h> |
27 | #include "keytrans.h" | 27 | #include "keytrans.h" |
28 | 28 | ||
29 | class TEmulation : public QObject | 29 | class TEmulation : public QObject |
30 | { Q_OBJECT | 30 | { Q_OBJECT |
31 | 31 | ||
32 | public: | 32 | public: |
33 | 33 | ||
34 | TEmulation(TEWidget* gui); | 34 | TEmulation(TEWidget* gui); |
35 | ~TEmulation(); | 35 | ~TEmulation(); |
36 | 36 | ||
37 | public: | 37 | public: |
38 | virtual void setHistory(bool on); | 38 | virtual void setHistory(bool on); |
39 | virtual bool history(); | 39 | virtual bool history(); |
40 | 40 | ||
41 | public slots: // signals incoming from TEWidget | 41 | public slots: // signals incoming from TEWidget |
42 | 42 | ||
43 | virtual void onImageSizeChange(int lines, int columns); | 43 | virtual void onImageSizeChange(int lines, int columns); |
44 | virtual void onHistoryCursorChange(int cursor); | 44 | virtual void onHistoryCursorChange(int cursor); |
45 | virtual void onHorzCursorChange(int cursor); | ||
45 | virtual void onKeyPress(QKeyEvent*); | 46 | virtual void onKeyPress(QKeyEvent*); |
46 | 47 | ||
47 | virtual void clearSelection(); | 48 | virtual void clearSelection(); |
48 | virtual void onSelectionBegin(const int x, const int y); | 49 | virtual void onSelectionBegin(const int x, const int y); |
49 | virtual void onSelectionExtend(const int x, const int y); | 50 | virtual void onSelectionExtend(const int x, const int y); |
50 | virtual void setSelection(const BOOL preserve_line_breaks); | 51 | virtual void setSelection(const BOOL preserve_line_breaks); |
51 | 52 | ||
52 | public slots: // signals incoming from data source | 53 | public slots: // signals incoming from data source |
53 | 54 | ||
54 | void onRcvBlock(const char* txt,int len); | 55 | void onRcvBlock(const char* txt,int len); |
55 | 56 | ||
56 | signals: | 57 | signals: |
57 | 58 | ||
58 | void sndBlock(const char* txt,int len); | 59 | void sndBlock(const char* txt,int len); |
59 | void ImageSizeChanged(int lines, int columns); | 60 | void ImageSizeChanged(int lines, int columns); |
60 | void changeColumns(int columns); | 61 | void changeColumns(int columns); |
61 | void changeTitle(int arg, const char* str); | 62 | void changeTitle(int arg, const char* str); |
62 | 63 | ||
63 | public: | 64 | public: |
64 | 65 | ||
65 | virtual void onRcvChar(int); | 66 | virtual void onRcvChar(int); |
66 | 67 | ||
67 | virtual void setMode (int) = 0; | 68 | virtual void setMode (int) = 0; |
68 | virtual void resetMode(int) = 0; | 69 | virtual void resetMode(int) = 0; |
69 | 70 | ||
70 | virtual void sendString(const char*) = 0; | 71 | virtual void sendString(const char*) = 0; |
71 | 72 | ||
72 | virtual void setConnect(bool r); | 73 | virtual void setConnect(bool r); |
73 | void setColumns(int columns); | 74 | void setColumns(int columns); |
74 | 75 | ||
75 | void setKeytrans(int no); | 76 | void setKeytrans(int no); |
76 | void setKeytrans(const char * no); | 77 | void setKeytrans(const char * no); |
77 | 78 | ||
78 | protected: | 79 | protected: |
79 | 80 | ||
80 | TEWidget* gui; | 81 | TEWidget* gui; |
81 | TEScreen* scr; // referes to one `screen' | 82 | TEScreen* scr; // referes to one `screen' |
82 | TEScreen* screen[2]; // 0 = primary, 1 = alternate | 83 | TEScreen* screen[2]; // 0 = primary, 1 = alternate |
83 | void setScreen(int n); // set `scr' to `screen[n]' | 84 | void setScreen(int n); // set `scr' to `screen[n]' |
84 | 85 | ||
85 | bool connected; // communicate with widget | 86 | bool connected; // communicate with widget |
86 | 87 | ||
87 | void setCodec(int c); // codec number, 0 = locale, 1=utf8 | 88 | void setCodec(int c); // codec number, 0 = locale, 1=utf8 |
88 | 89 | ||
89 | QTextCodec* codec; | 90 | QTextCodec* codec; |
90 | QTextCodec* localeCodec; | 91 | QTextCodec* localeCodec; |
91 | QTextDecoder* decoder; | 92 | QTextDecoder* decoder; |
92 | 93 | ||
93 | KeyTrans* keytrans; | 94 | KeyTrans* keytrans; |
94 | 95 | ||
95 | // refreshing related material. | 96 | // refreshing related material. |
96 | // this is localized in the class. | 97 | // this is localized in the class. |
97 | private slots: // triggered by timer | 98 | private slots: // triggered by timer |
98 | 99 | ||
99 | void showBulk(); | 100 | void showBulk(); |
100 | 101 | ||
101 | private: | 102 | private: |
102 | 103 | ||
103 | void bulkNewline(); | 104 | void bulkNewline(); |
104 | void bulkStart(); | 105 | void bulkStart(); |
105 | void bulkEnd(); | 106 | void bulkEnd(); |
106 | 107 | ||
107 | private: | 108 | private: |
108 | 109 | ||
109 | QTimer bulk_timer; | 110 | QTimer bulk_timer; |
110 | int bulk_nlcnt; // bulk newline counter | 111 | int bulk_nlcnt; // bulk newline counter |
111 | char* SelectedText; | 112 | char* SelectedText; |
112 | int bulk_incnt; // bulk counter | 113 | int bulk_incnt; // bulk counter |
113 | 114 | ||
114 | 115 | ||
115 | }; | 116 | }; |
116 | 117 | ||
117 | #endif // ifndef EMULATION_H | 118 | #endif // ifndef EMULATION_H |
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp index 3c87ad4..16db0ea 100644 --- a/core/apps/embeddedkonsole/konsole.cpp +++ b/core/apps/embeddedkonsole/konsole.cpp | |||
@@ -1,973 +1,1007 @@ | |||
1 | /* ---------------------------------------------------------------------- */ | 1 | /* ---------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [main.C] Konsole */ | 3 | /* [main.C] Konsole */ |
4 | /* */ | 4 | /* */ |
5 | /* ---------------------------------------------------------------------- */ | 5 | /* ---------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole, an X terminal. */ | 9 | /* This file is part of Konsole, an X terminal. */ |
10 | /* */ | 10 | /* */ |
11 | /* The material contained in here more or less directly orginates from */ | 11 | /* The material contained in here more or less directly orginates from */ |
12 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ | 12 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ |
13 | /* */ | 13 | /* */ |
14 | /* ---------------------------------------------------------------------- */ | 14 | /* ---------------------------------------------------------------------- */ |
15 | /* */ | 15 | /* */ |
16 | /* Ported Konsole to Qt/Embedded */ | 16 | /* Ported Konsole to Qt/Embedded */ |
17 | /* */ | 17 | /* */ |
18 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 18 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
19 | /* */ | 19 | /* */ |
20 | /* -------------------------------------------------------------------------- */ | 20 | /* -------------------------------------------------------------------------- */ |
21 | // enhancements added by L.J. Potter <ljp@llornkcor.com> | 21 | // enhancements added by L.J. Potter <ljp@llornkcor.com> |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | 24 | ||
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qevent.h> | 26 | #include <qevent.h> |
27 | #include <qdragobject.h> | 27 | #include <qdragobject.h> |
28 | #include <qobjectlist.h> | 28 | #include <qobjectlist.h> |
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | #include <qpe/qpetoolbar.h> | 30 | #include <qpe/qpetoolbar.h> |
31 | #include <qpushbutton.h> | 31 | #include <qpushbutton.h> |
32 | #include <qfontdialog.h> | 32 | #include <qfontdialog.h> |
33 | #include <qglobal.h> | 33 | #include <qglobal.h> |
34 | #include <qpainter.h> | 34 | #include <qpainter.h> |
35 | #include <qpe/qpemenubar.h> | 35 | #include <qpe/qpemenubar.h> |
36 | #include <qmessagebox.h> | 36 | #include <qmessagebox.h> |
37 | #include <qaction.h> | 37 | #include <qaction.h> |
38 | #include <qapplication.h> | 38 | #include <qapplication.h> |
39 | #include <qfontmetrics.h> | 39 | #include <qfontmetrics.h> |
40 | #include <qcombobox.h> | 40 | #include <qcombobox.h> |
41 | #include <qevent.h> | 41 | #include <qevent.h> |
42 | #include <qtabwidget.h> | 42 | #include <qtabwidget.h> |
43 | #include <qtabbar.h> | 43 | #include <qtabbar.h> |
44 | #include <qpe/config.h> | 44 | #include <qpe/config.h> |
45 | #include <qstringlist.h> | 45 | #include <qstringlist.h> |
46 | #include <qpalette.h> | 46 | #include <qpalette.h> |
47 | 47 | ||
48 | #include <sys/wait.h> | 48 | #include <sys/wait.h> |
49 | #include <stdio.h> | 49 | #include <stdio.h> |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> |
51 | #include <assert.h> | 51 | #include <assert.h> |
52 | 52 | ||
53 | #include "konsole.h" | 53 | #include "konsole.h" |
54 | #include "keytrans.h" | 54 | #include "keytrans.h" |
55 | #include "commandeditdialog.h" | 55 | #include "commandeditdialog.h" |
56 | 56 | ||
57 | #include <opie/colorpopupmenu.h> | 57 | #include <opie/colorpopupmenu.h> |
58 | 58 | ||
59 | class EKNumTabBar : public QTabBar { | 59 | class EKNumTabBar : public QTabBar { |
60 | public: | 60 | public: |
61 | void numberTabs() | 61 | void numberTabs() |
62 | { | 62 | { |
63 | // Yes, it really is this messy. QTabWidget needs functions | 63 | // Yes, it really is this messy. QTabWidget needs functions |
64 | // that provide acces to tabs in a sequential way. | 64 | // that provide acces to tabs in a sequential way. |
65 | int m=INT_MIN; | 65 | int m=INT_MIN; |
66 | for (int i=0; i<count(); i++) { | 66 | for (int i=0; i<count(); i++) { |
67 | QTab* left=0; | 67 | QTab* left=0; |
68 | QListIterator<QTab> it(*tabList()); | 68 | QListIterator<QTab> it(*tabList()); |
69 | int x=INT_MAX; | 69 | int x=INT_MAX; |
70 | for( QTab* t; (t=it.current()); ++it ) { | 70 | for( QTab* t; (t=it.current()); ++it ) { |
71 | int tx = t->rect().x(); | 71 | int tx = t->rect().x(); |
72 | if ( tx<x && tx>m ) { | 72 | if ( tx<x && tx>m ) { |
73 | x = tx; | 73 | x = tx; |
74 | left = t; | 74 | left = t; |
75 | } | 75 | } |
76 | } | 76 | } |
77 | if ( left ) { | 77 | if ( left ) { |
78 | left->setText(QString::number(i+1)); | 78 | left->setText(QString::number(i+1)); |
79 | m = left->rect().x(); | 79 | m = left->rect().x(); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | } | 82 | } |
83 | }; | 83 | }; |
84 | 84 | ||
85 | class EKNumTabWidget : public QTabWidget { | 85 | class EKNumTabWidget : public QTabWidget { |
86 | public: | 86 | public: |
87 | EKNumTabWidget(QWidget* parent) : QTabWidget(parent) | 87 | EKNumTabWidget(QWidget* parent) : QTabWidget(parent) |
88 | { | 88 | { |
89 | } | 89 | } |
90 | 90 | ||
91 | void addTab(QWidget* w) | 91 | void addTab(QWidget* w) |
92 | { | 92 | { |
93 | QTab* t = new QTab(QString::number(tabBar()->count()+1)); | 93 | QTab* t = new QTab(QString::number(tabBar()->count()+1)); |
94 | QTabWidget::addTab(w,t); | 94 | QTabWidget::addTab(w,t); |
95 | } | 95 | } |
96 | 96 | ||
97 | void removeTab(QWidget* w) | 97 | void removeTab(QWidget* w) |
98 | { | 98 | { |
99 | removePage(w); | 99 | removePage(w); |
100 | ((EKNumTabBar*)tabBar())->numberTabs(); | 100 | ((EKNumTabBar*)tabBar())->numberTabs(); |
101 | } | 101 | } |
102 | }; | 102 | }; |
103 | 103 | ||
104 | // This could be configurable or dynamicly generated from the bash history | 104 | // This could be configurable or dynamicly generated from the bash history |
105 | // file of the user | 105 | // file of the user |
106 | static const char *commonCmds[] = | 106 | static const char *commonCmds[] = |
107 | { | 107 | { |
108 | "ls ", // I left this here, cause it looks better than the first alpha | 108 | "ls ", // I left this here, cause it looks better than the first alpha |
109 | "cardctl eject", | 109 | "cardctl eject", |
110 | "cat ", | 110 | "cat ", |
111 | "cd ", | 111 | "cd ", |
112 | "chmod ", | 112 | "chmod ", |
113 | "clear", | 113 | "clear", |
114 | "cp ", | 114 | "cp ", |
115 | "dc ", | 115 | "dc ", |
116 | "df ", | 116 | "df ", |
117 | "dmesg", | 117 | "dmesg", |
118 | "echo ", | 118 | "echo ", |
119 | "env", | 119 | "env", |
120 | "find ", | 120 | "find ", |
121 | "free", | 121 | "free", |
122 | "grep ", | 122 | "grep ", |
123 | "ifconfig ", | 123 | "ifconfig ", |
124 | "ipkg ", | 124 | "ipkg ", |
125 | "mkdir ", | 125 | "mkdir ", |
126 | "mv ", | 126 | "mv ", |
127 | "nc localhost 7776", | 127 | "nc localhost 7776", |
128 | "nc localhost 7777", | 128 | "nc localhost 7777", |
129 | "netstat ", | 129 | "netstat ", |
130 | "nslookup ", | 130 | "nslookup ", |
131 | "ping ", | 131 | "ping ", |
132 | "ps aux", | 132 | "ps aux", |
133 | "pwd ", | 133 | "pwd ", |
134 | "qcop QPE/System 'linkChanged(QString)' ''", | 134 | "qcop QPE/System 'linkChanged(QString)' ''", |
135 | "qcop QPE/System 'restart()'", | 135 | "qcop QPE/System 'restart()'", |
136 | "qcop QPE/System 'quit()'", | 136 | "qcop QPE/System 'quit()'", |
137 | "rm ", | 137 | "rm ", |
138 | "rmdir ", | 138 | "rmdir ", |
139 | "route ", | 139 | "route ", |
140 | "set ", | 140 | "set ", |
141 | "traceroute", | 141 | "traceroute", |
142 | 142 | ||
143 | /* | 143 | /* |
144 | "gzip", | 144 | "gzip", |
145 | "gunzip", | 145 | "gunzip", |
146 | "chgrp", | 146 | "chgrp", |
147 | "chown", | 147 | "chown", |
148 | "date", | 148 | "date", |
149 | "dd", | 149 | "dd", |
150 | "df", | 150 | "df", |
151 | "dmesg", | 151 | "dmesg", |
152 | "fuser", | 152 | "fuser", |
153 | "hostname", | 153 | "hostname", |
154 | "kill", | 154 | "kill", |
155 | "killall", | 155 | "killall", |
156 | "ln", | 156 | "ln", |
157 | "ping", | 157 | "ping", |
158 | "mount", | 158 | "mount", |
159 | "more", | 159 | "more", |
160 | "sort", | 160 | "sort", |
161 | "touch", | 161 | "touch", |
162 | "umount", | 162 | "umount", |
163 | "mknod", | 163 | "mknod", |
164 | "netstat", | 164 | "netstat", |
165 | */ | 165 | */ |
166 | 166 | ||
167 | "exit", | 167 | "exit", |
168 | NULL | 168 | NULL |
169 | }; | 169 | }; |
170 | 170 | ||
171 | 171 | ||
172 | Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : | 172 | Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : |
173 | QMainWindow(parent, name, fl) | 173 | QMainWindow(parent, name, fl) |
174 | { | 174 | { |
175 | QStrList args; | 175 | QStrList args; |
176 | init("/bin/sh",args); | 176 | init("/bin/sh",args); |
177 | } | 177 | } |
178 | 178 | ||
179 | Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) | 179 | Konsole::Konsole(const char* name, const char* _pgm, QStrList & _args, int) |
180 | : QMainWindow(0, name) | 180 | : QMainWindow(0, name) |
181 | { | 181 | { |
182 | init(_pgm,_args); | 182 | init(_pgm,_args); |
183 | } | 183 | } |
184 | 184 | ||
185 | void Konsole::initCommandList() | 185 | void Konsole::initCommandList() |
186 | { | 186 | { |
187 | // qDebug("Konsole::initCommandList"); | 187 | // qDebug("Konsole::initCommandList"); |
188 | Config cfg("Konsole"); | 188 | Config cfg("Konsole"); |
189 | cfg.setGroup("Commands"); | 189 | cfg.setGroup("Commands"); |
190 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); | 190 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); |
191 | commonCombo->clear(); | 191 | commonCombo->clear(); |
192 | if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { | 192 | if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { |
193 | for (int i = 0; commonCmds[i] != NULL; i++) { | 193 | for (int i = 0; commonCmds[i] != NULL; i++) { |
194 | commonCombo->insertItem(commonCmds[i],i); | 194 | commonCombo->insertItem(commonCmds[i],i); |
195 | } | 195 | } |
196 | } else { | 196 | } else { |
197 | for (int i = 0; i < 100; i++) { | 197 | for (int i = 0; i < 100; i++) { |
198 | if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) | 198 | if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) |
199 | commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); | 199 | commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); |
200 | } | 200 | } |
201 | } | 201 | } |
202 | 202 | ||
203 | } | 203 | } |
204 | 204 | ||
205 | void Konsole::init(const char* _pgm, QStrList & _args) | 205 | void Konsole::init(const char* _pgm, QStrList & _args) |
206 | { | 206 | { |
207 | b_scroll = TRUE; // histon; | 207 | b_scroll = TRUE; // histon; |
208 | n_keytab = 0; | 208 | n_keytab = 0; |
209 | n_render = 0; | 209 | n_render = 0; |
210 | startUp=0; | 210 | startUp=0; |
211 | fromMenu = FALSE; | 211 | fromMenu = FALSE; |
212 | 212 | ||
213 | setCaption( tr("Terminal") ); | 213 | setCaption( tr("Terminal") ); |
214 | setIcon( Resource::loadPixmap( "konsole" ) ); | 214 | setIcon( Resource::loadPixmap( "konsole" ) ); |
215 | 215 | ||
216 | Config cfg("Konsole"); | 216 | Config cfg("Konsole"); |
217 | cfg.setGroup("Konsole"); | 217 | cfg.setGroup("Konsole"); |
218 | QString tmp; | 218 | QString tmp; |
219 | // initialize the list of allowed fonts /////////////////////////////////// | 219 | // initialize the list of allowed fonts /////////////////////////////////// |
220 | cfont = cfg.readNumEntry("FontID", 1); | 220 | cfont = cfg.readNumEntry("FontID", 1); |
221 | QFont f = QFont("Micro", 4, QFont::Normal); | 221 | QFont f = QFont("Micro", 4, QFont::Normal); |
222 | f.setFixedPitch(TRUE); | 222 | f.setFixedPitch(TRUE); |
223 | fonts.append(new VTFont(tr("Micro"), f)); | 223 | fonts.append(new VTFont(tr("Micro"), f)); |
224 | 224 | ||
225 | f = QFont("Fixed", 7, QFont::Normal); | 225 | f = QFont("Fixed", 7, QFont::Normal); |
226 | f.setFixedPitch(TRUE); | 226 | f.setFixedPitch(TRUE); |
227 | fonts.append(new VTFont(tr("Small Fixed"), f)); | 227 | fonts.append(new VTFont(tr("Small Fixed"), f)); |
228 | 228 | ||
229 | f = QFont("Fixed", 12, QFont::Normal); | 229 | f = QFont("Fixed", 12, QFont::Normal); |
230 | f.setFixedPitch(TRUE); | 230 | f.setFixedPitch(TRUE); |
231 | fonts.append(new VTFont(tr("Medium Fixed"), f)); | 231 | fonts.append(new VTFont(tr("Medium Fixed"), f)); |
232 | 232 | ||
233 | // create terminal emulation framework //////////////////////////////////// | 233 | // create terminal emulation framework //////////////////////////////////// |
234 | nsessions = 0; | 234 | nsessions = 0; |
235 | 235 | ||
236 | tab = new EKNumTabWidget(this); | 236 | tab = new EKNumTabWidget(this); |
237 | 237 | ||
238 | connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); | 238 | connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); |
239 | 239 | ||
240 | // create terminal toolbar //////////////////////////////////////////////// | 240 | // create terminal toolbar //////////////////////////////////////////////// |
241 | setToolBarsMovable( FALSE ); | 241 | setToolBarsMovable( FALSE ); |
242 | QPEToolBar *menuToolBar = new QPEToolBar( this ); | 242 | QPEToolBar *menuToolBar = new QPEToolBar( this ); |
243 | menuToolBar->setHorizontalStretchable( TRUE ); | 243 | menuToolBar->setHorizontalStretchable( TRUE ); |
244 | 244 | ||
245 | QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar ); | 245 | QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar ); |
246 | 246 | ||
247 | fontList = new QPopupMenu( this ); | 247 | fontList = new QPopupMenu( this ); |
248 | for(uint i = 0; i < fonts.count(); i++) { | 248 | for(uint i = 0; i < fonts.count(); i++) { |
249 | VTFont *fnt = fonts.at(i); | 249 | VTFont *fnt = fonts.at(i); |
250 | fontList->insertItem(fnt->getName(), i); | 250 | fontList->insertItem(fnt->getName(), i); |
251 | } | 251 | } |
252 | fontChanged(cfont); | 252 | fontChanged(cfont); |
253 | 253 | ||
254 | configMenu = new QPopupMenu( this); | 254 | configMenu = new QPopupMenu( this); |
255 | colorMenu = new QPopupMenu( this); | 255 | colorMenu = new QPopupMenu( this); |
256 | scrollMenu = new QPopupMenu( this); | 256 | scrollMenu = new QPopupMenu( this); |
257 | editCommandListMenu = new QPopupMenu( this); | 257 | editCommandListMenu = new QPopupMenu( this); |
258 | 258 | ||
259 | configMenu->insertItem(tr("Command List"), editCommandListMenu); | 259 | configMenu->insertItem(tr("Command List"), editCommandListMenu); |
260 | 260 | ||
261 | bool listHidden; | 261 | bool listHidden; |
262 | cfg.setGroup("Menubar"); | 262 | cfg.setGroup("Menubar"); |
263 | if( cfg.readEntry("Hidden","FALSE") == "TRUE") { | 263 | if( cfg.readEntry("Hidden","FALSE") == "TRUE") { |
264 | editCommandListMenu->insertItem( tr( "Show command list" )); | 264 | editCommandListMenu->insertItem( tr( "Show command list" )); |
265 | listHidden=TRUE; | 265 | listHidden=TRUE; |
266 | } else { | 266 | } else { |
267 | editCommandListMenu->insertItem( tr( "Hide command list" )); | 267 | editCommandListMenu->insertItem( tr( "Hide command list" )); |
268 | listHidden=FALSE; | 268 | listHidden=FALSE; |
269 | } | 269 | } |
270 | 270 | ||
271 | cfg.setGroup("Tabs"); | 271 | cfg.setGroup("Tabs"); |
272 | tmp=cfg.readEntry("Position","Bottom"); | 272 | tmp=cfg.readEntry("Position","Bottom"); |
273 | if(tmp=="Top") { | 273 | if(tmp=="Top") { |
274 | tab->setTabPosition(QTabWidget::Top); | 274 | tab->setTabPosition(QTabWidget::Top); |
275 | configMenu->insertItem( tr( "Tabs on Bottom" ) ); | 275 | configMenu->insertItem( tr( "Tabs on Bottom" ) ); |
276 | } else { | 276 | } else { |
277 | tab->setTabPosition(QTabWidget::Bottom); | 277 | tab->setTabPosition(QTabWidget::Bottom); |
278 | configMenu->insertItem("Tabs on Top"); | 278 | configMenu->insertItem("Tabs on Top"); |
279 | } | 279 | } |
280 | configMenu->insertSeparator(2); | 280 | configMenu->insertSeparator(2); |
281 | 281 | ||
282 | colorMenu->insertItem(tr( "Green on Black")); | 282 | colorMenu->insertItem(tr( "Green on Black")); |
283 | colorMenu->insertItem(tr( "Black on White")); | 283 | colorMenu->insertItem(tr( "Black on White")); |
284 | colorMenu->insertItem(tr( "White on Black")); | 284 | colorMenu->insertItem(tr( "White on Black")); |
285 | colorMenu->insertItem(tr( "Black on Transparent")); | 285 | colorMenu->insertItem(tr( "Black on Transparent")); |
286 | colorMenu->insertItem(tr( "Black on Red")); | 286 | colorMenu->insertItem(tr( "Black on Red")); |
287 | colorMenu->insertItem(tr( "Red on Black")); | 287 | colorMenu->insertItem(tr( "Red on Black")); |
288 | colorMenu->insertItem(tr( "Green on Yellow")); | 288 | colorMenu->insertItem(tr( "Green on Yellow")); |
289 | colorMenu->insertItem(tr( "Blue on Magenta")); | 289 | colorMenu->insertItem(tr( "Blue on Magenta")); |
290 | colorMenu->insertItem(tr( "Magenta on Blue")); | 290 | colorMenu->insertItem(tr( "Magenta on Blue")); |
291 | colorMenu->insertItem(tr( "Cyan on White")); | 291 | colorMenu->insertItem(tr( "Cyan on White")); |
292 | colorMenu->insertItem(tr( "White on Cyan")); | 292 | colorMenu->insertItem(tr( "White on Cyan")); |
293 | colorMenu->insertItem(tr( "Blue on Black")); | 293 | colorMenu->insertItem(tr( "Blue on Black")); |
294 | colorMenu->insertItem(tr( "Amber on Black")); | 294 | colorMenu->insertItem(tr( "Amber on Black")); |
295 | colorMenu->insertItem(tr( "Custom")); | 295 | colorMenu->insertItem(tr( "Custom")); |
296 | configMenu->insertItem(tr( "Colors") ,colorMenu); | 296 | configMenu->insertItem(tr( "Colors") ,colorMenu); |
297 | 297 | ||
298 | connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); | 298 | connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); |
299 | connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); | 299 | connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); |
300 | connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) )); | 300 | connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) )); |
301 | connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int))); | 301 | connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int))); |
302 | connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int))); | 302 | connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int))); |
303 | menuBar->insertItem( tr("Font"), fontList ); | 303 | menuBar->insertItem( tr("Font"), fontList ); |
304 | menuBar->insertItem( tr("Options"), configMenu ); | 304 | menuBar->insertItem( tr("Options"), configMenu ); |
305 | 305 | ||
306 | QPEToolBar *toolbar = new QPEToolBar( this ); | 306 | QPEToolBar *toolbar = new QPEToolBar( this ); |
307 | 307 | ||
308 | QAction *a; | 308 | QAction *a; |
309 | 309 | ||
310 | // Button Commands | 310 | // Button Commands |
311 | a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 ); | 311 | a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 ); |
312 | connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar ); | 312 | connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar ); |
313 | a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 ); | 313 | a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 ); |
314 | connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar ); | 314 | connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar ); |
315 | a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 ); | 315 | a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 ); |
316 | connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar ); | 316 | connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar ); |
317 | a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 ); | 317 | a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 ); |
318 | connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar ); | 318 | connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar ); |
319 | a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 ); | 319 | a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 ); |
320 | connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); | 320 | connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); |
321 | a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 ); | 321 | a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 ); |
322 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); | 322 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); |
323 | a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 323 | a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
324 | connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar ); | 324 | connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar ); |
325 | /* | 325 | /* |
326 | a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 ); | 326 | a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 ); |
327 | connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); | 327 | connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); |
328 | a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 ); | 328 | a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 ); |
329 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); | 329 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); |
330 | */ | 330 | */ |
331 | 331 | ||
332 | secondToolBar = new QPEToolBar( this ); | 332 | secondToolBar = new QPEToolBar( this ); |
333 | secondToolBar->setHorizontalStretchable( TRUE ); | 333 | secondToolBar->setHorizontalStretchable( TRUE ); |
334 | 334 | ||
335 | commonCombo = new QComboBox( secondToolBar ); | 335 | commonCombo = new QComboBox( secondToolBar ); |
336 | commonCombo->setMaximumWidth(236); | 336 | commonCombo->setMaximumWidth(236); |
337 | 337 | ||
338 | editCommandListMenu->insertItem( tr( "Quick Edit" ) ); | 338 | editCommandListMenu->insertItem( tr( "Quick Edit" ) ); |
339 | if( listHidden) { | 339 | if( listHidden) { |
340 | secondToolBar->hide(); | 340 | secondToolBar->hide(); |
341 | editCommandListMenu->setItemEnabled(-23 ,FALSE); | 341 | editCommandListMenu->setItemEnabled(-23 ,FALSE); |
342 | } | 342 | } |
343 | editCommandListMenu->insertItem(tr( "Edit" ) ); | 343 | editCommandListMenu->insertItem(tr( "Edit" ) ); |
344 | 344 | ||
345 | cfg.setGroup("Commands"); | 345 | cfg.setGroup("Commands"); |
346 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); | 346 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); |
347 | 347 | ||
348 | initCommandList(); | 348 | initCommandList(); |
349 | // for (int i = 0; commonCmds[i] != NULL; i++) { | 349 | // for (int i = 0; commonCmds[i] != NULL; i++) { |
350 | // commonCombo->insertItem( commonCmds[i], i ); | 350 | // commonCombo->insertItem( commonCmds[i], i ); |
351 | // tmp = cfg.readEntry( QString::number(i),""); | 351 | // tmp = cfg.readEntry( QString::number(i),""); |
352 | // if(tmp != "") | 352 | // if(tmp != "") |
353 | // commonCombo->changeItem( tmp,i ); | 353 | // commonCombo->changeItem( tmp,i ); |
354 | // } | 354 | // } |
355 | 355 | ||
356 | connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); | 356 | connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); |
357 | 357 | ||
358 | scrollMenu->insertItem(tr( "None" )); | 358 | scrollMenu->insertItem(tr( "None" )); |
359 | scrollMenu->insertItem(tr( "Left" )); | 359 | scrollMenu->insertItem(tr( "Left" )); |
360 | scrollMenu->insertItem(tr( "Right" )); | 360 | scrollMenu->insertItem(tr( "Right" )); |
361 | scrollMenu->insertSeparator(4); | 361 | // scrollMenu->insertSeparator(4); |
362 | scrollMenu->insertItem(tr( "Horizontal" )); | 362 | // scrollMenu->insertItem(tr( "Horizontal" )); |
363 | 363 | ||
364 | configMenu->insertItem(tr( "ScrollBar" ),scrollMenu); | 364 | configMenu->insertItem(tr( "ScrollBar" ),scrollMenu); |
365 | |||
366 | configMenu->insertItem(tr( "Wrap" )); | ||
367 | |||
365 | //scrollMenuSelected(-29); | 368 | //scrollMenuSelected(-29); |
366 | // cfg.setGroup("ScrollBar"); | 369 | // cfg.setGroup("ScrollBar"); |
367 | // if(cfg.readBoolEntry("HorzScroll",0)) { | 370 | // if(cfg.readBoolEntry("HorzScroll",0)) { |
368 | // if(cfg.readNumEntry("Position",2) == 0) | 371 | // if(cfg.readNumEntry("Position",2) == 0) |
369 | // te->setScrollbarLocation(1); | 372 | // te->setScrollbarLocation(1); |
370 | // else | 373 | // else |
371 | // te->setScrollbarLocation(0); | 374 | // te->setScrollbarLocation(0); |
372 | // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); | 375 | // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); |
373 | // te->setWrapAt(120); | 376 | // te->setWrapAt(120); |
374 | // } | 377 | // } |
375 | // create applications ///////////////////////////////////////////////////// | 378 | // create applications ///////////////////////////////////////////////////// |
376 | setCentralWidget(tab); | 379 | setCentralWidget(tab); |
377 | 380 | ||
378 | // load keymaps //////////////////////////////////////////////////////////// | 381 | // load keymaps //////////////////////////////////////////////////////////// |
379 | KeyTrans::loadAll(); | 382 | KeyTrans::loadAll(); |
380 | for (int i = 0; i < KeyTrans::count(); i++) | 383 | for (int i = 0; i < KeyTrans::count(); i++) |
381 | { KeyTrans* s = KeyTrans::find(i); | 384 | { KeyTrans* s = KeyTrans::find(i); |
382 | assert( s ); | 385 | assert( s ); |
383 | } | 386 | } |
384 | 387 | ||
385 | se_pgm = _pgm; | 388 | se_pgm = _pgm; |
386 | se_args = _args; | 389 | se_args = _args; |
387 | se_args.prepend("--login"); | 390 | se_args.prepend("--login"); |
388 | parseCommandLine(); | 391 | parseCommandLine(); |
389 | // read and apply default values /////////////////////////////////////////// | 392 | // read and apply default values /////////////////////////////////////////// |
390 | resize(321, 321); // Dummy. | 393 | resize(321, 321); // Dummy. |
391 | QSize currentSize = size(); | 394 | QSize currentSize = size(); |
392 | if (currentSize != size()) | 395 | if (currentSize != size()) |
393 | defaultSize = size(); | 396 | defaultSize = size(); |
394 | } | 397 | } |
395 | 398 | ||
396 | void Konsole::show() | 399 | void Konsole::show() |
397 | { | 400 | { |
398 | if ( !nsessions ) { | 401 | if ( !nsessions ) { |
399 | newSession(); | 402 | newSession(); |
400 | } | 403 | } |
401 | QMainWindow::show(); | 404 | QMainWindow::show(); |
405 | |||
402 | } | 406 | } |
403 | 407 | ||
404 | void Konsole::initSession(const char*, QStrList &) | 408 | void Konsole::initSession(const char*, QStrList &) |
405 | { | 409 | { |
406 | QMainWindow::show(); | 410 | QMainWindow::show(); |
407 | } | 411 | } |
408 | 412 | ||
409 | Konsole::~Konsole() | 413 | Konsole::~Konsole() |
410 | { | 414 | { |
411 | while (nsessions > 0) { | 415 | while (nsessions > 0) { |
412 | doneSession(getTe()->currentSession, 0); | 416 | doneSession(getTe()->currentSession, 0); |
413 | } | 417 | } |
414 | 418 | ||
415 | Config cfg("Konsole"); | 419 | Config cfg("Konsole"); |
416 | cfg.setGroup("Konsole"); | 420 | cfg.setGroup("Konsole"); |
417 | cfg.writeEntry("FontID", cfont); | 421 | cfg.writeEntry("FontID", cfont); |
418 | } | 422 | } |
419 | 423 | ||
420 | void Konsole::fontChanged(int f) | 424 | void Konsole::fontChanged(int f) |
421 | { | 425 | { |
422 | VTFont* font = fonts.at(f); | 426 | VTFont* font = fonts.at(f); |
423 | if (font != 0) { | 427 | if (font != 0) { |
424 | for(uint i = 0; i < fonts.count(); i++) { | 428 | for(uint i = 0; i < fonts.count(); i++) { |
425 | fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE); | 429 | fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE); |
426 | } | 430 | } |
427 | 431 | ||
428 | cfont = f; | 432 | cfont = f; |
429 | 433 | ||
430 | TEWidget* te = getTe(); | 434 | TEWidget* te = getTe(); |
431 | if (te != 0) { | 435 | if (te != 0) { |
432 | te->setVTFont(font->getFont()); | 436 | te->setVTFont(font->getFont()); |
433 | } | 437 | } |
434 | } | 438 | } |
435 | } | 439 | } |
436 | 440 | ||
437 | 441 | ||
438 | void Konsole::enterCommand(int c) | 442 | void Konsole::enterCommand(int c) |
439 | { | 443 | { |
440 | TEWidget* te = getTe(); | 444 | TEWidget* te = getTe(); |
441 | if (te != 0) { | 445 | if (te != 0) { |
442 | if(!commonCombo->editable()) { | 446 | if(!commonCombo->editable()) { |
443 | QString text = commonCombo->text(c); //commonCmds[c]; | 447 | QString text = commonCombo->text(c); //commonCmds[c]; |
444 | te->emitText(text); | 448 | te->emitText(text); |
445 | } else { | 449 | } else { |
446 | changeCommand( commonCombo->text(c), c); | 450 | changeCommand( commonCombo->text(c), c); |
447 | } | 451 | } |
448 | } | 452 | } |
449 | } | 453 | } |
450 | 454 | ||
451 | void Konsole::hitEnter() | 455 | void Konsole::hitEnter() |
452 | { | 456 | { |
453 | TEWidget* te = getTe(); | 457 | TEWidget* te = getTe(); |
454 | if (te != 0) { | 458 | if (te != 0) { |
455 | te->emitText(QString("\r")); | 459 | te->emitText(QString("\r")); |
456 | } | 460 | } |
457 | } | 461 | } |
458 | 462 | ||
459 | void Konsole::hitSpace() | 463 | void Konsole::hitSpace() |
460 | { | 464 | { |
461 | TEWidget* te = getTe(); | 465 | TEWidget* te = getTe(); |
462 | if (te != 0) { | 466 | if (te != 0) { |
463 | te->emitText(QString(" ")); | 467 | te->emitText(QString(" ")); |
464 | } | 468 | } |
465 | } | 469 | } |
466 | 470 | ||
467 | void Konsole::hitTab() | 471 | void Konsole::hitTab() |
468 | { | 472 | { |
469 | TEWidget* te = getTe(); | 473 | TEWidget* te = getTe(); |
470 | if (te != 0) { | 474 | if (te != 0) { |
471 | te->emitText(QString("\t")); | 475 | te->emitText(QString("\t")); |
472 | } | 476 | } |
473 | } | 477 | } |
474 | 478 | ||
475 | void Konsole::hitPaste() | 479 | void Konsole::hitPaste() |
476 | { | 480 | { |
477 | TEWidget* te = getTe(); | 481 | TEWidget* te = getTe(); |
478 | if (te != 0) { | 482 | if (te != 0) { |
479 | te->pasteClipboard(); | 483 | te->pasteClipboard(); |
480 | } | 484 | } |
481 | } | 485 | } |
482 | 486 | ||
483 | void Konsole::hitUp() | 487 | void Konsole::hitUp() |
484 | { | 488 | { |
485 | TEWidget* te = getTe(); | 489 | TEWidget* te = getTe(); |
486 | if (te != 0) { | 490 | if (te != 0) { |
487 | QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); | 491 | QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); |
488 | QApplication::sendEvent( te, &ke ); | 492 | QApplication::sendEvent( te, &ke ); |
489 | } | 493 | } |
490 | } | 494 | } |
491 | 495 | ||
492 | void Konsole::hitDown() | 496 | void Konsole::hitDown() |
493 | { | 497 | { |
494 | TEWidget* te = getTe(); | 498 | TEWidget* te = getTe(); |
495 | if (te != 0) { | 499 | if (te != 0) { |
496 | QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); | 500 | QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); |
497 | QApplication::sendEvent( te, &ke ); | 501 | QApplication::sendEvent( te, &ke ); |
498 | } | 502 | } |
499 | } | 503 | } |
500 | 504 | ||
501 | /** | 505 | /** |
502 | This function calculates the size of the external widget | 506 | This function calculates the size of the external widget |
503 | needed for the internal widget to be | 507 | needed for the internal widget to be |
504 | */ | 508 | */ |
505 | QSize Konsole::calcSize(int columns, int lines) { | 509 | QSize Konsole::calcSize(int columns, int lines) { |
506 | TEWidget* te = getTe(); | 510 | TEWidget* te = getTe(); |
507 | if (te != 0) { | 511 | if (te != 0) { |
508 | QSize size = te->calcSize(columns, lines); | 512 | QSize size = te->calcSize(columns, lines); |
509 | return size; | 513 | return size; |
510 | } else { | 514 | } else { |
511 | QSize size; | 515 | QSize size; |
512 | return size; | 516 | return size; |
513 | } | 517 | } |
514 | } | 518 | } |
515 | 519 | ||
516 | /** | 520 | /** |
517 | sets application window to a size based on columns X lines of the te | 521 | sets application window to a size based on columns X lines of the te |
518 | guest widget. Call with (0,0) for setting default size. | 522 | guest widget. Call with (0,0) for setting default size. |
519 | */ | 523 | */ |
520 | 524 | ||
521 | void Konsole::setColLin(int columns, int lines) | 525 | void Konsole::setColLin(int columns, int lines) |
522 | { | 526 | { |
523 | qDebug("konsole::setColLin:: Columns %d", columns); | 527 | qDebug("konsole::setColLin:: Columns %d", columns); |
524 | 528 | ||
525 | if ((columns==0) || (lines==0)) | 529 | if ((columns==0) || (lines==0)) |
526 | { | 530 | { |
527 | if (defaultSize.isEmpty()) // not in config file : set default value | 531 | if (defaultSize.isEmpty()) // not in config file : set default value |
528 | { | 532 | { |
529 | defaultSize = calcSize(80,24); | 533 | defaultSize = calcSize(80,24); |
530 | // notifySize(24,80); // set menu items (strange arg order !) | 534 | // notifySize(24,80); // set menu items (strange arg order !) |
531 | } | 535 | } |
532 | resize(defaultSize); | 536 | resize(defaultSize); |
533 | } else { | 537 | } else { |
534 | resize(calcSize(columns, lines)); | 538 | resize(calcSize(columns, lines)); |
535 | // notifySize(lines,columns); // set menu items (strange arg order !) | 539 | // notifySize(lines,columns); // set menu items (strange arg order !) |
536 | } | 540 | } |
537 | } | 541 | } |
538 | 542 | ||
539 | /* | 543 | /* |
540 | void Konsole::setFont(int fontno) | 544 | void Konsole::setFont(int fontno) |
541 | { | 545 | { |
542 | QFont f; | 546 | QFont f; |
543 | if (fontno == 0) | 547 | if (fontno == 0) |
544 | f = defaultFont = QFont( "Helvetica", 12 ); | 548 | f = defaultFont = QFont( "Helvetica", 12 ); |
545 | else | 549 | else |
546 | if (fonts[fontno][0] == '-') | 550 | if (fonts[fontno][0] == '-') |
547 | f.setRawName( fonts[fontno] ); | 551 | f.setRawName( fonts[fontno] ); |
548 | else | 552 | else |
549 | { | 553 | { |
550 | f.setFamily(fonts[fontno]); | 554 | f.setFamily(fonts[fontno]); |
551 | f.setRawMode( TRUE ); | 555 | f.setRawMode( TRUE ); |
552 | } | 556 | } |
553 | if ( !f.exactMatch() && fontno != 0) | 557 | if ( !f.exactMatch() && fontno != 0) |
554 | { | 558 | { |
555 | QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); | 559 | QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); |
556 | QMessageBox(this, msg); | 560 | QMessageBox(this, msg); |
557 | return; | 561 | return; |
558 | } | 562 | } |
559 | if (se) se->setFontNo(fontno); | 563 | if (se) se->setFontNo(fontno); |
560 | te->setVTFont(f); | 564 | te->setVTFont(f); |
561 | n_font = fontno; | 565 | n_font = fontno; |
562 | } | 566 | } |
563 | */ | 567 | */ |
564 | 568 | ||
565 | // --| color selection |------------------------------------------------------- | 569 | // --| color selection |------------------------------------------------------- |
566 | 570 | ||
567 | void Konsole::changeColumns(int columns) | 571 | void Konsole::changeColumns(int columns) |
568 | { | 572 | { |
569 | qDebug("change columns"); | 573 | qDebug("change columns"); |
570 | TEWidget* te = getTe(); | 574 | TEWidget* te = getTe(); |
571 | if (te != 0) { | 575 | if (te != 0) { |
572 | setColLin(columns,te->Lines()); | 576 | setColLin(columns,te->Lines()); |
573 | te->update(); | 577 | te->update(); |
574 | } | 578 | } |
575 | } | 579 | } |
576 | 580 | ||
577 | //FIXME: If a child dies during session swap, | 581 | //FIXME: If a child dies during session swap, |
578 | // this routine might be called before | 582 | // this routine might be called before |
579 | // session swap is completed. | 583 | // session swap is completed. |
580 | 584 | ||
581 | void Konsole::doneSession(TESession*, int ) | 585 | void Konsole::doneSession(TESession*, int ) |
582 | { | 586 | { |
583 | TEWidget *te = getTe(); | 587 | TEWidget *te = getTe(); |
584 | if (te != 0) { | 588 | if (te != 0) { |
585 | te->currentSession->setConnect(FALSE); | 589 | te->currentSession->setConnect(FALSE); |
586 | tab->removeTab(te); | 590 | tab->removeTab(te); |
587 | delete te->currentSession; | 591 | delete te->currentSession; |
588 | delete te; | 592 | delete te; |
589 | nsessions--; | 593 | nsessions--; |
590 | } | 594 | } |
591 | 595 | ||
592 | if (nsessions == 0) { | 596 | if (nsessions == 0) { |
593 | close(); | 597 | close(); |
594 | } | 598 | } |
595 | } | 599 | } |
596 | 600 | ||
597 | void Konsole::newSession() { | 601 | void Konsole::newSession() { |
598 | if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? | 602 | if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? |
599 | TEWidget* te = new TEWidget(tab); | 603 | TEWidget* te = new TEWidget(tab); |
600 | // te->setBackgroundMode(PaletteBase); //we want transparent!! | 604 | // te->setBackgroundMode(PaletteBase); //we want transparent!! |
601 | te->setVTFont(fonts.at(cfont)->getFont()); | 605 | te->setVTFont(fonts.at(cfont)->getFont()); |
602 | tab->addTab(te); | 606 | tab->addTab(te); |
603 | TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); | 607 | TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); |
604 | te->currentSession = se; | 608 | te->currentSession = se; |
605 | connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) ); | 609 | connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) ); |
606 | se->run(); | 610 | se->run(); |
607 | se->setConnect(TRUE); | 611 | se->setConnect(TRUE); |
608 | se->setHistory(b_scroll); | 612 | se->setHistory(b_scroll); |
609 | tab->setCurrentPage(nsessions); | 613 | tab->setCurrentPage(nsessions); |
610 | nsessions++; | 614 | nsessions++; |
611 | setColor(); | 615 | doWrap(); |
616 | setColor(); | ||
612 | } | 617 | } |
613 | } | 618 | } |
614 | 619 | ||
615 | TEWidget* Konsole::getTe() { | 620 | TEWidget* Konsole::getTe() { |
616 | if (nsessions) { | 621 | if (nsessions) { |
617 | return (TEWidget *) tab->currentPage(); | 622 | return (TEWidget *) tab->currentPage(); |
618 | } else { | 623 | } else { |
619 | return 0; | 624 | return 0; |
620 | } | 625 | } |
621 | } | 626 | } |
622 | 627 | ||
623 | void Konsole::switchSession(QWidget* w) { | 628 | void Konsole::switchSession(QWidget* w) { |
624 | TEWidget* te = (TEWidget *) w; | 629 | TEWidget* te = (TEWidget *) w; |
625 | 630 | ||
626 | QFont teFnt = te->getVTFont(); | 631 | QFont teFnt = te->getVTFont(); |
627 | for(uint i = 0; i < fonts.count(); i++) { | 632 | for(uint i = 0; i < fonts.count(); i++) { |
628 | VTFont *fnt = fonts.at(i); | 633 | VTFont *fnt = fonts.at(i); |
629 | bool cf = fnt->getFont() == teFnt; | 634 | bool cf = fnt->getFont() == teFnt; |
630 | fontList->setItemChecked(i, cf); | 635 | fontList->setItemChecked(i, cf); |
631 | if (cf) { | 636 | if (cf) { |
632 | cfont = i; | 637 | cfont = i; |
633 | } | 638 | } |
634 | } | 639 | } |
635 | } | 640 | } |
636 | 641 | ||
637 | void Konsole::colorMenuIsSelected(int iD) { | 642 | void Konsole::colorMenuIsSelected(int iD) { |
638 | fromMenu = TRUE; | 643 | fromMenu = TRUE; |
639 | colorMenuSelected(iD); | 644 | colorMenuSelected(iD); |
640 | } | 645 | } |
641 | 646 | ||
642 | /// ------------------------------- some new stuff by L.J. Potter | 647 | /// ------------------------------- some new stuff by L.J. Potter |
643 | void Konsole::colorMenuSelected(int iD) | 648 | void Konsole::colorMenuSelected(int iD) |
644 | { // this is NOT pretty, elegant or anything else besides functional | 649 | { // this is NOT pretty, elegant or anything else besides functional |
645 | // QString temp; | 650 | // QString temp; |
646 | // qDebug( temp.sprintf("colormenu %d", iD)); | 651 | // qDebug( temp.sprintf("colormenu %d", iD)); |
647 | TEWidget* te = getTe(); | 652 | TEWidget* te = getTe(); |
648 | Config cfg("Konsole"); | 653 | Config cfg("Konsole"); |
649 | cfg.setGroup("Colors"); | 654 | cfg.setGroup("Colors"); |
650 | // QColor foreground; | 655 | // QColor foreground; |
651 | // QColor background; | 656 | // QColor background; |
652 | colorMenu->setItemChecked(lastSelectedMenu,FALSE); | 657 | colorMenu->setItemChecked(lastSelectedMenu,FALSE); |
653 | ColorEntry m_table[TABLE_COLORS]; | 658 | ColorEntry m_table[TABLE_COLORS]; |
654 | const ColorEntry * defaultCt=te->getdefaultColorTable(); | 659 | const ColorEntry * defaultCt=te->getdefaultColorTable(); |
655 | /////////// fore back | 660 | /////////// fore back |
656 | int i; | 661 | int i; |
657 | if(iD==-9) { // default default | 662 | if(iD==-9) { // default default |
658 | for (i = 0; i < TABLE_COLORS; i++) { | 663 | for (i = 0; i < TABLE_COLORS; i++) { |
659 | m_table[i].color = defaultCt[i].color; | 664 | m_table[i].color = defaultCt[i].color; |
660 | if(i==1 || i == 11) | 665 | if(i==1 || i == 11) |
661 | m_table[i].transparent=1; | 666 | m_table[i].transparent=1; |
662 | cfg.writeEntry("Schema","9"); | 667 | cfg.writeEntry("Schema","9"); |
663 | colorMenu->setItemChecked(-9,TRUE); | 668 | colorMenu->setItemChecked(-9,TRUE); |
664 | } | 669 | } |
665 | } else { | 670 | } else { |
666 | if(iD==-6) { // green black | 671 | if(iD==-6) { // green black |
667 | foreground.setRgb(0x18,255,0x18); | 672 | foreground.setRgb(0x18,255,0x18); |
668 | background.setRgb(0x00,0x00,0x00); | 673 | background.setRgb(0x00,0x00,0x00); |
669 | cfg.writeEntry("Schema","6"); | 674 | cfg.writeEntry("Schema","6"); |
670 | colorMenu->setItemChecked(-6,TRUE); | 675 | colorMenu->setItemChecked(-6,TRUE); |
671 | } | 676 | } |
672 | if(iD==-7) { // black white | 677 | if(iD==-7) { // black white |
673 | foreground.setRgb(0x00,0x00,0x00); | 678 | foreground.setRgb(0x00,0x00,0x00); |
674 | background.setRgb(0xFF,0xFF,0xFF); | 679 | background.setRgb(0xFF,0xFF,0xFF); |
675 | cfg.writeEntry("Schema","7"); | 680 | cfg.writeEntry("Schema","7"); |
676 | colorMenu->setItemChecked(-7,TRUE); | 681 | colorMenu->setItemChecked(-7,TRUE); |
677 | } | 682 | } |
678 | if(iD==-8) { // white black | 683 | if(iD==-8) { // white black |
679 | foreground.setRgb(0xFF,0xFF,0xFF); | 684 | foreground.setRgb(0xFF,0xFF,0xFF); |
680 | background.setRgb(0x00,0x00,0x00); | 685 | background.setRgb(0x00,0x00,0x00); |
681 | cfg.writeEntry("Schema","8"); | 686 | cfg.writeEntry("Schema","8"); |
682 | colorMenu->setItemChecked(-8,TRUE); | 687 | colorMenu->setItemChecked(-8,TRUE); |
683 | } | 688 | } |
684 | if(iD==-10) {// Black, Red | 689 | if(iD==-10) {// Black, Red |
685 | foreground.setRgb(0x00,0x00,0x00); | 690 | foreground.setRgb(0x00,0x00,0x00); |
686 | background.setRgb(0xB2,0x18,0x18); | 691 | background.setRgb(0xB2,0x18,0x18); |
687 | cfg.writeEntry("Schema","10"); | 692 | cfg.writeEntry("Schema","10"); |
688 | colorMenu->setItemChecked(-10,TRUE); | 693 | colorMenu->setItemChecked(-10,TRUE); |
689 | } | 694 | } |
690 | if(iD==-11) {// Red, Black | 695 | if(iD==-11) {// Red, Black |
691 | foreground.setRgb(230,31,31); //0xB2,0x18,0x18 | 696 | foreground.setRgb(230,31,31); //0xB2,0x18,0x18 |
692 | background.setRgb(0x00,0x00,0x00); | 697 | background.setRgb(0x00,0x00,0x00); |
693 | cfg.writeEntry("Schema","11"); | 698 | cfg.writeEntry("Schema","11"); |
694 | colorMenu->setItemChecked(-11,TRUE); | 699 | colorMenu->setItemChecked(-11,TRUE); |
695 | } | 700 | } |
696 | if(iD==-12) {// Green, Yellow - is ugly | 701 | if(iD==-12) {// Green, Yellow - is ugly |
697 | // foreground.setRgb(0x18,0xB2,0x18); | 702 | // foreground.setRgb(0x18,0xB2,0x18); |
698 | foreground.setRgb(36,139,10); | 703 | foreground.setRgb(36,139,10); |
699 | // background.setRgb(0xB2,0x68,0x18); | 704 | // background.setRgb(0xB2,0x68,0x18); |
700 | background.setRgb(255,255,0); | 705 | background.setRgb(255,255,0); |
701 | cfg.writeEntry("Schema","12"); | 706 | cfg.writeEntry("Schema","12"); |
702 | colorMenu->setItemChecked(-12,TRUE); | 707 | colorMenu->setItemChecked(-12,TRUE); |
703 | } | 708 | } |
704 | if(iD==-13) {// Blue, Magenta | 709 | if(iD==-13) {// Blue, Magenta |
705 | foreground.setRgb(0x18,0xB2,0xB2); | 710 | foreground.setRgb(0x18,0xB2,0xB2); |
706 | background.setRgb(0x18,0x18,0xB2); | 711 | background.setRgb(0x18,0x18,0xB2); |
707 | cfg.writeEntry("Schema","13"); | 712 | cfg.writeEntry("Schema","13"); |
708 | colorMenu->setItemChecked(-13,TRUE); | 713 | colorMenu->setItemChecked(-13,TRUE); |
709 | } | 714 | } |
710 | if(iD==-14) {// Magenta, Blue | 715 | if(iD==-14) {// Magenta, Blue |
711 | foreground.setRgb(0x18,0x18,0xB2); | 716 | foreground.setRgb(0x18,0x18,0xB2); |
712 | background.setRgb(0x18,0xB2,0xB2); | 717 | background.setRgb(0x18,0xB2,0xB2); |
713 | cfg.writeEntry("Schema","14"); | 718 | cfg.writeEntry("Schema","14"); |
714 | colorMenu->setItemChecked(-14,TRUE); | 719 | colorMenu->setItemChecked(-14,TRUE); |
715 | } | 720 | } |
716 | if(iD==-15) {// Cyan, White | 721 | if(iD==-15) {// Cyan, White |
717 | foreground.setRgb(0x18,0xB2,0xB2); | 722 | foreground.setRgb(0x18,0xB2,0xB2); |
718 | background.setRgb(0xFF,0xFF,0xFF); | 723 | background.setRgb(0xFF,0xFF,0xFF); |
719 | cfg.writeEntry("Schema","15"); | 724 | cfg.writeEntry("Schema","15"); |
720 | colorMenu->setItemChecked(-15,TRUE); | 725 | colorMenu->setItemChecked(-15,TRUE); |
721 | } | 726 | } |
722 | if(iD==-16) {// White, Cyan | 727 | if(iD==-16) {// White, Cyan |
723 | background.setRgb(0x18,0xB2,0xB2); | 728 | background.setRgb(0x18,0xB2,0xB2); |
724 | foreground.setRgb(0xFF,0xFF,0xFF); | 729 | foreground.setRgb(0xFF,0xFF,0xFF); |
725 | cfg.writeEntry("Schema","16"); | 730 | cfg.writeEntry("Schema","16"); |
726 | colorMenu->setItemChecked(-16,TRUE); | 731 | colorMenu->setItemChecked(-16,TRUE); |
727 | } | 732 | } |
728 | if(iD==-17) {// Black, Blue | 733 | if(iD==-17) {// Black, Blue |
729 | background.setRgb(0x00,0x00,0x00); | 734 | background.setRgb(0x00,0x00,0x00); |
730 | foreground.setRgb(0x18,0xB2,0xB2); | 735 | foreground.setRgb(0x18,0xB2,0xB2); |
731 | cfg.writeEntry("Schema","17"); | 736 | cfg.writeEntry("Schema","17"); |
732 | colorMenu->setItemChecked(-17,TRUE); | 737 | colorMenu->setItemChecked(-17,TRUE); |
733 | } | 738 | } |
734 | if(iD==-18) {// Black, Gold | 739 | if(iD==-18) {// Black, Gold |
735 | background.setRgb(0x00,0x00,0x00); | 740 | background.setRgb(0x00,0x00,0x00); |
736 | foreground.setRgb(255,215,0); | 741 | foreground.setRgb(255,215,0); |
737 | cfg.writeEntry("Schema","18"); | 742 | cfg.writeEntry("Schema","18"); |
738 | colorMenu->setItemChecked(-18,TRUE); | 743 | colorMenu->setItemChecked(-18,TRUE); |
739 | } | 744 | } |
740 | if(iD==-19) {// Custom | 745 | if(iD==-19) {// Custom |
741 | qDebug("do custom"); | 746 | qDebug("do custom"); |
742 | if(fromMenu) { | 747 | if(fromMenu) { |
743 | ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, this, "foreground color"); | 748 | ColorPopupMenu* penColorPopupMenu = new ColorPopupMenu(Qt::black, this, "foreground color"); |
744 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, | 749 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, |
745 | SLOT(changeForegroundColor(const QColor&))); | 750 | SLOT(changeForegroundColor(const QColor&))); |
746 | penColorPopupMenu->exec(); | 751 | penColorPopupMenu->exec(); |
747 | } | 752 | } |
748 | cfg.writeEntry("Schema","19"); | 753 | cfg.writeEntry("Schema","19"); |
749 | if(!fromMenu) { | 754 | if(!fromMenu) { |
750 | foreground.setNamedColor(cfg.readEntry("foreground","")); | 755 | foreground.setNamedColor(cfg.readEntry("foreground","")); |
751 | background.setNamedColor(cfg.readEntry("background","")); | 756 | background.setNamedColor(cfg.readEntry("background","")); |
752 | } | 757 | } |
753 | fromMenu=FALSE; | 758 | fromMenu=FALSE; |
754 | colorMenu->setItemChecked(-19,TRUE); | 759 | colorMenu->setItemChecked(-19,TRUE); |
755 | } | 760 | } |
756 | 761 | ||
757 | for (i = 0; i < TABLE_COLORS; i++) { | 762 | for (i = 0; i < TABLE_COLORS; i++) { |
758 | if(i==0 || i == 10) { | 763 | if(i==0 || i == 10) { |
759 | m_table[i].color = foreground; | 764 | m_table[i].color = foreground; |
760 | } | 765 | } |
761 | else if(i==1 || i == 11) { | 766 | else if(i==1 || i == 11) { |
762 | m_table[i].color = background; m_table[i].transparent=0; | 767 | m_table[i].color = background; m_table[i].transparent=0; |
763 | } | 768 | } |
764 | else | 769 | else |
765 | m_table[i].color = defaultCt[i].color; | 770 | m_table[i].color = defaultCt[i].color; |
766 | } | 771 | } |
767 | } | 772 | } |
768 | lastSelectedMenu = iD; | 773 | lastSelectedMenu = iD; |
769 | te->setColorTable(m_table); | 774 | te->setColorTable(m_table); |
770 | update(); | 775 | update(); |
771 | 776 | ||
772 | } | 777 | } |
773 | 778 | ||
774 | void Konsole::configMenuSelected(int iD) | 779 | void Konsole::configMenuSelected(int iD) |
775 | { | 780 | { |
776 | // QString temp; | 781 | QString temp; |
777 | // qDebug( temp.sprintf("configmenu %d",iD)); | 782 | qDebug( temp.sprintf("configmenu %d",iD)); |
778 | TEWidget* te = getTe(); | 783 | TEWidget* te = getTe(); |
779 | Config cfg("Konsole"); | 784 | Config cfg("Konsole"); |
780 | cfg.setGroup("Menubar"); | 785 | cfg.setGroup("Menubar"); |
781 | if( iD == -4) { | 786 | if( iD == -4) { |
782 | cfg.setGroup("Tabs"); | 787 | cfg.setGroup("Tabs"); |
783 | QString tmp=cfg.readEntry("Position","Bottom"); | 788 | QString tmp=cfg.readEntry("Position","Bottom"); |
784 | 789 | ||
785 | if(tmp=="Top") { | 790 | if(tmp=="Top") { |
786 | tab->setTabPosition(QTabWidget::Bottom); | 791 | tab->setTabPosition(QTabWidget::Bottom); |
787 | configMenu->changeItem( iD,"Tabs on Top"); | 792 | configMenu->changeItem( iD,"Tabs on Top"); |
788 | cfg.writeEntry("Position","Bottom"); | 793 | cfg.writeEntry("Position","Bottom"); |
789 | } else { | 794 | } else { |
790 | tab->setTabPosition(QTabWidget::Top); | 795 | tab->setTabPosition(QTabWidget::Top); |
791 | configMenu->changeItem( iD,"Tabs on Bottom"); | 796 | configMenu->changeItem( iD,"Tabs on Bottom"); |
792 | cfg.writeEntry("Position","Top"); | 797 | cfg.writeEntry("Position","Top"); |
793 | } | 798 | } |
794 | } | 799 | } |
800 | if( iD == -29) { | ||
801 | cfg.setGroup("ScrollBar"); | ||
802 | bool b=cfg.readBoolEntry("HorzScroll",0); | ||
803 | b=!b; | ||
804 | cfg.writeEntry("HorzScroll", b ); | ||
805 | cfg.write(); | ||
806 | doWrap(); | ||
807 | if(cfg.readNumEntry("Position",2) == 0) { | ||
808 | te->setScrollbarLocation(1); | ||
809 | } else { | ||
810 | te->setScrollbarLocation(0); | ||
811 | } | ||
812 | te->setScrollbarLocation( cfg.readNumEntry("Position",2)); | ||
813 | } | ||
795 | } | 814 | } |
796 | 815 | ||
797 | void Konsole::changeCommand(const QString &text, int c) | 816 | void Konsole::changeCommand(const QString &text, int c) |
798 | { | 817 | { |
799 | Config cfg("Konsole"); | 818 | Config cfg("Konsole"); |
800 | cfg.setGroup("Commands"); | 819 | cfg.setGroup("Commands"); |
801 | if(commonCmds[c] != text) { | 820 | if(commonCmds[c] != text) { |
802 | cfg.writeEntry(QString::number(c),text); | 821 | cfg.writeEntry(QString::number(c),text); |
803 | commonCombo->clearEdit(); | 822 | commonCombo->clearEdit(); |
804 | commonCombo->setCurrentItem(c); | 823 | commonCombo->setCurrentItem(c); |
805 | } | 824 | } |
806 | } | 825 | } |
807 | 826 | ||
808 | void Konsole::setColor() | 827 | void Konsole::setColor() |
809 | { | 828 | { |
810 | Config cfg("Konsole"); | 829 | Config cfg("Konsole"); |
811 | cfg.setGroup("Colors"); | 830 | cfg.setGroup("Colors"); |
812 | int scheme = cfg.readNumEntry("Schema",1); | 831 | int scheme = cfg.readNumEntry("Schema",1); |
813 | if(scheme != 1) colorMenuSelected( -scheme); | 832 | if(scheme != 1) colorMenuSelected( -scheme); |
814 | } | 833 | } |
815 | 834 | ||
816 | void Konsole::scrollMenuSelected(int index) | 835 | void Konsole::scrollMenuSelected(int index) |
817 | { | 836 | { |
818 | qDebug( "scrollbar menu %d",index); | 837 | qDebug( "scrollbar menu %d",index); |
819 | TEWidget* te = getTe(); | 838 | TEWidget* te = getTe(); |
820 | Config cfg("Konsole"); | 839 | Config cfg("Konsole"); |
821 | cfg.setGroup("ScrollBar"); | 840 | cfg.setGroup("ScrollBar"); |
822 | switch( index){ | 841 | switch( index){ |
823 | case -25: | 842 | case -25: |
824 | te->setScrollbarLocation(0); | 843 | te->setScrollbarLocation(0); |
825 | cfg.writeEntry("Position",0); | 844 | cfg.writeEntry("Position",0); |
826 | break; | 845 | break; |
827 | case -26: | 846 | case -26: |
828 | te->setScrollbarLocation(1); | 847 | te->setScrollbarLocation(1); |
829 | cfg.writeEntry("Position",1); | 848 | cfg.writeEntry("Position",1); |
830 | break; | 849 | break; |
831 | case -27: | 850 | case -27: |
832 | te->setScrollbarLocation(2); | 851 | te->setScrollbarLocation(2); |
833 | cfg.writeEntry("Position",2); | 852 | cfg.writeEntry("Position",2); |
834 | break; | 853 | break; |
835 | case -29: { | 854 | // case -29: { |
836 | bool b=cfg.readBoolEntry("HorzScroll",0); | 855 | // bool b=cfg.readBoolEntry("HorzScroll",0); |
837 | cfg.writeEntry("HorzScroll", !b ); | 856 | // cfg.writeEntry("HorzScroll", !b ); |
838 | cfg.write(); | 857 | // cfg.write(); |
839 | if(cfg.readNumEntry("Position",2) == 0) | 858 | // if(cfg.readNumEntry("Position",2) == 0) { |
840 | te->setScrollbarLocation(1); | 859 | // te->setScrollbarLocation(1); |
841 | else | 860 | // te->setWrapAt(0); |
842 | te->setScrollbarLocation(0); | 861 | // } else { |
843 | te->setScrollbarLocation( cfg.readNumEntry("Position",2)); | 862 | // te->setScrollbarLocation(0); |
844 | te->setWrapAt(120); | 863 | // te->setWrapAt(120); |
845 | } | 864 | // } |
846 | break; | 865 | // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); |
866 | // } | ||
867 | // break; | ||
847 | }; | 868 | }; |
848 | |||
849 | } | 869 | } |
850 | 870 | ||
851 | void Konsole::editCommandListMenuSelected(int iD) | 871 | void Konsole::editCommandListMenuSelected(int iD) |
852 | { | 872 | { |
853 | // QString temp; | 873 | // QString temp; |
854 | // qDebug( temp.sprintf("edit command list %d",iD)); | 874 | // qDebug( temp.sprintf("edit command list %d",iD)); |
855 | TEWidget* te = getTe(); | 875 | TEWidget* te = getTe(); |
856 | Config cfg("Konsole"); | 876 | Config cfg("Konsole"); |
857 | cfg.setGroup("Menubar"); | 877 | cfg.setGroup("Menubar"); |
858 | if( iD == -3) { | 878 | if( iD == -3) { |
859 | if(!secondToolBar->isHidden()) { | 879 | if(!secondToolBar->isHidden()) { |
860 | secondToolBar->hide(); | 880 | secondToolBar->hide(); |
861 | configMenu->changeItem( iD,tr( "Show Command List" )); | 881 | configMenu->changeItem( iD,tr( "Show Command List" )); |
862 | cfg.writeEntry("Hidden","TRUE"); | 882 | cfg.writeEntry("Hidden","TRUE"); |
863 | configMenu->setItemEnabled(-23 ,FALSE); | 883 | configMenu->setItemEnabled(-23 ,FALSE); |
864 | } else { | 884 | } else { |
865 | secondToolBar->show(); | 885 | secondToolBar->show(); |
866 | configMenu->changeItem( iD,tr( "Hide Command List" )); | 886 | configMenu->changeItem( iD,tr( "Hide Command List" )); |
867 | cfg.writeEntry("Hidden","FALSE"); | 887 | cfg.writeEntry("Hidden","FALSE"); |
868 | configMenu->setItemEnabled(-23 ,TRUE); | 888 | configMenu->setItemEnabled(-23 ,TRUE); |
869 | 889 | ||
870 | if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { | 890 | if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { |
871 | configMenu->setItemChecked(-23,TRUE); | 891 | configMenu->setItemChecked(-23,TRUE); |
872 | commonCombo->setEditable( TRUE ); | 892 | commonCombo->setEditable( TRUE ); |
873 | } else { | 893 | } else { |
874 | configMenu->setItemChecked(-23,FALSE); | 894 | configMenu->setItemChecked(-23,FALSE); |
875 | commonCombo->setEditable( FALSE ); | 895 | commonCombo->setEditable( FALSE ); |
876 | } | 896 | } |
877 | } | 897 | } |
878 | } | 898 | } |
879 | if( iD == -23) { | 899 | if( iD == -23) { |
880 | cfg.setGroup("Commands"); | 900 | cfg.setGroup("Commands"); |
881 | // qDebug("enableCommandEdit"); | 901 | // qDebug("enableCommandEdit"); |
882 | if( !configMenu->isItemChecked(iD) ) { | 902 | if( !configMenu->isItemChecked(iD) ) { |
883 | commonCombo->setEditable( TRUE ); | 903 | commonCombo->setEditable( TRUE ); |
884 | configMenu->setItemChecked(iD,TRUE); | 904 | configMenu->setItemChecked(iD,TRUE); |
885 | commonCombo->setCurrentItem(0); | 905 | commonCombo->setCurrentItem(0); |
886 | cfg.writeEntry("EditEnabled","TRUE"); | 906 | cfg.writeEntry("EditEnabled","TRUE"); |
887 | } else { | 907 | } else { |
888 | commonCombo->setEditable( FALSE ); | 908 | commonCombo->setEditable( FALSE ); |
889 | configMenu->setItemChecked(iD,FALSE); | 909 | configMenu->setItemChecked(iD,FALSE); |
890 | cfg.writeEntry("EditEnabled","FALSE"); | 910 | cfg.writeEntry("EditEnabled","FALSE"); |
891 | commonCombo->setFocusPolicy(QWidget::NoFocus); | 911 | commonCombo->setFocusPolicy(QWidget::NoFocus); |
892 | te->setFocus(); | 912 | te->setFocus(); |
893 | } | 913 | } |
894 | } | 914 | } |
895 | if(iD == -24) { | 915 | if(iD == -24) { |
896 | // "edit commands" | 916 | // "edit commands" |
897 | CommandEditDialog *m = new CommandEditDialog(this); | 917 | CommandEditDialog *m = new CommandEditDialog(this); |
898 | connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); | 918 | connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); |
899 | m->showMaximized(); | 919 | m->showMaximized(); |
900 | } | 920 | } |
901 | 921 | ||
902 | } | 922 | } |
903 | 923 | ||
904 | // $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V' | 924 | // $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V' |
905 | void Konsole::setDocument( const QString &cmd) { | 925 | void Konsole::setDocument( const QString &cmd) { |
906 | newSession(); | 926 | newSession(); |
907 | TEWidget* te = getTe(); | 927 | TEWidget* te = getTe(); |
908 | if(cmd.find("-e", 0, TRUE) != -1) { | 928 | if(cmd.find("-e", 0, TRUE) != -1) { |
909 | QString cmd2; | 929 | QString cmd2; |
910 | cmd2=cmd.right(cmd.length()-3)+" &"; | 930 | cmd2=cmd.right(cmd.length()-3)+" &"; |
911 | system(cmd2.latin1()); | 931 | system(cmd2.latin1()); |
912 | if(startUp <= 1 && nsessions < 2) { | 932 | if(startUp <= 1 && nsessions < 2) { |
913 | doneSession(getTe()->currentSession, 0); | 933 | doneSession(getTe()->currentSession, 0); |
914 | exit(0); | 934 | exit(0); |
915 | } else | 935 | } else |
916 | doneSession(getTe()->currentSession, 0); | 936 | doneSession(getTe()->currentSession, 0); |
917 | } else { | 937 | } else { |
918 | if (te != 0) { | 938 | if (te != 0) { |
919 | te->emitText(cmd+"\r"); | 939 | te->emitText(cmd+"\r"); |
920 | } | 940 | } |
921 | } | 941 | } |
922 | startUp++; | 942 | startUp++; |
923 | } | 943 | } |
924 | 944 | ||
925 | void Konsole::parseCommandLine() { | 945 | void Konsole::parseCommandLine() { |
926 | QString cmd; | 946 | QString cmd; |
927 | // newSession(); | 947 | // newSession(); |
928 | for (int i=1;i< qApp->argc();i++) { | 948 | for (int i=1;i< qApp->argc();i++) { |
929 | if( QString(qApp->argv()[i]) == "-e") { | 949 | if( QString(qApp->argv()[i]) == "-e") { |
930 | i++; | 950 | i++; |
931 | for ( int j=i;j< qApp->argc();j++) { | 951 | for ( int j=i;j< qApp->argc();j++) { |
932 | cmd+=QString(qApp->argv()[j])+" "; | 952 | cmd+=QString(qApp->argv()[j])+" "; |
933 | } | 953 | } |
934 | cmd.stripWhiteSpace(); | 954 | cmd.stripWhiteSpace(); |
935 | system(cmd.latin1()); | 955 | system(cmd.latin1()); |
936 | exit(0);//close(); | 956 | exit(0);//close(); |
937 | } // end -e switch | 957 | } // end -e switch |
938 | } | 958 | } |
939 | startUp++; | 959 | startUp++; |
940 | } | 960 | } |
941 | 961 | ||
942 | void Konsole::changeForegroundColor(const QColor &color) { | 962 | void Konsole::changeForegroundColor(const QColor &color) { |
943 | Config cfg("Konsole"); | 963 | Config cfg("Konsole"); |
944 | cfg.setGroup("Colors"); | 964 | cfg.setGroup("Colors"); |
945 | int r, g, b; | 965 | int r, g, b; |
946 | color.rgb(&r,&g,&b); | 966 | color.rgb(&r,&g,&b); |
947 | foreground.setRgb(r,g,b); | 967 | foreground.setRgb(r,g,b); |
948 | // QString colors; | 968 | // QString colors; |
949 | // colors.sprintf("%d,%d,%d"color.red,color.green,color.blue); | 969 | // colors.sprintf("%d,%d,%d"color.red,color.green,color.blue); |
950 | cfg.writeEntry("foreground",color.name()); | 970 | cfg.writeEntry("foreground",color.name()); |
951 | cfg.write(); | 971 | cfg.write(); |
952 | 972 | ||
953 | qDebug("do other dialog"); | 973 | qDebug("do other dialog"); |
954 | ColorPopupMenu* penColorPopupMenu2 = new ColorPopupMenu(Qt::black, this,"background color"); | 974 | ColorPopupMenu* penColorPopupMenu2 = new ColorPopupMenu(Qt::black, this,"background color"); |
955 | connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this, | 975 | connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this, |
956 | SLOT(changeBackgroundColor(const QColor&))); | 976 | SLOT(changeBackgroundColor(const QColor&))); |
957 | penColorPopupMenu2->exec(); | 977 | penColorPopupMenu2->exec(); |
958 | 978 | ||
959 | } | 979 | } |
960 | 980 | ||
961 | void Konsole::changeBackgroundColor(const QColor &color) { | 981 | void Konsole::changeBackgroundColor(const QColor &color) { |
962 | 982 | ||
963 | qDebug("Change background"); | 983 | qDebug("Change background"); |
964 | Config cfg("Konsole"); | 984 | Config cfg("Konsole"); |
965 | cfg.setGroup("Colors"); | 985 | cfg.setGroup("Colors"); |
966 | int r, g, b; | 986 | int r, g, b; |
967 | color.rgb(&r,&g,&b); | 987 | color.rgb(&r,&g,&b); |
968 | background.setRgb(r,g,b); | 988 | background.setRgb(r,g,b); |
969 | // QString colors; | 989 | // QString colors; |
970 | // colors.sprintf("%d,%d,%d"color.red,color.green,color.blue); | 990 | // colors.sprintf("%d,%d,%d"color.red,color.green,color.blue); |
971 | cfg.writeEntry("background",color.name()); | 991 | cfg.writeEntry("background",color.name()); |
972 | cfg.write(); | 992 | cfg.write(); |
973 | } | 993 | } |
994 | |||
995 | void Konsole::doWrap() { | ||
996 | Config cfg("Konsole"); | ||
997 | cfg.setGroup("ScrollBar"); | ||
998 | TEWidget* te = getTe(); | ||
999 | if( !cfg.readBoolEntry("HorzScroll",0)) { | ||
1000 | te->setWrapAt(0); | ||
1001 | configMenu->setItemChecked(-29,FALSE); | ||
1002 | } else { | ||
1003 | te->setWrapAt(90); | ||
1004 | // te->setWrapAt(120); | ||
1005 | configMenu->setItemChecked(-29,TRUE); | ||
1006 | } | ||
1007 | } | ||
diff --git a/core/apps/embeddedkonsole/konsole.h b/core/apps/embeddedkonsole/konsole.h index 0bf3fb3..4938159 100644 --- a/core/apps/embeddedkonsole/konsole.h +++ b/core/apps/embeddedkonsole/konsole.h | |||
@@ -1,143 +1,144 @@ | |||
1 | /* ----------------------------------------------------------------------- */ | 1 | /* ----------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [konsole.h] Konsole */ | 3 | /* [konsole.h] Konsole */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole, an X terminal. */ | 9 | /* This file is part of Konsole, an X terminal. */ |
10 | /* */ | 10 | /* */ |
11 | /* The material contained in here more or less directly orginates from */ | 11 | /* The material contained in here more or less directly orginates from */ |
12 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ | 12 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ |
13 | /* */ | 13 | /* */ |
14 | /* -------------------------------------------------------------------------- */ | 14 | /* -------------------------------------------------------------------------- */ |
15 | /* */ | 15 | /* */ |
16 | /* Ported Konsole to Qt/Embedded */ | 16 | /* Ported Konsole to Qt/Embedded */ |
17 | /* */ | 17 | /* */ |
18 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 18 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
19 | /* */ | 19 | /* */ |
20 | /* -------------------------------------------------------------------------- */ | 20 | /* -------------------------------------------------------------------------- */ |
21 | 21 | ||
22 | #ifndef KONSOLE_H | 22 | #ifndef KONSOLE_H |
23 | #define KONSOLE_H | 23 | #define KONSOLE_H |
24 | 24 | ||
25 | 25 | ||
26 | #include <qmainwindow.h> | 26 | #include <qmainwindow.h> |
27 | #include <qaction.h> | 27 | #include <qaction.h> |
28 | #include <qpopupmenu.h> | 28 | #include <qpopupmenu.h> |
29 | #include <qstrlist.h> | 29 | #include <qstrlist.h> |
30 | #include <qintdict.h> | 30 | #include <qintdict.h> |
31 | #include <qptrdict.h> | 31 | #include <qptrdict.h> |
32 | #include <qtabwidget.h> | 32 | #include <qtabwidget.h> |
33 | #include <qpe/qpetoolbar.h> | 33 | #include <qpe/qpetoolbar.h> |
34 | #include <qcombobox.h> | 34 | #include <qcombobox.h> |
35 | #include <qcolor.h> | 35 | #include <qcolor.h> |
36 | 36 | ||
37 | #include "MyPty.h" | 37 | #include "MyPty.h" |
38 | #include "TEWidget.h" | 38 | #include "TEWidget.h" |
39 | #include "TEmuVt102.h" | 39 | #include "TEmuVt102.h" |
40 | #include "session.h" | 40 | #include "session.h" |
41 | 41 | ||
42 | class EKNumTabWidget; | 42 | class EKNumTabWidget; |
43 | 43 | ||
44 | class Konsole : public QMainWindow | 44 | class Konsole : public QMainWindow |
45 | { | 45 | { |
46 | Q_OBJECT | 46 | Q_OBJECT |
47 | 47 | ||
48 | public: | 48 | public: |
49 | 49 | ||
50 | Konsole(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); | 50 | Konsole(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); |
51 | Konsole(const char * name, const char* pgm, QStrList & _args, int histon); | 51 | Konsole(const char * name, const char* pgm, QStrList & _args, int histon); |
52 | ~Konsole(); | 52 | ~Konsole(); |
53 | void setColLin(int columns, int lines); | 53 | void setColLin(int columns, int lines); |
54 | QPEToolBar *secondToolBar; | 54 | QPEToolBar *secondToolBar; |
55 | void show(); | 55 | void show(); |
56 | void setColor(); | 56 | void setColor(); |
57 | int lastSelectedMenu; | 57 | int lastSelectedMenu; |
58 | int startUp; | 58 | int startUp; |
59 | private slots: | 59 | private slots: |
60 | void setDocument(const QString &); | 60 | void setDocument(const QString &); |
61 | void doneSession(TESession*,int); | 61 | void doneSession(TESession*,int); |
62 | void changeColumns(int); | 62 | void changeColumns(int); |
63 | void fontChanged(int); | 63 | void fontChanged(int); |
64 | void configMenuSelected(int ); | 64 | void configMenuSelected(int ); |
65 | void colorMenuSelected(int); | 65 | void colorMenuSelected(int); |
66 | void colorMenuIsSelected(int); | 66 | void colorMenuIsSelected(int); |
67 | void enterCommand(int); | 67 | void enterCommand(int); |
68 | void hitEnter(); | 68 | void hitEnter(); |
69 | void hitSpace(); | 69 | void hitSpace(); |
70 | void hitTab(); | 70 | void hitTab(); |
71 | void hitPaste(); | 71 | void hitPaste(); |
72 | void hitUp(); | 72 | void hitUp(); |
73 | void hitDown(); | 73 | void hitDown(); |
74 | void switchSession(QWidget *); | 74 | void switchSession(QWidget *); |
75 | void newSession(); | 75 | void newSession(); |
76 | void changeCommand(const QString &, int); | 76 | void changeCommand(const QString &, int); |
77 | void initCommandList(); | 77 | void initCommandList(); |
78 | void scrollMenuSelected(int); | 78 | void scrollMenuSelected(int); |
79 | void editCommandListMenuSelected(int); | 79 | void editCommandListMenuSelected(int); |
80 | void parseCommandLine(); | 80 | void parseCommandLine(); |
81 | void changeForegroundColor(const QColor &); | 81 | void changeForegroundColor(const QColor &); |
82 | void changeBackgroundColor(const QColor &); | 82 | void changeBackgroundColor(const QColor &); |
83 | private: | 83 | private: |
84 | void doWrap(); | ||
84 | void init(const char* _pgm, QStrList & _args); | 85 | void init(const char* _pgm, QStrList & _args); |
85 | void initSession(const char* _pgm, QStrList & _args); | 86 | void initSession(const char* _pgm, QStrList & _args); |
86 | void runSession(TESession* s); | 87 | void runSession(TESession* s); |
87 | void setColorPixmaps(); | 88 | void setColorPixmaps(); |
88 | void setHistory(bool); | 89 | void setHistory(bool); |
89 | QSize calcSize(int columns, int lines); | 90 | QSize calcSize(int columns, int lines); |
90 | TEWidget* getTe(); | 91 | TEWidget* getTe(); |
91 | QStringList commands; | 92 | QStringList commands; |
92 | QLabel * msgLabel; | 93 | QLabel * msgLabel; |
93 | QColor foreground, background; | 94 | QColor foreground, background; |
94 | bool fromMenu; | 95 | bool fromMenu; |
95 | private: | 96 | private: |
96 | class VTFont | 97 | class VTFont |
97 | { | 98 | { |
98 | public: | 99 | public: |
99 | VTFont(QString name, QFont& font) | 100 | VTFont(QString name, QFont& font) |
100 | { | 101 | { |
101 | this->name = name; | 102 | this->name = name; |
102 | this->font = font; | 103 | this->font = font; |
103 | } | 104 | } |
104 | 105 | ||
105 | QFont& getFont() | 106 | QFont& getFont() |
106 | { | 107 | { |
107 | return font; | 108 | return font; |
108 | } | 109 | } |
109 | 110 | ||
110 | QString getName() | 111 | QString getName() |
111 | { | 112 | { |
112 | return name; | 113 | return name; |
113 | } | 114 | } |
114 | 115 | ||
115 | private: | 116 | private: |
116 | QString name; | 117 | QString name; |
117 | QFont font; | 118 | QFont font; |
118 | }; | 119 | }; |
119 | 120 | ||
120 | EKNumTabWidget* tab; | 121 | EKNumTabWidget* tab; |
121 | int nsessions; | 122 | int nsessions; |
122 | QList<VTFont> fonts; | 123 | QList<VTFont> fonts; |
123 | int cfont; | 124 | int cfont; |
124 | QCString se_pgm; | 125 | QCString se_pgm; |
125 | QStrList se_args; | 126 | QStrList se_args; |
126 | 127 | ||
127 | QPopupMenu *fontList,*configMenu,*colorMenu,*scrollMenu,*editCommandListMenu; | 128 | QPopupMenu *fontList,*configMenu,*colorMenu,*scrollMenu,*editCommandListMenu; |
128 | QComboBox *commonCombo; | 129 | QComboBox *commonCombo; |
129 | // history scrolling I think | 130 | // history scrolling I think |
130 | bool b_scroll; | 131 | bool b_scroll; |
131 | 132 | ||
132 | int n_keytab; | 133 | int n_keytab; |
133 | int n_scroll; | 134 | int n_scroll; |
134 | int n_render; | 135 | int n_render; |
135 | QString pmPath; // pixmap path | 136 | QString pmPath; // pixmap path |
136 | QString dropText; | 137 | QString dropText; |
137 | QFont defaultFont; | 138 | QFont defaultFont; |
138 | QSize defaultSize; | 139 | QSize defaultSize; |
139 | 140 | ||
140 | }; | 141 | }; |
141 | 142 | ||
142 | #endif | 143 | #endif |
143 | 144 | ||