xref: /linux/scripts/kconfig/qconf.h (revision 0074281bb6316108e0cff094bd4db78ab3eee236)
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 
20 class ConfigList;
21 class ConfigItem;
22 class ConfigMainWindow;
23 
24 class ConfigSettings : public QSettings {
25 public:
26 	ConfigSettings();
27 	~ConfigSettings(void);
28 	QList<int> readSizes(const QString& key, bool *ok);
29 	bool writeSizes(const QString& key, const QList<int>& value);
30 };
31 
32 enum colIdx {
33 	promptColIdx, nameColIdx, dataColIdx
34 };
35 enum listMode {
36 	singleMode, menuMode, symbolMode, fullMode, listMode
37 };
38 enum optionMode {
39 	normalOpt = 0, allOpt, promptOpt
40 };
41 
42 class ConfigList : public QTreeWidget {
43 	Q_OBJECT
44 	typedef class QTreeWidget Parent;
45 public:
46 	ConfigList(QWidget *parent, const char *name = 0);
47 	~ConfigList();
48 	void reinit(void);
49 	ConfigItem* findConfigItem(struct menu *);
setSelected(QTreeWidgetItem * item,bool enable)50 	void setSelected(QTreeWidgetItem *item, bool enable) {
51 		for (int i = 0; i < selectedItems().size(); i++)
52 			selectedItems().at(i)->setSelected(false);
53 
54 		item->setSelected(enable);
55 	}
56 
57 protected:
58 	void keyPressEvent(QKeyEvent *e);
59 	void mouseReleaseEvent(QMouseEvent *e);
60 	void mouseDoubleClickEvent(QMouseEvent *e);
61 	void focusInEvent(QFocusEvent *e);
62 	void contextMenuEvent(QContextMenuEvent *e);
63 
64 public slots:
65 	void setRootMenu(struct menu *menu);
66 
67 	void updateList();
68 	void setValue(ConfigItem* item, tristate val);
69 	void changeValue(ConfigItem* item);
70 	void updateSelection(void);
71 	void saveSettings(void);
72 	void setOptionMode(QAction *action);
73 	void setShowName(bool on);
74 
75 signals:
76 	void menuChanged(struct menu *menu);
77 	void menuSelected(struct menu *menu);
78 	void itemSelected(struct menu *menu);
79 	void parentSelected(void);
80 	void gotFocus(struct menu *);
81 	void showNameChanged(bool on);
82 
83 public:
updateListAll(void)84 	void updateListAll(void)
85 	{
86 		updateAll = true;
87 		updateList();
88 		updateAll = false;
89 	}
90 	void setAllOpen(bool open);
91 	void setParentMenu(void);
92 
93 	bool menuSkip(struct menu *);
94 
95 	void updateMenuList(ConfigItem *parent, struct menu*);
96 	void updateMenuList(struct menu *menu);
97 
98 	bool updateAll;
99 
100 	bool showName;
101 	enum listMode mode;
102 	enum optionMode optMode;
103 	struct menu *rootEntry;
104 	QPalette disabledColorGroup;
105 	QPalette inactivedColorGroup;
106 	QMenu* headerPopup;
107 
108 	static QList<ConfigList *> allLists;
109 	static void updateListForAll();
110 	static void updateListAllForAll();
111 
112 	static QAction *showNormalAction, *showAllAction, *showPromptAction;
113 };
114 
115 class ConfigItem : public QTreeWidgetItem {
116 	typedef class QTreeWidgetItem Parent;
117 public:
ConfigItem(ConfigList * parent,ConfigItem * after,struct menu * m)118 	ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m)
119 	: Parent(parent, after), nextItem(0), menu(m), goParent(false)
120 	{
121 		init();
122 	}
ConfigItem(ConfigItem * parent,ConfigItem * after,struct menu * m)123 	ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m)
124 	: Parent(parent, after), nextItem(0), menu(m), goParent(false)
125 	{
126 		init();
127 	}
ConfigItem(ConfigList * parent,ConfigItem * after)128 	ConfigItem(ConfigList *parent, ConfigItem *after)
129 	: Parent(parent, after), nextItem(0), menu(0), goParent(true)
130 	{
131 		init();
132 	}
133 	~ConfigItem(void);
134 	void init(void);
135 	void updateMenu(void);
136 	void testUpdateMenu(void);
listView()137 	ConfigList* listView() const
138 	{
139 		return (ConfigList*)Parent::treeWidget();
140 	}
firstChild()141 	ConfigItem* firstChild() const
142 	{
143 		return (ConfigItem *)Parent::child(0);
144 	}
nextSibling()145 	ConfigItem* nextSibling()
146 	{
147 		ConfigItem *ret = NULL;
148 		ConfigItem *_parent = (ConfigItem *)parent();
149 
150 		if(_parent) {
151 			ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
152 		} else {
153 			QTreeWidget *_treeWidget = treeWidget();
154 			ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
155 		}
156 
157 		return ret;
158 	}
159 	// TODO: Implement paintCell
160 
161 	ConfigItem* nextItem;
162 	struct menu *menu;
163 	bool goParent;
164 
165 	static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon;
166 	static QIcon choiceYesIcon, choiceNoIcon;
167 	static QIcon menuIcon, menubackIcon;
168 };
169 
170 class ConfigItemDelegate : public QStyledItemDelegate
171 {
172 private:
173 	struct menu *menu;
174 public:
175 	ConfigItemDelegate(QObject *parent = nullptr)
QStyledItemDelegate(parent)176 		: QStyledItemDelegate(parent) {}
177 	QWidget *createEditor(QWidget *parent,
178 			      const QStyleOptionViewItem &option,
179 			      const QModelIndex &index) const override;
180 	void setModelData(QWidget *editor, QAbstractItemModel *model,
181 			  const QModelIndex &index) const override;
182 };
183 
184 class ConfigInfoView : public QTextBrowser {
185 	Q_OBJECT
186 	typedef class QTextBrowser Parent;
187 	QMenu *contextMenu;
188 public:
189 	ConfigInfoView(QWidget* parent, const char *name = 0);
showDebug(void)190 	bool showDebug(void) const { return _showDebug; }
191 
192 public slots:
193 	void setInfo(struct menu *menu);
194 	void saveSettings(void);
195 	void setShowDebug(bool);
196 	void clicked (const QUrl &url);
197 
198 signals:
199 	void showDebugChanged(bool);
200 	void menuSelected(struct menu *);
201 
202 protected:
203 	void symbolInfo(void);
204 	void menuInfo(void);
205 	QString debug_info(struct symbol *sym);
206 	static QString print_filter(const QString &str);
207 	static void expr_print_help(void *data, struct symbol *sym, const char *str);
208 	void contextMenuEvent(QContextMenuEvent *event);
209 
210 	struct symbol *sym;
211 	struct menu *_menu;
212 	bool _showDebug;
213 };
214 
215 class ConfigSearchWindow : public QDialog {
216 	Q_OBJECT
217 	typedef class QDialog Parent;
218 public:
219 	ConfigSearchWindow(ConfigMainWindow *parent);
220 
221 public slots:
222 	void saveSettings(void);
223 	void search(void);
224 
225 protected:
226 	QLineEdit* editField;
227 	QPushButton* searchButton;
228 	QSplitter* split;
229 	ConfigList *list;
230 	ConfigInfoView* info;
231 
232 	struct symbol **result;
233 };
234 
235 class ConfigMainWindow : public QMainWindow {
236 	Q_OBJECT
237 
238 	QString configname;
239 	static QAction *saveAction;
240 	static void conf_changed(bool);
241 public:
242 	ConfigMainWindow(void);
243 public slots:
244 	void changeMenu(struct menu *);
245 	void changeItens(struct menu *);
246 	void setMenuLink(struct menu *);
247 	void listFocusChanged(void);
248 	void goBack(void);
249 	void loadConfig(void);
250 	bool saveConfig(void);
251 	void saveConfigAs(void);
252 	void searchConfig(void);
253 	void showSingleView(void);
254 	void showSplitView(void);
255 	void showFullView(void);
256 	void showIntro(void);
257 	void showAbout(void);
258 	void saveSettings(void);
259 
260 protected:
261 	void closeEvent(QCloseEvent *e);
262 
263 	ConfigSearchWindow *searchWindow;
264 	ConfigList *menuList;
265 	ConfigList *configList;
266 	ConfigInfoView *helpText;
267 	QAction *backAction;
268 	QAction *singleViewAction;
269 	QAction *splitViewAction;
270 	QAction *fullViewAction;
271 	QSplitter *split1;
272 	QSplitter *split2;
273 };
274