summaryrefslogtreecommitdiff
path: root/core/apps/textedit
Side-by-side diff
Diffstat (limited to 'core/apps/textedit') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/.cvsignore3
-rw-r--r--core/apps/textedit/Makefile.in125
-rw-r--r--core/apps/textedit/inserttable.ui103
-rw-r--r--core/apps/textedit/main.cpp35
-rw-r--r--core/apps/textedit/qpe-textedit.control9
-rw-r--r--core/apps/textedit/qtextedit.h282
-rw-r--r--core/apps/textedit/textedit.cpp594
-rw-r--r--core/apps/textedit/textedit.h102
-rw-r--r--core/apps/textedit/textedit.po108
-rw-r--r--core/apps/textedit/textedit.pro16
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 @@
+moc_*
+*.moc
+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 @@
+#############################################################################
+
+####### Compiler, tools and options
+
+CXX = $(SYSCONF_CXX) $(QT_CXX_MT)
+CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS)
+CC = $(SYSCONF_CC) $(QT_C_MT)
+CFLAGS = $(SYSCONF_CFLAGS)
+INCPATH = -I$(QPEDIR)/include
+LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
+LIBS = $(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP)
+MOC = $(SYSCONF_MOC)
+UIC = $(SYSCONF_UIC)
+
+####### Target
+
+DESTDIR = $(QPEDIR)/bin/
+VER_MAJ = 1
+VER_MIN = 0
+VER_PATCH = 0
+TARGET = textedit
+TARGET1 = lib$(TARGET).so.$(VER_MAJ)
+
+####### Files
+
+HEADERS = textedit.h
+SOURCES = main.cpp \
+ textedit.cpp
+OBJECTS = main.o \
+ textedit.o
+INTERFACES =
+UICDECLS =
+UICIMPLS =
+SRCMOC = moc_textedit.cpp
+OBJMOC = moc_textedit.o
+
+
+####### Implicit rules
+
+.SUFFIXES: .cpp .cxx .cc .C .c
+
+.cpp.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.cxx.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.cc.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.C.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.c.o:
+ $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
+
+####### Build rules
+
+
+all: $(DESTDIR)$(TARGET)
+
+$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
+ $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS)
+
+moc: $(SRCMOC)
+
+tmake:
+ tmake textedit.pro
+
+clean:
+ -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
+ -rm -f *~ core
+ -rm -f allmoc.cpp
+
+####### Extension Modules
+
+listpromodules:
+ @echo
+
+listallmodules:
+ @echo
+
+listaddonpromodules:
+ @echo
+
+listaddonentmodules:
+ @echo
+
+
+REQUIRES=
+
+####### Sub-libraries
+
+
+###### Combined headers
+
+
+
+####### Compile
+
+main.o: main.cpp \
+ textedit.h \
+ $(QPEDIR)/include/qpe/filemanager.h \
+ $(QPEDIR)/include/qpe/qpeapplication.h
+
+textedit.o: textedit.cpp \
+ textedit.h \
+ $(QPEDIR)/include/qpe/filemanager.h \
+ $(QPEDIR)/include/qpe/global.h \
+ $(QPEDIR)/include/qpe/fileselector.h \
+ $(QPEDIR)/include/qpe/applnk.h \
+ $(QPEDIR)/include/qpe/resource.h \
+ $(QPEDIR)/include/qpe/config.h \
+ $(QPEDIR)/include/qpe/qpeapplication.h \
+ $(QPEDIR)/include/qpe/qpemenubar.h \
+ $(QPEDIR)/include/qpe/qpetoolbar.h
+
+moc_textedit.o: moc_textedit.cpp \
+ textedit.h \
+ $(QPEDIR)/include/qpe/filemanager.h
+
+moc_textedit.cpp: textedit.h
+ $(MOC) textedit.h -o moc_textedit.cpp
+
+
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 @@
+<!DOCTYPE UI><UI>
+<class>InsertTable</class><comment>*********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+*********************************************************************</comment>
+<widget>
+ <class>QDialog</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>InsertTable</cstring>
+ </property>
+ <property stdset="1">
+ <name>geometry</name>
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>165</width>
+ <height>79</height>
+ </rect>
+ </property>
+ <property stdset="1">
+ <name>caption</name>
+ <string>Insert Table</string>
+ </property>
+ <grid>
+ <property stdset="1">
+ <name>margin</name>
+ <number>11</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget row="0" column="0" >
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel1</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Rows:</string>
+ </property>
+ </widget>
+ <widget row="0" column="1" >
+ <class>QSpinBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>spinRows</cstring>
+ </property>
+ <property stdset="1">
+ <name>minValue</name>
+ <number>1</number>
+ </property>
+ <property stdset="1">
+ <name>value</name>
+ <number>1</number>
+ </property>
+ </widget>
+ <widget row="1" column="1" >
+ <class>QSpinBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>spinColumns</cstring>
+ </property>
+ <property stdset="1">
+ <name>minValue</name>
+ <number>1</number>
+ </property>
+ <property stdset="1">
+ <name>value</name>
+ <number>1</number>
+ </property>
+ </widget>
+ <widget row="1" column="0" >
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel1_2</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Columns:</string>
+ </property>
+ </widget>
+ </grid>
+</widget>
+</UI>
diff --git a/core/apps/textedit/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 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "textedit.h"
+
+#include <qpe/qpeapplication.h>
+
+int main( int argc, char **argv )
+{
+ QPEApplication a( argc, argv );
+
+ TextEdit e;
+ a.showMainDocumentWidget(&e);
+ if ( argc == 3 && argv[1] == QCString("-f") )
+ e.openFile(argv[2]);
+
+ a.exec();
+}
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 @@
+Files: bin/textedit apps/Applications/textedit.desktop
+Priority: optional
+Section: qpe/applications
+Maintainer: Warwick Allison <warwick@trolltech.com>
+Architecture: arm
+Version: $QPE_VERSION-3
+Depends: qpe-base ($QPE_VERSION)
+Description: Text Editor
+ 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 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef QTEXTEDIT_H
+#define QTEXTEDIT_H
+
+#include <qscrollview.h>
+#include <qstylesheet.h>
+#include <qpainter.h>
+
+class QPainter;
+class QTextDocument;
+class QTextCursor;
+class QKeyEvent;
+class QResizeEvent;
+class QMouseEvent;
+class QTimer;
+class QTextString;
+class QVBox;
+class QListBox;
+class QTextCommand;
+class QTextParag;
+class QTextFormat;
+class QFont;
+class QColor;
+
+class QTextEdit : public QScrollView
+{
+ Q_OBJECT
+
+public:
+ QTextEdit( QWidget *parent, const QString &fn, bool tabify = FALSE );
+ QTextEdit( QWidget *parent = 0, const char *name = 0 );
+ virtual ~QTextEdit();
+
+#if defined(QTEXTEDIT_OPEN_API)
+ QTextDocument *document() const;
+ QTextCursor *textCursor() const;
+#endif
+
+ QString text() const;
+ QString text( int parag, bool formatted = FALSE ) const;
+ Qt::TextFormat textFormat() const;
+ QString fileName() const;
+
+ void cursorPosition( int &parag, int &index );
+ void selection( int &parag_from, int &index_from,
+ int &parag_to, int &index_to );
+ virtual bool find( const QString &expr, bool cs, bool wo, bool forward = TRUE,
+ int *parag = 0, int *index = 0 );
+ void insert( const QString &text, bool indent = FALSE, bool checkNewLine = FALSE );
+
+ int paragraphs() const;
+ int lines() const;
+ int linesOfParagraph( int parag ) const;
+ int lineOfChar( int parag, int chr );
+
+ bool isModified() const;
+
+ bool italic() const;
+ bool bold() const;
+ bool underline() const;
+ QString family() const;
+ int pointSize() const;
+ QColor color() const;
+ QFont font() const;
+ int alignment() const;
+ int maxLines() const;
+
+ const QStyleSheet* styleSheet() const;
+ void setStyleSheet( const QStyleSheet* styleSheet );
+
+ void setPaper( const QBrush& pap);
+ QBrush paper() const;
+
+ void setLinkColor( const QColor& );
+ QColor linkColor() const;
+
+ void setLinkUnderline( bool );
+ bool linkUnderline() const;
+
+ void setMimeSourceFactory( const QMimeSourceFactory* factory );
+ const QMimeSourceFactory* mimeSourceFactory() const;
+
+ int heightForWidth( int w ) const;
+
+ void append( const QString& text );
+
+ bool hasSelectedText() const;
+ QString selectedText() const;
+
+ QString context() const;
+
+ QString documentTitle() const;
+
+ void scrollToAnchor( const QString& name );
+ QString anchorAt(const QPoint& pos);
+
+public slots:
+ virtual void undo();
+ virtual void redo();
+
+ virtual void cut();
+ virtual void copy();
+ virtual void paste();
+
+ virtual void indent();
+
+ virtual void setItalic( bool b );
+ virtual void setBold( bool b );
+ virtual void setUnderline( bool b );
+ virtual void setFamily( const QString &f );
+ virtual void setPointSize( int s );
+ virtual void setColor( const QColor &c );
+ virtual void setFont( const QFont &f );
+
+ virtual void setAlignment( int );
+
+ virtual void setParagType( QStyleSheetItem::DisplayMode, int listStyle );
+
+ virtual void setTextFormat( Qt::TextFormat f );
+ virtual void setText( const QString &txt, const QString &context = QString::null ) { setText( txt, context, FALSE ); }
+ virtual void setText( const QString &txt, const QString &context, bool tabify );
+
+ virtual void load( const QString &fn ) { load( fn, FALSE ); }
+ virtual void load( const QString &fn, bool tabify );
+ virtual void save( bool untabify = FALSE ) { save( QString::null, untabify ); }
+ virtual void save( const QString &fn, bool untabify = FALSE );
+
+ virtual void setCursorPosition( int parag, int index );
+ virtual void setSelection( int parag_from, int index_from,
+ int parag_to, int index_to );
+
+ virtual void setModified( bool m );
+ virtual void selectAll( bool select );
+
+ virtual void setMaxLines( int l );
+ virtual void resetFormat();
+
+signals:
+ void currentFontChanged( const QFont &f );
+ void currentColorChanged( const QColor &c );
+ void currentAlignmentChanged( int );
+ void textChanged();
+ void highlighted( const QString& );
+ void linkClicked( const QString& );
+
+protected:
+ void setFormat( QTextFormat *f, int flags );
+ void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
+ void keyPressEvent( QKeyEvent *e );
+ void resizeEvent( QResizeEvent *e );
+ void contentsMousePressEvent( QMouseEvent *e );
+ void contentsMouseMoveEvent( QMouseEvent *e );
+ void contentsMouseReleaseEvent( QMouseEvent *e );
+ void contentsMouseDoubleClickEvent( QMouseEvent *e );
+#ifndef QT_NO_DRAGANDDROP
+ void contentsDragEnterEvent( QDragEnterEvent *e );
+ void contentsDragMoveEvent( QDragMoveEvent *e );
+ void contentsDragLeaveEvent( QDragLeaveEvent *e );
+ void contentsDropEvent( QDropEvent *e );
+#endif
+ bool eventFilter( QObject *o, QEvent *e );
+ bool focusNextPrevChild( bool next );
+#if !defined(QTEXTEDIT_OPEN_API)
+ QTextDocument *document() const;
+ QTextCursor *textCursor() const;
+#endif
+
+private slots:
+ void formatMore();
+ void doResize();
+ void doAutoScroll();
+ void doChangeInterval();
+ void blinkCursor();
+ void setModified();
+ void startDrag();
+
+private:
+ enum MoveDirection {
+ MoveLeft,
+ MoveRight,
+ MoveUp,
+ MoveDown,
+ MoveHome,
+ MoveEnd,
+ MovePgUp,
+ MovePgDown
+ };
+ enum KeyboardAction {
+ ActionBackspace,
+ ActionDelete,
+ ActionReturn
+ };
+
+ struct UndoRedoInfo {
+ enum Type { Invalid, Insert, Delete, Backspace, Return, RemoveSelected };
+ UndoRedoInfo( QTextDocument *d ) : type( Invalid ), doc( d )
+ { text = QString::null; id = -1; index = -1; }
+ void clear();
+ inline bool valid() const { return !text.isEmpty() && id >= 0&& index >= 0; }
+
+ QString text;
+ int id;
+ int index;
+ Type type;
+ QTextDocument *doc;
+ };
+
+private:
+ virtual bool isReadOnly() const { return FALSE; }
+ virtual bool linksEnabled() const { return TRUE; }
+ void init();
+ void ensureCursorVisible();
+ void drawCursor( bool visible );
+ void placeCursor( const QPoint &pos, QTextCursor *c = 0 );
+ void moveCursor( int direction, bool shift, bool control );
+ void moveCursor( int direction, bool control );
+ void removeSelectedText();
+ void doKeyboardAction( int action );
+ bool doCompletion();
+ void checkUndoRedoInfo( UndoRedoInfo::Type t );
+ void repaintChanged();
+ void updateCurrentFormat();
+ void handleReadOnlyKeyEvent( QKeyEvent *e );
+ void makeParagVisible( QTextParag *p );
+
+private:
+ QTextDocument *doc;
+ QTextCursor *cursor;
+ bool drawAll;
+ bool mousePressed;
+ QTimer *formatTimer, *scrollTimer, *changeIntervalTimer, *blinkTimer, *dragStartTimer, *resizeTimer;
+ QTextParag *lastFormatted;
+ int interval;
+ QVBox *completionPopup;
+ QListBox *completionListBox;
+ int completionOffset;
+ UndoRedoInfo undoRedoInfo;
+ QTextFormat *currentFormat;
+ QPainter painter;
+ int currentAlignment;
+ bool inDoubleClick;
+ QPoint oldMousePos, mousePos;
+ QPixmap *buf_pixmap;
+ bool cursorVisible, blinkCursorVisible;
+ bool readOnly, modified, mightStartDrag;
+ QPoint dragStartPos;
+ int mLines;
+ bool firstResize;
+ QString onLink;
+
+};
+
+inline QTextDocument *QTextEdit::document() const
+{
+ return doc;
+}
+
+inline QTextCursor *QTextEdit::textCursor() const
+{
+ return cursor;
+}
+
+#endif
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
new file mode 100644
index 0000000..867625e
--- a/dev/null
+++ b/core/apps/textedit/textedit.cpp
@@ -0,0 +1,594 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#include "textedit.h"
+
+#include <qpe/global.h>
+#include <qpe/fileselector.h>
+#include <qpe/applnk.h>
+#include <qpe/resource.h>
+#include <qpe/config.h>
+#include <qpe/qpeapplication.h>
+#include <qpe/qpemenubar.h>
+#include <qpe/qpetoolbar.h>
+//#include <qpe/finddialog.h>
+
+#include <qaction.h>
+#include <qcolordialog.h>
+#include <qfileinfo.h>
+#include <qlineedit.h>
+#include <qmessagebox.h>
+#include <qobjectlist.h>
+#include <qpopupmenu.h>
+#include <qspinbox.h>
+#include <qtoolbutton.h>
+#include <qwidgetstack.h>
+
+#include <stdlib.h> //getenv
+
+
+#if QT_VERSION < 300
+
+class QpeEditor : public QMultiLineEdit
+{
+ // Q_OBJECT
+public:
+ QpeEditor( QWidget *parent, const char * name = 0 )
+ : QMultiLineEdit( parent, name ) {}
+
+ //public slots:
+ void find( const QString &txt, bool caseSensitive,
+ bool backwards );
+ /*
+signals:
+ void notFound();
+ void searchWrapped();
+ */
+
+private:
+
+};
+
+
+void QpeEditor::find ( const QString &txt, bool caseSensitive,
+ bool backwards )
+{
+ static bool wrap = FALSE;
+ int line, col;
+ if ( wrap ) {
+ if ( !backwards )
+ line = col = 0;
+ wrap = FALSE;
+ // emit searchWrapped();
+ } else {
+ getCursorPosition( &line, &col );
+ }
+ //ignore backwards for now....
+ if ( !backwards ) {
+ for ( ; ; ) {
+ if ( line >= numLines() ) {
+ wrap = TRUE;
+ //emit notFound();
+ break;
+ }
+ int findCol = getString( line )->find( txt, col, caseSensitive );
+ if ( findCol >= 0 ) {
+ setCursorPosition( line, findCol, FALSE );
+ col = findCol + txt.length();
+ setCursorPosition( line, col, TRUE );
+
+ //found = TRUE;
+ break;
+ }
+ line++;
+ col = 0;
+ }
+
+ }
+
+}
+
+
+#else
+
+#error "Must make a QpeEditor that inherits QTextEdit"
+
+#endif
+
+
+
+
+static int u_id = 1;
+static int get_unique_id()
+{
+ return u_id++;
+}
+
+static const int nfontsizes = 6;
+static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
+
+TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
+ : QMainWindow( parent, name, f ), bFromDocView( FALSE )
+{
+ doc = 0;
+
+ QString lang = getenv( "LANG" );
+
+ setToolBarsMovable( FALSE );
+
+ setIcon( Resource::loadPixmap( "TextEditor" ) );
+
+ QPEToolBar *bar = new QPEToolBar( this );
+ bar->setHorizontalStretchable( TRUE );
+ menu = bar;
+
+ QPEMenuBar *mb = new QPEMenuBar( bar );
+ QPopupMenu *file = new QPopupMenu( this );
+ QPopupMenu *edit = new QPopupMenu( this );
+ QPopupMenu *font = new QPopupMenu( this );
+
+ bar = new QPEToolBar( this );
+ editBar = bar;
+
+ QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
+ a->addTo( bar );
+ a->addTo( file );
+
+ a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
+ a->addTo( bar );
+ a->addTo( file );
+
+ a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
+ a->addTo( editBar );
+ a->addTo( edit );
+
+ a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
+ a->addTo( editBar );
+ a->addTo( edit );
+
+ a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
+ a->addTo( editBar );
+ a->addTo( edit );
+
+ a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
+ edit->insertSeparator();
+ a->addTo( bar );
+ a->addTo( edit );
+
+ int defsize;
+ bool defb, defi, wrap;
+ {
+ Config cfg("TextEdit");
+ cfg.setGroup("View");
+ defsize = cfg.readNumEntry("FontSize",10);
+ defb = cfg.readBoolEntry("Bold",FALSE);
+ defi = cfg.readBoolEntry("Italic",FALSE);
+ wrap = cfg.readBoolEntry("Wrap",TRUE);
+ }
+
+ zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
+ connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
+ zin->addTo( font );
+
+ zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
+ connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
+ zout->addTo( font );
+
+ font->insertSeparator();
+
+#if 0
+ QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
+ connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
+ ba->setToggleAction(TRUE);
+ ba->addTo( font );
+
+ QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 );
+ connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) );
+ ia->setToggleAction(TRUE);
+ ia->addTo( font );
+
+ ba->setOn(defb);
+ ia->setOn(defi);
+
+ font->insertSeparator();
+#endif
+
+ QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
+ connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
+ wa->setToggleAction(TRUE);
+ wa->addTo( font );
+
+ mb->insertItem( tr( "File" ), file );
+ mb->insertItem( tr( "Edit" ), edit );
+ mb->insertItem( tr( "View" ), font );
+
+ searchBar = new QPEToolBar(this);
+ addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
+
+ searchBar->setHorizontalStretchable( TRUE );
+
+ searchEdit = new QLineEdit( searchBar, "searchEdit" );
+ searchBar->setStretchableWidget( searchEdit );
+ connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
+ this, SLOT( search() ) );
+
+ a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
+ a->addTo( searchBar );
+ a->addTo( edit );
+
+ a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
+ a->addTo( searchBar );
+
+ searchBar->hide();
+
+ editorStack = new QWidgetStack( this );
+ setCentralWidget( editorStack );
+
+ searchVisible = FALSE;
+
+ fileSelector = new FileSelector( "text/*", editorStack, "fileselector" ,
+ TRUE, FALSE );
+ fileSelector->setCategoriesVisible(TRUE);
+ connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
+ connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
+ connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
+ fileOpen();
+
+ editor = new QpeEditor( editorStack );
+ editorStack->addWidget( editor, get_unique_id() );
+
+ resize( 200, 300 );
+
+ setFontSize(defsize,TRUE);
+ wa->setOn(wrap);
+}
+
+TextEdit::~TextEdit()
+{
+ save();
+
+ Config cfg("TextEdit");
+ cfg.setGroup("View");
+ QFont f = editor->font();
+ cfg.writeEntry("FontSize",f.pointSize());
+ cfg.writeEntry("Bold",f.bold());
+ cfg.writeEntry("Italic",f.italic());
+ cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
+}
+
+void TextEdit::zoomIn()
+{
+ setFontSize(editor->font().pointSize()+1,FALSE);
+}
+
+void TextEdit::zoomOut()
+{
+ setFontSize(editor->font().pointSize()-1,TRUE);
+}
+
+
+void TextEdit::setFontSize(int sz, bool round_down_not_up)
+{
+ int s=10;
+ for (int i=0; i<nfontsizes; i++) {
+ if ( fontsize[i] == sz ) {
+ s = sz;
+ break;
+ } else if ( round_down_not_up ) {
+ if ( fontsize[i] < sz )
+ s = fontsize[i];
+ } else {
+ if ( fontsize[i] > sz ) {
+ s = fontsize[i];
+ break;
+ }
+ }
+ }
+
+ QFont f = editor->font();
+ f.setPointSize(s);
+ editor->setFont(f);
+
+ zin->setEnabled(s != fontsize[nfontsizes-1]);
+ zout->setEnabled(s != fontsize[0]);
+}
+
+void TextEdit::setBold(bool y)
+{
+ QFont f = editor->font();
+ f.setBold(y);
+ editor->setFont(f);
+}
+
+void TextEdit::setItalic(bool y)
+{
+ QFont f = editor->font();
+ f.setItalic(y);
+ editor->setFont(f);
+}
+
+void TextEdit::setWordWrap(bool y)
+{
+ editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
+}
+
+void TextEdit::fileNew()
+{
+ save();
+ newFile(DocLnk());
+}
+
+void TextEdit::fileOpen()
+{
+ if ( !save() ) {
+ if ( QMessageBox::critical( this, tr( "Out of space" ),
+ tr( "Text Editor was unable to\n"
+ "save your changes.\n"
+ "Free some space and try again.\n"
+ "\nContinue anyway?" ),
+ QMessageBox::Yes|QMessageBox::Escape,
+ QMessageBox::No|QMessageBox::Default )
+ != QMessageBox::Yes )
+ return;
+ else {
+ delete doc;
+ doc = 0;
+ }
+ }
+ menu->hide();
+ editBar->hide();
+ searchBar->hide();
+ clearWState (WState_Reserved1 );
+ editorStack->raiseWidget( fileSelector );
+ fileSelector->reread();
+ updateCaption();
+}
+
+
+#if 0
+void TextEdit::slotFind()
+{
+ FindDialog frmFind( "Text Editor", this );
+ connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
+ editor, SLOT(slotDoFind( const QString&,bool,bool)));
+
+ //case sensitive, backwards, [category]
+
+
+ connect( editor, SIGNAL(notFound()),
+ &frmFind, SLOT(slotNotFound()) );
+ connect( editor, SIGNAL(searchWrapped()),
+ &frmFind, SLOT(slotWrapAround()) );
+
+ frmFind.exec();
+
+
+}
+#endif
+
+void TextEdit::fileRevert()
+{
+ clear();
+ fileOpen();
+}
+
+void TextEdit::editCut()
+{
+#ifndef QT_NO_CLIPBOARD
+ editor->cut();
+#endif
+}
+
+void TextEdit::editCopy()
+{
+#ifndef QT_NO_CLIPBOARD
+ editor->copy();
+#endif
+}
+
+void TextEdit::editPaste()
+{
+#ifndef QT_NO_CLIPBOARD
+ editor->paste();
+#endif
+}
+
+void TextEdit::editFind()
+{
+ searchBar->show();
+ searchVisible = TRUE;
+ searchEdit->setFocus();
+}
+
+void TextEdit::findNext()
+{
+ editor->find( searchEdit->text(), FALSE, FALSE );
+
+}
+
+void TextEdit::findClose()
+{
+ searchVisible = FALSE;
+ searchBar->hide();
+}
+
+void TextEdit::search()
+{
+ editor->find( searchEdit->text(), FALSE, FALSE );
+}
+
+void TextEdit::newFile( const DocLnk &f )
+{
+ DocLnk nf = f;
+ nf.setType("text/plain");
+ clear();
+ editorStack->raiseWidget( editor );
+ setWState (WState_Reserved1 );
+ editor->setFocus();
+ doc = new DocLnk(nf);
+ updateCaption();
+}
+
+void TextEdit::openFile( const QString &f )
+{
+ bFromDocView = TRUE;
+ DocLnk nf;
+ nf.setType("text/plain");
+ nf.setFile(f);
+ openFile(nf);
+ showEditTools();
+ // Show filename in caption
+ QString name = f;
+ int sep = name.findRev( '/' );
+ if ( sep > 0 )
+ name = name.mid( sep+1 );
+ updateCaption( name );
+}
+
+void TextEdit::openFile( const DocLnk &f )
+{
+ clear();
+ FileManager fm;
+ QString txt;
+ if ( !fm.loadFile( f, txt ) ) {
+ // ####### could be a new file
+ //qDebug( "Cannot open file" );
+ //return;
+ }
+ fileNew();
+ if ( doc )
+ delete doc;
+ doc = new DocLnk(f);
+ editor->setText(txt);
+ editor->setEdited(FALSE);
+ updateCaption();
+}
+
+void TextEdit::showEditTools()
+{
+ if ( !doc )
+ close();
+ fileSelector->hide();
+ menu->show();
+ editBar->show();
+ if ( searchVisible )
+ searchBar->show();
+ updateCaption();
+}
+
+bool TextEdit::save()
+{
+ // case of nothing to save...
+ if ( !doc )
+ return true;
+ if ( !editor->edited() ) {
+ delete doc;
+ doc = 0;
+ return true;
+ }
+
+ QString rt = editor->text();
+
+ if ( doc->name().isEmpty() ) {
+ QString pt = rt.simplifyWhiteSpace();
+ int i = pt.find( ' ' );
+ QString docname = pt;
+ if ( i > 0 )
+ docname = pt.left( i );
+ // remove "." at the beginning
+ while( docname.startsWith( "." ) )
+ docname = docname.mid( 1 );
+ docname.replace( QRegExp("/"), "_" );
+ // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
+ if ( docname.length() > 40 )
+ docname = docname.left(40);
+ if ( docname.isEmpty() )
+ docname = "Empty Text";
+ doc->setName(docname);
+
+ // append .txt to the file name
+ if ( doc->file().find(".txt") == -1 ) {
+ QString file = doc->file() + ".txt";
+ doc->setFile( file );
+ }
+ }
+
+
+ FileManager fm;
+ if ( !fm.saveFile( *doc, rt ) ) {
+ return false;
+ }
+ delete doc;
+ doc = 0;
+ editor->setEdited( false );
+ return true;
+}
+
+void TextEdit::clear()
+{
+ delete doc;
+ doc = 0;
+ editor->clear();
+}
+
+void TextEdit::updateCaption( const QString &name )
+{
+ if ( !doc )
+ setCaption( tr("Text Editor") );
+ else {
+ QString s = name;
+ if ( s.isNull() )
+ s = doc->name();
+ if ( s.isEmpty() )
+ s = tr( "Unnamed" );
+ setCaption( s + " - " + tr("Text Editor") );
+ }
+}
+
+void TextEdit::setDocument(const QString& fileref)
+{
+ bFromDocView = TRUE;
+ openFile(DocLnk(fileref));
+ showEditTools();
+}
+
+void TextEdit::closeEvent( QCloseEvent *e )
+{
+ if ( editorStack->visibleWidget() == editor && !bFromDocView ) {
+ e->ignore();
+ fileRevert();
+ } else {
+ bFromDocView = FALSE;
+ e->accept();
+ }
+}
+
+void TextEdit::accept()
+{
+ fileOpen();
+}
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 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+#ifndef TEXTEDIT_H
+#define TEXTEDIT_H
+
+#define QTEXTEDIT_OPEN_API
+
+#include <qpe/filemanager.h>
+
+#include <qmainwindow.h>
+#include <qmultilineedit.h>
+#include <qlist.h>
+#include <qmap.h>
+
+class QWidgetStack;
+class QToolButton;
+class QPopupMenu;
+class QToolBar;
+class QLineEdit;
+class QAction;
+class FileSelector;
+class QpeEditor;
+
+class TextEdit : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
+ ~TextEdit();
+
+ void openFile( const QString & );
+
+protected:
+ void closeEvent( QCloseEvent *e );
+
+private slots:
+ void setDocument(const QString&);
+
+ void fileNew();
+ void fileRevert();
+ void fileOpen();
+
+ void editCut();
+ void editCopy();
+ void editPaste();
+ void editFind();
+
+ void findNext();
+ void findClose();
+
+ void search();
+ void accept();
+
+ void newFile( const DocLnk & );
+ void openFile( const DocLnk & );
+ void showEditTools();
+
+ void zoomIn();
+ void zoomOut();
+ void setBold(bool y);
+ void setItalic(bool y);
+ void setWordWrap(bool y);
+
+private:
+ void colorChanged( const QColor &c );
+ bool save();
+ void clear();
+ void updateCaption( const QString &name=QString::null );
+ void setFontSize(int sz, bool round_down_not_up);
+
+private:
+ QWidgetStack *editorStack;
+ FileSelector *fileSelector;
+ QpeEditor* editor;
+ QToolBar *menu, *editBar, *searchBar;
+ QLineEdit *searchEdit;
+ DocLnk *doc;
+ bool searchVisible;
+ bool bFromDocView;
+ QAction *zin, *zout;
+};
+
+#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 @@
+# This is a Qt message file in .po format. Each msgid starts with
+# a scope. This scope should *NOT* be translated - eg. translating
+# from French to English, "Foo::Bar" would be translated to "Pub",
+# not "Foo::Pub".
+msgid ""
+msgstr ""
+"Project-Id-Version: PROJECT VERSION\n"
+"POT-Creation-Date: 2001-03-16 14:29:14 EST\n"
+"PO-Revision-Date: YYYY-MM-DD\n"
+"Last-Translator: FULLNAME <EMAIL@ADDRESS>\n"
+"Content-Type: text/plain; charset=iso-8859-1\n"
+
+#: textedit.cpp:110
+msgid "TextEdit::&Edit"
+msgstr ""
+
+#: textedit.cpp:109
+msgid "TextEdit::&File"
+msgstr ""
+
+#: textedit.cpp:102
+msgid "TextEdit::&Insert"
+msgstr ""
+
+#: textedit.cpp:115
+msgid "TextEdit::Bold"
+msgstr ""
+
+#: textedit.cpp:191
+msgid "TextEdit::Bullet List"
+msgstr ""
+
+#: textedit.cpp:140
+msgid "TextEdit::Center"
+msgstr ""
+
+#: textedit.cpp:170
+msgid "TextEdit::Close Find"
+msgstr ""
+
+#: textedit.cpp:69
+msgid "TextEdit::Close"
+msgstr ""
+
+#: textedit.cpp:79
+msgid "TextEdit::Copy"
+msgstr ""
+
+#: textedit.cpp:74
+msgid "TextEdit::Cut"
+msgstr ""
+
+#: textedit.cpp:194
+msgid "TextEdit::Enumerated List"
+msgstr ""
+
+#: textedit.cpp:94
+msgid "TextEdit::Find Next"
+msgstr ""
+
+#: textedit.cpp:89
+msgid "TextEdit::Find..."
+msgstr ""
+
+#: textedit.cpp:120
+msgid "TextEdit::Italic"
+msgstr ""
+
+#: textedit.cpp:134
+msgid "TextEdit::Left"
+msgstr ""
+
+#: textedit.cpp:61
+msgid "TextEdit::New"
+msgstr ""
+
+#: textedit.cpp:65
+msgid "TextEdit::Open"
+msgstr ""
+
+#: textedit.cpp:84
+msgid "TextEdit::Paste"
+msgstr ""
+
+#: textedit.cpp:145
+msgid "TextEdit::Right"
+msgstr ""
+
+#: textedit.cpp:188
+msgid "TextEdit::Standard"
+msgstr ""
+
+#: textedit.cpp:104
+msgid "TextEdit::Table..."
+msgstr ""
+
+#: textedit.cpp:570
+msgid "TextEdit::Text Editor"
+msgstr ""
+
+#: textedit.cpp:125
+msgid "TextEdit::Underline"
+msgstr ""
+
+#: textedit.cpp:569
+msgid "TextEdit::Unnamed"
+msgstr ""
+
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 @@
+TEMPLATE = app
+CONFIG += qt warn_on release
+
+DESTDIR = $(QPEDIR)/bin
+
+HEADERS = textedit.h
+
+SOURCES = main.cpp textedit.cpp
+
+INCLUDEPATH += $(QPEDIR)/include
+DEPENDPATH += $(QPEDIR)/include
+LIBS += -lqpe
+
+TARGET = textedit
+
+TRANSLATIONS = ../i18n/de/textedit.ts