blob: 460b858b0faa8ccc7b0d7faa9032aeecbc7c9673 [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);
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +020048 ConfigItem* findConfigItem(struct menu *);
Boris Barbulovski59e56442015-09-22 11:36:18 -070049 ConfigView* parent(void) const
50 {
51 return (ConfigView*)Parent::parent();
52 }
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +020053 void setSelected(QTreeWidgetItem *item, bool enable) {
54 for (int i = 0; i < selectedItems().size(); i++)
55 selectedItems().at(i)->setSelected(false);
56
57 item->setSelected(enable);
58 }
Boris Barbulovski59e56442015-09-22 11:36:18 -070059
60protected:
61 void keyPressEvent(QKeyEvent *e);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070062 void mousePressEvent(QMouseEvent *e);
63 void mouseReleaseEvent(QMouseEvent *e);
64 void mouseMoveEvent(QMouseEvent *e);
65 void mouseDoubleClickEvent(QMouseEvent *e);
Boris Barbulovski59e56442015-09-22 11:36:18 -070066 void focusInEvent(QFocusEvent *e);
67 void contextMenuEvent(QContextMenuEvent *e);
68
69public slots:
70 void setRootMenu(struct menu *menu);
71
Masahiro Yamadacb770432020-08-07 18:18:59 +090072 void updateList();
Boris Barbulovski59e56442015-09-22 11:36:18 -070073 void setValue(ConfigItem* item, tristate val);
74 void changeValue(ConfigItem* item);
75 void updateSelection(void);
76 void saveSettings(void);
77signals:
78 void menuChanged(struct menu *menu);
79 void menuSelected(struct menu *menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +020080 void itemSelected(struct menu *menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -070081 void parentSelected(void);
82 void gotFocus(struct menu *);
83
84public:
85 void updateListAll(void)
86 {
87 updateAll = true;
Masahiro Yamadacb770432020-08-07 18:18:59 +090088 updateList();
Boris Barbulovski59e56442015-09-22 11:36:18 -070089 updateAll = false;
90 }
Boris Barbulovski59e56442015-09-22 11:36:18 -070091 void setAllOpen(bool open);
92 void setParentMenu(void);
93
94 bool menuSkip(struct menu *);
95
Boris Barbulovski5c6f1552015-09-22 11:36:27 -070096 void updateMenuList(ConfigItem *parent, struct menu*);
Masahiro Yamada5b75a6c2020-08-07 18:19:01 +090097 void updateMenuList(struct menu *menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -070098
99 bool updateAll;
100
Boris Barbulovski59e56442015-09-22 11:36:18 -0700101 bool showName, showRange, showData;
102 enum listMode mode;
103 enum optionMode optMode;
104 struct menu *rootEntry;
105 QPalette disabledColorGroup;
106 QPalette inactivedColorGroup;
107 QMenu* headerPopup;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700108};
109
110class ConfigItem : public QTreeWidgetItem {
111 typedef class QTreeWidgetItem Parent;
112public:
Boris Barbulovskid960b982015-09-22 11:36:30 -0700113 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700114 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700115 {
116 init();
117 }
118 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700119 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700120 {
121 init();
122 }
Boris Barbulovskid960b982015-09-22 11:36:30 -0700123 ConfigItem(ConfigList *parent, ConfigItem *after, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700124 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700125 {
126 init();
127 }
128 ~ConfigItem(void);
129 void init(void);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700130 void okRename(int col);
131 void updateMenu(void);
132 void testUpdateMenu(bool v);
133 ConfigList* listView() const
134 {
135 return (ConfigList*)Parent::treeWidget();
136 }
137 ConfigItem* firstChild() const
138 {
139 return (ConfigItem *)Parent::child(0);
140 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700141 ConfigItem* nextSibling()
Boris Barbulovski59e56442015-09-22 11:36:18 -0700142 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700143 ConfigItem *ret = NULL;
144 ConfigItem *_parent = (ConfigItem *)parent();
145
146 if(_parent) {
Boris Barbulovskib3c48f92015-09-22 11:36:32 -0700147 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700148 } else {
Boris Barbulovskib3c48f92015-09-22 11:36:32 -0700149 QTreeWidget *_treeWidget = treeWidget();
150 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700151 }
152
153 return ret;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700154 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700155 // TODO: Implement paintCell
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700156
157 ConfigItem* nextItem;
158 struct menu *menu;
159 bool visible;
160 bool goParent;
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900161
162 static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon;
163 static QIcon choiceYesIcon, choiceNoIcon;
164 static QIcon menuIcon, menubackIcon;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700165};
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167class ConfigLineEdit : public QLineEdit {
168 Q_OBJECT
169 typedef class QLineEdit Parent;
170public:
Roman Zippel43bf6122006-06-08 22:12:45 -0700171 ConfigLineEdit(ConfigView* parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 ConfigView* parent(void) const
173 {
174 return (ConfigView*)Parent::parent();
175 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700176 void show(ConfigItem *i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 void keyPressEvent(QKeyEvent *e);
178
179public:
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700180 ConfigItem *item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181};
182
Boris Barbulovski34d63202015-09-22 11:36:09 -0700183class ConfigView : public QWidget {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700184 Q_OBJECT
Boris Barbulovski34d63202015-09-22 11:36:09 -0700185 typedef class QWidget Parent;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700186public:
187 ConfigView(QWidget* parent, const char *name = 0);
188 ~ConfigView(void);
Masahiro Yamada10316852020-08-07 18:19:00 +0900189 static void updateList();
Roman Zippel7fc925f2006-06-08 22:12:46 -0700190 static void updateListAll(void);
191
Boris Barbulovski59e56442015-09-22 11:36:18 -0700192 bool showName(void) const { return list->showName; }
193 bool showRange(void) const { return list->showRange; }
194 bool showData(void) const { return list->showData; }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700195public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700196 void setShowName(bool);
197 void setShowRange(bool);
198 void setShowData(bool);
Li Zefan39a48972010-05-10 16:33:41 +0800199 void setOptionMode(QAction *);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700200signals:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700201 void showNameChanged(bool);
202 void showRangeChanged(bool);
203 void showDataChanged(bool);
204public:
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700205 ConfigList* list;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700206 ConfigLineEdit* lineEdit;
207
208 static ConfigView* viewList;
209 ConfigView* nextView;
Li Zefan39a48972010-05-10 16:33:41 +0800210
211 static QAction *showNormalAction;
212 static QAction *showAllAction;
213 static QAction *showPromptAction;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700214};
215
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700216class ConfigInfoView : public QTextBrowser {
Roman Zippel43bf6122006-06-08 22:12:45 -0700217 Q_OBJECT
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700218 typedef class QTextBrowser Parent;
Roman Zippel43bf6122006-06-08 22:12:45 -0700219public:
220 ConfigInfoView(QWidget* parent, const char *name = 0);
221 bool showDebug(void) const { return _showDebug; }
222
223public slots:
224 void setInfo(struct menu *menu);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700225 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700226 void setShowDebug(bool);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +0200227 void clicked (const QUrl &url);
Roman Zippel43bf6122006-06-08 22:12:45 -0700228
229signals:
230 void showDebugChanged(bool);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700231 void menuSelected(struct menu *);
Roman Zippel43bf6122006-06-08 22:12:45 -0700232
233protected:
Roman Zippelab45d192006-06-08 22:12:47 -0700234 void symbolInfo(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700235 void menuInfo(void);
236 QString debug_info(struct symbol *sym);
237 static QString print_filter(const QString &str);
Roman Zippelab45d192006-06-08 22:12:47 -0700238 static void expr_print_help(void *data, struct symbol *sym, const char *str);
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700239 QMenu *createStandardContextMenu(const QPoint & pos);
240 void contextMenuEvent(QContextMenuEvent *e);
Roman Zippel43bf6122006-06-08 22:12:45 -0700241
Roman Zippelab45d192006-06-08 22:12:47 -0700242 struct symbol *sym;
Alexander Stein133c5f72010-08-31 17:34:37 +0200243 struct menu *_menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700244 bool _showDebug;
245};
246
247class ConfigSearchWindow : public QDialog {
248 Q_OBJECT
249 typedef class QDialog Parent;
250public:
Masahiro Yamada740fdef2020-08-07 18:18:57 +0900251 ConfigSearchWindow(ConfigMainWindow *parent);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700252
Roman Zippel43bf6122006-06-08 22:12:45 -0700253public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700254 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700255 void search(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700256
Roman Zippel43bf6122006-06-08 22:12:45 -0700257protected:
258 QLineEdit* editField;
259 QPushButton* searchButton;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700260 QSplitter* split;
Roman Zippel43bf6122006-06-08 22:12:45 -0700261 ConfigView* list;
262 ConfigInfoView* info;
263
264 struct symbol **result;
265};
266
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700267class ConfigMainWindow : public QMainWindow {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 Q_OBJECT
Karsten Wiese3b354c52006-12-13 00:34:08 -0800269
Masahiro Yamada87419082019-03-11 01:13:15 +0900270 char *configname;
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700271 static QAction *saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -0800272 static void conf_changed(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273public:
274 ConfigMainWindow(void);
275public slots:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 void changeMenu(struct menu *);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200277 void changeItens(struct menu *);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700278 void setMenuLink(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 void listFocusChanged(void);
280 void goBack(void);
281 void loadConfig(void);
Michal Marekbac6aa82011-05-25 15:10:25 +0200282 bool saveConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 void saveConfigAs(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700284 void searchConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 void showSingleView(void);
286 void showSplitView(void);
287 void showFullView(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 void showIntro(void);
289 void showAbout(void);
290 void saveSettings(void);
291
292protected:
293 void closeEvent(QCloseEvent *e);
294
Roman Zippel43bf6122006-06-08 22:12:45 -0700295 ConfigSearchWindow *searchWindow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 ConfigView *menuView;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700297 ConfigList *menuList;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 ConfigView *configView;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700299 ConfigList *configList;
Roman Zippel43bf6122006-06-08 22:12:45 -0700300 ConfigInfoView *helpText;
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700301 QAction *backAction;
Boris Barbulovski780505e2015-09-22 11:36:13 -0700302 QAction *singleViewAction;
303 QAction *splitViewAction;
304 QAction *fullViewAction;
Boris Barbulovski76538662015-09-22 11:36:14 -0700305 QSplitter *split1;
306 QSplitter *split2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307};