author | llornkcor <llornkcor> | 2002-03-13 02:57:16 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-03-13 02:57:16 (UTC) |
commit | 13d8ac43bf8d4c6e492e57d2ab3c7353935a9365 (patch) (unidiff) | |
tree | 4efc47c39ebde1ad5bc6fe824b79d19ccb2cab7d | |
parent | ad4f318f600a00905d45a780cd100bcf1e08efaa (diff) | |
download | opie-13d8ac43bf8d4c6e492e57d2ab3c7353935a9365.zip opie-13d8ac43bf8d4c6e492e57d2ab3c7353935a9365.tar.gz opie-13d8ac43bf8d4c6e492e57d2ab3c7353935a9365.tar.bz2 |
I fixed somethin
-rw-r--r-- | core/apps/textedit/textedit.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index f031a0f..c46f089 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -234,736 +234,737 @@ static int get_unique_id() | |||
234 | } | 234 | } |
235 | 235 | ||
236 | static const int nfontsizes = 6; | 236 | static const int nfontsizes = 6; |
237 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 237 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
238 | 238 | ||
239 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 239 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
240 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | 240 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) |
241 | { | 241 | { |
242 | doc = 0; | 242 | doc = 0; |
243 | edited=FALSE; | 243 | edited=FALSE; |
244 | edited1=FALSE; | 244 | edited1=FALSE; |
245 | setToolBarsMovable( FALSE ); | 245 | setToolBarsMovable( FALSE ); |
246 | 246 | ||
247 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 247 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
248 | 248 | ||
249 | QPEToolBar *bar = new QPEToolBar( this ); | 249 | QPEToolBar *bar = new QPEToolBar( this ); |
250 | bar->setHorizontalStretchable( TRUE ); | 250 | bar->setHorizontalStretchable( TRUE ); |
251 | menu = bar; | 251 | menu = bar; |
252 | 252 | ||
253 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 253 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
254 | QPopupMenu *file = new QPopupMenu( this ); | 254 | QPopupMenu *file = new QPopupMenu( this ); |
255 | QPopupMenu *edit = new QPopupMenu( this ); | 255 | QPopupMenu *edit = new QPopupMenu( this ); |
256 | font = new QPopupMenu( this ); | 256 | font = new QPopupMenu( this ); |
257 | 257 | ||
258 | bar = new QPEToolBar( this ); | 258 | bar = new QPEToolBar( this ); |
259 | editBar = bar; | 259 | editBar = bar; |
260 | 260 | ||
261 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 261 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
262 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 262 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
263 | a->addTo( bar ); | 263 | a->addTo( bar ); |
264 | a->addTo( file ); | 264 | a->addTo( file ); |
265 | 265 | ||
266 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 266 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
267 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 267 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
268 | // a->addTo( bar ); | 268 | // a->addTo( bar ); |
269 | a->addTo( file ); | 269 | a->addTo( file ); |
270 | 270 | ||
271 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 271 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
272 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); | 272 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); |
273 | a->addTo( bar ); | 273 | a->addTo( bar ); |
274 | a->addTo( file ); | 274 | a->addTo( file ); |
275 | 275 | ||
276 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 276 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
277 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 277 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
278 | // a->addTo( bar ); | 278 | // a->addTo( bar ); |
279 | file->insertSeparator(); | 279 | file->insertSeparator(); |
280 | a->addTo( file ); | 280 | a->addTo( file ); |
281 | 281 | ||
282 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 282 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
283 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 283 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
284 | a->addTo( file ); | 284 | a->addTo( file ); |
285 | 285 | ||
286 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 286 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
287 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 287 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
288 | a->addTo( editBar ); | 288 | a->addTo( editBar ); |
289 | a->addTo( edit ); | 289 | a->addTo( edit ); |
290 | 290 | ||
291 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 291 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
292 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 292 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
293 | a->addTo( editBar ); | 293 | a->addTo( editBar ); |
294 | a->addTo( edit ); | 294 | a->addTo( edit ); |
295 | 295 | ||
296 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 296 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
297 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 297 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
298 | a->addTo( editBar ); | 298 | a->addTo( editBar ); |
299 | a->addTo( edit ); | 299 | a->addTo( edit ); |
300 | 300 | ||
301 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 301 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
302 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 302 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
303 | edit->insertSeparator(); | 303 | edit->insertSeparator(); |
304 | a->addTo( bar ); | 304 | a->addTo( bar ); |
305 | a->addTo( edit ); | 305 | a->addTo( edit ); |
306 | 306 | ||
307 | 307 | ||
308 | int defsize; | 308 | int defsize; |
309 | bool defb, defi, wrap; | 309 | bool defb, defi, wrap; |
310 | 310 | ||
311 | Config cfg("TextEdit"); | 311 | Config cfg("TextEdit"); |
312 | cfg.setGroup("View"); | 312 | cfg.setGroup("View"); |
313 | defsize = cfg.readNumEntry("FontSize",10); | 313 | defsize = cfg.readNumEntry("FontSize",10); |
314 | defb = cfg.readBoolEntry("Bold",FALSE); | 314 | defb = cfg.readBoolEntry("Bold",FALSE); |
315 | defi = cfg.readBoolEntry("Italic",FALSE); | 315 | defi = cfg.readBoolEntry("Italic",FALSE); |
316 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 316 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
317 | 317 | ||
318 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 318 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
319 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 319 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
320 | zin->addTo( font ); | 320 | zin->addTo( font ); |
321 | 321 | ||
322 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 322 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
323 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 323 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
324 | zout->addTo( font ); | 324 | zout->addTo( font ); |
325 | 325 | ||
326 | font->insertSeparator(); | 326 | font->insertSeparator(); |
327 | 327 | ||
328 | #if 0 | 328 | #if 0 |
329 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | 329 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); |
330 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | 330 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); |
331 | ba->setToggleAction(TRUE); | 331 | ba->setToggleAction(TRUE); |
332 | ba->addTo( font ); | 332 | ba->addTo( font ); |
333 | 333 | ||
334 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | 334 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); |
335 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); | 335 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); |
336 | ia->setToggleAction(TRUE); | 336 | ia->setToggleAction(TRUE); |
337 | ia->addTo( font ); | 337 | ia->addTo( font ); |
338 | 338 | ||
339 | ba->setOn(defb); | 339 | ba->setOn(defb); |
340 | ia->setOn(defi); | 340 | ia->setOn(defi); |
341 | 341 | ||
342 | font->insertSeparator(); | 342 | font->insertSeparator(); |
343 | #endif | 343 | #endif |
344 | 344 | ||
345 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 345 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
346 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 346 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
347 | wa->setToggleAction(TRUE); | 347 | wa->setToggleAction(TRUE); |
348 | wa->addTo( font ); | 348 | wa->addTo( font ); |
349 | 349 | ||
350 | font->insertSeparator(); | 350 | font->insertSeparator(); |
351 | font->insertItem("Font", this, SLOT(changeFont()) ); | 351 | font->insertItem("Font", this, SLOT(changeFont()) ); |
352 | 352 | ||
353 | font->insertSeparator(); | 353 | font->insertSeparator(); |
354 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); | 354 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); |
355 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); | 355 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); |
356 | nStart->setToggleAction(TRUE); | 356 | nStart->setToggleAction(TRUE); |
357 | nStart->addTo( font ); | 357 | nStart->addTo( font ); |
358 | 358 | ||
359 | mb->insertItem( tr( "File" ), file ); | 359 | mb->insertItem( tr( "File" ), file ); |
360 | mb->insertItem( tr( "Edit" ), edit ); | 360 | mb->insertItem( tr( "Edit" ), edit ); |
361 | mb->insertItem( tr( "View" ), font ); | 361 | mb->insertItem( tr( "View" ), font ); |
362 | 362 | ||
363 | searchBar = new QPEToolBar(this); | 363 | searchBar = new QPEToolBar(this); |
364 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 364 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
365 | 365 | ||
366 | searchBar->setHorizontalStretchable( TRUE ); | 366 | searchBar->setHorizontalStretchable( TRUE ); |
367 | 367 | ||
368 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 368 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
369 | searchBar->setStretchableWidget( searchEdit ); | 369 | searchBar->setStretchableWidget( searchEdit ); |
370 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 370 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
371 | this, SLOT( search() ) ); | 371 | this, SLOT( search() ) ); |
372 | 372 | ||
373 | 373 | ||
374 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 374 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
375 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 375 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
376 | a->addTo( searchBar ); | 376 | a->addTo( searchBar ); |
377 | a->addTo( edit ); | 377 | a->addTo( edit ); |
378 | 378 | ||
379 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 379 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
380 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 380 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
381 | a->addTo( searchBar ); | 381 | a->addTo( searchBar ); |
382 | 382 | ||
383 | edit->insertSeparator(); | 383 | edit->insertSeparator(); |
384 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 384 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
385 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 385 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
386 | a->addTo( edit ); | 386 | a->addTo( edit ); |
387 | 387 | ||
388 | searchBar->hide(); | 388 | searchBar->hide(); |
389 | 389 | ||
390 | editorStack = new QWidgetStack( this ); | 390 | editorStack = new QWidgetStack( this ); |
391 | setCentralWidget( editorStack ); | 391 | setCentralWidget( editorStack ); |
392 | 392 | ||
393 | searchVisible = FALSE; | 393 | searchVisible = FALSE; |
394 | 394 | ||
395 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy | 395 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy |
396 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 396 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
397 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 397 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
398 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | 398 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); |
399 | // fileOpen(); | 399 | // fileOpen(); |
400 | 400 | ||
401 | editor = new QpeEditor( editorStack ); | 401 | editor = new QpeEditor( editorStack ); |
402 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 402 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
403 | editorStack->addWidget( editor, get_unique_id() ); | 403 | editorStack->addWidget( editor, get_unique_id() ); |
404 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); | 404 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); |
405 | 405 | ||
406 | resize( 200, 300 ); | 406 | resize( 200, 300 ); |
407 | 407 | ||
408 | // setFontSize(defsize,TRUE); | 408 | // setFontSize(defsize,TRUE); |
409 | FontDatabase fdb; | 409 | FontDatabase fdb; |
410 | QFont defaultFont=editor->font(); | 410 | QFont defaultFont=editor->font(); |
411 | QFontInfo fontInfo(defaultFont); | 411 | QFontInfo fontInfo(defaultFont); |
412 | 412 | ||
413 | cfg.setGroup("Font"); | 413 | cfg.setGroup("Font"); |
414 | QString family = cfg.readEntry("Family", fontInfo.family()); | 414 | QString family = cfg.readEntry("Family", fontInfo.family()); |
415 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 415 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
416 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 416 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
417 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 417 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
418 | 418 | ||
419 | defaultFont = fdb.font(family,style,i_size,charSet); | 419 | defaultFont = fdb.font(family,style,i_size,charSet); |
420 | editor->setFont( defaultFont); | 420 | editor->setFont( defaultFont); |
421 | 421 | ||
422 | wa->setOn(wrap); | 422 | wa->setOn(wrap); |
423 | updateCaption(); | 423 | updateCaption(); |
424 | 424 | ||
425 | cfg.setGroup("View"); | 425 | cfg.setGroup("View"); |
426 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | 426 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { |
427 | nStart->setOn(TRUE); | 427 | nStart->setOn(TRUE); |
428 | fileNew(); | 428 | fileNew(); |
429 | } else { | 429 | } else { |
430 | fileOpen(); | 430 | fileOpen(); |
431 | } | 431 | } |
432 | 432 | ||
433 | } | 433 | } |
434 | 434 | ||
435 | TextEdit::~TextEdit() | 435 | TextEdit::~TextEdit() |
436 | { | 436 | { |
437 | // save(); | 437 | // save(); |
438 | 438 | ||
439 | Config cfg("TextEdit"); | 439 | Config cfg("TextEdit"); |
440 | cfg.setGroup("View"); | 440 | cfg.setGroup("View"); |
441 | QFont f = editor->font(); | 441 | QFont f = editor->font(); |
442 | cfg.writeEntry("FontSize",f.pointSize()); | 442 | cfg.writeEntry("FontSize",f.pointSize()); |
443 | cfg.writeEntry("Bold",f.bold()); | 443 | cfg.writeEntry("Bold",f.bold()); |
444 | cfg.writeEntry("Italic",f.italic()); | 444 | cfg.writeEntry("Italic",f.italic()); |
445 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 445 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
446 | } | 446 | } |
447 | 447 | ||
448 | void TextEdit::zoomIn() | 448 | void TextEdit::zoomIn() |
449 | { | 449 | { |
450 | setFontSize(editor->font().pointSize()+1,FALSE); | 450 | setFontSize(editor->font().pointSize()+1,FALSE); |
451 | } | 451 | } |
452 | 452 | ||
453 | void TextEdit::zoomOut() | 453 | void TextEdit::zoomOut() |
454 | { | 454 | { |
455 | setFontSize(editor->font().pointSize()-1,TRUE); | 455 | setFontSize(editor->font().pointSize()-1,TRUE); |
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||
459 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 459 | void TextEdit::setFontSize(int sz, bool round_down_not_up) |
460 | { | 460 | { |
461 | int s=10; | 461 | int s=10; |
462 | for (int i=0; i<nfontsizes; i++) { | 462 | for (int i=0; i<nfontsizes; i++) { |
463 | if ( fontsize[i] == sz ) { | 463 | if ( fontsize[i] == sz ) { |
464 | s = sz; | 464 | s = sz; |
465 | break; | 465 | break; |
466 | } else if ( round_down_not_up ) { | 466 | } else if ( round_down_not_up ) { |
467 | if ( fontsize[i] < sz ) | 467 | if ( fontsize[i] < sz ) |
468 | s = fontsize[i]; | 468 | s = fontsize[i]; |
469 | } else { | 469 | } else { |
470 | if ( fontsize[i] > sz ) { | 470 | if ( fontsize[i] > sz ) { |
471 | s = fontsize[i]; | 471 | s = fontsize[i]; |
472 | break; | 472 | break; |
473 | } | 473 | } |
474 | } | 474 | } |
475 | } | 475 | } |
476 | 476 | ||
477 | QFont f = editor->font(); | 477 | QFont f = editor->font(); |
478 | f.setPointSize(s); | 478 | f.setPointSize(s); |
479 | editor->setFont(f); | 479 | editor->setFont(f); |
480 | 480 | ||
481 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 481 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
482 | zout->setEnabled(s != fontsize[0]); | 482 | zout->setEnabled(s != fontsize[0]); |
483 | } | 483 | } |
484 | 484 | ||
485 | void TextEdit::setBold(bool y) | 485 | void TextEdit::setBold(bool y) |
486 | { | 486 | { |
487 | QFont f = editor->font(); | 487 | QFont f = editor->font(); |
488 | f.setBold(y); | 488 | f.setBold(y); |
489 | editor->setFont(f); | 489 | editor->setFont(f); |
490 | } | 490 | } |
491 | 491 | ||
492 | void TextEdit::setItalic(bool y) | 492 | void TextEdit::setItalic(bool y) |
493 | { | 493 | { |
494 | QFont f = editor->font(); | 494 | QFont f = editor->font(); |
495 | f.setItalic(y); | 495 | f.setItalic(y); |
496 | editor->setFont(f); | 496 | editor->setFont(f); |
497 | } | 497 | } |
498 | 498 | ||
499 | void TextEdit::setWordWrap(bool y) | 499 | void TextEdit::setWordWrap(bool y) |
500 | { | 500 | { |
501 | bool state = editor->edited(); | 501 | bool state = editor->edited(); |
502 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 502 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
503 | editor->setEdited( state ); | 503 | editor->setEdited( state ); |
504 | } | 504 | } |
505 | 505 | ||
506 | void TextEdit::fileNew() | 506 | void TextEdit::fileNew() |
507 | { | 507 | { |
508 | if( !bFromDocView ) { | 508 | if( !bFromDocView ) { |
509 | saveAs(); | 509 | saveAs(); |
510 | } | 510 | } |
511 | newFile(DocLnk()); | 511 | newFile(DocLnk()); |
512 | } | 512 | } |
513 | 513 | ||
514 | void TextEdit::fileOpen() | 514 | void TextEdit::fileOpen() |
515 | { | 515 | { |
516 | // if ( !save() ) { | 516 | // if ( !save() ) { |
517 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 517 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
518 | // tr( "Text Editor was unable to\n" | 518 | // tr( "Text Editor was unable to\n" |
519 | // "save your changes.\n" | 519 | // "save your changes.\n" |
520 | // "Free some space and try again.\n" | 520 | // "Free some space and try again.\n" |
521 | // "\nContinue anyway?" ), | 521 | // "\nContinue anyway?" ), |
522 | // QMessageBox::Yes|QMessageBox::Escape, | 522 | // QMessageBox::Yes|QMessageBox::Escape, |
523 | // QMessageBox::No|QMessageBox::Default ) | 523 | // QMessageBox::No|QMessageBox::Default ) |
524 | // != QMessageBox::Yes ) | 524 | // != QMessageBox::Yes ) |
525 | // return; | 525 | // return; |
526 | // else { | 526 | // else { |
527 | // delete doc; | 527 | // delete doc; |
528 | // doc = 0; | 528 | // doc = 0; |
529 | // } | 529 | // } |
530 | // } | 530 | // } |
531 | menu->hide(); | 531 | menu->hide(); |
532 | editBar->hide(); | 532 | editBar->hide(); |
533 | searchBar->hide(); | 533 | searchBar->hide(); |
534 | clearWState (WState_Reserved1 ); | 534 | clearWState (WState_Reserved1 ); |
535 | editorStack->raiseWidget( fileSelector ); | 535 | editorStack->raiseWidget( fileSelector ); |
536 | fileSelector->reread(); | 536 | fileSelector->reread(); |
537 | updateCaption(); | 537 | updateCaption(); |
538 | } | 538 | } |
539 | 539 | ||
540 | void TextEdit::newFileOpen() | 540 | void TextEdit::newFileOpen() |
541 | { | 541 | { |
542 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); | 542 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); |
543 | if( browseForFiles->exec() != -1 ) { | 543 | if( browseForFiles->exec() != -1 ) { |
544 | QString selFile= browseForFiles->selectedFileName; | 544 | QString selFile= browseForFiles->selectedFileName; |
545 | QStringList fileList=browseForFiles->fileList; | 545 | QStringList fileList=browseForFiles->fileList; |
546 | qDebug(selFile); | 546 | qDebug(selFile); |
547 | QStringList::ConstIterator f; | 547 | QStringList::ConstIterator f; |
548 | QString fileTemp; | 548 | QString fileTemp; |
549 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 549 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
550 | fileTemp = *f; | 550 | fileTemp = *f; |
551 | fileTemp.right( fileTemp.length()-5); | 551 | fileTemp.right( fileTemp.length()-5); |
552 | QString fileName = fileTemp; | 552 | QString fileName = fileTemp; |
553 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 553 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
554 | currentFileName = fileName; | 554 | currentFileName = fileName; |
555 | qDebug("please open "+currentFileName); | 555 | qDebug("please open "+currentFileName); |
556 | openFile(fileName ); | 556 | openFile(fileName ); |
557 | } | 557 | } |
558 | } | 558 | } |
559 | } | 559 | } |
560 | delete browseForFiles; | 560 | delete browseForFiles; |
561 | editor->setEdited( FALSE); | 561 | editor->setEdited( FALSE); |
562 | edited1=FALSE; | 562 | edited1=FALSE; |
563 | edited=FALSE; | 563 | edited=FALSE; |
564 | if(caption().left(1)=="*") | 564 | if(caption().left(1)=="*") |
565 | setCaption(caption().right(caption().length()-1)); | 565 | setCaption(caption().right(caption().length()-1)); |
566 | } | 566 | } |
567 | 567 | ||
568 | #if 0 | 568 | #if 0 |
569 | void TextEdit::slotFind() | 569 | void TextEdit::slotFind() |
570 | { | 570 | { |
571 | FindDialog frmFind( "Text Editor", this ); | 571 | FindDialog frmFind( "Text Editor", this ); |
572 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 572 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
573 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 573 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
574 | 574 | ||
575 | //case sensitive, backwards, [category] | 575 | //case sensitive, backwards, [category] |
576 | 576 | ||
577 | connect( editor, SIGNAL(notFound()), | 577 | connect( editor, SIGNAL(notFound()), |
578 | &frmFind, SLOT(slotNotFound()) ); | 578 | &frmFind, SLOT(slotNotFound()) ); |
579 | connect( editor, SIGNAL(searchWrapped()), | 579 | connect( editor, SIGNAL(searchWrapped()), |
580 | &frmFind, SLOT(slotWrapAround()) ); | 580 | &frmFind, SLOT(slotWrapAround()) ); |
581 | 581 | ||
582 | frmFind.exec(); | 582 | frmFind.exec(); |
583 | 583 | ||
584 | 584 | ||
585 | } | 585 | } |
586 | #endif | 586 | #endif |
587 | 587 | ||
588 | void TextEdit::fileRevert() | 588 | void TextEdit::fileRevert() |
589 | { | 589 | { |
590 | clear(); | 590 | clear(); |
591 | fileOpen(); | 591 | fileOpen(); |
592 | } | 592 | } |
593 | 593 | ||
594 | void TextEdit::editCut() | 594 | void TextEdit::editCut() |
595 | { | 595 | { |
596 | #ifndef QT_NO_CLIPBOARD | 596 | #ifndef QT_NO_CLIPBOARD |
597 | editor->cut(); | 597 | editor->cut(); |
598 | #endif | 598 | #endif |
599 | } | 599 | } |
600 | 600 | ||
601 | void TextEdit::editCopy() | 601 | void TextEdit::editCopy() |
602 | { | 602 | { |
603 | #ifndef QT_NO_CLIPBOARD | 603 | #ifndef QT_NO_CLIPBOARD |
604 | editor->copy(); | 604 | editor->copy(); |
605 | #endif | 605 | #endif |
606 | } | 606 | } |
607 | 607 | ||
608 | void TextEdit::editPaste() | 608 | void TextEdit::editPaste() |
609 | { | 609 | { |
610 | #ifndef QT_NO_CLIPBOARD | 610 | #ifndef QT_NO_CLIPBOARD |
611 | editor->paste(); | 611 | editor->paste(); |
612 | #endif | 612 | #endif |
613 | } | 613 | } |
614 | 614 | ||
615 | void TextEdit::editFind() | 615 | void TextEdit::editFind() |
616 | { | 616 | { |
617 | searchBar->show(); | 617 | searchBar->show(); |
618 | searchVisible = TRUE; | 618 | searchVisible = TRUE; |
619 | searchEdit->setFocus(); | 619 | searchEdit->setFocus(); |
620 | } | 620 | } |
621 | 621 | ||
622 | void TextEdit::findNext() | 622 | void TextEdit::findNext() |
623 | { | 623 | { |
624 | editor->find( searchEdit->text(), FALSE, FALSE ); | 624 | editor->find( searchEdit->text(), FALSE, FALSE ); |
625 | 625 | ||
626 | } | 626 | } |
627 | 627 | ||
628 | void TextEdit::findClose() | 628 | void TextEdit::findClose() |
629 | { | 629 | { |
630 | searchVisible = FALSE; | 630 | searchVisible = FALSE; |
631 | searchBar->hide(); | 631 | searchBar->hide(); |
632 | } | 632 | } |
633 | 633 | ||
634 | void TextEdit::search() | 634 | void TextEdit::search() |
635 | { | 635 | { |
636 | editor->find( searchEdit->text(), FALSE, FALSE ); | 636 | editor->find( searchEdit->text(), FALSE, FALSE ); |
637 | } | 637 | } |
638 | 638 | ||
639 | void TextEdit::newFile( const DocLnk &f ) | 639 | void TextEdit::newFile( const DocLnk &f ) |
640 | { | 640 | { |
641 | DocLnk nf = f; | 641 | DocLnk nf = f; |
642 | nf.setType("text/plain"); | 642 | nf.setType("text/plain"); |
643 | clear(); | 643 | clear(); |
644 | editorStack->raiseWidget( editor ); | 644 | editorStack->raiseWidget( editor ); |
645 | setWState (WState_Reserved1 ); | 645 | setWState (WState_Reserved1 ); |
646 | editor->setFocus(); | 646 | editor->setFocus(); |
647 | doc = new DocLnk(nf); | 647 | doc = new DocLnk(nf); |
648 | qDebug("newFile "+currentFileName); | 648 | qDebug("newFile "+currentFileName); |
649 | updateCaption(currentFileName); | 649 | updateCaption(currentFileName); |
650 | } | 650 | } |
651 | 651 | ||
652 | void TextEdit::openFile( const QString &f ) | 652 | void TextEdit::openFile( const QString &f ) |
653 | { | 653 | { |
654 | bFromDocView = TRUE; | 654 | bFromDocView = TRUE; |
655 | DocLnk nf; | 655 | DocLnk nf; |
656 | nf.setType("text/plain"); | 656 | nf.setType("text/plain"); |
657 | nf.setFile(f); | 657 | nf.setFile(f); |
658 | currentFileName=f; | 658 | currentFileName=f; |
659 | QFileInfo fi( currentFileName); | 659 | QFileInfo fi( currentFileName); |
660 | nf.setName(fi.baseName()); | 660 | nf.setName(fi.baseName()); |
661 | qDebug("openFile string"+currentFileName); | 661 | qDebug("openFile string"+currentFileName); |
662 | 662 | ||
663 | openFile(nf); | 663 | openFile(nf); |
664 | showEditTools(); | 664 | showEditTools(); |
665 | // Show filename in caption | 665 | // Show filename in caption |
666 | QString name = f; | 666 | QString name = f; |
667 | int sep = name.findRev( '/' ); | 667 | int sep = name.findRev( '/' ); |
668 | if ( sep > 0 ) | 668 | if ( sep > 0 ) |
669 | name = name.mid( sep+1 ); | 669 | name = name.mid( sep+1 ); |
670 | updateCaption( name ); | 670 | updateCaption( name ); |
671 | } | 671 | } |
672 | 672 | ||
673 | void TextEdit::openFile( const DocLnk &f ) | 673 | void TextEdit::openFile( const DocLnk &f ) |
674 | { | 674 | { |
675 | // clear(); | 675 | // clear(); |
676 | bFromDocView = TRUE; | 676 | bFromDocView = TRUE; |
677 | FileManager fm; | 677 | FileManager fm; |
678 | QString txt; | 678 | QString txt; |
679 | currentFileName=f.name(); | 679 | currentFileName=f.name(); |
680 | qDebug("openFile doclnk " + currentFileName); | 680 | qDebug("openFile doclnk " + currentFileName); |
681 | if ( !fm.loadFile( f, txt ) ) { | 681 | if ( !fm.loadFile( f, txt ) ) { |
682 | // ####### could be a new file | 682 | // ####### could be a new file |
683 | qDebug( "Cannot open file" ); | 683 | qDebug( "Cannot open file" ); |
684 | 684 | ||
685 | //return; | 685 | //return; |
686 | } | 686 | } |
687 | 687 | ||
688 | fileNew(); | 688 | fileNew(); |
689 | if ( doc ) | 689 | if ( doc ) |
690 | delete doc; | 690 | delete doc; |
691 | doc = new DocLnk(f); | 691 | doc = new DocLnk(f); |
692 | editor->setText(txt); | 692 | editor->setText(txt); |
693 | editor->setEdited( FALSE); | 693 | editor->setEdited( FALSE); |
694 | edited1=FALSE; | 694 | edited1=FALSE; |
695 | edited=FALSE; | 695 | edited=FALSE; |
696 | 696 | ||
697 | qDebug("openFile doclnk "+currentFileName); | 697 | qDebug("openFile doclnk "+currentFileName); |
698 | doc->setName(currentFileName); | 698 | doc->setName(currentFileName); |
699 | updateCaption(); | 699 | updateCaption(); |
700 | } | 700 | } |
701 | 701 | ||
702 | void TextEdit::showEditTools() | 702 | void TextEdit::showEditTools() |
703 | { | 703 | { |
704 | // if ( !doc ) | 704 | // if ( !doc ) |
705 | // close(); | 705 | // close(); |
706 | // clear(); | 706 | // clear(); |
707 | fileSelector->hide(); | 707 | fileSelector->hide(); |
708 | menu->show(); | 708 | menu->show(); |
709 | editBar->show(); | 709 | editBar->show(); |
710 | if ( searchVisible ) | 710 | if ( searchVisible ) |
711 | searchBar->show(); | 711 | searchBar->show(); |
712 | // updateCaption(); | 712 | // updateCaption(); |
713 | editorStack->raiseWidget( editor ); | 713 | editorStack->raiseWidget( editor ); |
714 | setWState (WState_Reserved1 ); | 714 | setWState (WState_Reserved1 ); |
715 | } | 715 | } |
716 | 716 | ||
717 | /*! | 717 | /*! |
718 | unprompted save */ | 718 | unprompted save */ |
719 | bool TextEdit::save() | 719 | bool TextEdit::save() |
720 | { | 720 | { |
721 | QString file = doc->file(); | 721 | QString file = doc->file(); |
722 | qDebug(file); | 722 | qDebug(file); |
723 | QString name= doc->name(); | 723 | QString name= doc->name(); |
724 | qDebug(name); | 724 | qDebug(name); |
725 | QString rt = editor->text(); | 725 | QString rt = editor->text(); |
726 | if( !rt.isEmpty() ) { | 726 | if( !rt.isEmpty() ) { |
727 | if(name.isEmpty()) { | 727 | if(name.isEmpty()) { |
728 | saveAs(); | 728 | saveAs(); |
729 | } else { | 729 | } else { |
730 | currentFileName= name ; | 730 | currentFileName= name ; |
731 | qDebug("saveFile "+currentFileName); | 731 | qDebug("saveFile "+currentFileName); |
732 | 732 | ||
733 | struct stat buf; | 733 | struct stat buf; |
734 | mode_t mode; | 734 | mode_t mode; |
735 | stat(file.latin1(), &buf); | 735 | stat(file.latin1(), &buf); |
736 | mode = buf.st_mode; | 736 | mode = buf.st_mode; |
737 | 737 | ||
738 | doc->setName( name); | 738 | doc->setName( name); |
739 | FileManager fm; | 739 | FileManager fm; |
740 | if ( !fm.saveFile( *doc, rt ) ) { | 740 | if ( !fm.saveFile( *doc, rt ) ) { |
741 | return false; | 741 | return false; |
742 | } | 742 | } |
743 | editor->setEdited( FALSE); | 743 | editor->setEdited( FALSE); |
744 | edited1=FALSE; | 744 | edited1=FALSE; |
745 | edited=FALSE; | 745 | edited=FALSE; |
746 | if(caption().left(1)=="*") | ||
746 | setCaption(caption().right(caption().length()-1)); | 747 | setCaption(caption().right(caption().length()-1)); |
747 | 748 | ||
748 | 749 | ||
749 | chmod( file.latin1(), mode); | 750 | chmod( file.latin1(), mode); |
750 | } | 751 | } |
751 | return true; | 752 | return true; |
752 | } | 753 | } |
753 | return false; | 754 | return false; |
754 | } | 755 | } |
755 | 756 | ||
756 | /*! | 757 | /*! |
757 | prompted save */ | 758 | prompted save */ |
758 | bool TextEdit::saveAs() | 759 | bool TextEdit::saveAs() |
759 | { | 760 | { |
760 | // qDebug("saveAsFile "+currentFileName); | 761 | // qDebug("saveAsFile "+currentFileName); |
761 | 762 | ||
762 | // case of nothing to save... /// there's always something to save | 763 | // case of nothing to save... /// there's always something to save |
763 | // if ( !doc )//|| !bFromDocView) | 764 | // if ( !doc )//|| !bFromDocView) |
764 | // { | 765 | // { |
765 | // qDebug("no doc"); | 766 | // qDebug("no doc"); |
766 | // return true; | 767 | // return true; |
767 | // } | 768 | // } |
768 | if ( !editor->edited() ) { | 769 | if ( !editor->edited() ) { |
769 | delete doc; | 770 | delete doc; |
770 | doc = 0; | 771 | doc = 0; |
771 | return true; | 772 | return true; |
772 | } | 773 | } |
773 | 774 | ||
774 | QString rt = editor->text(); | 775 | QString rt = editor->text(); |
775 | qDebug(currentFileName); | 776 | qDebug(currentFileName); |
776 | 777 | ||
777 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 778 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
778 | qDebug("do silly TT filename thing"); | 779 | qDebug("do silly TT filename thing"); |
779 | if ( doc->name().isEmpty() ) { | 780 | if ( doc->name().isEmpty() ) { |
780 | QString pt = rt.simplifyWhiteSpace(); | 781 | QString pt = rt.simplifyWhiteSpace(); |
781 | int i = pt.find( ' ' ); | 782 | int i = pt.find( ' ' ); |
782 | QString docname = pt; | 783 | QString docname = pt; |
783 | if ( i > 0 ) | 784 | if ( i > 0 ) |
784 | docname = pt.left( i ); | 785 | docname = pt.left( i ); |
785 | // remove "." at the beginning | 786 | // remove "." at the beginning |
786 | while( docname.startsWith( "." ) ) | 787 | while( docname.startsWith( "." ) ) |
787 | docname = docname.mid( 1 ); | 788 | docname = docname.mid( 1 ); |
788 | docname.replace( QRegExp("/"), "_" ); | 789 | docname.replace( QRegExp("/"), "_" ); |
789 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 790 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
790 | if ( docname.length() > 40 ) | 791 | if ( docname.length() > 40 ) |
791 | docname = docname.left(40); | 792 | docname = docname.left(40); |
792 | if ( docname.isEmpty() ) | 793 | if ( docname.isEmpty() ) |
793 | docname = "Unnamed"; | 794 | docname = "Unnamed"; |
794 | doc->setName(docname); | 795 | doc->setName(docname); |
795 | currentFileName=docname; | 796 | currentFileName=docname; |
796 | } | 797 | } |
797 | } | 798 | } |
798 | 799 | ||
799 | 800 | ||
800 | fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); | 801 | fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); |
801 | qDebug("wanna save filename "+currentFileName); | 802 | qDebug("wanna save filename "+currentFileName); |
802 | fileSaveDlg->exec(); | 803 | fileSaveDlg->exec(); |
803 | if( fileSaveDlg->result() == 1 ) { | 804 | if( fileSaveDlg->result() == 1 ) { |
804 | QString fileNm=fileSaveDlg->selectedFileName; | 805 | QString fileNm=fileSaveDlg->selectedFileName; |
805 | qDebug("saving filename "+fileNm); | 806 | qDebug("saving filename "+fileNm); |
806 | QFileInfo fi(fileNm); | 807 | QFileInfo fi(fileNm); |
807 | currentFileName=fi.fileName(); | 808 | currentFileName=fi.fileName(); |
808 | if(doc) { | 809 | if(doc) { |
809 | // QString file = doc->file(); | 810 | // QString file = doc->file(); |
810 | // doc->removeFiles(); | 811 | // doc->removeFiles(); |
811 | delete doc; | 812 | delete doc; |
812 | DocLnk nf; | 813 | DocLnk nf; |
813 | nf.setType("text/plain"); | 814 | nf.setType("text/plain"); |
814 | nf.setFile( fileNm); | 815 | nf.setFile( fileNm); |
815 | doc = new DocLnk(nf); | 816 | doc = new DocLnk(nf); |
816 | // editor->setText(rt); | 817 | // editor->setText(rt); |
817 | // qDebug("openFile doclnk "+currentFileName); | 818 | // qDebug("openFile doclnk "+currentFileName); |
818 | doc->setName( currentFileName); | 819 | doc->setName( currentFileName); |
819 | updateCaption( currentFileName); | 820 | updateCaption( currentFileName); |
820 | 821 | ||
821 | FileManager fm; | 822 | FileManager fm; |
822 | if ( !fm.saveFile( *doc, rt ) ) { | 823 | if ( !fm.saveFile( *doc, rt ) ) { |
823 | return false; | 824 | return false; |
824 | } | 825 | } |
825 | if( fileSaveDlg->filePermCheck->isChecked() ) { | 826 | if( fileSaveDlg->filePermCheck->isChecked() ) { |
826 | filePermissions *filePerm; | 827 | filePermissions *filePerm; |
827 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); | 828 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); |
828 | filePerm->exec(); | 829 | filePerm->exec(); |
829 | 830 | ||
830 | if( filePerm) | 831 | if( filePerm) |
831 | delete filePerm; | 832 | delete filePerm; |
832 | } | 833 | } |
833 | } | 834 | } |
834 | } | 835 | } |
835 | editor->setEdited( FALSE); | 836 | editor->setEdited(TRUE); |
836 | edited1=FALSE; | 837 | edited1=FALSE; |
837 | edited=FALSE; | 838 | edited=TRUE; |
838 | if(caption().left(1)=="*") | 839 | if(caption().left(1)=="*") |
839 | setCaption(caption().right(caption().length()-1)); | 840 | setCaption(caption().right(caption().length()-1)); |
840 | 841 | ||
841 | if(fileSaveDlg) | 842 | if(fileSaveDlg) |
842 | delete fileSaveDlg; | 843 | delete fileSaveDlg; |
843 | return true; | 844 | return true; |
844 | } | 845 | } |
845 | 846 | ||
846 | void TextEdit::clear() | 847 | void TextEdit::clear() |
847 | { | 848 | { |
848 | delete doc; | 849 | delete doc; |
849 | doc = 0; | 850 | doc = 0; |
850 | editor->clear(); | 851 | editor->clear(); |
851 | } | 852 | } |
852 | 853 | ||
853 | void TextEdit::updateCaption( const QString &name ) | 854 | void TextEdit::updateCaption( const QString &name ) |
854 | { | 855 | { |
855 | if ( !doc ) | 856 | if ( !doc ) |
856 | setCaption( tr("Text Editor") ); | 857 | setCaption( tr("Text Editor") ); |
857 | else { | 858 | else { |
858 | QString s = name; | 859 | QString s = name; |
859 | if ( s.isNull() ) | 860 | if ( s.isNull() ) |
860 | s = doc->name(); | 861 | s = doc->name(); |
861 | if ( s.isEmpty() ) { | 862 | if ( s.isEmpty() ) { |
862 | s = tr( "Unnamed" ); | 863 | s = tr( "Unnamed" ); |
863 | currentFileName=s; | 864 | currentFileName=s; |
864 | } | 865 | } |
865 | 866 | ||
866 | setCaption( s + " - " + tr("Text Editor") ); | 867 | setCaption( s + " - " + tr("Text Editor") ); |
867 | } | 868 | } |
868 | } | 869 | } |
869 | 870 | ||
870 | void TextEdit::setDocument(const QString& fileref) | 871 | void TextEdit::setDocument(const QString& fileref) |
871 | { | 872 | { |
872 | bFromDocView = TRUE; | 873 | bFromDocView = TRUE; |
873 | qDebug("setDocument "+fileref); | 874 | qDebug("setDocument "+fileref); |
874 | bFromDocView = TRUE; | 875 | bFromDocView = TRUE; |
875 | if(fileref.find(".desktop",0,TRUE) == -1) { | 876 | if(fileref.find(".desktop",0,TRUE) == -1) { |
876 | openFile(fileref); | 877 | openFile(fileref); |
877 | } else { | 878 | } else { |
878 | openFile(DocLnk(fileref)); | 879 | openFile(DocLnk(fileref)); |
879 | } | 880 | } |
880 | editor->setEdited(TRUE); | 881 | editor->setEdited(TRUE); |
881 | edited1=FALSE; | 882 | edited1=FALSE; |
882 | edited=TRUE; | 883 | edited=TRUE; |
883 | } | 884 | } |
884 | 885 | ||
885 | void TextEdit::closeEvent( QCloseEvent *e ) | 886 | void TextEdit::closeEvent( QCloseEvent *e ) |
886 | { | 887 | { |
887 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { | 888 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { |
888 | e->ignore(); | 889 | e->ignore(); |
889 | repaint(); | 890 | repaint(); |
890 | // fileRevert(); | 891 | // fileRevert(); |
891 | 892 | ||
892 | } else { | 893 | } else { |
893 | bFromDocView = FALSE; | 894 | bFromDocView = FALSE; |
894 | e->accept(); | 895 | e->accept(); |
895 | } | 896 | } |
896 | } | 897 | } |
897 | 898 | ||
898 | void TextEdit::accept() | 899 | void TextEdit::accept() |
899 | { | 900 | { |
900 | QString file = doc->file(); | 901 | QString file = doc->file(); |
901 | if (file.find("_.txt",0,TRUE) ==-1) | 902 | if (file.find("_.txt",0,TRUE) ==-1) |
902 | save(); | 903 | save(); |
903 | else { | 904 | else { |
904 | QFile(file).remove(); | 905 | QFile(file).remove(); |
905 | } | 906 | } |
906 | exit(0); | 907 | exit(0); |
907 | 908 | ||
908 | } | 909 | } |
909 | 910 | ||
910 | void TextEdit::changeFont() { | 911 | void TextEdit::changeFont() { |
911 | FontDatabase fdb; | 912 | FontDatabase fdb; |
912 | QFont defaultFont=editor->font(); | 913 | QFont defaultFont=editor->font(); |
913 | QFontInfo fontInfo(defaultFont); | 914 | QFontInfo fontInfo(defaultFont); |
914 | Config cfg("TextEdit"); | 915 | Config cfg("TextEdit"); |
915 | cfg.setGroup("Font"); | 916 | cfg.setGroup("Font"); |
916 | QString family = cfg.readEntry("Family", fontInfo.family()); | 917 | QString family = cfg.readEntry("Family", fontInfo.family()); |
917 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 918 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
918 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 919 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
919 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 920 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
920 | 921 | ||
921 | defaultFont = fdb.font(family,style,i_size,charSet); | 922 | defaultFont = fdb.font(family,style,i_size,charSet); |
922 | 923 | ||
923 | FontDialog *fontDlg; | 924 | FontDialog *fontDlg; |
924 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | 925 | fontDlg=new FontDialog(this,"FontDialog",TRUE); |
925 | 926 | ||
926 | fontDlg->exec(); | 927 | fontDlg->exec(); |
927 | 928 | ||
928 | QFont myFont=fontDlg->selectedFont; | 929 | QFont myFont=fontDlg->selectedFont; |
929 | editor->setFont( myFont); | 930 | editor->setFont( myFont); |
930 | delete fontDlg; | 931 | delete fontDlg; |
931 | 932 | ||
932 | } | 933 | } |
933 | 934 | ||
934 | void TextEdit::editDelete() | 935 | void TextEdit::editDelete() |
935 | { | 936 | { |
936 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { | 937 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { |
937 | case 0: | 938 | case 0: |
938 | if(doc) { | 939 | if(doc) { |
939 | doc->removeFiles(); | 940 | doc->removeFiles(); |
940 | clear(); | 941 | clear(); |
941 | setCaption( tr("Text Editor") ); | 942 | setCaption( tr("Text Editor") ); |
942 | } | 943 | } |
943 | break; | 944 | break; |
944 | case 1: | 945 | case 1: |
945 | // exit | 946 | // exit |
946 | break; | 947 | break; |
947 | }; | 948 | }; |
948 | } | 949 | } |
949 | 950 | ||
950 | void TextEdit::changeStartConfig( bool b ) { | 951 | void TextEdit::changeStartConfig( bool b ) { |
951 | 952 | ||
952 | Config cfg("TextEdit"); | 953 | Config cfg("TextEdit"); |
953 | cfg.setGroup("View"); | 954 | cfg.setGroup("View"); |
954 | if(b) { | 955 | if(b) { |
955 | qDebug("bool"); | 956 | qDebug("bool"); |
956 | cfg.writeEntry("startNew","TRUE"); | 957 | cfg.writeEntry("startNew","TRUE"); |
957 | } else { | 958 | } else { |
958 | cfg.writeEntry("startNew","FALSE"); | 959 | cfg.writeEntry("startNew","FALSE"); |
959 | } | 960 | } |
960 | update(); | 961 | update(); |
961 | } | 962 | } |
962 | 963 | ||
963 | void TextEdit::editorChanged() { | 964 | void TextEdit::editorChanged() { |
964 | if(editor->edited() && edited && !edited1) { | 965 | if(editor->edited() && edited && !edited1) { |
965 | setCaption( "*"+caption()); | 966 | setCaption( "*"+caption()); |
966 | edited1=TRUE; | 967 | edited1=TRUE; |
967 | } | 968 | } |
968 | edited=TRUE; | 969 | edited=TRUE; |
969 | } | 970 | } |