-rw-r--r-- | core/apps/textedit/textedit.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index c9178a5..086fdb6 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -1,557 +1,559 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | // textedit.cpp | 2 | // textedit.cpp |
3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
4 | ** | 4 | ** |
5 | ** This file is part of Opie Environment. | 5 | ** This file is part of Opie Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | **********************************************************************/ | 12 | **********************************************************************/ |
13 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 | 13 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 |
14 | 14 | ||
15 | #include "textedit.h" | 15 | #include "textedit.h" |
16 | #include "filePermissions.h" | 16 | #include "filePermissions.h" |
17 | 17 | ||
18 | /* OPIE */ | 18 | /* OPIE */ |
19 | #include <opie2/odebug.h> | 19 | #include <opie2/odebug.h> |
20 | #include <opie2/ofileselector.h> | 20 | #include <opie2/ofileselector.h> |
21 | #include <opie2/ofiledialog.h> | 21 | #include <opie2/ofiledialog.h> |
22 | #include <opie2/ofontselector.h> | 22 | #include <opie2/ofontselector.h> |
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | using namespace Opie::Core; | 26 | |
27 | using namespace Opie::Ui; | ||
28 | 27 | ||
29 | /* QT */ | 28 | /* QT */ |
30 | #include <qmenubar.h> | 29 | #include <qmenubar.h> |
31 | #include <qtoolbar.h> | 30 | #include <qtoolbar.h> |
32 | #include <qtextstream.h> | 31 | #include <qtextstream.h> |
33 | #include <qclipboard.h> | 32 | #include <qclipboard.h> |
34 | #include <qaction.h> | 33 | #include <qaction.h> |
35 | #include <qlineedit.h> | 34 | #include <qlineedit.h> |
36 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
37 | #include <qlayout.h> | 36 | #include <qlayout.h> |
38 | #include <qtimer.h> | 37 | #include <qtimer.h> |
39 | #include <qdir.h> | 38 | #include <qdir.h> |
40 | 39 | ||
41 | /* STD */ | 40 | /* STD */ |
42 | #include <unistd.h> | 41 | #include <unistd.h> |
43 | #include <sys/stat.h> | 42 | #include <sys/stat.h> |
44 | #include <stdlib.h> //getenv | 43 | #include <stdlib.h> //getenv |
45 | 44 | ||
45 | using namespace Opie::Core; | ||
46 | using namespace Opie::Ui; | ||
47 | |||
46 | #if QT_VERSION < 300 | 48 | #if QT_VERSION < 300 |
47 | class QpeEditor : public QMultiLineEdit | 49 | class QpeEditor : public QMultiLineEdit |
48 | { | 50 | { |
49 | 51 | ||
50 | public: | 52 | public: |
51 | QpeEditor( QWidget *parent, const char * name = 0 ) | 53 | QpeEditor( QWidget *parent, const char * name = 0 ) |
52 | : QMultiLineEdit( parent, name ) { | 54 | : QMultiLineEdit( parent, name ) { |
53 | clearTableFlags(); | 55 | clearTableFlags(); |
54 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 56 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
55 | } | 57 | } |
56 | 58 | ||
57 | void find( const QString &txt, bool caseSensitive, | 59 | void find( const QString &txt, bool caseSensitive, |
58 | bool backwards ); | 60 | bool backwards ); |
59 | protected: | 61 | protected: |
60 | bool markIt; | 62 | bool markIt; |
61 | int line1, line2, col1, col2; | 63 | int line1, line2, col1, col2; |
62 | void mousePressEvent( QMouseEvent * ); | 64 | void mousePressEvent( QMouseEvent * ); |
63 | void mouseReleaseEvent( QMouseEvent * ); | 65 | void mouseReleaseEvent( QMouseEvent * ); |
64 | 66 | ||
65 | //public slots: | 67 | //public slots: |
66 | /* | 68 | /* |
67 | signals: | 69 | signals: |
68 | void notFound(); | 70 | void notFound(); |
69 | void searchWrapped(); | 71 | void searchWrapped(); |
70 | */ | 72 | */ |
71 | 73 | ||
72 | private: | 74 | private: |
73 | 75 | ||
74 | }; | 76 | }; |
75 | 77 | ||
76 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { | 78 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { |
77 | switch(e->button()) { | 79 | switch(e->button()) { |
78 | case RightButton: | 80 | case RightButton: |
79 | { //rediculous workaround for qt popup menu | 81 | { //rediculous workaround for qt popup menu |
80 | //and the hold right click mechanism | 82 | //and the hold right click mechanism |
81 | this->setSelection( line1, col1, line2, col2); | 83 | this->setSelection( line1, col1, line2, col2); |
82 | QMultiLineEdit::mousePressEvent( e ); | 84 | QMultiLineEdit::mousePressEvent( e ); |
83 | markIt = false; | 85 | markIt = false; |
84 | } | 86 | } |
85 | break; | 87 | break; |
86 | default: | 88 | default: |
87 | { | 89 | { |
88 | if(!markIt) { | 90 | if(!markIt) { |
89 | int line, col; | 91 | int line, col; |
90 | this->getCursorPosition(&line, &col); | 92 | this->getCursorPosition(&line, &col); |
91 | line1=line2=line; | 93 | line1=line2=line; |
92 | col1=col2=col; | 94 | col1=col2=col; |
93 | } | 95 | } |
94 | QMultiLineEdit::mousePressEvent( e ); | 96 | QMultiLineEdit::mousePressEvent( e ); |
95 | } | 97 | } |
96 | break; | 98 | break; |
97 | }; | 99 | }; |
98 | } | 100 | } |
99 | 101 | ||
100 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { | 102 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { |
101 | if(this->hasMarkedText()) { | 103 | if(this->hasMarkedText()) { |
102 | markIt = true; | 104 | markIt = true; |
103 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); | 105 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); |
104 | } else { | 106 | } else { |
105 | markIt = false; | 107 | markIt = false; |
106 | } | 108 | } |
107 | } | 109 | } |
108 | 110 | ||
109 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 111 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
110 | bool backwards ) | 112 | bool backwards ) |
111 | { | 113 | { |
112 | static bool wrap = false; | 114 | static bool wrap = false; |
113 | int line, col; | 115 | int line, col; |
114 | if ( wrap ) { | 116 | if ( wrap ) { |
115 | if ( !backwards ) | 117 | if ( !backwards ) |
116 | line = col = 0; | 118 | line = col = 0; |
117 | wrap = false; | 119 | wrap = false; |
118 | // emit searchWrapped(); | 120 | // emit searchWrapped(); |
119 | } else { | 121 | } else { |
120 | getCursorPosition( &line, &col ); | 122 | getCursorPosition( &line, &col ); |
121 | } | 123 | } |
122 | //ignore backwards for now.... | 124 | //ignore backwards for now.... |
123 | if ( !backwards ) { | 125 | if ( !backwards ) { |
124 | for ( ; ; ) { | 126 | for ( ; ; ) { |
125 | if ( line >= numLines() ) { | 127 | if ( line >= numLines() ) { |
126 | wrap = true; | 128 | wrap = true; |
127 | //emit notFound(); | 129 | //emit notFound(); |
128 | break; | 130 | break; |
129 | } | 131 | } |
130 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 132 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
131 | if ( findCol >= 0 ) { | 133 | if ( findCol >= 0 ) { |
132 | setCursorPosition( line, findCol, false ); | 134 | setCursorPosition( line, findCol, false ); |
133 | col = findCol + txt.length(); | 135 | col = findCol + txt.length(); |
134 | setCursorPosition( line, col, true ); | 136 | setCursorPosition( line, col, true ); |
135 | 137 | ||
136 | //found = true; | 138 | //found = true; |
137 | break; | 139 | break; |
138 | } | 140 | } |
139 | line++; | 141 | line++; |
140 | col = 0; | 142 | col = 0; |
141 | } | 143 | } |
142 | } | 144 | } |
143 | } | 145 | } |
144 | 146 | ||
145 | 147 | ||
146 | #else | 148 | #else |
147 | 149 | ||
148 | #error "Must make a QpeEditor that inherits QTextEdit" | 150 | #error "Must make a QpeEditor that inherits QTextEdit" |
149 | 151 | ||
150 | #endif | 152 | #endif |
151 | 153 | ||
152 | 154 | ||
153 | static const int nfontsizes = 6; | 155 | static const int nfontsizes = 6; |
154 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 156 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
155 | 157 | ||
156 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 158 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
157 | : QMainWindow( parent, name, f ), bFromDocView( false ) | 159 | : QMainWindow( parent, name, f ), bFromDocView( false ) |
158 | { | 160 | { |
159 | doc = 0; | 161 | doc = 0; |
160 | edited=false; | 162 | edited=false; |
161 | fromSetDocument=false; | 163 | fromSetDocument=false; |
162 | 164 | ||
163 | setToolBarsMovable( false ); | 165 | setToolBarsMovable( false ); |
164 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 166 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
165 | 167 | ||
166 | channel = new QCopChannel( "QPE/Application/textedit", this ); | 168 | channel = new QCopChannel( "QPE/Application/textedit", this ); |
167 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 169 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
168 | this, SLOT(receive(const QCString&,const QByteArray&)) ); | 170 | this, SLOT(receive(const QCString&,const QByteArray&)) ); |
169 | 171 | ||
170 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 172 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
171 | 173 | ||
172 | QToolBar *bar = new QToolBar( this ); | 174 | QToolBar *bar = new QToolBar( this ); |
173 | bar->setHorizontalStretchable( true ); | 175 | bar->setHorizontalStretchable( true ); |
174 | menu = bar; | 176 | menu = bar; |
175 | 177 | ||
176 | QMenuBar *mb = new QMenuBar( bar ); | 178 | QMenuBar *mb = new QMenuBar( bar ); |
177 | QPopupMenu *file = new QPopupMenu( this ); | 179 | QPopupMenu *file = new QPopupMenu( this ); |
178 | QPopupMenu *edit = new QPopupMenu( this ); | 180 | QPopupMenu *edit = new QPopupMenu( this ); |
179 | QPopupMenu *advancedMenu = new QPopupMenu(this); | 181 | QPopupMenu *advancedMenu = new QPopupMenu(this); |
180 | 182 | ||
181 | font = new QPopupMenu( this ); | 183 | font = new QPopupMenu( this ); |
182 | 184 | ||
183 | bar = new QToolBar( this ); | 185 | bar = new QToolBar( this ); |
184 | editBar = bar; | 186 | editBar = bar; |
185 | 187 | ||
186 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 188 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
187 | QString::null, 0, this, 0 ); | 189 | QString::null, 0, this, 0 ); |
188 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 190 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
189 | // a->addTo( bar ); | 191 | // a->addTo( bar ); |
190 | a->addTo( file ); | 192 | a->addTo( file ); |
191 | 193 | ||
192 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), | 194 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), |
193 | QString::null, 0, this, 0 ); | 195 | QString::null, 0, this, 0 ); |
194 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 196 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
195 | a->addTo( bar ); | 197 | a->addTo( bar ); |
196 | a->addTo( file ); | 198 | a->addTo( file ); |
197 | 199 | ||
198 | a = new QAction( tr( "Save" ), Resource::loadPixmap("save") , | 200 | a = new QAction( tr( "Save" ), Resource::loadPixmap("save") , |
199 | QString::null, 0, this, 0 ); | 201 | QString::null, 0, this, 0 ); |
200 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 202 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
201 | file->insertSeparator(); | 203 | file->insertSeparator(); |
202 | a->addTo( bar ); | 204 | a->addTo( bar ); |
203 | a->addTo( file ); | 205 | a->addTo( file ); |
204 | 206 | ||
205 | a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") , | 207 | a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") , |
206 | QString::null, 0, this, 0 ); | 208 | QString::null, 0, this, 0 ); |
207 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 209 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
208 | a->addTo( file ); | 210 | a->addTo( file ); |
209 | 211 | ||
210 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), | 212 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), |
211 | QString::null, 0, this, 0 ); | 213 | QString::null, 0, this, 0 ); |
212 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 214 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
213 | a->addTo( editBar ); | 215 | a->addTo( editBar ); |
214 | a->addTo( edit ); | 216 | a->addTo( edit ); |
215 | 217 | ||
216 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), | 218 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), |
217 | QString::null, 0, this, 0 ); | 219 | QString::null, 0, this, 0 ); |
218 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 220 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
219 | a->addTo( editBar ); | 221 | a->addTo( editBar ); |
220 | a->addTo( edit ); | 222 | a->addTo( edit ); |
221 | 223 | ||
222 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), | 224 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), |
223 | QString::null, 0, this, 0 ); | 225 | QString::null, 0, this, 0 ); |
224 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 226 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
225 | a->addTo( editBar ); | 227 | a->addTo( editBar ); |
226 | a->addTo( edit ); | 228 | a->addTo( edit ); |
227 | 229 | ||
228 | 230 | ||
229 | #ifndef QT_NO_CLIPBOARD | 231 | #ifndef QT_NO_CLIPBOARD |
230 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), | 232 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), |
231 | QString::null, 0, this, 0 ); | 233 | QString::null, 0, this, 0 ); |
232 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); | 234 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); |
233 | a->addTo( edit ); | 235 | a->addTo( edit ); |
234 | #endif | 236 | #endif |
235 | 237 | ||
236 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), | 238 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), |
237 | QString::null, 0, this, 0 ); | 239 | QString::null, 0, this, 0 ); |
238 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); | 240 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); |
239 | edit->insertSeparator(); | 241 | edit->insertSeparator(); |
240 | a->addTo( edit ); | 242 | a->addTo( edit ); |
241 | 243 | ||
242 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), | 244 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), |
243 | QString::null, 0, this, 0 ); | 245 | QString::null, 0, this, 0 ); |
244 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 246 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
245 | a->addTo( bar ); | 247 | a->addTo( bar ); |
246 | a->addTo( edit ); | 248 | a->addTo( edit ); |
247 | 249 | ||
248 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 250 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
249 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 251 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
250 | zin->addTo( font ); | 252 | zin->addTo( font ); |
251 | 253 | ||
252 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 254 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
253 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 255 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
254 | zout->addTo( font ); | 256 | zout->addTo( font ); |
255 | 257 | ||
256 | font->insertSeparator(); | 258 | font->insertSeparator(); |
257 | 259 | ||
258 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); | 260 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
259 | 261 | ||
260 | font->insertSeparator(); | 262 | font->insertSeparator(); |
261 | font->insertItem(tr("Advanced Features"), advancedMenu); | 263 | font->insertItem(tr("Advanced Features"), advancedMenu); |
262 | 264 | ||
263 | QAction *wa = new QAction( tr("Wrap lines"), | 265 | QAction *wa = new QAction( tr("Wrap lines"), |
264 | QString::null, 0, this, 0 ); | 266 | QString::null, 0, this, 0 ); |
265 | connect( wa, SIGNAL( toggled(bool) ), | 267 | connect( wa, SIGNAL( toggled(bool) ), |
266 | this, SLOT( setWordWrap(bool) ) ); | 268 | this, SLOT( setWordWrap(bool) ) ); |
267 | wa->setToggleAction(true); | 269 | wa->setToggleAction(true); |
268 | wa->addTo( advancedMenu); | 270 | wa->addTo( advancedMenu); |
269 | 271 | ||
270 | nStart = new QAction( tr("Start with new file"), | 272 | nStart = new QAction( tr("Start with new file"), |
271 | QString::null, 0, this, 0 ); | 273 | QString::null, 0, this, 0 ); |
272 | connect( nStart, SIGNAL( toggled(bool) ), | 274 | connect( nStart, SIGNAL( toggled(bool) ), |
273 | this, SLOT( changeStartConfig(bool) ) ); | 275 | this, SLOT( changeStartConfig(bool) ) ); |
274 | nStart->setToggleAction(true); | 276 | nStart->setToggleAction(true); |
275 | nStart->addTo( advancedMenu ); | 277 | nStart->addTo( advancedMenu ); |
276 | nStart->setEnabled(false); | 278 | nStart->setEnabled(false); |
277 | 279 | ||
278 | nAdvanced = new QAction( tr("Prompt on Exit"), | 280 | nAdvanced = new QAction( tr("Prompt on Exit"), |
279 | QString::null, 0, this, 0 ); | 281 | QString::null, 0, this, 0 ); |
280 | connect( nAdvanced, SIGNAL( toggled(bool) ), | 282 | connect( nAdvanced, SIGNAL( toggled(bool) ), |
281 | this, SLOT( doPrompt(bool) ) ); | 283 | this, SLOT( doPrompt(bool) ) ); |
282 | nAdvanced->setToggleAction(true); | 284 | nAdvanced->setToggleAction(true); |
283 | nAdvanced->addTo( advancedMenu ); | 285 | nAdvanced->addTo( advancedMenu ); |
284 | 286 | ||
285 | desktopAction = new QAction( tr("Always open linked file"), | 287 | desktopAction = new QAction( tr("Always open linked file"), |
286 | QString::null, 0, this, 0 ); | 288 | QString::null, 0, this, 0 ); |
287 | connect( desktopAction, SIGNAL( toggled(bool) ), | 289 | connect( desktopAction, SIGNAL( toggled(bool) ), |
288 | this, SLOT( doDesktop(bool) ) ); | 290 | this, SLOT( doDesktop(bool) ) ); |
289 | desktopAction->setToggleAction(true); | 291 | desktopAction->setToggleAction(true); |
290 | desktopAction->addTo( advancedMenu); | 292 | desktopAction->addTo( advancedMenu); |
291 | 293 | ||
292 | filePermAction = new QAction( tr("File Permissions"), | 294 | filePermAction = new QAction( tr("File Permissions"), |
293 | QString::null, 0, this, 0 ); | 295 | QString::null, 0, this, 0 ); |
294 | connect( filePermAction, SIGNAL( toggled(bool) ), | 296 | connect( filePermAction, SIGNAL( toggled(bool) ), |
295 | this, SLOT( doFilePerms(bool) ) ); | 297 | this, SLOT( doFilePerms(bool) ) ); |
296 | filePermAction->setToggleAction(true); | 298 | filePermAction->setToggleAction(true); |
297 | filePermAction->addTo( advancedMenu); | 299 | filePermAction->addTo( advancedMenu); |
298 | 300 | ||
299 | searchBarAction = new QAction( tr("Search Bar Open"), | 301 | searchBarAction = new QAction( tr("Search Bar Open"), |
300 | QString::null, 0, this, 0 ); | 302 | QString::null, 0, this, 0 ); |
301 | connect( searchBarAction, SIGNAL( toggled(bool) ), | 303 | connect( searchBarAction, SIGNAL( toggled(bool) ), |
302 | this, SLOT( setSearchBar(bool) ) ); | 304 | this, SLOT( setSearchBar(bool) ) ); |
303 | searchBarAction->setToggleAction(true); | 305 | searchBarAction->setToggleAction(true); |
304 | searchBarAction->addTo( advancedMenu); | 306 | searchBarAction->addTo( advancedMenu); |
305 | 307 | ||
306 | nAutoSave = new QAction( tr("Auto Save 5 min."), | 308 | nAutoSave = new QAction( tr("Auto Save 5 min."), |
307 | QString::null, 0, this, 0 ); | 309 | QString::null, 0, this, 0 ); |
308 | connect( nAutoSave, SIGNAL( toggled(bool) ), | 310 | connect( nAutoSave, SIGNAL( toggled(bool) ), |
309 | this, SLOT( doTimer(bool) ) ); | 311 | this, SLOT( doTimer(bool) ) ); |
310 | nAutoSave->setToggleAction(true); | 312 | nAutoSave->setToggleAction(true); |
311 | nAutoSave->addTo( advancedMenu); | 313 | nAutoSave->addTo( advancedMenu); |
312 | 314 | ||
313 | 315 | ||
314 | //font->insertSeparator(); | 316 | //font->insertSeparator(); |
315 | 317 | ||
316 | //font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 318 | //font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
317 | 319 | ||
318 | mb->insertItem( tr( "File" ), file ); | 320 | mb->insertItem( tr( "File" ), file ); |
319 | mb->insertItem( tr( "Edit" ), edit ); | 321 | mb->insertItem( tr( "Edit" ), edit ); |
320 | mb->insertItem( tr( "View" ), font ); | 322 | mb->insertItem( tr( "View" ), font ); |
321 | 323 | ||
322 | searchBar = new QToolBar(this); | 324 | searchBar = new QToolBar(this); |
323 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 325 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
324 | 326 | ||
325 | searchBar->setHorizontalStretchable( true ); | 327 | searchBar->setHorizontalStretchable( true ); |
326 | 328 | ||
327 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 329 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
328 | searchBar->setStretchableWidget( searchEdit ); | 330 | searchBar->setStretchableWidget( searchEdit ); |
329 | connect( searchEdit, SIGNAL( textChanged(const QString&) ), | 331 | connect( searchEdit, SIGNAL( textChanged(const QString&) ), |
330 | this, SLOT( search() ) ); | 332 | this, SLOT( search() ) ); |
331 | 333 | ||
332 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), | 334 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), |
333 | QString::null, 0, this, 0 ); | 335 | QString::null, 0, this, 0 ); |
334 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 336 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
335 | a->addTo( searchBar ); | 337 | a->addTo( searchBar ); |
336 | a->addTo( edit ); | 338 | a->addTo( edit ); |
337 | 339 | ||
338 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), | 340 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), |
339 | QString::null, 0, this, 0 ); | 341 | QString::null, 0, this, 0 ); |
340 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 342 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
341 | a->addTo( searchBar ); | 343 | a->addTo( searchBar ); |
342 | 344 | ||
343 | edit->insertSeparator(); | 345 | edit->insertSeparator(); |
344 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), | 346 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), |
345 | QString::null, 0, this, 0 ); | 347 | QString::null, 0, this, 0 ); |
346 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 348 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
347 | a->addTo( edit ); | 349 | a->addTo( edit ); |
348 | 350 | ||
349 | searchBar->hide(); | 351 | searchBar->hide(); |
350 | 352 | ||
351 | editor = new QpeEditor( this ); | 353 | editor = new QpeEditor( this ); |
352 | setCentralWidget( editor ); | 354 | setCentralWidget( editor ); |
353 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 355 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
354 | connect( editor, SIGNAL( textChanged() ), | 356 | connect( editor, SIGNAL( textChanged() ), |
355 | this, SLOT( editorChanged() ) ); | 357 | this, SLOT( editorChanged() ) ); |
356 | 358 | ||
357 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); | 359 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); |
358 | 360 | ||
359 | Config cfg("TextEdit"); | 361 | Config cfg("TextEdit"); |
360 | cfg. setGroup ( "Font" ); | 362 | cfg. setGroup ( "Font" ); |
361 | 363 | ||
362 | QFont defaultFont = editor-> font ( ); | 364 | QFont defaultFont = editor-> font ( ); |
363 | 365 | ||
364 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); | 366 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); |
365 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); | 367 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); |
366 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); | 368 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); |
367 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); | 369 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); |
368 | 370 | ||
369 | defaultFont = QFont ( family, size, weight, italic ); | 371 | defaultFont = QFont ( family, size, weight, italic ); |
370 | editor-> setFont ( defaultFont ); | 372 | editor-> setFont ( defaultFont ); |
371 | // updateCaption(); | 373 | // updateCaption(); |
372 | 374 | ||
373 | cfg.setGroup ( "View" ); | 375 | cfg.setGroup ( "View" ); |
374 | 376 | ||
375 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); | 377 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
376 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); | 378 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
377 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); | 379 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
378 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | 380 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); |
379 | startWithNew = cfg.readBoolEntry ( "startNew", true); | 381 | startWithNew = cfg.readBoolEntry ( "startNew", true); |
380 | featureAutoSave = cfg.readBoolEntry( "autosave", false); | 382 | featureAutoSave = cfg.readBoolEntry( "autosave", false); |
381 | 383 | ||
382 | if(useSearchBar) searchBarAction->setOn(true); | 384 | if(useSearchBar) searchBarAction->setOn(true); |
383 | if(promptExit) nAdvanced->setOn( true ); | 385 | if(promptExit) nAdvanced->setOn( true ); |
384 | if(openDesktop) desktopAction->setOn( true ); | 386 | if(openDesktop) desktopAction->setOn( true ); |
385 | if(filePerms) filePermAction->setOn( true ); | 387 | if(filePerms) filePermAction->setOn( true ); |
386 | if(startWithNew) nStart->setOn( true ); | 388 | if(startWithNew) nStart->setOn( true ); |
387 | if(featureAutoSave) nAutoSave->setOn(true); | 389 | if(featureAutoSave) nAutoSave->setOn(true); |
388 | 390 | ||
389 | // { | 391 | // { |
390 | // doTimer(true); | 392 | // doTimer(true); |
391 | // } | 393 | // } |
392 | 394 | ||
393 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 395 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
394 | wa-> setOn ( wrap ); | 396 | wa-> setOn ( wrap ); |
395 | setWordWrap ( wrap ); | 397 | setWordWrap ( wrap ); |
396 | 398 | ||
397 | ///////////////// | 399 | ///////////////// |
398 | if( qApp->argc() > 1) { | 400 | if( qApp->argc() > 1) { |
399 | currentFileName=qApp->argv()[1]; | 401 | currentFileName=qApp->argv()[1]; |
400 | 402 | ||
401 | QFileInfo fi(currentFileName); | 403 | QFileInfo fi(currentFileName); |
402 | 404 | ||
403 | if(fi.baseName().left(1) == "") { | 405 | if(fi.baseName().left(1) == "") { |
404 | openDotFile(currentFileName); | 406 | openDotFile(currentFileName); |
405 | } else { | 407 | } else { |
406 | openFile(currentFileName); | 408 | openFile(currentFileName); |
407 | } | 409 | } |
408 | } else { | 410 | } else { |
409 | edited1=false; | 411 | edited1=false; |
410 | openDotFile(""); | 412 | openDotFile(""); |
411 | } | 413 | } |
412 | 414 | ||
413 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 415 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
414 | } | 416 | } |
415 | 417 | ||
416 | TextEdit::~TextEdit() { | 418 | TextEdit::~TextEdit() { |
417 | owarn << "textedit d'tor" << oendl; | 419 | owarn << "textedit d'tor" << oendl; |
418 | delete editor; | 420 | delete editor; |
419 | } | 421 | } |
420 | 422 | ||
421 | void TextEdit::closeEvent(QCloseEvent *) { | 423 | void TextEdit::closeEvent(QCloseEvent *) { |
422 | if( edited1 && promptExit) | 424 | if( edited1 && promptExit) |
423 | { | 425 | { |
424 | switch( savePrompt() ) | 426 | switch( savePrompt() ) |
425 | { | 427 | { |
426 | case 1: | 428 | case 1: |
427 | { | 429 | { |
428 | saveAs(); | 430 | saveAs(); |
429 | qApp->quit(); | 431 | qApp->quit(); |
430 | } | 432 | } |
431 | break; | 433 | break; |
432 | 434 | ||
433 | case 2: | 435 | case 2: |
434 | { | 436 | { |
435 | qApp->quit(); | 437 | qApp->quit(); |
436 | } | 438 | } |
437 | break; | 439 | break; |
438 | 440 | ||
439 | case -1: | 441 | case -1: |
440 | break; | 442 | break; |
441 | }; | 443 | }; |
442 | } | 444 | } |
443 | else | 445 | else |
444 | qApp->quit(); | 446 | qApp->quit(); |
445 | 447 | ||
446 | } | 448 | } |
447 | 449 | ||
448 | void TextEdit::cleanUp() { | 450 | void TextEdit::cleanUp() { |
449 | 451 | ||
450 | Config cfg ( "TextEdit" ); | 452 | Config cfg ( "TextEdit" ); |
451 | cfg. setGroup ( "Font" ); | 453 | cfg. setGroup ( "Font" ); |
452 | QFont f = editor->font(); | 454 | QFont f = editor->font(); |
453 | cfg.writeEntry ( "Family", f. family ( )); | 455 | cfg.writeEntry ( "Family", f. family ( )); |
454 | cfg.writeEntry ( "Size", f. pointSize ( )); | 456 | cfg.writeEntry ( "Size", f. pointSize ( )); |
455 | cfg.writeEntry ( "Weight", f. weight ( )); | 457 | cfg.writeEntry ( "Weight", f. weight ( )); |
456 | cfg.writeEntry ( "Italic", f. italic ( )); | 458 | cfg.writeEntry ( "Italic", f. italic ( )); |
457 | 459 | ||
458 | cfg.setGroup ( "View" ); | 460 | cfg.setGroup ( "View" ); |
459 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 461 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
460 | cfg.writeEntry ( "FileView", viewSelection ); | 462 | cfg.writeEntry ( "FileView", viewSelection ); |
461 | 463 | ||
462 | cfg.writeEntry ( "PromptExit", promptExit ); | 464 | cfg.writeEntry ( "PromptExit", promptExit ); |
463 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 465 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
464 | cfg.writeEntry ( "FilePermissions", filePerms ); | 466 | cfg.writeEntry ( "FilePermissions", filePerms ); |
465 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 467 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
466 | cfg.writeEntry ( "startNew", startWithNew ); | 468 | cfg.writeEntry ( "startNew", startWithNew ); |
467 | 469 | ||
468 | } | 470 | } |
469 | 471 | ||
470 | 472 | ||
471 | void TextEdit::accept() { | 473 | void TextEdit::accept() { |
472 | if( edited1) | 474 | if( edited1) |
473 | saveAs(); | 475 | saveAs(); |
474 | qApp->quit(); | 476 | qApp->quit(); |
475 | } | 477 | } |
476 | 478 | ||
477 | void TextEdit::zoomIn() { | 479 | void TextEdit::zoomIn() { |
478 | setFontSize(editor->font().pointSize()+1,false); | 480 | setFontSize(editor->font().pointSize()+1,false); |
479 | } | 481 | } |
480 | 482 | ||
481 | void TextEdit::zoomOut() { | 483 | void TextEdit::zoomOut() { |
482 | setFontSize(editor->font().pointSize()-1,true); | 484 | setFontSize(editor->font().pointSize()-1,true); |
483 | } | 485 | } |
484 | 486 | ||
485 | 487 | ||
486 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 488 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
487 | int s=10; | 489 | int s=10; |
488 | for (int i=0; i<nfontsizes; i++) { | 490 | for (int i=0; i<nfontsizes; i++) { |
489 | if ( fontsize[i] == sz ) { | 491 | if ( fontsize[i] == sz ) { |
490 | s = sz; | 492 | s = sz; |
491 | break; | 493 | break; |
492 | } else if ( round_down_not_up ) { | 494 | } else if ( round_down_not_up ) { |
493 | if ( fontsize[i] < sz ) | 495 | if ( fontsize[i] < sz ) |
494 | s = fontsize[i]; | 496 | s = fontsize[i]; |
495 | } else { | 497 | } else { |
496 | if ( fontsize[i] > sz ) { | 498 | if ( fontsize[i] > sz ) { |
497 | s = fontsize[i]; | 499 | s = fontsize[i]; |
498 | break; | 500 | break; |
499 | } | 501 | } |
500 | } | 502 | } |
501 | } | 503 | } |
502 | 504 | ||
503 | QFont f = editor->font(); | 505 | QFont f = editor->font(); |
504 | f.setPointSize(s); | 506 | f.setPointSize(s); |
505 | editor->setFont(f); | 507 | editor->setFont(f); |
506 | 508 | ||
507 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 509 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
508 | zout->setEnabled(s != fontsize[0]); | 510 | zout->setEnabled(s != fontsize[0]); |
509 | } | 511 | } |
510 | 512 | ||
511 | void TextEdit::setBold(bool y) { | 513 | void TextEdit::setBold(bool y) { |
512 | QFont f = editor->font(); | 514 | QFont f = editor->font(); |
513 | f.setBold(y); | 515 | f.setBold(y); |
514 | editor->setFont(f); | 516 | editor->setFont(f); |
515 | } | 517 | } |
516 | 518 | ||
517 | void TextEdit::setItalic(bool y) { | 519 | void TextEdit::setItalic(bool y) { |
518 | QFont f = editor->font(); | 520 | QFont f = editor->font(); |
519 | f.setItalic(y); | 521 | f.setItalic(y); |
520 | editor->setFont(f); | 522 | editor->setFont(f); |
521 | } | 523 | } |
522 | 524 | ||
523 | void TextEdit::setWordWrap(bool y) { | 525 | void TextEdit::setWordWrap(bool y) { |
524 | bool state = editor->edited(); | 526 | bool state = editor->edited(); |
525 | QString captionStr = caption(); | 527 | QString captionStr = caption(); |
526 | bool b1 = edited1; | 528 | bool b1 = edited1; |
527 | bool b2 = edited; | 529 | bool b2 = edited; |
528 | 530 | ||
529 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 531 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
530 | editor->setEdited( state ); | 532 | editor->setEdited( state ); |
531 | edited1=b1; | 533 | edited1=b1; |
532 | edited=b2; | 534 | edited=b2; |
533 | setCaption(captionStr); | 535 | setCaption(captionStr); |
534 | } | 536 | } |
535 | 537 | ||
536 | void TextEdit::setSearchBar(bool b) { | 538 | void TextEdit::setSearchBar(bool b) { |
537 | useSearchBar=b; | 539 | useSearchBar=b; |
538 | Config cfg("TextEdit"); | 540 | Config cfg("TextEdit"); |
539 | cfg.setGroup("View"); | 541 | cfg.setGroup("View"); |
540 | cfg.writeEntry ( "SearchBar", b ); | 542 | cfg.writeEntry ( "SearchBar", b ); |
541 | searchBarAction->setOn(b); | 543 | searchBarAction->setOn(b); |
542 | if(b) | 544 | if(b) |
543 | searchBar->show(); | 545 | searchBar->show(); |
544 | else | 546 | else |
545 | searchBar->hide(); | 547 | searchBar->hide(); |
546 | editor->setFocus(); | 548 | editor->setFocus(); |
547 | } | 549 | } |
548 | 550 | ||
549 | void TextEdit::fileNew() { | 551 | void TextEdit::fileNew() { |
550 | // if( !bFromDocView ) { | 552 | // if( !bFromDocView ) { |
551 | // saveAs(); | 553 | // saveAs(); |
552 | // } | 554 | // } |
553 | newFile(DocLnk()); | 555 | newFile(DocLnk()); |
554 | } | 556 | } |
555 | 557 | ||
556 | void TextEdit::fileOpen() { | 558 | void TextEdit::fileOpen() { |
557 | Config cfg("TextEdit"); | 559 | Config cfg("TextEdit"); |