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