-rw-r--r-- | core/apps/textedit/.cvsignore | 3 | ||||
-rw-r--r-- | core/apps/textedit/Makefile.in | 125 | ||||
-rw-r--r-- | core/apps/textedit/inserttable.ui | 103 | ||||
-rw-r--r-- | core/apps/textedit/main.cpp | 35 | ||||
-rw-r--r-- | core/apps/textedit/qpe-textedit.control | 9 | ||||
-rw-r--r-- | core/apps/textedit/qtextedit.h | 282 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 594 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 102 | ||||
-rw-r--r-- | core/apps/textedit/textedit.po | 108 | ||||
-rw-r--r-- | core/apps/textedit/textedit.pro | 16 |
10 files changed, 1377 insertions, 0 deletions
diff --git a/core/apps/textedit/.cvsignore b/core/apps/textedit/.cvsignore new file mode 100644 index 0000000..edfa921 --- a/dev/null +++ b/core/apps/textedit/.cvsignore | |||
@@ -0,0 +1,3 @@ | |||
1 | moc_* | ||
2 | *.moc | ||
3 | Makefile | ||
diff --git a/core/apps/textedit/Makefile.in b/core/apps/textedit/Makefile.in new file mode 100644 index 0000000..84542bb --- a/dev/null +++ b/core/apps/textedit/Makefile.in | |||
@@ -0,0 +1,125 @@ | |||
1 | ############################################################################# | ||
2 | |||
3 | ####### Compiler, tools and options | ||
4 | |||
5 | CXX =$(SYSCONF_CXX) $(QT_CXX_MT) | ||
6 | CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) | ||
7 | CC =$(SYSCONF_CC) $(QT_C_MT) | ||
8 | CFLAGS =$(SYSCONF_CFLAGS) | ||
9 | INCPATH =-I$(QPEDIR)/include | ||
10 | LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) | ||
11 | LIBS =$(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP) | ||
12 | MOC =$(SYSCONF_MOC) | ||
13 | UIC =$(SYSCONF_UIC) | ||
14 | |||
15 | ####### Target | ||
16 | |||
17 | DESTDIR = $(QPEDIR)/bin/ | ||
18 | VER_MAJ = 1 | ||
19 | VER_MIN = 0 | ||
20 | VER_PATCH = 0 | ||
21 | TARGET= textedit | ||
22 | TARGET1 = lib$(TARGET).so.$(VER_MAJ) | ||
23 | |||
24 | ####### Files | ||
25 | |||
26 | HEADERS =textedit.h | ||
27 | SOURCES =main.cpp \ | ||
28 | textedit.cpp | ||
29 | OBJECTS =main.o \ | ||
30 | textedit.o | ||
31 | INTERFACES = | ||
32 | UICDECLS = | ||
33 | UICIMPLS = | ||
34 | SRCMOC =moc_textedit.cpp | ||
35 | OBJMOC =moc_textedit.o | ||
36 | |||
37 | |||
38 | ####### Implicit rules | ||
39 | |||
40 | .SUFFIXES: .cpp .cxx .cc .C .c | ||
41 | |||
42 | .cpp.o: | ||
43 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
44 | |||
45 | .cxx.o: | ||
46 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
47 | |||
48 | .cc.o: | ||
49 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
50 | |||
51 | .C.o: | ||
52 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< | ||
53 | |||
54 | .c.o: | ||
55 | $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< | ||
56 | |||
57 | ####### Build rules | ||
58 | |||
59 | |||
60 | all: $(DESTDIR)$(TARGET) | ||
61 | |||
62 | $(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) | ||
63 | $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) | ||
64 | |||
65 | moc: $(SRCMOC) | ||
66 | |||
67 | tmake: | ||
68 | tmake textedit.pro | ||
69 | |||
70 | clean: | ||
71 | -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) | ||
72 | -rm -f *~ core | ||
73 | -rm -f allmoc.cpp | ||
74 | |||
75 | ####### Extension Modules | ||
76 | |||
77 | listpromodules: | ||
78 | @echo | ||
79 | |||
80 | listallmodules: | ||
81 | @echo | ||
82 | |||
83 | listaddonpromodules: | ||
84 | @echo | ||
85 | |||
86 | listaddonentmodules: | ||
87 | @echo | ||
88 | |||
89 | |||
90 | REQUIRES= | ||
91 | |||
92 | ####### Sub-libraries | ||
93 | |||
94 | |||
95 | ###### Combined headers | ||
96 | |||
97 | |||
98 | |||
99 | ####### Compile | ||
100 | |||
101 | main.o: main.cpp \ | ||
102 | textedit.h \ | ||
103 | $(QPEDIR)/include/qpe/filemanager.h \ | ||
104 | $(QPEDIR)/include/qpe/qpeapplication.h | ||
105 | |||
106 | textedit.o: textedit.cpp \ | ||
107 | textedit.h \ | ||
108 | $(QPEDIR)/include/qpe/filemanager.h \ | ||
109 | $(QPEDIR)/include/qpe/global.h \ | ||
110 | $(QPEDIR)/include/qpe/fileselector.h \ | ||
111 | $(QPEDIR)/include/qpe/applnk.h \ | ||
112 | $(QPEDIR)/include/qpe/resource.h \ | ||
113 | $(QPEDIR)/include/qpe/config.h \ | ||
114 | $(QPEDIR)/include/qpe/qpeapplication.h \ | ||
115 | $(QPEDIR)/include/qpe/qpemenubar.h \ | ||
116 | $(QPEDIR)/include/qpe/qpetoolbar.h | ||
117 | |||
118 | moc_textedit.o: moc_textedit.cpp \ | ||
119 | textedit.h \ | ||
120 | $(QPEDIR)/include/qpe/filemanager.h | ||
121 | |||
122 | moc_textedit.cpp: textedit.h | ||
123 | $(MOC) textedit.h -o moc_textedit.cpp | ||
124 | |||
125 | |||
diff --git a/core/apps/textedit/inserttable.ui b/core/apps/textedit/inserttable.ui new file mode 100644 index 0000000..09fe3c3 --- a/dev/null +++ b/core/apps/textedit/inserttable.ui | |||
@@ -0,0 +1,103 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>InsertTable</class><comment>********************************************************************* | ||
3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
4 | ** | ||
5 | ** This file is part of Qtopia Environment. | ||
6 | ** | ||
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 | ||
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
10 | ** packaging of this file. | ||
11 | ** | ||
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
14 | ** | ||
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
16 | ** | ||
17 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
18 | ** not clear to you. | ||
19 | ** | ||
20 | *********************************************************************</comment> | ||
21 | <widget> | ||
22 | <class>QDialog</class> | ||
23 | <property stdset="1"> | ||
24 | <name>name</name> | ||
25 | <cstring>InsertTable</cstring> | ||
26 | </property> | ||
27 | <property stdset="1"> | ||
28 | <name>geometry</name> | ||
29 | <rect> | ||
30 | <x>0</x> | ||
31 | <y>0</y> | ||
32 | <width>165</width> | ||
33 | <height>79</height> | ||
34 | </rect> | ||
35 | </property> | ||
36 | <property stdset="1"> | ||
37 | <name>caption</name> | ||
38 | <string>Insert Table</string> | ||
39 | </property> | ||
40 | <grid> | ||
41 | <property stdset="1"> | ||
42 | <name>margin</name> | ||
43 | <number>11</number> | ||
44 | </property> | ||
45 | <property stdset="1"> | ||
46 | <name>spacing</name> | ||
47 | <number>6</number> | ||
48 | </property> | ||
49 | <widget row="0" column="0" > | ||
50 | <class>QLabel</class> | ||
51 | <property stdset="1"> | ||
52 | <name>name</name> | ||
53 | <cstring>TextLabel1</cstring> | ||
54 | </property> | ||
55 | <property stdset="1"> | ||
56 | <name>text</name> | ||
57 | <string>Rows:</string> | ||
58 | </property> | ||
59 | </widget> | ||
60 | <widget row="0" column="1" > | ||
61 | <class>QSpinBox</class> | ||
62 | <property stdset="1"> | ||
63 | <name>name</name> | ||
64 | <cstring>spinRows</cstring> | ||
65 | </property> | ||
66 | <property stdset="1"> | ||
67 | <name>minValue</name> | ||
68 | <number>1</number> | ||
69 | </property> | ||
70 | <property stdset="1"> | ||
71 | <name>value</name> | ||
72 | <number>1</number> | ||
73 | </property> | ||
74 | </widget> | ||
75 | <widget row="1" column="1" > | ||
76 | <class>QSpinBox</class> | ||
77 | <property stdset="1"> | ||
78 | <name>name</name> | ||
79 | <cstring>spinColumns</cstring> | ||
80 | </property> | ||
81 | <property stdset="1"> | ||
82 | <name>minValue</name> | ||
83 | <number>1</number> | ||
84 | </property> | ||
85 | <property stdset="1"> | ||
86 | <name>value</name> | ||
87 | <number>1</number> | ||
88 | </property> | ||
89 | </widget> | ||
90 | <widget row="1" column="0" > | ||
91 | <class>QLabel</class> | ||
92 | <property stdset="1"> | ||
93 | <name>name</name> | ||
94 | <cstring>TextLabel1_2</cstring> | ||
95 | </property> | ||
96 | <property stdset="1"> | ||
97 | <name>text</name> | ||
98 | <string>Columns:</string> | ||
99 | </property> | ||
100 | </widget> | ||
101 | </grid> | ||
102 | </widget> | ||
103 | </UI> | ||
diff --git a/core/apps/textedit/main.cpp b/core/apps/textedit/main.cpp new file mode 100644 index 0000000..d0d37d2 --- a/dev/null +++ b/core/apps/textedit/main.cpp | |||
@@ -0,0 +1,35 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "textedit.h" | ||
22 | |||
23 | #include <qpe/qpeapplication.h> | ||
24 | |||
25 | int main( int argc, char **argv ) | ||
26 | { | ||
27 | QPEApplication a( argc, argv ); | ||
28 | |||
29 | TextEdit e; | ||
30 | a.showMainDocumentWidget(&e); | ||
31 | if ( argc == 3 && argv[1] == QCString("-f") ) | ||
32 | e.openFile(argv[2]); | ||
33 | |||
34 | a.exec(); | ||
35 | } | ||
diff --git a/core/apps/textedit/qpe-textedit.control b/core/apps/textedit/qpe-textedit.control new file mode 100644 index 0000000..b0dad7d --- a/dev/null +++ b/core/apps/textedit/qpe-textedit.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Files: bin/textedit apps/Applications/textedit.desktop | ||
2 | Priority: optional | ||
3 | Section: qpe/applications | ||
4 | Maintainer: Warwick Allison <warwick@trolltech.com> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-3 | ||
7 | Depends: qpe-base ($QPE_VERSION) | ||
8 | Description: Text Editor | ||
9 | The text editor for the Qtopia environment. | ||
diff --git a/core/apps/textedit/qtextedit.h b/core/apps/textedit/qtextedit.h new file mode 100644 index 0000000..b29a728 --- a/dev/null +++ b/core/apps/textedit/qtextedit.h | |||
@@ -0,0 +1,282 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #ifndef QTEXTEDIT_H | ||
22 | #define QTEXTEDIT_H | ||
23 | |||
24 | #include <qscrollview.h> | ||
25 | #include <qstylesheet.h> | ||
26 | #include <qpainter.h> | ||
27 | |||
28 | class QPainter; | ||
29 | class QTextDocument; | ||
30 | class QTextCursor; | ||
31 | class QKeyEvent; | ||
32 | class QResizeEvent; | ||
33 | class QMouseEvent; | ||
34 | class QTimer; | ||
35 | class QTextString; | ||
36 | class QVBox; | ||
37 | class QListBox; | ||
38 | class QTextCommand; | ||
39 | class QTextParag; | ||
40 | class QTextFormat; | ||
41 | class QFont; | ||
42 | class QColor; | ||
43 | |||
44 | class QTextEdit : public QScrollView | ||
45 | { | ||
46 | Q_OBJECT | ||
47 | |||
48 | public: | ||
49 | QTextEdit( QWidget *parent, const QString &fn, bool tabify = FALSE ); | ||
50 | QTextEdit( QWidget *parent = 0, const char *name = 0 ); | ||
51 | virtual ~QTextEdit(); | ||
52 | |||
53 | #if defined(QTEXTEDIT_OPEN_API) | ||
54 | QTextDocument *document() const; | ||
55 | QTextCursor *textCursor() const; | ||
56 | #endif | ||
57 | |||
58 | QString text() const; | ||
59 | QString text( int parag, bool formatted = FALSE ) const; | ||
60 | Qt::TextFormat textFormat() const; | ||
61 | QString fileName() const; | ||
62 | |||
63 | void cursorPosition( int ¶g, int &index ); | ||
64 | void selection( int ¶g_from, int &index_from, | ||
65 | int ¶g_to, int &index_to ); | ||
66 | virtual bool find( const QString &expr, bool cs, bool wo, bool forward = TRUE, | ||
67 | int *parag = 0, int *index = 0 ); | ||
68 | void insert( const QString &text, bool indent = FALSE, bool checkNewLine = FALSE ); | ||
69 | |||
70 | int paragraphs() const; | ||
71 | int lines() const; | ||
72 | int linesOfParagraph( int parag ) const; | ||
73 | int lineOfChar( int parag, int chr ); | ||
74 | |||
75 | bool isModified() const; | ||
76 | |||
77 | bool italic() const; | ||
78 | bool bold() const; | ||
79 | bool underline() const; | ||
80 | QString family() const; | ||
81 | int pointSize() const; | ||
82 | QColor color() const; | ||
83 | QFont font() const; | ||
84 | int alignment() const; | ||
85 | int maxLines() const; | ||
86 | |||
87 | const QStyleSheet* styleSheet() const; | ||
88 | void setStyleSheet( const QStyleSheet* styleSheet ); | ||
89 | |||
90 | void setPaper( const QBrush& pap); | ||
91 | QBrush paper() const; | ||
92 | |||
93 | void setLinkColor( const QColor& ); | ||
94 | QColor linkColor() const; | ||
95 | |||
96 | void setLinkUnderline( bool ); | ||
97 | bool linkUnderline() const; | ||
98 | |||
99 | void setMimeSourceFactory( const QMimeSourceFactory* factory ); | ||
100 | const QMimeSourceFactory* mimeSourceFactory() const; | ||
101 | |||
102 | int heightForWidth( int w ) const; | ||
103 | |||
104 | void append( const QString& text ); | ||
105 | |||
106 | bool hasSelectedText() const; | ||
107 | QString selectedText() const; | ||
108 | |||
109 | QString context() const; | ||
110 | |||
111 | QString documentTitle() const; | ||
112 | |||
113 | void scrollToAnchor( const QString& name ); | ||
114 | QString anchorAt(const QPoint& pos); | ||
115 | |||
116 | public slots: | ||
117 | virtual void undo(); | ||
118 | virtual void redo(); | ||
119 | |||
120 | virtual void cut(); | ||
121 | virtual void copy(); | ||
122 | virtual void paste(); | ||
123 | |||
124 | virtual void indent(); | ||
125 | |||
126 | virtual void setItalic( bool b ); | ||
127 | virtual void setBold( bool b ); | ||
128 | virtual void setUnderline( bool b ); | ||
129 | virtual void setFamily( const QString &f ); | ||
130 | virtual void setPointSize( int s ); | ||
131 | virtual void setColor( const QColor &c ); | ||
132 | virtual void setFont( const QFont &f ); | ||
133 | |||
134 | virtual void setAlignment( int ); | ||
135 | |||
136 | virtual void setParagType( QStyleSheetItem::DisplayMode, int listStyle ); | ||
137 | |||
138 | virtual void setTextFormat( Qt::TextFormat f ); | ||
139 | virtual void setText( const QString &txt, const QString &context = QString::null ) { setText( txt, context, FALSE ); } | ||
140 | virtual void setText( const QString &txt, const QString &context, bool tabify ); | ||
141 | |||
142 | virtual void load( const QString &fn ) { load( fn, FALSE ); } | ||
143 | virtual void load( const QString &fn, bool tabify ); | ||
144 | virtual void save( bool untabify = FALSE ) { save( QString::null, untabify ); } | ||
145 | virtual void save( const QString &fn, bool untabify = FALSE ); | ||
146 | |||
147 | virtual void setCursorPosition( int parag, int index ); | ||
148 | virtual void setSelection( int parag_from, int index_from, | ||
149 | int parag_to, int index_to ); | ||
150 | |||
151 | virtual void setModified( bool m ); | ||
152 | virtual void selectAll( bool select ); | ||
153 | |||
154 | virtual void setMaxLines( int l ); | ||
155 | virtual void resetFormat(); | ||
156 | |||
157 | signals: | ||
158 | void currentFontChanged( const QFont &f ); | ||
159 | void currentColorChanged( const QColor &c ); | ||
160 | void currentAlignmentChanged( int ); | ||
161 | void textChanged(); | ||
162 | void highlighted( const QString& ); | ||
163 | void linkClicked( const QString& ); | ||
164 | |||
165 | protected: | ||
166 | void setFormat( QTextFormat *f, int flags ); | ||
167 | void drawContents( QPainter *p, int cx, int cy, int cw, int ch ); | ||
168 | void keyPressEvent( QKeyEvent *e ); | ||
169 | void resizeEvent( QResizeEvent *e ); | ||
170 | void contentsMousePressEvent( QMouseEvent *e ); | ||
171 | void contentsMouseMoveEvent( QMouseEvent *e ); | ||
172 | void contentsMouseReleaseEvent( QMouseEvent *e ); | ||
173 | void contentsMouseDoubleClickEvent( QMouseEvent *e ); | ||
174 | #ifndef QT_NO_DRAGANDDROP | ||
175 | void contentsDragEnterEvent( QDragEnterEvent *e ); | ||
176 | void contentsDragMoveEvent( QDragMoveEvent *e ); | ||
177 | void contentsDragLeaveEvent( QDragLeaveEvent *e ); | ||
178 | void contentsDropEvent( QDropEvent *e ); | ||
179 | #endif | ||
180 | bool eventFilter( QObject *o, QEvent *e ); | ||
181 | bool focusNextPrevChild( bool next ); | ||
182 | #if !defined(QTEXTEDIT_OPEN_API) | ||
183 | QTextDocument *document() const; | ||
184 | QTextCursor *textCursor() const; | ||
185 | #endif | ||
186 | |||
187 | private slots: | ||
188 | void formatMore(); | ||
189 | void doResize(); | ||
190 | void doAutoScroll(); | ||
191 | void doChangeInterval(); | ||
192 | void blinkCursor(); | ||
193 | void setModified(); | ||
194 | void startDrag(); | ||
195 | |||
196 | private: | ||
197 | enum MoveDirection { | ||
198 | MoveLeft, | ||
199 | MoveRight, | ||
200 | MoveUp, | ||
201 | MoveDown, | ||
202 | MoveHome, | ||
203 | MoveEnd, | ||
204 | MovePgUp, | ||
205 | MovePgDown | ||
206 | }; | ||
207 | enum KeyboardAction { | ||
208 | ActionBackspace, | ||
209 | ActionDelete, | ||
210 | ActionReturn | ||
211 | }; | ||
212 | |||
213 | struct UndoRedoInfo { | ||
214 | enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected }; | ||
215 | UndoRedoInfo( QTextDocument *d ) : type( Invalid ), doc( d ) | ||
216 | { text = QString::null; id = -1; index = -1; } | ||
217 | void clear(); | ||
218 | inline bool valid() const { return !text.isEmpty() && id >= 0&& index >= 0; } | ||
219 | |||
220 | QString text; | ||
221 | int id; | ||
222 | int index; | ||
223 | Type type; | ||
224 | QTextDocument *doc; | ||
225 | }; | ||
226 | |||
227 | private: | ||
228 | virtual bool isReadOnly() const { return FALSE; } | ||
229 | virtual bool linksEnabled() const { return TRUE; } | ||
230 | void init(); | ||
231 | void ensureCursorVisible(); | ||
232 | void drawCursor( bool visible ); | ||
233 | void placeCursor( const QPoint &pos, QTextCursor *c = 0 ); | ||
234 | void moveCursor( int direction, bool shift, bool control ); | ||
235 | void moveCursor( int direction, bool control ); | ||
236 | void removeSelectedText(); | ||
237 | void doKeyboardAction( int action ); | ||
238 | bool doCompletion(); | ||
239 | void checkUndoRedoInfo( UndoRedoInfo::Type t ); | ||
240 | void repaintChanged(); | ||
241 | void updateCurrentFormat(); | ||
242 | void handleReadOnlyKeyEvent( QKeyEvent *e ); | ||
243 | void makeParagVisible( QTextParag *p ); | ||
244 | |||
245 | private: | ||
246 | QTextDocument *doc; | ||
247 | QTextCursor *cursor; | ||
248 | bool drawAll; | ||
249 | bool mousePressed; | ||
250 | QTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer, *resizeTimer; | ||
251 | QTextParag *lastFormatted; | ||
252 | int interval; | ||
253 | QVBox *completionPopup; | ||
254 | QListBox *completionListBox; | ||
255 | int completionOffset; | ||
256 | UndoRedoInfo undoRedoInfo; | ||
257 | QTextFormat *currentFormat; | ||
258 | QPainter painter; | ||
259 | int currentAlignment; | ||
260 | bool inDoubleClick; | ||
261 | QPoint oldMousePos, mousePos; | ||
262 | QPixmap *buf_pixmap; | ||
263 | bool cursorVisible, blinkCursorVisible; | ||
264 | bool readOnly, modified, mightStartDrag; | ||
265 | QPoint dragStartPos; | ||
266 | int mLines; | ||
267 | bool firstResize; | ||
268 | QString onLink; | ||
269 | |||
270 | }; | ||
271 | |||
272 | inline QTextDocument *QTextEdit::document() const | ||
273 | { | ||
274 | return doc; | ||
275 | } | ||
276 | |||
277 | inline QTextCursor *QTextEdit::textCursor() const | ||
278 | { | ||
279 | return cursor; | ||
280 | } | ||
281 | |||
282 | #endif | ||
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp new file mode 100644 index 0000000..867625e --- a/dev/null +++ b/core/apps/textedit/textedit.cpp | |||
@@ -0,0 +1,594 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "textedit.h" | ||
22 | |||
23 | #include <qpe/global.h> | ||
24 | #include <qpe/fileselector.h> | ||
25 | #include <qpe/applnk.h> | ||
26 | #include <qpe/resource.h> | ||
27 | #include <qpe/config.h> | ||
28 | #include <qpe/qpeapplication.h> | ||
29 | #include <qpe/qpemenubar.h> | ||
30 | #include <qpe/qpetoolbar.h> | ||
31 | //#include <qpe/finddialog.h> | ||
32 | |||
33 | #include <qaction.h> | ||
34 | #include <qcolordialog.h> | ||
35 | #include <qfileinfo.h> | ||
36 | #include <qlineedit.h> | ||
37 | #include <qmessagebox.h> | ||
38 | #include <qobjectlist.h> | ||
39 | #include <qpopupmenu.h> | ||
40 | #include <qspinbox.h> | ||
41 | #include <qtoolbutton.h> | ||
42 | #include <qwidgetstack.h> | ||
43 | |||
44 | #include <stdlib.h> //getenv | ||
45 | |||
46 | |||
47 | #if QT_VERSION < 300 | ||
48 | |||
49 | class QpeEditor : public QMultiLineEdit | ||
50 | { | ||
51 | // Q_OBJECT | ||
52 | public: | ||
53 | QpeEditor( QWidget *parent, const char * name = 0 ) | ||
54 | : QMultiLineEdit( parent, name ) {} | ||
55 | |||
56 | //public slots: | ||
57 | void find( const QString &txt, bool caseSensitive, | ||
58 | bool backwards ); | ||
59 | /* | ||
60 | signals: | ||
61 | void notFound(); | ||
62 | void searchWrapped(); | ||
63 | */ | ||
64 | |||
65 | private: | ||
66 | |||
67 | }; | ||
68 | |||
69 | |||
70 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | ||
71 | bool backwards ) | ||
72 | { | ||
73 | static bool wrap = FALSE; | ||
74 | int line, col; | ||
75 | if ( wrap ) { | ||
76 | if ( !backwards ) | ||
77 | line = col = 0; | ||
78 | wrap = FALSE; | ||
79 | //emit searchWrapped(); | ||
80 | } else { | ||
81 | getCursorPosition( &line, &col ); | ||
82 | } | ||
83 | //ignore backwards for now.... | ||
84 | if ( !backwards ) { | ||
85 | for ( ; ; ) { | ||
86 | if ( line >= numLines() ) { | ||
87 | wrap = TRUE; | ||
88 | //emit notFound(); | ||
89 | break; | ||
90 | } | ||
91 | int findCol = getString( line )->find( txt, col, caseSensitive ); | ||
92 | if ( findCol >= 0 ) { | ||
93 | setCursorPosition( line, findCol, FALSE ); | ||
94 | col = findCol + txt.length(); | ||
95 | setCursorPosition( line, col, TRUE ); | ||
96 | |||
97 | //found = TRUE; | ||
98 | break; | ||
99 | } | ||
100 | line++; | ||
101 | col = 0; | ||
102 | } | ||
103 | |||
104 | } | ||
105 | |||
106 | } | ||
107 | |||
108 | |||
109 | #else | ||
110 | |||
111 | #error "Must make a QpeEditor that inherits QTextEdit" | ||
112 | |||
113 | #endif | ||
114 | |||
115 | |||
116 | |||
117 | |||
118 | static int u_id = 1; | ||
119 | static int get_unique_id() | ||
120 | { | ||
121 | return u_id++; | ||
122 | } | ||
123 | |||
124 | static const int nfontsizes = 6; | ||
125 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | ||
126 | |||
127 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | ||
128 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | ||
129 | { | ||
130 | doc = 0; | ||
131 | |||
132 | QString lang = getenv( "LANG" ); | ||
133 | |||
134 | setToolBarsMovable( FALSE ); | ||
135 | |||
136 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | ||
137 | |||
138 | QPEToolBar *bar = new QPEToolBar( this ); | ||
139 | bar->setHorizontalStretchable( TRUE ); | ||
140 | menu = bar; | ||
141 | |||
142 | QPEMenuBar *mb = new QPEMenuBar( bar ); | ||
143 | QPopupMenu *file = new QPopupMenu( this ); | ||
144 | QPopupMenu *edit = new QPopupMenu( this ); | ||
145 | QPopupMenu *font = new QPopupMenu( this ); | ||
146 | |||
147 | bar = new QPEToolBar( this ); | ||
148 | editBar = bar; | ||
149 | |||
150 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | ||
151 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | ||
152 | a->addTo( bar ); | ||
153 | a->addTo( file ); | ||
154 | |||
155 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | ||
156 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | ||
157 | a->addTo( bar ); | ||
158 | a->addTo( file ); | ||
159 | |||
160 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | ||
161 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | ||
162 | a->addTo( editBar ); | ||
163 | a->addTo( edit ); | ||
164 | |||
165 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | ||
166 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | ||
167 | a->addTo( editBar ); | ||
168 | a->addTo( edit ); | ||
169 | |||
170 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | ||
171 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | ||
172 | a->addTo( editBar ); | ||
173 | a->addTo( edit ); | ||
174 | |||
175 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | ||
176 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | ||
177 | edit->insertSeparator(); | ||
178 | a->addTo( bar ); | ||
179 | a->addTo( edit ); | ||
180 | |||
181 | int defsize; | ||
182 | bool defb, defi, wrap; | ||
183 | { | ||
184 | Config cfg("TextEdit"); | ||
185 | cfg.setGroup("View"); | ||
186 | defsize = cfg.readNumEntry("FontSize",10); | ||
187 | defb = cfg.readBoolEntry("Bold",FALSE); | ||
188 | defi = cfg.readBoolEntry("Italic",FALSE); | ||
189 | wrap = cfg.readBoolEntry("Wrap",TRUE); | ||
190 | } | ||
191 | |||
192 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | ||
193 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | ||
194 | zin->addTo( font ); | ||
195 | |||
196 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | ||
197 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | ||
198 | zout->addTo( font ); | ||
199 | |||
200 | font->insertSeparator(); | ||
201 | |||
202 | #if 0 | ||
203 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | ||
204 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | ||
205 | ba->setToggleAction(TRUE); | ||
206 | ba->addTo( font ); | ||
207 | |||
208 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | ||
209 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); | ||
210 | ia->setToggleAction(TRUE); | ||
211 | ia->addTo( font ); | ||
212 | |||
213 | ba->setOn(defb); | ||
214 | ia->setOn(defi); | ||
215 | |||
216 | font->insertSeparator(); | ||
217 | #endif | ||
218 | |||
219 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | ||
220 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | ||
221 | wa->setToggleAction(TRUE); | ||
222 | wa->addTo( font ); | ||
223 | |||
224 | mb->insertItem( tr( "File" ), file ); | ||
225 | mb->insertItem( tr( "Edit" ), edit ); | ||
226 | mb->insertItem( tr( "View" ), font ); | ||
227 | |||
228 | searchBar = new QPEToolBar(this); | ||
229 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | ||
230 | |||
231 | searchBar->setHorizontalStretchable( TRUE ); | ||
232 | |||
233 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | ||
234 | searchBar->setStretchableWidget( searchEdit ); | ||
235 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | ||
236 | this, SLOT( search() ) ); | ||
237 | |||
238 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | ||
239 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | ||
240 | a->addTo( searchBar ); | ||
241 | a->addTo( edit ); | ||
242 | |||
243 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | ||
244 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | ||
245 | a->addTo( searchBar ); | ||
246 | |||
247 | searchBar->hide(); | ||
248 | |||
249 | editorStack = new QWidgetStack( this ); | ||
250 | setCentralWidget( editorStack ); | ||
251 | |||
252 | searchVisible = FALSE; | ||
253 | |||
254 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , | ||
255 | TRUE, FALSE ); | ||
256 | fileSelector->setCategoriesVisible(TRUE); | ||
257 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | ||
258 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | ||
259 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | ||
260 | fileOpen(); | ||
261 | |||
262 | editor = new QpeEditor( editorStack ); | ||
263 | editorStack->addWidget( editor, get_unique_id() ); | ||
264 | |||
265 | resize( 200, 300 ); | ||
266 | |||
267 | setFontSize(defsize,TRUE); | ||
268 | wa->setOn(wrap); | ||
269 | } | ||
270 | |||
271 | TextEdit::~TextEdit() | ||
272 | { | ||
273 | save(); | ||
274 | |||
275 | Config cfg("TextEdit"); | ||
276 | cfg.setGroup("View"); | ||
277 | QFont f = editor->font(); | ||
278 | cfg.writeEntry("FontSize",f.pointSize()); | ||
279 | cfg.writeEntry("Bold",f.bold()); | ||
280 | cfg.writeEntry("Italic",f.italic()); | ||
281 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | ||
282 | } | ||
283 | |||
284 | void TextEdit::zoomIn() | ||
285 | { | ||
286 | setFontSize(editor->font().pointSize()+1,FALSE); | ||
287 | } | ||
288 | |||
289 | void TextEdit::zoomOut() | ||
290 | { | ||
291 | setFontSize(editor->font().pointSize()-1,TRUE); | ||
292 | } | ||
293 | |||
294 | |||
295 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | ||
296 | { | ||
297 | int s=10; | ||
298 | for (int i=0; i<nfontsizes; i++) { | ||
299 | if ( fontsize[i] == sz ) { | ||
300 | s = sz; | ||
301 | break; | ||
302 | } else if ( round_down_not_up ) { | ||
303 | if ( fontsize[i] < sz ) | ||
304 | s = fontsize[i]; | ||
305 | } else { | ||
306 | if ( fontsize[i] > sz ) { | ||
307 | s = fontsize[i]; | ||
308 | break; | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | |||
313 | QFont f = editor->font(); | ||
314 | f.setPointSize(s); | ||
315 | editor->setFont(f); | ||
316 | |||
317 | zin->setEnabled(s != fontsize[nfontsizes-1]); | ||
318 | zout->setEnabled(s != fontsize[0]); | ||
319 | } | ||
320 | |||
321 | void TextEdit::setBold(bool y) | ||
322 | { | ||
323 | QFont f = editor->font(); | ||
324 | f.setBold(y); | ||
325 | editor->setFont(f); | ||
326 | } | ||
327 | |||
328 | void TextEdit::setItalic(bool y) | ||
329 | { | ||
330 | QFont f = editor->font(); | ||
331 | f.setItalic(y); | ||
332 | editor->setFont(f); | ||
333 | } | ||
334 | |||
335 | void TextEdit::setWordWrap(bool y) | ||
336 | { | ||
337 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | ||
338 | } | ||
339 | |||
340 | void TextEdit::fileNew() | ||
341 | { | ||
342 | save(); | ||
343 | newFile(DocLnk()); | ||
344 | } | ||
345 | |||
346 | void TextEdit::fileOpen() | ||
347 | { | ||
348 | if ( !save() ) { | ||
349 | if ( QMessageBox::critical( this, tr( "Out of space" ), | ||
350 | tr( "Text Editor was unable to\n" | ||
351 | "save your changes.\n" | ||
352 | "Free some space and try again.\n" | ||
353 | "\nContinue anyway?" ), | ||
354 | QMessageBox::Yes|QMessageBox::Escape, | ||
355 | QMessageBox::No|QMessageBox::Default ) | ||
356 | != QMessageBox::Yes ) | ||
357 | return; | ||
358 | else { | ||
359 | delete doc; | ||
360 | doc = 0; | ||
361 | } | ||
362 | } | ||
363 | menu->hide(); | ||
364 | editBar->hide(); | ||
365 | searchBar->hide(); | ||
366 | clearWState (WState_Reserved1 ); | ||
367 | editorStack->raiseWidget( fileSelector ); | ||
368 | fileSelector->reread(); | ||
369 | updateCaption(); | ||
370 | } | ||
371 | |||
372 | |||
373 | #if 0 | ||
374 | void TextEdit::slotFind() | ||
375 | { | ||
376 | FindDialog frmFind( "Text Editor", this ); | ||
377 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | ||
378 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | ||
379 | |||
380 | //case sensitive, backwards, [category] | ||
381 | |||
382 | |||
383 | connect( editor, SIGNAL(notFound()), | ||
384 | &frmFind, SLOT(slotNotFound()) ); | ||
385 | connect( editor, SIGNAL(searchWrapped()), | ||
386 | &frmFind, SLOT(slotWrapAround()) ); | ||
387 | |||
388 | frmFind.exec(); | ||
389 | |||
390 | |||
391 | } | ||
392 | #endif | ||
393 | |||
394 | void TextEdit::fileRevert() | ||
395 | { | ||
396 | clear(); | ||
397 | fileOpen(); | ||
398 | } | ||
399 | |||
400 | void TextEdit::editCut() | ||
401 | { | ||
402 | #ifndef QT_NO_CLIPBOARD | ||
403 | editor->cut(); | ||
404 | #endif | ||
405 | } | ||
406 | |||
407 | void TextEdit::editCopy() | ||
408 | { | ||
409 | #ifndef QT_NO_CLIPBOARD | ||
410 | editor->copy(); | ||
411 | #endif | ||
412 | } | ||
413 | |||
414 | void TextEdit::editPaste() | ||
415 | { | ||
416 | #ifndef QT_NO_CLIPBOARD | ||
417 | editor->paste(); | ||
418 | #endif | ||
419 | } | ||
420 | |||
421 | void TextEdit::editFind() | ||
422 | { | ||
423 | searchBar->show(); | ||
424 | searchVisible = TRUE; | ||
425 | searchEdit->setFocus(); | ||
426 | } | ||
427 | |||
428 | void TextEdit::findNext() | ||
429 | { | ||
430 | editor->find( searchEdit->text(), FALSE, FALSE ); | ||
431 | |||
432 | } | ||
433 | |||
434 | void TextEdit::findClose() | ||
435 | { | ||
436 | searchVisible = FALSE; | ||
437 | searchBar->hide(); | ||
438 | } | ||
439 | |||
440 | void TextEdit::search() | ||
441 | { | ||
442 | editor->find( searchEdit->text(), FALSE, FALSE ); | ||
443 | } | ||
444 | |||
445 | void TextEdit::newFile( const DocLnk &f ) | ||
446 | { | ||
447 | DocLnk nf = f; | ||
448 | nf.setType("text/plain"); | ||
449 | clear(); | ||
450 | editorStack->raiseWidget( editor ); | ||
451 | setWState (WState_Reserved1 ); | ||
452 | editor->setFocus(); | ||
453 | doc = new DocLnk(nf); | ||
454 | updateCaption(); | ||
455 | } | ||
456 | |||
457 | void TextEdit::openFile( const QString &f ) | ||
458 | { | ||
459 | bFromDocView = TRUE; | ||
460 | DocLnk nf; | ||
461 | nf.setType("text/plain"); | ||
462 | nf.setFile(f); | ||
463 | openFile(nf); | ||
464 | showEditTools(); | ||
465 | // Show filename in caption | ||
466 | QString name = f; | ||
467 | int sep = name.findRev( '/' ); | ||
468 | if ( sep > 0 ) | ||
469 | name = name.mid( sep+1 ); | ||
470 | updateCaption( name ); | ||
471 | } | ||
472 | |||
473 | void TextEdit::openFile( const DocLnk &f ) | ||
474 | { | ||
475 | clear(); | ||
476 | FileManager fm; | ||
477 | QString txt; | ||
478 | if ( !fm.loadFile( f, txt ) ) { | ||
479 | // ####### could be a new file | ||
480 | //qDebug( "Cannot open file" ); | ||
481 | //return; | ||
482 | } | ||
483 | fileNew(); | ||
484 | if ( doc ) | ||
485 | delete doc; | ||
486 | doc = new DocLnk(f); | ||
487 | editor->setText(txt); | ||
488 | editor->setEdited(FALSE); | ||
489 | updateCaption(); | ||
490 | } | ||
491 | |||
492 | void TextEdit::showEditTools() | ||
493 | { | ||
494 | if ( !doc ) | ||
495 | close(); | ||
496 | fileSelector->hide(); | ||
497 | menu->show(); | ||
498 | editBar->show(); | ||
499 | if ( searchVisible ) | ||
500 | searchBar->show(); | ||
501 | updateCaption(); | ||
502 | } | ||
503 | |||
504 | bool TextEdit::save() | ||
505 | { | ||
506 | // case of nothing to save... | ||
507 | if ( !doc ) | ||
508 | return true; | ||
509 | if ( !editor->edited() ) { | ||
510 | delete doc; | ||
511 | doc = 0; | ||
512 | return true; | ||
513 | } | ||
514 | |||
515 | QString rt = editor->text(); | ||
516 | |||
517 | if ( doc->name().isEmpty() ) { | ||
518 | QString pt = rt.simplifyWhiteSpace(); | ||
519 | int i = pt.find( ' ' ); | ||
520 | QString docname = pt; | ||
521 | if ( i > 0 ) | ||
522 | docname = pt.left( i ); | ||
523 | // remove "." at the beginning | ||
524 | while( docname.startsWith( "." ) ) | ||
525 | docname = docname.mid( 1 ); | ||
526 | docname.replace( QRegExp("/"), "_" ); | ||
527 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | ||
528 | if ( docname.length() > 40 ) | ||
529 | docname = docname.left(40); | ||
530 | if ( docname.isEmpty() ) | ||
531 | docname = "Empty Text"; | ||
532 | doc->setName(docname); | ||
533 | |||
534 | // append .txt to the file name | ||
535 | if ( doc->file().find(".txt") == -1 ) { | ||
536 | QString file = doc->file() + ".txt"; | ||
537 | doc->setFile( file ); | ||
538 | } | ||
539 | } | ||
540 | |||
541 | |||
542 | FileManager fm; | ||
543 | if ( !fm.saveFile( *doc, rt ) ) { | ||
544 | return false; | ||
545 | } | ||
546 | delete doc; | ||
547 | doc = 0; | ||
548 | editor->setEdited( false ); | ||
549 | return true; | ||
550 | } | ||
551 | |||
552 | void TextEdit::clear() | ||
553 | { | ||
554 | delete doc; | ||
555 | doc = 0; | ||
556 | editor->clear(); | ||
557 | } | ||
558 | |||
559 | void TextEdit::updateCaption( const QString &name ) | ||
560 | { | ||
561 | if ( !doc ) | ||
562 | setCaption( tr("Text Editor") ); | ||
563 | else { | ||
564 | QString s = name; | ||
565 | if ( s.isNull() ) | ||
566 | s = doc->name(); | ||
567 | if ( s.isEmpty() ) | ||
568 | s = tr( "Unnamed" ); | ||
569 | setCaption( s + " - " + tr("Text Editor") ); | ||
570 | } | ||
571 | } | ||
572 | |||
573 | void TextEdit::setDocument(const QString& fileref) | ||
574 | { | ||
575 | bFromDocView = TRUE; | ||
576 | openFile(DocLnk(fileref)); | ||
577 | showEditTools(); | ||
578 | } | ||
579 | |||
580 | void TextEdit::closeEvent( QCloseEvent *e ) | ||
581 | { | ||
582 | if ( editorStack->visibleWidget() == editor && !bFromDocView ) { | ||
583 | e->ignore(); | ||
584 | fileRevert(); | ||
585 | } else { | ||
586 | bFromDocView = FALSE; | ||
587 | e->accept(); | ||
588 | } | ||
589 | } | ||
590 | |||
591 | void TextEdit::accept() | ||
592 | { | ||
593 | fileOpen(); | ||
594 | } | ||
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h new file mode 100644 index 0000000..f7d1052 --- a/dev/null +++ b/core/apps/textedit/textedit.h | |||
@@ -0,0 +1,102 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #ifndef TEXTEDIT_H | ||
22 | #define TEXTEDIT_H | ||
23 | |||
24 | #define QTEXTEDIT_OPEN_API | ||
25 | |||
26 | #include <qpe/filemanager.h> | ||
27 | |||
28 | #include <qmainwindow.h> | ||
29 | #include <qmultilineedit.h> | ||
30 | #include <qlist.h> | ||
31 | #include <qmap.h> | ||
32 | |||
33 | class QWidgetStack; | ||
34 | class QToolButton; | ||
35 | class QPopupMenu; | ||
36 | class QToolBar; | ||
37 | class QLineEdit; | ||
38 | class QAction; | ||
39 | class FileSelector; | ||
40 | class QpeEditor; | ||
41 | |||
42 | class TextEdit : public QMainWindow | ||
43 | { | ||
44 | Q_OBJECT | ||
45 | |||
46 | public: | ||
47 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | ||
48 | ~TextEdit(); | ||
49 | |||
50 | void openFile( const QString & ); | ||
51 | |||
52 | protected: | ||
53 | void closeEvent( QCloseEvent *e ); | ||
54 | |||
55 | private slots: | ||
56 | void setDocument(const QString&); | ||
57 | |||
58 | void fileNew(); | ||
59 | void fileRevert(); | ||
60 | void fileOpen(); | ||
61 | |||
62 | void editCut(); | ||
63 | void editCopy(); | ||
64 | void editPaste(); | ||
65 | void editFind(); | ||
66 | |||
67 | void findNext(); | ||
68 | void findClose(); | ||
69 | |||
70 | void search(); | ||
71 | void accept(); | ||
72 | |||
73 | void newFile( const DocLnk & ); | ||
74 | void openFile( const DocLnk & ); | ||
75 | void showEditTools(); | ||
76 | |||
77 | void zoomIn(); | ||
78 | void zoomOut(); | ||
79 | void setBold(bool y); | ||
80 | void setItalic(bool y); | ||
81 | void setWordWrap(bool y); | ||
82 | |||
83 | private: | ||
84 | void colorChanged( const QColor &c ); | ||
85 | bool save(); | ||
86 | void clear(); | ||
87 | void updateCaption( const QString &name=QString::null ); | ||
88 | void setFontSize(int sz, bool round_down_not_up); | ||
89 | |||
90 | private: | ||
91 | QWidgetStack *editorStack; | ||
92 | FileSelector *fileSelector; | ||
93 | QpeEditor* editor; | ||
94 | QToolBar *menu, *editBar, *searchBar; | ||
95 | QLineEdit *searchEdit; | ||
96 | DocLnk *doc; | ||
97 | bool searchVisible; | ||
98 | bool bFromDocView; | ||
99 | QAction *zin, *zout; | ||
100 | }; | ||
101 | |||
102 | #endif | ||
diff --git a/core/apps/textedit/textedit.po b/core/apps/textedit/textedit.po new file mode 100644 index 0000000..683a5e3 --- a/dev/null +++ b/core/apps/textedit/textedit.po | |||
@@ -0,0 +1,108 @@ | |||
1 | # This is a Qt message file in .po format. Each msgid starts with | ||
2 | # a scope. This scope should *NOT* be translated - eg. translating | ||
3 | # from French to English, "Foo::Bar" would be translated to "Pub", | ||
4 | # not "Foo::Pub". | ||
5 | msgid "" | ||
6 | msgstr "" | ||
7 | "Project-Id-Version: PROJECT VERSION\n" | ||
8 | "POT-Creation-Date: 2001-03-16 14:29:14 EST\n" | ||
9 | "PO-Revision-Date: YYYY-MM-DD\n" | ||
10 | "Last-Translator: FULLNAME <EMAIL@ADDRESS>\n" | ||
11 | "Content-Type: text/plain; charset=iso-8859-1\n" | ||
12 | |||
13 | #: textedit.cpp:110 | ||
14 | msgid "TextEdit::&Edit" | ||
15 | msgstr "" | ||
16 | |||
17 | #: textedit.cpp:109 | ||
18 | msgid "TextEdit::&File" | ||
19 | msgstr "" | ||
20 | |||
21 | #: textedit.cpp:102 | ||
22 | msgid "TextEdit::&Insert" | ||
23 | msgstr "" | ||
24 | |||
25 | #: textedit.cpp:115 | ||
26 | msgid "TextEdit::Bold" | ||
27 | msgstr "" | ||
28 | |||
29 | #: textedit.cpp:191 | ||
30 | msgid "TextEdit::Bullet List" | ||
31 | msgstr "" | ||
32 | |||
33 | #: textedit.cpp:140 | ||
34 | msgid "TextEdit::Center" | ||
35 | msgstr "" | ||
36 | |||
37 | #: textedit.cpp:170 | ||
38 | msgid "TextEdit::Close Find" | ||
39 | msgstr "" | ||
40 | |||
41 | #: textedit.cpp:69 | ||
42 | msgid "TextEdit::Close" | ||
43 | msgstr "" | ||
44 | |||
45 | #: textedit.cpp:79 | ||
46 | msgid "TextEdit::Copy" | ||
47 | msgstr "" | ||
48 | |||
49 | #: textedit.cpp:74 | ||
50 | msgid "TextEdit::Cut" | ||
51 | msgstr "" | ||
52 | |||
53 | #: textedit.cpp:194 | ||
54 | msgid "TextEdit::Enumerated List" | ||
55 | msgstr "" | ||
56 | |||
57 | #: textedit.cpp:94 | ||
58 | msgid "TextEdit::Find Next" | ||
59 | msgstr "" | ||
60 | |||
61 | #: textedit.cpp:89 | ||
62 | msgid "TextEdit::Find..." | ||
63 | msgstr "" | ||
64 | |||
65 | #: textedit.cpp:120 | ||
66 | msgid "TextEdit::Italic" | ||
67 | msgstr "" | ||
68 | |||
69 | #: textedit.cpp:134 | ||
70 | msgid "TextEdit::Left" | ||
71 | msgstr "" | ||
72 | |||
73 | #: textedit.cpp:61 | ||
74 | msgid "TextEdit::New" | ||
75 | msgstr "" | ||
76 | |||
77 | #: textedit.cpp:65 | ||
78 | msgid "TextEdit::Open" | ||
79 | msgstr "" | ||
80 | |||
81 | #: textedit.cpp:84 | ||
82 | msgid "TextEdit::Paste" | ||
83 | msgstr "" | ||
84 | |||
85 | #: textedit.cpp:145 | ||
86 | msgid "TextEdit::Right" | ||
87 | msgstr "" | ||
88 | |||
89 | #: textedit.cpp:188 | ||
90 | msgid "TextEdit::Standard" | ||
91 | msgstr "" | ||
92 | |||
93 | #: textedit.cpp:104 | ||
94 | msgid "TextEdit::Table..." | ||
95 | msgstr "" | ||
96 | |||
97 | #: textedit.cpp:570 | ||
98 | msgid "TextEdit::Text Editor" | ||
99 | msgstr "" | ||
100 | |||
101 | #: textedit.cpp:125 | ||
102 | msgid "TextEdit::Underline" | ||
103 | msgstr "" | ||
104 | |||
105 | #: textedit.cpp:569 | ||
106 | msgid "TextEdit::Unnamed" | ||
107 | msgstr "" | ||
108 | |||
diff --git a/core/apps/textedit/textedit.pro b/core/apps/textedit/textedit.pro new file mode 100644 index 0000000..3f5473e --- a/dev/null +++ b/core/apps/textedit/textedit.pro | |||
@@ -0,0 +1,16 @@ | |||
1 | TEMPLATE= app | ||
2 | CONFIG += qt warn_on release | ||
3 | |||
4 | DESTDIR = $(QPEDIR)/bin | ||
5 | |||
6 | HEADERS= textedit.h | ||
7 | |||
8 | SOURCES= main.cpp textedit.cpp | ||
9 | |||
10 | INCLUDEPATH += $(QPEDIR)/include | ||
11 | DEPENDPATH+= $(QPEDIR)/include | ||
12 | LIBS += -lqpe | ||
13 | |||
14 | TARGET = textedit | ||
15 | |||
16 | TRANSLATIONS = ../i18n/de/textedit.ts | ||