texteditor.h
author jhilmer
Tue Aug 16 17:27:34 2005 +0000 (2005-08-16)
changeset 153 47cd4ae30000
parent 131 16b250a57c17
child 190 68c49789ec0b
permissions -rw-r--r--
Fixed link handling in aboutdialog
jhilmer@142
     1
/* emacs: -*- Mode: C; c-style: "bsd"; c-basic-offset: 4; c-recognize-knr-p: nil; -*- */
insilmaril@0
     2
#ifndef TEXTEDITOR_H 
insilmaril@0
     3
#define TEXTEDITOR_H
insilmaril@0
     4
insilmaril@0
     5
#include <qmainwindow.h>
insilmaril@0
     6
#include <qtextedit.h>
insilmaril@0
     7
#include <qaction.h>
insilmaril@0
     8
#include <qfontdatabase.h>
insilmaril@0
     9
#include <qcombobox.h>
insilmaril@0
    10
insilmaril@0
    11
insilmaril@0
    12
enum EditorState {inactiveEditor,emptyEditor,filledEditor};
insilmaril@0
    13
insilmaril@131
    14
QString textConvertToASCII(const QString &);
insilmaril@131
    15
jhilmer@142
    16
class MyTextEdit;
jhilmer@142
    17
insilmaril@0
    18
class TextEditor : public QMainWindow {
insilmaril@0
    19
    Q_OBJECT
insilmaril@0
    20
public:
insilmaril@0
    21
    TextEditor();
insilmaril@0
    22
    ~TextEditor();
insilmaril@0
    23
insilmaril@0
    24
	bool isEmpty();
insilmaril@0
    25
	void setShowWithMain (bool);
insilmaril@0
    26
	bool showWithMain ();
insilmaril@0
    27
	void setFontHint(const QString&);
insilmaril@0
    28
	QString getFontHint();
insilmaril@0
    29
	QString getFontHintDefault();
insilmaril@0
    30
	void setFilename (const QString&);
insilmaril@0
    31
	QString getFilename ();
insilmaril@106
    32
	void setFilenameHint (const QString&);
insilmaril@106
    33
	QString getFilenameHint ();
insilmaril@0
    34
	bool findText(const QString &, const bool &); // find Text 
insilmaril@0
    35
insilmaril@0
    36
protected:
insilmaril@0
    37
	void setupFileActions();
insilmaril@0
    38
	void setupEditActions();
insilmaril@0
    39
	void setupFormatActions();
insilmaril@0
    40
	void setupSettingsActions();
insilmaril@0
    41
    void closeEvent( QCloseEvent* );
insilmaril@0
    42
	
insilmaril@0
    43
insilmaril@0
    44
public:
insilmaril@0
    45
	QString getText();
insilmaril@0
    46
insilmaril@0
    47
public slots:
insilmaril@0
    48
	void editorChanged();	// received when text() changed
insilmaril@0
    49
	void setText(QString);	// set Text (by MapEditor)
insilmaril@0
    50
	void setInactive();		// Nothing can be entered
insilmaril@0
    51
	void editCopyAll();
insilmaril@0
    52
insilmaril@0
    53
signals:
insilmaril@0
    54
	void textHasChanged();
insilmaril@0
    55
	void fontFamilyHasChanged();
insilmaril@0
    56
	void fontSizeHasChanged();
insilmaril@0
    57
	
insilmaril@0
    58
private slots:
insilmaril@0
    59
    void textLoad();
insilmaril@0
    60
    void textSaveAs();
insilmaril@0
    61
    void textSave();
insilmaril@0
    62
	void textConvertPar();
insilmaril@0
    63
	void textJoinLines();
insilmaril@0
    64
	void textExportAsASCII();
insilmaril@0
    65
    void textPrint();
insilmaril@0
    66
	void textEditUndo();
insilmaril@0
    67
    void toggleFonthint();
insilmaril@0
    68
    void setFixedFont();
insilmaril@0
    69
    void setVarFont();
insilmaril@0
    70
    void textBold();
insilmaril@0
    71
    void textUnderline();
insilmaril@0
    72
    void textItalic();
insilmaril@0
    73
    void textFamily( const QString &f );
insilmaril@0
    74
    void textSize( const QString &p );
insilmaril@0
    75
	void textColor();
insilmaril@0
    76
	void textAlign(QAction*);
jhilmer@142
    77
	void textVAlign();
insilmaril@0
    78
    void fontChanged( const QFont &f );
insilmaril@0
    79
    void colorChanged( const QColor &c );
insilmaril@0
    80
    void alignmentChanged( int a );
jhilmer@142
    81
    void verticalAlignmentChanged(int a);
insilmaril@0
    82
	void enableActions();
insilmaril@0
    83
	void disableActions();
insilmaril@0
    84
insilmaril@0
    85
private:
insilmaril@0
    86
    QPrinter *printer;
jhilmer@142
    87
    MyTextEdit *e;
insilmaril@0
    88
	QPoint lastPos;			// save last position of window
insilmaril@0
    89
    QString filename;
insilmaril@106
    90
    QString filenameHint;
insilmaril@0
    91
insilmaril@0
    92
	QBrush emptyPaper;		// setting the background color
insilmaril@0
    93
	QBrush filledPaper;		// depending on the state
insilmaril@0
    94
	QBrush inactivePaper;	// depending on the state
insilmaril@0
    95
	EditorState state;
insilmaril@0
    96
	bool showwithmain;		// same visibility as mainwindow?
insilmaril@0
    97
insilmaril@0
    98
	QFont varFont;
insilmaril@0
    99
	QFont fixedFont;
insilmaril@0
   100
    QComboBox
insilmaril@0
   101
	*comboFont,
insilmaril@0
   102
	*comboSize;
insilmaril@0
   103
	
insilmaril@0
   104
	QAction *actionFileLoad,
insilmaril@0
   105
	*actionFileSave,
insilmaril@0
   106
	*actionFileSaveAs,
insilmaril@0
   107
	*actionFilePrint,
insilmaril@0
   108
	*actionEditUndo,
insilmaril@0
   109
	*actionEditRedo,
insilmaril@0
   110
	*actionEditCopy,
insilmaril@0
   111
	*actionEditCut,
insilmaril@0
   112
	*actionEditPaste,
insilmaril@0
   113
	*actionEditDeleteAll,
insilmaril@0
   114
	*actionEditConvertPar,
insilmaril@0
   115
	*actionEditJoinLines,
insilmaril@0
   116
	*actionFormatUseFixedFont,
insilmaril@0
   117
	*actionSettingsVarFont,
insilmaril@0
   118
	*actionSettingsFixedFont,
insilmaril@0
   119
	*actionSettingsFonthintDefault,
insilmaril@0
   120
    *actionTextBold,
insilmaril@0
   121
	*actionTextUnderline,
insilmaril@0
   122
	*actionTextItalic,
insilmaril@0
   123
	*actionTextColor,
insilmaril@0
   124
	*actionAlignLeft,
insilmaril@0
   125
	*actionAlignCenter,
insilmaril@0
   126
	*actionAlignRight,
jhilmer@142
   127
	*actionAlignJustify,
jhilmer@142
   128
	*actionAlignSubScript,
jhilmer@142
   129
	*actionAlignSuperScript;
jhilmer@142
   130
};
jhilmer@142
   131
