summaryrefslogtreecommitdiff
authordrw <drw>2002-03-15 01:09:57 (UTC)
committer drw <drw>2002-03-15 01:09:57 (UTC)
commit320291b5006c75e3e42ba1cbbac9639a54309553 (patch) (unidiff)
tree0cfd5d74be6598c778dc94688797cf47cdf6c9d6
parent5283a32d6d9ab9b9bccd3482ab6694c940c874d3 (diff)
downloadopie-320291b5006c75e3e42ba1cbbac9639a54309553.zip
opie-320291b5006c75e3e42ba1cbbac9639a54309553.tar.gz
opie-320291b5006c75e3e42ba1cbbac9639a54309553.tar.bz2
Made file browser resize
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileBrowser.cpp46
-rw-r--r--core/apps/textedit/textedit.cpp1
2 files changed, 31 insertions, 16 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp
index c16bd41..2e88067 100644
--- a/core/apps/textedit/fileBrowser.cpp
+++ b/core/apps/textedit/fileBrowser.cpp
@@ -1,216 +1,230 @@
1/**************************************************************************** 1/****************************************************************************
2** copyright 2001 ljp ljp@llornkcor.com 2** copyright 2001 ljp ljp@llornkcor.com
3** Created: Fri Dec 14 08:16:46 2001 3** Created: Fri Dec 14 08:16:46 2001
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13****************************************************************************/ 13****************************************************************************/
14#include "fileBrowser.h" 14#include "fileBrowser.h"
15#include <qpe/config.h> 15#include <qpe/config.h>
16#include <qpe/resource.h> 16#include <qpe/resource.h>
17#include <qpe/qpeapplication.h> 17#include <qpe/qpeapplication.h>
18 18
19#include <qlistview.h> 19#include <qlistview.h>
20#include <qpushbutton.h> 20#include <qpushbutton.h>
21#include <qfile.h> 21#include <qfile.h>
22#include <qmessagebox.h> 22#include <qmessagebox.h>
23#include <qlayout.h>
23#include <unistd.h> 24#include <unistd.h>
24 25
25 26
26 27
27fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) 28fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter )
28 : QDialog( parent, name, modal, fl ) 29 : QDialog( parent, name, modal, fl )
29{ 30{
30 if ( !name ) 31 if ( !name )
31 setName( "fileBrowser" ); 32 setName( "fileBrowser" );
32 resize( 240, 280 );
33 setCaption(tr( name ) ); 33 setCaption(tr( name ) );
34 filterStr=filter; 34 filterStr=filter;
35 35
36 QGridLayout *layout = new QGridLayout( this );
37 layout->setSpacing( 4 );
38 layout->setMargin( 4 );
39
40
36 dirLabel = new QLabel(this, "DirLabel"); 41 dirLabel = new QLabel(this, "DirLabel");
37 dirLabel->setText(currentDir.canonicalPath()); 42 dirLabel->setText(currentDir.canonicalPath());
38 dirLabel->setGeometry(10,20,230,15); 43 dirLabel->setMinimumSize( QSize( 50, 15 ) );
44 dirLabel->setMaximumSize( QSize( 250, 15 ) );
45 layout->addWidget( dirLabel, 0, 0 );
39 46
40 homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); 47 hideButton = new QPushButton( Resource::loadIconSet("s_hidden"),"",this,"hideButton");
41 homeButton->setGeometry(200,4,25,25); 48 hideButton->setMinimumSize( QSize( 25, 25 ) );
42 connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); 49 hideButton->setMaximumSize( QSize( 25, 25 ) );
43 homeButton->setFlat(TRUE); 50 connect( hideButton,SIGNAL(toggled(bool)),this,SLOT( hideButtonPushed(bool)) );
51 hideButton->setToggleButton(TRUE);
52 hideButton->setFlat(TRUE);
53 layout->addWidget( hideButton, 0, 1 );
44 54
45 docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); 55 docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton");
46 docButton->setGeometry(170,4,25,25); 56 docButton->setMinimumSize( QSize( 25, 25 ) );
57 docButton->setMaximumSize( QSize( 25, 25 ) );
47 connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); 58 connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) );
48 docButton->setFlat(TRUE); 59 docButton->setFlat(TRUE);
60 layout->addWidget( docButton, 0, 2 );
61
62 homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton");
63 homeButton->setMinimumSize( QSize( 25, 25 ) );
64 homeButton->setMaximumSize( QSize( 25, 25 ) );
65 connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) );
66 homeButton->setFlat(TRUE);
67 layout->addWidget( homeButton, 0, 3 );
49 68
50 hideButton = new QPushButton( Resource::loadIconSet("s_hidden"),"",this,"hideButton");
51 hideButton->setGeometry(140,4,25,25);
52 connect( hideButton,SIGNAL(toggled(bool)),this,SLOT( hideButtonPushed(bool)) );
53 hideButton->setToggleButton(TRUE);
54 hideButton->setFlat(TRUE);
55
56 ListView = new QListView( this, "ListView" ); 69 ListView = new QListView( this, "ListView" );
70 ListView->setMinimumSize( QSize( 100, 25 ) );
57 ListView->addColumn( tr( "Name" ) ); 71 ListView->addColumn( tr( "Name" ) );
58 ListView->setColumnWidth(0,140); 72 ListView->setColumnWidth(0,140);
59 ListView->setSorting( 2, FALSE); 73 ListView->setSorting( 2, FALSE);
60 ListView->addColumn( tr( "Size" ) ); 74 ListView->addColumn( tr( "Size" ) );
61 ListView->setColumnWidth(1,59); 75 ListView->setColumnWidth(1,59);
62// ListView->addColumn( tr( "" ) ); 76// ListView->addColumn( tr( "" ) );
63 ListView->setColumnWidthMode(0,QListView::Manual); 77 ListView->setColumnWidthMode(0,QListView::Manual);
64 ListView->setColumnAlignment(1,QListView::AlignRight); 78 ListView->setColumnAlignment(1,QListView::AlignRight);
65// ListView->setMultiSelection(true); 79// ListView->setMultiSelection(true);
66// ListView->setSelectionMode(QListView::Extended); 80// ListView->setSelectionMode(QListView::Extended);
67 81
68 ListView->setAllColumnsShowFocus( TRUE ); 82 ListView->setAllColumnsShowFocus( TRUE );
69 ListView->setGeometry( QRect( 10, 35, 220, 240 ) ); 83 layout->addMultiCellWidget( ListView, 1, 1, 0, 3 );
70 84
71 // signals and slots connections 85 // signals and slots connections
72 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); 86 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
73 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 87 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
74 currentDir.setPath(QDir::currentDirPath()); 88 currentDir.setPath(QDir::currentDirPath());
75 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); 89 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All);
76 90
77 populateList(); 91 populateList();
78 move(0,15); 92 move(0,15);
79} 93}
80 94
81fileBrowser::~fileBrowser() 95fileBrowser::~fileBrowser()
82{ 96{
83} 97}
84 98
85 99
86void fileBrowser::populateList() 100void fileBrowser::populateList()
87{ 101{
88 ListView->clear(); 102 ListView->clear();
89//qDebug(currentDir.canonicalPath()); 103//qDebug(currentDir.canonicalPath());
90 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 104 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
91 currentDir.setMatchAllDirs(TRUE); 105 currentDir.setMatchAllDirs(TRUE);
92 106
93 currentDir.setNameFilter(filterStr); 107 currentDir.setNameFilter(filterStr);
94// currentDir.setNameFilter("*.txt;*.etx"); 108// currentDir.setNameFilter("*.txt;*.etx");
95 QString fileL, fileS; 109 QString fileL, fileS;
96 const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); 110 const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/);
97 QFileInfoListIterator it(*list); 111 QFileInfoListIterator it(*list);
98 QFileInfo *fi; 112 QFileInfo *fi;
99 while ( (fi=it.current()) ) { 113 while ( (fi=it.current()) ) {
100 114
101 if (fi->isSymLink() ){ 115 if (fi->isSymLink() ){
102 QString symLink=fi->readLink(); 116 QString symLink=fi->readLink();
103// qDebug("Symlink detected "+symLink); 117// qDebug("Symlink detected "+symLink);
104 QFileInfo sym( symLink); 118 QFileInfo sym( symLink);
105 fileS.sprintf( "%10li", sym.size() ); 119 fileS.sprintf( "%10li", sym.size() );
106 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); 120 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() );
107 121
108 } else { 122 } else {
109// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); 123// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
110 fileS.sprintf( "%10li", fi->size() ); 124 fileS.sprintf( "%10li", fi->size() );
111 fileL.sprintf( "%s",fi->fileName().data() ); 125 fileL.sprintf( "%s",fi->fileName().data() );
112 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { 126 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
113 fileL+="/"; 127 fileL+="/";
114// qDebug( fileL); 128// qDebug( fileL);
115 } 129 }
116 } 130 }
117 item= new QListViewItem( ListView,fileL,fileS ); 131 item= new QListViewItem( ListView,fileL,fileS );
118 ++it; 132 ++it;
119 } 133 }
120 ListView->setSorting( 2, FALSE); 134 ListView->setSorting( 2, FALSE);
121 dirLabel->setText(currentDir.canonicalPath()); 135 dirLabel->setText(currentDir.canonicalPath());
122} 136}
123 137
124void fileBrowser::upDir() 138void fileBrowser::upDir()
125{ 139{
126// qDebug(currentDir.canonicalPath()); 140// qDebug(currentDir.canonicalPath());
127} 141}
128 142
129void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) 143void fileBrowser::listDoubleClicked(QListViewItem *selectedItem)
130{ 144{
131} 145}
132 146
133// you may want to switch these 2 functions. I like single clicks 147// you may want to switch these 2 functions. I like single clicks
134void fileBrowser::listClicked(QListViewItem *selectedItem) 148void fileBrowser::listClicked(QListViewItem *selectedItem)
135{ 149{
136 QString strItem=selectedItem->text(0); 150 QString strItem=selectedItem->text(0);
137 QString strSize=selectedItem->text(1); 151 QString strSize=selectedItem->text(1);
138// qDebug("strItem is "+strItem); 152// qDebug("strItem is "+strItem);
139 strSize.stripWhiteSpace(); 153 strSize.stripWhiteSpace();
140// qDebug(strSize); 154// qDebug(strSize);
141 155
142 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink 156 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink
143 // is symlink 157 // is symlink
144 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); 158 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4);
145// qDebug("strItem symlink is "+strItem2); 159// qDebug("strItem symlink is "+strItem2);
146 if(QDir(strItem2).exists() ) { 160 if(QDir(strItem2).exists() ) {
147 currentDir.cd(strItem2, TRUE); 161 currentDir.cd(strItem2, TRUE);
148 populateList(); 162 populateList();
149 } 163 }
150 } else { // not a symlink 164 } else { // not a symlink
151 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { 165 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
152 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { 166 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) {
153 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 167 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
154 currentDir.cd(strItem,FALSE); 168 currentDir.cd(strItem,FALSE);
155// qDebug("Path is "+strItem); 169// qDebug("Path is "+strItem);
156 populateList(); 170 populateList();
157 } else { 171 } else {
158 currentDir.cdUp(); 172 currentDir.cdUp();
159 populateList(); 173 populateList();
160 } 174 }
161 if(QDir(strItem).exists()){ 175 if(QDir(strItem).exists()){
162 currentDir.cd(strItem, TRUE); 176 currentDir.cd(strItem, TRUE);
163 populateList(); 177 populateList();
164 } 178 }
165 } else { 179 } else {
166 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 180 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
167 if( QFile::exists(strItem ) ) { 181 if( QFile::exists(strItem ) ) {
168//currentDir.canonicalPath() 182//currentDir.canonicalPath()
169 qDebug("We found our files!!"+strItem); 183 qDebug("We found our files!!"+strItem);
170 OnOK(); 184 OnOK();
171 } 185 }
172 } //end not symlink 186 } //end not symlink
173 chdir(strItem.latin1()); 187 chdir(strItem.latin1());
174 } 188 }
175} 189}
176 190
177void fileBrowser::OnOK() 191void fileBrowser::OnOK()
178{ 192{
179 QListViewItemIterator it1( ListView); 193 QListViewItemIterator it1( ListView);
180 for ( ; it1.current(); ++it1 ) { 194 for ( ; it1.current(); ++it1 ) {
181 if ( it1.current()->isSelected() ) { 195 if ( it1.current()->isSelected() ) {
182 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); 196 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0));
183 qDebug("selected filename is "+selectedFileName); 197 qDebug("selected filename is "+selectedFileName);
184 fileList.append( selectedFileName ); 198 fileList.append( selectedFileName );
185 } 199 }
186 } 200 }
187 accept(); 201 accept();
188} 202}
189 203
190void fileBrowser::homeButtonPushed() { 204void fileBrowser::homeButtonPushed() {
191 chdir( QDir::homeDirPath().latin1() ); 205 chdir( QDir::homeDirPath().latin1() );
192 currentDir.cd( QDir::homeDirPath(), TRUE); 206 currentDir.cd( QDir::homeDirPath(), TRUE);
193 populateList(); 207 populateList();
194 update(); 208 update();
195} 209}
196 210
197void fileBrowser::docButtonPushed() { 211void fileBrowser::docButtonPushed() {
198 chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); 212 chdir( QString(QPEApplication::documentDir()+"/text").latin1() );
199 currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); 213 currentDir.cd( QPEApplication::documentDir()+"/text", TRUE);
200 populateList(); 214 populateList();
201 update(); 215 update();
202 216
203} 217}
204 218
205void fileBrowser::hideButtonPushed(bool b) { 219void fileBrowser::hideButtonPushed(bool b) {
206 if (b) 220 if (b)
207 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); 221 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
208 else 222 else
209 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); 223 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
210 224
211// chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); 225// chdir( QString(QPEApplication::documentDir()+"/text").latin1() );
212// currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); 226// currentDir.cd( QPEApplication::documentDir()+"/text", TRUE);
213 populateList(); 227 populateList();
214 update(); 228 update();
215 229
216} 230}
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index c46f089..3a189cb 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -159,768 +159,769 @@ class QpeEditor : public QMultiLineEdit
159 // Q_OBJECT 159 // Q_OBJECT
160public: 160public:
161 QpeEditor( QWidget *parent, const char * name = 0 ) 161 QpeEditor( QWidget *parent, const char * name = 0 )
162 : QMultiLineEdit( parent, name ) 162 : QMultiLineEdit( parent, name )
163 { 163 {
164 clearTableFlags(); 164 clearTableFlags();
165 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); 165 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
166 } 166 }
167 167
168 void find( const QString &txt, bool caseSensitive, 168 void find( const QString &txt, bool caseSensitive,
169 bool backwards ); 169 bool backwards );
170//public slots: 170//public slots:
171 /* 171 /*
172signals: 172signals:
173 void notFound(); 173 void notFound();
174 void searchWrapped(); 174 void searchWrapped();
175 */ 175 */
176 176
177private: 177private:
178 178
179}; 179};
180 180
181 181
182void QpeEditor::find ( const QString &txt, bool caseSensitive, 182void QpeEditor::find ( const QString &txt, bool caseSensitive,
183 bool backwards ) 183 bool backwards )
184{ 184{
185 static bool wrap = FALSE; 185 static bool wrap = FALSE;
186 int line, col; 186 int line, col;
187 if ( wrap ) { 187 if ( wrap ) {
188 if ( !backwards ) 188 if ( !backwards )
189 line = col = 0; 189 line = col = 0;
190 wrap = FALSE; 190 wrap = FALSE;
191 // emit searchWrapped(); 191 // emit searchWrapped();
192 } else { 192 } else {
193 getCursorPosition( &line, &col ); 193 getCursorPosition( &line, &col );
194 } 194 }
195 //ignore backwards for now.... 195 //ignore backwards for now....
196 if ( !backwards ) { 196 if ( !backwards ) {
197 for ( ; ; ) { 197 for ( ; ; ) {
198 if ( line >= numLines() ) { 198 if ( line >= numLines() ) {
199 wrap = TRUE; 199 wrap = TRUE;
200 //emit notFound(); 200 //emit notFound();
201 break; 201 break;
202 } 202 }
203 int findCol = getString( line )->find( txt, col, caseSensitive ); 203 int findCol = getString( line )->find( txt, col, caseSensitive );
204 if ( findCol >= 0 ) { 204 if ( findCol >= 0 ) {
205 setCursorPosition( line, findCol, FALSE ); 205 setCursorPosition( line, findCol, FALSE );
206 col = findCol + txt.length(); 206 col = findCol + txt.length();
207 setCursorPosition( line, col, TRUE ); 207 setCursorPosition( line, col, TRUE );
208 208
209 //found = TRUE; 209 //found = TRUE;
210 break; 210 break;
211 } 211 }
212 line++; 212 line++;
213 col = 0; 213 col = 0;
214 } 214 }
215 215
216 } 216 }
217 217
218} 218}
219 219
220 220
221#else 221#else
222 222
223#error "Must make a QpeEditor that inherits QTextEdit" 223#error "Must make a QpeEditor that inherits QTextEdit"
224 224
225#endif 225#endif
226 226
227 227
228 228
229 229
230static int u_id = 1; 230static int u_id = 1;
231static int get_unique_id() 231static int get_unique_id()
232{ 232{
233 return u_id++; 233 return u_id++;
234} 234}
235 235
236static const int nfontsizes = 6; 236static const int nfontsizes = 6;
237static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; 237static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
238 238
239TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) 239TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
240 : QMainWindow( parent, name, f ), bFromDocView( FALSE ) 240 : QMainWindow( parent, name, f ), bFromDocView( FALSE )
241{ 241{
242 doc = 0; 242 doc = 0;
243 edited=FALSE; 243 edited=FALSE;
244 edited1=FALSE; 244 edited1=FALSE;
245 setToolBarsMovable( FALSE ); 245 setToolBarsMovable( FALSE );
246 246
247 setIcon( Resource::loadPixmap( "TextEditor" ) ); 247 setIcon( Resource::loadPixmap( "TextEditor" ) );
248 248
249 QPEToolBar *bar = new QPEToolBar( this ); 249 QPEToolBar *bar = new QPEToolBar( this );
250 bar->setHorizontalStretchable( TRUE ); 250 bar->setHorizontalStretchable( TRUE );
251 menu = bar; 251 menu = bar;
252 252
253 QPEMenuBar *mb = new QPEMenuBar( bar ); 253 QPEMenuBar *mb = new QPEMenuBar( bar );
254 QPopupMenu *file = new QPopupMenu( this ); 254 QPopupMenu *file = new QPopupMenu( this );
255 QPopupMenu *edit = new QPopupMenu( this ); 255 QPopupMenu *edit = new QPopupMenu( this );
256 font = new QPopupMenu( this ); 256 font = new QPopupMenu( this );
257 257
258 bar = new QPEToolBar( this ); 258 bar = new QPEToolBar( this );
259 editBar = bar; 259 editBar = bar;
260 260
261 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 261 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
262 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 262 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
263 a->addTo( bar ); 263 a->addTo( bar );
264 a->addTo( file ); 264 a->addTo( file );
265 265
266 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 266 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
267 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 267 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
268// a->addTo( bar ); 268// a->addTo( bar );
269 a->addTo( file ); 269 a->addTo( file );
270 270
271 a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 271 a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
272 connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); 272 connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) );
273 a->addTo( bar ); 273 a->addTo( bar );
274 a->addTo( file ); 274 a->addTo( file );
275 275
276 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); 276 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
277 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 277 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
278// a->addTo( bar ); 278// a->addTo( bar );
279 file->insertSeparator(); 279 file->insertSeparator();
280 a->addTo( file ); 280 a->addTo( file );
281 281
282 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); 282 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
283 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); 283 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
284 a->addTo( file ); 284 a->addTo( file );
285 285
286 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 286 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
287 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 287 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
288 a->addTo( editBar ); 288 a->addTo( editBar );
289 a->addTo( edit ); 289 a->addTo( edit );
290 290
291 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); 291 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
292 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 292 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
293 a->addTo( editBar ); 293 a->addTo( editBar );
294 a->addTo( edit ); 294 a->addTo( edit );
295 295
296 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 296 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
297 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 297 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
298 a->addTo( editBar ); 298 a->addTo( editBar );
299 a->addTo( edit ); 299 a->addTo( edit );
300 300
301 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); 301 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
302 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 302 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
303 edit->insertSeparator(); 303 edit->insertSeparator();
304 a->addTo( bar ); 304 a->addTo( bar );
305 a->addTo( edit ); 305 a->addTo( edit );
306 306
307 307
308 int defsize; 308 int defsize;
309 bool defb, defi, wrap; 309 bool defb, defi, wrap;
310 310
311 Config cfg("TextEdit"); 311 Config cfg("TextEdit");
312 cfg.setGroup("View"); 312 cfg.setGroup("View");
313 defsize = cfg.readNumEntry("FontSize",10); 313 defsize = cfg.readNumEntry("FontSize",10);
314 defb = cfg.readBoolEntry("Bold",FALSE); 314 defb = cfg.readBoolEntry("Bold",FALSE);
315 defi = cfg.readBoolEntry("Italic",FALSE); 315 defi = cfg.readBoolEntry("Italic",FALSE);
316 wrap = cfg.readBoolEntry("Wrap",TRUE); 316 wrap = cfg.readBoolEntry("Wrap",TRUE);
317 317
318 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); 318 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
319 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); 319 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
320 zin->addTo( font ); 320 zin->addTo( font );
321 321
322 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); 322 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
323 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); 323 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
324 zout->addTo( font ); 324 zout->addTo( font );
325 325
326 font->insertSeparator(); 326 font->insertSeparator();
327 327
328#if 0 328#if 0
329 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); 329 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
330 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); 330 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
331 ba->setToggleAction(TRUE); 331 ba->setToggleAction(TRUE);
332 ba->addTo( font ); 332 ba->addTo( font );
333 333
334 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); 334 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 );
335 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); 335 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) );
336 ia->setToggleAction(TRUE); 336 ia->setToggleAction(TRUE);
337 ia->addTo( font ); 337 ia->addTo( font );
338 338
339 ba->setOn(defb); 339 ba->setOn(defb);
340 ia->setOn(defi); 340 ia->setOn(defi);
341 341
342 font->insertSeparator(); 342 font->insertSeparator();
343#endif 343#endif
344 344
345 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); 345 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
346 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); 346 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
347 wa->setToggleAction(TRUE); 347 wa->setToggleAction(TRUE);
348 wa->addTo( font ); 348 wa->addTo( font );
349 349
350 font->insertSeparator(); 350 font->insertSeparator();
351 font->insertItem("Font", this, SLOT(changeFont()) ); 351 font->insertItem("Font", this, SLOT(changeFont()) );
352 352
353 font->insertSeparator(); 353 font->insertSeparator();
354 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); 354 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 );
355 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); 355 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) );
356 nStart->setToggleAction(TRUE); 356 nStart->setToggleAction(TRUE);
357 nStart->addTo( font ); 357 nStart->addTo( font );
358 358
359 mb->insertItem( tr( "File" ), file ); 359 mb->insertItem( tr( "File" ), file );
360 mb->insertItem( tr( "Edit" ), edit ); 360 mb->insertItem( tr( "Edit" ), edit );
361 mb->insertItem( tr( "View" ), font ); 361 mb->insertItem( tr( "View" ), font );
362 362
363 searchBar = new QPEToolBar(this); 363 searchBar = new QPEToolBar(this);
364 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 364 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
365 365
366 searchBar->setHorizontalStretchable( TRUE ); 366 searchBar->setHorizontalStretchable( TRUE );
367 367
368 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 368 searchEdit = new QLineEdit( searchBar, "searchEdit" );
369 searchBar->setStretchableWidget( searchEdit ); 369 searchBar->setStretchableWidget( searchEdit );
370 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 370 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
371 this, SLOT( search() ) ); 371 this, SLOT( search() ) );
372 372
373 373
374 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 374 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
375 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 375 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
376 a->addTo( searchBar ); 376 a->addTo( searchBar );
377 a->addTo( edit ); 377 a->addTo( edit );
378 378
379 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 379 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
380 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 380 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
381 a->addTo( searchBar ); 381 a->addTo( searchBar );
382 382
383 edit->insertSeparator(); 383 edit->insertSeparator();
384 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 384 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
385 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); 385 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
386 a->addTo( edit ); 386 a->addTo( edit );
387 387
388 searchBar->hide(); 388 searchBar->hide();
389 389
390 editorStack = new QWidgetStack( this ); 390 editorStack = new QWidgetStack( this );
391 setCentralWidget( editorStack ); 391 setCentralWidget( editorStack );
392 392
393 searchVisible = FALSE; 393 searchVisible = FALSE;
394 394
395 fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy 395 fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy
396 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); 396 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
397 connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); 397 connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
398 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); 398 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
399// fileOpen(); 399// fileOpen();
400 400
401 editor = new QpeEditor( editorStack ); 401 editor = new QpeEditor( editorStack );
402 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 402 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
403 editorStack->addWidget( editor, get_unique_id() ); 403 editorStack->addWidget( editor, get_unique_id() );
404 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); 404 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
405 405
406 resize( 200, 300 ); 406 resize( 200, 300 );
407 407
408// setFontSize(defsize,TRUE); 408// setFontSize(defsize,TRUE);
409 FontDatabase fdb; 409 FontDatabase fdb;
410 QFont defaultFont=editor->font(); 410 QFont defaultFont=editor->font();
411 QFontInfo fontInfo(defaultFont); 411 QFontInfo fontInfo(defaultFont);
412 412
413 cfg.setGroup("Font"); 413 cfg.setGroup("Font");
414 QString family = cfg.readEntry("Family", fontInfo.family()); 414 QString family = cfg.readEntry("Family", fontInfo.family());
415 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 415 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
416 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 416 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
417 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 417 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
418 418
419 defaultFont = fdb.font(family,style,i_size,charSet); 419 defaultFont = fdb.font(family,style,i_size,charSet);
420 editor->setFont( defaultFont); 420 editor->setFont( defaultFont);
421 421
422 wa->setOn(wrap); 422 wa->setOn(wrap);
423 updateCaption(); 423 updateCaption();
424 424
425 cfg.setGroup("View"); 425 cfg.setGroup("View");
426 if(cfg.readEntry("startNew","TRUE") == "TRUE") { 426 if(cfg.readEntry("startNew","TRUE") == "TRUE") {
427 nStart->setOn(TRUE); 427 nStart->setOn(TRUE);
428 fileNew(); 428 fileNew();
429 } else { 429 } else {
430 fileOpen(); 430 fileOpen();
431 } 431 }
432 432
433} 433}
434 434
435TextEdit::~TextEdit() 435TextEdit::~TextEdit()
436{ 436{
437// save(); 437// save();
438 438
439 Config cfg("TextEdit"); 439 Config cfg("TextEdit");
440 cfg.setGroup("View"); 440 cfg.setGroup("View");
441 QFont f = editor->font(); 441 QFont f = editor->font();
442 cfg.writeEntry("FontSize",f.pointSize()); 442 cfg.writeEntry("FontSize",f.pointSize());
443 cfg.writeEntry("Bold",f.bold()); 443 cfg.writeEntry("Bold",f.bold());
444 cfg.writeEntry("Italic",f.italic()); 444 cfg.writeEntry("Italic",f.italic());
445 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); 445 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
446} 446}
447 447
448void TextEdit::zoomIn() 448void TextEdit::zoomIn()
449{ 449{
450 setFontSize(editor->font().pointSize()+1,FALSE); 450 setFontSize(editor->font().pointSize()+1,FALSE);
451} 451}
452 452
453void TextEdit::zoomOut() 453void TextEdit::zoomOut()
454{ 454{
455 setFontSize(editor->font().pointSize()-1,TRUE); 455 setFontSize(editor->font().pointSize()-1,TRUE);
456} 456}
457 457
458 458
459void TextEdit::setFontSize(int sz, bool round_down_not_up) 459void TextEdit::setFontSize(int sz, bool round_down_not_up)
460{ 460{
461 int s=10; 461 int s=10;
462 for (int i=0; i<nfontsizes; i++) { 462 for (int i=0; i<nfontsizes; i++) {
463 if ( fontsize[i] == sz ) { 463 if ( fontsize[i] == sz ) {
464 s = sz; 464 s = sz;
465 break; 465 break;
466 } else if ( round_down_not_up ) { 466 } else if ( round_down_not_up ) {
467 if ( fontsize[i] < sz ) 467 if ( fontsize[i] < sz )
468 s = fontsize[i]; 468 s = fontsize[i];
469 } else { 469 } else {
470 if ( fontsize[i] > sz ) { 470 if ( fontsize[i] > sz ) {
471 s = fontsize[i]; 471 s = fontsize[i];
472 break; 472 break;
473 } 473 }
474 } 474 }
475 } 475 }
476 476
477 QFont f = editor->font(); 477 QFont f = editor->font();
478 f.setPointSize(s); 478 f.setPointSize(s);
479 editor->setFont(f); 479 editor->setFont(f);
480 480
481 zin->setEnabled(s != fontsize[nfontsizes-1]); 481 zin->setEnabled(s != fontsize[nfontsizes-1]);
482 zout->setEnabled(s != fontsize[0]); 482 zout->setEnabled(s != fontsize[0]);
483} 483}
484 484
485void TextEdit::setBold(bool y) 485void TextEdit::setBold(bool y)
486{ 486{
487 QFont f = editor->font(); 487 QFont f = editor->font();
488 f.setBold(y); 488 f.setBold(y);
489 editor->setFont(f); 489 editor->setFont(f);
490} 490}
491 491
492void TextEdit::setItalic(bool y) 492void TextEdit::setItalic(bool y)
493{ 493{
494 QFont f = editor->font(); 494 QFont f = editor->font();
495 f.setItalic(y); 495 f.setItalic(y);
496 editor->setFont(f); 496 editor->setFont(f);
497} 497}
498 498
499void TextEdit::setWordWrap(bool y) 499void TextEdit::setWordWrap(bool y)
500{ 500{
501 bool state = editor->edited(); 501 bool state = editor->edited();
502 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 502 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
503 editor->setEdited( state ); 503 editor->setEdited( state );
504} 504}
505 505
506void TextEdit::fileNew() 506void TextEdit::fileNew()
507{ 507{
508 if( !bFromDocView ) { 508 if( !bFromDocView ) {
509 saveAs(); 509 saveAs();
510 } 510 }
511 newFile(DocLnk()); 511 newFile(DocLnk());
512} 512}
513 513
514void TextEdit::fileOpen() 514void TextEdit::fileOpen()
515{ 515{
516// if ( !save() ) { 516// if ( !save() ) {
517// if ( QMessageBox::critical( this, tr( "Out of space" ), 517// if ( QMessageBox::critical( this, tr( "Out of space" ),
518// tr( "Text Editor was unable to\n" 518// tr( "Text Editor was unable to\n"
519// "save your changes.\n" 519// "save your changes.\n"
520// "Free some space and try again.\n" 520// "Free some space and try again.\n"
521// "\nContinue anyway?" ), 521// "\nContinue anyway?" ),
522// QMessageBox::Yes|QMessageBox::Escape, 522// QMessageBox::Yes|QMessageBox::Escape,
523// QMessageBox::No|QMessageBox::Default ) 523// QMessageBox::No|QMessageBox::Default )
524// != QMessageBox::Yes ) 524// != QMessageBox::Yes )
525// return; 525// return;
526// else { 526// else {
527// delete doc; 527// delete doc;
528// doc = 0; 528// doc = 0;
529// } 529// }
530// } 530// }
531 menu->hide(); 531 menu->hide();
532 editBar->hide(); 532 editBar->hide();
533 searchBar->hide(); 533 searchBar->hide();
534 clearWState (WState_Reserved1 ); 534 clearWState (WState_Reserved1 );
535 editorStack->raiseWidget( fileSelector ); 535 editorStack->raiseWidget( fileSelector );
536 fileSelector->reread(); 536 fileSelector->reread();
537 updateCaption(); 537 updateCaption();
538} 538}
539 539
540void TextEdit::newFileOpen() 540void TextEdit::newFileOpen()
541{ 541{
542 browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); 542 browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*");
543 browseForFiles->showMaximized();
543 if( browseForFiles->exec() != -1 ) { 544 if( browseForFiles->exec() != -1 ) {
544 QString selFile= browseForFiles->selectedFileName; 545 QString selFile= browseForFiles->selectedFileName;
545 QStringList fileList=browseForFiles->fileList; 546 QStringList fileList=browseForFiles->fileList;
546 qDebug(selFile); 547 qDebug(selFile);
547 QStringList::ConstIterator f; 548 QStringList::ConstIterator f;
548 QString fileTemp; 549 QString fileTemp;
549 for ( f = fileList.begin(); f != fileList.end(); f++ ) { 550 for ( f = fileList.begin(); f != fileList.end(); f++ ) {
550 fileTemp = *f; 551 fileTemp = *f;
551 fileTemp.right( fileTemp.length()-5); 552 fileTemp.right( fileTemp.length()-5);
552 QString fileName = fileTemp; 553 QString fileName = fileTemp;
553 if( fileName != "Unnamed" || fileName != "Empty Text" ) { 554 if( fileName != "Unnamed" || fileName != "Empty Text" ) {
554 currentFileName = fileName; 555 currentFileName = fileName;
555 qDebug("please open "+currentFileName); 556 qDebug("please open "+currentFileName);
556 openFile(fileName ); 557 openFile(fileName );
557 } 558 }
558 } 559 }
559 } 560 }
560 delete browseForFiles; 561 delete browseForFiles;
561 editor->setEdited( FALSE); 562 editor->setEdited( FALSE);
562 edited1=FALSE; 563 edited1=FALSE;
563 edited=FALSE; 564 edited=FALSE;
564 if(caption().left(1)=="*") 565 if(caption().left(1)=="*")
565 setCaption(caption().right(caption().length()-1)); 566 setCaption(caption().right(caption().length()-1));
566} 567}
567 568
568#if 0 569#if 0
569void TextEdit::slotFind() 570void TextEdit::slotFind()
570{ 571{
571 FindDialog frmFind( "Text Editor", this ); 572 FindDialog frmFind( "Text Editor", this );
572 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 573 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
573 editor, SLOT(slotDoFind( const QString&,bool,bool))); 574 editor, SLOT(slotDoFind( const QString&,bool,bool)));
574 575
575 //case sensitive, backwards, [category] 576 //case sensitive, backwards, [category]
576 577
577 connect( editor, SIGNAL(notFound()), 578 connect( editor, SIGNAL(notFound()),
578 &frmFind, SLOT(slotNotFound()) ); 579 &frmFind, SLOT(slotNotFound()) );
579 connect( editor, SIGNAL(searchWrapped()), 580 connect( editor, SIGNAL(searchWrapped()),
580 &frmFind, SLOT(slotWrapAround()) ); 581 &frmFind, SLOT(slotWrapAround()) );
581 582
582 frmFind.exec(); 583 frmFind.exec();
583 584
584 585
585} 586}
586#endif 587#endif
587 588
588void TextEdit::fileRevert() 589void TextEdit::fileRevert()
589{ 590{
590 clear(); 591 clear();
591 fileOpen(); 592 fileOpen();
592} 593}
593 594
594void TextEdit::editCut() 595void TextEdit::editCut()
595{ 596{
596#ifndef QT_NO_CLIPBOARD 597#ifndef QT_NO_CLIPBOARD
597 editor->cut(); 598 editor->cut();
598#endif 599#endif
599} 600}
600 601
601void TextEdit::editCopy() 602void TextEdit::editCopy()
602{ 603{
603#ifndef QT_NO_CLIPBOARD 604#ifndef QT_NO_CLIPBOARD
604 editor->copy(); 605 editor->copy();
605#endif 606#endif
606} 607}
607 608
608void TextEdit::editPaste() 609void TextEdit::editPaste()
609{ 610{
610#ifndef QT_NO_CLIPBOARD 611#ifndef QT_NO_CLIPBOARD
611 editor->paste(); 612 editor->paste();
612#endif 613#endif
613} 614}
614 615
615void TextEdit::editFind() 616void TextEdit::editFind()
616{ 617{
617 searchBar->show(); 618 searchBar->show();
618 searchVisible = TRUE; 619 searchVisible = TRUE;
619 searchEdit->setFocus(); 620 searchEdit->setFocus();
620} 621}
621 622
622void TextEdit::findNext() 623void TextEdit::findNext()
623{ 624{
624 editor->find( searchEdit->text(), FALSE, FALSE ); 625 editor->find( searchEdit->text(), FALSE, FALSE );
625 626
626} 627}
627 628
628void TextEdit::findClose() 629void TextEdit::findClose()
629{ 630{
630 searchVisible = FALSE; 631 searchVisible = FALSE;
631 searchBar->hide(); 632 searchBar->hide();
632} 633}
633 634
634void TextEdit::search() 635void TextEdit::search()
635{ 636{
636 editor->find( searchEdit->text(), FALSE, FALSE ); 637 editor->find( searchEdit->text(), FALSE, FALSE );
637} 638}
638 639
639void TextEdit::newFile( const DocLnk &f ) 640void TextEdit::newFile( const DocLnk &f )
640{ 641{
641 DocLnk nf = f; 642 DocLnk nf = f;
642 nf.setType("text/plain"); 643 nf.setType("text/plain");
643 clear(); 644 clear();
644 editorStack->raiseWidget( editor ); 645 editorStack->raiseWidget( editor );
645 setWState (WState_Reserved1 ); 646 setWState (WState_Reserved1 );
646 editor->setFocus(); 647 editor->setFocus();
647 doc = new DocLnk(nf); 648 doc = new DocLnk(nf);
648 qDebug("newFile "+currentFileName); 649 qDebug("newFile "+currentFileName);
649 updateCaption(currentFileName); 650 updateCaption(currentFileName);
650} 651}
651 652
652void TextEdit::openFile( const QString &f ) 653void TextEdit::openFile( const QString &f )
653{ 654{
654 bFromDocView = TRUE; 655 bFromDocView = TRUE;
655 DocLnk nf; 656 DocLnk nf;
656 nf.setType("text/plain"); 657 nf.setType("text/plain");
657 nf.setFile(f); 658 nf.setFile(f);
658 currentFileName=f; 659 currentFileName=f;
659 QFileInfo fi( currentFileName); 660 QFileInfo fi( currentFileName);
660 nf.setName(fi.baseName()); 661 nf.setName(fi.baseName());
661 qDebug("openFile string"+currentFileName); 662 qDebug("openFile string"+currentFileName);
662 663
663 openFile(nf); 664 openFile(nf);
664 showEditTools(); 665 showEditTools();
665 // Show filename in caption 666 // Show filename in caption
666 QString name = f; 667 QString name = f;
667 int sep = name.findRev( '/' ); 668 int sep = name.findRev( '/' );
668 if ( sep > 0 ) 669 if ( sep > 0 )
669 name = name.mid( sep+1 ); 670 name = name.mid( sep+1 );
670 updateCaption( name ); 671 updateCaption( name );
671} 672}
672 673
673void TextEdit::openFile( const DocLnk &f ) 674void TextEdit::openFile( const DocLnk &f )
674{ 675{
675// clear(); 676// clear();
676 bFromDocView = TRUE; 677 bFromDocView = TRUE;
677 FileManager fm; 678 FileManager fm;
678 QString txt; 679 QString txt;
679 currentFileName=f.name(); 680 currentFileName=f.name();
680 qDebug("openFile doclnk " + currentFileName); 681 qDebug("openFile doclnk " + currentFileName);
681 if ( !fm.loadFile( f, txt ) ) { 682 if ( !fm.loadFile( f, txt ) ) {
682 // ####### could be a new file 683 // ####### could be a new file
683 qDebug( "Cannot open file" ); 684 qDebug( "Cannot open file" );
684 685
685 //return; 686 //return;
686 } 687 }
687 688
688 fileNew(); 689 fileNew();
689 if ( doc ) 690 if ( doc )
690 delete doc; 691 delete doc;
691 doc = new DocLnk(f); 692 doc = new DocLnk(f);
692 editor->setText(txt); 693 editor->setText(txt);
693 editor->setEdited( FALSE); 694 editor->setEdited( FALSE);
694 edited1=FALSE; 695 edited1=FALSE;
695 edited=FALSE; 696 edited=FALSE;
696 697
697 qDebug("openFile doclnk "+currentFileName); 698 qDebug("openFile doclnk "+currentFileName);
698 doc->setName(currentFileName); 699 doc->setName(currentFileName);
699 updateCaption(); 700 updateCaption();
700} 701}
701 702
702void TextEdit::showEditTools() 703void TextEdit::showEditTools()
703{ 704{
704// if ( !doc ) 705// if ( !doc )
705// close(); 706// close();
706// clear(); 707// clear();
707 fileSelector->hide(); 708 fileSelector->hide();
708 menu->show(); 709 menu->show();
709 editBar->show(); 710 editBar->show();
710 if ( searchVisible ) 711 if ( searchVisible )
711 searchBar->show(); 712 searchBar->show();
712// updateCaption(); 713// updateCaption();
713 editorStack->raiseWidget( editor ); 714 editorStack->raiseWidget( editor );
714 setWState (WState_Reserved1 ); 715 setWState (WState_Reserved1 );
715} 716}
716 717
717/*! 718/*!
718 unprompted save */ 719 unprompted save */
719bool TextEdit::save() 720bool TextEdit::save()
720{ 721{
721 QString file = doc->file(); 722 QString file = doc->file();
722 qDebug(file); 723 qDebug(file);
723 QString name= doc->name(); 724 QString name= doc->name();
724 qDebug(name); 725 qDebug(name);
725 QString rt = editor->text(); 726 QString rt = editor->text();
726 if( !rt.isEmpty() ) { 727 if( !rt.isEmpty() ) {
727 if(name.isEmpty()) { 728 if(name.isEmpty()) {
728 saveAs(); 729 saveAs();
729 } else { 730 } else {
730 currentFileName= name ; 731 currentFileName= name ;
731 qDebug("saveFile "+currentFileName); 732 qDebug("saveFile "+currentFileName);
732 733
733 struct stat buf; 734 struct stat buf;
734 mode_t mode; 735 mode_t mode;
735 stat(file.latin1(), &buf); 736 stat(file.latin1(), &buf);
736 mode = buf.st_mode; 737 mode = buf.st_mode;
737 738
738 doc->setName( name); 739 doc->setName( name);
739 FileManager fm; 740 FileManager fm;
740 if ( !fm.saveFile( *doc, rt ) ) { 741 if ( !fm.saveFile( *doc, rt ) ) {
741 return false; 742 return false;
742 } 743 }
743 editor->setEdited( FALSE); 744 editor->setEdited( FALSE);
744 edited1=FALSE; 745 edited1=FALSE;
745 edited=FALSE; 746 edited=FALSE;
746 if(caption().left(1)=="*") 747 if(caption().left(1)=="*")
747 setCaption(caption().right(caption().length()-1)); 748 setCaption(caption().right(caption().length()-1));
748 749
749 750
750 chmod( file.latin1(), mode); 751 chmod( file.latin1(), mode);
751 } 752 }
752 return true; 753 return true;
753 } 754 }
754 return false; 755 return false;
755} 756}
756 757
757/*! 758/*!
758 prompted save */ 759 prompted save */
759bool TextEdit::saveAs() 760bool TextEdit::saveAs()
760{ 761{
761// qDebug("saveAsFile "+currentFileName); 762// qDebug("saveAsFile "+currentFileName);
762 763
763 // case of nothing to save... /// there's always something to save 764 // case of nothing to save... /// there's always something to save
764// if ( !doc )//|| !bFromDocView) 765// if ( !doc )//|| !bFromDocView)
765// { 766// {
766// qDebug("no doc"); 767// qDebug("no doc");
767// return true; 768// return true;
768// } 769// }
769 if ( !editor->edited() ) { 770 if ( !editor->edited() ) {
770 delete doc; 771 delete doc;
771 doc = 0; 772 doc = 0;
772 return true; 773 return true;
773 } 774 }
774 775
775 QString rt = editor->text(); 776 QString rt = editor->text();
776 qDebug(currentFileName); 777 qDebug(currentFileName);
777 778
778 if( currentFileName.isEmpty() || currentFileName == "Unnamed") { 779 if( currentFileName.isEmpty() || currentFileName == "Unnamed") {
779 qDebug("do silly TT filename thing"); 780 qDebug("do silly TT filename thing");
780 if ( doc->name().isEmpty() ) { 781 if ( doc->name().isEmpty() ) {
781 QString pt = rt.simplifyWhiteSpace(); 782 QString pt = rt.simplifyWhiteSpace();
782 int i = pt.find( ' ' ); 783 int i = pt.find( ' ' );
783 QString docname = pt; 784 QString docname = pt;
784 if ( i > 0 ) 785 if ( i > 0 )
785 docname = pt.left( i ); 786 docname = pt.left( i );
786 // remove "." at the beginning 787 // remove "." at the beginning
787 while( docname.startsWith( "." ) ) 788 while( docname.startsWith( "." ) )
788 docname = docname.mid( 1 ); 789 docname = docname.mid( 1 );
789 docname.replace( QRegExp("/"), "_" ); 790 docname.replace( QRegExp("/"), "_" );
790 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 791 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
791 if ( docname.length() > 40 ) 792 if ( docname.length() > 40 )
792 docname = docname.left(40); 793 docname = docname.left(40);
793 if ( docname.isEmpty() ) 794 if ( docname.isEmpty() )
794 docname = "Unnamed"; 795 docname = "Unnamed";
795 doc->setName(docname); 796 doc->setName(docname);
796 currentFileName=docname; 797 currentFileName=docname;
797 } 798 }
798 } 799 }
799 800
800 801
801 fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); 802 fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName);
802 qDebug("wanna save filename "+currentFileName); 803 qDebug("wanna save filename "+currentFileName);
803 fileSaveDlg->exec(); 804 fileSaveDlg->exec();
804 if( fileSaveDlg->result() == 1 ) { 805 if( fileSaveDlg->result() == 1 ) {
805 QString fileNm=fileSaveDlg->selectedFileName; 806 QString fileNm=fileSaveDlg->selectedFileName;
806 qDebug("saving filename "+fileNm); 807 qDebug("saving filename "+fileNm);
807 QFileInfo fi(fileNm); 808 QFileInfo fi(fileNm);
808 currentFileName=fi.fileName(); 809 currentFileName=fi.fileName();
809 if(doc) { 810 if(doc) {
810// QString file = doc->file(); 811// QString file = doc->file();
811// doc->removeFiles(); 812// doc->removeFiles();
812 delete doc; 813 delete doc;
813 DocLnk nf; 814 DocLnk nf;
814 nf.setType("text/plain"); 815 nf.setType("text/plain");
815 nf.setFile( fileNm); 816 nf.setFile( fileNm);
816 doc = new DocLnk(nf); 817 doc = new DocLnk(nf);
817// editor->setText(rt); 818// editor->setText(rt);
818// qDebug("openFile doclnk "+currentFileName); 819// qDebug("openFile doclnk "+currentFileName);
819 doc->setName( currentFileName); 820 doc->setName( currentFileName);
820 updateCaption( currentFileName); 821 updateCaption( currentFileName);
821 822
822 FileManager fm; 823 FileManager fm;
823 if ( !fm.saveFile( *doc, rt ) ) { 824 if ( !fm.saveFile( *doc, rt ) ) {
824 return false; 825 return false;
825 } 826 }
826 if( fileSaveDlg->filePermCheck->isChecked() ) { 827 if( fileSaveDlg->filePermCheck->isChecked() ) {
827 filePermissions *filePerm; 828 filePermissions *filePerm;
828 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); 829 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm);
829 filePerm->exec(); 830 filePerm->exec();
830 831
831 if( filePerm) 832 if( filePerm)
832 delete filePerm; 833 delete filePerm;
833 } 834 }
834 } 835 }
835 } 836 }
836 editor->setEdited(TRUE); 837 editor->setEdited(TRUE);
837 edited1=FALSE; 838 edited1=FALSE;
838 edited=TRUE; 839 edited=TRUE;
839 if(caption().left(1)=="*") 840 if(caption().left(1)=="*")
840 setCaption(caption().right(caption().length()-1)); 841 setCaption(caption().right(caption().length()-1));
841 842
842 if(fileSaveDlg) 843 if(fileSaveDlg)
843 delete fileSaveDlg; 844 delete fileSaveDlg;
844 return true; 845 return true;
845} 846}
846 847
847void TextEdit::clear() 848void TextEdit::clear()
848{ 849{
849 delete doc; 850 delete doc;
850 doc = 0; 851 doc = 0;
851 editor->clear(); 852 editor->clear();
852} 853}
853 854
854void TextEdit::updateCaption( const QString &name ) 855void TextEdit::updateCaption( const QString &name )
855{ 856{
856 if ( !doc ) 857 if ( !doc )
857 setCaption( tr("Text Editor") ); 858 setCaption( tr("Text Editor") );
858 else { 859 else {
859 QString s = name; 860 QString s = name;
860 if ( s.isNull() ) 861 if ( s.isNull() )
861 s = doc->name(); 862 s = doc->name();
862 if ( s.isEmpty() ) { 863 if ( s.isEmpty() ) {
863 s = tr( "Unnamed" ); 864 s = tr( "Unnamed" );
864 currentFileName=s; 865 currentFileName=s;
865 } 866 }
866 867
867 setCaption( s + " - " + tr("Text Editor") ); 868 setCaption( s + " - " + tr("Text Editor") );
868 } 869 }
869} 870}
870 871
871void TextEdit::setDocument(const QString& fileref) 872void TextEdit::setDocument(const QString& fileref)
872{ 873{
873 bFromDocView = TRUE; 874 bFromDocView = TRUE;
874 qDebug("setDocument "+fileref); 875 qDebug("setDocument "+fileref);
875 bFromDocView = TRUE; 876 bFromDocView = TRUE;
876 if(fileref.find(".desktop",0,TRUE) == -1) { 877 if(fileref.find(".desktop",0,TRUE) == -1) {
877 openFile(fileref); 878 openFile(fileref);
878 } else { 879 } else {
879 openFile(DocLnk(fileref)); 880 openFile(DocLnk(fileref));
880 } 881 }
881 editor->setEdited(TRUE); 882 editor->setEdited(TRUE);
882 edited1=FALSE; 883 edited1=FALSE;
883 edited=TRUE; 884 edited=TRUE;
884} 885}
885 886
886void TextEdit::closeEvent( QCloseEvent *e ) 887void TextEdit::closeEvent( QCloseEvent *e )
887{ 888{
888 if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { 889 if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
889 e->ignore(); 890 e->ignore();
890 repaint(); 891 repaint();
891// fileRevert(); 892// fileRevert();
892 893
893 } else { 894 } else {
894 bFromDocView = FALSE; 895 bFromDocView = FALSE;
895 e->accept(); 896 e->accept();
896 } 897 }
897} 898}
898 899
899void TextEdit::accept() 900void TextEdit::accept()
900 { 901 {
901 QString file = doc->file(); 902 QString file = doc->file();
902 if (file.find("_.txt",0,TRUE) ==-1) 903 if (file.find("_.txt",0,TRUE) ==-1)
903 save(); 904 save();
904 else { 905 else {
905 QFile(file).remove(); 906 QFile(file).remove();
906 } 907 }
907 exit(0); 908 exit(0);
908 909
909} 910}
910 911
911void TextEdit::changeFont() { 912void TextEdit::changeFont() {
912 FontDatabase fdb; 913 FontDatabase fdb;
913 QFont defaultFont=editor->font(); 914 QFont defaultFont=editor->font();
914 QFontInfo fontInfo(defaultFont); 915 QFontInfo fontInfo(defaultFont);
915 Config cfg("TextEdit"); 916 Config cfg("TextEdit");
916 cfg.setGroup("Font"); 917 cfg.setGroup("Font");
917 QString family = cfg.readEntry("Family", fontInfo.family()); 918 QString family = cfg.readEntry("Family", fontInfo.family());
918 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 919 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
919 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 920 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
920 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 921 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
921 922
922 defaultFont = fdb.font(family,style,i_size,charSet); 923 defaultFont = fdb.font(family,style,i_size,charSet);
923 924
924 FontDialog *fontDlg; 925 FontDialog *fontDlg;
925 fontDlg=new FontDialog(this,"FontDialog",TRUE); 926 fontDlg=new FontDialog(this,"FontDialog",TRUE);
926 927