blob: e52f3e90bf0cea264738a9ba0d1117bcf4afa724 [file] [log] [blame]
Denis Vlasenko7d219aa2006-10-05 10:17:08 +00001/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */
5
6#include <qlistview.h>
7#if QT_VERSION >= 300
8#include <qsettings.h>
9#else
10class QSettings { };
11#endif
12
13class ConfigList;
14class ConfigItem;
15class ConfigLineEdit;
16class ConfigMainWindow;
17
18
19class ConfigSettings : public QSettings {
20public:
21 ConfigSettings();
22
23#if QT_VERSION >= 300
24 void readListSettings();
25 QValueList<int> readSizes(const QString& key, bool *ok);
26 bool writeSizes(const QString& key, const QValueList<int>& value);
27#endif
28
29 bool showAll;
30 bool showName;
31 bool showRange;
32 bool showData;
33};
34
35class ConfigView : public QVBox {
36 Q_OBJECT
37 typedef class QVBox Parent;
38public:
39 ConfigView(QWidget* parent, ConfigMainWindow* cview, ConfigSettings* configSettings);
40 ~ConfigView(void);
41 static void updateList(ConfigItem* item);
42 static void updateListAll(void);
43
44public:
45 ConfigList* list;
46 ConfigLineEdit* lineEdit;
47
48 static ConfigView* viewList;
49 ConfigView* nextView;
50};
51
52enum colIdx {
53 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr
54};
55enum listMode {
56 singleMode, menuMode, symbolMode, fullMode
57};
58
59class ConfigList : public QListView {
60 Q_OBJECT
61 typedef class QListView Parent;
62public:
63 ConfigList(ConfigView* p, ConfigMainWindow* cview, ConfigSettings *configSettings);
64 void reinit(void);
65 ConfigView* parent(void) const
66 {
67 return (ConfigView*)Parent::parent();
68 }
69
70protected:
71 ConfigMainWindow* cview;
72
73 void keyPressEvent(QKeyEvent *e);
74 void contentsMousePressEvent(QMouseEvent *e);
75 void contentsMouseReleaseEvent(QMouseEvent *e);
76 void contentsMouseMoveEvent(QMouseEvent *e);
77 void contentsMouseDoubleClickEvent(QMouseEvent *e);
78 void focusInEvent(QFocusEvent *e);
79public slots:
80 void setRootMenu(struct menu *menu);
81
82 void updateList(ConfigItem *item);
83 void setValue(ConfigItem* item, tristate val);
84 void changeValue(ConfigItem* item);
85 void updateSelection(void);
86signals:
87 void menuSelected(struct menu *menu);
88 void parentSelected(void);
89 void gotFocus(void);
90
91public:
92 void updateListAll(void)
93 {
94 updateAll = true;
95 updateList(NULL);
96 updateAll = false;
97 }
98 ConfigList* listView()
99 {
100 return this;
101 }
102 ConfigItem* firstChild() const
103 {
104 return (ConfigItem *)Parent::firstChild();
105 }
106 int mapIdx(colIdx idx)
107 {
108 return colMap[idx];
109 }
110 void addColumn(colIdx idx, const QString& label)
111 {
112 colMap[idx] = Parent::addColumn(label);
113 colRevMap[colMap[idx]] = idx;
114 }
115 void removeColumn(colIdx idx)
116 {
117 int col = colMap[idx];
118 if (col >= 0) {
119 Parent::removeColumn(col);
120 colRevMap[col] = colMap[idx] = -1;
121 }
122 }
123 void setAllOpen(bool open);
124 void setParentMenu(void);
125
126 template <class P>
127 void updateMenuList(P*, struct menu*);
128
129 bool updateAll;
130
131 QPixmap symbolYesPix, symbolModPix, symbolNoPix;
132 QPixmap choiceYesPix, choiceNoPix;
133 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
134
135 bool showAll, showName, showRange, showData;
136 enum listMode mode;
137 struct menu *rootEntry;
138 QColorGroup disabledColorGroup;
139 QColorGroup inactivedColorGroup;
140
141private:
142 int colMap[colNr];
143 int colRevMap[colNr];
144};
145
146class ConfigItem : public QListViewItem {
147 typedef class QListViewItem Parent;
148public:
149 ConfigItem(QListView *parent, ConfigItem *after, struct menu *m, bool v)
150 : Parent(parent, after), menu(m), visible(v), goParent(false)
151 {
152 init();
153 }
154 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
155 : Parent(parent, after), menu(m), visible(v), goParent(false)
156 {
157 init();
158 }
159 ConfigItem(QListView *parent, ConfigItem *after, bool v)
160 : Parent(parent, after), menu(0), visible(v), goParent(true)
161 {
162 init();
163 }
164 ~ConfigItem(void);
165 void init(void);
166#if QT_VERSION >= 300
167 void okRename(int col);
168#endif
169 void updateMenu(void);
170 void testUpdateMenu(bool v);
171 ConfigList* listView() const
172 {
173 return (ConfigList*)Parent::listView();
174 }
175 ConfigItem* firstChild() const
176 {
177 return (ConfigItem *)Parent::firstChild();
178 }
179 ConfigItem* nextSibling() const
180 {
181 return (ConfigItem *)Parent::nextSibling();
182 }
183 void setText(colIdx idx, const QString& text)
184 {
185 Parent::setText(listView()->mapIdx(idx), text);
186 }
187 QString text(colIdx idx) const
188 {
189 return Parent::text(listView()->mapIdx(idx));
190 }
191 void setPixmap(colIdx idx, const QPixmap& pm)
192 {
193 Parent::setPixmap(listView()->mapIdx(idx), pm);
194 }
195 const QPixmap* pixmap(colIdx idx) const
196 {
197 return Parent::pixmap(listView()->mapIdx(idx));
198 }
199 void paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align);
200
201 ConfigItem* nextItem;
202 struct menu *menu;
203 bool visible;
204 bool goParent;
205};
206
207class ConfigLineEdit : public QLineEdit {
208 Q_OBJECT
209 typedef class QLineEdit Parent;
210public:
211 ConfigLineEdit(ConfigView* parent)
212 : Parent(parent)
213 { }
214 ConfigView* parent(void) const
215 {
216 return (ConfigView*)Parent::parent();
217 }
218 void show(ConfigItem *i);
219 void keyPressEvent(QKeyEvent *e);
220
221public:
222 ConfigItem *item;
223};
224
225class ConfigMainWindow : public QMainWindow {
226 Q_OBJECT
227public:
228 ConfigMainWindow(void);
229public slots:
230 void setHelp(QListViewItem* item);
231 void changeMenu(struct menu *);
232 void listFocusChanged(void);
233 void goBack(void);
234 void loadConfig(void);
235 void saveConfig(void);
236 void saveConfigAs(void);
237 void showSingleView(void);
238 void showSplitView(void);
239 void showFullView(void);
240 void setShowAll(bool);
241 void setShowDebug(bool);
242 void setShowRange(bool);
243 void setShowName(bool);
244 void setShowData(bool);
245 void showIntro(void);
246 void showAbout(void);
247 void saveSettings(void);
248
249protected:
250 void closeEvent(QCloseEvent *e);
251
252 ConfigView *menuView;
253 ConfigList *menuList;
254 ConfigView *configView;
255 ConfigList *configList;
256 QTextView *helpText;
257 QToolBar *toolBar;
258 QAction *backAction;
259 QSplitter* split1;
260 QSplitter* split2;
261
262 bool showDebug;
263};