summaryrefslogtreecommitdiffstats
path: root/utils/regtools/qeditor/aux.h
blob: d6a572826c79ba88cbc010ac654c7f6cfb074829 (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#ifndef AUX_H
#define AUX_H

#include <QEvent>
#include <QPaintEvent>
#include <QLineEdit>
#include <QValidator>
#include <QToolButton>
#include <QMenu>
#include <QHBoxLayout>
#include <QTextEdit>
#include <QTableWidget>
#include <QToolBar>
#include <QLabel>
#include <QHBoxLayout>
#include <QItemEditorCreatorBase>
#include <QStyledItemDelegate>
#include "backend.h"

class SocBitRangeValidator : public QValidator
{
    Q_OBJECT
public:
    SocBitRangeValidator(QObject *parent = 0);

    virtual void fixup(QString& input) const;
    virtual State validate(QString& input, int& pos) const;
    /* validate and return the interpreted value */
    State parse(const QString& input, int& last_bit, int& first_bit) const;
};

class SocFieldValidator : public QValidator
{
    Q_OBJECT
public:
    SocFieldValidator(QObject *parent = 0);
    SocFieldValidator(const soc_reg_field_t& field, QObject *parent = 0);

    virtual void fixup(QString& input) const;
    virtual State validate(QString& input, int& pos) const;
    /* validate and return the interpreted value */
    State parse(const QString& input, soc_word_t& val) const;

protected:
    soc_reg_field_t m_field;
};

class RegLineEdit : public QWidget
{
    Q_OBJECT
public:
    enum EditMode
    {
        Write, Set, Clear, Toggle
    };

    RegLineEdit(QWidget *parent = 0);
    ~RegLineEdit();
    void SetReadOnly(bool ro);
    void EnableSCT(bool en);
    void SetMode(EditMode mode);
    EditMode GetMode();
    QLineEdit *GetLineEdit();
    void setText(const QString& text);
    QString text() const;

    Q_PROPERTY(QString text READ text WRITE setText USER true)

protected slots:
    void OnWriteAct();
    void OnSetAct();
    void OnClearAct();
    void OnToggleAct();
protected:
    void ShowMode(bool show);
    void DoAutoHide();

    QHBoxLayout *m_layout;
    QToolButton *m_button;
    QLineEdit *m_edit;
    EditMode m_mode;
    bool m_has_sct;
    bool m_readonly;
    QMenu *m_menu;
};

class SocFieldItemDelegate : public QStyledItemDelegate
{
public:
    SocFieldItemDelegate(QObject *parent = 0):QStyledItemDelegate(parent), m_bitcount(32) {}
    SocFieldItemDelegate(const soc_reg_field_t& field, QObject *parent = 0)
        :QStyledItemDelegate(parent), m_bitcount(field.last_bit - field.first_bit + 1) {}

    virtual QString displayText(const QVariant& value, const QLocale& locale) const;
protected:
    int m_bitcount;
};

class SocFieldEditor : public QLineEdit
{
    Q_OBJECT
    Q_PROPERTY(uint field READ field WRITE setField USER true)
public:
    SocFieldEditor(const soc_reg_field_t& field, QWidget *parent = 0);
    virtual ~SocFieldEditor();

    uint field() const;
    void setField(uint field);

protected:
    SocFieldValidator *m_validator;
    uint m_field;
    soc_reg_field_t m_reg_field;
};

class SocFieldEditorCreator : public QItemEditorCreatorBase
{
public:
    SocFieldEditorCreator() { m_field.first_bit = 0; m_field.last_bit = 31; }
    SocFieldEditorCreator(const soc_reg_field_t& field):m_field(field) {}

    virtual QWidget *createWidget(QWidget *parent) const;
    virtual QByteArray valuePropertyName() const;

protected:
    soc_reg_field_t m_field;
};

class RegSexyDisplay : public QWidget
{
    Q_OBJECT
public:
    RegSexyDisplay(const SocRegRef& reg, QWidget *parent = 0);

    QSize minimumSizeHint() const;
    QSize sizeHint() const;

protected:
    int marginSize() const;
    int separatorSize() const;
    int columnWidth() const;
    int headerHeight() const;
    int gapHeight() const;
    int maxContentHeight() const;
    int textSep() const;
    void paintEvent(QPaintEvent *event);

private:
    SocRegRef m_reg;
    mutable QSize m_size;
};

class GrowingTextEdit : public QTextEdit
{
    Q_OBJECT
public:
    GrowingTextEdit(QWidget *parent = 0);

protected slots:
    void TextChanged();
};

class GrowingTableWidget : public QTableWidget
{
    Q_OBJECT
public:
    GrowingTableWidget(QWidget *parent = 0);

protected slots:
    void DataChanged(const QModelIndex& tl, const QModelIndex& br);
};

class MyTextEditor : public QWidget
{
    Q_OBJECT
public:
    MyTextEditor(QWidget *parent = 0);
    void SetGrowingMode(bool en);
    void SetReadOnly(bool ro);
    void SetTextHtml(const QString& text);
    QString GetTextHtml();
    bool IsModified();
signals:
    void OnTextChanged();

protected slots:
    void OnInternalTextChanged();
    void OnTextBold(bool checked);
    void OnTextItalic(bool checked);
    void OnTextUnderline(bool checked);
    void OnCharFormatChanged(const QTextCharFormat& fmt);

protected:
    bool m_growing_mode;
    bool m_read_only;
    QToolBar *m_toolbar;
    QTextEdit *m_edit;
    QToolButton *m_bold_button;
    QToolButton *m_italic_button;
    QToolButton *m_underline_button;
};

class MySwitchableTextEditor : public QWidget
{
    Q_OBJECT
public:
    MySwitchableTextEditor(QWidget *parent = 0);
    QString GetTextHtml();
    void SetTextHtml(const QString& text);
    void SetEditorMode(bool en);
    MyTextEditor *GetEditor();
    QLineEdit *GetLineEdit();
    QLabel *GetLabel();
    void SetLineMode(bool en);
    bool IsModified();

protected:
    void UpdateVisibility();

    bool m_editor_mode;
    bool m_line_mode;
    QLabel *m_label;
    MyTextEditor *m_edit;
    QLineEdit *m_line;
};

#endif /* AUX_H */