1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 4 */ 5 6 #include <QCheckBox> 7 #include <QDialog> 8 #include <QHeaderView> 9 #include <QLineEdit> 10 #include <QMainWindow> 11 #include <QPushButton> 12 #include <QSettings> 13 #include <QSplitter> 14 #include <QTextBrowser> 15 #include <QTreeWidget> 16 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 ConfigItem* findConfigItem(struct menu *); 49 ConfigView* parent(void) const 50 { 51 return (ConfigView*)Parent::parent(); 52 } 53 void setSelected(QTreeWidgetItem *item, bool enable) { 54 for (int i = 0; i < selectedItems().size(); i++) 55 selectedItems().at(i)->setSelected(false); 56 57 item->setSelected(enable); 58 } 59 60 protected: 61 void keyPressEvent(QKeyEvent *e); 62 void mousePressEvent(QMouseEvent *e); 63 void mouseReleaseEvent(QMouseEvent *e); 64 void mouseMoveEvent(QMouseEvent *e); 65 void mouseDoubleClickEvent(QMouseEvent *e); 66 void focusInEvent(QFocusEvent *e); 67 void contextMenuEvent(QContextMenuEvent *e); 68 69 public slots: 70 void setRootMenu(struct menu *menu); 71 72 void updateList(); 73 void setValue(ConfigItem* item, tristate val); 74 void changeValue(ConfigItem* item); 75 void updateSelection(void); 76 void saveSettings(void); 77 signals: 78 void menuChanged(struct menu *menu); 79 void menuSelected(struct menu *menu); 80 void itemSelected(struct menu *menu); 81 void parentSelected(void); 82 void gotFocus(struct menu *); 83 84 public: 85 void updateListAll(void) 86 { 87 updateAll = true; 88 updateList(); 89 updateAll = false; 90 } 91 void setAllOpen(bool open); 92 void setParentMenu(void); 93 94 bool menuSkip(struct menu *); 95 96 void updateMenuList(ConfigItem *parent, struct menu*); 97 void updateMenuList(struct menu *menu); 98 99 bool updateAll; 100 101 bool showName, showRange, showData; 102 enum listMode mode; 103 enum optionMode optMode; 104 struct menu *rootEntry; 105 QPalette disabledColorGroup; 106 QPalette inactivedColorGroup; 107 QMenu* headerPopup; 108 }; 109 110 class ConfigItem : public QTreeWidgetItem { 111 typedef class QTreeWidgetItem Parent; 112 public: 113 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v) 114 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false) 115 { 116 init(); 117 } 118 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v) 119 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false) 120 { 121 init(); 122 } 123 ConfigItem(ConfigList *parent, ConfigItem *after, bool v) 124 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true) 125 { 126 init(); 127 } 128 ~ConfigItem(void); 129 void init(void); 130 void okRename(int col); 131 void updateMenu(void); 132 void testUpdateMenu(bool v); 133 ConfigList* listView() const 134 { 135 return (ConfigList*)Parent::treeWidget(); 136 } 137 ConfigItem* firstChild() const 138 { 139 return (ConfigItem *)Parent::child(0); 140 } 141 ConfigItem* nextSibling() 142 { 143 ConfigItem *ret = NULL; 144 ConfigItem *_parent = (ConfigItem *)parent(); 145 146 if(_parent) { 147 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1); 148 } else { 149 QTreeWidget *_treeWidget = treeWidget(); 150 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1); 151 } 152 153 return ret; 154 } 155 // TODO: Implement paintCell 156 157 ConfigItem* nextItem; 158 struct menu *menu; 159 bool visible; 160 bool goParent; 161 162 static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon; 163 static QIcon choiceYesIcon, choiceNoIcon; 164 static QIcon menuIcon, menubackIcon; 165 }; 166 167 class ConfigLineEdit : public QLineEdit { 168 Q_OBJECT 169 typedef class QLineEdit Parent; 170 public: 171 ConfigLineEdit(ConfigView* parent); 172 ConfigView* parent(void) const 173 { 174 return (ConfigView*)Parent::parent(); 175 } 176 void show(ConfigItem *i); 177 void keyPressEvent(QKeyEvent *e); 178 179 public: 180 ConfigItem *item; 181 }; 182 183 class ConfigView : public QWidget { 184 Q_OBJECT 185 typedef class QWidget Parent; 186 public: 187 ConfigView(QWidget* parent, const char *name = 0); 188 ~ConfigView(void); 189 static void updateList(); 190 static void updateListAll(void); 191 192 bool showName(void) const { return list->showName; } 193 bool showRange(void) const { return list->showRange; } 194 bool showData(void) const { return list->showData; } 195 public slots: 196 void setShowName(bool); 197 void setShowRange(bool); 198 void setShowData(bool); 199 void setOptionMode(QAction *); 200 signals: 201 void showNameChanged(bool); 202 void showRangeChanged(bool); 203 void showDataChanged(bool); 204 public: 205 ConfigList* list; 206 ConfigLineEdit* lineEdit; 207 208 static ConfigView* viewList; 209 ConfigView* nextView; 210 211 static QAction *showNormalAction; 212 static QAction *showAllAction; 213 static QAction *showPromptAction; 214 }; 215 216 class ConfigInfoView : public QTextBrowser { 217 Q_OBJECT 218 typedef class QTextBrowser Parent; 219 public: 220 ConfigInfoView(QWidget* parent, const char *name = 0); 221 bool showDebug(void) const { return _showDebug; } 222 223 public slots: 224 void setInfo(struct menu *menu); 225 void saveSettings(void); 226 void setShowDebug(bool); 227 void clicked (const QUrl &url); 228 229 signals: 230 void showDebugChanged(bool); 231 void menuSelected(struct menu *); 232 233 protected: 234 void symbolInfo(void); 235 void menuInfo(void); 236 QString debug_info(struct symbol *sym); 237 static QString print_filter(const QString &str); 238 static void expr_print_help(void *data, struct symbol *sym, const char *str); 239 QMenu *createStandardContextMenu(const QPoint & pos); 240 void contextMenuEvent(QContextMenuEvent *e); 241 242 struct symbol *sym; 243 struct menu *_menu; 244 bool _showDebug; 245 }; 246 247 class ConfigSearchWindow : public QDialog { 248 Q_OBJECT 249 typedef class QDialog Parent; 250 public: 251 ConfigSearchWindow(ConfigMainWindow *parent); 252 253 public slots: 254 void saveSettings(void); 255 void search(void); 256 257 protected: 258 QLineEdit* editField; 259 QPushButton* searchButton; 260 QSplitter* split; 261 ConfigView* list; 262 ConfigInfoView* info; 263 264 struct symbol **result; 265 }; 266 267 class ConfigMainWindow : public QMainWindow { 268 Q_OBJECT 269 270 char *configname; 271 static QAction *saveAction; 272 static void conf_changed(void); 273 public: 274 ConfigMainWindow(void); 275 public slots: 276 void changeMenu(struct menu *); 277 void changeItens(struct menu *); 278 void setMenuLink(struct menu *); 279 void listFocusChanged(void); 280 void goBack(void); 281 void loadConfig(void); 282 bool saveConfig(void); 283 void saveConfigAs(void); 284 void searchConfig(void); 285 void showSingleView(void); 286 void showSplitView(void); 287 void showFullView(void); 288 void showIntro(void); 289 void showAbout(void); 290 void saveSettings(void); 291 292 protected: 293 void closeEvent(QCloseEvent *e); 294 295 ConfigSearchWindow *searchWindow; 296 ConfigView *menuView; 297 ConfigList *menuList; 298 ConfigView *configView; 299 ConfigList *configList; 300 ConfigInfoView *helpText; 301 QAction *backAction; 302 QAction *singleViewAction; 303 QAction *splitViewAction; 304 QAction *fullViewAction; 305 QSplitter *split1; 306 QSplitter *split2; 307 }; 308