summaryrefslogtreecommitdiff
path: root/utils/regtools/qeditor/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/regtools/qeditor/utils.h')
-rw-r--r--utils/regtools/qeditor/utils.h277
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
20class SocBitRangeValidator : public QValidator
21{
22 Q_OBJECT
23public:
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
32class SocFieldValidator : public QValidator
33{
34 Q_OBJECT
35public:
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
44protected:
45 soc_reg_field_t m_field;
46};
47
48class RegLineEdit : public QWidget
49{
50 Q_OBJECT
51public:
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
69protected slots:
70 void OnWriteAct();
71 void OnSetAct();
72 void OnClearAct();
73 void OnToggleAct();
74protected:
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
87class SocFieldItemDelegate : public QStyledItemDelegate
88{
89public:
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;
95protected:
96 int m_bitcount;
97};
98
99class SocFieldEditor : public QLineEdit
100{
101 Q_OBJECT
102 Q_PROPERTY(uint field READ field WRITE setField USER true)
103public:
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
111protected:
112 SocFieldValidator *m_validator;
113 uint m_field;
114 soc_reg_field_t m_reg_field;
115};
116
117class SocFieldEditorCreator : public QItemEditorCreatorBase
118{
119public:
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
126protected:
127 soc_reg_field_t m_field;
128};
129
130class SocFieldCachedValue
131{
132public:
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; }
139protected:
140 soc_reg_field_t m_field;
141 uint m_value;
142};
143
144Q_DECLARE_METATYPE(SocFieldCachedValue)
145
146class SocFieldCachedItemDelegate : public QStyledItemDelegate
147{
148public:
149 SocFieldCachedItemDelegate(QObject *parent = 0):QStyledItemDelegate(parent) {}
150
151 virtual QString displayText(const QVariant& value, const QLocale& locale) const;
152};
153
154class SocFieldCachedEditor : public SocFieldEditor
155{
156 Q_OBJECT
157 Q_PROPERTY(SocFieldCachedValue value READ value WRITE setValue USER true)
158public:
159 SocFieldCachedEditor(QWidget *parent = 0);
160 virtual ~SocFieldCachedEditor();
161
162 SocFieldCachedValue value() const;
163 void setValue(SocFieldCachedValue field);
164protected:
165 SocFieldCachedValue m_value;
166};
167
168class SocFieldCachedEditorCreator : public QItemEditorCreatorBase
169{
170public:
171 SocFieldCachedEditorCreator() {}
172
173 virtual QWidget *createWidget(QWidget *parent) const;
174 virtual QByteArray valuePropertyName() const;
175
176protected:
177};
178
179class RegSexyDisplay : public QWidget
180{
181 Q_OBJECT
182public:
183 RegSexyDisplay(const SocRegRef& reg, QWidget *parent = 0);
184
185 QSize minimumSizeHint() const;
186 QSize sizeHint() const;
187
188protected:
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
198private:
199 SocRegRef m_reg;
200 mutable QSize m_size;
201};
202
203class GrowingTextEdit : public QTextEdit
204{
205 Q_OBJECT
206public:
207 GrowingTextEdit(QWidget *parent = 0);
208
209protected slots:
210 void TextChanged();
211};
212
213class GrowingTableWidget : public QTableWidget
214{
215 Q_OBJECT
216public:
217 GrowingTableWidget(QWidget *parent = 0);
218
219protected slots:
220 void DataChanged(const QModelIndex& tl, const QModelIndex& br);
221};
222
223class MyTextEditor : public QWidget
224{
225 Q_OBJECT
226public:
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();
233signals:
234 void OnTextChanged();
235
236protected 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
243protected:
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
253class MySwitchableTextEditor : public QWidget
254{
255 Q_OBJECT
256public:
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
267protected:
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 */