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