blob: bde0c6b6f9e87dbeff3004413123f6d2cef0d42f [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#if QT_VERSION < 0x040000
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <qlistview.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#else
Alexander Stein133c5f72010-08-31 17:34:37 +02009#include <q3listview.h>
10#endif
11#include <qsettings.h>
12
13#if QT_VERSION < 0x040000
14#define Q3ValueList QValueList
15#define Q3PopupMenu QPopupMenu
16#define Q3ListView QListView
17#define Q3ListViewItem QListViewItem
18#define Q3VBox QVBox
19#define Q3TextBrowser QTextBrowser
20#define Q3MainWindow QMainWindow
21#define Q3Action QAction
22#define Q3ToolBar QToolBar
23#define Q3ListViewItemIterator QListViewItemIterator
24#define Q3FileDialog QFileDialog
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#endif
26
Roman Zippel7fc925f2006-06-08 22:12:46 -070027class ConfigView;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028class ConfigList;
29class ConfigItem;
30class ConfigLineEdit;
31class ConfigMainWindow;
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033class ConfigSettings : public QSettings {
34public:
Ben Hutchings00d4f8f2013-10-06 19:21:31 +010035 ConfigSettings();
Alexander Stein133c5f72010-08-31 17:34:37 +020036 Q3ValueList<int> readSizes(const QString& key, bool *ok);
37 bool writeSizes(const QString& key, const Q3ValueList<int>& value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038};
39
40enum colIdx {
41 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
42};
43enum listMode {
Roman Zippel43bf6122006-06-08 22:12:45 -070044 singleMode, menuMode, symbolMode, fullMode, listMode
Linus Torvalds1da177e2005-04-16 15:20:36 -070045};
Li Zefan39a48972010-05-10 16:33:41 +080046enum optionMode {
47 normalOpt = 0, allOpt, promptOpt
48};
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Alexander Stein133c5f72010-08-31 17:34:37 +020050class ConfigList : public Q3ListView {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +020052 typedef class Q3ListView Parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053public:
Roman Zippel7fc925f2006-06-08 22:12:46 -070054 ConfigList(ConfigView* p, const char *name = 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 void reinit(void);
56 ConfigView* parent(void) const
57 {
58 return (ConfigView*)Parent::parent();
59 }
Roman Zippelb65a47e2006-06-08 22:12:47 -070060 ConfigItem* findConfigItem(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62protected:
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 void keyPressEvent(QKeyEvent *e);
64 void contentsMousePressEvent(QMouseEvent *e);
65 void contentsMouseReleaseEvent(QMouseEvent *e);
66 void contentsMouseMoveEvent(QMouseEvent *e);
67 void contentsMouseDoubleClickEvent(QMouseEvent *e);
68 void focusInEvent(QFocusEvent *e);
Roman Zippel7fc925f2006-06-08 22:12:46 -070069 void contextMenuEvent(QContextMenuEvent *e);
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071public slots:
72 void setRootMenu(struct menu *menu);
73
74 void updateList(ConfigItem *item);
75 void setValue(ConfigItem* item, tristate val);
76 void changeValue(ConfigItem* item);
77 void updateSelection(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -070078 void saveSettings(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079signals:
Roman Zippel43bf6122006-06-08 22:12:45 -070080 void menuChanged(struct menu *menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 void menuSelected(struct menu *menu);
82 void parentSelected(void);
Roman Zippelb65a47e2006-06-08 22:12:47 -070083 void gotFocus(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85public:
86 void updateListAll(void)
87 {
88 updateAll = true;
89 updateList(NULL);
90 updateAll = false;
91 }
92 ConfigList* listView()
93 {
94 return this;
95 }
96 ConfigItem* firstChild() const
97 {
98 return (ConfigItem *)Parent::firstChild();
99 }
100 int mapIdx(colIdx idx)
101 {
102 return colMap[idx];
103 }
104 void addColumn(colIdx idx, const QString& label)
105 {
106 colMap[idx] = Parent::addColumn(label);
107 colRevMap[colMap[idx]] = idx;
108 }
109 void removeColumn(colIdx idx)
110 {
111 int col = colMap[idx];
112 if (col >= 0) {
113 Parent::removeColumn(col);
114 colRevMap[col] = colMap[idx] = -1;
115 }
116 }
117 void setAllOpen(bool open);
118 void setParentMenu(void);
119
Li Zefan39a48972010-05-10 16:33:41 +0800120 bool menuSkip(struct menu *);
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 template <class P>
Dave Jones19144d02006-01-08 01:05:02 -0800123 void updateMenuList(P*, struct menu*);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 bool updateAll;
126
127 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
128 QPixmap choiceYesPix, choiceNoPix;
129 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
130
Li Zefan39a48972010-05-10 16:33:41 +0800131 bool showName, showRange, showData;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 enum listMode mode;
Li Zefan39a48972010-05-10 16:33:41 +0800133 enum optionMode optMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 struct menu *rootEntry;
135 QColorGroup disabledColorGroup;
136 QColorGroup inactivedColorGroup;
Alexander Stein133c5f72010-08-31 17:34:37 +0200137 Q3PopupMenu* headerPopup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139private:
140 int colMap[colNr];
141 int colRevMap[colNr];
142};
143
Alexander Stein133c5f72010-08-31 17:34:37 +0200144class ConfigItem : public Q3ListViewItem {
145 typedef class Q3ListViewItem Parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146public:
Alexander Stein133c5f72010-08-31 17:34:37 +0200147 ConfigItem(Q3ListView *parent, ConfigItem *after, struct menu *m, bool v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 : Parent(parent, after), menu(m), visible(v), goParent(false)
149 {
150 init();
151 }
152 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
153 : Parent(parent, after), menu(m), visible(v), goParent(false)
154 {
155 init();
156 }
Alexander Stein133c5f72010-08-31 17:34:37 +0200157 ConfigItem(Q3ListView *parent, ConfigItem *after, bool v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 : Parent(parent, after), menu(0), visible(v), goParent(true)
159 {
160 init();
161 }
162 ~ConfigItem(void);
163 void init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 void okRename(int col);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 void updateMenu(void);
166 void testUpdateMenu(bool v);
167 ConfigList* listView() const
168 {
169 return (ConfigList*)Parent::listView();
170 }
171 ConfigItem* firstChild() const
172 {
173 return (ConfigItem *)Parent::firstChild();
174 }
175 ConfigItem* nextSibling() const
176 {
177 return (ConfigItem *)Parent::nextSibling();
178 }
179 void setText(colIdx idx, const QString& text)
180 {
181 Parent::setText(listView()->mapIdx(idx), text);
182 }
183 QString text(colIdx idx) const
184 {
185 return Parent::text(listView()->mapIdx(idx));
186 }
187 void setPixmap(colIdx idx, const QPixmap& pm)
188 {
189 Parent::setPixmap(listView()->mapIdx(idx), pm);
190 }
191 const QPixmap* pixmap(colIdx idx) const
192 {
193 return Parent::pixmap(listView()->mapIdx(idx));
194 }
195 void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
196
197 ConfigItem* nextItem;
198 struct menu *menu;
199 bool visible;
200 bool goParent;
201};
202
203class ConfigLineEdit : public QLineEdit {
204 Q_OBJECT
205 typedef class QLineEdit Parent;
206public:
Roman Zippel43bf6122006-06-08 22:12:45 -0700207 ConfigLineEdit(ConfigView* parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 ConfigView* parent(void) const
209 {
210 return (ConfigView*)Parent::parent();
211 }
212 void show(ConfigItem *i);
213 void keyPressEvent(QKeyEvent *e);
214
215public:
216 ConfigItem *item;
217};
218
Alexander Stein133c5f72010-08-31 17:34:37 +0200219class ConfigView : public Q3VBox {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700220 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +0200221 typedef class Q3VBox Parent;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700222public:
223 ConfigView(QWidget* parent, const char *name = 0);
224 ~ConfigView(void);
225 static void updateList(ConfigItem* item);
226 static void updateListAll(void);
227
Roman Zippel7fc925f2006-06-08 22:12:46 -0700228 bool showName(void) const { return list->showName; }
229 bool showRange(void) const { return list->showRange; }
230 bool showData(void) const { return list->showData; }
231public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700232 void setShowName(bool);
233 void setShowRange(bool);
234 void setShowData(bool);
Li Zefan39a48972010-05-10 16:33:41 +0800235 void setOptionMode(QAction *);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700236signals:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700237 void showNameChanged(bool);
238 void showRangeChanged(bool);
239 void showDataChanged(bool);
240public:
241 ConfigList* list;
242 ConfigLineEdit* lineEdit;
243
244 static ConfigView* viewList;
245 ConfigView* nextView;
Li Zefan39a48972010-05-10 16:33:41 +0800246
247 static QAction *showNormalAction;
248 static QAction *showAllAction;
249 static QAction *showPromptAction;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700250};
251
Alexander Stein133c5f72010-08-31 17:34:37 +0200252class ConfigInfoView : public Q3TextBrowser {
Roman Zippel43bf6122006-06-08 22:12:45 -0700253 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +0200254 typedef class Q3TextBrowser Parent;
Roman Zippel43bf6122006-06-08 22:12:45 -0700255public:
256 ConfigInfoView(QWidget* parent, const char *name = 0);
257 bool showDebug(void) const { return _showDebug; }
258
259public slots:
260 void setInfo(struct menu *menu);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700261 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700262 void setShowDebug(bool);
263
264signals:
265 void showDebugChanged(bool);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700266 void menuSelected(struct menu *);
Roman Zippel43bf6122006-06-08 22:12:45 -0700267
268protected:
Roman Zippelab45d192006-06-08 22:12:47 -0700269 void symbolInfo(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700270 void menuInfo(void);
271 QString debug_info(struct symbol *sym);
272 static QString print_filter(const QString &str);
Roman Zippelab45d192006-06-08 22:12:47 -0700273 static void expr_print_help(void *data, struct symbol *sym, const char *str);
Alexander Stein133c5f72010-08-31 17:34:37 +0200274 Q3PopupMenu* createPopupMenu(const QPoint& pos);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700275 void contentsContextMenuEvent(QContextMenuEvent *e);
Roman Zippel43bf6122006-06-08 22:12:45 -0700276
Roman Zippelab45d192006-06-08 22:12:47 -0700277 struct symbol *sym;
Alexander Stein133c5f72010-08-31 17:34:37 +0200278 struct menu *_menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700279 bool _showDebug;
280};
281
282class ConfigSearchWindow : public QDialog {
283 Q_OBJECT
284 typedef class QDialog Parent;
285public:
Marco Costalba63431e72006-10-05 19:12:59 +0200286 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700287
Roman Zippel43bf6122006-06-08 22:12:45 -0700288public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700289 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700290 void search(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700291
Roman Zippel43bf6122006-06-08 22:12:45 -0700292protected:
293 QLineEdit* editField;
294 QPushButton* searchButton;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700295 QSplitter* split;
Roman Zippel43bf6122006-06-08 22:12:45 -0700296 ConfigView* list;
297 ConfigInfoView* info;
298
299 struct symbol **result;
300};
301
Alexander Stein133c5f72010-08-31 17:34:37 +0200302class ConfigMainWindow : public Q3MainWindow {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 Q_OBJECT
Karsten Wiese3b354c52006-12-13 00:34:08 -0800304
Alexander Stein133c5f72010-08-31 17:34:37 +0200305 static Q3Action *saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -0800306 static void conf_changed(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307public:
308 ConfigMainWindow(void);
309public slots:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 void changeMenu(struct menu *);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700311 void setMenuLink(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 void listFocusChanged(void);
313 void goBack(void);
314 void loadConfig(void);
Michal Marekbac6aa82011-05-25 15:10:25 +0200315 bool saveConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 void saveConfigAs(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700317 void searchConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 void showSingleView(void);
319 void showSplitView(void);
320 void showFullView(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 void showIntro(void);
322 void showAbout(void);
323 void saveSettings(void);
324
325protected:
326 void closeEvent(QCloseEvent *e);
327
Roman Zippel43bf6122006-06-08 22:12:45 -0700328 ConfigSearchWindow *searchWindow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 ConfigView *menuView;
330 ConfigList *menuList;
331 ConfigView *configView;
332 ConfigList *configList;
Roman Zippel43bf6122006-06-08 22:12:45 -0700333 ConfigInfoView *helpText;
Alexander Stein133c5f72010-08-31 17:34:37 +0200334 Q3ToolBar *toolBar;
335 Q3Action *backAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 QSplitter* split1;
337 QSplitter* split2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338};