diff options
author | Dmitry Gamza <gamzad@yahoo.com> | 2014-05-12 09:59:24 +0400 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2014-05-12 19:05:19 +0200 |
commit | 440ff9500bc74cc278e0b66f528cfdf624547240 (patch) | |
tree | eed9c67fa3d282e33821267ca0d7d94bb97dc7e7 /utils/regtools/qeditor/utils.h | |
parent | 7b590a953639714cf8ea4b550dd7f6558698e23f (diff) | |
download | rockbox-440ff9500bc74cc278e0b66f528cfdf624547240.tar.gz rockbox-440ff9500bc74cc278e0b66f528cfdf624547240.zip |
qeditor: on Windows it’s not impossible to create a file with AUX
Change-Id: Ic7ef01328eccbed4afddb0a09d2afbb6c1f6a28f
Reviewed-on: http://gerrit.rockbox.org/811
Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
Diffstat (limited to 'utils/regtools/qeditor/utils.h')
-rw-r--r-- | utils/regtools/qeditor/utils.h | 277 |
1 files changed, 277 insertions, 0 deletions
diff --git a/utils/regtools/qeditor/utils.h b/utils/regtools/qeditor/utils.h new file mode 100644 index 0000000000..ee08f1f31b --- /dev/null +++ b/utils/regtools/qeditor/utils.h | |||
@@ -0,0 +1,277 @@ | |||
1 | #ifndef AUX_H | ||
2 | #define AUX_H | ||
3 | |||
4 | #include <QEvent> | ||
5 | #include <QPaintEvent> | ||
6 | #include <QLineEdit> | ||
7 | #include <QValidator> | ||
8 | #include <QToolButton> | ||
9 | #include <QMenu> | ||
10 | #include <QHBoxLayout> | ||
11 | #include <QTextEdit> | ||
12 | #include <QTableWidget> | ||
13 | #include <QToolBar> | ||
14 | #include <QLabel> | ||
15 | #include <QHBoxLayout> | ||
16 | #include <QItemEditorCreatorBase> | ||
17 | #include <QStyledItemDelegate> | ||
18 | #include "backend.h" | ||
19 | |||
20 | class SocBitRangeValidator : public QValidator | ||
21 | { | ||
22 | Q_OBJECT | ||
23 | public: | ||
24 | SocBitRangeValidator(QObject *parent = 0); | ||
25 | |||
26 | virtual void fixup(QString& input) const; | ||
27 | virtual State validate(QString& input, int& pos) const; | ||
28 | /* validate and return the interpreted value */ | ||
29 | State parse(const QString& input, int& last_bit, int& first_bit) const; | ||
30 | }; | ||
31 | |||
32 | class SocFieldValidator : public QValidator | ||
33 | { | ||
34 | Q_OBJECT | ||
35 | public: | ||
36 | SocFieldValidator(QObject *parent = 0); | ||
37 | SocFieldValidator(const soc_reg_field_t& field, QObject *parent = 0); | ||
38 | |||
39 | virtual void fixup(QString& input) const; | ||
40 | virtual State validate(QString& input, int& pos) const; | ||
41 | /* validate and return the interpreted value */ | ||
42 | State parse(const QString& input, soc_word_t& val) const; | ||
43 | |||
44 | protected: | ||
45 | soc_reg_field_t m_field; | ||
46 | }; | ||
47 | |||
48 | class RegLineEdit : public QWidget | ||
49 | { | ||
50 | Q_OBJECT | ||
51 | public: | ||
52 | enum EditMode | ||
53 | { | ||
54 | Write, Set, Clear, Toggle | ||
55 | }; | ||
56 | |||
57 | RegLineEdit(QWidget *parent = 0); | ||
58 | ~RegLineEdit(); | ||
59 | void SetReadOnly(bool ro); | ||
60 | void EnableSCT(bool en); | ||
61 | void SetMode(EditMode mode); | ||
62 | EditMode GetMode(); | ||
63 | QLineEdit *GetLineEdit(); | ||
64 | void setText(const QString& text); | ||
65 | QString text() const; | ||
66 | |||
67 | Q_PROPERTY(QString text READ text WRITE setText USER true) | ||
68 | |||
69 | protected slots: | ||
70 | void OnWriteAct(); | ||
71 | void OnSetAct(); | ||
72 | void OnClearAct(); | ||
73 | void OnToggleAct(); | ||
74 | protected: | ||
75 | void ShowMode(bool show); | ||
76 | void DoAutoHide(); | ||
77 | |||
78 | QHBoxLayout *m_layout; | ||
79 | QToolButton *m_button; | ||
80 | QLineEdit *m_edit; | ||
81 | EditMode m_mode; | ||
82 | bool m_has_sct; | ||
83 | bool m_readonly; | ||
84 | QMenu *m_menu; | ||
85 | }; | ||
86 | |||
87 | class SocFieldItemDelegate : public QStyledItemDelegate | ||
88 | { | ||
89 | public: | ||
90 | SocFieldItemDelegate(QObject *parent = 0):QStyledItemDelegate(parent), m_bitcount(32) {} | ||
91 | SocFieldItemDelegate(const soc_reg_field_t& field, QObject *parent = 0) | ||
92 | :QStyledItemDelegate(parent), m_bitcount(field.last_bit - field.first_bit + 1) {} | ||
93 | |||
94 | virtual QString displayText(const QVariant& value, const QLocale& locale) const; | ||
95 | protected: | ||
96 | int m_bitcount; | ||
97 | }; | ||
98 | |||
99 | class SocFieldEditor : public QLineEdit | ||
100 | { | ||
101 | Q_OBJECT | ||
102 | Q_PROPERTY(uint field READ field WRITE setField USER true) | ||
103 | public: | ||
104 | SocFieldEditor(const soc_reg_field_t& field, QWidget *parent = 0); | ||
105 | virtual ~SocFieldEditor(); | ||
106 | |||
107 | uint field() const; | ||
108 | void setField(uint field); | ||
109 | void SetRegField(const soc_reg_field_t& field) { m_reg_field = field; } | ||
110 | |||
111 | protected: | ||
112 | SocFieldValidator *m_validator; | ||
113 | uint m_field; | ||
114 | soc_reg_field_t m_reg_field; | ||
115 | }; | ||
116 | |||
117 | class SocFieldEditorCreator : public QItemEditorCreatorBase | ||
118 | { | ||
119 | public: | ||
120 | SocFieldEditorCreator() { m_field.first_bit = 0; m_field.last_bit = 31; } | ||
121 | SocFieldEditorCreator(const soc_reg_field_t& field):m_field(field) {} | ||
122 | |||
123 | virtual QWidget *createWidget(QWidget *parent) const; | ||
124 | virtual QByteArray valuePropertyName() const; | ||
125 | |||
126 | protected: | ||
127 | soc_reg_field_t m_field; | ||
128 | }; | ||
129 | |||
130 | class SocFieldCachedValue | ||
131 | { | ||
132 | public: | ||
133 | SocFieldCachedValue():m_value(0) {} | ||
134 | SocFieldCachedValue(const soc_reg_field_t& field, uint value) | ||
135 | :m_field(field), m_value(value) {} | ||
136 | virtual ~SocFieldCachedValue() {} | ||
137 | const soc_reg_field_t& field() const { return m_field; } | ||
138 | uint value() const { return m_value; } | ||
139 | protected: | ||
140 | soc_reg_field_t m_field; | ||
141 | uint m_value; | ||
142 | }; | ||
143 | |||
144 | Q_DECLARE_METATYPE(SocFieldCachedValue) | ||
145 | |||
146 | class SocFieldCachedItemDelegate : public QStyledItemDelegate | ||
147 | { | ||
148 | public: | ||
149 | SocFieldCachedItemDelegate(QObject *parent = 0):QStyledItemDelegate(parent) {} | ||
150 | |||
151 | virtual QString displayText(const QVariant& value, const QLocale& locale) const; | ||
152 | }; | ||
153 | |||
154 | class SocFieldCachedEditor : public SocFieldEditor | ||
155 | { | ||
156 | Q_OBJECT | ||
157 | Q_PROPERTY(SocFieldCachedValue value READ value WRITE setValue USER true) | ||
158 | public: | ||
159 | SocFieldCachedEditor(QWidget *parent = 0); | ||
160 | virtual ~SocFieldCachedEditor(); | ||
161 | |||
162 | SocFieldCachedValue value() const; | ||
163 | void setValue(SocFieldCachedValue field); | ||
164 | protected: | ||
165 | SocFieldCachedValue m_value; | ||
166 | }; | ||
167 | |||
168 | class SocFieldCachedEditorCreator : public QItemEditorCreatorBase | ||
169 | { | ||
170 | public: | ||
171 | SocFieldCachedEditorCreator() {} | ||
172 | |||
173 | virtual QWidget *createWidget(QWidget *parent) const; | ||
174 | virtual QByteArray valuePropertyName() const; | ||
175 | |||
176 | protected: | ||
177 | }; | ||
178 | |||
179 | class RegSexyDisplay : public QWidget | ||
180 | { | ||
181 | Q_OBJECT | ||
182 | public: | ||
183 | RegSexyDisplay(const SocRegRef& reg, QWidget *parent = 0); | ||
184 | |||
185 | QSize minimumSizeHint() const; | ||
186 | QSize sizeHint() const; | ||
187 | |||
188 | protected: | ||
189 | int marginSize() const; | ||
190 | int separatorSize() const; | ||
191 | int columnWidth() const; | ||
192 | int headerHeight() const; | ||
193 | int gapHeight() const; | ||
194 | int maxContentHeight() const; | ||
195 | int textSep() const; | ||
196 | void paintEvent(QPaintEvent *event); | ||
197 | |||
198 | private: | ||
199 | SocRegRef m_reg; | ||
200 | mutable QSize m_size; | ||
201 | }; | ||
202 | |||
203 | class GrowingTextEdit : public QTextEdit | ||
204 | { | ||
205 | Q_OBJECT | ||
206 | public: | ||
207 | GrowingTextEdit(QWidget *parent = 0); | ||
208 | |||
209 | protected slots: | ||
210 | void TextChanged(); | ||
211 | }; | ||
212 | |||
213 | class GrowingTableWidget : public QTableWidget | ||
214 | { | ||
215 | Q_OBJECT | ||
216 | public: | ||
217 | GrowingTableWidget(QWidget *parent = 0); | ||
218 | |||
219 | protected slots: | ||
220 | void DataChanged(const QModelIndex& tl, const QModelIndex& br); | ||
221 | }; | ||
222 | |||
223 | class MyTextEditor : public QWidget | ||
224 | { | ||
225 | Q_OBJECT | ||
226 | public: | ||
227 | MyTextEditor(QWidget *parent = 0); | ||
228 | void SetGrowingMode(bool en); | ||
229 | void SetReadOnly(bool ro); | ||
230 | void SetTextHtml(const QString& text); | ||
231 | QString GetTextHtml(); | ||
232 | bool IsModified(); | ||
233 | signals: | ||
234 | void OnTextChanged(); | ||
235 | |||
236 | protected slots: | ||
237 | void OnInternalTextChanged(); | ||
238 | void OnTextBold(bool checked); | ||
239 | void OnTextItalic(bool checked); | ||
240 | void OnTextUnderline(bool checked); | ||
241 | void OnCharFormatChanged(const QTextCharFormat& fmt); | ||
242 | |||
243 | protected: | ||
244 | bool m_growing_mode; | ||
245 | bool m_read_only; | ||
246 | QToolBar *m_toolbar; | ||
247 | QTextEdit *m_edit; | ||
248 | QToolButton *m_bold_button; | ||
249 | QToolButton *m_italic_button; | ||
250 | QToolButton *m_underline_button; | ||
251 | }; | ||
252 | |||
253 | class MySwitchableTextEditor : public QWidget | ||
254 | { | ||
255 | Q_OBJECT | ||
256 | public: | ||
257 | MySwitchableTextEditor(QWidget *parent = 0); | ||
258 | QString GetTextHtml(); | ||
259 | void SetTextHtml(const QString& text); | ||
260 | void SetEditorMode(bool en); | ||
261 | MyTextEditor *GetEditor(); | ||
262 | QLineEdit *GetLineEdit(); | ||
263 | QLabel *GetLabel(); | ||
264 | void SetLineMode(bool en); | ||
265 | bool IsModified(); | ||
266 | |||
267 | protected: | ||
268 | void UpdateVisibility(); | ||
269 | |||
270 | bool m_editor_mode; | ||
271 | bool m_line_mode; | ||
272 | QLabel *m_label; | ||
273 | MyTextEditor *m_edit; | ||
274 | QLineEdit *m_line; | ||
275 | }; | ||
276 | |||
277 | #endif /* AUX_H */ | ||