-
Notifications
You must be signed in to change notification settings - Fork 3
/
qcpl_text_editor.h
156 lines (119 loc) · 3.96 KB
/
qcpl_text_editor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifndef QCPL_TEXT_EDITOR_H
#define QCPL_TEXT_EDITOR_H
#include <QWidget>
#include "qcpl_types.h"
QT_BEGIN_NAMESPACE
class QAction;
class QComboBox;
class QFontComboBox;
class QLabel;
class QLineEdit;
class QPlainTextEdit;
class QToolBar;
class QToolButton;
QT_END_NAMESPACE
namespace Ori {
namespace Widgets {
class MenuToolButton;
class BaseColorButton;
}}
namespace QCPL {
/// Full text edit with font and color selectors
class TextEditorWidget : public QWidget
{
Q_OBJECT
public:
struct Options
{
/// If non zero, it will override the default icon size for text toolbar.
QSize iconSize;
/// A list of variables that can be inserted into text via special menu.
/// Or one just can type variable names and they will be highlighted in the text
/// as having special meannig.
QVector<TextVariable> vars;
/// If provided, a command added to vars menu to reset the editor text to this value.
QString defaultText;
bool readOnly = false;
/// Use line editor instead of text editor.
/// If provided, @ref multiLineEditor() returns null.
/// Vars menu doesn't work in this mode.
bool singleLine = false;
/// Show text alignment drop-down
bool showAlignment = false;
/// Show background color selector button in teh toolbar
bool showBackColor = false;
/// Use color with alpha-channel for text
bool colorAlphaText = false;
/// Use color with alpha-channel for background
bool colorAlphaBack = false;
/// Arrange buttons in two narrower tool bars instead of one longer
bool narrow = false;
};
TextEditorWidget(const Options& opts);
void setText(const QString& text);
void setFont(const QFont& font);
void setColor(const QColor& color);
void setBackColor(const QColor& color);
void setTextFlags(int flags);
QString text() const;
QFont font() const;
QColor color() const { return _color; }
QColor backColor() const { return _backColor; }
int textFlags() const;
void addAction(QAction *actn, bool secondToolbar = false);
QPlainTextEdit* multiLineEditor() const { return _textEditor; }
QLineEdit* singleLineEditor() const { return _lineEditor; }
signals:
void acceptRequested();
private slots:
void setFontFamily(const QString& family);
void setFontSize(const QString& size);
private:
Options _opts;
QPlainTextEdit *_textEditor = nullptr;
QLineEdit *_lineEditor = nullptr;
QColor _color, _backColor;
QAction *_actnBold, *_actnItalic, *_actnUnderline;
Ori::Widgets::MenuToolButton* _btnAlign = nullptr;
Ori::Widgets::BaseColorButton *_btnTextColor, *_btnBackColor = nullptr;
QFontComboBox *_comboFont;
QComboBox *_comboSize;
QToolBar *_toolbar1, *_toolbar2;
int _textFlags = 0;
QWidget* editorWidget();
QFont currentFont() const;
void setCurrentFont(const QFont& font);
void selectFont();
void toggleBold();
void toggleItalic();
void toggleUnderline();
void insertVar();
};
/// Simplified text editor having only text field and variables button
class TextOnlyEditorWidget : public QWidget
{
Q_OBJECT
public:
struct Options
{
/// If provided, a command added to vars menu to reset editot text to this value
QString defaultText;
/// A list of variables that can be inserted into text via special menu.
/// Or one just can type variable names and they will be highlighted in the text
/// as having special meannig
QVector<TextVariable> vars;
};
TextOnlyEditorWidget(const Options& opts);
void setText(const QString& text);
QString text() const;
QPlainTextEdit* editor() const { return _editor; }
signals:
void acceptRequested();
protected:
void resizeEvent(QResizeEvent *event) override;
private:
QPlainTextEdit *_editor;
void insertVar();
};
} // namespace QCPL
#endif // QCPL_TEXT_EDITOR_H