blob: 91677d900dbd0aa68e07ca74a90709d5182edcf5 [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:
Alexander Stein133c5f72010-08-31 17:34:37 +020035 Q3ValueList<int> readSizes(const QString& key, bool *ok);
36 bool writeSizes(const QString& key, const Q3ValueList<int>& value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037};
38
39enum colIdx {
40 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
41};
42enum listMode {
Roman Zippel43bf6122006-06-08 22:12:45 -070043 singleMode, menuMode, symbolMode, fullMode, listMode
Linus Torvalds1da177e2005-04-16 15:20:36 -070044};
Li Zefan39a48972010-05-10 16:33:41 +080045enum optionMode {
46 normalOpt = 0, allOpt, promptOpt
47};
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Alexander Stein133c5f72010-08-31 17:34:37 +020049class ConfigList : public Q3ListView {
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +020051 typedef class Q3ListView Parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052public:
Roman Zippel7fc925f2006-06-08 22:12:46 -070053 ConfigList(ConfigView* p, const char *name = 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 void reinit(void);
55 ConfigView* parent(void) const
56 {
57 return (ConfigView*)Parent::parent();
58 }
Roman Zippelb65a47e2006-06-08 22:12:47 -070059 ConfigItem* findConfigItem(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61protected:
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 void keyPressEvent(QKeyEvent *e);
63 void contentsMousePressEvent(QMouseEvent *e);
64 void contentsMouseReleaseEvent(QMouseEvent *e);
65 void contentsMouseMoveEvent(QMouseEvent *e);
66 void contentsMouseDoubleClickEvent(QMouseEvent *e);
67 void focusInEvent(QFocusEvent *e);
Roman Zippel7fc925f2006-06-08 22:12:46 -070068 void contextMenuEvent(QContextMenuEvent *e);
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070public slots:
71 void setRootMenu(struct menu *menu);
72
73 void updateList(ConfigItem *item);
74 void setValue(ConfigItem* item, tristate val);
75 void changeValue(ConfigItem* item);
76 void updateSelection(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -070077 void saveSettings(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078signals:
Roman Zippel43bf6122006-06-08 22:12:45 -070079 void menuChanged(struct menu *menu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 void menuSelected(struct menu *menu);
81 void parentSelected(void);
Roman Zippelb65a47e2006-06-08 22:12:47 -070082 void gotFocus(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84public:
85 void updateListAll(void)
86 {
87 updateAll = true;
88 updateList(NULL);
89 updateAll = false;
90 }
91 ConfigList* listView()
92 {
93 return this;
94 }
95 ConfigItem* firstChild() const
96 {
97 return (ConfigItem *)Parent::firstChild();
98 }
99 int mapIdx(colIdx idx)
100 {
101 return colMap[idx];
102 }
103 void addColumn(colIdx idx, const QString& label)
104 {
105 colMap[idx] = Parent::addColumn(label);
106 colRevMap[colMap[idx]] = idx;
107 }
108 void removeColumn(colIdx idx)
109 {
110 int col = colMap[idx];
111 if (col >= 0) {
112 Parent::removeColumn(col);
113 colRevMap[col] = colMap[idx] = -1;
114 }
115 }
116 void setAllOpen(bool open);
117 void setParentMenu(void);
118
Li Zefan39a48972010-05-10 16:33:41 +0800119 bool menuSkip(struct menu *);
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 template <class P>
Dave Jones19144d02006-01-08 01:05:02 -0800122 void updateMenuList(P*, struct menu*);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 bool updateAll;
125
126 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
127 QPixmap choiceYesPix, choiceNoPix;
128 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
129
Li Zefan39a48972010-05-10 16:33:41 +0800130 bool showName, showRange, showData;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 enum listMode mode;
Li Zefan39a48972010-05-10 16:33:41 +0800132 enum optionMode optMode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 struct menu *rootEntry;
134 QColorGroup disabledColorGroup;
135 QColorGroup inactivedColorGroup;
Alexander Stein133c5f72010-08-31 17:34:37 +0200136 Q3PopupMenu* headerPopup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138private:
139 int colMap[colNr];
140 int colRevMap[colNr];
141};
142
Alexander Stein133c5f72010-08-31 17:34:37 +0200143class ConfigItem : public Q3ListViewItem {
144 typedef class Q3ListViewItem Parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145public:
Alexander Stein133c5f72010-08-31 17:34:37 +0200146 ConfigItem(Q3ListView *parent, ConfigItem *after, struct menu *m, bool v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 : Parent(parent, after), menu(m), visible(v), goParent(false)
148 {
149 init();
150 }
151 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
152 : Parent(parent, after), menu(m), visible(v), goParent(false)
153 {
154 init();
155 }
Alexander Stein133c5f72010-08-31 17:34:37 +0200156 ConfigItem(Q3ListView *parent, ConfigItem *after, bool v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 : Parent(parent, after), menu(0), visible(v), goParent(true)
158 {
159 init();
160 }
161 ~ConfigItem(void);
162 void init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 void okRename(int col);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 void updateMenu(void);
165 void testUpdateMenu(bool v);
166 ConfigList* listView() const
167 {
168 return (ConfigList*)Parent::listView();
169 }
170 ConfigItem* firstChild() const
171 {
172 return (ConfigItem *)Parent::firstChild();
173 }
174 ConfigItem* nextSibling() const
175 {
176 return (ConfigItem *)Parent::nextSibling();
177 }
178 void setText(colIdx idx, const QString& text)
179 {
180 Parent::setText(listView()->mapIdx(idx), text);
181 }
182 QString text(colIdx idx) const
183 {
184 return Parent::text(listView()->mapIdx(idx));
185 }
186 void setPixmap(colIdx idx, const QPixmap& pm)
187 {
188 Parent::setPixmap(listView()->mapIdx(idx), pm);
189 }
190 const QPixmap* pixmap(colIdx idx) const
191 {
192 return Parent::pixmap(listView()->mapIdx(idx));
193 }
194 void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
195
196 ConfigItem* nextItem;
197 struct menu *menu;
198 bool visible;
199 bool goParent;
200};
201
202class ConfigLineEdit : public QLineEdit {
203 Q_OBJECT
204 typedef class QLineEdit Parent;
205public:
Roman Zippel43bf6122006-06-08 22:12:45 -0700206 ConfigLineEdit(ConfigView* parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 ConfigView* parent(void) const
208 {
209 return (ConfigView*)Parent::parent();
210 }
211 void show(ConfigItem *i);
212 void keyPressEvent(QKeyEvent *e);
213
214public:
215 ConfigItem *item;
216};
217
Alexander Stein133c5f72010-08-31 17:34:37 +0200218class ConfigView : public Q3VBox {
Roman Zippel7fc925f2006-06-08 22:12:46 -0700219 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +0200220 typedef class Q3VBox Parent;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700221public:
222 ConfigView(QWidget* parent, const char *name = 0);
223 ~ConfigView(void);
224 static void updateList(ConfigItem* item);
225 static void updateListAll(void);
226
Roman Zippel7fc925f2006-06-08 22:12:46 -0700227 bool showName(void) const { return list->showName; }
228 bool showRange(void) const { return list->showRange; }
229 bool showData(void) const { return list->showData; }
230public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700231 void setShowName(bool);
232 void setShowRange(bool);
233 void setShowData(bool);
Li Zefan39a48972010-05-10 16:33:41 +0800234 void setOptionMode(QAction *);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700235signals:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700236 void showNameChanged(bool);
237 void showRangeChanged(bool);
238 void showDataChanged(bool);
239public:
240 ConfigList* list;
241 ConfigLineEdit* lineEdit;
242
243 static ConfigView* viewList;
244 ConfigView* nextView;
Li Zefan39a48972010-05-10 16:33:41 +0800245
246 static QAction *showNormalAction;
247 static QAction *showAllAction;
248 static QAction *showPromptAction;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700249};
250
Alexander Stein133c5f72010-08-31 17:34:37 +0200251class ConfigInfoView : public Q3TextBrowser {
Roman Zippel43bf6122006-06-08 22:12:45 -0700252 Q_OBJECT
Alexander Stein133c5f72010-08-31 17:34:37 +0200253 typedef class Q3TextBrowser Parent;
Roman Zippel43bf6122006-06-08 22:12:45 -0700254public:
255 ConfigInfoView(QWidget* parent, const char *name = 0);
256 bool showDebug(void) const { return _showDebug; }
257
258public slots:
259 void setInfo(struct menu *menu);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700260 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700261 void setShowDebug(bool);
262
263signals:
264 void showDebugChanged(bool);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700265 void menuSelected(struct menu *);
Roman Zippel43bf6122006-06-08 22:12:45 -0700266
267protected:
Roman Zippelab45d192006-06-08 22:12:47 -0700268 void symbolInfo(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700269 void menuInfo(void);
270 QString debug_info(struct symbol *sym);
271 static QString print_filter(const QString &str);
Roman Zippelab45d192006-06-08 22:12:47 -0700272 static void expr_print_help(void *data, struct symbol *sym, const char *str);
Alexander Stein133c5f72010-08-31 17:34:37 +0200273 Q3PopupMenu* createPopupMenu(const QPoint& pos);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700274 void contentsContextMenuEvent(QContextMenuEvent *e);
Roman Zippel43bf6122006-06-08 22:12:45 -0700275
Roman Zippelab45d192006-06-08 22:12:47 -0700276 struct symbol *sym;
Alexander Stein133c5f72010-08-31 17:34:37 +0200277 struct menu *_menu;
Roman Zippel43bf6122006-06-08 22:12:45 -0700278 bool _showDebug;
279};
280
281class ConfigSearchWindow : public QDialog {
282 Q_OBJECT
283 typedef class QDialog Parent;
284public:
Marco Costalba63431e72006-10-05 19:12:59 +0200285 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700286
Roman Zippel43bf6122006-06-08 22:12:45 -0700287public slots:
Roman Zippel7fc925f2006-06-08 22:12:46 -0700288 void saveSettings(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700289 void search(void);
Roman Zippel7fc925f2006-06-08 22:12:46 -0700290
Roman Zippel43bf6122006-06-08 22:12:45 -0700291protected:
292 QLineEdit* editField;
293 QPushButton* searchButton;
Roman Zippel7fc925f2006-06-08 22:12:46 -0700294 QSplitter* split;
Roman Zippel43bf6122006-06-08 22:12:45 -0700295 ConfigView* list;
296 ConfigInfoView* info;
297
298 struct symbol **result;
299};
300
Alexander Stein133c5f72010-08-31 17:34:37 +0200301class ConfigMainWindow : public Q3MainWindow {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 Q_OBJECT
Karsten Wiese3b354c52006-12-13 00:34:08 -0800303
Alexander Stein133c5f72010-08-31 17:34:37 +0200304 static Q3Action *saveAction;
Karsten Wiese3b354c52006-12-13 00:34:08 -0800305 static void conf_changed(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306public:
307 ConfigMainWindow(void);
308public slots:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 void changeMenu(struct menu *);
Roman Zippelb65a47e2006-06-08 22:12:47 -0700310 void setMenuLink(struct menu *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 void listFocusChanged(void);
312 void goBack(void);
313 void loadConfig(void);
314 void saveConfig(void);
315 void saveConfigAs(void);
Roman Zippel43bf6122006-06-08 22:12:45 -0700316 void searchConfig(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 void showSingleView(void);
318 void showSplitView(void);
319 void showFullView(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 void showIntro(void);
321 void showAbout(void);
322 void saveSettings(void);
323
324protected:
325 void closeEvent(QCloseEvent *e);
326
Roman Zippel43bf6122006-06-08 22:12:45 -0700327 ConfigSearchWindow *searchWindow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 ConfigView *menuView;
329 ConfigList *menuList;
330 ConfigView *configView;
331 ConfigList *configList;
Roman Zippel43bf6122006-06-08 22:12:45 -0700332 ConfigInfoView *helpText;
Alexander Stein133c5f72010-08-31 17:34:37 +0200333 Q3ToolBar *toolBar;
334 Q3Action *backAction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 QSplitter* split1;
336 QSplitter* split2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337};