Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 130 |
1 files changed, 31 insertions, 99 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index f571511..b81f3b4 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -1,252 +1,154 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | // textedit.cpp | 2 | // textedit.cpp |
3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
4 | ** | 4 | ** |
5 | ** This file is part of Opie Environment. | 5 | ** This file is part of Opie Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | **********************************************************************/ | 12 | **********************************************************************/ |
13 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 | 13 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 |
14 | #include "textedit.h" | 14 | #include "textedit.h" |
15 | #include "filePermissions.h" | 15 | #include "filePermissions.h" |
16 | 16 | ||
17 | 17 | ||
18 | #include <opie/ofileselector.h> | 18 | #include <opie/ofileselector.h> |
19 | #include <opie/ofiledialog.h> | 19 | #include <opie/ofiledialog.h> |
20 | #include <opie/ofontselector.h> | 20 | #include <opie/ofontselector.h> |
21 | 21 | ||
22 | #include <qpe/fontdatabase.h> | 22 | #include <qpe/fontdatabase.h> |
23 | #include <qpe/global.h> | 23 | #include <qpe/global.h> |
24 | #include <qpe/fileselector.h> | 24 | #include <qpe/fileselector.h> |
25 | #include <qpe/applnk.h> | 25 | #include <qpe/applnk.h> |
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | #include <qpe/qpeapplication.h> | 28 | #include <qpe/qpeapplication.h> |
29 | #include <qpe/qpemenubar.h> | 29 | #include <qpe/qpemenubar.h> |
30 | #include <qpe/qpetoolbar.h> | 30 | #include <qpe/qpetoolbar.h> |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | 32 | ||
33 | #include <qpoint.h> | 33 | #include <qpoint.h> |
34 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
35 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
36 | #include <qclipboard.h> | 36 | #include <qclipboard.h> |
37 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
38 | #include <qaction.h> | 38 | #include <qaction.h> |
39 | #include <qcolordialog.h> | 39 | #include <qcolordialog.h> |
40 | #include <qfileinfo.h> | 40 | #include <qfileinfo.h> |
41 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | #include <qmessagebox.h> | 42 | #include <qmessagebox.h> |
43 | #include <qobjectlist.h> | 43 | #include <qobjectlist.h> |
44 | #include <qpopupmenu.h> | 44 | #include <qpopupmenu.h> |
45 | #include <qspinbox.h> | 45 | #include <qspinbox.h> |
46 | #include <qtoolbutton.h> | 46 | #include <qtoolbutton.h> |
47 | #include <qwidgetstack.h> | 47 | #include <qwidgetstack.h> |
48 | #include <qcheckbox.h> | 48 | #include <qcheckbox.h> |
49 | #include <qcombo.h> | 49 | #include <qcombo.h> |
50 | #include <qlayout.h> | 50 | #include <qlayout.h> |
51 | #include <qapplication.h> | 51 | #include <qapplication.h> |
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | #include <qdir.h> | 53 | #include <qdir.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <sys/stat.h> | 55 | #include <sys/stat.h> |
56 | #include <stdlib.h> //getenv | 56 | #include <stdlib.h> //getenv |
57 | 57 | ||
58 | 58 | #include "resource.h" | |
59 | /* XPM */ | ||
60 | static char * filesave_xpm[] = { | ||
61 | "16 16 78 1", | ||
62 | " c None", | ||
63 | ". c #343434", | ||
64 | "+ c #A0A0A0", | ||
65 | "@ c #565656", | ||
66 | "# c #9E9E9E", | ||
67 | "$ c #525252", | ||
68 | "% c #929292", | ||
69 | "& c #676767", | ||
70 | "* c #848484", | ||
71 | "= c #666666", | ||
72 | "- c #D8D8D8", | ||
73 | "; c #FFFFFF", | ||
74 | "> c #DBDBDB", | ||
75 | ", c #636363", | ||
76 | "' c #989898", | ||
77 | ") c #2D2D2D", | ||
78 | "! c #909090", | ||
79 | "~ c #AEAEAE", | ||
80 | "{ c #EAEAEA", | ||
81 | "] c #575757", | ||
82 | "^ c #585858", | ||
83 | "/ c #8A8A8A", | ||
84 | "( c #828282", | ||
85 | "_ c #6F6F6F", | ||
86 | ": c #C9C9C9", | ||
87 | "< c #050505", | ||
88 | "[ c #292929", | ||
89 | "} c #777777", | ||
90 | "| c #616161", | ||
91 | "1 c #3A3A3A", | ||
92 | "2 c #BEBEBE", | ||
93 | "3 c #2C2C2C", | ||
94 | "4 c #7C7C7C", | ||
95 | "5 c #F6F6F6", | ||
96 | "6 c #FCFCFC", | ||
97 | "7 c #6B6B6B", | ||
98 | "8 c #959595", | ||
99 | "9 c #4F4F4F", | ||
100 | "0 c #808080", | ||
101 | "a c #767676", | ||
102 | "b c #818181", | ||
103 | "c c #B8B8B8", | ||
104 | "d c #FBFBFB", | ||
105 | "e c #F9F9F9", | ||
106 | "f c #CCCCCC", | ||
107 | "g c #030303", | ||
108 | "h c #737373", | ||
109 | "i c #7A7A7A", | ||
110 | "j c #7E7E7E", | ||
111 | "k c #6A6A6A", | ||
112 | "l c #FAFAFA", | ||
113 | "m c #505050", | ||
114 | "n c #9D9D9D", | ||
115 | "o c #333333", | ||
116 | "p c #7B7B7B", | ||
117 | "q c #787878", | ||
118 | "r c #696969", | ||
119 | "s c #494949", | ||
120 | "t c #555555", | ||
121 | "u c #949494", | ||
122 | "v c #E6E6E6", | ||
123 | "w c #424242", | ||
124 | "x c #515151", | ||
125 | "y c #535353", | ||
126 | "z c #3E3E3E", | ||
127 | "A c #D4D4D4", | ||
128 | "B c #0C0C0C", | ||
129 | "C c #353535", | ||
130 | "D c #474747", | ||
131 | "E c #ECECEC", | ||
132 | "F c #919191", | ||
133 | "G c #7D7D7D", | ||
134 | "H c #000000", | ||
135 | "I c #404040", | ||
136 | "J c #858585", | ||
137 | "K c #323232", | ||
138 | "L c #D0D0D0", | ||
139 | "M c #1C1C1C", | ||
140 | " ...+ ", | ||
141 | " @#$%&..+ ", | ||
142 | " .*=-;;>,..+ ", | ||
143 | " ')!~;;;;;;{]..", | ||
144 | " ^/(-;;;;;;;_:<", | ||
145 | " [}|;;;;;;;{12$", | ||
146 | " #34-55;;;;678$+", | ||
147 | " 90ab=c;dd;e1fg ", | ||
148 | " [ahij((kbl0mn$ ", | ||
149 | " op^q^^7r&]s/$+ ", | ||
150 | "@btu;vbwxy]zAB ", | ||
151 | "CzDEvEv;;DssF$ ", | ||
152 | "G.H{E{E{IxsJ$+ ", | ||
153 | " +...vEKxzLM ", | ||
154 | " +...z]n$ ", | ||
155 | " +... "}; | ||
156 | |||
157 | 59 | ||
158 | #if QT_VERSION < 300 | 60 | #if QT_VERSION < 300 |
159 | 61 | ||
160 | class QpeEditor : public QMultiLineEdit | 62 | class QpeEditor : public QMultiLineEdit |
161 | { | 63 | { |
162 | 64 | ||
163 | public: | 65 | public: |
164 | QpeEditor( QWidget *parent, const char * name = 0 ) | 66 | QpeEditor( QWidget *parent, const char * name = 0 ) |
165 | : QMultiLineEdit( parent, name ) { | 67 | : QMultiLineEdit( parent, name ) { |
166 | clearTableFlags(); | 68 | clearTableFlags(); |
167 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 69 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
168 | } | 70 | } |
169 | 71 | ||
170 | void find( const QString &txt, bool caseSensitive, | 72 | void find( const QString &txt, bool caseSensitive, |
171 | bool backwards ); | 73 | bool backwards ); |
172 | protected: | 74 | protected: |
173 | bool markIt; | 75 | bool markIt; |
174 | int line1, line2, col1, col2; | 76 | int line1, line2, col1, col2; |
175 | void mousePressEvent( QMouseEvent * ); | 77 | void mousePressEvent( QMouseEvent * ); |
176 | void mouseReleaseEvent( QMouseEvent * ); | 78 | void mouseReleaseEvent( QMouseEvent * ); |
177 | 79 | ||
178 | //public slots: | 80 | //public slots: |
179 | /* | 81 | /* |
180 | signals: | 82 | signals: |
181 | void notFound(); | 83 | void notFound(); |
182 | void searchWrapped(); | 84 | void searchWrapped(); |
183 | */ | 85 | */ |
184 | 86 | ||
185 | private: | 87 | private: |
186 | 88 | ||
187 | }; | 89 | }; |
188 | 90 | ||
189 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { | 91 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { |
190 | switch(e->button()) { | 92 | switch(e->button()) { |
191 | case RightButton: | 93 | case RightButton: |
192 | { //rediculous workaround for qt popup menu | 94 | { //rediculous workaround for qt popup menu |
193 | //and the hold right click mechanism | 95 | //and the hold right click mechanism |
194 | this->setSelection( line1, col1, line2, col2); | 96 | this->setSelection( line1, col1, line2, col2); |
195 | QMultiLineEdit::mousePressEvent( e ); | 97 | QMultiLineEdit::mousePressEvent( e ); |
196 | markIt = false; | 98 | markIt = false; |
197 | } | 99 | } |
198 | break; | 100 | break; |
199 | default: | 101 | default: |
200 | { | 102 | { |
201 | if(!markIt) { | 103 | if(!markIt) { |
202 | int line, col; | 104 | int line, col; |
203 | this->getCursorPosition(&line, &col); | 105 | this->getCursorPosition(&line, &col); |
204 | line1=line2=line; | 106 | line1=line2=line; |
205 | col1=col2=col; | 107 | col1=col2=col; |
206 | } | 108 | } |
207 | QMultiLineEdit::mousePressEvent( e ); | 109 | QMultiLineEdit::mousePressEvent( e ); |
208 | } | 110 | } |
209 | break; | 111 | break; |
210 | }; | 112 | }; |
211 | } | 113 | } |
212 | 114 | ||
213 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { | 115 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { |
214 | if(this->hasMarkedText()) { | 116 | if(this->hasMarkedText()) { |
215 | markIt = true; | 117 | markIt = true; |
216 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); | 118 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); |
217 | } else { | 119 | } else { |
218 | markIt = false; | 120 | markIt = false; |
219 | } | 121 | } |
220 | } | 122 | } |
221 | 123 | ||
222 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 124 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
223 | bool backwards ) | 125 | bool backwards ) |
224 | { | 126 | { |
225 | static bool wrap = false; | 127 | static bool wrap = false; |
226 | int line, col; | 128 | int line, col; |
227 | if ( wrap ) { | 129 | if ( wrap ) { |
228 | if ( !backwards ) | 130 | if ( !backwards ) |
229 | line = col = 0; | 131 | line = col = 0; |
230 | wrap = false; | 132 | wrap = false; |
231 | // emit searchWrapped(); | 133 | // emit searchWrapped(); |
232 | } else { | 134 | } else { |
233 | getCursorPosition( &line, &col ); | 135 | getCursorPosition( &line, &col ); |
234 | } | 136 | } |
235 | //ignore backwards for now.... | 137 | //ignore backwards for now.... |
236 | if ( !backwards ) { | 138 | if ( !backwards ) { |
237 | for ( ; ; ) { | 139 | for ( ; ; ) { |
238 | if ( line >= numLines() ) { | 140 | if ( line >= numLines() ) { |
239 | wrap = true; | 141 | wrap = true; |
240 | //emit notFound(); | 142 | //emit notFound(); |
241 | break; | 143 | break; |
242 | } | 144 | } |
243 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 145 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
244 | if ( findCol >= 0 ) { | 146 | if ( findCol >= 0 ) { |
245 | setCursorPosition( line, findCol, false ); | 147 | setCursorPosition( line, findCol, false ); |
246 | col = findCol + txt.length(); | 148 | col = findCol + txt.length(); |
247 | setCursorPosition( line, col, true ); | 149 | setCursorPosition( line, col, true ); |
248 | 150 | ||
249 | //found = true; | 151 | //found = true; |
250 | break; | 152 | break; |
251 | } | 153 | } |
252 | line++; | 154 | line++; |
@@ -260,192 +162,197 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, | |||
260 | 162 | ||
261 | #error "Must make a QpeEditor that inherits QTextEdit" | 163 | #error "Must make a QpeEditor that inherits QTextEdit" |
262 | 164 | ||
263 | #endif | 165 | #endif |
264 | 166 | ||
265 | 167 | ||
266 | static const int nfontsizes = 6; | 168 | static const int nfontsizes = 6; |
267 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 169 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
268 | 170 | ||
269 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 171 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
270 | : QMainWindow( parent, name, f ), bFromDocView( false ) | 172 | : QMainWindow( parent, name, f ), bFromDocView( false ) |
271 | { | 173 | { |
272 | doc = 0; | 174 | doc = 0; |
273 | edited=false; | 175 | edited=false; |
274 | fromSetDocument=false; | 176 | fromSetDocument=false; |
275 | 177 | ||
276 | setToolBarsMovable( false ); | 178 | setToolBarsMovable( false ); |
277 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 179 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
278 | 180 | ||
279 | channel = new QCopChannel( "QPE/Application/textedit", this ); | 181 | channel = new QCopChannel( "QPE/Application/textedit", this ); |
280 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 182 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
281 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 183 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
282 | 184 | ||
283 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 185 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
284 | 186 | ||
285 | QPEToolBar *bar = new QPEToolBar( this ); | 187 | QPEToolBar *bar = new QPEToolBar( this ); |
286 | bar->setHorizontalStretchable( true ); | 188 | bar->setHorizontalStretchable( true ); |
287 | menu = bar; | 189 | menu = bar; |
288 | 190 | ||
289 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 191 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
290 | QPopupMenu *file = new QPopupMenu( this ); | 192 | QPopupMenu *file = new QPopupMenu( this ); |
291 | QPopupMenu *edit = new QPopupMenu( this ); | 193 | QPopupMenu *edit = new QPopupMenu( this ); |
292 | QPopupMenu *advancedMenu = new QPopupMenu(this); | 194 | QPopupMenu *advancedMenu = new QPopupMenu(this); |
293 | 195 | ||
294 | font = new QPopupMenu( this ); | 196 | font = new QPopupMenu( this ); |
295 | 197 | ||
296 | bar = new QPEToolBar( this ); | 198 | bar = new QPEToolBar( this ); |
297 | editBar = bar; | 199 | editBar = bar; |
298 | 200 | ||
299 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 201 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
300 | QString::null, 0, this, 0 ); | 202 | QString::null, 0, this, 0 ); |
301 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 203 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
302 | // a->addTo( bar ); | 204 | // a->addTo( bar ); |
303 | a->addTo( file ); | 205 | a->addTo( file ); |
304 | 206 | ||
305 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), | 207 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), |
306 | QString::null, 0, this, 0 ); | 208 | QString::null, 0, this, 0 ); |
307 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 209 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
308 | a->addTo( bar ); | 210 | a->addTo( bar ); |
309 | a->addTo( file ); | 211 | a->addTo( file ); |
310 | 212 | ||
311 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , | 213 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , |
312 | QString::null, 0, this, 0 ); | 214 | QString::null, 0, this, 0 ); |
313 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 215 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
314 | file->insertSeparator(); | 216 | file->insertSeparator(); |
315 | a->addTo( bar ); | 217 | a->addTo( bar ); |
316 | a->addTo( file ); | 218 | a->addTo( file ); |
317 | 219 | ||
318 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , | 220 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , |
319 | QString::null, 0, this, 0 ); | 221 | QString::null, 0, this, 0 ); |
320 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 222 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
321 | a->addTo( file ); | 223 | a->addTo( file ); |
322 | 224 | ||
323 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), | 225 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), |
324 | QString::null, 0, this, 0 ); | 226 | QString::null, 0, this, 0 ); |
325 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 227 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
326 | a->addTo( editBar ); | 228 | a->addTo( editBar ); |
327 | a->addTo( edit ); | 229 | a->addTo( edit ); |
328 | 230 | ||
329 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), | 231 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), |
330 | QString::null, 0, this, 0 ); | 232 | QString::null, 0, this, 0 ); |
331 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 233 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
332 | a->addTo( editBar ); | 234 | a->addTo( editBar ); |
333 | a->addTo( edit ); | 235 | a->addTo( edit ); |
334 | 236 | ||
335 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), | 237 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), |
336 | QString::null, 0, this, 0 ); | 238 | QString::null, 0, this, 0 ); |
337 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 239 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
338 | a->addTo( editBar ); | 240 | a->addTo( editBar ); |
339 | a->addTo( edit ); | 241 | a->addTo( edit ); |
340 | 242 | ||
341 | 243 | ||
342 | #ifndef QT_NO_CLIPBOARD | 244 | #ifndef QT_NO_CLIPBOARD |
343 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), | 245 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), |
344 | QString::null, 0, this, 0 ); | 246 | QString::null, 0, this, 0 ); |
345 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); | 247 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); |
346 | a->addTo( edit ); | 248 | a->addTo( edit ); |
347 | #endif | 249 | #endif |
348 | 250 | ||
349 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), | 251 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), |
350 | QString::null, 0, this, 0 ); | 252 | QString::null, 0, this, 0 ); |
351 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 253 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
352 | edit->insertSeparator(); | 254 | edit->insertSeparator(); |
353 | a->addTo( bar ); | 255 | a->addTo( bar ); |
354 | a->addTo( edit ); | 256 | a->addTo( edit ); |
355 | 257 | ||
258 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), | ||
259 | QString::null, 0, this, 0 ); | ||
260 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); | ||
261 | a->addTo( edit ); | ||
262 | |||
356 | 263 | ||
357 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 264 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
358 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 265 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
359 | zin->addTo( font ); | 266 | zin->addTo( font ); |
360 | 267 | ||
361 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 268 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
362 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 269 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
363 | zout->addTo( font ); | 270 | zout->addTo( font ); |
364 | 271 | ||
365 | font->insertSeparator(); | 272 | font->insertSeparator(); |
366 | 273 | ||
367 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); | 274 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
368 | 275 | ||
369 | font->insertSeparator(); | 276 | font->insertSeparator(); |
370 | font->insertItem(tr("Advanced Features"), advancedMenu); | 277 | font->insertItem(tr("Advanced Features"), advancedMenu); |
371 | 278 | ||
372 | QAction *wa = new QAction( tr("Wrap lines"), | 279 | QAction *wa = new QAction( tr("Wrap lines"), |
373 | QString::null, 0, this, 0 ); | 280 | QString::null, 0, this, 0 ); |
374 | connect( wa, SIGNAL( toggled(bool) ), | 281 | connect( wa, SIGNAL( toggled(bool) ), |
375 | this, SLOT( setWordWrap(bool) ) ); | 282 | this, SLOT( setWordWrap(bool) ) ); |
376 | wa->setToggleAction(true); | 283 | wa->setToggleAction(true); |
377 | wa->addTo( advancedMenu); | 284 | wa->addTo( advancedMenu); |
378 | 285 | ||
379 | nStart = new QAction( tr("Start with new file"), | 286 | nStart = new QAction( tr("Start with new file"), |
380 | QString::null, 0, this, 0 ); | 287 | QString::null, 0, this, 0 ); |
381 | connect( nStart, SIGNAL( toggled(bool) ), | 288 | connect( nStart, SIGNAL( toggled(bool) ), |
382 | this, SLOT( changeStartConfig(bool) ) ); | 289 | this, SLOT( changeStartConfig(bool) ) ); |
383 | nStart->setToggleAction(true); | 290 | nStart->setToggleAction(true); |
384 | nStart->addTo( advancedMenu ); | 291 | nStart->addTo( advancedMenu ); |
385 | nStart->setEnabled(false); | 292 | nStart->setEnabled(false); |
386 | 293 | ||
387 | nAdvanced = new QAction( tr("Prompt on Exit"), | 294 | nAdvanced = new QAction( tr("Prompt on Exit"), |
388 | QString::null, 0, this, 0 ); | 295 | QString::null, 0, this, 0 ); |
389 | connect( nAdvanced, SIGNAL( toggled(bool) ), | 296 | connect( nAdvanced, SIGNAL( toggled(bool) ), |
390 | this, SLOT( doPrompt(bool) ) ); | 297 | this, SLOT( doPrompt(bool) ) ); |
391 | nAdvanced->setToggleAction(true); | 298 | nAdvanced->setToggleAction(true); |
392 | nAdvanced->addTo( advancedMenu ); | 299 | nAdvanced->addTo( advancedMenu ); |
393 | 300 | ||
394 | desktopAction = new QAction( tr("Always open linked file"), | 301 | desktopAction = new QAction( tr("Always open linked file"), |
395 | QString::null, 0, this, 0 ); | 302 | QString::null, 0, this, 0 ); |
396 | connect( desktopAction, SIGNAL( toggled(bool) ), | 303 | connect( desktopAction, SIGNAL( toggled(bool) ), |
397 | this, SLOT( doDesktop(bool) ) ); | 304 | this, SLOT( doDesktop(bool) ) ); |
398 | desktopAction->setToggleAction(true); | 305 | desktopAction->setToggleAction(true); |
399 | desktopAction->addTo( advancedMenu); | 306 | desktopAction->addTo( advancedMenu); |
400 | 307 | ||
401 | filePermAction = new QAction( tr("File Permissions"), | 308 | filePermAction = new QAction( tr("File Permissions"), |
402 | QString::null, 0, this, 0 ); | 309 | QString::null, 0, this, 0 ); |
403 | connect( filePermAction, SIGNAL( toggled(bool) ), | 310 | connect( filePermAction, SIGNAL( toggled(bool) ), |
404 | this, SLOT( doFilePerms(bool) ) ); | 311 | this, SLOT( doFilePerms(bool) ) ); |
405 | filePermAction->setToggleAction(true); | 312 | filePermAction->setToggleAction(true); |
406 | filePermAction->addTo( advancedMenu); | 313 | filePermAction->addTo( advancedMenu); |
407 | 314 | ||
408 | searchBarAction = new QAction( tr("Search Bar Open"), | 315 | searchBarAction = new QAction( tr("Search Bar Open"), |
409 | QString::null, 0, this, 0 ); | 316 | QString::null, 0, this, 0 ); |
410 | connect( searchBarAction, SIGNAL( toggled(bool) ), | 317 | connect( searchBarAction, SIGNAL( toggled(bool) ), |
411 | this, SLOT( setSearchBar(bool) ) ); | 318 | this, SLOT( setSearchBar(bool) ) ); |
412 | searchBarAction->setToggleAction(true); | 319 | searchBarAction->setToggleAction(true); |
413 | searchBarAction->addTo( advancedMenu); | 320 | searchBarAction->addTo( advancedMenu); |
414 | 321 | ||
415 | nAutoSave = new QAction( tr("Auto Save 5 min."), | 322 | nAutoSave = new QAction( tr("Auto Save 5 min."), |
416 | QString::null, 0, this, 0 ); | 323 | QString::null, 0, this, 0 ); |
417 | connect( nAutoSave, SIGNAL( toggled(bool) ), | 324 | connect( nAutoSave, SIGNAL( toggled(bool) ), |
418 | this, SLOT( doTimer(bool) ) ); | 325 | this, SLOT( doTimer(bool) ) ); |
419 | nAutoSave->setToggleAction(true); | 326 | nAutoSave->setToggleAction(true); |
420 | nAutoSave->addTo( advancedMenu); | 327 | nAutoSave->addTo( advancedMenu); |
421 | 328 | ||
422 | 329 | ||
423 | font->insertSeparator(); | 330 | font->insertSeparator(); |
424 | 331 | ||
425 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 332 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
426 | 333 | ||
427 | mb->insertItem( tr( "File" ), file ); | 334 | mb->insertItem( tr( "File" ), file ); |
428 | mb->insertItem( tr( "Edit" ), edit ); | 335 | mb->insertItem( tr( "Edit" ), edit ); |
429 | mb->insertItem( tr( "View" ), font ); | 336 | mb->insertItem( tr( "View" ), font ); |
430 | 337 | ||
431 | searchBar = new QPEToolBar(this); | 338 | searchBar = new QPEToolBar(this); |
432 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 339 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
433 | 340 | ||
434 | searchBar->setHorizontalStretchable( true ); | 341 | searchBar->setHorizontalStretchable( true ); |
435 | 342 | ||
436 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 343 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
437 | searchBar->setStretchableWidget( searchEdit ); | 344 | searchBar->setStretchableWidget( searchEdit ); |
438 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 345 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
439 | this, SLOT( search() ) ); | 346 | this, SLOT( search() ) ); |
440 | 347 | ||
441 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), | 348 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), |
442 | QString::null, 0, this, 0 ); | 349 | QString::null, 0, this, 0 ); |
443 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 350 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
444 | a->addTo( searchBar ); | 351 | a->addTo( searchBar ); |
445 | a->addTo( edit ); | 352 | a->addTo( edit ); |
446 | 353 | ||
447 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), | 354 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), |
448 | QString::null, 0, this, 0 ); | 355 | QString::null, 0, this, 0 ); |
449 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 356 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
450 | a->addTo( searchBar ); | 357 | a->addTo( searchBar ); |
451 | 358 | ||
@@ -1167,96 +1074,121 @@ void TextEdit::doDesktop(bool b) { | |||
1167 | openDesktop=b; | 1074 | openDesktop=b; |
1168 | Config cfg("TextEdit"); | 1075 | Config cfg("TextEdit"); |
1169 | cfg.setGroup ( "View" ); | 1076 | cfg.setGroup ( "View" ); |
1170 | cfg.writeEntry ( "OpenDesktop", b); | 1077 | cfg.writeEntry ( "OpenDesktop", b); |
1171 | } | 1078 | } |
1172 | 1079 | ||
1173 | void TextEdit::doFilePerms(bool b) { | 1080 | void TextEdit::doFilePerms(bool b) { |
1174 | filePerms=b; | 1081 | filePerms=b; |
1175 | Config cfg("TextEdit"); | 1082 | Config cfg("TextEdit"); |
1176 | cfg.setGroup ( "View" ); | 1083 | cfg.setGroup ( "View" ); |
1177 | cfg.writeEntry ( "FilePermissions", b); | 1084 | cfg.writeEntry ( "FilePermissions", b); |
1178 | } | 1085 | } |
1179 | 1086 | ||
1180 | void TextEdit::editPasteTimeDate() { | 1087 | void TextEdit::editPasteTimeDate() { |
1181 | #ifndef QT_NO_CLIPBOARD | 1088 | #ifndef QT_NO_CLIPBOARD |
1182 | QClipboard *cb = QApplication::clipboard(); | 1089 | QClipboard *cb = QApplication::clipboard(); |
1183 | QDateTime dt = QDateTime::currentDateTime(); | 1090 | QDateTime dt = QDateTime::currentDateTime(); |
1184 | cb->setText( dt.toString()); | 1091 | cb->setText( dt.toString()); |
1185 | editor->paste(); | 1092 | editor->paste(); |
1186 | #endif | 1093 | #endif |
1187 | } | 1094 | } |
1188 | 1095 | ||
1189 | int TextEdit::savePrompt() | 1096 | int TextEdit::savePrompt() |
1190 | { | 1097 | { |
1191 | switch( QMessageBox::information( 0, (tr("Textedit")), | 1098 | switch( QMessageBox::information( 0, (tr("Textedit")), |
1192 | (tr("Textedit detected\n" | 1099 | (tr("Textedit detected\n" |
1193 | "you have unsaved changes\n" | 1100 | "you have unsaved changes\n" |
1194 | "Go ahead and save?\n")), | 1101 | "Go ahead and save?\n")), |
1195 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | 1102 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) |
1196 | { | 1103 | { |
1197 | case 0: | 1104 | case 0: |
1198 | { | 1105 | { |
1199 | return 1; | 1106 | return 1; |
1200 | } | 1107 | } |
1201 | break; | 1108 | break; |
1202 | 1109 | ||
1203 | case 1: | 1110 | case 1: |
1204 | { | 1111 | { |
1205 | return 2; | 1112 | return 2; |
1206 | } | 1113 | } |
1207 | break; | 1114 | break; |
1208 | 1115 | ||
1209 | case 2: | 1116 | case 2: |
1210 | { | 1117 | { |
1211 | return -1; | 1118 | return -1; |
1212 | } | 1119 | } |
1213 | break; | 1120 | break; |
1214 | }; | 1121 | }; |
1215 | 1122 | ||
1216 | return 0; | 1123 | return 0; |
1217 | } | 1124 | } |
1218 | 1125 | ||
1219 | void TextEdit::timerCrank() | 1126 | void TextEdit::timerCrank() |
1220 | { | 1127 | { |
1221 | if(featureAutoSave && edited1) | 1128 | if(featureAutoSave && edited1) |
1222 | { | 1129 | { |
1223 | if(currentFileName.isEmpty()) | 1130 | if(currentFileName.isEmpty()) |
1224 | { | 1131 | { |
1225 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; | 1132 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; |
1226 | saveAs(); | 1133 | saveAs(); |
1227 | } | 1134 | } |
1228 | else | 1135 | else |
1229 | { | 1136 | { |
1230 | // qDebug("autosave"); | 1137 | // qDebug("autosave"); |
1231 | save(); | 1138 | save(); |
1232 | } | 1139 | } |
1233 | setTimer(); | 1140 | setTimer(); |
1234 | } | 1141 | } |
1235 | } | 1142 | } |
1236 | 1143 | ||
1237 | void TextEdit::doTimer(bool b) | 1144 | void TextEdit::doTimer(bool b) |
1238 | { | 1145 | { |
1239 | Config cfg("TextEdit"); | 1146 | Config cfg("TextEdit"); |
1240 | cfg.setGroup ( "View" ); | 1147 | cfg.setGroup ( "View" ); |
1241 | cfg.writeEntry ( "autosave", b); | 1148 | cfg.writeEntry ( "autosave", b); |
1242 | featureAutoSave = b; | 1149 | featureAutoSave = b; |
1243 | nAutoSave->setOn(b); | 1150 | nAutoSave->setOn(b); |
1244 | if(b) | 1151 | if(b) |
1245 | { | 1152 | { |
1246 | // qDebug("doTimer true"); | 1153 | // qDebug("doTimer true"); |
1247 | setTimer(); | 1154 | setTimer(); |
1248 | } | 1155 | } |
1249 | // else | 1156 | // else |
1250 | // qDebug("doTimer false"); | 1157 | // qDebug("doTimer false"); |
1251 | } | 1158 | } |
1252 | 1159 | ||
1253 | void TextEdit::setTimer() | 1160 | void TextEdit::setTimer() |
1254 | { | 1161 | { |
1255 | if(featureAutoSave) | 1162 | if(featureAutoSave) |
1256 | { | 1163 | { |
1257 | // qDebug("setting autosave"); | 1164 | // qDebug("setting autosave"); |
1258 | QTimer *timer = new QTimer(this ); | 1165 | QTimer *timer = new QTimer(this ); |
1259 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); | 1166 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); |
1260 | timer->start( 300000, true); //5 minutes | 1167 | timer->start( 300000, true); //5 minutes |
1261 | } | 1168 | } |
1262 | } | 1169 | } |
1170 | |||
1171 | void TextEdit::gotoLine() { | ||
1172 | |||
1173 | QWidget *d = QApplication::desktop(); | ||
1174 | gotoEdit = new QLineEdit( 0, "Goto line"); | ||
1175 | |||
1176 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); | ||
1177 | gotoEdit->setFrame(true); | ||
1178 | gotoEdit->show(); | ||
1179 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); | ||
1180 | } | ||
1181 | |||
1182 | void TextEdit::doGoto() { | ||
1183 | QString number = gotoEdit->text(); | ||
1184 | gotoEdit->hide(); | ||
1185 | if(gotoEdit) delete gotoEdit; | ||
1186 | bool ok; | ||
1187 | int lineNumber = number.toInt(&ok, 10); | ||
1188 | if(editor->numLines() < lineNumber) | ||
1189 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); | ||
1190 | else | ||
1191 | { | ||
1192 | editor->setCursorPosition(lineNumber, 0, false); | ||
1193 | } | ||
1194 | } | ||