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