jhilmer@142
   132
/* Wraps currentVerticalAlignmentChanged(VerticalAlignment)
jhilmer@142
   133
 * to currentVerticalAlignmentChanged(int) 
jhilmer@142
   134
 * this way the signal can be used without use of the internal 
jhilmer@142
   135
 * VerticalAlignment enum of QTextEdit 
jhilmer@142
   136
 * If VerticalAlignment has been a global like the normal alignment there
jhilmer@142
   137
 * have been no problems!
jhilmer@142
   138
 */
jhilmer@142
   139
 
jhilmer@142
   140
class MyTextEdit : public QTextEdit 
jhilmer@142
   141
{
jhilmer@142
   142
    Q_OBJECT;
jhilmer@142
   143
 public:
jhilmer@142
   144
    MyTextEdit(QWidget *parent, const char *name) : QTextEdit(parent, name) {
jhilmer@142
   145
	connect(this, 
jhilmer@142
   146
		SIGNAL(currentVerticalAlignmentChanged(VerticalAlignment)),
jhilmer@142
   147
		this, 
jhilmer@142
   148
		SLOT(verticalAlignmentChanged(VerticalAlignment)));
jhilmer@142
   149
    }
jhilmer@142
   150
    int verticalAlignment() const { return m_verticalAlignment; } 
jhilmer@142
   151
 signals:
jhilmer@142
   152
    void currentVerticalAlignmentChanged(int a);
jhilmer@142
   153
 public slots:
jhilmer@142
   154
    void verticalAlignmentChanged(VerticalAlignment a) {
jhilmer@142
   155
     m_verticalAlignment = a;
jhilmer@142
   156
	emit currentVerticalAlignmentChanged((int)a);
jhilmer@142
   157
    }
jhilmer@142
   158
 private: 
jhilmer@142
   159
 int m_verticalAlignment;
insilmaril@0
   160
};
insilmaril@0
   161
insilmaril@0
   162
#endif