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(ConfigItem *item); 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(NULL); 89 updateAll = false; 90 } 91 ConfigList* listView() 92 { 93 return this; 94 } 95 void addColumn(colIdx idx) 96 { 97 showColumn(idx); 98 } 99 void removeColumn(colIdx idx) 100 { 101 hideColumn(idx); 102 } 103 void setAllOpen(bool open); 104 void setParentMenu(void); 105 106 bool menuSkip(struct menu *); 107 108 void updateMenuList(ConfigItem *parent, struct menu*); 109 void updateMenuList(ConfigList *parent, struct menu*); 110 111 bool updateAll; 112 113 QPixmap symbolYesPix, symbolModPix, symbolNoPix; 114 QPixmap choiceYesPix, choiceNoPix; 115 QPixmap menuPix, menuInvPix, menuBackPix, voidPix; 116 117 bool showName, showRange, showData; 118 enum listMode mode; 119 enum optionMode optMode; 120 struct menu *rootEntry; 121 QPalette disabledColorGroup; 122 QPalette inactivedColorGroup; 123 QMenu* headerPopup; 124 }; 125 126 class ConfigItem : public QTreeWidgetItem { 127 typedef class QTreeWidgetItem Parent; 128 public: 129 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v) 130 : Parent(parent, after), nextItem(0), 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), nextItem(0), menu(m), visible(v), goParent(false) 136 { 137 init(); 138 } 139 ConfigItem(ConfigList *parent, ConfigItem *after, bool v) 140 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true) 141 { 142 init(); 143 } 144 ~ConfigItem(void); 145 void init(void); 146 void okRename(int col); 147 void updateMenu(void); 148 void testUpdateMenu(bool v); 149 ConfigList* listView() const 150 { 151 return (ConfigList*)Parent::treeWidget(); 152 } 153 ConfigItem* firstChild() const 154 { 155 return (ConfigItem *)Parent::child(0); 156 } 157 ConfigItem* nextSibling() 158 { 159 ConfigItem *ret = NULL; 160 ConfigItem *_parent = (ConfigItem *)parent(); 161 162 if(_parent) { 163 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1); 164 } else { 165 QTreeWidget *_treeWidget = treeWidget(); 166 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1); 167 } 168 169 return ret; 170 } 171 void setText(colIdx idx, const QString& text) 172 { 173 Parent::setText(idx, text); 174 } 175 QString text(colIdx idx) const 176 { 177 return Parent::text(idx); 178 } 179 void setPixmap(colIdx idx, const QIcon &icon) 180 { 181 Parent::setIcon(idx, icon); 182 } 183 const QIcon pixmap(colIdx idx) const 184 { 185 return icon(idx); 186 } 187 // TODO: Implement paintCell 188 189 ConfigItem* nextItem; 190 struct menu *menu; 191 bool visible; 192 bool goParent; 193 }; 194 195 class ConfigLineEdit : public QLineEdit { 196 Q_OBJECT 197 typedef class QLineEdit Parent; 198 public: 199 ConfigLineEdit(ConfigView* parent); 200 ConfigView* parent(void) const 201 { 202 return (ConfigView*)Parent::parent(); 203 } 204 void show(ConfigItem *i); 205 void keyPressEvent(QKeyEvent *e); 206 207 public: 208 ConfigItem *item; 209 }; 210 211 class ConfigView : public QWidget { 212 Q_OBJECT 213 typedef class QWidget Parent; 214 public: 215 ConfigView(QWidget* parent, const char *name = 0); 216 ~ConfigView(void); 217 static void updateList(ConfigItem* item); 218 static void updateListAll(void); 219 220 bool showName(void) const { return list->showName; } 221 bool showRange(void) const { return list->showRange; } 222 bool showData(void) const { return list->showData; } 223 public slots: 224 void setShowName(bool); 225 void setShowRange(bool); 226 void setShowData(bool); 227 void setOptionMode(QAction *); 228 signals: 229 void showNameChanged(bool); 230 void showRangeChanged(bool); 231 void showDataChanged(bool); 232 public: 233 ConfigList* list; 234 ConfigLineEdit* lineEdit; 235 236 static ConfigView* viewList; 237 ConfigView* nextView; 238 239 static QAction *showNormalAction; 240 static QAction *showAllAction; 241 static QAction *showPromptAction; 242 }; 243 244 class ConfigInfoView : public QTextBrowser { 245 Q_OBJECT 246 typedef class QTextBrowser Parent; 247 public: 248 ConfigInfoView(QWidget* parent, const char *name = 0); 249 bool showDebug(void) const { return _showDebug; } 250 251 public slots: 252 void setInfo(struct menu *menu); 253 void saveSettings(void); 254 void setShowDebug(bool); 255 void clicked (const QUrl &url); 256 257 signals: 258 void showDebugChanged(bool); 259 void menuSelected(struct menu *); 260 261 protected: 262 void symbolInfo(void); 263 void menuInfo(void); 264 QString debug_info(struct symbol *sym); 265 static QString print_filter(const QString &str); 266 static void expr_print_help(void *data, struct symbol *sym, const char *str); 267 QMenu *createStandardContextMenu(const QPoint & pos); 268 void contextMenuEvent(QContextMenuEvent *e); 269 270 struct symbol *sym; 271 struct menu *_menu; 272 bool _showDebug; 273 }; 274 275 class ConfigSearchWindow : public QDialog { 276 Q_OBJECT 277 typedef class QDialog Parent; 278 public: 279 ConfigSearchWindow(ConfigMainWindow* parent, const char *name = 0); 280 281 public slots: 282 void saveSettings(void); 283 void search(void); 284 285 protected: 286 QLineEdit* editField; 287 QPushButton* searchButton; 288 QSplitter* split; 289 ConfigView* list; 290 ConfigInfoView* info; 291 292 struct symbol **result; 293 }; 294 295 class ConfigMainWindow : public QMainWindow { 296 Q_OBJECT 297 298 char *configname; 299 static QAction *saveAction; 300 static void conf_changed(void); 301 public: 302 ConfigMainWindow(void); 303 public slots: 304 void changeMenu(struct menu *); 305 void changeItens(struct menu *); 306 void setMenuLink(struct menu *); 307 void listFocusChanged(void); 308 void goBack(void); 309 void loadConfig(void); 310 bool saveConfig(void); 311 void saveConfigAs(void); 312 void searchConfig(void); 313 void showSingleView(void); 314 void showSplitView(void); 315 void showFullView(void); 316 void showIntro(void); 317 void showAbout(void); 318 void saveSettings(void); 319 320 protected: 321 void closeEvent(QCloseEvent *e); 322 323 ConfigSearchWindow *searchWindow; 324 ConfigView *menuView; 325 ConfigList *menuList; 326 ConfigView *configView; 327 ConfigList *configList; 328 ConfigInfoView *helpText; 329 QToolBar *toolBar; 330 QAction *backAction; 331 QAction *singleViewAction; 332 QAction *splitViewAction; 333 QAction *fullViewAction; 334 QSplitter *split1; 335 QSplitter *split2; 336 }; 337