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