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