author | llornkcor <llornkcor> | 2002-02-18 14:08:55 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-18 14:08:55 (UTC) |
commit | 9741205aa0b0892b870d2b7df7c5dd7e25b0bb18 (patch) (side-by-side diff) | |
tree | 7f2f3d44ff3215984bd8b487b206d3d958a498da | |
parent | 0640b30f13beb9d6480d8042ec5397a68e6247fc (diff) | |
download | opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.zip opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.tar.gz opie-9741205aa0b0892b870d2b7df7c5dd7e25b0bb18.tar.bz2 |
added fontDialog, fileBrowserDialog, and fileSave dialog, so we can edit anyfile, save anywhere,
using a user selected name.
Changed what is seen when it opens. It now opens with the texteditor opened to a new
file, instead of the file selector, unless one is specified from commandline, or setDocument message.
FileSelector is still available, but from a menu item.
-rw-r--r-- | core/apps/textedit/Makefile.in | 8 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 160 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.h | 67 | ||||
-rw-r--r-- | core/apps/textedit/fileSaver.cpp | 164 | ||||
-rw-r--r-- | core/apps/textedit/fileSaver.h | 71 | ||||
-rw-r--r-- | core/apps/textedit/fontDialog.cpp | 236 | ||||
-rw-r--r-- | core/apps/textedit/fontDialog.h | 63 | ||||
-rw-r--r-- | core/apps/textedit/inserttable.ui | 103 | ||||
-rw-r--r-- | core/apps/textedit/qtextedit.h | 282 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 481 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 7 | ||||
-rw-r--r-- | core/apps/textedit/textedit.pro | 14 |
12 files changed, 1125 insertions, 531 deletions
diff --git a/core/apps/textedit/Makefile.in b/core/apps/textedit/Makefile.in index 997f2a4..bef671c 100644 --- a/core/apps/textedit/Makefile.in +++ b/core/apps/textedit/Makefile.in @@ -80,46 +80,52 @@ listpromodules: listallmodules: @echo listaddonpromodules: @echo listaddonentmodules: @echo REQUIRES= ####### Sub-libraries ###### Combined headers ####### Compile main.o: main.cpp \ textedit.h \ $(OPIEDIR)/include/qpe/filemanager.h \ - $(OPIEDIR)/include/qpe/qpeapplication.h + $(OPIEDIR)/include/qpe/qpeapplication.h \ + $(OPIEDIR)/include/qpedecoration_qws.h \ + $(OPIEDIR)/include/timestring.h textedit.o: textedit.cpp \ textedit.h \ $(OPIEDIR)/include/qpe/filemanager.h \ $(OPIEDIR)/include/qpe/global.h \ $(OPIEDIR)/include/qpe/fileselector.h \ + $(OPIEDIR)/include/filemanager.h \ + $(OPIEDIR)/include/applnk.h \ $(OPIEDIR)/include/qpe/applnk.h \ $(OPIEDIR)/include/qpe/resource.h \ $(OPIEDIR)/include/qpe/config.h \ $(OPIEDIR)/include/qpe/qpeapplication.h \ + $(OPIEDIR)/include/qpedecoration_qws.h \ + $(OPIEDIR)/include/timestring.h \ $(OPIEDIR)/include/qpe/qpemenubar.h \ $(OPIEDIR)/include/qpe/qpetoolbar.h moc_textedit.o: moc_textedit.cpp \ textedit.h \ $(OPIEDIR)/include/qpe/filemanager.h moc_textedit.cpp: textedit.h $(MOC) textedit.h -o moc_textedit.cpp diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp new file mode 100644 index 0000000..82ccf2c --- a/dev/null +++ b/core/apps/textedit/fileBrowser.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** copyright 2001 ljp ljp@llornkcor.com +** Created: Fri Dec 14 08:16:46 2001 +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ +#include "fileBrowser.h" +#include <qpe/config.h> + +#include <qlistview.h> +#include <qpushbutton.h> +#include <qfile.h> +#include <qmessagebox.h> +#include <unistd.h> + +fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) + : QDialog( parent, name, modal, fl ) +{ + if ( !name ) + setName( "fileBrowser" ); + resize( 236, 280 ); + setCaption(tr( "Browse for file" ) ); + filterStr=filter; + dirLabel = new QLabel(this, "DirLabel"); + dirLabel->setText(currentDir.canonicalPath()); + dirLabel->setGeometry(10,4,230,30); + ListView = new QListView( this, "ListView" ); + ListView->addColumn( tr( "Name" ) ); + ListView->setColumnWidth(0,140); + ListView->setSorting( 2, FALSE); + ListView->addColumn( tr( "Size" ) ); + ListView->setColumnWidth(1,59); +// ListView->addColumn( tr( "" ) ); +// ListView->setColumnWidth(1,59); +// ListView->setMultiSelection(true); +// ListView->setSelectionMode(QListView::Extended); + + ListView->setAllColumnsShowFocus( TRUE ); + ListView->setGeometry( QRect( 10, 35, 220, 240 ) ); + + // signals and slots connections + connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); + connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); + currentDir.setPath(QDir::currentDirPath()); + populateList(); +} + +fileBrowser::~fileBrowser() +{ +} + + +void fileBrowser::populateList() +{ + ListView->clear(); +//qDebug(currentDir.canonicalPath()); + currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); + currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); + currentDir.setMatchAllDirs(TRUE); + + currentDir.setNameFilter(filterStr); +// currentDir.setNameFilter("*.txt;*.etx"); + QString fileL, fileS; + const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/); + QFileInfoListIterator it(*list); + QFileInfo *fi; + while ( (fi=it.current()) ) { + + if (fi->isSymLink() ){ + QString symLink=fi->readLink(); +// qDebug("Symlink detected "+symLink); + QFileInfo sym( symLink); + fileS.sprintf( "%10li", sym.size() ); + fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); + + } else { +// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); + fileS.sprintf( "%10li", fi->size() ); + fileL.sprintf( "%s",fi->fileName().data() ); + if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { + fileL+="/"; +// qDebug(currentDir.canonicalPath()+fileL); + } + } + item= new QListViewItem( ListView,fileL,fileS ); + ++it; + } + ListView->setSorting( 2, FALSE); + dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); +} + +void fileBrowser::upDir() +{ +// qDebug(currentDir.canonicalPath()); +} + +void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) +{ +} + +// you may want to switch these 2 functions. I like single clicks +void fileBrowser::listClicked(QListViewItem *selectedItem) +{ + QString strItem=selectedItem->text(0); + QString strSize=selectedItem->text(1); +// qDebug("strItem is "+strItem); + strSize.stripWhiteSpace(); +// qDebug(strSize); + + if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink + // is symlink + QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); +// qDebug("strItem symlink is "+strItem2); + if(QDir(strItem2).exists() ) { + currentDir.cd(strItem2, TRUE); + populateList(); + } + } else { // not a symlink + if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { + if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { + strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); + currentDir.cd(strItem,FALSE); +// qDebug("Path is "+strItem); + populateList(); + } else { + currentDir.cdUp(); + populateList(); + } + if(QDir(strItem).exists()){ + currentDir.cd(strItem, TRUE); + populateList(); + } + } else + if( QFile::exists(strItem ) ) { +// qDebug("We found our files!!"); + OnOK(); + } //end not symlink + chdir(strItem.latin1()); + } +} + +void fileBrowser::OnOK() +{ + QListViewItemIterator it1( ListView); + for ( ; it1.current(); ++it1 ) { + if ( it1.current()->isSelected() ) { + selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); +// qDebug("selected filename is "+selectedFileName); + fileList.append( selectedFileName ); + } + } + accept(); +} diff --git a/core/apps/textedit/fileBrowser.h b/core/apps/textedit/fileBrowser.h new file mode 100644 index 0000000..17ed862 --- a/dev/null +++ b/core/apps/textedit/fileBrowser.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Created: Fri Dec 14 08:16:02 2001 +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +copyright Sun 02-17-2002 22:28:23 L. J. Potter ljp@llornkcor.com +****************************************************************************/ +#ifndef FILEBROWSER_H +#define FILEBROWSER_H + +//#include <qvariant.h> +#include <qdialog.h> +#include <qfile.h> +#include <qdir.h> +#include <qstringlist.h> +#include <qlabel.h> +#include <qstring.h> + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QListView; +class QListViewItem; +class QPushButton; + +class fileBrowser : public QDialog +{ + Q_OBJECT + +public: + void populateList(); + fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); + ~fileBrowser(); + + QPushButton* buttonOk; + QListView* ListView; + QPushButton* buttonCancel; + QLabel *dirLabel; + QString selectedFileName, filterStr; + QDir currentDir; + QFile file; + QStringList fileList; + +QListViewItem * item; +public slots: + +private: + +private slots: + void upDir(); + void listDoubleClicked(QListViewItem *); + void listClicked(QListViewItem *); + void OnOK(); +protected slots: + +protected: + +}; + +#endif // FILEBROWSER_H diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp new file mode 100644 index 0000000..d01daee --- a/dev/null +++ b/core/apps/textedit/fileSaver.cpp @@ -0,0 +1,164 @@ +/**************************************************************************** +** copyright 2001 ljp ljp@llornkcor.com +** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ +#include "fileSaver.h" +#include <qpe/config.h> +#include <qpe/qpeapplication.h> + +#include <qlistview.h> +#include <qpushbutton.h> +#include <qfile.h> +#include <qmessagebox.h> +#include <unistd.h> +#include <qlineedit.h> + +fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) + : QDialog( parent, name, modal, fl ) +{ + if ( !name ) + setName( "fileSaver" ); + resize( 236, 280 ); + setCaption(tr( "Save file" ) ); +// filterStr=currentFileName; + + dirLabel = new QLabel(this, "DirLabel"); + dirLabel->setText(currentDir.canonicalPath()); + dirLabel->setGeometry(10,4,230,30); + + ListView = new QListView( this, "ListView" ); + ListView->addColumn( tr( "Name" ) ); + ListView->setColumnWidth(0,140); + ListView->setSorting( 2, FALSE); + ListView->addColumn( tr( "Size" ) ); + ListView->setColumnWidth(1,59); +// ListView->setMultiSelection(true); +// ListView->setSelectionMode(QListView::Extended); + + ListView->setAllColumnsShowFocus( TRUE ); + ListView->setGeometry( QRect( 10, 35, 220, 160 ) ); + + fileEdit= new QLineEdit(this); + fileEdit->setGeometry( QRect( 10, 230, 200, 25)); + fileEdit->setText(currentFileName); + // signals and slots connections + connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); + connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); + currentDir.setPath(QDir::currentDirPath() ); + populateList(); +} + +fileSaver::~fileSaver() +{ +} + + +void fileSaver::populateList() +{ + ListView->clear(); + currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); + currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); + currentDir.setMatchAllDirs(TRUE); + + currentDir.setNameFilter("*"); + QString fileL, fileS; + const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/); + QFileInfoListIterator it(*list); + QFileInfo *fi; + while ( (fi=it.current()) ) { + + if (fi->isSymLink() ){ + QString symLink=fi->readLink(); +// qDebug("Symlink detected "+symLink); + QFileInfo sym( symLink); + fileS.sprintf( "%10li", sym.size() ); + fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); + + } else { +// // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); + fileS.sprintf( "%10li", fi->size() ); + fileL.sprintf( "%s",fi->fileName().data() ); + if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { + fileL+="/"; +// qDebug(currentDir.canonicalPath()+fileL); + } + } + item= new QListViewItem( ListView,fileL,fileS ); + ++it; + } + ListView->setSorting( 2, FALSE); + dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); + + +} + +void fileSaver::upDir() +{ +// qDebug(currentDir.canonicalPath()); +} + +void fileSaver::listDoubleClicked(QListViewItem *selectedItem) +{ +} + +void fileSaver::listClicked(QListViewItem *selectedItem) +{ + QString strItem=selectedItem->text(0); + QString strSize=selectedItem->text(1); +// qDebug("strItem is "+strItem); + strSize.stripWhiteSpace(); +// qDebug(strSize); + + if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink + QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); +// qDebug("strItem symlink is "+strItem2); + if(QDir(strItem2).exists() ) { + currentDir.cd(strItem2, TRUE); + populateList(); + } + } else { // not a symlink + if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { + if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { + strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); + currentDir.cd(strItem,FALSE); +// qDebug("Path is "+strItem); + populateList(); + } else { + currentDir.cdUp(); + populateList(); + } + if(QDir(strItem).exists()){ + currentDir.cd(strItem, TRUE); + populateList(); + } + } // else +// if( QFile::exists(strItem ) ) { +// qDebug("We found our files!!"); + +// OnOK(); + } //end not symlink + chdir(strItem.latin1()); + + +} + + +void fileSaver::OnOK() +{ +// reject(); +} + +void fileSaver::accept() { + selectedFileName = fileEdit->text(); + selectedFileName = currentDir.canonicalPath()+ selectedFileName; + reject(); +} diff --git a/core/apps/textedit/fileSaver.h b/core/apps/textedit/fileSaver.h new file mode 100644 index 0000000..f496270 --- a/dev/null +++ b/core/apps/textedit/fileSaver.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Created: Fri Dec 14 08:16:02 2001 fileSaver.h +** +copyright Sun 02-17-2002 22:28:48 L. J. Potter ljp@llornkcor.com + +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ +#ifndef FILESAVER_H +#define FILESAVER_H + +//#include <qvariant.h> +#include <qdialog.h> +#include <qfile.h> +#include <qdir.h> +#include <qstringlist.h> +#include <qlabel.h> +#include <qstring.h> + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QListView; +class QListViewItem; +class QPushButton; +class QLineEdit; + +class fileSaver : public QDialog +{ + Q_OBJECT + +public: + void populateList(); + fileSaver( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); + ~fileSaver(); + QLineEdit *fileEdit; + + QPushButton* buttonOk; + QListView* ListView; + QPushButton* buttonCancel; + QLabel *dirLabel; + QString selectedFileName, filterStr; + QDir currentDir; + QFile file; + QStringList fileList; + +QListViewItem * item; +public slots: + +private: + +private slots: + void accept(); + void upDir(); + void listDoubleClicked(QListViewItem *); + void listClicked(QListViewItem *); + void OnOK(); +protected slots: + +protected: + +}; + +#endif // FILESAVER_H diff --git a/core/apps/textedit/fontDialog.cpp b/core/apps/textedit/fontDialog.cpp new file mode 100644 index 0000000..e7bd924 --- a/dev/null +++ b/core/apps/textedit/fontDialog.cpp @@ -0,0 +1,236 @@ +/**************************************************************************** +** Created: Sun Jan 27 11:03:24 2002 fileDialog.cpp +copyright 2002 by L.J. Potter ljp@llornkcor.com + +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ +#include "fontDialog.h" + +#include <qpe/fontdatabase.h> +#include <qpe/config.h> + +#include <qstringlist.h> +#include <qfontinfo.h> +#include <qvaluelist.h> +#include <qpe/qpeapplication.h> + +#include <qgroupbox.h> +#include <qlabel.h> +#include <qlistbox.h> +#include <qmultilineedit.h> +#include <qpushbutton.h> +#include <qlayout.h> +#include <qvariant.h> +#include <qtooltip.h> +#include <qwhatsthis.h> + +FontDialog::FontDialog( QWidget * parent, const char* name , bool modal, WFlags fl ) + :QDialog /*QWidget*/( parent, name , modal, fl ) +{ + if ( !name ) + setName( "FontDialog" ); + setCaption( tr( "Font Dialog" ) ); + FontTextLabel4 = new QLabel( this, "TextLabel4" ); + FontTextLabel4->setGeometry( QRect( 145, 100, 30, 19 /*192, 0, 43, 19*/ ) ); + FontTextLabel4->setText( tr( "Size" ) ); + + FamilyGroup = new QGroupBox( this, "FamilyGroup" ); + FamilyGroup->setGeometry( QRect( 5, 5, 115, 135 /*0, 6, 185, 131 */) ); + FamilyGroup->setTitle( tr( "Font" ) ); + + familyListBox = new QListBox( FamilyGroup, "familyListBox" ); + familyListBox->setGeometry( QRect( 5, 20, 100, 105 /* 6, 18, 170, 105 */) ); + + GroupBox2 = new QGroupBox( this, "GroupBox2" ); + GroupBox2->setGeometry( QRect( 120, 5, 100, 90/* 0, 138, 170, 90*/ ) ); + GroupBox2->setTitle( tr( "Font Style" ) ); + + styleListBox = new QListBox( GroupBox2, "styleListBox" ); + styleListBox->setGeometry( QRect( 5, 20, 90, 60 /*10, 20, 150, 61*/ ) ); + + sizeListBox = new QListBox( this, "sizeListBox" ); + sizeListBox->setGeometry( QRect( 180, 100, 40, 60 /* 192, 24, 40, 108 */) ); + + MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" ); + MultiLineEdit1->setGeometry( QRect( 5, 165, 215, 45 /* 6, 234, 222, 55*/ ) ); + MultiLineEdit1->setText( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ) ); + MultiLineEdit1->setWordWrap(QMultiLineEdit::WidgetWidth); + + connect( familyListBox,SIGNAL( highlighted( const QString &)),SLOT( familyListBoxSlot(const QString &) )); + connect( styleListBox,SIGNAL( highlighted( const QString &)),SLOT( styleListBoxSlot(const QString &) )); + connect( sizeListBox,SIGNAL( highlighted( const QString &)),SLOT( sizeListBoxSlot(const QString &) )); + + populateLists(); +// MultiLineEdit1 +// connect(); + +} + +FontDialog::~FontDialog() +{ +} + +void FontDialog::familyListBoxSlot(const QString & text) +{ + int styleInt=styleListBox->currentItem(); + int sizeInt=sizeListBox->currentItem(); + + styleListBox->clear(); + sizeListBox->clear(); + family= text; +// qDebug(family); + QStringList styles = fdb.styles( family ); // string list of styles of our current font family + styleListBox->insertStringList( styles); + QString dstyle;// = "\t" + style + " ("; + QValueList<int> smoothies = fdb.smoothSizes( family, styleListBox->text(0) ); + for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) { + dstyle = QString::number( *points ); + sizeListBox ->insertItem( dstyle.left( dstyle.length() - 1 )); + } + if(styleInt == -1 || styleInt > styleListBox->count() ) + styleListBox->setCurrentItem(0); + else + styleListBox->setCurrentItem(styleInt); + + if(sizeInt == -1 || sizeInt > sizeListBox->count()) + sizeListBox->setCurrentItem(0); + else + sizeListBox->setCurrentItem(sizeInt); + + changeText(); +} + +void FontDialog::styleListBoxSlot(const QString &text) +{ + changeText(); +} + +void FontDialog::sizeListBoxSlot(const QString & text) +{ + changeText(); +} + +void FontDialog::populateLists() +{ +// QFont defaultFont=MultiLineEdit1->font(); +// QFont defaultFont=Lview->font(); +// QFontInfo fontInfo(defaultFont); + Config config("TextEdit"); + config.setGroup("Font"); + QString familyStr = config.readEntry("Family", "fixed"); + QString styleStr = config.readEntry("Style", "Regular"); + QString sizeStr = config.readEntry("Size", "10"); + QString charSetStr = config.readEntry("CharSet", "iso10646-1" ); + bool ok; + int i_size=sizeStr.toInt(&ok,10); + selectedFont = fdb.font(familyStr,styleStr,i_size,charSetStr); +// defaultFont.setItalic(TRUE); + families = fdb.families(); + for ( QStringList::Iterator f = families.begin(); f != families.end();++f ) { + QString family = *f; +// if(family == defaultFont.family()) +// qDebug(family); + familyListBox->insertItem( family); + + if( familyListBox->text(0) == family) { + QStringList styles = fdb.styles( family ); // string list of styles of our current font family + styleListBox->insertStringList( styles); + for ( QStringList::Iterator s = styles.begin(); s != styles.end();++s ) { // for each font style + style = *s; + QString dstyle;// = "\t" + style + " ("; + if(styleListBox->text(0) == style) { + QValueList<int> smoothies = fdb.smoothSizes( family, style ); + for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) { + dstyle = QString::number( *points ) + " "; + + sizeListBox ->insertItem( dstyle.left( dstyle.length() - 1 )); + } + dstyle = dstyle.left( dstyle.length() - 1 ) + ")"; + } + } // styles + } + } + for(int i=0;i < familyListBox->count();i++) { + if( familyListBox->text(i) == familyStr) + familyListBox->setSelected( i, TRUE); + } + + for(int i=0;i < styleListBox->count();i++) { + if( styleListBox->text(i) == styleStr) + styleListBox->setSelected( i, TRUE); + } + + for(int i=0;i < sizeListBox->count();i++) { + if( sizeListBox->text(i) == sizeStr) + sizeListBox->setSelected( i, TRUE); + } + changeText(); +} + +void FontDialog::clearListBoxes() { + familyListBox->clear(); + sizeListBox->clear(); + styleListBox->clear(); +} + +void FontDialog::changeText() +{ + if( familyListBox->currentItem() == -1) + family= familyListBox->text(0); + else { + family = familyListBox->currentText(); + } +// qDebug("Font family is "+family); + if( styleListBox->currentItem() == -1) + style=styleListBox->text(0); + else { + style = styleListBox->currentText(); + } +// qDebug("font style is "+style); + if( sizeListBox->currentItem() == -1 ) + size= sizeListBox->text(0); + else { + size = sizeListBox->currentText(); + } + +// qDebug("Font size is "+size); + bool ok; + int i_size= size.toInt(&ok,10); + QStringList charSetList= fdb.charSets(family); +// QStringList styles = fdb.styles( family ); // string list of styles of our current font family + QString charSet; + for ( QStringList::Iterator s = charSetList.begin(); s != charSetList.end();++s ) { // for each font style + charSet = *s; +// qDebug(charSet); + } + selectedFont = fdb.font(family,style,i_size,charSet); + QFontInfo fontInfo( selectedFont); +// if(fontInfo.italic() ) qDebug("italic"); + selectedFont.setWeight(fontInfo.weight() ); +// qDebug("Style are "+style+" %d ",fontInfo.weight()); + Config cfg("TextEdit"); + cfg.setGroup("Font"); + cfg.writeEntry("Family",family); + cfg.writeEntry("Style",style); + cfg.writeEntry("Size",size); + cfg.writeEntry("CharSet",charSet); + + if(style.find("Italic",0,TRUE) != -1) { + selectedFont = fdb.font(family,"Regular",i_size,charSet); + selectedFont.setItalic(TRUE); //ya right + cfg.writeEntry("Italic","TRUE"); +// qDebug("Style is "+styleListBox->currentText()); + } else + cfg.writeEntry("Italic","FALSE"); + changedFonts=TRUE; + MultiLineEdit1->setFont( selectedFont); + MultiLineEdit1->update(); +} + diff --git a/core/apps/textedit/fontDialog.h b/core/apps/textedit/fontDialog.h new file mode 100644 index 0000000..ef930df --- a/dev/null +++ b/core/apps/textedit/fontDialog.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** Created: Sun Jan 27 11:02:59 2002 fileDialog.h +copyright 2002 by L.J. Potter ljp@llornkcor.com + +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ +#ifndef FONTDIALOG_H +#define FONTDIALOG_H + +#include <qvariant.h> +#include <qdialog.h> +#include <qpe/fontdatabase.h> +#include <qfont.h> + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QLabel; +class QListBox; +class QListBoxItem; +class QPushButton; +class QGroupBox; +class QMultiLineEdit; + +class FontDialog : public QDialog// QWidget +{ + Q_OBJECT + +public: + FontDialog( QWidget * parent = 0, const char* name = 0 , bool modal=FALSE, WFlags fl = 0 ); + ~FontDialog(); + + QLabel *FontTextLabel4; + QGroupBox *FamilyGroup, *GroupBox2; + QListBox *familyListBox, *styleListBox, *sizeListBox; + QMultiLineEdit *MultiLineEdit1; + QPushButton *PushButtonOk,*PushButtonCancel; + QStringList families; + + FontDatabase fdb; + QString family, style, size; + QFont selectedFont; + bool changedFonts; + void populateLists(); + void clearListBoxes(); + void changeText(); +protected slots: + + void familyListBoxSlot(const QString &); + void styleListBoxSlot(const QString &); + void sizeListBoxSlot(const QString &); + + +}; + +#endif // FONTDIALOG_H diff --git a/core/apps/textedit/inserttable.ui b/core/apps/textedit/inserttable.ui deleted file mode 100644 index 09fe3c3..0000000 --- a/core/apps/textedit/inserttable.ui +++ b/dev/null @@ -1,103 +0,0 @@ -<!DOCTYPE UI><UI> -<class>InsertTable</class><comment>********************************************************************* -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of Qtopia Environment. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -*********************************************************************</comment> -<widget> - <class>QDialog</class> - <property stdset="1"> - <name>name</name> - <cstring>InsertTable</cstring> - </property> - <property stdset="1"> - <name>geometry</name> - <rect> - <x>0</x> - <y>0</y> - <width>165</width> - <height>79</height> - </rect> - </property> - <property stdset="1"> - <name>caption</name> - <string>Insert Table</string> - </property> - <grid> - <property stdset="1"> - <name>margin</name> - <number>11</number> - </property> - <property stdset="1"> - <name>spacing</name> - <number>6</number> - </property> - <widget row="0" column="0" > - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel1</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Rows:</string> - </property> - </widget> - <widget row="0" column="1" > - <class>QSpinBox</class> - <property stdset="1"> - <name>name</name> - <cstring>spinRows</cstring> - </property> - <property stdset="1"> - <name>minValue</name> - <number>1</number> - </property> - <property stdset="1"> - <name>value</name> - <number>1</number> - </property> - </widget> - <widget row="1" column="1" > - <class>QSpinBox</class> - <property stdset="1"> - <name>name</name> - <cstring>spinColumns</cstring> - </property> - <property stdset="1"> - <name>minValue</name> - <number>1</number> - </property> - <property stdset="1"> - <name>value</name> - <number>1</number> - </property> - </widget> - <widget row="1" column="0" > - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel1_2</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Columns:</string> - </property> - </widget> - </grid> -</widget> -</UI> diff --git a/core/apps/textedit/qtextedit.h b/core/apps/textedit/qtextedit.h deleted file mode 100644 index b29a728..0000000 --- a/core/apps/textedit/qtextedit.h +++ b/dev/null @@ -1,282 +0,0 @@ -/********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. -** -** This file is part of Qtopia Environment. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.trolltech.com/gpl/ for GPL licensing information. -** -** Contact info@trolltech.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef QTEXTEDIT_H -#define QTEXTEDIT_H - -#include <qscrollview.h> -#include <qstylesheet.h> -#include <qpainter.h> - -class QPainter; -class QTextDocument; -class QTextCursor; -class QKeyEvent; -class QResizeEvent; -class QMouseEvent; -class QTimer; -class QTextString; -class QVBox; -class QListBox; -class QTextCommand; -class QTextParag; -class QTextFormat; -class QFont; -class QColor; - -class QTextEdit : public QScrollView -{ - Q_OBJECT - -public: - QTextEdit( QWidget *parent, const QString &fn, bool tabify = FALSE ); - QTextEdit( QWidget *parent = 0, const char *name = 0 ); - virtual ~QTextEdit(); - -#if defined(QTEXTEDIT_OPEN_API) - QTextDocument *document() const; - QTextCursor *textCursor() const; -#endif - - QString text() const; - QString text( int parag, bool formatted = FALSE ) const; - Qt::TextFormat textFormat() const; - QString fileName() const; - - void cursorPosition( int ¶g, int &index ); - void selection( int ¶g_from, int &index_from, - int ¶g_to, int &index_to ); - virtual bool find( const QString &expr, bool cs, bool wo, bool forward = TRUE, - int *parag = 0, int *index = 0 ); - void insert( const QString &text, bool indent = FALSE, bool checkNewLine = FALSE ); - - int paragraphs() const; - int lines() const; - int linesOfParagraph( int parag ) const; - int lineOfChar( int parag, int chr ); - - bool isModified() const; - - bool italic() const; - bool bold() const; - bool underline() const; - QString family() const; - int pointSize() const; - QColor color() const; - QFont font() const; - int alignment() const; - int maxLines() const; - - const QStyleSheet* styleSheet() const; - void setStyleSheet( const QStyleSheet* styleSheet ); - - void setPaper( const QBrush& pap); - QBrush paper() const; - - void setLinkColor( const QColor& ); - QColor linkColor() const; - - void setLinkUnderline( bool ); - bool linkUnderline() const; - - void setMimeSourceFactory( const QMimeSourceFactory* factory ); - const QMimeSourceFactory* mimeSourceFactory() const; - - int heightForWidth( int w ) const; - - void append( const QString& text ); - - bool hasSelectedText() const; - QString selectedText() const; - - QString context() const; - - QString documentTitle() const; - - void scrollToAnchor( const QString& name ); - QString anchorAt(const QPoint& pos); - -public slots: - virtual void undo(); - virtual void redo(); - - virtual void cut(); - virtual void copy(); - virtual void paste(); - - virtual void indent(); - - virtual void setItalic( bool b ); - virtual void setBold( bool b ); - virtual void setUnderline( bool b ); - virtual void setFamily( const QString &f ); - virtual void setPointSize( int s ); - virtual void setColor( const QColor &c ); - virtual void setFont( const QFont &f ); - - virtual void setAlignment( int ); - - virtual void setParagType( QStyleSheetItem::DisplayMode, int listStyle ); - - virtual void setTextFormat( Qt::TextFormat f ); - virtual void setText( const QString &txt, const QString &context = QString::null ) { setText( txt, context, FALSE ); } - virtual void setText( const QString &txt, const QString &context, bool tabify ); - - virtual void load( const QString &fn ) { load( fn, FALSE ); } - virtual void load( const QString &fn, bool tabify ); - virtual void save( bool untabify = FALSE ) { save( QString::null, untabify ); } - virtual void save( const QString &fn, bool untabify = FALSE ); - - virtual void setCursorPosition( int parag, int index ); - virtual void setSelection( int parag_from, int index_from, - int parag_to, int index_to ); - - virtual void setModified( bool m ); - virtual void selectAll( bool select ); - - virtual void setMaxLines( int l ); - virtual void resetFormat(); - -signals: - void currentFontChanged( const QFont &f ); - void currentColorChanged( const QColor &c ); - void currentAlignmentChanged( int ); - void textChanged(); - void highlighted( const QString& ); - void linkClicked( const QString& ); - -protected: - void setFormat( QTextFormat *f, int flags ); - void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); - void keyPressEvent( QKeyEvent *e ); - void resizeEvent( QResizeEvent *e ); - void contentsMousePressEvent( QMouseEvent *e ); - void contentsMouseMoveEvent( QMouseEvent *e ); - void contentsMouseReleaseEvent( QMouseEvent *e ); - void contentsMouseDoubleClickEvent( QMouseEvent *e ); -#ifndef QT_NO_DRAGANDDROP - void contentsDragEnterEvent( QDragEnterEvent *e ); - void contentsDragMoveEvent( QDragMoveEvent *e ); - void contentsDragLeaveEvent( QDragLeaveEvent *e ); - void contentsDropEvent( QDropEvent *e ); -#endif - bool eventFilter( QObject *o, QEvent *e ); - bool focusNextPrevChild( bool next ); -#if !defined(QTEXTEDIT_OPEN_API) - QTextDocument *document() const; - QTextCursor *textCursor() const; -#endif - -private slots: - void formatMore(); - void doResize(); - void doAutoScroll(); - void doChangeInterval(); - void blinkCursor(); - void setModified(); - void startDrag(); - -private: - enum MoveDirection { - MoveLeft, - MoveRight, - MoveUp, - MoveDown, - MoveHome, - MoveEnd, - MovePgUp, - MovePgDown - }; - enum KeyboardAction { - ActionBackspace, - ActionDelete, - ActionReturn - }; - - struct UndoRedoInfo { - enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected }; - UndoRedoInfo( QTextDocument *d ) : type( Invalid ), doc( d ) - { text = QString::null; id = -1; index = -1; } - void clear(); - inline bool valid() const { return !text.isEmpty() && id >= 0&& index >= 0; } - - QString text; - int id; - int index; - Type type; - QTextDocument *doc; - }; - -private: - virtual bool isReadOnly() const { return FALSE; } - virtual bool linksEnabled() const { return TRUE; } - void init(); - void ensureCursorVisible(); - void drawCursor( bool visible ); - void placeCursor( const QPoint &pos, QTextCursor *c = 0 ); - void moveCursor( int direction, bool shift, bool control ); - void moveCursor( int direction, bool control ); - void removeSelectedText(); - void doKeyboardAction( int action ); - bool doCompletion(); - void checkUndoRedoInfo( UndoRedoInfo::Type t ); - void repaintChanged(); - void updateCurrentFormat(); - void handleReadOnlyKeyEvent( QKeyEvent *e ); - void makeParagVisible( QTextParag *p ); - -private: - QTextDocument *doc; - QTextCursor *cursor; - bool drawAll; - bool mousePressed; - QTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer, *resizeTimer; - QTextParag *lastFormatted; - int interval; - QVBox *completionPopup; - QListBox *completionListBox; - int completionOffset; - UndoRedoInfo undoRedoInfo; - QTextFormat *currentFormat; - QPainter painter; - int currentAlignment; - bool inDoubleClick; - QPoint oldMousePos, mousePos; - QPixmap *buf_pixmap; - bool cursorVisible, blinkCursorVisible; - bool readOnly, modified, mightStartDrag; - QPoint dragStartPos; - int mLines; - bool firstResize; - QString onLink; - -}; - -inline QTextDocument *QTextEdit::document() const -{ - return doc; -} - -inline QTextCursor *QTextEdit::textCursor() const -{ - return cursor; -} - -#endif 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 @@ -1,410 +1,578 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ +// 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> #include <qpe/applnk.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpe/qpeapplication.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> //#include <qpe/finddialog.h> +#include <qstringlist.h> #include <qaction.h> #include <qcolordialog.h> #include <qfileinfo.h> #include <qlineedit.h> #include <qmessagebox.h> #include <qobjectlist.h> #include <qpopupmenu.h> #include <qspinbox.h> #include <qtoolbutton.h> #include <qwidgetstack.h> #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$ ", +" +... "}; #if QT_VERSION < 300 class QpeEditor : public QMultiLineEdit { // Q_OBJECT public: QpeEditor( QWidget *parent, const char * name = 0 ) - : QMultiLineEdit( parent, name ) {} + : QMultiLineEdit( parent, name ) + { + clearTableFlags(); + setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); + } //public slots: void find( const QString &txt, bool caseSensitive, bool backwards ); /* signals: void notFound(); void searchWrapped(); */ 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; + } } } #else #error "Must make a QpeEditor that inherits QTextEdit" #endif 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; - QString lang = getenv( "LANG" ); - 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( "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); - } + + 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 ); 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) ) ); ba->setToggleAction(TRUE); ba->addTo( font ); QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); ia->setToggleAction(TRUE); ia->addTo( font ); ba->setOn(defb); ia->setOn(defi); - + font->insertSeparator(); #endif QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); wa->setToggleAction(TRUE); wa->addTo( font ); + font->insertSeparator(); + font->insertItem("Font", this, SLOT(changeFont()) ); + mb->insertItem( tr( "File" ), file ); mb->insertItem( tr( "Edit" ), edit ); mb->insertItem( tr( "View" ), font ); searchBar = new QPEToolBar(this); addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); searchBar->setHorizontalStretchable( TRUE ); searchEdit = new QLineEdit( searchBar, "searchEdit" ); 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 ); 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, 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(); } TextEdit::~TextEdit() { save(); 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; - } - } + 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); zin->setEnabled(s != fontsize[nfontsizes-1]); zout->setEnabled(s != fontsize[0]); } void TextEdit::setBold(bool y) { QFont f = editor->font(); f.setBold(y); editor->setFont(f); } void TextEdit::setItalic(bool y) { QFont f = editor->font(); f.setItalic(y); editor->setFont(f); } void TextEdit::setWordWrap(bool y) { + bool state = editor->edited(); editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); + editor->setEdited( state ); } void TextEdit::fileNew() { save(); newFile(DocLnk()); } 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(); searchBar->hide(); clearWState (WState_Reserved1 ); editorStack->raiseWidget( fileSelector ); fileSelector->reread(); updateCaption(); } +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 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(); } #endif void TextEdit::fileRevert() { clear(); fileOpen(); } void TextEdit::editCut() { #ifndef QT_NO_CLIPBOARD editor->cut(); #endif } void TextEdit::editCopy() { #ifndef QT_NO_CLIPBOARD editor->copy(); @@ -445,150 +613,191 @@ void TextEdit::search() 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(); } 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 ); + name = name.mid( sep+1 ); updateCaption( name ); } 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); editor->setEdited(FALSE); updateCaption(); } 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; 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") ); + 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") ); } } 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; + +} + diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index f7d1052..4e469cc 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -1,102 +1,105 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ +// additions made by L.J. Potter Sun 02-17-2002 22:27:46 #ifndef TEXTEDIT_H #define TEXTEDIT_H #define QTEXTEDIT_OPEN_API #include <qpe/filemanager.h> #include <qmainwindow.h> #include <qmultilineedit.h> #include <qlist.h> #include <qmap.h> class QWidgetStack; class QToolButton; class QPopupMenu; class QToolBar; class QLineEdit; class QAction; class FileSelector; class QpeEditor; class TextEdit : public QMainWindow { Q_OBJECT public: TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~TextEdit(); void openFile( const QString & ); protected: void closeEvent( QCloseEvent *e ); private slots: void setDocument(const QString&); - + void changeFont(); void fileNew(); void fileRevert(); void fileOpen(); + void newFileOpen(); + bool save(); void editCut(); void editCopy(); void editPaste(); void editFind(); void findNext(); void findClose(); void search(); void accept(); void newFile( const DocLnk & ); void openFile( const DocLnk & ); void showEditTools(); void zoomIn(); void zoomOut(); void setBold(bool y); void setItalic(bool y); void setWordWrap(bool y); private: void colorChanged( const QColor &c ); - bool save(); void clear(); void updateCaption( const QString &name=QString::null ); void setFontSize(int sz, bool round_down_not_up); private: QWidgetStack *editorStack; FileSelector *fileSelector; QpeEditor* editor; QToolBar *menu, *editBar, *searchBar; QLineEdit *searchEdit; DocLnk *doc; bool searchVisible; bool bFromDocView; QAction *zin, *zout; + QString currentFileName; }; #endif diff --git a/core/apps/textedit/textedit.pro b/core/apps/textedit/textedit.pro index 23b8d8d..9b1a841 100644 --- a/core/apps/textedit/textedit.pro +++ b/core/apps/textedit/textedit.pro @@ -1,16 +1,16 @@ -TEMPLATE = app -CONFIG += qt warn_on release +TEMPLATE = app +CONFIG += qt warn_on release -DESTDIR = $(OPIEDIR)/bin +DESTDIR = $(OPIEDIR)/bin -HEADERS = textedit.h +HEADERS = textedit.h fileBrowser.h fontDialog.h fileSaver.h -SOURCES = main.cpp textedit.cpp +SOURCES = main.cpp textedit.cpp fileBrowser.cpp fontDialog.cpp fileSaver.cpp INCLUDEPATH += $(OPIEDIR)/include -DEPENDPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -TARGET = textedit +TARGET = textedit TRANSLATIONS = ../i18n/de/textedit.ts |