blob: a193137f2314605f436ec77dc1345f6e9b0c060e [file] [log] [blame]
Masahiro Yamada0c874102018-12-18 21:13:35 +09001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07006#include <QCheckBox>
7#include <QDialog>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +02008#include <QHeaderView>
9#include <QLineEdit>
10#include <QMainWindow>
11#include <QPushButton>
12#include <QSettings>
13#include <QSplitter>
14#include <QTextBrowser>
15#include <QTreeWidget>
16
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070017#include "expr.h"
Alexander Stein133c5f72010-08-31 17:34:37 +020018
Roman Zippel7fc925f2006-06-08 22:12:46 -070019class ConfigView;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -070020class ConfigList;
21class ConfigItem;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022class ConfigLineEdit;
23class ConfigMainWindow;
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025class ConfigSettings : public QSettings {
26public:
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010027 ConfigSettings();
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070028 QList<int> readSizes(const QString& key, bool *ok);
29 bool writeSizes(const QString& key, const QList<int>& value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030};
31
32enum colIdx {
33 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
34};
35enum listMode {
Roman Zippel43bf6122006-06-08 22:12:45 -070036 singleMode, menuMode, symbolMode, fullMode, listMode
Linus Torvalds1da177e2005-04-16 15:20:36 -070037};
Li Zefan39a48972010-05-10 16:33:41 +080038enum optionMode {
39 normalOpt = 0, allOpt, promptOpt
40};
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Boris Barbulovski1019f1a2015-09-22 11:36:17 -070042class ConfigList : public QTreeWidget {
43 Q_OBJECT
44 typedef class QTreeWidget Parent;
45public:
46 ConfigList(ConfigView* p, const char *name = 0);
Boris Barbulovski59e56442015-09-22 11:36:18 -070047 void reinit(void);
48 ConfigView* parent(void) const
49 {
50 return (ConfigView*)Parent::parent();
51 }
52 ConfigItem* findConfigItem(struct menu *);
53
54protected:
55 void keyPressEvent(QKeyEvent *e);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070056 void mousePressEvent(QMouseEvent *e);
57 void mouseReleaseEvent(QMouseEvent *e);
58 void mouseMoveEvent(QMouseEvent *e);
59 void mouseDoubleClickEvent(QMouseEvent *e);
Boris Barbulovski59e56442015-09-22 11:36:18 -070060 void focusInEvent(QFocusEvent *e);
61 void contextMenuEvent(QContextMenuEvent *e);
62
63public slots:
64 void setRootMenu(struct menu *menu);
65
66 void updateList(ConfigItem *item);
67 void setValue(ConfigItem* item, tristate val);
68 void changeValue(ConfigItem* item);
69 void updateSelection(void);
70 void saveSettings(void);
71signals:
72 void menuChanged(struct menu *menu);
73 void menuSelected(struct menu *menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +020074 void itemSelected(struct menu *menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -070075 void parentSelected(void);
76 void gotFocus(struct menu *);
77
78public:
79 void updateListAll(void)
80 {
81 updateAll = true;
82 updateList(NULL);
83 updateAll = false;
84 }
85 ConfigList* listView()
86 {
87 return this;
88 }
89 ConfigItem* firstChild() const
90 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070091 return (ConfigItem *)children().first();
Boris Barbulovski59e56442015-09-22 11:36:18 -070092 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070093 void addColumn(colIdx idx)
Boris Barbulovski59e56442015-09-22 11:36:18 -070094 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070095 showColumn(idx);
Boris Barbulovski59e56442015-09-22 11:36:18 -070096 }
97 void removeColumn(colIdx idx)
98 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070099 hideColumn(idx);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700100 }
101 void setAllOpen(bool open);
102 void setParentMenu(void);
103
104 bool menuSkip(struct menu *);
105
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700106 void updateMenuList(ConfigItem *parent, struct menu*);
107 void updateMenuList(ConfigList *parent, struct menu*);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700108
109 bool updateAll;
110
111 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
112 QPixmap choiceYesPix, choiceNoPix;
113 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
114
115 bool showName, showRange, showData;
116 enum listMode mode;
117 enum optionMode optMode;
118 struct menu *rootEntry;
119 QPalette disabledColorGroup;
120 QPalette inactivedColorGroup;
121 QMenu* headerPopup;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700122};
123
124class ConfigItem : public QTreeWidgetItem {
125 typedef class QTreeWidgetItem Parent;
126public:
Boris Barbulovskid960b982015-09-22 11:36:30 -0700127 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700128 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700129 {
130 init();
131 }
132 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700133 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700134 {
135 init();
136 }
Boris Barbulovskid960b982015-09-22 11:36:30 -0700137 ConfigItem(ConfigList *parent, ConfigItem *after, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700138 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700139 {
140 init();
141 }
142 ~ConfigItem(void);
143 void init(void);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700144 void okRename(int col);
145 void updateMenu(void);
146 void testUpdateMenu(bool v);
147 ConfigList* listView() const
148 {
149 return (ConfigList*)Parent::treeWidget();
150 }
151 ConfigItem* firstChild() const
152 {
153 return (ConfigItem *)Parent::child(0);
154 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700155 ConfigItem* nextSibling()
Boris Barbulovski59e56442015-09-22 11:36:18 -0700156 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700157 ConfigItem *ret = NULL;
158 ConfigItem *_parent = (ConfigItem *)parent();
159
160 if(_parent) {
Boris Barbulovskib3c48f92015-09-22 11:36:32 -0700161 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700162 } else {
Boris Barbulovskib3c48f92015-09-22 11:36:32 -0700163 QTreeWidget *_treeWidget = treeWidget();
164 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700165 }
166
167 return ret;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700168 }
169 void setText(colIdx idx, const QString& text)
170 {
171 Parent::setText(idx, text);
172 }
173 QString text(colIdx idx) const
174 {
175 return Parent::text(idx);
176 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700177 void setPixmap(colIdx idx, const QIcon &icon)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700178 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700179 Parent::setIcon(idx, icon);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700180 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700181 const QIcon pixmap(colIdx idx) const
Boris Barbulovski59e56442015-09-22 11:36:18 -0700182 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700183 return icon(idx);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700184 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700185 // TODO: Implement paintCell
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700186
187 ConfigItem* nextItem;
188 struct menu *menu;
189 bool visible;
190 bool goParent;
191};
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193class ConfigLineEdit : public QLineEdit {
194 Q_OBJECT
195 typedef class QLineEdit Parent;
196public:
Roman Zippel43bf6122006-06-08 22:12:45 -0700197 ConfigLineEdit(ConfigView* parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 ConfigView* parent(void) const
199 {
200 return (ConfigView*)Parent::parent();
201 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700202 void show(ConfigItem *i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 void keyPressEvent(QKeyEvent *e);
204
205public:
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700206 ConfigItem *item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207};
208
Boris Barbulovski34d63202015-09-22 11:36:09 -0700209class ConfigView : public QWidget {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700210 Q_OBJECT
Boris Barbulovski34d63202015-09-22 11:36:09 -0700211 typedef class QWidget Parent;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700212public:
213 ConfigView(QWidget* parent, const char *name = 0);
214 ~ConfigView(void);
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700215 static void updateList(ConfigItem* item);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700216 static void updateListAll(void);
217
Boris Barbulovski59e56442015-09-22 11:36:18 -0700218 bool showName(void) const { return list->showName; }
219 bool showRange(void) const { return list->showRange; }
220 bool showData(void) const { return list->showData; }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700221public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700222 void setShowName(bool);
223 void setShowRange(bool);
224 void setShowData(bool);
Li Zefan39a48972010-05-10 16:33:41 +0800225 void setOptionMode(QAction *);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700226signals:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700227 void showNameChanged(bool);
228 void showRangeChanged(bool);
229 void showDataChanged(bool);
230public:
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700231 ConfigList* list;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700232 ConfigLineEdit* lineEdit;
233
234 static ConfigView* viewList;
235 ConfigView* nextView;
Li Zefan39a48972010-05-10 16:33:41 +0800236
237 static QAction *showNormalAction;
238 static QAction *showAllAction;
239 static QAction *showPromptAction;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700240};
241
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700242class ConfigInfoView : public QTextBrowser {
Roman Zippel43bf6122006-06-08 22:12:45 -0700243 Q_OBJECT
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700244 typedef class QTextBrowser Parent;
Roman Zippel43bf6122006-06-08 22:12:45 -0700245public:
246 ConfigInfoView(QWidget* parent, const char *name = 0);
247 bool showDebug(void) const { return _showDebug; }
248
249public slots:
250 void setInfo(struct menu *menu);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700251 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700252 void setShowDebug(bool);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +0200253 void clicked (const QUrl &url);
Roman Zippel43bf6122006-06-08 22:12:45 -0700254
255signals:
256 void showDebugChanged(bool);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700257 void menuSelected(struct menu *);
Roman Zippel43bf6122006-06-08 22:12:45 -0700258
259protected:
Roman Zippelab45d192006-06-08 22:12:47 -0700260 void symbolInfo(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700261 void menuInfo(void);
262 QString debug_info(struct symbol *sym);
263 static QString print_filter(const QString &str);
Roman Zippelab45d192006-06-08 22:12:47 -0700264 static void expr_print_help(void *data, struct symbol *sym, const char *str);
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700265 QMenu *createStandardContextMenu(const QPoint & pos);
266 void contextMenuEvent(QContextMenuEvent *e);
Roman Zippel43bf6122006-06-08 22:12:45 -0700267
Roman Zippelab45d192006-06-08 22:12:47 -0700268 struct symbol *sym;
Alexander Stein133c5f72010-08-31 17:34:37 +0200269 struct menu *_menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700270 bool _showDebug;
271};
272
273class ConfigSearchWindow : public QDialog {
274 Q_OBJECT
275 typedef class QDialog Parent;
276public:
Marco Costalba63431e72006-10-05 19:12:59 +0200277 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700278
Roman Zippel43bf6122006-06-08 22:12:45 -0700279public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700280 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700281 void search(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700282
Roman Zippel43bf6122006-06-08 22:12:45 -0700283protected:
284 QLineEdit* editField;
285 QPushButton* searchButton;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700286 QSplitter* split;
Roman Zippel43bf6122006-06-08 22:12:45 -0700287 ConfigView* list;
288 ConfigInfoView* info;
289
290 struct symbol **result;
291};
292
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700293class ConfigMainWindow : public QMainWindow {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 Q_OBJECT
Karsten Wiese3b354c52006-12-13 00:34:08 -0800295
Masahiro Yamada87419082019-03-11 01:13:15 +0900296 char *configname;
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700297 static QAction *saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -0800298 static void conf_changed(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299public:
300 ConfigMainWindow(void);
301public slots:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 void changeMenu(struct menu *);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200303 void changeItens(struct menu *);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700304 void setMenuLink(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 void listFocusChanged(void);
306 void goBack(void);
307 void loadConfig(void);
Michal Marekbac6aa82011-05-25 15:10:25 +0200308 bool saveConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 void saveConfigAs(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700310 void searchConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 void showSingleView(void);
312 void showSplitView(void);
313 void showFullView(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 void showIntro(void);
315 void showAbout(void);
316 void saveSettings(void);
317
318protected:
319 void closeEvent(QCloseEvent *e);
320
Roman Zippel43bf6122006-06-08 22:12:45 -0700321 ConfigSearchWindow *searchWindow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 ConfigView *menuView;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700323 ConfigList *menuList;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 ConfigView *configView;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700325 ConfigList *configList;
Roman Zippel43bf6122006-06-08 22:12:45 -0700326 ConfigInfoView *helpText;
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700327 QToolBar *toolBar;
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700328 QAction *backAction;
Boris Barbulovski780505e2015-09-22 11:36:13 -0700329 QAction *singleViewAction;
330 QAction *splitViewAction;
331 QAction *fullViewAction;
Boris Barbulovski76538662015-09-22 11:36:14 -0700332 QSplitter *split1;
333 QSplitter *split2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334};