blob: 78b0a1dfcd53dee44083dcf3d0efdcd0bd905998 [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>
Masahiro Yamada37162a62020-08-29 17:14:12 +090014#include <QStyledItemDelegate>
Mauro Carvalho Chehabcf81dfa2020-06-30 08:26:35 +020015#include <QTextBrowser>
16#include <QTreeWidget>
17
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070018#include "expr.h"
Alexander Stein133c5f72010-08-31 17:34:37 +020019
Boris Barbulovski1019f1a2015-09-22 11:36:17 -070020class ConfigList;
21class ConfigItem;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022class ConfigMainWindow;
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024class ConfigSettings : public QSettings {
25public:
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010026 ConfigSettings();
Boris Barbulovski041fbdc2015-09-22 11:36:05 -070027 QList<int> readSizes(const QString& key, bool *ok);
28 bool writeSizes(const QString& key, const QList<int>& value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029};
30
31enum colIdx {
Masahiro Yamadaa0fce282020-08-29 17:14:16 +090032 promptColIdx, nameColIdx, dataColIdx
Linus Torvalds1da177e2005-04-16 15:20:36 -070033};
34enum listMode {
Roman Zippel43bf6122006-06-08 22:12:45 -070035 singleMode, menuMode, symbolMode, fullMode, listMode
Linus Torvalds1da177e2005-04-16 15:20:36 -070036};
Li Zefan39a48972010-05-10 16:33:41 +080037enum optionMode {
38 normalOpt = 0, allOpt, promptOpt
39};
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Boris Barbulovski1019f1a2015-09-22 11:36:17 -070041class ConfigList : public QTreeWidget {
42 Q_OBJECT
43 typedef class QTreeWidget Parent;
44public:
Masahiro Yamada62ed1652020-08-29 17:14:15 +090045 ConfigList(QWidget *parent, const char *name = 0);
Masahiro Yamadaf9b918f2020-08-29 17:14:10 +090046 ~ConfigList();
Boris Barbulovski59e56442015-09-22 11:36:18 -070047 void reinit(void);
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +020048 ConfigItem* findConfigItem(struct menu *);
Mauro Carvalho Chehabb06c3ec2020-06-30 08:26:38 +020049 void setSelected(QTreeWidgetItem *item, bool enable) {
50 for (int i = 0; i < selectedItems().size(); i++)
51 selectedItems().at(i)->setSelected(false);
52
53 item->setSelected(enable);
54 }
Boris Barbulovski59e56442015-09-22 11:36:18 -070055
56protected:
57 void keyPressEvent(QKeyEvent *e);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070058 void mousePressEvent(QMouseEvent *e);
59 void mouseReleaseEvent(QMouseEvent *e);
60 void mouseMoveEvent(QMouseEvent *e);
61 void mouseDoubleClickEvent(QMouseEvent *e);
Boris Barbulovski59e56442015-09-22 11:36:18 -070062 void focusInEvent(QFocusEvent *e);
63 void contextMenuEvent(QContextMenuEvent *e);
64
65public slots:
66 void setRootMenu(struct menu *menu);
67
Masahiro Yamadacb770432020-08-07 18:18:59 +090068 void updateList();
Boris Barbulovski59e56442015-09-22 11:36:18 -070069 void setValue(ConfigItem* item, tristate val);
70 void changeValue(ConfigItem* item);
71 void updateSelection(void);
72 void saveSettings(void);
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +090073 void setOptionMode(QAction *action);
Masahiro Yamada7930dd92020-08-29 17:14:14 +090074 void setShowName(bool on);
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +090075
Boris Barbulovski59e56442015-09-22 11:36:18 -070076signals:
77 void menuChanged(struct menu *menu);
78 void menuSelected(struct menu *menu);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +020079 void itemSelected(struct menu *menu);
Boris Barbulovski59e56442015-09-22 11:36:18 -070080 void parentSelected(void);
81 void gotFocus(struct menu *);
Masahiro Yamada7930dd92020-08-29 17:14:14 +090082 void showNameChanged(bool on);
Boris Barbulovski59e56442015-09-22 11:36:18 -070083
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
Masahiro Yamadaa0fce282020-08-29 17:14:16 +0900101 bool showName;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700102 enum listMode mode;
103 enum optionMode optMode;
104 struct menu *rootEntry;
105 QPalette disabledColorGroup;
106 QPalette inactivedColorGroup;
107 QMenu* headerPopup;
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +0900108
Masahiro Yamadaf9b918f2020-08-29 17:14:10 +0900109 static QList<ConfigList *> allLists;
110 static void updateListForAll();
111 static void updateListAllForAll();
112
Masahiro Yamadad4bbe8a2020-08-07 18:19:09 +0900113 static QAction *showNormalAction, *showAllAction, *showPromptAction;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700114};
115
116class ConfigItem : public QTreeWidgetItem {
117 typedef class QTreeWidgetItem Parent;
118public:
Boris Barbulovskid960b982015-09-22 11:36:30 -0700119 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700120 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700121 {
122 init();
123 }
124 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700125 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700126 {
127 init();
128 }
Boris Barbulovskid960b982015-09-22 11:36:30 -0700129 ConfigItem(ConfigList *parent, ConfigItem *after, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700130 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700131 {
132 init();
133 }
134 ~ConfigItem(void);
135 void init(void);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700136 void updateMenu(void);
137 void testUpdateMenu(bool v);
138 ConfigList* listView() const
139 {
140 return (ConfigList*)Parent::treeWidget();
141 }
142 ConfigItem* firstChild() const
143 {
144 return (ConfigItem *)Parent::child(0);
145 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700146 ConfigItem* nextSibling()
Boris Barbulovski59e56442015-09-22 11:36:18 -0700147 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700148 ConfigItem *ret = NULL;
149 ConfigItem *_parent = (ConfigItem *)parent();
150
151 if(_parent) {
Boris Barbulovskib3c48f92015-09-22 11:36:32 -0700152 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700153 } else {
Boris Barbulovskib3c48f92015-09-22 11:36:32 -0700154 QTreeWidget *_treeWidget = treeWidget();
155 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700156 }
157
158 return ret;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700159 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700160 // TODO: Implement paintCell
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700161
162 ConfigItem* nextItem;
163 struct menu *menu;
164 bool visible;
165 bool goParent;
Masahiro Yamada5cb255f2020-08-07 18:19:07 +0900166
167 static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon;
168 static QIcon choiceYesIcon, choiceNoIcon;
169 static QIcon menuIcon, menubackIcon;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700170};
171
Masahiro Yamada37162a62020-08-29 17:14:12 +0900172class ConfigItemDelegate : public QStyledItemDelegate
173{
174private:
175 struct menu *menu;
176public:
177 ConfigItemDelegate(QObject *parent = nullptr)
178 : QStyledItemDelegate(parent) {}
179 QWidget *createEditor(QWidget *parent,
180 const QStyleOptionViewItem &option,
181 const QModelIndex &index) const override;
182 void setModelData(QWidget *editor, QAbstractItemModel *model,
183 const QModelIndex &index) const override;
184};
185
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700186class ConfigInfoView : public QTextBrowser {
Roman Zippel43bf6122006-06-08 22:12:45 -0700187 Q_OBJECT
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700188 typedef class QTextBrowser Parent;
Masahiro Yamada7d1300e2020-08-18 01:36:30 +0900189 QMenu *contextMenu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700190public:
191 ConfigInfoView(QWidget* parent, const char *name = 0);
192 bool showDebug(void) const { return _showDebug; }
193
194public slots:
195 void setInfo(struct menu *menu);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700196 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700197 void setShowDebug(bool);
Mauro Carvalho Chehabc4f73982020-06-30 08:26:37 +0200198 void clicked (const QUrl &url);
Roman Zippel43bf6122006-06-08 22:12:45 -0700199
200signals:
201 void showDebugChanged(bool);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700202 void menuSelected(struct menu *);
Roman Zippel43bf6122006-06-08 22:12:45 -0700203
204protected:
Roman Zippelab45d192006-06-08 22:12:47 -0700205 void symbolInfo(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700206 void menuInfo(void);
207 QString debug_info(struct symbol *sym);
208 static QString print_filter(const QString &str);
Roman Zippelab45d192006-06-08 22:12:47 -0700209 static void expr_print_help(void *data, struct symbol *sym, const char *str);
Masahiro Yamada7d1300e2020-08-18 01:36:30 +0900210 void contextMenuEvent(QContextMenuEvent *event);
Roman Zippel43bf6122006-06-08 22:12:45 -0700211
Roman Zippelab45d192006-06-08 22:12:47 -0700212 struct symbol *sym;
Alexander Stein133c5f72010-08-31 17:34:37 +0200213 struct menu *_menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700214 bool _showDebug;
215};
216
217class ConfigSearchWindow : public QDialog {
218 Q_OBJECT
219 typedef class QDialog Parent;
220public:
Masahiro Yamada740fdef2020-08-07 18:18:57 +0900221 ConfigSearchWindow(ConfigMainWindow *parent);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700222
Roman Zippel43bf6122006-06-08 22:12:45 -0700223public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700224 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700225 void search(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700226
Roman Zippel43bf6122006-06-08 22:12:45 -0700227protected:
228 QLineEdit* editField;
229 QPushButton* searchButton;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700230 QSplitter* split;
Masahiro Yamada62ed1652020-08-29 17:14:15 +0900231 ConfigList *list;
Roman Zippel43bf6122006-06-08 22:12:45 -0700232 ConfigInfoView* info;
233
234 struct symbol **result;
235};
236
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700237class ConfigMainWindow : public QMainWindow {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 Q_OBJECT
Karsten Wiese3b354c52006-12-13 00:34:08 -0800239
Masahiro Yamada87419082019-03-11 01:13:15 +0900240 char *configname;
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700241 static QAction *saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -0800242 static void conf_changed(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243public:
244 ConfigMainWindow(void);
245public slots:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 void changeMenu(struct menu *);
Mauro Carvalho Chehabb3111422020-04-02 11:28:01 +0200247 void changeItens(struct menu *);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700248 void setMenuLink(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 void listFocusChanged(void);
250 void goBack(void);
251 void loadConfig(void);
Michal Marekbac6aa82011-05-25 15:10:25 +0200252 bool saveConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 void saveConfigAs(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700254 void searchConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 void showSingleView(void);
256 void showSplitView(void);
257 void showFullView(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 void showIntro(void);
259 void showAbout(void);
260 void saveSettings(void);
261
262protected:
263 void closeEvent(QCloseEvent *e);
264
Roman Zippel43bf6122006-06-08 22:12:45 -0700265 ConfigSearchWindow *searchWindow;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700266 ConfigList *menuList;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700267 ConfigList *configList;
Roman Zippel43bf6122006-06-08 22:12:45 -0700268 ConfigInfoView *helpText;
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700269 QAction *backAction;
Boris Barbulovski780505e2015-09-22 11:36:13 -0700270 QAction *singleViewAction;
271 QAction *splitViewAction;
272 QAction *fullViewAction;
Boris Barbulovski76538662015-09-22 11:36:14 -0700273 QSplitter *split1;
274 QSplitter *split2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275};