-rw-r--r-- | core/apps/textedit/textedit.cpp | 163 |
1 files changed, 102 insertions, 61 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 4f4f994..dc0d61b 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -1,61 +1,49 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | // textedit.cpp | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 4 | ** |
4 | ** This file is part of Qtopia Environment. | 5 | ** This file is part of Opie Environment. |
5 | ** | 6 | ** |
6 | ** 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 |
7 | ** 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 |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 10 | ** packaging of this file. |
10 | ** | 11 | ** |
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | 12 | **********************************************************************/ |
20 | // 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 |
21 | /* | ||
22 | useAdvancedfeatures = | ||
23 | 1) do not prompt on cancel, even if text is edited. | ||
24 | 2) prompt user is .desktop file | ||
25 | 3) prompt user for File Permissions on saveAs | ||
26 | */ | ||
27 | #include "textedit.h" | 14 | #include "textedit.h" |
28 | #include "filePermissions.h" | 15 | #include "filePermissions.h" |
29 | //#include "fontDialog.h" | 16 | |
30 | 17 | ||
31 | #include <opie/ofileselector.h> | 18 | #include <opie/ofileselector.h> |
32 | #include <opie/ofiledialog.h> | 19 | #include <opie/ofiledialog.h> |
33 | #include <opie/ofontselector.h> | 20 | #include <opie/ofontselector.h> |
34 | 21 | ||
35 | #include <qpe/fontdatabase.h> | 22 | #include <qpe/fontdatabase.h> |
36 | #include <qpe/global.h> | 23 | #include <qpe/global.h> |
37 | #include <qpe/fileselector.h> | 24 | #include <qpe/fileselector.h> |
38 | #include <qpe/applnk.h> | 25 | #include <qpe/applnk.h> |
39 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
40 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
41 | #include <qpe/qpeapplication.h> | 28 | #include <qpe/qpeapplication.h> |
42 | #include <qpe/qpemenubar.h> | 29 | #include <qpe/qpemenubar.h> |
43 | #include <qpe/qpetoolbar.h> | 30 | #include <qpe/qpetoolbar.h> |
44 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
45 | 32 | ||
33 | #include <qpoint.h> | ||
46 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
47 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
48 | #include <qclipboard.h> | 36 | #include <qclipboard.h> |
49 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
50 | #include <qaction.h> | 38 | #include <qaction.h> |
51 | #include <qcolordialog.h> | 39 | #include <qcolordialog.h> |
52 | #include <qfileinfo.h> | 40 | #include <qfileinfo.h> |
53 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
54 | #include <qmessagebox.h> | 42 | #include <qmessagebox.h> |
55 | #include <qobjectlist.h> | 43 | #include <qobjectlist.h> |
56 | #include <qpopupmenu.h> | 44 | #include <qpopupmenu.h> |
57 | #include <qspinbox.h> | 45 | #include <qspinbox.h> |
58 | #include <qtoolbutton.h> | 46 | #include <qtoolbutton.h> |
59 | #include <qwidgetstack.h> | 47 | #include <qwidgetstack.h> |
60 | #include <qcheckbox.h> | 48 | #include <qcheckbox.h> |
61 | #include <qcombo.h> | 49 | #include <qcombo.h> |
@@ -156,53 +144,91 @@ static char * filesave_xpm[] = { | |||
156 | " #34-55;;;;678$+", | 144 | " #34-55;;;;678$+", |
157 | " 90ab=c;dd;e1fg ", | 145 | " 90ab=c;dd;e1fg ", |
158 | " [ahij((kbl0mn$ ", | 146 | " [ahij((kbl0mn$ ", |
159 | " op^q^^7r&]s/$+ ", | 147 | " op^q^^7r&]s/$+ ", |
160 | "@btu;vbwxy]zAB ", | 148 | "@btu;vbwxy]zAB ", |
161 | "CzDEvEv;;DssF$ ", | 149 | "CzDEvEv;;DssF$ ", |
162 | "G.H{E{E{IxsJ$+ ", | 150 | "G.H{E{E{IxsJ$+ ", |
163 | " +...vEKxzLM ", | 151 | " +...vEKxzLM ", |
164 | " +...z]n$ ", | 152 | " +...z]n$ ", |
165 | " +... "}; | 153 | " +... "}; |
166 | 154 | ||
167 | 155 | ||
168 | #if QT_VERSION < 300 | 156 | #if QT_VERSION < 300 |
169 | 157 | ||
170 | class QpeEditor : public QMultiLineEdit | 158 | class QpeEditor : public QMultiLineEdit |
171 | { | 159 | { |
172 | // Q_OBJECT | 160 | |
173 | public: | 161 | public: |
174 | QpeEditor( QWidget *parent, const char * name = 0 ) | 162 | QpeEditor( QWidget *parent, const char * name = 0 ) |
175 | : QMultiLineEdit( parent, name ) { | 163 | : QMultiLineEdit( parent, name ) { |
176 | clearTableFlags(); | 164 | clearTableFlags(); |
177 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 165 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
178 | } | 166 | } |
179 | 167 | ||
180 | void find( const QString &txt, bool caseSensitive, | 168 | void find( const QString &txt, bool caseSensitive, |
181 | bool backwards ); | 169 | bool backwards ); |
170 | protected: | ||
171 | bool markIt; | ||
172 | int line1, line2, col1, col2; | ||
173 | void mousePressEvent( QMouseEvent * ); | ||
174 | void mouseReleaseEvent( QMouseEvent * ); | ||
175 | |||
182 | //public slots: | 176 | //public slots: |
183 | /* | 177 | /* |
184 | signals: | 178 | signals: |
185 | void notFound(); | 179 | void notFound(); |
186 | void searchWrapped(); | 180 | void searchWrapped(); |
187 | */ | 181 | */ |
188 | 182 | ||
189 | private: | 183 | private: |
190 | 184 | ||
191 | }; | 185 | }; |
192 | 186 | ||
187 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { | ||
188 | switch(e->button()) { | ||
189 | case RightButton: | ||
190 | { //rediculous workaround for qt popup menu | ||
191 | //and the hold right click mechanism | ||
192 | this->setSelection( line1, col1, line2, col2); | ||
193 | QMultiLineEdit::mousePressEvent( e ); | ||
194 | markIt = false; | ||
195 | } | ||
196 | break; | ||
197 | default: | ||
198 | { | ||
199 | if(!markIt) { | ||
200 | int line, col; | ||
201 | this->getCursorPosition(&line, &col); | ||
202 | line1=line2=line; | ||
203 | col1=col2=col; | ||
204 | } | ||
205 | QMultiLineEdit::mousePressEvent( e ); | ||
206 | } | ||
207 | break; | ||
208 | }; | ||
209 | } | ||
210 | |||
211 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { | ||
212 | if(this->hasMarkedText()) { | ||
213 | markIt = true; | ||
214 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); | ||
215 | } else { | ||
216 | markIt = false; | ||
217 | } | ||
218 | } | ||
193 | 219 | ||
194 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 220 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
195 | bool backwards ) | 221 | bool backwards ) |
196 | { | 222 | { |
197 | static bool wrap = false; | 223 | static bool wrap = false; |
198 | int line, col; | 224 | int line, col; |
199 | if ( wrap ) { | 225 | if ( wrap ) { |
200 | if ( !backwards ) | 226 | if ( !backwards ) |
201 | line = col = 0; | 227 | line = col = 0; |
202 | wrap = false; | 228 | wrap = false; |
203 | // emit searchWrapped(); | 229 | // emit searchWrapped(); |
204 | } else { | 230 | } else { |
205 | getCursorPosition( &line, &col ); | 231 | getCursorPosition( &line, &col ); |
206 | } | 232 | } |
207 | //ignore backwards for now.... | 233 | //ignore backwards for now.... |
208 | if ( !backwards ) { | 234 | if ( !backwards ) { |
@@ -255,166 +281,192 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
255 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 281 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
256 | 282 | ||
257 | QPEToolBar *bar = new QPEToolBar( this ); | 283 | QPEToolBar *bar = new QPEToolBar( this ); |
258 | bar->setHorizontalStretchable( true ); | 284 | bar->setHorizontalStretchable( true ); |
259 | menu = bar; | 285 | menu = bar; |
260 | 286 | ||
261 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 287 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
262 | QPopupMenu *file = new QPopupMenu( this ); | 288 | QPopupMenu *file = new QPopupMenu( this ); |
263 | QPopupMenu *edit = new QPopupMenu( this ); | 289 | QPopupMenu *edit = new QPopupMenu( this ); |
264 | QPopupMenu *advancedMenu = new QPopupMenu(this); | 290 | QPopupMenu *advancedMenu = new QPopupMenu(this); |
265 | 291 | ||
266 | font = new QPopupMenu( this ); | 292 | font = new QPopupMenu( this ); |
267 | 293 | ||
268 | bar = new QPEToolBar( this ); | 294 | bar = new QPEToolBar( this ); |
269 | editBar = bar; | 295 | editBar = bar; |
270 | 296 | ||
271 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 297 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
298 | QString::null, 0, this, 0 ); | ||
272 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 299 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
273 | // a->addTo( bar ); | 300 | // a->addTo( bar ); |
274 | a->addTo( file ); | 301 | a->addTo( file ); |
275 | 302 | ||
276 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 303 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), |
304 | QString::null, 0, this, 0 ); | ||
277 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 305 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
278 | a->addTo( bar ); | 306 | a->addTo( bar ); |
279 | a->addTo( file ); | 307 | a->addTo( file ); |
280 | 308 | ||
281 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 309 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , |
310 | QString::null, 0, this, 0 ); | ||
282 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 311 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
283 | file->insertSeparator(); | 312 | file->insertSeparator(); |
284 | a->addTo( bar ); | 313 | a->addTo( bar ); |
285 | a->addTo( file ); | 314 | a->addTo( file ); |
286 | 315 | ||
287 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 316 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , |
317 | QString::null, 0, this, 0 ); | ||
288 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 318 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
289 | a->addTo( file ); | 319 | a->addTo( file ); |
290 | 320 | ||
291 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 321 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), |
322 | QString::null, 0, this, 0 ); | ||
292 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 323 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
293 | a->addTo( editBar ); | 324 | a->addTo( editBar ); |
294 | a->addTo( edit ); | 325 | a->addTo( edit ); |
295 | 326 | ||
296 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 327 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), |
328 | QString::null, 0, this, 0 ); | ||
297 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 329 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
298 | a->addTo( editBar ); | 330 | a->addTo( editBar ); |
299 | a->addTo( edit ); | 331 | a->addTo( edit ); |
300 | 332 | ||
301 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 333 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), |
334 | QString::null, 0, this, 0 ); | ||
302 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 335 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
303 | a->addTo( editBar ); | 336 | a->addTo( editBar ); |
304 | a->addTo( edit ); | 337 | a->addTo( edit ); |
305 | 338 | ||
306 | 339 | ||
307 | #ifndef QT_NO_CLIPBOARD | 340 | #ifndef QT_NO_CLIPBOARD |
308 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 341 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), |
342 | QString::null, 0, this, 0 ); | ||
309 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); | 343 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); |
310 | a->addTo( edit ); | 344 | a->addTo( edit ); |
311 | #endif | 345 | #endif |
312 | 346 | ||
313 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 347 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), |
348 | QString::null, 0, this, 0 ); | ||
314 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 349 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
315 | edit->insertSeparator(); | 350 | edit->insertSeparator(); |
316 | a->addTo( bar ); | 351 | a->addTo( bar ); |
317 | a->addTo( edit ); | 352 | a->addTo( edit ); |
318 | 353 | ||
319 | 354 | ||
320 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 355 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
321 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 356 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
322 | zin->addTo( font ); | 357 | zin->addTo( font ); |
323 | 358 | ||
324 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 359 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
325 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 360 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
326 | zout->addTo( font ); | 361 | zout->addTo( font ); |
327 | 362 | ||
328 | font->insertSeparator(); | 363 | font->insertSeparator(); |
329 | // font->insertSeparator(); | 364 | |
330 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); | 365 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
331 | 366 | ||
332 | font->insertSeparator(); | 367 | font->insertSeparator(); |
333 | font->insertItem(tr("Advanced Features"), advancedMenu); | 368 | font->insertItem(tr("Advanced Features"), advancedMenu); |
334 | 369 | ||
335 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 370 | QAction *wa = new QAction( tr("Wrap lines"), |
336 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 371 | QString::null, 0, this, 0 ); |
372 | connect( wa, SIGNAL( toggled(bool) ), | ||
373 | this, SLOT( setWordWrap(bool) ) ); | ||
337 | wa->setToggleAction(true); | 374 | wa->setToggleAction(true); |
338 | wa->addTo( advancedMenu); | 375 | wa->addTo( advancedMenu); |
339 | 376 | ||
340 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); | 377 | nStart = new QAction( tr("Start with new file"), |
341 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); | 378 | QString::null, 0, this, 0 ); |
379 | connect( nStart, SIGNAL( toggled(bool) ), | ||
380 | this, SLOT( changeStartConfig(bool) ) ); | ||
342 | nStart->setToggleAction(true); | 381 | nStart->setToggleAction(true); |
343 | nStart->addTo( advancedMenu ); | 382 | nStart->addTo( advancedMenu ); |
344 | nStart->setEnabled(false); | 383 | nStart->setEnabled(false); |
345 | 384 | ||
346 | nAdvanced = new QAction( tr("Prompt on Exit"), QString::null, 0, this, 0 ); | 385 | nAdvanced = new QAction( tr("Prompt on Exit"), |
347 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doPrompt(bool) ) ); | 386 | QString::null, 0, this, 0 ); |
387 | connect( nAdvanced, SIGNAL( toggled(bool) ), | ||
388 | this, SLOT( doPrompt(bool) ) ); | ||
348 | nAdvanced->setToggleAction(true); | 389 | nAdvanced->setToggleAction(true); |
349 | nAdvanced->addTo( advancedMenu ); | 390 | nAdvanced->addTo( advancedMenu ); |
350 | 391 | ||
351 | desktopAction = new QAction( tr("Always open linked file"), QString::null, 0, this, 0 ); | 392 | desktopAction = new QAction( tr("Always open linked file"), |
352 | connect( desktopAction, SIGNAL( toggled(bool) ), this, SLOT( doDesktop(bool) ) ); | 393 | QString::null, 0, this, 0 ); |
394 | connect( desktopAction, SIGNAL( toggled(bool) ), | ||
395 | this, SLOT( doDesktop(bool) ) ); | ||
353 | desktopAction->setToggleAction(true); | 396 | desktopAction->setToggleAction(true); |
354 | desktopAction->addTo( advancedMenu); | 397 | desktopAction->addTo( advancedMenu); |
355 | 398 | ||
356 | filePermAction = new QAction( tr("File Permissions"), QString::null, 0, this, 0 ); | 399 | filePermAction = new QAction( tr("File Permissions"), |
357 | connect( filePermAction, SIGNAL( toggled(bool) ), this, SLOT( doFilePerms(bool) ) ); | 400 | QString::null, 0, this, 0 ); |
401 | connect( filePermAction, SIGNAL( toggled(bool) ), | ||
402 | this, SLOT( doFilePerms(bool) ) ); | ||
358 | filePermAction->setToggleAction(true); | 403 | filePermAction->setToggleAction(true); |
359 | filePermAction->addTo( advancedMenu); | 404 | filePermAction->addTo( advancedMenu); |
360 | 405 | ||
361 | searchBarAction = new QAction( tr("Search Bar Open"), QString::null, 0, this, 0 ); | 406 | searchBarAction = new QAction( tr("Search Bar Open"), |
362 | connect( searchBarAction, SIGNAL( toggled(bool) ), this, SLOT( setSearchBar(bool) ) ); | 407 | QString::null, 0, this, 0 ); |
408 | connect( searchBarAction, SIGNAL( toggled(bool) ), | ||
409 | this, SLOT( setSearchBar(bool) ) ); | ||
363 | searchBarAction->setToggleAction(true); | 410 | searchBarAction->setToggleAction(true); |
364 | searchBarAction->addTo( advancedMenu); | 411 | searchBarAction->addTo( advancedMenu); |
365 | 412 | ||
366 | 413 | ||
367 | font->insertSeparator(); | 414 | font->insertSeparator(); |
368 | 415 | ||
369 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 416 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
370 | 417 | ||
371 | mb->insertItem( tr( "File" ), file ); | 418 | mb->insertItem( tr( "File" ), file ); |
372 | mb->insertItem( tr( "Edit" ), edit ); | 419 | mb->insertItem( tr( "Edit" ), edit ); |
373 | mb->insertItem( tr( "View" ), font ); | 420 | mb->insertItem( tr( "View" ), font ); |
374 | 421 | ||
375 | searchBar = new QPEToolBar(this); | 422 | searchBar = new QPEToolBar(this); |
376 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 423 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
377 | 424 | ||
378 | searchBar->setHorizontalStretchable( true ); | 425 | searchBar->setHorizontalStretchable( true ); |
379 | 426 | ||
380 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 427 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
381 | searchBar->setStretchableWidget( searchEdit ); | 428 | searchBar->setStretchableWidget( searchEdit ); |
382 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 429 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
383 | this, SLOT( search() ) ); | 430 | this, SLOT( search() ) ); |
384 | 431 | ||
385 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 432 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), |
433 | QString::null, 0, this, 0 ); | ||
386 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 434 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
387 | a->addTo( searchBar ); | 435 | a->addTo( searchBar ); |
388 | a->addTo( edit ); | 436 | a->addTo( edit ); |
389 | 437 | ||
390 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 438 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), |
439 | QString::null, 0, this, 0 ); | ||
391 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 440 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
392 | a->addTo( searchBar ); | 441 | a->addTo( searchBar ); |
393 | 442 | ||
394 | edit->insertSeparator(); | 443 | edit->insertSeparator(); |
395 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 444 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), |
445 | QString::null, 0, this, 0 ); | ||
396 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 446 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
397 | a->addTo( edit ); | 447 | a->addTo( edit ); |
398 | 448 | ||
399 | searchBar->hide(); | 449 | searchBar->hide(); |
400 | 450 | ||
401 | editor = new QpeEditor( this ); | 451 | editor = new QpeEditor( this ); |
402 | setCentralWidget( editor ); | 452 | setCentralWidget( editor ); |
403 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 453 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
404 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); | 454 | connect( editor, SIGNAL( textChanged() ), |
455 | this, SLOT( editorChanged() ) ); | ||
456 | |||
405 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); | 457 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); |
406 | 458 | ||
407 | Config cfg("TextEdit"); | 459 | Config cfg("TextEdit"); |
408 | cfg. setGroup ( "Font" ); | 460 | cfg. setGroup ( "Font" ); |
409 | 461 | ||
410 | QFont defaultFont = editor-> font ( ); | 462 | QFont defaultFont = editor-> font ( ); |
411 | 463 | ||
412 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); | 464 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); |
413 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); | 465 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); |
414 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); | 466 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); |
415 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); | 467 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); |
416 | 468 | ||
417 | defaultFont = QFont ( family, size, weight, italic ); | 469 | defaultFont = QFont ( family, size, weight, italic ); |
418 | editor-> setFont ( defaultFont ); | 470 | editor-> setFont ( defaultFont ); |
419 | 471 | ||
420 | // updateCaption(); | 472 | // updateCaption(); |
@@ -436,83 +488,73 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
436 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 488 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
437 | wa-> setOn ( wrap ); | 489 | wa-> setOn ( wrap ); |
438 | setWordWrap ( wrap ); | 490 | setWordWrap ( wrap ); |
439 | 491 | ||
440 | if( qApp->argc() > 1) { | 492 | if( qApp->argc() > 1) { |
441 | currentFileName=qApp->argv()[1]; | 493 | currentFileName=qApp->argv()[1]; |
442 | 494 | ||
443 | QFileInfo fi(currentFileName); | 495 | QFileInfo fi(currentFileName); |
444 | 496 | ||
445 | if(fi.baseName().left(1) == "") { | 497 | if(fi.baseName().left(1) == "") { |
446 | openDotFile(currentFileName); | 498 | openDotFile(currentFileName); |
447 | } else { | 499 | } else { |
448 | openFile(currentFileName); | 500 | openFile(currentFileName); |
449 | } | 501 | } |
450 | } else { | 502 | } else { |
451 | edited1=false; | 503 | edited1=false; |
452 | |||
453 | // if(startWithNew ) { | ||
454 | openDotFile(""); | 504 | openDotFile(""); |
455 | // fileNew(); | ||
456 | // } | ||
457 | // else { | ||
458 | // fileOpen(); | ||
459 | // } | ||
460 | } | 505 | } |
461 | 506 | ||
462 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 507 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
463 | // setCaption(tr("Text Editor")); | ||
464 | } | 508 | } |
465 | 509 | ||
466 | TextEdit::~TextEdit() { | 510 | TextEdit::~TextEdit() { |
467 | // qDebug("destr"); | 511 | qWarning("textedit d'tor"); |
512 | delete editor; | ||
468 | } | 513 | } |
469 | 514 | ||
470 | void TextEdit::closeEvent(QCloseEvent *) { | 515 | void TextEdit::closeEvent(QCloseEvent *) { |
471 | // qDebug("closing here"); | ||
472 | if( edited1 && promptExit) | 516 | if( edited1 && promptExit) |
473 | saveAs(); | 517 | saveAs(); |
474 | qApp->quit(); | 518 | qApp->quit(); |
475 | } | 519 | } |
476 | 520 | ||
477 | void TextEdit::cleanUp() { | 521 | void TextEdit::cleanUp() { |
478 | // qDebug("cleanUp");// save(); | ||
479 | 522 | ||
480 | Config cfg ( "TextEdit" ); | 523 | Config cfg ( "TextEdit" ); |
481 | cfg. setGroup ( "Font" ); | 524 | cfg. setGroup ( "Font" ); |
482 | QFont f = editor->font(); | 525 | QFont f = editor->font(); |
483 | cfg.writeEntry ( "Family", f. family ( )); | 526 | cfg.writeEntry ( "Family", f. family ( )); |
484 | cfg.writeEntry ( "Size", f. pointSize ( )); | 527 | cfg.writeEntry ( "Size", f. pointSize ( )); |
485 | cfg.writeEntry ( "Weight", f. weight ( )); | 528 | cfg.writeEntry ( "Weight", f. weight ( )); |
486 | cfg.writeEntry ( "Italic", f. italic ( )); | 529 | cfg.writeEntry ( "Italic", f. italic ( )); |
487 | 530 | ||
488 | cfg.setGroup ( "View" ); | 531 | cfg.setGroup ( "View" ); |
489 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 532 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
490 | cfg.writeEntry ( "FileView", viewSelection ); | 533 | cfg.writeEntry ( "FileView", viewSelection ); |
491 | 534 | ||
492 | cfg.writeEntry ( "PromptExit", promptExit ); | 535 | cfg.writeEntry ( "PromptExit", promptExit ); |
493 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 536 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
494 | cfg.writeEntry ( "FilePermissions", filePerms ); | 537 | cfg.writeEntry ( "FilePermissions", filePerms ); |
495 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 538 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
496 | cfg.writeEntry ( "startNew", startWithNew ); | 539 | cfg.writeEntry ( "startNew", startWithNew ); |
497 | 540 | ||
498 | } | 541 | } |
499 | 542 | ||
500 | 543 | ||
501 | void TextEdit::accept() { | 544 | void TextEdit::accept() { |
502 | // qDebug("accept"); | ||
503 | if( edited1) | 545 | if( edited1) |
504 | saveAs(); | 546 | saveAs(); |
505 | qApp->quit(); | 547 | qApp->quit(); |
506 | } | 548 | } |
507 | 549 | ||
508 | void TextEdit::zoomIn() { | 550 | void TextEdit::zoomIn() { |
509 | setFontSize(editor->font().pointSize()+1,false); | 551 | setFontSize(editor->font().pointSize()+1,false); |
510 | } | 552 | } |
511 | 553 | ||
512 | void TextEdit::zoomOut() { | 554 | void TextEdit::zoomOut() { |
513 | setFontSize(editor->font().pointSize()-1,true); | 555 | setFontSize(editor->font().pointSize()-1,true); |
514 | } | 556 | } |
515 | 557 | ||
516 | 558 | ||
517 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 559 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
518 | int s=10; | 560 | int s=10; |
@@ -777,33 +819,33 @@ void TextEdit::openFile( const DocLnk &f ) { | |||
777 | void TextEdit::showEditTools() { | 819 | void TextEdit::showEditTools() { |
778 | menu->show(); | 820 | menu->show(); |
779 | editBar->show(); | 821 | editBar->show(); |
780 | if(!useSearchBar) | 822 | if(!useSearchBar) |
781 | searchBar->hide(); | 823 | searchBar->hide(); |
782 | else | 824 | else |
783 | searchBar->show(); | 825 | searchBar->show(); |
784 | setWState (WState_Reserved1 ); | 826 | setWState (WState_Reserved1 ); |
785 | } | 827 | } |
786 | 828 | ||
787 | /*! | 829 | /*! |
788 | unprompted save */ | 830 | unprompted save */ |
789 | bool TextEdit::save() { | 831 | bool TextEdit::save() { |
790 | qDebug("saveAsFile " + currentFileName); | 832 | qDebug("saveAsFile " + currentFileName); |
791 | if(currentFileName.isEmpty()) { | 833 | if(currentFileName.isEmpty()) { |
792 | saveAs(); | 834 | saveAs(); |
793 | return; | 835 | return false; |
794 | } | 836 | } |
795 | QString file = doc->file(); | 837 | QString file = doc->file(); |
796 | qDebug("saver file "+file); | 838 | qDebug("saver file "+file); |
797 | QString name= doc->name(); | 839 | QString name= doc->name(); |
798 | qDebug("File named "+name); | 840 | qDebug("File named "+name); |
799 | QString rt = editor->text(); | 841 | QString rt = editor->text(); |
800 | if( !rt.isEmpty() ) { | 842 | if( !rt.isEmpty() ) { |
801 | if(name.isEmpty()) { | 843 | if(name.isEmpty()) { |
802 | saveAs(); | 844 | saveAs(); |
803 | } else { | 845 | } else { |
804 | currentFileName= name ; | 846 | currentFileName= name ; |
805 | qDebug("saveFile "+currentFileName); | 847 | qDebug("saveFile "+currentFileName); |
806 | 848 | ||
807 | struct stat buf; | 849 | struct stat buf; |
808 | mode_t mode; | 850 | mode_t mode; |
809 | stat(file.latin1(), &buf); | 851 | stat(file.latin1(), &buf); |
@@ -1040,33 +1082,33 @@ void TextEdit::changeStartConfig( bool b ) { | |||
1040 | startWithNew=b; | 1082 | startWithNew=b; |
1041 | Config cfg("TextEdit"); | 1083 | Config cfg("TextEdit"); |
1042 | cfg.setGroup("View"); | 1084 | cfg.setGroup("View"); |
1043 | cfg.writeEntry("startNew",b); | 1085 | cfg.writeEntry("startNew",b); |
1044 | update(); | 1086 | update(); |
1045 | } | 1087 | } |
1046 | 1088 | ||
1047 | void TextEdit::editorChanged() { | 1089 | void TextEdit::editorChanged() { |
1048 | // qDebug("editor changed"); | 1090 | // qDebug("editor changed"); |
1049 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1091 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1050 | setCaption( "*"+caption()); | 1092 | setCaption( "*"+caption()); |
1051 | edited1=true; | 1093 | edited1=true; |
1052 | } | 1094 | } |
1053 | edited=true; | 1095 | edited=true; |
1054 | } | 1096 | } |
1055 | 1097 | ||
1056 | void TextEdit::receive(const QCString&msg, const QByteArray &data) { | 1098 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1057 | qDebug("QCop "+msg); | 1099 | qDebug("QCop "+msg); |
1058 | if ( msg == "setDocument(QString)" ) { | 1100 | if ( msg == "setDocument(QString)" ) { |
1059 | qDebug("bugger all"); | 1101 | qDebug("bugger all"); |
1060 | 1102 | ||
1061 | } | 1103 | } |
1062 | 1104 | ||
1063 | } | 1105 | } |
1064 | 1106 | ||
1065 | void TextEdit::doAbout() { | 1107 | void TextEdit::doAbout() { |
1066 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1108 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1067 | "2000 Trolltech AS, and<BR>" | 1109 | "2000 Trolltech AS, and<BR>" |
1068 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1110 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1069 | "and is licensed under the GPL")); | 1111 | "and is licensed under the GPL")); |
1070 | } | 1112 | } |
1071 | 1113 | ||
1072 | void TextEdit::doPrompt(bool b) { | 1114 | void TextEdit::doPrompt(bool b) { |
@@ -1085,17 +1127,16 @@ void TextEdit::doDesktop(bool b) { | |||
1085 | 1127 | ||
1086 | void TextEdit::doFilePerms(bool b) { | 1128 | void TextEdit::doFilePerms(bool b) { |
1087 | filePerms=b; | 1129 | filePerms=b; |
1088 | Config cfg("TextEdit"); | 1130 | Config cfg("TextEdit"); |
1089 | cfg.setGroup ( "View" ); | 1131 | cfg.setGroup ( "View" ); |
1090 | cfg.writeEntry ( "FilePermissions", b); | 1132 | cfg.writeEntry ( "FilePermissions", b); |
1091 | } | 1133 | } |
1092 | 1134 | ||
1093 | void TextEdit::editPasteTimeDate() { | 1135 | void TextEdit::editPasteTimeDate() { |
1094 | #ifndef QT_NO_CLIPBOARD | 1136 | #ifndef QT_NO_CLIPBOARD |
1095 | QClipboard *cb = QApplication::clipboard(); | 1137 | QClipboard *cb = QApplication::clipboard(); |
1096 | QDateTime dt = QDateTime::currentDateTime(); | 1138 | QDateTime dt = QDateTime::currentDateTime(); |
1097 | cb->setText( dt.toString()); | 1139 | cb->setText( dt.toString()); |
1098 | editor->paste(); | 1140 | editor->paste(); |
1099 | #endif | 1141 | #endif |
1100 | } | 1142 | } |
1101 | |||