1
0

qconf.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  3. * Released under the terms of the GNU GPL v2.0.
  4. */
  5. #include <QTextBrowser>
  6. #include <QTreeWidget>
  7. #include <QMainWindow>
  8. #include <QHeaderView>
  9. #include <qsettings.h>
  10. #include <QPushButton>
  11. #include <QSettings>
  12. #include <QLineEdit>
  13. #include <QSplitter>
  14. #include <QCheckBox>
  15. #include <QDialog>
  16. #include "expr.h"
  17. class ConfigView;
  18. class ConfigList;
  19. class ConfigItem;
  20. class ConfigLineEdit;
  21. class ConfigMainWindow;
  22. class ConfigSettings : public QSettings {
  23. public:
  24. ConfigSettings();
  25. QList<int> readSizes(const QString& key, bool *ok);
  26. bool writeSizes(const QString& key, const QList<int>& value);
  27. };
  28. enum colIdx {
  29. promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
  30. };
  31. enum listMode {
  32. singleMode, menuMode, symbolMode, fullMode, listMode
  33. };
  34. enum optionMode {
  35. normalOpt = 0, allOpt, promptOpt
  36. };
  37. class ConfigList : public QTreeWidget {
  38. Q_OBJECT
  39. typedef class QTreeWidget Parent;
  40. public:
  41. ConfigList(ConfigView* p, const char *name = 0);
  42. void reinit(void);
  43. ConfigView* parent(void) const
  44. {
  45. return (ConfigView*)Parent::parent();
  46. }
  47. ConfigItem* findConfigItem(struct menu *);
  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(ConfigItem *item);
  59. void setValue(ConfigItem* item, tristate val);
  60. void changeValue(ConfigItem* item);
  61. void updateSelection(void);
  62. void saveSettings(void);
  63. signals:
  64. void menuChanged(struct menu *menu);
  65. void menuSelected(struct menu *menu);
  66. void parentSelected(void);
  67. void gotFocus(struct menu *);
  68. public:
  69. void updateListAll(void)
  70. {
  71. updateAll = true;
  72. updateList(NULL);
  73. updateAll = false;
  74. }
  75. ConfigList* listView()
  76. {
  77. return this;
  78. }
  79. ConfigItem* firstChild() const
  80. {
  81. return (ConfigItem *)children().first();
  82. }
  83. void addColumn(colIdx idx)
  84. {
  85. showColumn(idx);
  86. }
  87. void removeColumn(colIdx idx)
  88. {
  89. hideColumn(idx);
  90. }
  91. void setAllOpen(bool open);
  92. void setParentMenu(void);
  93. bool menuSkip(struct menu *);
  94. void updateMenuList(ConfigItem *parent, struct menu*);
  95. void updateMenuList(ConfigList *parent, struct menu*);
  96. bool updateAll;
  97. QPixmap symbolYesPix, symbolModPix, symbolNoPix;
  98. QPixmap choiceYesPix, choiceNoPix;
  99. QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
  100. bool showName, showRange, showData;
  101. enum listMode mode;
  102. enum optionMode optMode;
  103. struct menu *rootEntry;
  104. QPalette disabledColorGroup;
  105. QPalette inactivedColorGroup;
  106. QMenu* headerPopup;
  107. };
  108. class ConfigItem : public QTreeWidgetItem {
  109. typedef class QTreeWidgetItem Parent;
  110. public:
  111. ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v)
  112. : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
  113. {
  114. init();
  115. }
  116. ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
  117. : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
  118. {
  119. init();
  120. }
  121. ConfigItem(ConfigList *parent, ConfigItem *after, bool v)
  122. : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
  123. {
  124. init();
  125. }
  126. ~ConfigItem(void);
  127. void init(void);
  128. void okRename(int col);
  129. void updateMenu(void);
  130. void testUpdateMenu(bool v);
  131. ConfigList* listView() const
  132. {
  133. return (ConfigList*)Parent::treeWidget();
  134. }
  135. ConfigItem* firstChild() const
  136. {
  137. return (ConfigItem *)Parent::child(0);
  138. }
  139. ConfigItem* nextSibling()
  140. {
  141. ConfigItem *ret = NULL;
  142. ConfigItem *_parent = (ConfigItem *)parent();
  143. if(_parent) {
  144. ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
  145. } else {
  146. QTreeWidget *_treeWidget = treeWidget();
  147. ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
  148. }
  149. return ret;
  150. }
  151. void setText(colIdx idx, const QString& text)
  152. {
  153. Parent::setText(idx, text);
  154. }
  155. QString text(colIdx idx) const
  156. {
  157. return Parent::text(idx);
  158. }
  159. void setPixmap(colIdx idx, const QIcon &icon)
  160. {
  161. Parent::setIcon(idx, icon);
  162. }
  163. const QIcon pixmap(colIdx idx) const
  164. {
  165. return icon(idx);
  166. }
  167. // TODO: Implement paintCell
  168. ConfigItem* nextItem;
  169. struct menu *menu;
  170. bool visible;
  171. bool goParent;
  172. };
  173. class ConfigLineEdit : public QLineEdit {
  174. Q_OBJECT
  175. typedef class QLineEdit Parent;
  176. public:
  177. ConfigLineEdit(ConfigView* parent);
  178. ConfigView* parent(void) const
  179. {
  180. return (ConfigView*)Parent::parent();
  181. }
  182. void show(ConfigItem *i);
  183. void keyPressEvent(QKeyEvent *e);
  184. public:
  185. ConfigItem *item;
  186. };
  187. class ConfigView : public QWidget {
  188. Q_OBJECT
  189. typedef class QWidget Parent;
  190. public:
  191. ConfigView(QWidget* parent, const char *name = 0);
  192. ~ConfigView(void);
  193. static void updateList(ConfigItem* item);
  194. static void updateListAll(void);
  195. bool showName(void) const { return list->showName; }
  196. bool showRange(void) const { return list->showRange; }
  197. bool showData(void) const { return list->showData; }
  198. public slots:
  199. void setShowName(bool);
  200. void setShowRange(bool);
  201. void setShowData(bool);
  202. void setOptionMode(QAction *);
  203. signals:
  204. void showNameChanged(bool);
  205. void showRangeChanged(bool);
  206. void showDataChanged(bool);
  207. public:
  208. ConfigList* list;
  209. ConfigLineEdit* lineEdit;
  210. static ConfigView* viewList;
  211. ConfigView* nextView;
  212. static QAction *showNormalAction;
  213. static QAction *showAllAction;
  214. static QAction *showPromptAction;
  215. };
  216. class ConfigInfoView : public QTextBrowser {
  217. Q_OBJECT
  218. typedef class QTextBrowser Parent;
  219. public:
  220. ConfigInfoView(QWidget* parent, const char *name = 0);
  221. bool showDebug(void) const { return _showDebug; }
  222. public slots:
  223. void setInfo(struct menu *menu);
  224. void saveSettings(void);
  225. void setShowDebug(bool);
  226. signals:
  227. void showDebugChanged(bool);
  228. void menuSelected(struct menu *);
  229. protected:
  230. void symbolInfo(void);
  231. void menuInfo(void);
  232. QString debug_info(struct symbol *sym);
  233. static QString print_filter(const QString &str);
  234. static void expr_print_help(void *data, struct symbol *sym, const char *str);
  235. QMenu *createStandardContextMenu(const QPoint & pos);
  236. void contextMenuEvent(QContextMenuEvent *e);
  237. struct symbol *sym;
  238. struct menu *_menu;
  239. bool _showDebug;
  240. };
  241. class ConfigSearchWindow : public QDialog {
  242. Q_OBJECT
  243. typedef class QDialog Parent;
  244. public:
  245. ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0);
  246. public slots:
  247. void saveSettings(void);
  248. void search(void);
  249. protected:
  250. QLineEdit* editField;
  251. QPushButton* searchButton;
  252. QSplitter* split;
  253. ConfigView* list;
  254. ConfigInfoView* info;
  255. struct symbol **result;
  256. };
  257. class ConfigMainWindow : public QMainWindow {
  258. Q_OBJECT
  259. static QAction *saveAction;
  260. static void conf_changed(void);
  261. public:
  262. ConfigMainWindow(void);
  263. public slots:
  264. void changeMenu(struct menu *);
  265. void setMenuLink(struct menu *);
  266. void listFocusChanged(void);
  267. void goBack(void);
  268. void loadConfig(void);
  269. bool saveConfig(void);
  270. void saveConfigAs(void);
  271. void searchConfig(void);
  272. void showSingleView(void);
  273. void showSplitView(void);
  274. void showFullView(void);
  275. void showIntro(void);
  276. void showAbout(void);
  277. void saveSettings(void);
  278. protected:
  279. void closeEvent(QCloseEvent *e);
  280. ConfigSearchWindow *searchWindow;
  281. ConfigView *menuView;
  282. ConfigList *menuList;
  283. ConfigView *configView;
  284. ConfigList *configList;
  285. ConfigInfoView *helpText;
  286. QToolBar *toolBar;
  287. QAction *backAction;
  288. QAction *singleViewAction;
  289. QAction *splitViewAction;
  290. QAction *fullViewAction;
  291. QSplitter *split1;
  292. QSplitter *split2;
  293. };