summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp14
1 files changed, 3 insertions, 11 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 834971a..8004771 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -223,97 +223,96 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive,
static int u_id = 1;
static int get_unique_id()
{
return u_id++;
}
static const int nfontsizes = 6;
static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
: QMainWindow( parent, name, f ), bFromDocView( FALSE )
{
doc = 0;
setToolBarsMovable( FALSE );
setIcon( Resource::loadPixmap( "TextEditor" ) );
QPEToolBar *bar = new QPEToolBar( this );
bar->setHorizontalStretchable( TRUE );
menu = bar;
QPEMenuBar *mb = new QPEMenuBar( bar );
QPopupMenu *file = new QPopupMenu( this );
QPopupMenu *edit = new QPopupMenu( this );
QPopupMenu *font = new QPopupMenu( this );
bar = new QPEToolBar( this );
editBar = bar;
QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
a->addTo( bar );
a->addTo( file );
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( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
a->addTo( file );
a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
a->addTo( editBar );
a->addTo( edit );
a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
a->addTo( editBar );
a->addTo( edit );
a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
a->addTo( editBar );
a->addTo( edit );
a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
edit->insertSeparator();
a->addTo( bar );
a->addTo( edit );
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);
zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
zin->addTo( font );
zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
zout->addTo( font );
@@ -359,105 +358,97 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
this, SLOT( search() ) );
a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
a->addTo( searchBar );
a->addTo( edit );
a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
a->addTo( searchBar );
searchBar->hide();
editorStack = new QWidgetStack( this );
setCentralWidget( editorStack );
searchVisible = FALSE;
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();
editor = new QpeEditor( editorStack );
editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
editorStack->addWidget( editor, get_unique_id() );
resize( 200, 300 );
// 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();
}
TextEdit::~TextEdit()
{
saveAs();
Config cfg("TextEdit");
cfg.setGroup("View");
QFont f = editor->font();
cfg.writeEntry("FontSize",f.pointSize());
cfg.writeEntry("Bold",f.bold());
cfg.writeEntry("Italic",f.italic());
cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
}
void TextEdit::zoomIn()
{
setFontSize(editor->font().pointSize()+1,FALSE);
}
void TextEdit::zoomOut()
{
setFontSize(editor->font().pointSize()-1,TRUE);
}
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;
}
}
}
QFont f = editor->font();
f.setPointSize(s);
editor->setFont(f);
@@ -581,97 +572,97 @@ void TextEdit::editCut()
void TextEdit::editCopy()
{
#ifndef QT_NO_CLIPBOARD
editor->copy();
#endif
}
void TextEdit::editPaste()
{
#ifndef QT_NO_CLIPBOARD
editor->paste();
#endif
}
void TextEdit::editFind()
{
searchBar->show();
searchVisible = TRUE;
searchEdit->setFocus();
}
void TextEdit::findNext()
{
editor->find( searchEdit->text(), FALSE, FALSE );
}
void TextEdit::findClose()
{
searchVisible = FALSE;
searchBar->hide();
}
void TextEdit::search()
{
editor->find( searchEdit->text(), FALSE, FALSE );
}
void TextEdit::newFile( const DocLnk &f )
{
DocLnk nf = f;
nf.setType("text/plain");
clear();
editorStack->raiseWidget( editor );
setWState (WState_Reserved1 );
editor->setFocus();
doc = new DocLnk(nf);
-// updateCaption();
+ updateCaption(currentFileName);
}
void TextEdit::openFile( const QString &f )
{
bFromDocView = TRUE;
DocLnk nf;
nf.setType("text/plain");
nf.setFile(f);
openFile(nf);
showEditTools();
// Show filename in caption
QString name = f;
int sep = name.findRev( '/' );
if ( sep > 0 )
name = name.mid( sep+1 );
updateCaption( name );
}
void TextEdit::openFile( const DocLnk &f )
{
// clear();
bFromDocView = TRUE;
FileManager fm;
QString txt;
if ( !fm.loadFile( f, txt ) ) {
// ####### could be a new file
qDebug( "Cannot open file" );
//return;
}
fileNew();
if ( doc )
delete doc;
doc = new DocLnk(f);
editor->setText(txt);
editor->setEdited(FALSE);
updateCaption(currentFileName);
}
void TextEdit::showEditTools()
{
// if ( !doc )
// close();
// clear();
fileSelector->hide();
menu->show();
editBar->show();
@@ -727,96 +718,97 @@ bool TextEdit::saveAs()
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);
if( fileSaveDlg->exec() != 0 ) {
QString fileNm=fileSaveDlg->selectedFileName;
qDebug("save filename "+fileNm);
doc->setName(fileNm);
updateCaption(fileNm);
}
delete fileSaveDlg;
FileManager fm;
if ( !fm.saveFile( *doc, rt ) ) {
return false;
}
delete doc;
doc = 0;
editor->setEdited( false );
return true;
}
void TextEdit::clear()
{
delete doc;
doc = 0;
editor->clear();
}
void TextEdit::updateCaption( const QString &name )
{
if ( !doc )
setCaption( tr("Text Editor") );
else {
QString s = name;
if ( s.isNull() )
s = doc->name();
if ( s.isEmpty() ) {
s = tr( "Unnamed" );
currentFileName=s;
}
+
setCaption( s + " - " + tr("Text Editor") );
}
}
void TextEdit::setDocument(const QString& fileref)
{
bFromDocView = TRUE;
openFile(DocLnk(fileref));
// showEditTools();
}
void TextEdit::closeEvent( QCloseEvent *e )
{
if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
e->ignore();
repaint();
// fileRevert();
} else {
bFromDocView = FALSE;
e->accept();
}
}
void TextEdit::accept()
{
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();