qconf.h 7.9 KB

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