qconf.h 7.8 KB

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