summaryrefslogtreecommitdiff
path: root/core/apps/textedit/textedit.cpp
Side-by-side diff
Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp481
1 files changed, 345 insertions, 136 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
@@ -18,7 +18,13 @@
**
**********************************************************************/
+// 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>
#include <qpe/fileselector.h>
@@ -31,4 +37,5 @@
//#include <qpe/finddialog.h>
+#include <qstringlist.h>
#include <qaction.h>
#include <qcolordialog.h>
@@ -43,4 +50,101 @@
#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$ ",
+" +... "};
@@ -52,5 +156,9 @@ class QpeEditor : public QMultiLineEdit
public:
QpeEditor( QWidget *parent, const char * name = 0 )
- : QMultiLineEdit( parent, name ) {}
+ : QMultiLineEdit( parent, name )
+ {
+ clearTableFlags();
+ setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
+ }
//public slots:
@@ -64,41 +172,41 @@ signals:
private:
-
+
};
void QpeEditor::find ( const QString &txt, bool caseSensitive,
- bool backwards )
+ bool backwards )
{
static bool wrap = FALSE;
int line, col;
if ( wrap ) {
- if ( !backwards )
- line = col = 0;
- wrap = FALSE;
- // emit searchWrapped();
+ if ( !backwards )
+ line = col = 0;
+ wrap = FALSE;
+ // emit searchWrapped();
} else {
- getCursorPosition( &line, &col );
+ getCursorPosition( &line, &col );
}
- //ignore backwards for now....
+ //ignore backwards for now....
if ( !backwards ) {
- for ( ; ; ) {
- if ( line >= numLines() ) {
- wrap = TRUE;
- //emit notFound();
- break;
- }
- int findCol = getString( line )->find( txt, col, caseSensitive );
- if ( findCol >= 0 ) {
- setCursorPosition( line, findCol, FALSE );
- col = findCol + txt.length();
- setCursorPosition( line, col, TRUE );
-
- //found = TRUE;
- break;
- }
- line++;
- col = 0;
- }
+ for ( ; ; ) {
+ if ( line >= numLines() ) {
+ wrap = TRUE;
+ //emit notFound();
+ break;
+ }
+ int findCol = getString( line )->find( txt, col, caseSensitive );
+ if ( findCol >= 0 ) {
+ setCursorPosition( line, findCol, FALSE );
+ col = findCol + txt.length();
+ setCursorPosition( line, col, TRUE );
+
+ //found = TRUE;
+ break;
+ }
+ line++;
+ col = 0;
+ }
}
@@ -130,6 +238,4 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
doc = 0;
- QString lang = getenv( "LANG" );
-
setToolBarsMovable( FALSE );
@@ -155,7 +261,19 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
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 );
a->addTo( file );
+//
+ 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 );
connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
@@ -181,12 +299,11 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
int defsize;
bool defb, defi, wrap;
- {
- Config cfg("TextEdit");
- cfg.setGroup("View");
- defsize = cfg.readNumEntry("FontSize",10);
- defb = cfg.readBoolEntry("Bold",FALSE);
- defi = cfg.readBoolEntry("Italic",FALSE);
- wrap = cfg.readBoolEntry("Wrap",TRUE);
- }
+
+ Config cfg("TextEdit");
+ cfg.setGroup("View");
+ defsize = cfg.readNumEntry("FontSize",10);
+ defb = cfg.readBoolEntry("Bold",FALSE);
+ defi = cfg.readBoolEntry("Italic",FALSE);
+ wrap = cfg.readBoolEntry("Wrap",TRUE);
zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
@@ -200,5 +317,5 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
font->insertSeparator();
-#if 0
+#if 0
QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
@@ -213,5 +330,5 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
ba->setOn(defb);
ia->setOn(defi);
-
+
font->insertSeparator();
#endif
@@ -222,4 +339,7 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
wa->addTo( font );
+ font->insertSeparator();
+ font->insertItem("Font", this, SLOT(changeFont()) );
+
mb->insertItem( tr( "File" ), file );
mb->insertItem( tr( "Edit" ), edit );
@@ -234,5 +354,6 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
searchBar->setStretchableWidget( searchEdit );
connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
- this, SLOT( search() ) );
+ this, SLOT( search() ) );
+
a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
@@ -246,5 +367,5 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
searchBar->hide();
-
+
editorStack = new QWidgetStack( this );
setCentralWidget( editorStack );
@@ -252,19 +373,42 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
searchVisible = FALSE;
- 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() ) );
connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
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() );
resize( 200, 300 );
- 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();
}
@@ -297,16 +441,16 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up)
int s=10;
for (int i=0; i<nfontsizes; i++) {
- if ( fontsize[i] == sz ) {
- s = sz;
- break;
- } else if ( round_down_not_up ) {
- if ( fontsize[i] < sz )
- s = fontsize[i];
- } else {
- if ( fontsize[i] > sz ) {
- s = fontsize[i];
- break;
- }
- }
+ if ( fontsize[i] == sz ) {
+ s = sz;
+ break;
+ } else if ( round_down_not_up ) {
+ if ( fontsize[i] < sz )
+ s = fontsize[i];
+ } else {
+ if ( fontsize[i] > sz ) {
+ s = fontsize[i];
+ break;
+ }
+ }
}
@@ -335,5 +479,7 @@ void TextEdit::setItalic(bool y)
void TextEdit::setWordWrap(bool y)
{
+ bool state = editor->edited();
editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
+ editor->setEdited( state );
}
@@ -346,19 +492,19 @@ void TextEdit::fileNew()
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();
editBar->hide();
@@ -370,4 +516,27 @@ 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;
+
+}
#if 0
@@ -375,14 +544,13 @@ void TextEdit::slotFind()
{
FindDialog frmFind( "Text Editor", this );
- connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
- editor, SLOT(slotDoFind( const QString&,bool,bool)));
-
- //case sensitive, backwards, [category]
+ connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
+ editor, SLOT(slotDoFind( const QString&,bool,bool)));
+ //case sensitive, backwards, [category]
- connect( editor, SIGNAL(notFound()),
- &frmFind, SLOT(slotNotFound()) );
- connect( editor, SIGNAL(searchWrapped()),
- &frmFind, SLOT(slotWrapAround()) );
+ connect( editor, SIGNAL(notFound()),
+ &frmFind, SLOT(slotNotFound()) );
+ connect( editor, SIGNAL(searchWrapped()),
+ &frmFind, SLOT(slotWrapAround()) );
frmFind.exec();
@@ -467,5 +635,5 @@ void TextEdit::openFile( const QString &f )
int sep = name.findRev( '/' );
if ( sep > 0 )
- name = name.mid( sep+1 );
+ name = name.mid( sep+1 );
updateCaption( name );
}
@@ -473,15 +641,17 @@ void TextEdit::openFile( const QString &f )
void TextEdit::openFile( const DocLnk &f )
{
- clear();
+// clear();
FileManager fm;
QString txt;
if ( !fm.loadFile( f, txt ) ) {
- // ####### could be a new file
- //qDebug( "Cannot open file" );
- //return;
+ // ####### could be a new file
+ qDebug( "Cannot open file" );
+
+ //return;
}
+
fileNew();
if ( doc )
- delete doc;
+ delete doc;
doc = new DocLnk(f);
editor->setText(txt);
@@ -492,55 +662,64 @@ void TextEdit::openFile( const DocLnk &f )
void TextEdit::showEditTools()
{
- if ( !doc )
- close();
+// if ( !doc )
+// close();
+// clear();
fileSelector->hide();
menu->show();
editBar->show();
if ( searchVisible )
- searchBar->show();
+ searchBar->show();
updateCaption();
+ editorStack->raiseWidget( editor );
+ setWState (WState_Reserved1 );
}
bool TextEdit::save()
{
- // case of nothing to save...
- if ( !doc )
- return true;
+ // case of nothing to save...
+ if ( !doc || !bFromDocView)
+ return true;
if ( !editor->edited() ) {
- delete doc;
- doc = 0;
- return true;
+ delete doc;
+ doc = 0;
+ return true;
}
QString rt = editor->text();
- if ( doc->name().isEmpty() ) {
- QString pt = rt.simplifyWhiteSpace();
- int i = pt.find( ' ' );
- QString docname = pt;
- if ( i > 0 )
- docname = pt.left( i );
- // remove "." at the beginning
- while( docname.startsWith( "." ) )
- docname = docname.mid( 1 );
- docname.replace( QRegExp("/"), "_" );
- // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
- if ( docname.length() > 40 )
- docname = docname.left(40);
- if ( docname.isEmpty() )
- docname = "Empty Text";
- doc->setName(docname);
-
- // append .txt to the file name
- if ( doc->file().find(".txt") == -1 ) {
- QString file = doc->file() + ".txt";
- doc->setFile( file );
- }
+ if(currentFileName.isEmpty() || currentFileName == "Unnamed") {
+
+ if ( doc->name().isEmpty() ) {
+ QString pt = rt.simplifyWhiteSpace();
+ int i = pt.find( ' ' );
+ QString docname = pt;
+ if ( i > 0 )
+ docname = pt.left( i );
+ // remove "." at the beginning
+ while( docname.startsWith( "." ) )
+ docname = docname.mid( 1 );
+ docname.replace( QRegExp("/"), "_" );
+ // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
+ if ( docname.length() > 40 )
+ docname = docname.left(40);
+ if ( docname.isEmpty() )
+ docname = "Empty Text";
+ doc->setName(docname);
+ currentFileName=docname;
+ }
}
-
+ 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;
+
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
- return false;
+ return false;
}
delete doc;
@@ -560,12 +739,14 @@ void TextEdit::updateCaption( const QString &name )
{
if ( !doc )
- setCaption( tr("Text Editor") );
+ setCaption( tr("Text Editor") );
else {
- QString s = name;
- if ( s.isNull() )
- s = doc->name();
- if ( s.isEmpty() )
- s = tr( "Unnamed" );
- setCaption( s + " - " + tr("Text Editor") );
+ QString s = name;
+ if ( s.isNull() )
+ s = doc->name();
+ if ( s.isEmpty() ) {
+ s = tr( "Unnamed" );
+ currentFileName=s;
+ }
+ setCaption( s + " - " + tr("Text Editor") );
}
}
@@ -575,20 +756,48 @@ void TextEdit::setDocument(const QString& fileref)
bFromDocView = TRUE;
openFile(DocLnk(fileref));
- showEditTools();
+// showEditTools();
}
void TextEdit::closeEvent( QCloseEvent *e )
{
- if ( editorStack->visibleWidget() == editor && !bFromDocView ) {
- e->ignore();
- fileRevert();
+ if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
+ e->ignore();
+ repaint();
+// fileRevert();
+
} else {
- bFromDocView = FALSE;
- e->accept();
+ bFromDocView = FALSE;
+ e->accept();
}
}
-
+
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;
+
+}
+