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