blob: db4b417300539ad2c56c693c1ff06e83fe542655 [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
Alexander Stein133c5f72010-08-31 17:34:37 +02006#include <q3listview.h>
Boris Barbulovskib1f8a452015-09-22 11:36:02 -07007#include <QMainWindow>
Alexander Stein133c5f72010-08-31 17:34:37 +02008#include <qsettings.h>
9
Roman Zippel7fc925f2006-06-08 22:12:46 -070010class ConfigView;
Linus Torvalds1da177e2005-04-16 15:20:36 -070011class ConfigList;
12class ConfigItem;
13class ConfigLineEdit;
14class ConfigMainWindow;
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016class ConfigSettings : public QSettings {
17public:
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010018 ConfigSettings();
Alexander Stein133c5f72010-08-31 17:34:37 +020019 Q3ValueList<int> readSizes(const QString& key, bool *ok);
20 bool writeSizes(const QString& key, const Q3ValueList<int>& value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021};
22
23enum colIdx {
24 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
25};
26enum listMode {
Roman Zippel43bf6122006-06-08 22:12:45 -070027 singleMode, menuMode, symbolMode, fullMode, listMode
Linus Torvalds1da177e2005-04-16 15:20:36 -070028};
Li Zefan39a48972010-05-10 16:33:41 +080029enum optionMode {
30 normalOpt = 0, allOpt, promptOpt
31};
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Alexander Stein133c5f72010-08-31 17:34:37 +020033class ConfigList : public Q3ListView {
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +020035 typedef class Q3ListView Parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036public:
Roman Zippel7fc925f2006-06-08 22:12:46 -070037 ConfigList(ConfigView* p, const char *name = 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 void reinit(void);
39 ConfigView* parent(void) const
40 {
41 return (ConfigView*)Parent::parent();
42 }
Roman Zippelb65a47e2006-06-08 22:12:47 -070043 ConfigItem* findConfigItem(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45protected:
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 void keyPressEvent(QKeyEvent *e);
47 void contentsMousePressEvent(QMouseEvent *e);
48 void contentsMouseReleaseEvent(QMouseEvent *e);
49 void contentsMouseMoveEvent(QMouseEvent *e);
50 void contentsMouseDoubleClickEvent(QMouseEvent *e);
51 void focusInEvent(QFocusEvent *e);
Roman Zippel7fc925f2006-06-08 22:12:46 -070052 void contextMenuEvent(QContextMenuEvent *e);
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054public slots:
55 void setRootMenu(struct menu *menu);
56
57 void updateList(ConfigItem *item);
58 void setValue(ConfigItem* item, tristate val);
59 void changeValue(ConfigItem* item);
60 void updateSelection(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -070061 void saveSettings(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062signals:
Roman Zippel43bf6122006-06-08 22:12:45 -070063 void menuChanged(struct menu *menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 void menuSelected(struct menu *menu);
65 void parentSelected(void);
Roman Zippelb65a47e2006-06-08 22:12:47 -070066 void gotFocus(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68public:
69 void updateListAll(void)
70 {
71 updateAll = true;
72 updateList(NULL);
73 updateAll = false;
74 }
75 ConfigList* listView()
76 {
77 return this;
78 }
79 ConfigItem* firstChild() const
80 {
81 return (ConfigItem *)Parent::firstChild();
82 }
83 int mapIdx(colIdx idx)
84 {
85 return colMap[idx];
86 }
87 void addColumn(colIdx idx, const QString& label)
88 {
89 colMap[idx] = Parent::addColumn(label);
90 colRevMap[colMap[idx]] = idx;
91 }
92 void removeColumn(colIdx idx)
93 {
94 int col = colMap[idx];
95 if (col >= 0) {
96 Parent::removeColumn(col);
97 colRevMap[col] = colMap[idx] = -1;
98 }
99 }
100 void setAllOpen(bool open);
101 void setParentMenu(void);
102
Li Zefan39a48972010-05-10 16:33:41 +0800103 bool menuSkip(struct menu *);
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 template <class P>
Dave Jones19144d02006-01-08 01:05:02 -0800106 void updateMenuList(P*, struct menu*);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 bool updateAll;
109
110 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
111 QPixmap choiceYesPix, choiceNoPix;
112 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
113
Li Zefan39a48972010-05-10 16:33:41 +0800114 bool showName, showRange, showData;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 enum listMode mode;
Li Zefan39a48972010-05-10 16:33:41 +0800116 enum optionMode optMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 struct menu *rootEntry;
118 QColorGroup disabledColorGroup;
119 QColorGroup inactivedColorGroup;
Alexander Stein133c5f72010-08-31 17:34:37 +0200120 Q3PopupMenu* headerPopup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122private:
123 int colMap[colNr];
124 int colRevMap[colNr];
125};
126
Alexander Stein133c5f72010-08-31 17:34:37 +0200127class ConfigItem : public Q3ListViewItem {
128 typedef class Q3ListViewItem Parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129public:
Alexander Stein133c5f72010-08-31 17:34:37 +0200130 ConfigItem(Q3ListView *parent, ConfigItem *after, struct menu *m, bool v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 : Parent(parent, after), menu(m), visible(v), goParent(false)
132 {
133 init();
134 }
135 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
136 : Parent(parent, after), menu(m), visible(v), goParent(false)
137 {
138 init();
139 }
Alexander Stein133c5f72010-08-31 17:34:37 +0200140 ConfigItem(Q3ListView *parent, ConfigItem *after, bool v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 : Parent(parent, after), menu(0), visible(v), goParent(true)
142 {
143 init();
144 }
145 ~ConfigItem(void);
146 void init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 void okRename(int col);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 void updateMenu(void);
149 void testUpdateMenu(bool v);
150 ConfigList* listView() const
151 {
152 return (ConfigList*)Parent::listView();
153 }
154 ConfigItem* firstChild() const
155 {
156 return (ConfigItem *)Parent::firstChild();
157 }
158 ConfigItem* nextSibling() const
159 {
160 return (ConfigItem *)Parent::nextSibling();
161 }
162 void setText(colIdx idx, const QString& text)
163 {
164 Parent::setText(listView()->mapIdx(idx), text);
165 }
166 QString text(colIdx idx) const
167 {
168 return Parent::text(listView()->mapIdx(idx));
169 }
170 void setPixmap(colIdx idx, const QPixmap& pm)
171 {
172 Parent::setPixmap(listView()->mapIdx(idx), pm);
173 }
174 const QPixmap* pixmap(colIdx idx) const
175 {
176 return Parent::pixmap(listView()->mapIdx(idx));
177 }
178 void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
179
180 ConfigItem* nextItem;
181 struct menu *menu;
182 bool visible;
183 bool goParent;
184};
185
186class ConfigLineEdit : public QLineEdit {
187 Q_OBJECT
188 typedef class QLineEdit Parent;
189public:
Roman Zippel43bf6122006-06-08 22:12:45 -0700190 ConfigLineEdit(ConfigView* parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 ConfigView* parent(void) const
192 {
193 return (ConfigView*)Parent::parent();
194 }
195 void show(ConfigItem *i);
196 void keyPressEvent(QKeyEvent *e);
197
198public:
199 ConfigItem *item;
200};
201
Alexander Stein133c5f72010-08-31 17:34:37 +0200202class ConfigView : public Q3VBox {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700203 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +0200204 typedef class Q3VBox Parent;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700205public:
206 ConfigView(QWidget* parent, const char *name = 0);
207 ~ConfigView(void);
208 static void updateList(ConfigItem* item);
209 static void updateListAll(void);
210
Roman Zippel7fc925f2006-06-08 22:12:46 -0700211 bool showName(void) const { return list->showName; }
212 bool showRange(void) const { return list->showRange; }
213 bool showData(void) const { return list->showData; }
214public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700215 void setShowName(bool);
216 void setShowRange(bool);
217 void setShowData(bool);
Li Zefan39a48972010-05-10 16:33:41 +0800218 void setOptionMode(QAction *);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700219signals:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700220 void showNameChanged(bool);
221 void showRangeChanged(bool);
222 void showDataChanged(bool);
223public:
224 ConfigList* list;
225 ConfigLineEdit* lineEdit;
226
227 static ConfigView* viewList;
228 ConfigView* nextView;
Li Zefan39a48972010-05-10 16:33:41 +0800229
230 static QAction *showNormalAction;
231 static QAction *showAllAction;
232 static QAction *showPromptAction;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700233};
234
Alexander Stein133c5f72010-08-31 17:34:37 +0200235class ConfigInfoView : public Q3TextBrowser {
Roman Zippel43bf6122006-06-08 22:12:45 -0700236 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +0200237 typedef class Q3TextBrowser Parent;
Roman Zippel43bf6122006-06-08 22:12:45 -0700238public:
239 ConfigInfoView(QWidget* parent, const char *name = 0);
240 bool showDebug(void) const { return _showDebug; }
241
242public slots:
243 void setInfo(struct menu *menu);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700244 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700245 void setShowDebug(bool);
246
247signals:
248 void showDebugChanged(bool);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700249 void menuSelected(struct menu *);
Roman Zippel43bf6122006-06-08 22:12:45 -0700250
251protected:
Roman Zippelab45d192006-06-08 22:12:47 -0700252 void symbolInfo(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700253 void menuInfo(void);
254 QString debug_info(struct symbol *sym);
255 static QString print_filter(const QString &str);
Roman Zippelab45d192006-06-08 22:12:47 -0700256 static void expr_print_help(void *data, struct symbol *sym, const char *str);
Alexander Stein133c5f72010-08-31 17:34:37 +0200257 Q3PopupMenu* createPopupMenu(const QPoint& pos);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700258 void contentsContextMenuEvent(QContextMenuEvent *e);
Roman Zippel43bf6122006-06-08 22:12:45 -0700259
Roman Zippelab45d192006-06-08 22:12:47 -0700260 struct symbol *sym;
Alexander Stein133c5f72010-08-31 17:34:37 +0200261 struct menu *_menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700262 bool _showDebug;
263};
264
265class ConfigSearchWindow : public QDialog {
266 Q_OBJECT
267 typedef class QDialog Parent;
268public:
Marco Costalba63431e72006-10-05 19:12:59 +0200269 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700270
Roman Zippel43bf6122006-06-08 22:12:45 -0700271public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700272 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700273 void search(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700274
Roman Zippel43bf6122006-06-08 22:12:45 -0700275protected:
276 QLineEdit* editField;
277 QPushButton* searchButton;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700278 QSplitter* split;
Roman Zippel43bf6122006-06-08 22:12:45 -0700279 ConfigView* list;
280 ConfigInfoView* info;
281
282 struct symbol **result;
283};
284
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700285class ConfigMainWindow : public QMainWindow {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 Q_OBJECT
Karsten Wiese3b354c52006-12-13 00:34:08 -0800287
Alexander Stein133c5f72010-08-31 17:34:37 +0200288 static Q3Action *saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -0800289 static void conf_changed(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290public:
291 ConfigMainWindow(void);
292public slots:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 void changeMenu(struct menu *);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700294 void setMenuLink(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 void listFocusChanged(void);
296 void goBack(void);
297 void loadConfig(void);
Michal Marekbac6aa82011-05-25 15:10:25 +0200298 bool saveConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 void saveConfigAs(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700300 void searchConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 void showSingleView(void);
302 void showSplitView(void);
303 void showFullView(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 void showIntro(void);
305 void showAbout(void);
306 void saveSettings(void);
307
308protected:
309 void closeEvent(QCloseEvent *e);
310
Roman Zippel43bf6122006-06-08 22:12:45 -0700311 ConfigSearchWindow *searchWindow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 ConfigView *menuView;
313 ConfigList *menuList;
314 ConfigView *configView;
315 ConfigList *configList;
Roman Zippel43bf6122006-06-08 22:12:45 -0700316 ConfigInfoView *helpText;
Boris Barbulovskib1f8a452015-09-22 11:36:02 -0700317 QToolBar *toolBar;
Alexander Stein133c5f72010-08-31 17:34:37 +0200318 Q3Action *backAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 QSplitter* split1;
320 QSplitter* split2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321};