blob: 676d88db3d9ba66942eb5fd3b1557818c6d18829 [file] [log] [blame]
Patrick Georgi0588d192009-08-12 15:00:51 +00001/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
zbao11a262c2016-01-22 18:54:22 +08006#include <QTextBrowser>
7#include <QTreeWidget>
8#include <QMainWindow>
9#include <QHeaderView>
Patrick Georgid5208402014-04-11 20:24:06 +020010#include <qsettings.h>
zbao11a262c2016-01-22 18:54:22 +080011#include <QPushButton>
12#include <QSettings>
13#include <QLineEdit>
14#include <QSplitter>
15#include <QCheckBox>
16#include <QDialog>
17#include "expr.h"
Patrick Georgi0588d192009-08-12 15:00:51 +000018
19class ConfigView;
20class ConfigList;
21class ConfigItem;
22class ConfigLineEdit;
23class ConfigMainWindow;
24
Patrick Georgi0588d192009-08-12 15:00:51 +000025class ConfigSettings : public QSettings {
26public:
Patrick Georgid5208402014-04-11 20:24:06 +020027 ConfigSettings();
zbao11a262c2016-01-22 18:54:22 +080028 QList<int> readSizes(const QString& key, bool *ok);
29 bool writeSizes(const QString& key, const QList<int>& value);
Patrick Georgi0588d192009-08-12 15:00:51 +000030};
31
32enum colIdx {
33 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
34};
35enum listMode {
36 singleMode, menuMode, symbolMode, fullMode, listMode
37};
Patrick Georgid5208402014-04-11 20:24:06 +020038enum optionMode {
39 normalOpt = 0, allOpt, promptOpt
40};
Patrick Georgi0588d192009-08-12 15:00:51 +000041
zbao11a262c2016-01-22 18:54:22 +080042class ConfigList : public QTreeWidget {
Patrick Georgi0588d192009-08-12 15:00:51 +000043 Q_OBJECT
zbao11a262c2016-01-22 18:54:22 +080044 typedef class QTreeWidget Parent;
Patrick Georgi0588d192009-08-12 15:00:51 +000045public:
Elyes HAOUAS1d3fde42018-06-05 08:41:29 +020046 ConfigList(ConfigView* p, const char *name = NULL);
Patrick Georgi0588d192009-08-12 15:00:51 +000047 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);
zbao11a262c2016-01-22 18:54:22 +080056 void mousePressEvent(QMouseEvent *e);
57 void mouseReleaseEvent(QMouseEvent *e);
58 void mouseMoveEvent(QMouseEvent *e);
59 void mouseDoubleClickEvent(QMouseEvent *e);
Patrick Georgi0588d192009-08-12 15:00:51 +000060 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);
74 void parentSelected(void);
75 void gotFocus(struct menu *);
76
77public:
78 void updateListAll(void)
79 {
80 updateAll = true;
81 updateList(NULL);
82 updateAll = false;
83 }
84 ConfigList* listView()
85 {
86 return this;
87 }
88 ConfigItem* firstChild() const
89 {
zbao11a262c2016-01-22 18:54:22 +080090 return (ConfigItem *)children().first();
Patrick Georgi0588d192009-08-12 15:00:51 +000091 }
zbao11a262c2016-01-22 18:54:22 +080092 void addColumn(colIdx idx)
Patrick Georgi0588d192009-08-12 15:00:51 +000093 {
zbao11a262c2016-01-22 18:54:22 +080094 showColumn(idx);
Patrick Georgi0588d192009-08-12 15:00:51 +000095 }
96 void removeColumn(colIdx idx)
97 {
zbao11a262c2016-01-22 18:54:22 +080098 hideColumn(idx);
Patrick Georgi0588d192009-08-12 15:00:51 +000099 }
100 void setAllOpen(bool open);
101 void setParentMenu(void);
102
Patrick Georgid5208402014-04-11 20:24:06 +0200103 bool menuSkip(struct menu *);
104
zbao11a262c2016-01-22 18:54:22 +0800105 void updateMenuList(ConfigItem *parent, struct menu*);
106 void updateMenuList(ConfigList *parent, struct menu*);
Patrick Georgi0588d192009-08-12 15:00:51 +0000107
108 bool updateAll;
109
110 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
111 QPixmap choiceYesPix, choiceNoPix;
112 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
113
Patrick Georgid5208402014-04-11 20:24:06 +0200114 bool showName, showRange, showData;
Patrick Georgi0588d192009-08-12 15:00:51 +0000115 enum listMode mode;
Patrick Georgid5208402014-04-11 20:24:06 +0200116 enum optionMode optMode;
Patrick Georgi0588d192009-08-12 15:00:51 +0000117 struct menu *rootEntry;
zbao11a262c2016-01-22 18:54:22 +0800118 QPalette disabledColorGroup;
119 QPalette inactivedColorGroup;
120 QMenu* headerPopup;
Patrick Georgi0588d192009-08-12 15:00:51 +0000121};
122
zbao11a262c2016-01-22 18:54:22 +0800123class ConfigItem : public QTreeWidgetItem {
124 typedef class QTreeWidgetItem Parent;
Patrick Georgi0588d192009-08-12 15:00:51 +0000125public:
zbao11a262c2016-01-22 18:54:22 +0800126 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v)
127 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Patrick Georgi0588d192009-08-12 15:00:51 +0000128 {
129 init();
130 }
131 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
zbao11a262c2016-01-22 18:54:22 +0800132 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Patrick Georgi0588d192009-08-12 15:00:51 +0000133 {
134 init();
135 }
zbao11a262c2016-01-22 18:54:22 +0800136 ConfigItem(ConfigList *parent, ConfigItem *after, bool v)
137 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
Patrick Georgi0588d192009-08-12 15:00:51 +0000138 {
139 init();
140 }
141 ~ConfigItem(void);
142 void init(void);
Patrick Georgi0588d192009-08-12 15:00:51 +0000143 void okRename(int col);
Patrick Georgi0588d192009-08-12 15:00:51 +0000144 void updateMenu(void);
145 void testUpdateMenu(bool v);
146 ConfigList* listView() const
147 {
zbao11a262c2016-01-22 18:54:22 +0800148 return (ConfigList*)Parent::treeWidget();
Patrick Georgi0588d192009-08-12 15:00:51 +0000149 }
150 ConfigItem* firstChild() const
151 {
zbao11a262c2016-01-22 18:54:22 +0800152 return (ConfigItem *)Parent::child(0);
Patrick Georgi0588d192009-08-12 15:00:51 +0000153 }
zbao11a262c2016-01-22 18:54:22 +0800154 ConfigItem* nextSibling()
Patrick Georgi0588d192009-08-12 15:00:51 +0000155 {
zbao11a262c2016-01-22 18:54:22 +0800156 ConfigItem *ret = NULL;
157 ConfigItem *_parent = (ConfigItem *)parent();
158
159 if(_parent) {
160 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
161 } else {
162 QTreeWidget *_treeWidget = treeWidget();
163 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
164 }
165
166 return ret;
Patrick Georgi0588d192009-08-12 15:00:51 +0000167 }
168 void setText(colIdx idx, const QString& text)
169 {
zbao11a262c2016-01-22 18:54:22 +0800170 Parent::setText(idx, text);
Patrick Georgi0588d192009-08-12 15:00:51 +0000171 }
172 QString text(colIdx idx) const
173 {
zbao11a262c2016-01-22 18:54:22 +0800174 return Parent::text(idx);
Patrick Georgi0588d192009-08-12 15:00:51 +0000175 }
zbao11a262c2016-01-22 18:54:22 +0800176 void setPixmap(colIdx idx, const QIcon &icon)
Patrick Georgi0588d192009-08-12 15:00:51 +0000177 {
zbao11a262c2016-01-22 18:54:22 +0800178 Parent::setIcon(idx, icon);
Patrick Georgi0588d192009-08-12 15:00:51 +0000179 }
zbao11a262c2016-01-22 18:54:22 +0800180 const QIcon pixmap(colIdx idx) const
Patrick Georgi0588d192009-08-12 15:00:51 +0000181 {
zbao11a262c2016-01-22 18:54:22 +0800182 return icon(idx);
Patrick Georgi0588d192009-08-12 15:00:51 +0000183 }
zbao11a262c2016-01-22 18:54:22 +0800184 // TODO: Implement paintCell
Patrick Georgi0588d192009-08-12 15:00:51 +0000185
186 ConfigItem* nextItem;
187 struct menu *menu;
188 bool visible;
189 bool goParent;
190};
191
192class ConfigLineEdit : public QLineEdit {
193 Q_OBJECT
194 typedef class QLineEdit Parent;
195public:
196 ConfigLineEdit(ConfigView* parent);
197 ConfigView* parent(void) const
198 {
199 return (ConfigView*)Parent::parent();
200 }
201 void show(ConfigItem *i);
202 void keyPressEvent(QKeyEvent *e);
203
204public:
205 ConfigItem *item;
206};
207
zbao11a262c2016-01-22 18:54:22 +0800208class ConfigView : public QWidget {
Patrick Georgi0588d192009-08-12 15:00:51 +0000209 Q_OBJECT
zbao11a262c2016-01-22 18:54:22 +0800210 typedef class QWidget Parent;
Patrick Georgi0588d192009-08-12 15:00:51 +0000211public:
Elyes HAOUAS1d3fde42018-06-05 08:41:29 +0200212 ConfigView(QWidget* parent, const char *name = NULL);
Patrick Georgi0588d192009-08-12 15:00:51 +0000213 ~ConfigView(void);
214 static void updateList(ConfigItem* item);
215 static void updateListAll(void);
216
Patrick Georgi0588d192009-08-12 15:00:51 +0000217 bool showName(void) const { return list->showName; }
218 bool showRange(void) const { return list->showRange; }
219 bool showData(void) const { return list->showData; }
220public slots:
Patrick Georgi0588d192009-08-12 15:00:51 +0000221 void setShowName(bool);
222 void setShowRange(bool);
223 void setShowData(bool);
Patrick Georgid5208402014-04-11 20:24:06 +0200224 void setOptionMode(QAction *);
Patrick Georgi0588d192009-08-12 15:00:51 +0000225signals:
Patrick Georgi0588d192009-08-12 15:00:51 +0000226 void showNameChanged(bool);
227 void showRangeChanged(bool);
228 void showDataChanged(bool);
229public:
230 ConfigList* list;
231 ConfigLineEdit* lineEdit;
232
233 static ConfigView* viewList;
234 ConfigView* nextView;
Patrick Georgid5208402014-04-11 20:24:06 +0200235
236 static QAction *showNormalAction;
237 static QAction *showAllAction;
238 static QAction *showPromptAction;
Patrick Georgi0588d192009-08-12 15:00:51 +0000239};
240
zbao11a262c2016-01-22 18:54:22 +0800241class ConfigInfoView : public QTextBrowser {
Patrick Georgi0588d192009-08-12 15:00:51 +0000242 Q_OBJECT
zbao11a262c2016-01-22 18:54:22 +0800243 typedef class QTextBrowser Parent;
Patrick Georgi0588d192009-08-12 15:00:51 +0000244public:
Elyes HAOUAS1d3fde42018-06-05 08:41:29 +0200245 ConfigInfoView(QWidget* parent, const char *name = NULL);
Patrick Georgi0588d192009-08-12 15:00:51 +0000246 bool showDebug(void) const { return _showDebug; }
247
248public slots:
249 void setInfo(struct menu *menu);
250 void saveSettings(void);
Patrick Georgi0588d192009-08-12 15:00:51 +0000251 void setShowDebug(bool);
252
253signals:
254 void showDebugChanged(bool);
255 void menuSelected(struct menu *);
256
257protected:
258 void symbolInfo(void);
259 void menuInfo(void);
260 QString debug_info(struct symbol *sym);
261 static QString print_filter(const QString &str);
262 static void expr_print_help(void *data, struct symbol *sym, const char *str);
zbao11a262c2016-01-22 18:54:22 +0800263 QMenu *createStandardContextMenu(const QPoint & pos);
264 void contextMenuEvent(QContextMenuEvent *e);
Patrick Georgi0588d192009-08-12 15:00:51 +0000265
266 struct symbol *sym;
Patrick Georgid5208402014-04-11 20:24:06 +0200267 struct menu *_menu;
Patrick Georgi0588d192009-08-12 15:00:51 +0000268 bool _showDebug;
269};
270
271class ConfigSearchWindow : public QDialog {
272 Q_OBJECT
273 typedef class QDialog Parent;
274public:
Elyes HAOUAS1d3fde42018-06-05 08:41:29 +0200275 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = NULL);
Patrick Georgi0588d192009-08-12 15:00:51 +0000276
277public slots:
278 void saveSettings(void);
279 void search(void);
280
281protected:
282 QLineEdit* editField;
283 QPushButton* searchButton;
284 QSplitter* split;
285 ConfigView* list;
286 ConfigInfoView* info;
287
288 struct symbol **result;
289};
290
zbao11a262c2016-01-22 18:54:22 +0800291class ConfigMainWindow : public QMainWindow {
Patrick Georgi0588d192009-08-12 15:00:51 +0000292 Q_OBJECT
293
zbao11a262c2016-01-22 18:54:22 +0800294 static QAction *saveAction;
Patrick Georgi0588d192009-08-12 15:00:51 +0000295 static void conf_changed(void);
296public:
297 ConfigMainWindow(void);
298public slots:
299 void changeMenu(struct menu *);
300 void setMenuLink(struct menu *);
301 void listFocusChanged(void);
302 void goBack(void);
303 void loadConfig(void);
Patrick Georgid5208402014-04-11 20:24:06 +0200304 bool saveConfig(void);
Patrick Georgi0588d192009-08-12 15:00:51 +0000305 void saveConfigAs(void);
306 void searchConfig(void);
307 void showSingleView(void);
308 void showSplitView(void);
309 void showFullView(void);
310 void showIntro(void);
311 void showAbout(void);
312 void saveSettings(void);
313
314protected:
315 void closeEvent(QCloseEvent *e);
316
317 ConfigSearchWindow *searchWindow;
318 ConfigView *menuView;
319 ConfigList *menuList;
320 ConfigView *configView;
321 ConfigList *configList;
322 ConfigInfoView *helpText;
zbao11a262c2016-01-22 18:54:22 +0800323 QToolBar *toolBar;
324 QAction *backAction;
325 QAction *singleViewAction;
326 QAction *splitViewAction;
327 QAction *fullViewAction;
328 QSplitter *split1;
329 QSplitter *split2;
Patrick Georgi0588d192009-08-12 15:00:51 +0000330};