-rw-r--r-- | core/apps/textedit/textedit.cpp | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 834971a..8004771 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -1,828 +1,820 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 | 20 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 |
21 | 21 | ||
22 | #include "textedit.h" | 22 | #include "textedit.h" |
23 | #include "fileBrowser.h" | 23 | #include "fileBrowser.h" |
24 | #include "fileSaver.h" | 24 | #include "fileSaver.h" |
25 | 25 | ||
26 | #include "fontDialog.h" | 26 | #include "fontDialog.h" |
27 | 27 | ||
28 | #include <qpe/fontdatabase.h> | 28 | #include <qpe/fontdatabase.h> |
29 | #include <qpe/global.h> | 29 | #include <qpe/global.h> |
30 | #include <qpe/fileselector.h> | 30 | #include <qpe/fileselector.h> |
31 | #include <qpe/applnk.h> | 31 | #include <qpe/applnk.h> |
32 | #include <qpe/resource.h> | 32 | #include <qpe/resource.h> |
33 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
34 | #include <qpe/qpeapplication.h> | 34 | #include <qpe/qpeapplication.h> |
35 | #include <qpe/qpemenubar.h> | 35 | #include <qpe/qpemenubar.h> |
36 | #include <qpe/qpetoolbar.h> | 36 | #include <qpe/qpetoolbar.h> |
37 | //#include <qpe/finddialog.h> | 37 | //#include <qpe/finddialog.h> |
38 | 38 | ||
39 | #include <qstringlist.h> | 39 | #include <qstringlist.h> |
40 | #include <qaction.h> | 40 | #include <qaction.h> |
41 | #include <qcolordialog.h> | 41 | #include <qcolordialog.h> |
42 | #include <qfileinfo.h> | 42 | #include <qfileinfo.h> |
43 | #include <qlineedit.h> | 43 | #include <qlineedit.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qobjectlist.h> | 45 | #include <qobjectlist.h> |
46 | #include <qpopupmenu.h> | 46 | #include <qpopupmenu.h> |
47 | #include <qspinbox.h> | 47 | #include <qspinbox.h> |
48 | #include <qtoolbutton.h> | 48 | #include <qtoolbutton.h> |
49 | #include <qwidgetstack.h> | 49 | #include <qwidgetstack.h> |
50 | 50 | ||
51 | #include <stdlib.h> //getenv | 51 | #include <stdlib.h> //getenv |
52 | /* XPM */ | 52 | /* XPM */ |
53 | static char * filesave_xpm[] = { | 53 | static char * filesave_xpm[] = { |
54 | "16 16 78 1", | 54 | "16 16 78 1", |
55 | " c None", | 55 | " c None", |
56 | ". c #343434", | 56 | ". c #343434", |
57 | "+ c #A0A0A0", | 57 | "+ c #A0A0A0", |
58 | "@ c #565656", | 58 | "@ c #565656", |
59 | "# c #9E9E9E", | 59 | "# c #9E9E9E", |
60 | "$ c #525252", | 60 | "$ c #525252", |
61 | "% c #929292", | 61 | "% c #929292", |
62 | "& c #676767", | 62 | "& c #676767", |
63 | "* c #848484", | 63 | "* c #848484", |
64 | "= c #666666", | 64 | "= c #666666", |
65 | "- c #D8D8D8", | 65 | "- c #D8D8D8", |
66 | "; c #FFFFFF", | 66 | "; c #FFFFFF", |
67 | "> c #DBDBDB", | 67 | "> c #DBDBDB", |
68 | ", c #636363", | 68 | ", c #636363", |
69 | "' c #989898", | 69 | "' c #989898", |
70 | ") c #2D2D2D", | 70 | ") c #2D2D2D", |
71 | "! c #909090", | 71 | "! c #909090", |
72 | "~ c #AEAEAE", | 72 | "~ c #AEAEAE", |
73 | "{ c #EAEAEA", | 73 | "{ c #EAEAEA", |
74 | "] c #575757", | 74 | "] c #575757", |
75 | "^ c #585858", | 75 | "^ c #585858", |
76 | "/ c #8A8A8A", | 76 | "/ c #8A8A8A", |
77 | "( c #828282", | 77 | "( c #828282", |
78 | "_ c #6F6F6F", | 78 | "_ c #6F6F6F", |
79 | ": c #C9C9C9", | 79 | ": c #C9C9C9", |
80 | "< c #050505", | 80 | "< c #050505", |
81 | "[ c #292929", | 81 | "[ c #292929", |
82 | "} c #777777", | 82 | "} c #777777", |
83 | "| c #616161", | 83 | "| c #616161", |
84 | "1 c #3A3A3A", | 84 | "1 c #3A3A3A", |
85 | "2 c #BEBEBE", | 85 | "2 c #BEBEBE", |
86 | "3 c #2C2C2C", | 86 | "3 c #2C2C2C", |
87 | "4 c #7C7C7C", | 87 | "4 c #7C7C7C", |
88 | "5 c #F6F6F6", | 88 | "5 c #F6F6F6", |
89 | "6 c #FCFCFC", | 89 | "6 c #FCFCFC", |
90 | "7 c #6B6B6B", | 90 | "7 c #6B6B6B", |
91 | "8 c #959595", | 91 | "8 c #959595", |
92 | "9 c #4F4F4F", | 92 | "9 c #4F4F4F", |
93 | "0 c #808080", | 93 | "0 c #808080", |
94 | "a c #767676", | 94 | "a c #767676", |
95 | "b c #818181", | 95 | "b c #818181", |
96 | "c c #B8B8B8", | 96 | "c c #B8B8B8", |
97 | "d c #FBFBFB", | 97 | "d c #FBFBFB", |
98 | "e c #F9F9F9", | 98 | "e c #F9F9F9", |
99 | "f c #CCCCCC", | 99 | "f c #CCCCCC", |
100 | "g c #030303", | 100 | "g c #030303", |
101 | "h c #737373", | 101 | "h c #737373", |
102 | "i c #7A7A7A", | 102 | "i c #7A7A7A", |
103 | "j c #7E7E7E", | 103 | "j c #7E7E7E", |
104 | "k c #6A6A6A", | 104 | "k c #6A6A6A", |
105 | "l c #FAFAFA", | 105 | "l c #FAFAFA", |
106 | "m c #505050", | 106 | "m c #505050", |
107 | "n c #9D9D9D", | 107 | "n c #9D9D9D", |
108 | "o c #333333", | 108 | "o c #333333", |
109 | "p c #7B7B7B", | 109 | "p c #7B7B7B", |
110 | "q c #787878", | 110 | "q c #787878", |
111 | "r c #696969", | 111 | "r c #696969", |
112 | "s c #494949", | 112 | "s c #494949", |
113 | "t c #555555", | 113 | "t c #555555", |
114 | "u c #949494", | 114 | "u c #949494", |
115 | "v c #E6E6E6", | 115 | "v c #E6E6E6", |
116 | "w c #424242", | 116 | "w c #424242", |
117 | "x c #515151", | 117 | "x c #515151", |
118 | "y c #535353", | 118 | "y c #535353", |
119 | "z c #3E3E3E", | 119 | "z c #3E3E3E", |
120 | "A c #D4D4D4", | 120 | "A c #D4D4D4", |
121 | "B c #0C0C0C", | 121 | "B c #0C0C0C", |
122 | "C c #353535", | 122 | "C c #353535", |
123 | "D c #474747", | 123 | "D c #474747", |
124 | "E c #ECECEC", | 124 | "E c #ECECEC", |
125 | "F c #919191", | 125 | "F c #919191", |
126 | "G c #7D7D7D", | 126 | "G c #7D7D7D", |
127 | "H c #000000", | 127 | "H c #000000", |
128 | "I c #404040", | 128 | "I c #404040", |
129 | "J c #858585", | 129 | "J c #858585", |
130 | "K c #323232", | 130 | "K c #323232", |
131 | "L c #D0D0D0", | 131 | "L c #D0D0D0", |
132 | "M c #1C1C1C", | 132 | "M c #1C1C1C", |
133 | " ...+ ", | 133 | " ...+ ", |
134 | " @#$%&..+ ", | 134 | " @#$%&..+ ", |
135 | " .*=-;;>,..+ ", | 135 | " .*=-;;>,..+ ", |
136 | " ')!~;;;;;;{]..", | 136 | " ')!~;;;;;;{]..", |
137 | " ^/(-;;;;;;;_:<", | 137 | " ^/(-;;;;;;;_:<", |
138 | " [}|;;;;;;;{12$", | 138 | " [}|;;;;;;;{12$", |
139 | " #34-55;;;;678$+", | 139 | " #34-55;;;;678$+", |
140 | " 90ab=c;dd;e1fg ", | 140 | " 90ab=c;dd;e1fg ", |
141 | " [ahij((kbl0mn$ ", | 141 | " [ahij((kbl0mn$ ", |
142 | " op^q^^7r&]s/$+ ", | 142 | " op^q^^7r&]s/$+ ", |
143 | "@btu;vbwxy]zAB ", | 143 | "@btu;vbwxy]zAB ", |
144 | "CzDEvEv;;DssF$ ", | 144 | "CzDEvEv;;DssF$ ", |
145 | "G.H{E{E{IxsJ$+ ", | 145 | "G.H{E{E{IxsJ$+ ", |
146 | " +...vEKxzLM ", | 146 | " +...vEKxzLM ", |
147 | " +...z]n$ ", | 147 | " +...z]n$ ", |
148 | " +... "}; | 148 | " +... "}; |
149 | 149 | ||
150 | 150 | ||
151 | #if QT_VERSION < 300 | 151 | #if QT_VERSION < 300 |
152 | 152 | ||
153 | class QpeEditor : public QMultiLineEdit | 153 | class QpeEditor : public QMultiLineEdit |
154 | { | 154 | { |
155 | // Q_OBJECT | 155 | // Q_OBJECT |
156 | public: | 156 | public: |
157 | QpeEditor( QWidget *parent, const char * name = 0 ) | 157 | QpeEditor( QWidget *parent, const char * name = 0 ) |
158 | : QMultiLineEdit( parent, name ) | 158 | : QMultiLineEdit( parent, name ) |
159 | { | 159 | { |
160 | clearTableFlags(); | 160 | clearTableFlags(); |
161 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 161 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
162 | } | 162 | } |
163 | 163 | ||
164 | //public slots: | 164 | //public slots: |
165 | void find( const QString &txt, bool caseSensitive, | 165 | void find( const QString &txt, bool caseSensitive, |
166 | bool backwards ); | 166 | bool backwards ); |
167 | /* | 167 | /* |
168 | signals: | 168 | signals: |
169 | void notFound(); | 169 | void notFound(); |
170 | void searchWrapped(); | 170 | void searchWrapped(); |
171 | */ | 171 | */ |
172 | 172 | ||
173 | private: | 173 | private: |
174 | 174 | ||
175 | }; | 175 | }; |
176 | 176 | ||
177 | 177 | ||
178 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 178 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
179 | bool backwards ) | 179 | bool backwards ) |
180 | { | 180 | { |
181 | static bool wrap = FALSE; | 181 | static bool wrap = FALSE; |
182 | int line, col; | 182 | int line, col; |
183 | if ( wrap ) { | 183 | if ( wrap ) { |
184 | if ( !backwards ) | 184 | if ( !backwards ) |
185 | line = col = 0; | 185 | line = col = 0; |
186 | wrap = FALSE; | 186 | wrap = FALSE; |
187 | // emit searchWrapped(); | 187 | // emit searchWrapped(); |
188 | } else { | 188 | } else { |
189 | getCursorPosition( &line, &col ); | 189 | getCursorPosition( &line, &col ); |
190 | } | 190 | } |
191 | //ignore backwards for now.... | 191 | //ignore backwards for now.... |
192 | if ( !backwards ) { | 192 | if ( !backwards ) { |
193 | for ( ; ; ) { | 193 | for ( ; ; ) { |
194 | if ( line >= numLines() ) { | 194 | if ( line >= numLines() ) { |
195 | wrap = TRUE; | 195 | wrap = TRUE; |
196 | //emit notFound(); | 196 | //emit notFound(); |
197 | break; | 197 | break; |
198 | } | 198 | } |
199 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 199 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
200 | if ( findCol >= 0 ) { | 200 | if ( findCol >= 0 ) { |
201 | setCursorPosition( line, findCol, FALSE ); | 201 | setCursorPosition( line, findCol, FALSE ); |
202 | col = findCol + txt.length(); | 202 | col = findCol + txt.length(); |
203 | setCursorPosition( line, col, TRUE ); | 203 | setCursorPosition( line, col, TRUE ); |
204 | 204 | ||
205 | //found = TRUE; | 205 | //found = TRUE; |
206 | break; | 206 | break; |
207 | } | 207 | } |
208 | line++; | 208 | line++; |
209 | col = 0; | 209 | col = 0; |
210 | } | 210 | } |
211 | 211 | ||
212 | } | 212 | } |
213 | 213 | ||
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | #else | 217 | #else |
218 | 218 | ||
219 | #error "Must make a QpeEditor that inherits QTextEdit" | 219 | #error "Must make a QpeEditor that inherits QTextEdit" |
220 | 220 | ||
221 | #endif | 221 | #endif |
222 | 222 | ||
223 | 223 | ||
224 | 224 | ||
225 | 225 | ||
226 | static int u_id = 1; | 226 | static int u_id = 1; |
227 | static int get_unique_id() | 227 | static int get_unique_id() |
228 | { | 228 | { |
229 | return u_id++; | 229 | return u_id++; |
230 | } | 230 | } |
231 | 231 | ||
232 | static const int nfontsizes = 6; | 232 | static const int nfontsizes = 6; |
233 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 233 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
234 | 234 | ||
235 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 235 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
236 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | 236 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) |
237 | { | 237 | { |
238 | doc = 0; | 238 | doc = 0; |
239 | 239 | ||
240 | setToolBarsMovable( FALSE ); | 240 | setToolBarsMovable( FALSE ); |
241 | 241 | ||
242 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 242 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
243 | 243 | ||
244 | QPEToolBar *bar = new QPEToolBar( this ); | 244 | QPEToolBar *bar = new QPEToolBar( this ); |
245 | bar->setHorizontalStretchable( TRUE ); | 245 | bar->setHorizontalStretchable( TRUE ); |
246 | menu = bar; | 246 | menu = bar; |
247 | 247 | ||
248 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 248 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
249 | QPopupMenu *file = new QPopupMenu( this ); | 249 | QPopupMenu *file = new QPopupMenu( this ); |
250 | QPopupMenu *edit = new QPopupMenu( this ); | 250 | QPopupMenu *edit = new QPopupMenu( this ); |
251 | QPopupMenu *font = new QPopupMenu( this ); | 251 | QPopupMenu *font = new QPopupMenu( this ); |
252 | 252 | ||
253 | bar = new QPEToolBar( this ); | 253 | bar = new QPEToolBar( this ); |
254 | editBar = bar; | 254 | editBar = bar; |
255 | 255 | ||
256 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 256 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
257 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 257 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
258 | a->addTo( bar ); | 258 | a->addTo( bar ); |
259 | a->addTo( file ); | 259 | a->addTo( file ); |
260 | 260 | ||
261 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 261 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
262 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 262 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
263 | // a->addTo( bar ); | 263 | // a->addTo( bar ); |
264 | a->addTo( file ); | 264 | a->addTo( file ); |
265 | 265 | ||
266 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 266 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
267 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); | 267 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); |
268 | a->addTo( bar ); | 268 | a->addTo( bar ); |
269 | a->addTo( file ); | 269 | a->addTo( file ); |
270 | 270 | ||
271 | // | ||
272 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 271 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
273 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 272 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
274 | // a->addTo( bar ); | 273 | // a->addTo( bar ); |
275 | file->insertSeparator(); | 274 | file->insertSeparator(); |
276 | a->addTo( file ); | 275 | a->addTo( file ); |
277 | 276 | ||
278 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 277 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
279 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 278 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
280 | a->addTo( file ); | 279 | a->addTo( file ); |
281 | 280 | ||
282 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 281 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
283 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 282 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
284 | a->addTo( editBar ); | 283 | a->addTo( editBar ); |
285 | a->addTo( edit ); | 284 | a->addTo( edit ); |
286 | 285 | ||
287 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 286 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
288 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 287 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
289 | a->addTo( editBar ); | 288 | a->addTo( editBar ); |
290 | a->addTo( edit ); | 289 | a->addTo( edit ); |
291 | 290 | ||
292 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 291 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
293 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 292 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
294 | a->addTo( editBar ); | 293 | a->addTo( editBar ); |
295 | a->addTo( edit ); | 294 | a->addTo( edit ); |
296 | 295 | ||
297 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 296 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
298 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 297 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
299 | edit->insertSeparator(); | 298 | edit->insertSeparator(); |
300 | a->addTo( bar ); | 299 | a->addTo( bar ); |
301 | a->addTo( edit ); | 300 | a->addTo( edit ); |
302 | 301 | ||
303 | int defsize; | 302 | int defsize; |
304 | bool defb, defi, wrap; | 303 | bool defb, defi, wrap; |
305 | 304 | ||
306 | Config cfg("TextEdit"); | 305 | Config cfg("TextEdit"); |
307 | cfg.setGroup("View"); | 306 | cfg.setGroup("View"); |
308 | defsize = cfg.readNumEntry("FontSize",10); | 307 | defsize = cfg.readNumEntry("FontSize",10); |
309 | defb = cfg.readBoolEntry("Bold",FALSE); | 308 | defb = cfg.readBoolEntry("Bold",FALSE); |
310 | defi = cfg.readBoolEntry("Italic",FALSE); | 309 | defi = cfg.readBoolEntry("Italic",FALSE); |
311 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 310 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
312 | 311 | ||
313 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 312 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
314 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 313 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
315 | zin->addTo( font ); | 314 | zin->addTo( font ); |
316 | 315 | ||
317 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 316 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
318 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 317 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
319 | zout->addTo( font ); | 318 | zout->addTo( font ); |
320 | 319 | ||
321 | font->insertSeparator(); | 320 | font->insertSeparator(); |
322 | 321 | ||
323 | #if 0 | 322 | #if 0 |
324 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | 323 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); |
325 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | 324 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); |
326 | ba->setToggleAction(TRUE); | 325 | ba->setToggleAction(TRUE); |
327 | ba->addTo( font ); | 326 | ba->addTo( font ); |
328 | 327 | ||
329 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | 328 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); |
330 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); | 329 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); |
331 | ia->setToggleAction(TRUE); | 330 | ia->setToggleAction(TRUE); |
332 | ia->addTo( font ); | 331 | ia->addTo( font ); |
333 | 332 | ||
334 | ba->setOn(defb); | 333 | ba->setOn(defb); |
335 | ia->setOn(defi); | 334 | ia->setOn(defi); |
336 | 335 | ||
337 | font->insertSeparator(); | 336 | font->insertSeparator(); |
338 | #endif | 337 | #endif |
339 | 338 | ||
340 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 339 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
341 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 340 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
342 | wa->setToggleAction(TRUE); | 341 | wa->setToggleAction(TRUE); |
343 | wa->addTo( font ); | 342 | wa->addTo( font ); |
344 | 343 | ||
345 | font->insertSeparator(); | 344 | font->insertSeparator(); |
346 | font->insertItem("Font", this, SLOT(changeFont()) ); | 345 | font->insertItem("Font", this, SLOT(changeFont()) ); |
347 | 346 | ||
348 | mb->insertItem( tr( "File" ), file ); | 347 | mb->insertItem( tr( "File" ), file ); |
349 | mb->insertItem( tr( "Edit" ), edit ); | 348 | mb->insertItem( tr( "Edit" ), edit ); |
350 | mb->insertItem( tr( "View" ), font ); | 349 | mb->insertItem( tr( "View" ), font ); |
351 | 350 | ||
352 | searchBar = new QPEToolBar(this); | 351 | searchBar = new QPEToolBar(this); |
353 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 352 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
354 | 353 | ||
355 | searchBar->setHorizontalStretchable( TRUE ); | 354 | searchBar->setHorizontalStretchable( TRUE ); |
356 | 355 | ||
357 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 356 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
358 | searchBar->setStretchableWidget( searchEdit ); | 357 | searchBar->setStretchableWidget( searchEdit ); |
359 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 358 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
360 | this, SLOT( search() ) ); | 359 | this, SLOT( search() ) ); |
361 | 360 | ||
362 | 361 | ||
363 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 362 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
364 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 363 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
365 | a->addTo( searchBar ); | 364 | a->addTo( searchBar ); |
366 | a->addTo( edit ); | 365 | a->addTo( edit ); |
367 | 366 | ||
368 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 367 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
369 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 368 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
370 | a->addTo( searchBar ); | 369 | a->addTo( searchBar ); |
371 | 370 | ||
372 | searchBar->hide(); | 371 | searchBar->hide(); |
373 | 372 | ||
374 | editorStack = new QWidgetStack( this ); | 373 | editorStack = new QWidgetStack( this ); |
375 | setCentralWidget( editorStack ); | 374 | setCentralWidget( editorStack ); |
376 | 375 | ||
377 | searchVisible = FALSE; | 376 | searchVisible = FALSE; |
378 | 377 | ||
379 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy | 378 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy |
380 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 379 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
381 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 380 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
382 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | 381 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); |
383 | // fileOpen(); | 382 | // fileOpen(); |
384 | 383 | ||
385 | editor = new QpeEditor( editorStack ); | 384 | editor = new QpeEditor( editorStack ); |
386 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 385 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
387 | editorStack->addWidget( editor, get_unique_id() ); | 386 | editorStack->addWidget( editor, get_unique_id() ); |
388 | 387 | ||
389 | resize( 200, 300 ); | 388 | resize( 200, 300 ); |
390 | 389 | ||
391 | // setFontSize(defsize,TRUE); | 390 | // setFontSize(defsize,TRUE); |
392 | FontDatabase fdb; | 391 | FontDatabase fdb; |
393 | QFont defaultFont=editor->font(); | 392 | QFont defaultFont=editor->font(); |
394 | QFontInfo fontInfo(defaultFont); | 393 | QFontInfo fontInfo(defaultFont); |
395 | 394 | ||
396 | cfg.setGroup("Font"); | 395 | cfg.setGroup("Font"); |
397 | QString family = cfg.readEntry("Family", fontInfo.family()); | 396 | QString family = cfg.readEntry("Family", fontInfo.family()); |
398 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 397 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
399 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 398 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
400 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 399 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
401 | 400 | ||
402 | defaultFont = fdb.font(family,style,i_size,charSet); | 401 | defaultFont = fdb.font(family,style,i_size,charSet); |
403 | editor->setFont( defaultFont); | 402 | editor->setFont( defaultFont); |
404 | 403 | ||
405 | wa->setOn(wrap); | 404 | wa->setOn(wrap); |
406 | updateCaption(); | 405 | updateCaption(); |
407 | if( qApp->argc() > 1 ) { | 406 | |
408 | for (int i=1;i< qApp->argc();i++) { | 407 | fileNew(); |
409 | QString tmp; | ||
410 | currentFileName = tmp.sprintf("%s",qApp->argv()[i]); | ||
411 | qDebug(currentFileName); | ||
412 | setDocument( currentFileName ); | ||
413 | } | ||
414 | } | ||
415 | else | ||
416 | fileNew(); | ||
417 | } | 408 | } |
418 | 409 | ||
419 | TextEdit::~TextEdit() | 410 | TextEdit::~TextEdit() |
420 | { | 411 | { |
421 | saveAs(); | 412 | saveAs(); |
422 | 413 | ||
423 | Config cfg("TextEdit"); | 414 | Config cfg("TextEdit"); |
424 | cfg.setGroup("View"); | 415 | cfg.setGroup("View"); |
425 | QFont f = editor->font(); | 416 | QFont f = editor->font(); |
426 | cfg.writeEntry("FontSize",f.pointSize()); | 417 | cfg.writeEntry("FontSize",f.pointSize()); |
427 | cfg.writeEntry("Bold",f.bold()); | 418 | cfg.writeEntry("Bold",f.bold()); |
428 | cfg.writeEntry("Italic",f.italic()); | 419 | cfg.writeEntry("Italic",f.italic()); |
429 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 420 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
430 | } | 421 | } |
431 | 422 | ||
432 | void TextEdit::zoomIn() | 423 | void TextEdit::zoomIn() |
433 | { | 424 | { |
434 | setFontSize(editor->font().pointSize()+1,FALSE); | 425 | setFontSize(editor->font().pointSize()+1,FALSE); |
435 | } | 426 | } |
436 | 427 | ||
437 | void TextEdit::zoomOut() | 428 | void TextEdit::zoomOut() |
438 | { | 429 | { |
439 | setFontSize(editor->font().pointSize()-1,TRUE); | 430 | setFontSize(editor->font().pointSize()-1,TRUE); |
440 | } | 431 | } |
441 | 432 | ||
442 | 433 | ||
443 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 434 | void TextEdit::setFontSize(int sz, bool round_down_not_up) |
444 | { | 435 | { |
445 | int s=10; | 436 | int s=10; |
446 | for (int i=0; i<nfontsizes; i++) { | 437 | for (int i=0; i<nfontsizes; i++) { |
447 | if ( fontsize[i] == sz ) { | 438 | if ( fontsize[i] == sz ) { |
448 | s = sz; | 439 | s = sz; |
449 | break; | 440 | break; |
450 | } else if ( round_down_not_up ) { | 441 | } else if ( round_down_not_up ) { |
451 | if ( fontsize[i] < sz ) | 442 | if ( fontsize[i] < sz ) |
452 | s = fontsize[i]; | 443 | s = fontsize[i]; |
453 | } else { | 444 | } else { |
454 | if ( fontsize[i] > sz ) { | 445 | if ( fontsize[i] > sz ) { |
455 | s = fontsize[i]; | 446 | s = fontsize[i]; |
456 | break; | 447 | break; |
457 | } | 448 | } |
458 | } | 449 | } |
459 | } | 450 | } |
460 | 451 | ||
461 | QFont f = editor->font(); | 452 | QFont f = editor->font(); |
462 | f.setPointSize(s); | 453 | f.setPointSize(s); |
463 | editor->setFont(f); | 454 | editor->setFont(f); |
464 | 455 | ||
465 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 456 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
466 | zout->setEnabled(s != fontsize[0]); | 457 | zout->setEnabled(s != fontsize[0]); |
467 | } | 458 | } |
468 | 459 | ||
469 | void TextEdit::setBold(bool y) | 460 | void TextEdit::setBold(bool y) |
470 | { | 461 | { |
471 | QFont f = editor->font(); | 462 | QFont f = editor->font(); |
472 | f.setBold(y); | 463 | f.setBold(y); |
473 | editor->setFont(f); | 464 | editor->setFont(f); |
474 | } | 465 | } |
475 | 466 | ||
476 | void TextEdit::setItalic(bool y) | 467 | void TextEdit::setItalic(bool y) |
477 | { | 468 | { |
478 | QFont f = editor->font(); | 469 | QFont f = editor->font(); |
479 | f.setItalic(y); | 470 | f.setItalic(y); |
480 | editor->setFont(f); | 471 | editor->setFont(f); |
481 | } | 472 | } |
482 | 473 | ||
483 | void TextEdit::setWordWrap(bool y) | 474 | void TextEdit::setWordWrap(bool y) |
484 | { | 475 | { |
485 | bool state = editor->edited(); | 476 | bool state = editor->edited(); |
486 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 477 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
487 | editor->setEdited( state ); | 478 | editor->setEdited( state ); |
488 | } | 479 | } |
489 | 480 | ||
490 | void TextEdit::fileNew() | 481 | void TextEdit::fileNew() |
491 | { | 482 | { |
492 | if( !bFromDocView ) { | 483 | if( !bFromDocView ) { |
493 | saveAs(); | 484 | saveAs(); |
494 | } | 485 | } |
495 | newFile(DocLnk()); | 486 | newFile(DocLnk()); |
496 | } | 487 | } |
497 | 488 | ||
498 | void TextEdit::fileOpen() | 489 | void TextEdit::fileOpen() |
499 | { | 490 | { |
500 | // if ( !save() ) { | 491 | // if ( !save() ) { |
501 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 492 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
502 | // tr( "Text Editor was unable to\n" | 493 | // tr( "Text Editor was unable to\n" |
503 | // "save your changes.\n" | 494 | // "save your changes.\n" |
504 | // "Free some space and try again.\n" | 495 | // "Free some space and try again.\n" |
505 | // "\nContinue anyway?" ), | 496 | // "\nContinue anyway?" ), |
506 | // QMessageBox::Yes|QMessageBox::Escape, | 497 | // QMessageBox::Yes|QMessageBox::Escape, |
507 | // QMessageBox::No|QMessageBox::Default ) | 498 | // QMessageBox::No|QMessageBox::Default ) |
508 | // != QMessageBox::Yes ) | 499 | // != QMessageBox::Yes ) |
509 | // return; | 500 | // return; |
510 | // else { | 501 | // else { |
511 | // delete doc; | 502 | // delete doc; |
512 | // doc = 0; | 503 | // doc = 0; |
513 | // } | 504 | // } |
514 | // } | 505 | // } |
515 | menu->hide(); | 506 | menu->hide(); |
516 | editBar->hide(); | 507 | editBar->hide(); |
517 | searchBar->hide(); | 508 | searchBar->hide(); |
518 | clearWState (WState_Reserved1 ); | 509 | clearWState (WState_Reserved1 ); |
519 | editorStack->raiseWidget( fileSelector ); | 510 | editorStack->raiseWidget( fileSelector ); |
520 | fileSelector->reread(); | 511 | fileSelector->reread(); |
521 | updateCaption(currentFileName); | 512 | updateCaption(currentFileName); |
522 | } | 513 | } |
523 | 514 | ||
524 | void TextEdit::newFileOpen() | 515 | void TextEdit::newFileOpen() |
525 | { | 516 | { |
526 | fileBrowser *browseForFiles; | 517 | fileBrowser *browseForFiles; |
527 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); | 518 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); |
528 | if( browseForFiles->exec()!= 0 ) { | 519 | if( browseForFiles->exec()!= 0 ) { |
529 | QString selFile= browseForFiles->selectedFileName; | 520 | QString selFile= browseForFiles->selectedFileName; |
530 | QStringList fileList=browseForFiles->fileList; | 521 | QStringList fileList=browseForFiles->fileList; |
531 | qDebug(selFile); | 522 | qDebug(selFile); |
532 | QStringList::ConstIterator f; | 523 | QStringList::ConstIterator f; |
533 | QString fileTemp; | 524 | QString fileTemp; |
534 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 525 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
535 | fileTemp = *f; | 526 | fileTemp = *f; |
536 | fileTemp.right( fileTemp.length()-5); | 527 | fileTemp.right( fileTemp.length()-5); |
537 | QString fileName = fileTemp; | 528 | QString fileName = fileTemp; |
538 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 529 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
539 | currentFileName = fileName; | 530 | currentFileName = fileName; |
540 | // qDebug("please open "+currentFileName); | 531 | // qDebug("please open "+currentFileName); |
541 | openFile(fileName ); | 532 | openFile(fileName ); |
542 | } | 533 | } |
543 | } | 534 | } |
544 | } | 535 | } |
545 | delete browseForFiles; | 536 | delete browseForFiles; |
546 | 537 | ||
547 | } | 538 | } |
548 | 539 | ||
549 | #if 0 | 540 | #if 0 |
550 | void TextEdit::slotFind() | 541 | void TextEdit::slotFind() |
551 | { | 542 | { |
552 | FindDialog frmFind( "Text Editor", this ); | 543 | FindDialog frmFind( "Text Editor", this ); |
553 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 544 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
554 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 545 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
555 | 546 | ||
556 | //case sensitive, backwards, [category] | 547 | //case sensitive, backwards, [category] |
557 | 548 | ||
558 | connect( editor, SIGNAL(notFound()), | 549 | connect( editor, SIGNAL(notFound()), |
559 | &frmFind, SLOT(slotNotFound()) ); | 550 | &frmFind, SLOT(slotNotFound()) ); |
560 | connect( editor, SIGNAL(searchWrapped()), | 551 | connect( editor, SIGNAL(searchWrapped()), |
561 | &frmFind, SLOT(slotWrapAround()) ); | 552 | &frmFind, SLOT(slotWrapAround()) ); |
562 | 553 | ||
563 | frmFind.exec(); | 554 | frmFind.exec(); |
564 | 555 | ||
565 | 556 | ||
566 | } | 557 | } |
567 | #endif | 558 | #endif |
568 | 559 | ||
569 | void TextEdit::fileRevert() | 560 | void TextEdit::fileRevert() |
570 | { | 561 | { |
571 | clear(); | 562 | clear(); |
572 | fileOpen(); | 563 | fileOpen(); |
573 | } | 564 | } |
574 | 565 | ||
575 | void TextEdit::editCut() | 566 | void TextEdit::editCut() |
576 | { | 567 | { |
577 | #ifndef QT_NO_CLIPBOARD | 568 | #ifndef QT_NO_CLIPBOARD |
578 | editor->cut(); | 569 | editor->cut(); |
579 | #endif | 570 | #endif |
580 | } | 571 | } |
581 | 572 | ||
582 | void TextEdit::editCopy() | 573 | void TextEdit::editCopy() |
583 | { | 574 | { |
584 | #ifndef QT_NO_CLIPBOARD | 575 | #ifndef QT_NO_CLIPBOARD |
585 | editor->copy(); | 576 | editor->copy(); |
586 | #endif | 577 | #endif |
587 | } | 578 | } |
588 | 579 | ||
589 | void TextEdit::editPaste() | 580 | void TextEdit::editPaste() |
590 | { | 581 | { |
591 | #ifndef QT_NO_CLIPBOARD | 582 | #ifndef QT_NO_CLIPBOARD |
592 | editor->paste(); | 583 | editor->paste(); |
593 | #endif | 584 | #endif |
594 | } | 585 | } |
595 | 586 | ||
596 | void TextEdit::editFind() | 587 | void TextEdit::editFind() |
597 | { | 588 | { |
598 | searchBar->show(); | 589 | searchBar->show(); |
599 | searchVisible = TRUE; | 590 | searchVisible = TRUE; |
600 | searchEdit->setFocus(); | 591 | searchEdit->setFocus(); |
601 | } | 592 | } |
602 | 593 | ||
603 | void TextEdit::findNext() | 594 | void TextEdit::findNext() |
604 | { | 595 | { |
605 | editor->find( searchEdit->text(), FALSE, FALSE ); | 596 | editor->find( searchEdit->text(), FALSE, FALSE ); |
606 | 597 | ||
607 | } | 598 | } |
608 | 599 | ||
609 | void TextEdit::findClose() | 600 | void TextEdit::findClose() |
610 | { | 601 | { |
611 | searchVisible = FALSE; | 602 | searchVisible = FALSE; |
612 | searchBar->hide(); | 603 | searchBar->hide(); |
613 | } | 604 | } |
614 | 605 | ||
615 | void TextEdit::search() | 606 | void TextEdit::search() |
616 | { | 607 | { |
617 | editor->find( searchEdit->text(), FALSE, FALSE ); | 608 | editor->find( searchEdit->text(), FALSE, FALSE ); |
618 | } | 609 | } |
619 | 610 | ||
620 | void TextEdit::newFile( const DocLnk &f ) | 611 | void TextEdit::newFile( const DocLnk &f ) |
621 | { | 612 | { |
622 | DocLnk nf = f; | 613 | DocLnk nf = f; |
623 | nf.setType("text/plain"); | 614 | nf.setType("text/plain"); |
624 | clear(); | 615 | clear(); |
625 | editorStack->raiseWidget( editor ); | 616 | editorStack->raiseWidget( editor ); |
626 | setWState (WState_Reserved1 ); | 617 | setWState (WState_Reserved1 ); |
627 | editor->setFocus(); | 618 | editor->setFocus(); |
628 | doc = new DocLnk(nf); | 619 | doc = new DocLnk(nf); |
629 | // updateCaption(); | 620 | updateCaption(currentFileName); |
630 | } | 621 | } |
631 | 622 | ||
632 | void TextEdit::openFile( const QString &f ) | 623 | void TextEdit::openFile( const QString &f ) |
633 | { | 624 | { |
634 | bFromDocView = TRUE; | 625 | bFromDocView = TRUE; |
635 | DocLnk nf; | 626 | DocLnk nf; |
636 | nf.setType("text/plain"); | 627 | nf.setType("text/plain"); |
637 | nf.setFile(f); | 628 | nf.setFile(f); |
638 | openFile(nf); | 629 | openFile(nf); |
639 | showEditTools(); | 630 | showEditTools(); |
640 | // Show filename in caption | 631 | // Show filename in caption |
641 | QString name = f; | 632 | QString name = f; |
642 | int sep = name.findRev( '/' ); | 633 | int sep = name.findRev( '/' ); |
643 | if ( sep > 0 ) | 634 | if ( sep > 0 ) |
644 | name = name.mid( sep+1 ); | 635 | name = name.mid( sep+1 ); |
645 | updateCaption( name ); | 636 | updateCaption( name ); |
646 | } | 637 | } |
647 | 638 | ||
648 | void TextEdit::openFile( const DocLnk &f ) | 639 | void TextEdit::openFile( const DocLnk &f ) |
649 | { | 640 | { |
650 | // clear(); | 641 | // clear(); |
651 | bFromDocView = TRUE; | 642 | bFromDocView = TRUE; |
652 | FileManager fm; | 643 | FileManager fm; |
653 | QString txt; | 644 | QString txt; |
654 | if ( !fm.loadFile( f, txt ) ) { | 645 | if ( !fm.loadFile( f, txt ) ) { |
655 | // ####### could be a new file | 646 | // ####### could be a new file |
656 | qDebug( "Cannot open file" ); | 647 | qDebug( "Cannot open file" ); |
657 | 648 | ||
658 | //return; | 649 | //return; |
659 | } | 650 | } |
660 | 651 | ||
661 | fileNew(); | 652 | fileNew(); |
662 | if ( doc ) | 653 | if ( doc ) |
663 | delete doc; | 654 | delete doc; |
664 | doc = new DocLnk(f); | 655 | doc = new DocLnk(f); |
665 | editor->setText(txt); | 656 | editor->setText(txt); |
666 | editor->setEdited(FALSE); | 657 | editor->setEdited(FALSE); |
667 | updateCaption(currentFileName); | 658 | updateCaption(currentFileName); |
668 | } | 659 | } |
669 | 660 | ||
670 | void TextEdit::showEditTools() | 661 | void TextEdit::showEditTools() |
671 | { | 662 | { |
672 | // if ( !doc ) | 663 | // if ( !doc ) |
673 | // close(); | 664 | // close(); |
674 | // clear(); | 665 | // clear(); |
675 | fileSelector->hide(); | 666 | fileSelector->hide(); |
676 | menu->show(); | 667 | menu->show(); |
677 | editBar->show(); | 668 | editBar->show(); |
678 | if ( searchVisible ) | 669 | if ( searchVisible ) |
679 | searchBar->show(); | 670 | searchBar->show(); |
680 | // updateCaption(); | 671 | // updateCaption(); |
681 | editorStack->raiseWidget( editor ); | 672 | editorStack->raiseWidget( editor ); |
682 | setWState (WState_Reserved1 ); | 673 | setWState (WState_Reserved1 ); |
683 | } | 674 | } |
684 | 675 | ||
685 | bool TextEdit::save() | 676 | bool TextEdit::save() |
686 | { | 677 | { |
687 | QString rt = editor->text(); | 678 | QString rt = editor->text(); |
688 | doc->setName( currentFileName); | 679 | doc->setName( currentFileName); |
689 | FileManager fm; | 680 | FileManager fm; |
690 | if ( !fm.saveFile( *doc, rt ) ) { | 681 | if ( !fm.saveFile( *doc, rt ) ) { |
691 | return false; | 682 | return false; |
692 | } | 683 | } |
693 | delete doc; | 684 | delete doc; |
694 | doc = 0; | 685 | doc = 0; |
695 | editor->setEdited( false ); | 686 | editor->setEdited( false ); |
696 | return true; | 687 | return true; |
697 | 688 | ||
698 | } | 689 | } |
699 | 690 | ||
700 | bool TextEdit::saveAs() | 691 | bool TextEdit::saveAs() |
701 | { | 692 | { |
702 | // case of nothing to save... | 693 | // case of nothing to save... |
703 | if ( !doc || !bFromDocView) | 694 | if ( !doc || !bFromDocView) |
704 | return true; | 695 | return true; |
705 | if ( !editor->edited() ) { | 696 | if ( !editor->edited() ) { |
706 | delete doc; | 697 | delete doc; |
707 | doc = 0; | 698 | doc = 0; |
708 | return true; | 699 | return true; |
709 | } | 700 | } |
710 | 701 | ||
711 | QString rt = editor->text(); | 702 | QString rt = editor->text(); |
712 | qDebug(currentFileName); | 703 | qDebug(currentFileName); |
713 | 704 | ||
714 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 705 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
715 | 706 | ||
716 | if ( doc->name().isEmpty() ) { | 707 | if ( doc->name().isEmpty() ) { |
717 | QString pt = rt.simplifyWhiteSpace(); | 708 | QString pt = rt.simplifyWhiteSpace(); |
718 | int i = pt.find( ' ' ); | 709 | int i = pt.find( ' ' ); |
719 | QString docname = pt; | 710 | QString docname = pt; |
720 | if ( i > 0 ) | 711 | if ( i > 0 ) |
721 | docname = pt.left( i ); | 712 | docname = pt.left( i ); |
722 | // remove "." at the beginning | 713 | // remove "." at the beginning |
723 | while( docname.startsWith( "." ) ) | 714 | while( docname.startsWith( "." ) ) |
724 | docname = docname.mid( 1 ); | 715 | docname = docname.mid( 1 ); |
725 | docname.replace( QRegExp("/"), "_" ); | 716 | docname.replace( QRegExp("/"), "_" ); |
726 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 717 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
727 | if ( docname.length() > 40 ) | 718 | if ( docname.length() > 40 ) |
728 | docname = docname.left(40); | 719 | docname = docname.left(40); |
729 | if ( docname.isEmpty() ) | 720 | if ( docname.isEmpty() ) |
730 | docname = "Empty Text"; | 721 | docname = "Empty Text"; |
731 | doc->setName(docname); | 722 | doc->setName(docname); |
732 | currentFileName=docname; | 723 | currentFileName=docname; |
733 | } | 724 | } |
734 | } | 725 | } |
735 | 726 | ||
736 | fileSaver *fileSaveDlg; | 727 | fileSaver *fileSaveDlg; |
737 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); | 728 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); |
738 | if( fileSaveDlg->exec() != 0 ) { | 729 | if( fileSaveDlg->exec() != 0 ) { |
739 | QString fileNm=fileSaveDlg->selectedFileName; | 730 | QString fileNm=fileSaveDlg->selectedFileName; |
740 | qDebug("save filename "+fileNm); | 731 | qDebug("save filename "+fileNm); |
741 | doc->setName(fileNm); | 732 | doc->setName(fileNm); |
742 | updateCaption(fileNm); | 733 | updateCaption(fileNm); |
743 | } | 734 | } |
744 | delete fileSaveDlg; | 735 | delete fileSaveDlg; |
745 | 736 | ||
746 | FileManager fm; | 737 | FileManager fm; |
747 | if ( !fm.saveFile( *doc, rt ) ) { | 738 | if ( !fm.saveFile( *doc, rt ) ) { |
748 | return false; | 739 | return false; |
749 | } | 740 | } |
750 | delete doc; | 741 | delete doc; |
751 | doc = 0; | 742 | doc = 0; |
752 | editor->setEdited( false ); | 743 | editor->setEdited( false ); |
753 | return true; | 744 | return true; |
754 | } | 745 | } |
755 | 746 | ||
756 | void TextEdit::clear() | 747 | void TextEdit::clear() |
757 | { | 748 | { |
758 | delete doc; | 749 | delete doc; |
759 | doc = 0; | 750 | doc = 0; |
760 | editor->clear(); | 751 | editor->clear(); |
761 | } | 752 | } |
762 | 753 | ||
763 | void TextEdit::updateCaption( const QString &name ) | 754 | void TextEdit::updateCaption( const QString &name ) |
764 | { | 755 | { |
765 | if ( !doc ) | 756 | if ( !doc ) |
766 | setCaption( tr("Text Editor") ); | 757 | setCaption( tr("Text Editor") ); |
767 | else { | 758 | else { |
768 | QString s = name; | 759 | QString s = name; |
769 | if ( s.isNull() ) | 760 | if ( s.isNull() ) |
770 | s = doc->name(); | 761 | s = doc->name(); |
771 | if ( s.isEmpty() ) { | 762 | if ( s.isEmpty() ) { |
772 | s = tr( "Unnamed" ); | 763 | s = tr( "Unnamed" ); |
773 | currentFileName=s; | 764 | currentFileName=s; |
774 | } | 765 | } |
766 | |||
775 | setCaption( s + " - " + tr("Text Editor") ); | 767 | setCaption( s + " - " + tr("Text Editor") ); |
776 | } | 768 | } |
777 | } | 769 | } |
778 | 770 | ||
779 | void TextEdit::setDocument(const QString& fileref) | 771 | void TextEdit::setDocument(const QString& fileref) |
780 | { | 772 | { |
781 | bFromDocView = TRUE; | 773 | bFromDocView = TRUE; |
782 | openFile(DocLnk(fileref)); | 774 | openFile(DocLnk(fileref)); |
783 | // showEditTools(); | 775 | // showEditTools(); |
784 | } | 776 | } |
785 | 777 | ||
786 | void TextEdit::closeEvent( QCloseEvent *e ) | 778 | void TextEdit::closeEvent( QCloseEvent *e ) |
787 | { | 779 | { |
788 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { | 780 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { |
789 | e->ignore(); | 781 | e->ignore(); |
790 | repaint(); | 782 | repaint(); |
791 | // fileRevert(); | 783 | // fileRevert(); |
792 | 784 | ||
793 | } else { | 785 | } else { |
794 | bFromDocView = FALSE; | 786 | bFromDocView = FALSE; |
795 | e->accept(); | 787 | e->accept(); |
796 | } | 788 | } |
797 | } | 789 | } |
798 | 790 | ||
799 | void TextEdit::accept() | 791 | void TextEdit::accept() |
800 | { | 792 | { |
801 | close(); | 793 | close(); |
802 | // fileOpen(); //godamn thats obnoxious! lemme out!!! | 794 | // fileOpen(); //godamn thats obnoxious! lemme out!!! |
803 | } | 795 | } |
804 | 796 | ||
805 | void TextEdit::changeFont() { | 797 | void TextEdit::changeFont() { |
806 | FontDatabase fdb; | 798 | FontDatabase fdb; |
807 | QFont defaultFont=editor->font(); | 799 | QFont defaultFont=editor->font(); |
808 | QFontInfo fontInfo(defaultFont); | 800 | QFontInfo fontInfo(defaultFont); |
809 | Config cfg("TextEdit"); | 801 | Config cfg("TextEdit"); |
810 | cfg.setGroup("Font"); | 802 | cfg.setGroup("Font"); |
811 | QString family = cfg.readEntry("Family", fontInfo.family()); | 803 | QString family = cfg.readEntry("Family", fontInfo.family()); |
812 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 804 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
813 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 805 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
814 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 806 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
815 | 807 | ||
816 | defaultFont = fdb.font(family,style,i_size,charSet); | 808 | defaultFont = fdb.font(family,style,i_size,charSet); |
817 | 809 | ||
818 | FontDialog *fontDlg; | 810 | FontDialog *fontDlg; |
819 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | 811 | fontDlg=new FontDialog(this,"FontDialog",TRUE); |
820 | 812 | ||
821 | fontDlg->exec(); | 813 | fontDlg->exec(); |
822 | 814 | ||
823 | QFont myFont=fontDlg->selectedFont; | 815 | QFont myFont=fontDlg->selectedFont; |
824 | editor->setFont( myFont); | 816 | editor->setFont( myFont); |
825 | delete fontDlg; | 817 | delete fontDlg; |
826 | 818 | ||
827 | } | 819 | } |
828 | 820 | ||