qconf.h 7.7 KB

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