summaryrefslogtreecommitdiff
path: root/utils/regtools/qeditor/aux.h
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-04-07 11:28:04 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-05-01 19:34:18 +0200
commit4356666101e0e7985e65a19f86bc4a74519e93f9 (patch)
treebf8de8057d93d0fab0a30cae92a90f5a4edc79dc /utils/regtools/qeditor/aux.h
parent3754624edc48539c5cc5acbf426ce909477e87d8 (diff)
downloadrockbox-4356666101e0e7985e65a19f86bc4a74519e93f9.tar.gz
rockbox-4356666101e0e7985e65a19f86bc4a74519e93f9.zip
regtools: completely rework qeditor, improve soc desc library and tools
The graphical editor can now display and editor description files. The library has been improved to provide more useful function. The XML format has been slightly changed: only one soc is allowed per file (this is was already de facto the case since <soc> was the root tag). Also introduce a DTD to validate the files. Change-Id: If70ba35b6dc0242bdb87411cf4baee9597798aac
Diffstat (limited to 'utils/regtools/qeditor/aux.h')
-rw-r--r--utils/regtools/qeditor/aux.h227
1 files changed, 227 insertions, 0 deletions
diff --git a/utils/regtools/qeditor/aux.h b/utils/regtools/qeditor/aux.h
new file mode 100644
index 0000000000..d6a572826c
--- /dev/null
+++ b/utils/regtools/qeditor/aux.h
@@ -0,0 +1,227 @@
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
110protected:
111 SocFieldValidator *m_validator;
112 uint m_field;
113 soc_reg_field_t m_reg_field;
114};
115
116class SocFieldEditorCreator : public QItemEditorCreatorBase
117{
118public:
119 SocFieldEditorCreator() { m_field.first_bit = 0; m_field.last_bit = 31; }
120 SocFieldEditorCreator(const soc_reg_field_t& field):m_field(field) {}
121
122 virtual QWidget *createWidget(QWidget *parent) const;
123 virtual QByteArray valuePropertyName() const;
124
125protected:
126 soc_reg_field_t m_field;
127};
128
129class RegSexyDisplay : public QWidget
130{
131 Q_OBJECT
132public:
133 RegSexyDisplay(const SocRegRef& reg, QWidget *parent = 0);
134
135 QSize minimumSizeHint() const;
136 QSize sizeHint() const;
137
138protected:
139 int marginSize() const;
140 int separatorSize() const;
141 int columnWidth() const;
142 int headerHeight() const;
143 int gapHeight() const;
144 int maxContentHeight() const;
145 int textSep() const;
146 void paintEvent(QPaintEvent *event);
147
148private:
149 SocRegRef m_reg;
150 mutable QSize m_size;
151};
152
153class GrowingTextEdit : public QTextEdit
154{
155 Q_OBJECT
156public:
157 GrowingTextEdit(QWidget *parent = 0);
158
159protected slots:
160 void TextChanged();
161};
162
163class GrowingTableWidget : public QTableWidget
164{
165 Q_OBJECT
166public:
167 GrowingTableWidget(QWidget *parent = 0);
168
169protected slots:
170 void DataChanged(const QModelIndex& tl, const QModelIndex& br);
171};
172
173class MyTextEditor : public QWidget
174{
175 Q_OBJECT
176public:
177 MyTextEditor(QWidget *parent = 0);
178 void SetGrowingMode(bool en);
179 void SetReadOnly(bool ro);
180 void SetTextHtml(const QString& text);
181 QString GetTextHtml();
182 bool IsModified();
183signals:
184 void OnTextChanged();
185
186protected slots:
187 void OnInternalTextChanged();
188 void OnTextBold(bool checked);
189 void OnTextItalic(bool checked);
190 void OnTextUnderline(bool checked);
191 void OnCharFormatChanged(const QTextCharFormat& fmt);
192
193protected:
194 bool m_growing_mode;
195 bool m_read_only;
196 QToolBar *m_toolbar;
197 QTextEdit *m_edit;
198 QToolButton *m_bold_button;
199 QToolButton *m_italic_button;
200 QToolButton *m_underline_button;
201};
202
203class MySwitchableTextEditor : public QWidget
204{
205 Q_OBJECT
206public:
207 MySwitchableTextEditor(QWidget *parent = 0);
208 QString GetTextHtml();
209 void SetTextHtml(const QString& text);
210 void SetEditorMode(bool en);
211 MyTextEditor *GetEditor();
212 QLineEdit *GetLineEdit();
213 QLabel *GetLabel();
214 void SetLineMode(bool en);
215 bool IsModified();
216
217protected:
218 void UpdateVisibility();
219
220 bool m_editor_mode;
221 bool m_line_mode;
222 QLabel *m_label;
223 MyTextEditor *m_edit;
224 QLineEdit *m_line;
225};
226
227#endif /* AUX_H */