qconf.h 7.6 KB

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