summaryrefslogtreecommitdiff
path: root/core/apps/textedit/textedit.cpp
Unidiff
Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp291
1 files changed, 250 insertions, 41 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 867625e..14bc496 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -19,5 +19,11 @@
19**********************************************************************/ 19**********************************************************************/
20// changes added by L. J. Potter Sun 02-17-2002 21:31:31
20 21
21#include "textedit.h" 22#include "textedit.h"
23#include "fileBrowser.h"
24#include "fileSaver.h"
22 25
26#include "fontDialog.h"
27
28#include <qpe/fontdatabase.h>
23#include <qpe/global.h> 29#include <qpe/global.h>
@@ -32,2 +38,3 @@
32 38
39#include <qstringlist.h>
33#include <qaction.h> 40#include <qaction.h>
@@ -44,2 +51,99 @@
44#include <stdlib.h> //getenv 51#include <stdlib.h> //getenv
52/* XPM */
53static char * filesave_xpm[] = {
54"16 16 78 1",
55" c None",
56". c #343434",
57"+ c #A0A0A0",
58"@ c #565656",
59"# c #9E9E9E",
60"$ c #525252",
61"% c #929292",
62"& c #676767",
63"* c #848484",
64"= c #666666",
65"- c #D8D8D8",
66"; c #FFFFFF",
67"> c #DBDBDB",
68", c #636363",
69"' c #989898",
70") c #2D2D2D",
71"! c #909090",
72"~ c #AEAEAE",
73"{ c #EAEAEA",
74"] c #575757",
75"^ c #585858",
76"/ c #8A8A8A",
77"( c #828282",
78"_ c #6F6F6F",
79": c #C9C9C9",
80"< c #050505",
81"[ c #292929",
82"} c #777777",
83"| c #616161",
84"1 c #3A3A3A",
85"2 c #BEBEBE",
86"3 c #2C2C2C",
87"4 c #7C7C7C",
88"5 c #F6F6F6",
89"6 c #FCFCFC",
90"7 c #6B6B6B",
91"8 c #959595",
92"9 c #4F4F4F",
93"0 c #808080",
94"a c #767676",
95"b c #818181",
96"c c #B8B8B8",
97"d c #FBFBFB",
98"e c #F9F9F9",
99"f c #CCCCCC",
100"g c #030303",
101"h c #737373",
102"i c #7A7A7A",
103"j c #7E7E7E",
104"k c #6A6A6A",
105"l c #FAFAFA",
106"m c #505050",
107"n c #9D9D9D",
108"o c #333333",
109"p c #7B7B7B",
110"q c #787878",
111"r c #696969",
112"s c #494949",
113"t c #555555",
114"u c #949494",
115"v c #E6E6E6",
116"w c #424242",
117"x c #515151",
118"y c #535353",
119"z c #3E3E3E",
120"A c #D4D4D4",
121"B c #0C0C0C",
122"C c #353535",
123"D c #474747",
124"E c #ECECEC",
125"F c #919191",
126"G c #7D7D7D",
127"H c #000000",
128"I c #404040",
129"J c #858585",
130"K c #323232",
131"L c #D0D0D0",
132"M c #1C1C1C",
133" ...+ ",
134" @#$%&..+ ",
135" .*=-;;>,..+ ",
136" ')!~;;;;;;{]..",
137" ^/(-;;;;;;;_:<",
138" [}|;;;;;;;{12$",
139" #34-55;;;;678$+",
140" 90ab=c;dd;e1fg ",
141" [ahij((kbl0mn$ ",
142" op^q^^7r&]s/$+ ",
143"@btu;vbwxy]zAB ",
144"CzDEvEv;;DssF$ ",
145"G.H{E{E{IxsJ$+ ",
146" +...vEKxzLM ",
147" +...z]n$ ",
148" +... "};
45 149
@@ -53,3 +157,7 @@ public:
53 QpeEditor( QWidget *parent, const char * name = 0 ) 157 QpeEditor( QWidget *parent, const char * name = 0 )
54 : QMultiLineEdit( parent, name ) {} 158 : QMultiLineEdit( parent, name )
159 {
160 clearTableFlags();
161 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
162 }
55 163
@@ -131,4 +239,2 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
131 239
132 QString lang = getenv( "LANG" );
133
134 setToolBarsMovable( FALSE ); 240 setToolBarsMovable( FALSE );
@@ -156,2 +262,7 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
156 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 262 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
263// a->addTo( bar );
264 a->addTo( file );
265
266 a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
267 connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) );
157 a->addTo( bar ); 268 a->addTo( bar );
@@ -159,2 +270,9 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
159 270
271//
272 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
273 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
274// a->addTo( bar );
275 file->insertSeparator();
276 a->addTo( file );
277
160 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 278 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
@@ -182,3 +300,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
182 bool defb, defi, wrap; 300 bool defb, defi, wrap;
183 { 301
184 Config cfg("TextEdit"); 302 Config cfg("TextEdit");
@@ -189,3 +307,2 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
189 wrap = cfg.readBoolEntry("Wrap",TRUE); 307 wrap = cfg.readBoolEntry("Wrap",TRUE);
190 }
191 308
@@ -223,2 +340,5 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
223 340
341 font->insertSeparator();
342 font->insertItem("Font", this, SLOT(changeFont()) );
343
224 mb->insertItem( tr( "File" ), file ); 344 mb->insertItem( tr( "File" ), file );
@@ -237,2 +357,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
237 357
358
238 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 359 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
@@ -253,5 +374,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
253 374
254 fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , 375 fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy
255 TRUE, FALSE );
256 fileSelector->setCategoriesVisible(TRUE);
257 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); 376 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
@@ -259,5 +378,6 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
259 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); 378 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
260 fileOpen(); 379// fileOpen();
261 380
262 editor = new QpeEditor( editorStack ); 381 editor = new QpeEditor( editorStack );
382 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
263 editorStack->addWidget( editor, get_unique_id() ); 383 editorStack->addWidget( editor, get_unique_id() );
@@ -266,4 +386,28 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
266 386
267 setFontSize(defsize,TRUE); 387// setFontSize(defsize,TRUE);
388 FontDatabase fdb;
389 QFont defaultFont=editor->font();
390 QFontInfo fontInfo(defaultFont);
391
392 cfg.setGroup("Font");
393 QString family = cfg.readEntry("Family", fontInfo.family());
394 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
395 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
396 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
397
398 defaultFont = fdb.font(family,style,i_size,charSet);
399 editor->setFont( defaultFont);
400
268 wa->setOn(wrap); 401 wa->setOn(wrap);
402 updateCaption();
403 if( qApp->argc() > 1 ) {
404 for (int i=1;i< qApp->argc();i++) {
405 QString tmp;
406 currentFileName = tmp.sprintf("%s",qApp->argv()[i]);
407 qDebug(currentFileName);
408 setDocument( currentFileName );
409 }
410 }
411 else
412 fileNew();
269} 413}
@@ -336,3 +480,5 @@ void TextEdit::setWordWrap(bool y)
336{ 480{
481 bool state = editor->edited();
337 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 482 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
483 editor->setEdited( state );
338} 484}
@@ -347,17 +493,17 @@ void TextEdit::fileOpen()
347{ 493{
348 if ( !save() ) { 494// if ( !save() ) {
349 if ( QMessageBox::critical( this, tr( "Out of space" ), 495// if ( QMessageBox::critical( this, tr( "Out of space" ),
350 tr( "Text Editor was unable to\n" 496// tr( "Text Editor was unable to\n"
351 "save your changes.\n" 497// "save your changes.\n"
352 "Free some space and try again.\n" 498// "Free some space and try again.\n"
353 "\nContinue anyway?" ), 499// "\nContinue anyway?" ),
354 QMessageBox::Yes|QMessageBox::Escape, 500// QMessageBox::Yes|QMessageBox::Escape,
355 QMessageBox::No|QMessageBox::Default ) 501// QMessageBox::No|QMessageBox::Default )
356 != QMessageBox::Yes ) 502// != QMessageBox::Yes )
357 return; 503// return;
358 else { 504// else {
359 delete doc; 505// delete doc;
360 doc = 0; 506// doc = 0;
361 } 507// }
362 } 508// }
363 menu->hide(); 509 menu->hide();
@@ -371,2 +517,25 @@ void TextEdit::fileOpen()
371 517
518void TextEdit::newFileOpen()
519{
520 fileBrowser *browseForFiles;
521 browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*");
522 browseForFiles->exec();
523 QString selFile= browseForFiles->selectedFileName;
524 QStringList fileList=browseForFiles->fileList;
525 qDebug(selFile);
526 QStringList::ConstIterator f;
527 QString fileTemp;
528 for ( f = fileList.begin(); f != fileList.end(); f++ ) {
529 fileTemp = *f;
530 fileTemp.right( fileTemp.length()-5);
531 QString fileName = fileTemp;
532 if( fileName != "Unnamed" || fileName != "Empty Text" ) {
533 currentFileName = fileName;
534 qDebug("please open "+currentFileName);
535 openFile(fileName );
536 }
537 }
538 delete browseForFiles;
539
540}
372 541
@@ -381,3 +550,2 @@ void TextEdit::slotFind()
381 550
382
383 connect( editor, SIGNAL(notFound()), 551 connect( editor, SIGNAL(notFound()),
@@ -474,3 +642,3 @@ void TextEdit::openFile( const DocLnk &f )
474{ 642{
475 clear(); 643// clear();
476 FileManager fm; 644 FileManager fm;
@@ -479,5 +647,7 @@ void TextEdit::openFile( const DocLnk &f )
479 // ####### could be a new file 647 // ####### could be a new file
480 //qDebug( "Cannot open file" ); 648 qDebug( "Cannot open file" );
649
481 //return; 650 //return;
482 } 651 }
652
483 fileNew(); 653 fileNew();
@@ -493,4 +663,5 @@ void TextEdit::showEditTools()
493{ 663{
494 if ( !doc ) 664// if ( !doc )
495 close(); 665// close();
666// clear();
496 fileSelector->hide(); 667 fileSelector->hide();
@@ -501,2 +672,4 @@ void TextEdit::showEditTools()
501 updateCaption(); 672 updateCaption();
673 editorStack->raiseWidget( editor );
674 setWState (WState_Reserved1 );
502} 675}
@@ -506,3 +679,3 @@ bool TextEdit::save()
506 // case of nothing to save... 679 // case of nothing to save...
507 if ( !doc ) 680 if ( !doc || !bFromDocView)
508 return true; 681 return true;
@@ -516,2 +689,4 @@ bool TextEdit::save()
516 689
690 if(currentFileName.isEmpty() || currentFileName == "Unnamed") {
691
517 if ( doc->name().isEmpty() ) { 692 if ( doc->name().isEmpty() ) {
@@ -532,7 +707,3 @@ bool TextEdit::save()
532 doc->setName(docname); 707 doc->setName(docname);
533 708 currentFileName=docname;
534 // append .txt to the file name
535 if ( doc->file().find(".txt") == -1 ) {
536 QString file = doc->file() + ".txt";
537 doc->setFile( file );
538 } 709 }
@@ -540,2 +711,10 @@ bool TextEdit::save()
540 711
712 fileSaver *fileSaveDlg;
713 fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName);
714 fileSaveDlg->exec();
715 QString fileNm=fileSaveDlg->selectedFileName;
716 qDebug("save filename "+fileNm);
717 doc->setName(fileNm);
718 updateCaption();
719 delete fileSaveDlg;
541 720
@@ -566,4 +745,6 @@ void TextEdit::updateCaption( const QString &name )
566 s = doc->name(); 745 s = doc->name();
567 if ( s.isEmpty() ) 746 if ( s.isEmpty() ) {
568 s = tr( "Unnamed" ); 747 s = tr( "Unnamed" );
748 currentFileName=s;
749 }
569 setCaption( s + " - " + tr("Text Editor") ); 750 setCaption( s + " - " + tr("Text Editor") );
@@ -576,3 +757,3 @@ void TextEdit::setDocument(const QString& fileref)
576 openFile(DocLnk(fileref)); 757 openFile(DocLnk(fileref));
577 showEditTools(); 758// showEditTools();
578} 759}
@@ -581,5 +762,7 @@ void TextEdit::closeEvent( QCloseEvent *e )
581{ 762{
582 if ( editorStack->visibleWidget() == editor && !bFromDocView ) { 763 if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
583 e->ignore(); 764 e->ignore();
584 fileRevert(); 765 repaint();
766// fileRevert();
767
585 } else { 768 } else {
@@ -592,3 +775,29 @@ void TextEdit::accept()
592{ 775{
593 fileOpen(); 776 close();
777// fileOpen(); //godamn thats obnoxious! lemme out!!!
778}
779
780void TextEdit::changeFont() {
781 FontDatabase fdb;
782 QFont defaultFont=editor->font();
783 QFontInfo fontInfo(defaultFont);
784 Config cfg("TextEdit");
785 cfg.setGroup("Font");
786 QString family = cfg.readEntry("Family", fontInfo.family());
787 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
788 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
789 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
790
791 defaultFont = fdb.font(family,style,i_size,charSet);
792
793 FontDialog *fontDlg;
794 fontDlg=new FontDialog(this,"FontDialog",TRUE);
795
796 fontDlg->exec();
797
798 QFont myFont=fontDlg->selectedFont;
799 editor->setFont( myFont);
800 delete fontDlg;
801
594 } 802 }
803