qconf.h 6.3 KB

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