Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 */
5
6#include <QCheckBox>
7#include <QDialog>
8#include <QHeaderView>
9#include <QLineEdit>
10#include <QMainWindow>
11#include <QPushButton>
12#include <QSettings>
13#include <QSplitter>
14#include <QStyledItemDelegate>
15#include <QTextBrowser>
16#include <QTreeWidget>
17
18#include "expr.h"
19
20class ConfigList;
21class ConfigItem;
22class ConfigMainWindow;
23
24class ConfigSettings : public QSettings {
25public:
26 ConfigSettings();
27 QList<int> readSizes(const QString& key, bool *ok);
28 bool writeSizes(const QString& key, const QList<int>& value);
29};
30
31enum colIdx {
32 promptColIdx, nameColIdx, dataColIdx
33};
34enum listMode {
35 singleMode, menuMode, symbolMode, fullMode, listMode
36};
37enum optionMode {
38 normalOpt = 0, allOpt, promptOpt
39};
40
41class ConfigList : public QTreeWidget {
42 Q_OBJECT
43 typedef class QTreeWidget Parent;
44public:
45 ConfigList(QWidget *parent, const char *name = 0);
46 ~ConfigList();
47 void reinit(void);
48 ConfigItem* findConfigItem(struct menu *);
49 void setSelected(QTreeWidgetItem *item, bool enable) {
50 for (int i = 0; i < selectedItems().size(); i++)
51 selectedItems().at(i)->setSelected(false);
52
53 item->setSelected(enable);
54 }
55
56protected:
57 void keyPressEvent(QKeyEvent *e);
58 void mousePressEvent(QMouseEvent *e);
59 void mouseReleaseEvent(QMouseEvent *e);
60 void mouseMoveEvent(QMouseEvent *e);
61 void mouseDoubleClickEvent(QMouseEvent *e);
62 void focusInEvent(QFocusEvent *e);
63 void contextMenuEvent(QContextMenuEvent *e);
64
65public slots:
66 void setRootMenu(struct menu *menu);
67
68 void updateList();
69 void setValue(ConfigItem* item, tristate val);
70 void changeValue(ConfigItem* item);
71 void updateSelection(void);
72 void saveSettings(void);
73 void setOptionMode(QAction *action);
74 void setShowName(bool on);
75
76signals:
77 void menuChanged(struct menu *menu);
78 void menuSelected(struct menu *menu);
79 void itemSelected(struct menu *menu);
80 void parentSelected(void);
81 void gotFocus(struct menu *);
82 void showNameChanged(bool on);
83
84public:
85 void updateListAll(void)
86 {
87 updateAll = true;
88 updateList();
89 updateAll = false;
90 }
91 void setAllOpen(bool open);
92 void setParentMenu(void);
93
94 bool menuSkip(struct menu *);
95
96 void updateMenuList(ConfigItem *parent, struct menu*);
97 void updateMenuList(struct menu *menu);
98
99 bool updateAll;
100
101 bool showName;
102 enum listMode mode;
103 enum optionMode optMode;
104 struct menu *rootEntry;
105 QPalette disabledColorGroup;
106 QPalette inactivedColorGroup;
107 QMenu* headerPopup;
108
109 static QList<ConfigList *> allLists;
110 static void updateListForAll();
111 static void updateListAllForAll();
112
113 static QAction *showNormalAction, *showAllAction, *showPromptAction;
114};
115
116class ConfigItem : public QTreeWidgetItem {
117 typedef class QTreeWidgetItem Parent;
118public:
119 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v)
120 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
121 {
122 init();
123 }
124 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
125 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
126 {
127 init();
128 }
129 ConfigItem(ConfigList *parent, ConfigItem *after, bool v)
130 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
131 {
132 init();
133 }
134 ~ConfigItem(void);
135 void init(void);
136 void updateMenu(void);
137 void testUpdateMenu(bool v);
138 ConfigList* listView() const
139 {
140 return (ConfigList*)Parent::treeWidget();
141 }
142 ConfigItem* firstChild() const
143 {
144 return (ConfigItem *)Parent::child(0);
145 }
146 ConfigItem* nextSibling()
147 {
148 ConfigItem *ret = NULL;
149 ConfigItem *_parent = (ConfigItem *)parent();
150
151 if(_parent) {
152 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
153 } else {
154 QTreeWidget *_treeWidget = treeWidget();
155 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
156 }
157
158 return ret;
159 }
160 // TODO: Implement paintCell
161
162 ConfigItem* nextItem;
163 struct menu *menu;
164 bool visible;
165 bool goParent;
166
167 static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon;
168 static QIcon choiceYesIcon, choiceNoIcon;
169 static QIcon menuIcon, menubackIcon;
170};
171
172class ConfigItemDelegate : public QStyledItemDelegate
173{
174private:
175 struct menu *menu;
176public:
177 ConfigItemDelegate(QObject *parent = nullptr)
178 : QStyledItemDelegate(parent) {}
179 QWidget *createEditor(QWidget *parent,
180 const QStyleOptionViewItem &option,
181 const QModelIndex &index) const override;
182 void setModelData(QWidget *editor, QAbstractItemModel *model,
183 const QModelIndex &index) const override;
184};
185
186class ConfigInfoView : public QTextBrowser {
187 Q_OBJECT
188 typedef class QTextBrowser Parent;
189 QMenu *contextMenu;
190public:
191 ConfigInfoView(QWidget* parent, const char *name = 0);
192 bool showDebug(void) const { return _showDebug; }
193
194public slots:
195 void setInfo(struct menu *menu);
196 void saveSettings(void);
197 void setShowDebug(bool);
198 void clicked (const QUrl &url);
199
200signals:
201 void showDebugChanged(bool);
202 void menuSelected(struct menu *);
203
204protected:
205 void symbolInfo(void);
206 void menuInfo(void);
207 QString debug_info(struct symbol *sym);
208 static QString print_filter(const QString &str);
209 static void expr_print_help(void *data, struct symbol *sym, const char *str);
210 void contextMenuEvent(QContextMenuEvent *event);
211
212 struct symbol *sym;
213 struct menu *_menu;
214 bool _showDebug;
215};
216
217class ConfigSearchWindow : public QDialog {
218 Q_OBJECT
219 typedef class QDialog Parent;
220public:
221 ConfigSearchWindow(ConfigMainWindow *parent);
222
223public slots:
224 void saveSettings(void);
225 void search(void);
226
227protected:
228 QLineEdit* editField;
229 QPushButton* searchButton;
230 QSplitter* split;
231 ConfigList *list;
232 ConfigInfoView* info;
233
234 struct symbol **result;
235};
236
237class ConfigMainWindow : public QMainWindow {
238 Q_OBJECT
239
240 char *configname;
241 static QAction *saveAction;
242 static void conf_changed(void);
243public:
244 ConfigMainWindow(void);
245public slots:
246 void changeMenu(struct menu *);
247 void changeItens(struct menu *);
248 void setMenuLink(struct menu *);
249 void listFocusChanged(void);
250 void goBack(void);
251 void loadConfig(void);
252 bool saveConfig(void);
253 void saveConfigAs(void);
254 void searchConfig(void);
255 void showSingleView(void);
256 void showSplitView(void);
257 void showFullView(void);
258 void showIntro(void);
259 void showAbout(void);
260 void saveSettings(void);
261
262protected:
263 void closeEvent(QCloseEvent *e);
264
265 ConfigSearchWindow *searchWindow;
266 ConfigList *menuList;
267 ConfigList *configList;
268 ConfigInfoView *helpText;
269 QAction *backAction;
270 QAction *singleViewAction;
271 QAction *splitViewAction;
272 QAction *fullViewAction;
273 QSplitter *split1;
274 QSplitter *split2;
275};
1/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
6#if QT_VERSION < 0x040000
7#include <qlistview.h>
8#else
9#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
25#endif
26
27class ConfigView;
28class ConfigList;
29class ConfigItem;
30class ConfigLineEdit;
31class ConfigMainWindow;
32
33class ConfigSettings : public QSettings {
34public:
35 Q3ValueList<int> readSizes(const QString& key, bool *ok);
36 bool writeSizes(const QString& key, const Q3ValueList<int>& value);
37};
38
39enum colIdx {
40 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
41};
42enum listMode {
43 singleMode, menuMode, symbolMode, fullMode, listMode
44};
45enum optionMode {
46 normalOpt = 0, allOpt, promptOpt
47};
48
49class ConfigList : public Q3ListView {
50 Q_OBJECT
51 typedef class Q3ListView Parent;
52public:
53 ConfigList(ConfigView* p, const char *name = 0);
54 void reinit(void);
55 ConfigView* parent(void) const
56 {
57 return (ConfigView*)Parent::parent();
58 }
59 ConfigItem* findConfigItem(struct menu *);
60
61protected:
62 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);
68 void contextMenuEvent(QContextMenuEvent *e);
69
70public 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);
77 void saveSettings(void);
78signals:
79 void menuChanged(struct menu *menu);
80 void menuSelected(struct menu *menu);
81 void parentSelected(void);
82 void gotFocus(struct menu *);
83
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
119 bool menuSkip(struct menu *);
120
121 template <class P>
122 void updateMenuList(P*, struct menu*);
123
124 bool updateAll;
125
126 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
127 QPixmap choiceYesPix, choiceNoPix;
128 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
129
130 bool showName, showRange, showData;
131 enum listMode mode;
132 enum optionMode optMode;
133 struct menu *rootEntry;
134 QColorGroup disabledColorGroup;
135 QColorGroup inactivedColorGroup;
136 Q3PopupMenu* headerPopup;
137
138private:
139 int colMap[colNr];
140 int colRevMap[colNr];
141};
142
143class ConfigItem : public Q3ListViewItem {
144 typedef class Q3ListViewItem Parent;
145public:
146 ConfigItem(Q3ListView *parent, ConfigItem *after, struct menu *m, bool v)
147 : 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 }
156 ConfigItem(Q3ListView *parent, ConfigItem *after, bool v)
157 : Parent(parent, after), menu(0), visible(v), goParent(true)
158 {
159 init();
160 }
161 ~ConfigItem(void);
162 void init(void);
163 void okRename(int col);
164 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:
206 ConfigLineEdit(ConfigView* parent);
207 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
218class ConfigView : public Q3VBox {
219 Q_OBJECT
220 typedef class Q3VBox Parent;
221public:
222 ConfigView(QWidget* parent, const char *name = 0);
223 ~ConfigView(void);
224 static void updateList(ConfigItem* item);
225 static void updateListAll(void);
226
227 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:
231 void setShowName(bool);
232 void setShowRange(bool);
233 void setShowData(bool);
234 void setOptionMode(QAction *);
235signals:
236 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;
245
246 static QAction *showNormalAction;
247 static QAction *showAllAction;
248 static QAction *showPromptAction;
249};
250
251class ConfigInfoView : public Q3TextBrowser {
252 Q_OBJECT
253 typedef class Q3TextBrowser Parent;
254public:
255 ConfigInfoView(QWidget* parent, const char *name = 0);
256 bool showDebug(void) const { return _showDebug; }
257
258public slots:
259 void setInfo(struct menu *menu);
260 void saveSettings(void);
261 void setShowDebug(bool);
262
263signals:
264 void showDebugChanged(bool);
265 void menuSelected(struct menu *);
266
267protected:
268 void symbolInfo(void);
269 void menuInfo(void);
270 QString debug_info(struct symbol *sym);
271 static QString print_filter(const QString &str);
272 static void expr_print_help(void *data, struct symbol *sym, const char *str);
273 Q3PopupMenu* createPopupMenu(const QPoint& pos);
274 void contentsContextMenuEvent(QContextMenuEvent *e);
275
276 struct symbol *sym;
277 struct menu *_menu;
278 bool _showDebug;
279};
280
281class ConfigSearchWindow : public QDialog {
282 Q_OBJECT
283 typedef class QDialog Parent;
284public:
285 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
286
287public slots:
288 void saveSettings(void);
289 void search(void);
290
291protected:
292 QLineEdit* editField;
293 QPushButton* searchButton;
294 QSplitter* split;
295 ConfigView* list;
296 ConfigInfoView* info;
297
298 struct symbol **result;
299};
300
301class ConfigMainWindow : public Q3MainWindow {
302 Q_OBJECT
303
304 static Q3Action *saveAction;
305 static void conf_changed(void);
306public:
307 ConfigMainWindow(void);
308public slots:
309 void changeMenu(struct menu *);
310 void setMenuLink(struct menu *);
311 void listFocusChanged(void);
312 void goBack(void);
313 void loadConfig(void);
314 bool saveConfig(void);
315 void saveConfigAs(void);
316 void searchConfig(void);
317 void showSingleView(void);
318 void showSplitView(void);
319 void showFullView(void);
320 void showIntro(void);
321 void showAbout(void);
322 void saveSettings(void);
323
324protected:
325 void closeEvent(QCloseEvent *e);
326
327 ConfigSearchWindow *searchWindow;
328 ConfigView *menuView;
329 ConfigList *menuList;
330 ConfigView *configView;
331 ConfigList *configList;
332 ConfigInfoView *helpText;
333 Q3ToolBar *toolBar;
334 Q3Action *backAction;
335 QSplitter* split1;
336 QSplitter* split2;
337};