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 <QStyledItemDelegate> 15 #include <QTextBrowser> 16 #include <QTreeWidget> 17 18 #include "expr.h" 19 20 class ConfigList; 21 class ConfigItem; 22 class ConfigMainWindow; 23 24 class ConfigSettings : public QSettings { 25 public: 26 ConfigSettings(); 27 QList<int> readSizes(const QString& key, bool *ok); 28 bool writeSizes(const QString& key, const QList<int>& value); 29 }; 30 31 enum colIdx { 32 promptColIdx, nameColIdx, dataColIdx 33 }; 34 enum listMode { 35 singleMode, menuMode, symbolMode, fullMode, listMode 36 }; 37 enum optionMode { 38 normalOpt = 0, allOpt, promptOpt 39 }; 40 41 class ConfigList : public QTreeWidget { 42 Q_OBJECT 43 typedef class QTreeWidget Parent; 44 public: 45 ConfigList(QWidget *parent, const char *name = 0); 46 ~ConfigList(); 47 void reinit(void); 48 ConfigItem* findConfigItem(struct menu *); setSelected(QTreeWidgetItem * item,bool enable)49 void setSelected(QTreeWidgetItem *item, bool enable) { 50 for (int i = 0; i < selectedItems().size(); i++) 51 selectedItems().at(i)->setSelected(false); 52 53 item->setSelected(enable); 54 } 55 56 protected: 57 void keyPressEvent(QKeyEvent *e); 58 void mouseReleaseEvent(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(); 67 void setValue(ConfigItem* item, tristate val); 68 void changeValue(ConfigItem* item); 69 void updateSelection(void); 70 void saveSettings(void); 71 void setOptionMode(QAction *action); 72 void setShowName(bool on); 73 74 signals: 75 void menuChanged(struct menu *menu); 76 void menuSelected(struct menu *menu); 77 void itemSelected(struct menu *menu); 78 void parentSelected(void); 79 void gotFocus(struct menu *); 80 void showNameChanged(bool on); 81 82 public: updateListAll(void)83 void updateListAll(void) 84 { 85 updateAll = true; 86 updateList(); 87 updateAll = false; 88 } 89 void setAllOpen(bool open); 90 void setParentMenu(void); 91 92 bool menuSkip(struct menu *); 93 94 void updateMenuList(ConfigItem *parent, struct menu*); 95 void updateMenuList(struct menu *menu); 96 97 bool updateAll; 98 99 bool showName; 100 enum listMode mode; 101 enum optionMode optMode; 102 struct menu *rootEntry; 103 QPalette disabledColorGroup; 104 QPalette inactivedColorGroup; 105 QMenu* headerPopup; 106 107 static QList<ConfigList *> allLists; 108 static void updateListForAll(); 109 static void updateListAllForAll(); 110 111 static QAction *showNormalAction, *showAllAction, *showPromptAction; 112 }; 113 114 class ConfigItem : public QTreeWidgetItem { 115 typedef class QTreeWidgetItem Parent; 116 public: ConfigItem(ConfigList * parent,ConfigItem * after,struct menu * m)117 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m) 118 : Parent(parent, after), nextItem(0), menu(m), goParent(false) 119 { 120 init(); 121 } ConfigItem(ConfigItem * parent,ConfigItem * after,struct menu * m)122 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m) 123 : Parent(parent, after), nextItem(0), menu(m), goParent(false) 124 { 125 init(); 126 } ConfigItem(ConfigList * parent,ConfigItem * after)127 ConfigItem(ConfigList *parent, ConfigItem *after) 128 : Parent(parent, after), nextItem(0), menu(0), goParent(true) 129 { 130 init(); 131 } 132 ~ConfigItem(void); 133 void init(void); 134 void updateMenu(void); 135 void testUpdateMenu(void); listView()136 ConfigList* listView() const 137 { 138 return (ConfigList*)Parent::treeWidget(); 139 } firstChild()140 ConfigItem* firstChild() const 141 { 142 return (ConfigItem *)Parent::child(0); 143 } nextSibling()144 ConfigItem* nextSibling() 145 { 146 ConfigItem *ret = NULL; 147 ConfigItem *_parent = (ConfigItem *)parent(); 148 149 if(_parent) { 150 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1); 151 } else { 152 QTreeWidget *_treeWidget = treeWidget(); 153 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1); 154 } 155 156 return ret; 157 } 158 // TODO: Implement paintCell 159 160 ConfigItem* nextItem; 161 struct menu *menu; 162 bool goParent; 163 164 static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon; 165 static QIcon choiceYesIcon, choiceNoIcon; 166 static QIcon menuIcon, menubackIcon; 167 }; 168 169 class ConfigItemDelegate : public QStyledItemDelegate 170 { 171 private: 172 struct menu *menu; 173 public: 174 ConfigItemDelegate(QObject *parent = nullptr) QStyledItemDelegate(parent)175 : QStyledItemDelegate(parent) {} 176 QWidget *createEditor(QWidget *parent, 177 const QStyleOptionViewItem &option, 178 const QModelIndex &index) const override; 179 void setModelData(QWidget *editor, QAbstractItemModel *model, 180 const QModelIndex &index) const override; 181 }; 182 183 class ConfigInfoView : public QTextBrowser { 184 Q_OBJECT 185 typedef class QTextBrowser Parent; 186 QMenu *contextMenu; 187 public: 188 ConfigInfoView(QWidget* parent, const char *name = 0); showDebug(void)189 bool showDebug(void) const { return _showDebug; } 190 191 public slots: 192 void setInfo(struct menu *menu); 193 void saveSettings(void); 194 void setShowDebug(bool); 195 void clicked (const QUrl &url); 196 197 signals: 198 void showDebugChanged(bool); 199 void menuSelected(struct menu *); 200 201 protected: 202 void symbolInfo(void); 203 void menuInfo(void); 204 QString debug_info(struct symbol *sym); 205 static QString print_filter(const QString &str); 206 static void expr_print_help(void *data, struct symbol *sym, const char *str); 207 void contextMenuEvent(QContextMenuEvent *event); 208 209 struct symbol *sym; 210 struct menu *_menu; 211 bool _showDebug; 212 }; 213 214 class ConfigSearchWindow : public QDialog { 215 Q_OBJECT 216 typedef class QDialog Parent; 217 public: 218 ConfigSearchWindow(ConfigMainWindow *parent); 219 220 public slots: 221 void saveSettings(void); 222 void search(void); 223 224 protected: 225 QLineEdit* editField; 226 QPushButton* searchButton; 227 QSplitter* split; 228 ConfigList *list; 229 ConfigInfoView* info; 230 231 struct symbol **result; 232 }; 233 234 class ConfigMainWindow : public QMainWindow { 235 Q_OBJECT 236 237 QString configname; 238 static QAction *saveAction; 239 static void conf_changed(bool); 240 public: 241 ConfigMainWindow(void); 242 public slots: 243 void changeMenu(struct menu *); 244 void changeItens(struct menu *); 245 void setMenuLink(struct menu *); 246 void listFocusChanged(void); 247 void goBack(void); 248 void loadConfig(void); 249 bool saveConfig(void); 250 void saveConfigAs(void); 251 void searchConfig(void); 252 void showSingleView(void); 253 void showSplitView(void); 254 void showFullView(void); 255 void showIntro(void); 256 void showAbout(void); 257 void saveSettings(void); 258 259 protected: 260 void closeEvent(QCloseEvent *e); 261 262 ConfigSearchWindow *searchWindow; 263 ConfigList *menuList; 264 ConfigList *configList; 265 ConfigInfoView *helpText; 266 QAction *backAction; 267 QAction *singleViewAction; 268 QAction *splitViewAction; 269 QAction *fullViewAction; 270 QSplitter *split1; 271 QSplitter *split2; 272 }; 273