1
0

qconf.h 6.4 KB

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