summaryrefslogtreecommitdiff
path: root/core/apps/textedit/textedit.cpp
Side-by-side diff
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 @@
**********************************************************************/
+// changes added by L. J. Potter Sun 02-17-2002 21:31:31
#include "textedit.h"
+#include "fileBrowser.h"
+#include "fileSaver.h"
+#include "fontDialog.h"
+
+#include <qpe/fontdatabase.h>
#include <qpe/global.h>
@@ -32,2 +38,3 @@
+#include <qstringlist.h>
#include <qaction.h>
@@ -44,2 +51,99 @@
#include <stdlib.h> //getenv
+/* XPM */
+static char * filesave_xpm[] = {
+"16 16 78 1",
+" c None",
+". c #343434",
+"+ c #A0A0A0",
+"@ c #565656",
+"# c #9E9E9E",
+"$ c #525252",
+"% c #929292",
+"& c #676767",
+"* c #848484",
+"= c #666666",
+"- c #D8D8D8",
+"; c #FFFFFF",
+"> c #DBDBDB",
+", c #636363",
+"' c #989898",
+") c #2D2D2D",
+"! c #909090",
+"~ c #AEAEAE",
+"{ c #EAEAEA",
+"] c #575757",
+"^ c #585858",
+"/ c #8A8A8A",
+"( c #828282",
+"_ c #6F6F6F",
+": c #C9C9C9",
+"< c #050505",
+"[ c #292929",
+"} c #777777",
+"| c #616161",
+"1 c #3A3A3A",
+"2 c #BEBEBE",
+"3 c #2C2C2C",
+"4 c #7C7C7C",
+"5 c #F6F6F6",
+"6 c #FCFCFC",
+"7 c #6B6B6B",
+"8 c #959595",
+"9 c #4F4F4F",
+"0 c #808080",
+"a c #767676",
+"b c #818181",
+"c c #B8B8B8",
+"d c #FBFBFB",
+"e c #F9F9F9",
+"f c #CCCCCC",
+"g c #030303",
+"h c #737373",
+"i c #7A7A7A",
+"j c #7E7E7E",
+"k c #6A6A6A",
+"l c #FAFAFA",
+"m c #505050",
+"n c #9D9D9D",
+"o c #333333",
+"p c #7B7B7B",
+"q c #787878",
+"r c #696969",
+"s c #494949",
+"t c #555555",
+"u c #949494",
+"v c #E6E6E6",
+"w c #424242",
+"x c #515151",
+"y c #535353",
+"z c #3E3E3E",
+"A c #D4D4D4",
+"B c #0C0C0C",
+"C c #353535",
+"D c #474747",
+"E c #ECECEC",
+"F c #919191",
+"G c #7D7D7D",
+"H c #000000",
+"I c #404040",
+"J c #858585",
+"K c #323232",
+"L c #D0D0D0",
+"M c #1C1C1C",
+" ...+ ",
+" @#$%&..+ ",
+" .*=-;;>,..+ ",
+" ')!~;;;;;;{]..",
+" ^/(-;;;;;;;_:<",
+" [}|;;;;;;;{12$",
+" #34-55;;;;678$+",
+" 90ab=c;dd;e1fg ",
+" [ahij((kbl0mn$ ",
+" op^q^^7r&]s/$+ ",
+"@btu;vbwxy]zAB ",
+"CzDEvEv;;DssF$ ",
+"G.H{E{E{IxsJ$+ ",
+" +...vEKxzLM ",
+" +...z]n$ ",
+" +... "};
@@ -53,3 +157,7 @@ public:
QpeEditor( QWidget *parent, const char * name = 0 )
- : QMultiLineEdit( parent, name ) {}
+ : QMultiLineEdit( parent, name )
+ {
+ clearTableFlags();
+ setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
+ }
@@ -131,4 +239,2 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
- QString lang = getenv( "LANG" );
-
setToolBarsMovable( FALSE );
@@ -156,2 +262,7 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
+// a->addTo( bar );
+ a->addTo( file );
+
+ a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) );
a->addTo( bar );
@@ -159,2 +270,9 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
+//
+ a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
+// a->addTo( bar );
+ file->insertSeparator();
+ a->addTo( file );
+
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 )
bool defb, defi, wrap;
- {
+
Config cfg("TextEdit");
@@ -189,3 +307,2 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
wrap = cfg.readBoolEntry("Wrap",TRUE);
- }
@@ -223,2 +340,5 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
+ font->insertSeparator();
+ font->insertItem("Font", this, SLOT(changeFont()) );
+
mb->insertItem( tr( "File" ), file );
@@ -237,2 +357,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
+
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 )
- fileSelector = new FileSelector( "text/*", editorStack, "fileselector" ,
- TRUE, FALSE );
- fileSelector->setCategoriesVisible(TRUE);
+ fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy
connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
@@ -259,5 +378,6 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
- fileOpen();
+// fileOpen();
editor = new QpeEditor( editorStack );
+ editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
editorStack->addWidget( editor, get_unique_id() );
@@ -266,4 +386,28 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
- setFontSize(defsize,TRUE);
+// setFontSize(defsize,TRUE);
+ FontDatabase fdb;
+ QFont defaultFont=editor->font();
+ QFontInfo fontInfo(defaultFont);
+
+ cfg.setGroup("Font");
+ QString family = cfg.readEntry("Family", fontInfo.family());
+ QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
+ int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
+ QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
+
+ defaultFont = fdb.font(family,style,i_size,charSet);
+ editor->setFont( defaultFont);
+
wa->setOn(wrap);
+ updateCaption();
+ if( qApp->argc() > 1 ) {
+ for (int i=1;i< qApp->argc();i++) {
+ QString tmp;
+ currentFileName = tmp.sprintf("%s",qApp->argv()[i]);
+ qDebug(currentFileName);
+ setDocument( currentFileName );
+ }
+ }
+ else
+ fileNew();
}
@@ -336,3 +480,5 @@ void TextEdit::setWordWrap(bool y)
{
+ bool state = editor->edited();
editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
+ editor->setEdited( state );
}
@@ -347,17 +493,17 @@ void TextEdit::fileOpen()
{
- if ( !save() ) {
- if ( QMessageBox::critical( this, tr( "Out of space" ),
- tr( "Text Editor was unable to\n"
- "save your changes.\n"
- "Free some space and try again.\n"
- "\nContinue anyway?" ),
- QMessageBox::Yes|QMessageBox::Escape,
- QMessageBox::No|QMessageBox::Default )
- != QMessageBox::Yes )
- return;
- else {
- delete doc;
- doc = 0;
- }
- }
+// if ( !save() ) {
+// if ( QMessageBox::critical( this, tr( "Out of space" ),
+// tr( "Text Editor was unable to\n"
+// "save your changes.\n"
+// "Free some space and try again.\n"
+// "\nContinue anyway?" ),
+// QMessageBox::Yes|QMessageBox::Escape,
+// QMessageBox::No|QMessageBox::Default )
+// != QMessageBox::Yes )
+// return;
+// else {
+// delete doc;
+// doc = 0;
+// }
+// }
menu->hide();
@@ -371,2 +517,25 @@ void TextEdit::fileOpen()
+void TextEdit::newFileOpen()
+{
+ fileBrowser *browseForFiles;
+ browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*");
+ browseForFiles->exec();
+ QString selFile= browseForFiles->selectedFileName;
+ QStringList fileList=browseForFiles->fileList;
+ qDebug(selFile);
+ QStringList::ConstIterator f;
+ QString fileTemp;
+ for ( f = fileList.begin(); f != fileList.end(); f++ ) {
+ fileTemp = *f;
+ fileTemp.right( fileTemp.length()-5);
+ QString fileName = fileTemp;
+ if( fileName != "Unnamed" || fileName != "Empty Text" ) {
+ currentFileName = fileName;
+ qDebug("please open "+currentFileName);
+ openFile(fileName );
+ }
+ }
+ delete browseForFiles;
+
+}
@@ -381,3 +550,2 @@ void TextEdit::slotFind()
-
connect( editor, SIGNAL(notFound()),
@@ -474,3 +642,3 @@ void TextEdit::openFile( const DocLnk &f )
{
- clear();
+// clear();
FileManager fm;
@@ -479,5 +647,7 @@ void TextEdit::openFile( const DocLnk &f )
// ####### could be a new file
- //qDebug( "Cannot open file" );
+ qDebug( "Cannot open file" );
+
//return;
}
+
fileNew();
@@ -493,4 +663,5 @@ void TextEdit::showEditTools()
{
- if ( !doc )
- close();
+// if ( !doc )
+// close();
+// clear();
fileSelector->hide();
@@ -501,2 +672,4 @@ void TextEdit::showEditTools()
updateCaption();
+ editorStack->raiseWidget( editor );
+ setWState (WState_Reserved1 );
}
@@ -506,3 +679,3 @@ bool TextEdit::save()
// case of nothing to save...
- if ( !doc )
+ if ( !doc || !bFromDocView)
return true;
@@ -516,2 +689,4 @@ bool TextEdit::save()
+ if(currentFileName.isEmpty() || currentFileName == "Unnamed") {
+
if ( doc->name().isEmpty() ) {
@@ -532,7 +707,3 @@ bool TextEdit::save()
doc->setName(docname);
-
- // append .txt to the file name
- if ( doc->file().find(".txt") == -1 ) {
- QString file = doc->file() + ".txt";
- doc->setFile( file );
+ currentFileName=docname;
}
@@ -540,2 +711,10 @@ bool TextEdit::save()
+ fileSaver *fileSaveDlg;
+ fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName);
+ fileSaveDlg->exec();
+ QString fileNm=fileSaveDlg->selectedFileName;
+ qDebug("save filename "+fileNm);
+ doc->setName(fileNm);
+ updateCaption();
+ delete fileSaveDlg;
@@ -566,4 +745,6 @@ void TextEdit::updateCaption( const QString &name )
s = doc->name();
- if ( s.isEmpty() )
+ if ( s.isEmpty() ) {
s = tr( "Unnamed" );
+ currentFileName=s;
+ }
setCaption( s + " - " + tr("Text Editor") );
@@ -576,3 +757,3 @@ void TextEdit::setDocument(const QString& fileref)
openFile(DocLnk(fileref));
- showEditTools();
+// showEditTools();
}
@@ -581,5 +762,7 @@ void TextEdit::closeEvent( QCloseEvent *e )
{
- if ( editorStack->visibleWidget() == editor && !bFromDocView ) {
+ if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
e->ignore();
- fileRevert();
+ repaint();
+// fileRevert();
+
} else {
@@ -592,3 +775,29 @@ void TextEdit::accept()
{
- fileOpen();
+ close();
+// fileOpen(); //godamn thats obnoxious! lemme out!!!
+}
+
+void TextEdit::changeFont() {
+ FontDatabase fdb;
+ QFont defaultFont=editor->font();
+ QFontInfo fontInfo(defaultFont);
+ Config cfg("TextEdit");
+ cfg.setGroup("Font");
+ QString family = cfg.readEntry("Family", fontInfo.family());
+ QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
+ int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
+ QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
+
+ defaultFont = fdb.font(family,style,i_size,charSet);
+
+ FontDialog *fontDlg;
+ fontDlg=new FontDialog(this,"FontDialog",TRUE);
+
+ fontDlg->exec();
+
+ QFont myFont=fontDlg->selectedFont;
+ editor->setFont( myFont);
+ delete fontDlg;
+
}
+