Masahiro Yamada | 0c87410 | 2018-12-18 21:13:35 +0900 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 6 | #include <QCheckBox> |
| 7 | #include <QDialog> |
Mauro Carvalho Chehab | cf81dfa | 2020-06-30 08:26:35 +0200 | [diff] [blame] | 8 | #include <QHeaderView> |
| 9 | #include <QLineEdit> |
| 10 | #include <QMainWindow> |
| 11 | #include <QPushButton> |
| 12 | #include <QSettings> |
| 13 | #include <QSplitter> |
Masahiro Yamada | 37162a6 | 2020-08-29 17:14:12 +0900 | [diff] [blame] | 14 | #include <QStyledItemDelegate> |
Mauro Carvalho Chehab | cf81dfa | 2020-06-30 08:26:35 +0200 | [diff] [blame] | 15 | #include <QTextBrowser> |
| 16 | #include <QTreeWidget> |
| 17 | |
Boris Barbulovski | 68ccb7e | 2015-09-22 11:36:15 -0700 | [diff] [blame] | 18 | #include "expr.h" |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 19 | |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 20 | class ConfigList; |
| 21 | class ConfigItem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | class ConfigMainWindow; |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | class ConfigSettings : public QSettings { |
| 25 | public: |
Ben Hutchings | 00d4f8f | 2013-10-06 19:21:31 +0100 | [diff] [blame] | 26 | ConfigSettings(); |
Boris Barbulovski | 041fbdc | 2015-09-22 11:36:05 -0700 | [diff] [blame] | 27 | QList<int> readSizes(const QString& key, bool *ok); |
| 28 | bool writeSizes(const QString& key, const QList<int>& value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | enum colIdx { |
Masahiro Yamada | a0fce28 | 2020-08-29 17:14:16 +0900 | [diff] [blame] | 32 | promptColIdx, nameColIdx, dataColIdx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | }; |
| 34 | enum listMode { |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 35 | singleMode, menuMode, symbolMode, fullMode, listMode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | }; |
Li Zefan | 39a4897 | 2010-05-10 16:33:41 +0800 | [diff] [blame] | 37 | enum optionMode { |
| 38 | normalOpt = 0, allOpt, promptOpt |
| 39 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 41 | class ConfigList : public QTreeWidget { |
| 42 | Q_OBJECT |
| 43 | typedef class QTreeWidget Parent; |
| 44 | public: |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame] | 45 | ConfigList(QWidget *parent, const char *name = 0); |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 46 | ~ConfigList(); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 47 | void reinit(void); |
Mauro Carvalho Chehab | b06c3ec | 2020-06-30 08:26:38 +0200 | [diff] [blame] | 48 | ConfigItem* findConfigItem(struct menu *); |
Mauro Carvalho Chehab | b06c3ec | 2020-06-30 08:26:38 +0200 | [diff] [blame] | 49 | 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 Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 55 | |
| 56 | protected: |
| 57 | void keyPressEvent(QKeyEvent *e); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 58 | void mousePressEvent(QMouseEvent *e); |
| 59 | void mouseReleaseEvent(QMouseEvent *e); |
| 60 | void mouseMoveEvent(QMouseEvent *e); |
| 61 | void mouseDoubleClickEvent(QMouseEvent *e); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 62 | void focusInEvent(QFocusEvent *e); |
| 63 | void contextMenuEvent(QContextMenuEvent *e); |
| 64 | |
| 65 | public slots: |
| 66 | void setRootMenu(struct menu *menu); |
| 67 | |
Masahiro Yamada | cb77043 | 2020-08-07 18:18:59 +0900 | [diff] [blame] | 68 | void updateList(); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 69 | void setValue(ConfigItem* item, tristate val); |
| 70 | void changeValue(ConfigItem* item); |
| 71 | void updateSelection(void); |
| 72 | void saveSettings(void); |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 73 | void setOptionMode(QAction *action); |
Masahiro Yamada | 7930dd9 | 2020-08-29 17:14:14 +0900 | [diff] [blame] | 74 | void setShowName(bool on); |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 75 | |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 76 | signals: |
| 77 | void menuChanged(struct menu *menu); |
| 78 | void menuSelected(struct menu *menu); |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 79 | void itemSelected(struct menu *menu); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 80 | void parentSelected(void); |
| 81 | void gotFocus(struct menu *); |
Masahiro Yamada | 7930dd9 | 2020-08-29 17:14:14 +0900 | [diff] [blame] | 82 | void showNameChanged(bool on); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 83 | |
| 84 | public: |
| 85 | void updateListAll(void) |
| 86 | { |
| 87 | updateAll = true; |
Masahiro Yamada | cb77043 | 2020-08-07 18:18:59 +0900 | [diff] [blame] | 88 | updateList(); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 89 | updateAll = false; |
| 90 | } |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 91 | void setAllOpen(bool open); |
| 92 | void setParentMenu(void); |
| 93 | |
| 94 | bool menuSkip(struct menu *); |
| 95 | |
Boris Barbulovski | 5c6f155 | 2015-09-22 11:36:27 -0700 | [diff] [blame] | 96 | void updateMenuList(ConfigItem *parent, struct menu*); |
Masahiro Yamada | 5b75a6c | 2020-08-07 18:19:01 +0900 | [diff] [blame] | 97 | void updateMenuList(struct menu *menu); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 98 | |
| 99 | bool updateAll; |
| 100 | |
Masahiro Yamada | a0fce28 | 2020-08-29 17:14:16 +0900 | [diff] [blame] | 101 | bool showName; |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 102 | enum listMode mode; |
| 103 | enum optionMode optMode; |
| 104 | struct menu *rootEntry; |
| 105 | QPalette disabledColorGroup; |
| 106 | QPalette inactivedColorGroup; |
| 107 | QMenu* headerPopup; |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 108 | |
Masahiro Yamada | f9b918f | 2020-08-29 17:14:10 +0900 | [diff] [blame] | 109 | static QList<ConfigList *> allLists; |
| 110 | static void updateListForAll(); |
| 111 | static void updateListAllForAll(); |
| 112 | |
Masahiro Yamada | d4bbe8a | 2020-08-07 18:19:09 +0900 | [diff] [blame] | 113 | static QAction *showNormalAction, *showAllAction, *showPromptAction; |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | class ConfigItem : public QTreeWidgetItem { |
| 117 | typedef class QTreeWidgetItem Parent; |
| 118 | public: |
Boris Barbulovski | d960b98 | 2015-09-22 11:36:30 -0700 | [diff] [blame] | 119 | ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v) |
Boris Barbulovski | 86c0528 | 2015-09-22 11:36:25 -0700 | [diff] [blame] | 120 | : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false) |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 121 | { |
| 122 | init(); |
| 123 | } |
| 124 | ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v) |
Boris Barbulovski | 86c0528 | 2015-09-22 11:36:25 -0700 | [diff] [blame] | 125 | : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false) |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 126 | { |
| 127 | init(); |
| 128 | } |
Boris Barbulovski | d960b98 | 2015-09-22 11:36:30 -0700 | [diff] [blame] | 129 | ConfigItem(ConfigList *parent, ConfigItem *after, bool v) |
Boris Barbulovski | 86c0528 | 2015-09-22 11:36:25 -0700 | [diff] [blame] | 130 | : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true) |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 131 | { |
| 132 | init(); |
| 133 | } |
| 134 | ~ConfigItem(void); |
| 135 | void init(void); |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 136 | 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 Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 146 | ConfigItem* nextSibling() |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 147 | { |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 148 | ConfigItem *ret = NULL; |
| 149 | ConfigItem *_parent = (ConfigItem *)parent(); |
| 150 | |
| 151 | if(_parent) { |
Boris Barbulovski | b3c48f9 | 2015-09-22 11:36:32 -0700 | [diff] [blame] | 152 | ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 153 | } else { |
Boris Barbulovski | b3c48f9 | 2015-09-22 11:36:32 -0700 | [diff] [blame] | 154 | QTreeWidget *_treeWidget = treeWidget(); |
| 155 | ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1); |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | return ret; |
Boris Barbulovski | 59e5644 | 2015-09-22 11:36:18 -0700 | [diff] [blame] | 159 | } |
Boris Barbulovski | d5d973c | 2015-09-22 11:36:19 -0700 | [diff] [blame] | 160 | // TODO: Implement paintCell |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 161 | |
| 162 | ConfigItem* nextItem; |
| 163 | struct menu *menu; |
| 164 | bool visible; |
| 165 | bool goParent; |
Masahiro Yamada | 5cb255f | 2020-08-07 18:19:07 +0900 | [diff] [blame] | 166 | |
| 167 | static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon; |
| 168 | static QIcon choiceYesIcon, choiceNoIcon; |
| 169 | static QIcon menuIcon, menubackIcon; |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
Masahiro Yamada | 37162a6 | 2020-08-29 17:14:12 +0900 | [diff] [blame] | 172 | class ConfigItemDelegate : public QStyledItemDelegate |
| 173 | { |
| 174 | private: |
| 175 | struct menu *menu; |
| 176 | public: |
| 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 Barbulovski | 924bbb5 | 2015-09-22 11:36:06 -0700 | [diff] [blame] | 186 | class ConfigInfoView : public QTextBrowser { |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 187 | Q_OBJECT |
Boris Barbulovski | 924bbb5 | 2015-09-22 11:36:06 -0700 | [diff] [blame] | 188 | typedef class QTextBrowser Parent; |
Masahiro Yamada | 7d1300e | 2020-08-18 01:36:30 +0900 | [diff] [blame] | 189 | QMenu *contextMenu; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 190 | public: |
| 191 | ConfigInfoView(QWidget* parent, const char *name = 0); |
| 192 | bool showDebug(void) const { return _showDebug; } |
| 193 | |
| 194 | public slots: |
| 195 | void setInfo(struct menu *menu); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 196 | void saveSettings(void); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 197 | void setShowDebug(bool); |
Mauro Carvalho Chehab | c4f7398 | 2020-06-30 08:26:37 +0200 | [diff] [blame] | 198 | void clicked (const QUrl &url); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 199 | |
| 200 | signals: |
| 201 | void showDebugChanged(bool); |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 202 | void menuSelected(struct menu *); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 203 | |
| 204 | protected: |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 205 | void symbolInfo(void); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 206 | void menuInfo(void); |
| 207 | QString debug_info(struct symbol *sym); |
| 208 | static QString print_filter(const QString &str); |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 209 | static void expr_print_help(void *data, struct symbol *sym, const char *str); |
Masahiro Yamada | 7d1300e | 2020-08-18 01:36:30 +0900 | [diff] [blame] | 210 | void contextMenuEvent(QContextMenuEvent *event); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 211 | |
Roman Zippel | ab45d19 | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 212 | struct symbol *sym; |
Alexander Stein | 133c5f7 | 2010-08-31 17:34:37 +0200 | [diff] [blame] | 213 | struct menu *_menu; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 214 | bool _showDebug; |
| 215 | }; |
| 216 | |
| 217 | class ConfigSearchWindow : public QDialog { |
| 218 | Q_OBJECT |
| 219 | typedef class QDialog Parent; |
| 220 | public: |
Masahiro Yamada | 740fdef | 2020-08-07 18:18:57 +0900 | [diff] [blame] | 221 | ConfigSearchWindow(ConfigMainWindow *parent); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 222 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 223 | public slots: |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 224 | void saveSettings(void); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 225 | void search(void); |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 226 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 227 | protected: |
| 228 | QLineEdit* editField; |
| 229 | QPushButton* searchButton; |
Roman Zippel | 7fc925f | 2006-06-08 22:12:46 -0700 | [diff] [blame] | 230 | QSplitter* split; |
Masahiro Yamada | 62ed165 | 2020-08-29 17:14:15 +0900 | [diff] [blame] | 231 | ConfigList *list; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 232 | ConfigInfoView* info; |
| 233 | |
| 234 | struct symbol **result; |
| 235 | }; |
| 236 | |
Boris Barbulovski | b1f8a45 | 2015-09-22 11:36:02 -0700 | [diff] [blame] | 237 | class ConfigMainWindow : public QMainWindow { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | Q_OBJECT |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 239 | |
Masahiro Yamada | 8741908 | 2019-03-11 01:13:15 +0900 | [diff] [blame] | 240 | char *configname; |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 241 | static QAction *saveAction; |
Karsten Wiese | 3b354c5 | 2006-12-13 00:34:08 -0800 | [diff] [blame] | 242 | static void conf_changed(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | public: |
| 244 | ConfigMainWindow(void); |
| 245 | public slots: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | void changeMenu(struct menu *); |
Mauro Carvalho Chehab | b311142 | 2020-04-02 11:28:01 +0200 | [diff] [blame] | 247 | void changeItens(struct menu *); |
Roman Zippel | b65a47e | 2006-06-08 22:12:47 -0700 | [diff] [blame] | 248 | void setMenuLink(struct menu *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | void listFocusChanged(void); |
| 250 | void goBack(void); |
| 251 | void loadConfig(void); |
Michal Marek | bac6aa8 | 2011-05-25 15:10:25 +0200 | [diff] [blame] | 252 | bool saveConfig(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | void saveConfigAs(void); |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 254 | void searchConfig(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | void showSingleView(void); |
| 256 | void showSplitView(void); |
| 257 | void showFullView(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | void showIntro(void); |
| 259 | void showAbout(void); |
| 260 | void saveSettings(void); |
| 261 | |
| 262 | protected: |
| 263 | void closeEvent(QCloseEvent *e); |
| 264 | |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 265 | ConfigSearchWindow *searchWindow; |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 266 | ConfigList *menuList; |
Boris Barbulovski | 1019f1a | 2015-09-22 11:36:17 -0700 | [diff] [blame] | 267 | ConfigList *configList; |
Roman Zippel | 43bf612 | 2006-06-08 22:12:45 -0700 | [diff] [blame] | 268 | ConfigInfoView *helpText; |
Boris Barbulovski | 85eaf28 | 2015-09-22 11:36:03 -0700 | [diff] [blame] | 269 | QAction *backAction; |
Boris Barbulovski | 780505e | 2015-09-22 11:36:13 -0700 | [diff] [blame] | 270 | QAction *singleViewAction; |
| 271 | QAction *splitViewAction; |
| 272 | QAction *fullViewAction; |
Boris Barbulovski | 7653866 | 2015-09-22 11:36:14 -0700 | [diff] [blame] | 273 | QSplitter *split1; |
| 274 | QSplitter *split2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | }; |