]> git.sven.stormbind.net Git - sven/vym.git/blob - src/texteditor.h
New upstream version 2.9.22
[sven/vym.git] / src / texteditor.h
1 #ifndef TEXTEDITOR_H
2 #define TEXTEDITOR_H
3
4 #include <QMainWindow>
5 #include <QtGui>
6
7 class QTextEdit;
8 class QComboBox;
9
10 #include "vymtext.h"
11
12 enum EditorState { inactiveEditor, emptyEditor, filledEditor };
13
14 class TextEditor : public QMainWindow {
15     Q_OBJECT
16   public:
17     TextEditor();
18     ~TextEditor();
19
20     void init(const QString &ename);
21     bool isEmpty();
22     void setEditorName(const QString &);
23     void setEditorTitle(const QString &t = "");
24     QString getEditorTitle();
25     void setFont(const QFont &);
26     void setFontHint(const QString &);
27     QString getFontHint();
28     QString getFontHintDefault();
29     void setFilename(const QString &);
30     QString getFilename();
31     void setFilenameHint(const QString &);
32     QString getFilenameHint();
33     QString getText();
34     VymText getVymText();
35
36     bool findText(const QString &, const QTextDocument::FindFlags &);
37     bool findText(const QString &, const QTextDocument::FindFlags &, int i);
38     void setTextCursor(const QTextCursor &cursor);
39     QTextCursor getTextCursor();
40     void setFocus();
41
42   protected:
43     void setupFileActions();
44     void setupEditActions();
45     void setupFormatActions();
46     void setupSettingsActions();
47     void closeEvent(QCloseEvent *);
48     bool eventFilter(QObject *obj, QEvent *ev);
49
50   public slots:
51     void editorChanged(); // received when text() changed
52     void setRichText(const QString &t);
53     void setPlainText(const QString &t);
54     void setTextAuto(const QString &); // set Text and autodetect mode
55     void setVymText(const VymText &vt);
56     void setInactive(); // Nothing can be entered
57     void editCopyAll();
58     void clear();
59
60   protected slots:
61     void deleteAll();
62
63   signals:
64     void textHasChanged(const VymText &vt);
65     void windowClosed();
66     void fontFamilyHasChanged();
67     void fontSizeHasChanged();
68
69   private slots:
70     void textLoad();
71     void textSaveAs();
72     void textSave();
73     void textExportAsASCII();
74     void textPrint();
75     void textEditUndo();
76     void toggleFonthint();
77     void setRichTextMode(bool b);
78     void toggleRichText();
79     void setFixedFont();
80     void setVarFont();
81     void textBold();
82     void textUnderline();
83     void textItalic();
84     void textFamily(const QString &f);
85     void textSize(const QString &p);
86     void textColor();
87     void textAlign(QAction *);
88     void textVAlign();
89     void fontChanged(const QFont &f);
90     void colorChanged(const QColor &c);
91     void formatChanged(const QTextCharFormat &f);
92     void alignmentChanged(int a);
93     void verticalAlignmentChanged(QTextCharFormat::VerticalAlignment);
94     void updateActions();
95     void setState(EditorState);
96     void updateState();
97     void selectColorRichTextDefaultBackground();
98     void selectColorRichTextDefaultForeground();
99
100   public:
101     void setColorRichTextDefaultForeground(const QColor &);
102     void setColorRichTextDefaultBackground(const QColor &);
103     void setColorMapBackground(const QColor&);
104     void setUseColorMapBackground(bool);
105
106   protected:
107     QString shortcutScope; // used for settings and shortcut scopes
108     QTextEdit *e;
109     QPoint lastPos;     // save last position of window
110     QString editorName; // Name of editor, e.g. note editor, heading editor, ...
111     QString editorTitle; // window title: Editor name + selected branch
112     QString filename;
113     QString filenameHint;
114
115     EditorState state;
116     bool blockChangedSignal;
117     bool blockTextUpdate;       // Set *while* textHasChanged is still being emitted
118
119     QColor colorRichTextDefaultBackground;
120     QColor colorRichTextDefaultForeground;
121     QColor colorMapBackground;
122     bool useColorMapBackground;
123
124     QFont varFont;
125     QFont fixedFont;
126     QComboBox *comboFont, *comboSize;
127
128     QToolBar *editToolBar;
129     QToolBar *fontToolBar;
130     QToolBar *fontHintsToolBar;
131     QToolBar *formatToolBar;
132
133     QAction *actionFileLoad, *actionFileSave, *actionFileSaveAs,
134         *actionFilePrint, *actionFileDeleteAll, *actionEditUndo,
135         *actionEditRedo, *actionEditCopy, *actionEditCut, *actionEditPaste,
136         *actionFormatUseFixedFont, *actionFormatRichText,
137         *actionSettingsVarFont, *actionSettingsFixedFont,
138         *actionSettingsFonthintDefault, *actionEmptyEditorColor,
139         *actionFilledEditorColor, *actionInactiveEditorColor, *actionFontColor;
140
141     QAction *actionTextBold, *actionTextUnderline, *actionTextItalic,
142         *actionTextColor, *actionAlignSubScript, *actionAlignSuperScript,
143         *actionAlignLeft, *actionAlignCenter, *actionAlignRight,
144         *actionAlignJustify;
145 };
146
147 #endif