blob: d86ae3c2697909ca733f42dfa16f6567b0111140 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07006#include <QTextBrowser>
7#include <QTreeWidget>
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07008#include <QMainWindow>
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -07009#include <QHeaderView>
Alexander Stein133c5f72010-08-31 17:34:37 +020010#include <qsettings.h>
Boris Barbulovski68ccb7e2015-09-22 11:36:15 -070011#include <QPushButton>
12#include <QSettings>
13#include <QLineEdit>
14#include <QSplitter>
15#include <QCheckBox>
16#include <QDialog>
17#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);
48 ConfigView* parent(void) const
49 {
50 return (ConfigView*)Parent::parent();
51 }
52 ConfigItem* findConfigItem(struct menu *);
53
54protected:
55 void keyPressEvent(QKeyEvent *e);
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070056 void mousePressEvent(QMouseEvent *e);
57 void mouseReleaseEvent(QMouseEvent *e);
58 void mouseMoveEvent(QMouseEvent *e);
59 void mouseDoubleClickEvent(QMouseEvent *e);
Boris Barbulovski59e56442015-09-22 11:36:18 -070060 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 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070090 return (ConfigItem *)children().first();
Boris Barbulovski59e56442015-09-22 11:36:18 -070091 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070092 void addColumn(colIdx idx)
Boris Barbulovski59e56442015-09-22 11:36:18 -070093 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070094 showColumn(idx);
Boris Barbulovski59e56442015-09-22 11:36:18 -070095 }
96 void removeColumn(colIdx idx)
97 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -070098 hideColumn(idx);
Boris Barbulovski59e56442015-09-22 11:36:18 -070099 }
100 void setAllOpen(bool open);
101 void setParentMenu(void);
102
103 bool menuSkip(struct menu *);
104
Boris Barbulovski5c6f1552015-09-22 11:36:27 -0700105 void updateMenuList(ConfigItem *parent, struct menu*);
106 void updateMenuList(ConfigList *parent, struct menu*);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700107
108 bool updateAll;
109
110 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
111 QPixmap choiceYesPix, choiceNoPix;
112 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
113
114 bool showName, showRange, showData;
115 enum listMode mode;
116 enum optionMode optMode;
117 struct menu *rootEntry;
118 QPalette disabledColorGroup;
119 QPalette inactivedColorGroup;
120 QMenu* headerPopup;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700121};
122
123class ConfigItem : public QTreeWidgetItem {
124 typedef class QTreeWidgetItem Parent;
125public:
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700126 ConfigItem(QTreeWidget *parent, ConfigItem *after, struct menu *m, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700127 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700128 {
129 init();
130 }
131 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700132 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700133 {
134 init();
135 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700136 ConfigItem(QTreeWidget *parent, ConfigItem *after, bool v)
Boris Barbulovski86c05282015-09-22 11:36:25 -0700137 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700138 {
139 init();
140 }
141 ~ConfigItem(void);
142 void init(void);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700143 void okRename(int col);
144 void updateMenu(void);
145 void testUpdateMenu(bool v);
146 ConfigList* listView() const
147 {
148 return (ConfigList*)Parent::treeWidget();
149 }
150 ConfigItem* firstChild() const
151 {
152 return (ConfigItem *)Parent::child(0);
153 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700154 ConfigItem* nextSibling()
Boris Barbulovski59e56442015-09-22 11:36:18 -0700155 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700156 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;
Boris Barbulovski59e56442015-09-22 11:36:18 -0700167 }
168 void setText(colIdx idx, const QString& text)
169 {
170 Parent::setText(idx, text);
171 }
172 QString text(colIdx idx) const
173 {
174 return Parent::text(idx);
175 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700176 void setPixmap(colIdx idx, const QIcon &icon)
Boris Barbulovski59e56442015-09-22 11:36:18 -0700177 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700178 Parent::setIcon(idx, icon);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700179 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700180 const QIcon pixmap(colIdx idx) const
Boris Barbulovski59e56442015-09-22 11:36:18 -0700181 {
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700182 return icon(idx);
Boris Barbulovski59e56442015-09-22 11:36:18 -0700183 }
Boris Barbulovskid5d973c2015-09-22 11:36:19 -0700184 // TODO: Implement paintCell
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700185
186 ConfigItem* nextItem;
187 struct menu *menu;
188 bool visible;
189 bool goParent;
190};
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192class ConfigLineEdit : public QLineEdit {
193 Q_OBJECT
194 typedef class QLineEdit Parent;
195public:
Roman Zippel43bf6122006-06-08 22:12:45 -0700196 ConfigLineEdit(ConfigView* parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 ConfigView* parent(void) const
198 {
199 return (ConfigView*)Parent::parent();
200 }
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700201 void show(ConfigItem *i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 void keyPressEvent(QKeyEvent *e);
203
204public:
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700205 ConfigItem *item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206};
207
Boris Barbulovski34d63202015-09-22 11:36:09 -0700208class ConfigView : public QWidget {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700209 Q_OBJECT
Boris Barbulovski34d63202015-09-22 11:36:09 -0700210 typedef class QWidget Parent;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700211public:
212 ConfigView(QWidget* parent, const char *name = 0);
213 ~ConfigView(void);
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700214 static void updateList(ConfigItem* item);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700215 static void updateListAll(void);
216
Boris Barbulovski59e56442015-09-22 11:36:18 -0700217 bool showName(void) const { return list->showName; }
218 bool showRange(void) const { return list->showRange; }
219 bool showData(void) const { return list->showData; }
Roman Zippel7fc925f2006-06-08 22:12:46 -0700220public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700221 void setShowName(bool);
222 void setShowRange(bool);
223 void setShowData(bool);
Li Zefan39a48972010-05-10 16:33:41 +0800224 void setOptionMode(QAction *);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700225signals:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700226 void showNameChanged(bool);
227 void showRangeChanged(bool);
228 void showDataChanged(bool);
229public:
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700230 ConfigList* list;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700231 ConfigLineEdit* lineEdit;
232
233 static ConfigView* viewList;
234 ConfigView* nextView;
Li Zefan39a48972010-05-10 16:33:41 +0800235
236 static QAction *showNormalAction;
237 static QAction *showAllAction;
238 static QAction *showPromptAction;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700239};
240
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700241class ConfigInfoView : public QTextBrowser {
Roman Zippel43bf6122006-06-08 22:12:45 -0700242 Q_OBJECT
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700243 typedef class QTextBrowser Parent;
Roman Zippel43bf6122006-06-08 22:12:45 -0700244public:
245 ConfigInfoView(QWidget* parent, const char *name = 0);
246 bool showDebug(void) const { return _showDebug; }
247
248public slots:
249 void setInfo(struct menu *menu);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700250 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700251 void setShowDebug(bool);
252
253signals:
254 void showDebugChanged(bool);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700255 void menuSelected(struct menu *);
Roman Zippel43bf6122006-06-08 22:12:45 -0700256
257protected:
Roman Zippelab45d192006-06-08 22:12:47 -0700258 void symbolInfo(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700259 void menuInfo(void);
260 QString debug_info(struct symbol *sym);
261 static QString print_filter(const QString &str);
Roman Zippelab45d192006-06-08 22:12:47 -0700262 static void expr_print_help(void *data, struct symbol *sym, const char *str);
Boris Barbulovski924bbb52015-09-22 11:36:06 -0700263 QMenu *createStandardContextMenu(const QPoint & pos);
264 void contextMenuEvent(QContextMenuEvent *e);
Roman Zippel43bf6122006-06-08 22:12:45 -0700265
Roman Zippelab45d192006-06-08 22:12:47 -0700266 struct symbol *sym;
Alexander Stein133c5f72010-08-31 17:34:37 +0200267 struct menu *_menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700268 bool _showDebug;
269};
270
271class ConfigSearchWindow : public QDialog {
272 Q_OBJECT
273 typedef class QDialog Parent;
274public:
Marco Costalba63431e72006-10-05 19:12:59 +0200275 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700276
Roman Zippel43bf6122006-06-08 22:12:45 -0700277public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700278 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700279 void search(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700280
Roman Zippel43bf6122006-06-08 22:12:45 -0700281protected:
282 QLineEdit* editField;
283 QPushButton* searchButton;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700284 QSplitter* split;
Roman Zippel43bf6122006-06-08 22:12:45 -0700285 ConfigView* list;
286 ConfigInfoView* info;
287
288 struct symbol **result;
289};
290
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700291class ConfigMainWindow : public QMainWindow {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 Q_OBJECT
Karsten Wiese3b354c52006-12-13 00:34:08 -0800293
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700294 static QAction *saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -0800295 static void conf_changed(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296public:
297 ConfigMainWindow(void);
298public slots:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 void changeMenu(struct menu *);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700300 void setMenuLink(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 void listFocusChanged(void);
302 void goBack(void);
303 void loadConfig(void);
Michal Marekbac6aa82011-05-25 15:10:25 +0200304 bool saveConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 void saveConfigAs(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700306 void searchConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 void showSingleView(void);
308 void showSplitView(void);
309 void showFullView(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 void showIntro(void);
311 void showAbout(void);
312 void saveSettings(void);
313
314protected:
315 void closeEvent(QCloseEvent *e);
316
Roman Zippel43bf6122006-06-08 22:12:45 -0700317 ConfigSearchWindow *searchWindow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 ConfigView *menuView;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700319 ConfigList *menuList;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 ConfigView *configView;
Boris Barbulovski1019f1a2015-09-22 11:36:17 -0700321 ConfigList *configList;
Roman Zippel43bf6122006-06-08 22:12:45 -0700322 ConfigInfoView *helpText;
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700323 QToolBar *toolBar;
Boris Barbulovski85eaf282015-09-22 11:36:03 -0700324 QAction *backAction;
Boris Barbulovski780505e2015-09-22 11:36:13 -0700325 QAction *singleViewAction;
326 QAction *splitViewAction;
327 QAction *fullViewAction;
Boris Barbulovski76538662015-09-22 11:36:14 -0700328 QSplitter *split1;
329 QSplitter *split2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330};