Port xconfig to Qt5 - Use QList
[firefly-linux-kernel-4.4.55.git] / scripts / kconfig / qconf.h
1 /*
2  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3  * Released under the terms of the GNU GPL v2.0.
4  */
5
6 #include <q3listview.h>
7 #include <QMainWindow>
8 #include <qsettings.h>
9
10 class ConfigView;
11 class ConfigList;
12 class ConfigItem;
13 class ConfigLineEdit;
14 class ConfigMainWindow;
15
16 class ConfigSettings : public QSettings {
17 public:
18         ConfigSettings();
19         QList<int> readSizes(const QString& key, bool *ok);
20         bool writeSizes(const QString& key, const QList<int>& value);
21 };
22
23 enum colIdx {
24         promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
25 };
26 enum listMode {
27         singleMode, menuMode, symbolMode, fullMode, listMode
28 };
29 enum optionMode {
30         normalOpt = 0, allOpt, promptOpt
31 };
32
33 class ConfigList : public Q3ListView {
34         Q_OBJECT
35         typedef class Q3ListView Parent;
36 public:
37         ConfigList(ConfigView* p, const char *name = 0);
38         void reinit(void);
39         ConfigView* parent(void) const
40         {
41                 return (ConfigView*)Parent::parent();
42         }
43         ConfigItem* findConfigItem(struct menu *);
44
45 protected:
46         void keyPressEvent(QKeyEvent *e);
47         void contentsMousePressEvent(QMouseEvent *e);
48         void contentsMouseReleaseEvent(QMouseEvent *e);
49         void contentsMouseMoveEvent(QMouseEvent *e);
50         void contentsMouseDoubleClickEvent(QMouseEvent *e);
51         void focusInEvent(QFocusEvent *e);
52         void contextMenuEvent(QContextMenuEvent *e);
53
54 public slots:
55         void setRootMenu(struct menu *menu);
56
57         void updateList(ConfigItem *item);
58         void setValue(ConfigItem* item, tristate val);
59         void changeValue(ConfigItem* item);
60         void updateSelection(void);
61         void saveSettings(void);
62 signals:
63         void menuChanged(struct menu *menu);
64         void menuSelected(struct menu *menu);
65         void parentSelected(void);
66         void gotFocus(struct menu *);
67
68 public:
69         void updateListAll(void)
70         {
71                 updateAll = true;
72                 updateList(NULL);
73                 updateAll = false;
74         }
75         ConfigList* listView()
76         {
77                 return this;
78         }
79         ConfigItem* firstChild() const
80         {
81                 return (ConfigItem *)Parent::firstChild();
82         }
83         int mapIdx(colIdx idx)
84         {
85                 return colMap[idx];
86         }
87         void addColumn(colIdx idx, const QString& label)
88         {
89                 colMap[idx] = Parent::addColumn(label);
90                 colRevMap[colMap[idx]] = idx;
91         }
92         void removeColumn(colIdx idx)
93         {
94                 int col = colMap[idx];
95                 if (col >= 0) {
96                         Parent::removeColumn(col);
97                         colRevMap[col] = colMap[idx] = -1;
98                 }
99         }
100         void setAllOpen(bool open);
101         void setParentMenu(void);
102
103         bool menuSkip(struct menu *);
104
105         template <class P>
106         void updateMenuList(P*, struct menu*);
107
108         bool updateAll;
109
110         QPixmap symbolYesPix, symbolModPix, symbolNoPix;
111         QPixmap choiceYesPix, choiceNoPix;
112         QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
113
114         bool showName, showRange, showData;
115         enum listMode mode;
116         enum optionMode optMode;
117         struct menu *rootEntry;
118         QColorGroup disabledColorGroup;
119         QColorGroup inactivedColorGroup;
120         Q3PopupMenu* headerPopup;
121
122 private:
123         int colMap[colNr];
124         int colRevMap[colNr];
125 };
126
127 class ConfigItem : public Q3ListViewItem {
128         typedef class Q3ListViewItem Parent;
129 public:
130         ConfigItem(Q3ListView *parent, ConfigItem *after, struct menu *m, bool v)
131         : Parent(parent, after), menu(m), visible(v), goParent(false)
132         {
133                 init();
134         }
135         ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
136         : Parent(parent, after), menu(m), visible(v), goParent(false)
137         {
138                 init();
139         }
140         ConfigItem(Q3ListView *parent, ConfigItem *after, bool v)
141         : Parent(parent, after), menu(0), visible(v), goParent(true)
142         {
143                 init();
144         }
145         ~ConfigItem(void);
146         void init(void);
147         void okRename(int col);
148         void updateMenu(void);
149         void testUpdateMenu(bool v);
150         ConfigList* listView() const
151         {
152                 return (ConfigList*)Parent::listView();
153         }
154         ConfigItem* firstChild() const
155         {
156                 return (ConfigItem *)Parent::firstChild();
157         }
158         ConfigItem* nextSibling() const
159         {
160                 return (ConfigItem *)Parent::nextSibling();
161         }
162         void setText(colIdx idx, const QString& text)
163         {
164                 Parent::setText(listView()->mapIdx(idx), text);
165         }
166         QString text(colIdx idx) const
167         {
168                 return Parent::text(listView()->mapIdx(idx));
169         }
170         void setPixmap(colIdx idx, const QPixmap& pm)
171         {
172                 Parent::setPixmap(listView()->mapIdx(idx), pm);
173         }
174         const QPixmap* pixmap(colIdx idx) const
175         {
176                 return Parent::pixmap(listView()->mapIdx(idx));
177         }
178         void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
179
180         ConfigItem* nextItem;
181         struct menu *menu;
182         bool visible;
183         bool goParent;
184 };
185
186 class ConfigLineEdit : public QLineEdit {
187         Q_OBJECT
188         typedef class QLineEdit Parent;
189 public:
190         ConfigLineEdit(ConfigView* parent);
191         ConfigView* parent(void) const
192         {
193                 return (ConfigView*)Parent::parent();
194         }
195         void show(ConfigItem *i);
196         void keyPressEvent(QKeyEvent *e);
197
198 public:
199         ConfigItem *item;
200 };
201
202 class ConfigView : public Q3VBox {
203         Q_OBJECT
204         typedef class Q3VBox Parent;
205 public:
206         ConfigView(QWidget* parent, const char *name = 0);
207         ~ConfigView(void);
208         static void updateList(ConfigItem* item);
209         static void updateListAll(void);
210
211         bool showName(void) const { return list->showName; }
212         bool showRange(void) const { return list->showRange; }
213         bool showData(void) const { return list->showData; }
214 public slots:
215         void setShowName(bool);
216         void setShowRange(bool);
217         void setShowData(bool);
218         void setOptionMode(QAction *);
219 signals:
220         void showNameChanged(bool);
221         void showRangeChanged(bool);
222         void showDataChanged(bool);
223 public:
224         ConfigList* list;
225         ConfigLineEdit* lineEdit;
226
227         static ConfigView* viewList;
228         ConfigView* nextView;
229
230         static QAction *showNormalAction;
231         static QAction *showAllAction;
232         static QAction *showPromptAction;
233 };
234
235 class ConfigInfoView : public Q3TextBrowser {
236         Q_OBJECT
237         typedef class Q3TextBrowser Parent;
238 public:
239         ConfigInfoView(QWidget* parent, const char *name = 0);
240         bool showDebug(void) const { return _showDebug; }
241
242 public slots:
243         void setInfo(struct menu *menu);
244         void saveSettings(void);
245         void setShowDebug(bool);
246
247 signals:
248         void showDebugChanged(bool);
249         void menuSelected(struct menu *);
250
251 protected:
252         void symbolInfo(void);
253         void menuInfo(void);
254         QString debug_info(struct symbol *sym);
255         static QString print_filter(const QString &str);
256         static void expr_print_help(void *data, struct symbol *sym, const char *str);
257         Q3PopupMenu* createPopupMenu(const QPoint& pos);
258         void contentsContextMenuEvent(QContextMenuEvent *e);
259
260         struct symbol *sym;
261         struct menu *_menu;
262         bool _showDebug;
263 };
264
265 class ConfigSearchWindow : public QDialog {
266         Q_OBJECT
267         typedef class QDialog Parent;
268 public:
269         ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
270
271 public slots:
272         void saveSettings(void);
273         void search(void);
274
275 protected:
276         QLineEdit* editField;
277         QPushButton* searchButton;
278         QSplitter* split;
279         ConfigView* list;
280         ConfigInfoView* info;
281
282         struct symbol **result;
283 };
284
285 class ConfigMainWindow : public QMainWindow {
286         Q_OBJECT
287
288         static QAction *saveAction;
289         static void conf_changed(void);
290 public:
291         ConfigMainWindow(void);
292 public slots:
293         void changeMenu(struct menu *);
294         void setMenuLink(struct menu *);
295         void listFocusChanged(void);
296         void goBack(void);
297         void loadConfig(void);
298         bool saveConfig(void);
299         void saveConfigAs(void);
300         void searchConfig(void);
301         void showSingleView(void);
302         void showSplitView(void);
303         void showFullView(void);
304         void showIntro(void);
305         void showAbout(void);
306         void saveSettings(void);
307
308 protected:
309         void closeEvent(QCloseEvent *e);
310
311         ConfigSearchWindow *searchWindow;
312         ConfigView *menuView;
313         ConfigList *menuList;
314         ConfigView *configView;
315         ConfigList *configList;
316         ConfigInfoView *helpText;
317         QToolBar *toolBar;
318         QAction *backAction;
319         QSplitter* split1;
320         QSplitter* split2;
321 };