texteditor.h
author insilmaril
Mon, 10 Apr 2006 11:21:35 +0000
changeset 287 557a4e13afef
parent 190 68c49789ec0b
child 366 e95081c21da2
permissions -rw-r--r--
switching to KDE icons
     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 class MyTextEdit;
    15 
    16 class TextEditor : public QMainWindow {
    17     Q_OBJECT
    18 public:
    19     TextEditor();
    20     ~TextEditor();
    21 
    22 	bool isEmpty();
    23 	void setShowWithMain (bool);
    24 	bool showWithMain ();
    25 	void setFontHint(const QString&);
    26 	QString getFontHint();
    27 	QString getFontHintDefault();
    28 	void setFilename (const QString&);
    29 	QString getFilename ();
    30 	void setFilenameHint (const QString&);
    31 	QString getFilenameHint ();
    32 	bool findText(const QString &, const bool &); // find Text 
    33 
    34 protected:
    35 	void setupFileActions();
    36 	void setupEditActions();
    37 	void setupFormatActions();
    38 	void setupSettingsActions();
    39     void closeEvent( QCloseEvent* );
    40 	
    41 
    42 public:
    43 	QString getText();
    44 
    45 public slots:
    46 	void editorChanged();	// received when text() changed
    47 	void setText(QString);	// set Text (by MapEditor)
    48 	void setInactive();		// Nothing can be entered
    49 	void editCopyAll();
    50 
    51 signals:
    52 	void textHasChanged();
    53 	void fontFamilyHasChanged();
    54 	void fontSizeHasChanged();
    55 	
    56 private slots:
    57     void textLoad();
    58     void textSaveAs();
    59     void textSave();
    60 	void textConvertPar();
    61 	void textJoinLines();
    62 	void textExportAsASCII();
    63     void textPrint();
    64 	void textEditUndo();
    65     void toggleFonthint();
    66     void setFixedFont();
    67     void setVarFont();
    68     void textBold();
    69     void textUnderline();
    70     void textItalic();
    71     void textFamily( const QString &f );
    72     void textSize( const QString &p );
    73 	void textColor();
    74 	void textAlign(QAction*);
    75 	void textVAlign();
    76     void fontChanged( const QFont &f );
    77     void colorChanged( const QColor &c );
    78     void alignmentChanged( int a );
    79     void verticalAlignmentChanged(int a);
    80 	void enableActions();
    81 	void disableActions();
    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 /* 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 	connect(this, 
   144 		SIGNAL(currentVerticalAlignmentChanged(VerticalAlignment)),
   145 		this, 
   146 		SLOT(verticalAlignmentChanged(VerticalAlignment)));
   147     }
   148     int verticalAlignment() const { return m_verticalAlignment; } 
   149  signals:
   150     void currentVerticalAlignmentChanged(int a);
   151  public slots:
   152     void verticalAlignmentChanged(VerticalAlignment a) {
   153      m_verticalAlignment = a;
   154 	emit currentVerticalAlignmentChanged((int)a);
   155     }
   156  private: 
   157  int m_verticalAlignment;
   158 };
   159 
   160 #endif