blob: 703285d0faf67006d5e80d3ea15dac8a2646f7fd [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>
Alexander Stein133c5f72010-08-31 17:34:37 +02007#include <qsettings.h>
8
Roman Zippel7fc925f2006-06-08 22:12:46 -07009class ConfigView;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010class ConfigList;
11class ConfigItem;
12class ConfigLineEdit;
13class ConfigMainWindow;
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015class ConfigSettings : public QSettings {
16public:
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010017 ConfigSettings();
Alexander Stein133c5f72010-08-31 17:34:37 +020018 Q3ValueList<int> readSizes(const QString& key, bool *ok);
19 bool writeSizes(const QString& key, const Q3ValueList<int>& value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020};
21
22enum colIdx {
23 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
24};
25enum listMode {
Roman Zippel43bf6122006-06-08 22:12:45 -070026 singleMode, menuMode, symbolMode, fullMode, listMode
Linus Torvalds1da177e2005-04-16 15:20:36 -070027};
Li Zefan39a48972010-05-10 16:33:41 +080028enum optionMode {
29 normalOpt = 0, allOpt, promptOpt
30};
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Alexander Stein133c5f72010-08-31 17:34:37 +020032class ConfigList : public Q3ListView {
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +020034 typedef class Q3ListView Parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035public:
Roman Zippel7fc925f2006-06-08 22:12:46 -070036 ConfigList(ConfigView* p, const char *name = 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 void reinit(void);
38 ConfigView* parent(void) const
39 {
40 return (ConfigView*)Parent::parent();
41 }
Roman Zippelb65a47e2006-06-08 22:12:47 -070042 ConfigItem* findConfigItem(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44protected:
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 void keyPressEvent(QKeyEvent *e);
46 void contentsMousePressEvent(QMouseEvent *e);
47 void contentsMouseReleaseEvent(QMouseEvent *e);
48 void contentsMouseMoveEvent(QMouseEvent *e);
49 void contentsMouseDoubleClickEvent(QMouseEvent *e);
50 void focusInEvent(QFocusEvent *e);
Roman Zippel7fc925f2006-06-08 22:12:46 -070051 void contextMenuEvent(QContextMenuEvent *e);
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053public slots:
54 void setRootMenu(struct menu *menu);
55
56 void updateList(ConfigItem *item);
57 void setValue(ConfigItem* item, tristate val);
58 void changeValue(ConfigItem* item);
59 void updateSelection(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -070060 void saveSettings(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061signals:
Roman Zippel43bf6122006-06-08 22:12:45 -070062 void menuChanged(struct menu *menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 void menuSelected(struct menu *menu);
64 void parentSelected(void);
Roman Zippelb65a47e2006-06-08 22:12:47 -070065 void gotFocus(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67public:
68 void updateListAll(void)
69 {
70 updateAll = true;
71 updateList(NULL);
72 updateAll = false;
73 }
74 ConfigList* listView()
75 {
76 return this;
77 }
78 ConfigItem* firstChild() const
79 {
80 return (ConfigItem *)Parent::firstChild();
81 }
82 int mapIdx(colIdx idx)
83 {
84 return colMap[idx];
85 }
86 void addColumn(colIdx idx, const QString& label)
87 {
88 colMap[idx] = Parent::addColumn(label);
89 colRevMap[colMap[idx]] = idx;
90 }
91 void removeColumn(colIdx idx)
92 {
93 int col = colMap[idx];
94 if (col >= 0) {
95 Parent::removeColumn(col);
96 colRevMap[col] = colMap[idx] = -1;
97 }
98 }
99 void setAllOpen(bool open);
100 void setParentMenu(void);
101
Li Zefan39a48972010-05-10 16:33:41 +0800102 bool menuSkip(struct menu *);
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 template <class P>
Dave Jones19144d02006-01-08 01:05:02 -0800105 void updateMenuList(P*, struct menu*);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 bool updateAll;
108
109 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
110 QPixmap choiceYesPix, choiceNoPix;
111 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
112
Li Zefan39a48972010-05-10 16:33:41 +0800113 bool showName, showRange, showData;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 enum listMode mode;
Li Zefan39a48972010-05-10 16:33:41 +0800115 enum optionMode optMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 struct menu *rootEntry;
117 QColorGroup disabledColorGroup;
118 QColorGroup inactivedColorGroup;
Alexander Stein133c5f72010-08-31 17:34:37 +0200119 Q3PopupMenu* headerPopup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121private:
122 int colMap[colNr];
123 int colRevMap[colNr];
124};
125
Alexander Stein133c5f72010-08-31 17:34:37 +0200126class ConfigItem : public Q3ListViewItem {
127 typedef class Q3ListViewItem Parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128public:
Alexander Stein133c5f72010-08-31 17:34:37 +0200129 ConfigItem(Q3ListView *parent, ConfigItem *after, struct menu *m, bool v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 : Parent(parent, after), menu(m), visible(v), goParent(false)
131 {
132 init();
133 }
134 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
135 : Parent(parent, after), menu(m), visible(v), goParent(false)
136 {
137 init();
138 }
Alexander Stein133c5f72010-08-31 17:34:37 +0200139 ConfigItem(Q3ListView *parent, ConfigItem *after, bool v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 : Parent(parent, after), menu(0), visible(v), goParent(true)
141 {
142 init();
143 }
144 ~ConfigItem(void);
145 void init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 void okRename(int col);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 void updateMenu(void);
148 void testUpdateMenu(bool v);
149 ConfigList* listView() const
150 {
151 return (ConfigList*)Parent::listView();
152 }
153 ConfigItem* firstChild() const
154 {
155 return (ConfigItem *)Parent::firstChild();
156 }
157 ConfigItem* nextSibling() const
158 {
159 return (ConfigItem *)Parent::nextSibling();
160 }
161 void setText(colIdx idx, const QString& text)
162 {
163 Parent::setText(listView()->mapIdx(idx), text);
164 }
165 QString text(colIdx idx) const
166 {
167 return Parent::text(listView()->mapIdx(idx));
168 }
169 void setPixmap(colIdx idx, const QPixmap& pm)
170 {
171 Parent::setPixmap(listView()->mapIdx(idx), pm);
172 }
173 const QPixmap* pixmap(colIdx idx) const
174 {
175 return Parent::pixmap(listView()->mapIdx(idx));
176 }
177 void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
178
179 ConfigItem* nextItem;
180 struct menu *menu;
181 bool visible;
182 bool goParent;
183};
184
185class ConfigLineEdit : public QLineEdit {
186 Q_OBJECT
187 typedef class QLineEdit Parent;
188public:
Roman Zippel43bf6122006-06-08 22:12:45 -0700189 ConfigLineEdit(ConfigView* parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 ConfigView* parent(void) const
191 {
192 return (ConfigView*)Parent::parent();
193 }
194 void show(ConfigItem *i);
195 void keyPressEvent(QKeyEvent *e);
196
197public:
198 ConfigItem *item;
199};
200
Alexander Stein133c5f72010-08-31 17:34:37 +0200201class ConfigView : public Q3VBox {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700202 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +0200203 typedef class Q3VBox Parent;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700204public:
205 ConfigView(QWidget* parent, const char *name = 0);
206 ~ConfigView(void);
207 static void updateList(ConfigItem* item);
208 static void updateListAll(void);
209
Roman Zippel7fc925f2006-06-08 22:12:46 -0700210 bool showName(void) const { return list->showName; }
211 bool showRange(void) const { return list->showRange; }
212 bool showData(void) const { return list->showData; }
213public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700214 void setShowName(bool);
215 void setShowRange(bool);
216 void setShowData(bool);
Li Zefan39a48972010-05-10 16:33:41 +0800217 void setOptionMode(QAction *);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700218signals:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700219 void showNameChanged(bool);
220 void showRangeChanged(bool);
221 void showDataChanged(bool);
222public:
223 ConfigList* list;
224 ConfigLineEdit* lineEdit;
225
226 static ConfigView* viewList;
227 ConfigView* nextView;
Li Zefan39a48972010-05-10 16:33:41 +0800228
229 static QAction *showNormalAction;
230 static QAction *showAllAction;
231 static QAction *showPromptAction;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700232};
233
Alexander Stein133c5f72010-08-31 17:34:37 +0200234class ConfigInfoView : public Q3TextBrowser {
Roman Zippel43bf6122006-06-08 22:12:45 -0700235 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +0200236 typedef class Q3TextBrowser Parent;
Roman Zippel43bf6122006-06-08 22:12:45 -0700237public:
238 ConfigInfoView(QWidget* parent, const char *name = 0);
239 bool showDebug(void) const { return _showDebug; }
240
241public slots:
242 void setInfo(struct menu *menu);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700243 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700244 void setShowDebug(bool);
245
246signals:
247 void showDebugChanged(bool);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700248 void menuSelected(struct menu *);
Roman Zippel43bf6122006-06-08 22:12:45 -0700249
250protected:
Roman Zippelab45d192006-06-08 22:12:47 -0700251 void symbolInfo(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700252 void menuInfo(void);
253 QString debug_info(struct symbol *sym);
254 static QString print_filter(const QString &str);
Roman Zippelab45d192006-06-08 22:12:47 -0700255 static void expr_print_help(void *data, struct symbol *sym, const char *str);
Alexander Stein133c5f72010-08-31 17:34:37 +0200256 Q3PopupMenu* createPopupMenu(const QPoint& pos);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700257 void contentsContextMenuEvent(QContextMenuEvent *e);
Roman Zippel43bf6122006-06-08 22:12:45 -0700258
Roman Zippelab45d192006-06-08 22:12:47 -0700259 struct symbol *sym;
Alexander Stein133c5f72010-08-31 17:34:37 +0200260 struct menu *_menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700261 bool _showDebug;
262};
263
264class ConfigSearchWindow : public QDialog {
265 Q_OBJECT
266 typedef class QDialog Parent;
267public:
Marco Costalba63431e72006-10-05 19:12:59 +0200268 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700269
Roman Zippel43bf6122006-06-08 22:12:45 -0700270public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700271 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700272 void search(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700273
Roman Zippel43bf6122006-06-08 22:12:45 -0700274protected:
275 QLineEdit* editField;
276 QPushButton* searchButton;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700277 QSplitter* split;
Roman Zippel43bf6122006-06-08 22:12:45 -0700278 ConfigView* list;
279 ConfigInfoView* info;
280
281 struct symbol **result;
282};
283
Alexander Stein133c5f72010-08-31 17:34:37 +0200284class ConfigMainWindow : public Q3MainWindow {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 Q_OBJECT
Karsten Wiese3b354c52006-12-13 00:34:08 -0800286
Alexander Stein133c5f72010-08-31 17:34:37 +0200287 static Q3Action *saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -0800288 static void conf_changed(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289public:
290 ConfigMainWindow(void);
291public slots:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 void changeMenu(struct menu *);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700293 void setMenuLink(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 void listFocusChanged(void);
295 void goBack(void);
296 void loadConfig(void);
Michal Marekbac6aa82011-05-25 15:10:25 +0200297 bool saveConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 void saveConfigAs(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700299 void searchConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 void showSingleView(void);
301 void showSplitView(void);
302 void showFullView(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 void showIntro(void);
304 void showAbout(void);
305 void saveSettings(void);
306
307protected:
308 void closeEvent(QCloseEvent *e);
309
Roman Zippel43bf6122006-06-08 22:12:45 -0700310 ConfigSearchWindow *searchWindow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 ConfigView *menuView;
312 ConfigList *menuList;
313 ConfigView *configView;
314 ConfigList *configList;
Roman Zippel43bf6122006-06-08 22:12:45 -0700315 ConfigInfoView *helpText;
Alexander Stein133c5f72010-08-31 17:34:37 +0200316 Q3ToolBar *toolBar;
317 Q3Action *backAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 QSplitter* split1;
319 QSplitter* split2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320};