1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 4 */ 5 6 #include <QTextBrowser> 7 #include <QTreeWidget> 8 #include <QMainWindow> 9 #include <QHeaderView> 10 #include <qsettings.h> 11 #include <QPushButton> 12 #include <QSettings> 13 #include <QLineEdit> 14 #include <QSplitter> 15 #include <QCheckBox> 16 #include <QDialog> 17 #include "expr.h" 18 19 class ConfigView; 20 class ConfigList; 21 class ConfigItem; 22 class ConfigLineEdit; 23 class ConfigMainWindow; 24 25 class ConfigSettings : public QSettings { 26 public: 27 ConfigSettings(); 28 QList<int> readSizes(const QString& key, bool *ok); 29 bool writeSizes(const QString& key, const QList<int>& value); 30 }; 31 32 enum colIdx { 33 promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx, colNr 34 }; 35 enum listMode { 36 singleMode, menuMode, symbolMode, fullMode, listMode 37 }; 38 enum optionMode { 39 normalOpt = 0, allOpt, promptOpt 40 }; 41 42 class ConfigList : public QTreeWidget { 43 Q_OBJECT 44 typedef class QTreeWidget Parent; 45 public: 46 ConfigList(ConfigView* p, const char *name = 0); 47 void reinit(void); 48 ConfigView* parent(void) const 49 { 50 return (ConfigView*)Parent::parent(); 51 } 52 ConfigItem* findConfigItem(struct menu *); 53 54 protected: 55 void keyPressEvent(QKeyEvent *e); 56 void mousePressEvent(QMouseEvent *e); 57 void mouseReleaseEvent(QMouseEvent *e); 58 void mouseMoveEvent(QMouseEvent *e); 59 void mouseDoubleClickEvent(QMouseEvent *e); 60 void focusInEvent(QFocusEvent *e); 61 void contextMenuEvent(QContextMenuEvent *e); 62 63 public slots: 64 void setRootMenu(struct menu *menu); 65 66 void updateList(ConfigItem *item); 67 void setValue(ConfigItem* item, tristate val); 68 void changeValue(ConfigItem* item); 69 void updateSelection(void); 70 void saveSettings(void); 71 signals: 72 void menuChanged(struct menu *menu); 73 void menuSelected(struct menu *menu); 74 void itemSelected(struct menu *menu); 75 void parentSelected(void); 76 void gotFocus(struct menu *); 77 78 public: 79 void updateListAll(void) 80 { 81 updateAll = true; 82 updateList(NULL); 83 updateAll = false; 84 } 85 ConfigList* listView() 86 { 87 return this; 88 } 89 ConfigItem* firstChild() const 90 { 91 return (ConfigItem *)children().first(); 92 } 93 void addColumn(colIdx idx) 94 { 95 showColumn(idx); 96 } 97 void removeColumn(colIdx idx) 98 { 99 hideColumn(idx); 100 } 101 void setAllOpen(bool open); 102 void setParentMenu(void); 103 104 bool menuSkip(struct menu *); 105 106 void updateMenuList(ConfigItem *parent, struct menu*); 107 void updateMenuList(ConfigList *parent, struct menu*); 108 109 bool updateAll; 110 111 QPixmap symbolYesPix, symbolModPix, symbolNoPix; 112 QPixmap choiceYesPix, choiceNoPix; 113 QPixmap menuPix, menuInvPix, menuBackPix, voidPix; 114 115 bool showName, showRange, showData; 116 enum listMode mode; 117 enum optionMode optMode; 118 struct menu *rootEntry; 119 QPalette disabledColorGroup; 120 QPalette inactivedColorGroup; 121 QMenu* headerPopup; 122 }; 123 124 class ConfigItem : public QTreeWidgetItem { 125 typedef class QTreeWidgetItem Parent; 126 public: 127 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v) 128 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false) 129 { 130 init(); 131 } 132 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v) 133 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false) 134 { 135 init(); 136 } 137 ConfigItem(ConfigList *parent, ConfigItem *after, bool v) 138 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true) 139 { 140 init(); 141 } 142 ~ConfigItem(void); 143 void init(void); 144 void okRename(int col); 145 void updateMenu(void); 146 void testUpdateMenu(bool v); 147 ConfigList* listView() const 148 { 149 return (ConfigList*)Parent::treeWidget(); 150 } 151 ConfigItem* firstChild() const 152 { 153 return (ConfigItem *)Parent::child(0); 154 } 155 ConfigItem* nextSibling() 156 { 157 ConfigItem *ret = NULL; 158 ConfigItem *_parent = (ConfigItem *)parent(); 159 160 if(_parent) { 161 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1); 162 } else { 163 QTreeWidget *_treeWidget = treeWidget(); 164 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1); 165 } 166 167 return ret; 168 } 169 void setText(colIdx idx, const QString& text) 170 { 171 Parent::setText(idx, text); 172 } 173 QString text(colIdx idx) const 174 { 175 return Parent::text(idx); 176 } 177 void setPixmap(colIdx idx, const QIcon &icon) 178 { 179 Parent::setIcon(idx, icon); 180 } 181 const QIcon pixmap(colIdx idx) const 182 { 183 return icon(idx); 184 } 185 // TODO: Implement paintCell 186 187 ConfigItem* nextItem; 188 struct menu *menu; 189 bool visible; 190 bool goParent; 191 }; 192 193 class ConfigLineEdit : public QLineEdit { 194 Q_OBJECT 195 typedef class QLineEdit Parent; 196 public: 197 ConfigLineEdit(ConfigView* parent); 198 ConfigView* parent(void) const 199 { 200 return (ConfigView*)Parent::parent(); 201 } 202 void show(ConfigItem *i); 203 void keyPressEvent(QKeyEvent *e); 204 205 public: 206 ConfigItem *item; 207 }; 208 209 class ConfigView : public QWidget { 210 Q_OBJECT 211 typedef class QWidget Parent; 212 public: 213 ConfigView(QWidget* parent, const char *name = 0); 214 ~ConfigView(void); 215 static void updateList(ConfigItem* item); 216 static void updateListAll(void); 217 218 bool showName(void) const { return list->showName; } 219 bool showRange(void) const { return list->showRange; } 220 bool showData(void) const { return list->showData; } 221 public slots: 222 void setShowName(bool); 223 void setShowRange(bool); 224 void setShowData(bool); 225 void setOptionMode(QAction *); 226 signals: 227 void showNameChanged(bool); 228 void showRangeChanged(bool); 229 void showDataChanged(bool); 230 public: 231 ConfigList* list; 232 ConfigLineEdit* lineEdit; 233 234 static ConfigView* viewList; 235 ConfigView* nextView; 236 237 static QAction *showNormalAction; 238 static QAction *showAllAction; 239 static QAction *showPromptAction; 240 }; 241 242 class ConfigInfoView : public QTextBrowser { 243 Q_OBJECT 244 typedef class QTextBrowser Parent; 245 public: 246 ConfigInfoView(QWidget* parent, const char *name = 0); 247 bool showDebug(void) const { return _showDebug; } 248 249 public slots: 250 void setInfo(struct menu *menu); 251 void saveSettings(void); 252 void setShowDebug(bool); 253 254 signals: 255 void showDebugChanged(bool); 256 void menuSelected(struct menu *); 257 258 protected: 259 void symbolInfo(void); 260 void menuInfo(void); 261 QString debug_info(struct symbol *sym); 262 static QString print_filter(const QString &str); 263 static void expr_print_help(void *data, struct symbol *sym, const char *str); 264 QMenu *createStandardContextMenu(const QPoint & pos); 265 void contextMenuEvent(QContextMenuEvent *e); 266 267 struct symbol *sym; 268 struct menu *_menu; 269 bool _showDebug; 270 }; 271 272 class ConfigSearchWindow : public QDialog { 273 Q_OBJECT 274 typedef class QDialog Parent; 275 public: 276 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0); 277 278 public slots: 279 void saveSettings(void); 280 void search(void); 281 282 protected: 283 QLineEdit* editField; 284 QPushButton* searchButton; 285 QSplitter* split; 286 ConfigView* list; 287 ConfigInfoView* info; 288 289 struct symbol **result; 290 }; 291 292 class ConfigMainWindow : public QMainWindow { 293 Q_OBJECT 294 295 char *configname; 296 static QAction *saveAction; 297 static void conf_changed(void); 298 public: 299 ConfigMainWindow(void); 300 public slots: 301 void changeMenu(struct menu *); 302 void changeItens(struct menu *); 303 void setMenuLink(struct menu *); 304 void listFocusChanged(void); 305 void goBack(void); 306 void loadConfig(void); 307 bool saveConfig(void); 308 void saveConfigAs(void); 309 void searchConfig(void); 310 void showSingleView(void); 311 void showSplitView(void); 312 void showFullView(void); 313 void showIntro(void); 314 void showAbout(void); 315 void saveSettings(void); 316 317 protected: 318 void closeEvent(QCloseEvent *e); 319 320 ConfigSearchWindow *searchWindow; 321 ConfigView *menuView; 322 ConfigList *menuList; 323 ConfigView *configView; 324 ConfigList *configList; 325 ConfigInfoView *helpText; 326 QToolBar *toolBar; 327 QAction *backAction; 328 QAction *singleViewAction; 329 QAction *splitViewAction; 330 QAction *fullViewAction; 331 QSplitter *split1; 332 QSplitter *split2; 333 }; 334