qconf.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. #endif
  11. class ConfigList;
  12. class ConfigItem;
  13. class ConfigLineEdit;
  14. class ConfigMainWindow;
  15. class ConfigSettings : public QSettings {
  16. public:
  17. ConfigSettings();
  18. #if QT_VERSION >= 300
  19. void readListSettings();
  20. QValueList<int> readSizes(const QString& key, bool *ok);
  21. bool writeSizes(const QString& key, const QValueList<int>& value);
  22. #endif
  23. bool showAll;
  24. bool showName;
  25. bool showRange;
  26. bool showData;
  27. };
  28. class ConfigView : public QVBox {
  29. Q_OBJECT
  30. typedef class QVBox Parent;
  31. public:
  32. ConfigView(QWidget* parent, ConfigMainWindow* cview, ConfigSettings* configSettings);
  33. ~ConfigView(void);
  34. static void updateList(ConfigItem* item);
  35. static void updateListAll(void);
  36. public:
  37. ConfigList* list;
  38. ConfigLineEdit* lineEdit;
  39. static ConfigView* viewList;
  40. ConfigView* nextView;
  41. };
  42. enum colIdx {
  43. promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
  44. };
  45. enum listMode {
  46. singleMode, menuMode, symbolMode, fullMode
  47. };
  48. class ConfigList : public QListView {
  49. Q_OBJECT
  50. typedef class QListView Parent;
  51. public:
  52. ConfigList(ConfigView* p, ConfigMainWindow* cview, ConfigSettings *configSettings);
  53. void reinit(void);
  54. ConfigView* parent(void) const
  55. {
  56. return (ConfigView*)Parent::parent();
  57. }
  58. protected:
  59. ConfigMainWindow* cview;
  60. void keyPressEvent(QKeyEvent *e);
  61. void contentsMousePressEvent(QMouseEvent *e);
  62. void contentsMouseReleaseEvent(QMouseEvent *e);
  63. void contentsMouseMoveEvent(QMouseEvent *e);
  64. void contentsMouseDoubleClickEvent(QMouseEvent *e);
  65. void focusInEvent(QFocusEvent *e);
  66. public slots:
  67. void setRootMenu(struct menu *menu);
  68. void updateList(ConfigItem *item);
  69. void setValue(ConfigItem* item, tristate val);
  70. void changeValue(ConfigItem* item);
  71. void updateSelection(void);
  72. signals:
  73. void menuSelected(struct menu *menu);
  74. void parentSelected(void);
  75. void gotFocus(void);
  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. template <class P>
  111. void updateMenuList(P*, struct menu*);
  112. bool updateAll;
  113. QPixmap symbolYesPix, symbolModPix, symbolNoPix;
  114. QPixmap choiceYesPix, choiceNoPix;
  115. QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
  116. bool showAll, showName, showRange, showData;
  117. enum listMode mode;
  118. struct menu *rootEntry;
  119. QColorGroup disabledColorGroup;
  120. QColorGroup inactivedColorGroup;
  121. private:
  122. int colMap[colNr];
  123. int colRevMap[colNr];
  124. };
  125. class ConfigItem : public QListViewItem {
  126. typedef class QListViewItem Parent;
  127. public:
  128. ConfigItem(QListView *parent, ConfigItem *after, struct menu *m, bool v)
  129. : Parent(parent, after), menu(m), visible(v), goParent(false)
  130. {
  131. init();
  132. }
  133. ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
  134. : Parent(parent, after), menu(m), visible(v), goParent(false)
  135. {
  136. init();
  137. }
  138. ConfigItem(QListView *parent, ConfigItem *after, bool v)
  139. : Parent(parent, after), menu(0), visible(v), goParent(true)
  140. {
  141. init();
  142. }
  143. ~ConfigItem(void);
  144. void init(void);
  145. #if QT_VERSION >= 300
  146. void okRename(int col);
  147. #endif
  148. void updateMenu(void);
  149. void testUpdateMenu(bool v);
  150. ConfigList* listView() const
  151. {
  152. return (ConfigList*)Parent::listView();
  153. }
  154. ConfigItem* firstChild() const
  155. {
  156. return (ConfigItem *)Parent::firstChild();
  157. }
  158. ConfigItem* nextSibling() const
  159. {
  160. return (ConfigItem *)Parent::nextSibling();
  161. }
  162. void setText(colIdx idx, const QString& text)
  163. {
  164. Parent::setText(listView()->mapIdx(idx), text);
  165. }
  166. QString text(colIdx idx) const
  167. {
  168. return Parent::text(listView()->mapIdx(idx));
  169. }
  170. void setPixmap(colIdx idx, const QPixmap& pm)
  171. {
  172. Parent::setPixmap(listView()->mapIdx(idx), pm);
  173. }
  174. const QPixmap* pixmap(colIdx idx) const
  175. {
  176. return Parent::pixmap(listView()->mapIdx(idx));
  177. }
  178. void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
  179. ConfigItem* nextItem;
  180. struct menu *menu;
  181. bool visible;
  182. bool goParent;
  183. };
  184. class ConfigLineEdit : public QLineEdit {
  185. Q_OBJECT
  186. typedef class QLineEdit Parent;
  187. public:
  188. ConfigLineEdit(ConfigView* parent)
  189. : Parent(parent)
  190. { }
  191. ConfigView* parent(void) const
  192. {
  193. return (ConfigView*)Parent::parent();
  194. }
  195. void show(ConfigItem *i);
  196. void keyPressEvent(QKeyEvent *e);
  197. public:
  198. ConfigItem *item;
  199. };
  200. class ConfigMainWindow : public QMainWindow {
  201. Q_OBJECT
  202. public:
  203. ConfigMainWindow(void);
  204. public slots:
  205. void setHelp(QListViewItem* item);
  206. void changeMenu(struct menu *);
  207. void listFocusChanged(void);
  208. void goBack(void);
  209. void loadConfig(void);
  210. void saveConfig(void);
  211. void saveConfigAs(void);
  212. void showSingleView(void);
  213. void showSplitView(void);
  214. void showFullView(void);
  215. void setShowAll(bool);
  216. void setShowDebug(bool);
  217. void setShowRange(bool);
  218. void setShowName(bool);
  219. void setShowData(bool);
  220. void showIntro(void);
  221. void showAbout(void);
  222. void saveSettings(void);
  223. protected:
  224. void closeEvent(QCloseEvent *e);
  225. ConfigView *menuView;
  226. ConfigList *menuList;
  227. ConfigView *configView;
  228. ConfigList *configList;
  229. QTextView *helpText;
  230. QToolBar *toolBar;
  231. QAction *backAction;
  232. QSplitter* split1;
  233. QSplitter* split2;
  234. bool showDebug;
  235. };