0001
0002
0003
0004
0005
0006 #include <QCheckBox>
0007 #include <QDialog>
0008 #include <QHeaderView>
0009 #include <QLineEdit>
0010 #include <QMainWindow>
0011 #include <QPushButton>
0012 #include <QSettings>
0013 #include <QSplitter>
0014 #include <QStyledItemDelegate>
0015 #include <QTextBrowser>
0016 #include <QTreeWidget>
0017
0018 #include "expr.h"
0019
0020 class ConfigList;
0021 class ConfigItem;
0022 class ConfigMainWindow;
0023
0024 class ConfigSettings : public QSettings {
0025 public:
0026 ConfigSettings();
0027 QList<int> readSizes(const QString& key, bool *ok);
0028 bool writeSizes(const QString& key, const QList<int>& value);
0029 };
0030
0031 enum colIdx {
0032 promptColIdx, nameColIdx, dataColIdx
0033 };
0034 enum listMode {
0035 singleMode, menuMode, symbolMode, fullMode, listMode
0036 };
0037 enum optionMode {
0038 normalOpt = 0, allOpt, promptOpt
0039 };
0040
0041 class ConfigList : public QTreeWidget {
0042 Q_OBJECT
0043 typedef class QTreeWidget Parent;
0044 public:
0045 ConfigList(QWidget *parent, const char *name = 0);
0046 ~ConfigList();
0047 void reinit(void);
0048 ConfigItem* findConfigItem(struct menu *);
0049 void setSelected(QTreeWidgetItem *item, bool enable) {
0050 for (int i = 0; i < selectedItems().size(); i++)
0051 selectedItems().at(i)->setSelected(false);
0052
0053 item->setSelected(enable);
0054 }
0055
0056 protected:
0057 void keyPressEvent(QKeyEvent *e);
0058 void mousePressEvent(QMouseEvent *e);
0059 void mouseReleaseEvent(QMouseEvent *e);
0060 void mouseMoveEvent(QMouseEvent *e);
0061 void mouseDoubleClickEvent(QMouseEvent *e);
0062 void focusInEvent(QFocusEvent *e);
0063 void contextMenuEvent(QContextMenuEvent *e);
0064
0065 public slots:
0066 void setRootMenu(struct menu *menu);
0067
0068 void updateList();
0069 void setValue(ConfigItem* item, tristate val);
0070 void changeValue(ConfigItem* item);
0071 void updateSelection(void);
0072 void saveSettings(void);
0073 void setOptionMode(QAction *action);
0074 void setShowName(bool on);
0075
0076 signals:
0077 void menuChanged(struct menu *menu);
0078 void menuSelected(struct menu *menu);
0079 void itemSelected(struct menu *menu);
0080 void parentSelected(void);
0081 void gotFocus(struct menu *);
0082 void showNameChanged(bool on);
0083
0084 public:
0085 void updateListAll(void)
0086 {
0087 updateAll = true;
0088 updateList();
0089 updateAll = false;
0090 }
0091 void setAllOpen(bool open);
0092 void setParentMenu(void);
0093
0094 bool menuSkip(struct menu *);
0095
0096 void updateMenuList(ConfigItem *parent, struct menu*);
0097 void updateMenuList(struct menu *menu);
0098
0099 bool updateAll;
0100
0101 bool showName;
0102 enum listMode mode;
0103 enum optionMode optMode;
0104 struct menu *rootEntry;
0105 QPalette disabledColorGroup;
0106 QPalette inactivedColorGroup;
0107 QMenu* headerPopup;
0108
0109 static QList<ConfigList *> allLists;
0110 static void updateListForAll();
0111 static void updateListAllForAll();
0112
0113 static QAction *showNormalAction, *showAllAction, *showPromptAction;
0114 };
0115
0116 class ConfigItem : public QTreeWidgetItem {
0117 typedef class QTreeWidgetItem Parent;
0118 public:
0119 ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v)
0120 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
0121 {
0122 init();
0123 }
0124 ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
0125 : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
0126 {
0127 init();
0128 }
0129 ConfigItem(ConfigList *parent, ConfigItem *after, bool v)
0130 : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
0131 {
0132 init();
0133 }
0134 ~ConfigItem(void);
0135 void init(void);
0136 void updateMenu(void);
0137 void testUpdateMenu(bool v);
0138 ConfigList* listView() const
0139 {
0140 return (ConfigList*)Parent::treeWidget();
0141 }
0142 ConfigItem* firstChild() const
0143 {
0144 return (ConfigItem *)Parent::child(0);
0145 }
0146 ConfigItem* nextSibling()
0147 {
0148 ConfigItem *ret = NULL;
0149 ConfigItem *_parent = (ConfigItem *)parent();
0150
0151 if(_parent) {
0152 ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
0153 } else {
0154 QTreeWidget *_treeWidget = treeWidget();
0155 ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
0156 }
0157
0158 return ret;
0159 }
0160
0161
0162 ConfigItem* nextItem;
0163 struct menu *menu;
0164 bool visible;
0165 bool goParent;
0166
0167 static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon;
0168 static QIcon choiceYesIcon, choiceNoIcon;
0169 static QIcon menuIcon, menubackIcon;
0170 };
0171
0172 class ConfigItemDelegate : public QStyledItemDelegate
0173 {
0174 private:
0175 struct menu *menu;
0176 public:
0177 ConfigItemDelegate(QObject *parent = nullptr)
0178 : QStyledItemDelegate(parent) {}
0179 QWidget *createEditor(QWidget *parent,
0180 const QStyleOptionViewItem &option,
0181 const QModelIndex &index) const override;
0182 void setModelData(QWidget *editor, QAbstractItemModel *model,
0183 const QModelIndex &index) const override;
0184 };
0185
0186 class ConfigInfoView : public QTextBrowser {
0187 Q_OBJECT
0188 typedef class QTextBrowser Parent;
0189 QMenu *contextMenu;
0190 public:
0191 ConfigInfoView(QWidget* parent, const char *name = 0);
0192 bool showDebug(void) const { return _showDebug; }
0193
0194 public slots:
0195 void setInfo(struct menu *menu);
0196 void saveSettings(void);
0197 void setShowDebug(bool);
0198 void clicked (const QUrl &url);
0199
0200 signals:
0201 void showDebugChanged(bool);
0202 void menuSelected(struct menu *);
0203
0204 protected:
0205 void symbolInfo(void);
0206 void menuInfo(void);
0207 QString debug_info(struct symbol *sym);
0208 static QString print_filter(const QString &str);
0209 static void expr_print_help(void *data, struct symbol *sym, const char *str);
0210 void contextMenuEvent(QContextMenuEvent *event);
0211
0212 struct symbol *sym;
0213 struct menu *_menu;
0214 bool _showDebug;
0215 };
0216
0217 class ConfigSearchWindow : public QDialog {
0218 Q_OBJECT
0219 typedef class QDialog Parent;
0220 public:
0221 ConfigSearchWindow(ConfigMainWindow *parent);
0222
0223 public slots:
0224 void saveSettings(void);
0225 void search(void);
0226
0227 protected:
0228 QLineEdit* editField;
0229 QPushButton* searchButton;
0230 QSplitter* split;
0231 ConfigList *list;
0232 ConfigInfoView* info;
0233
0234 struct symbol **result;
0235 };
0236
0237 class ConfigMainWindow : public QMainWindow {
0238 Q_OBJECT
0239
0240 char *configname;
0241 static QAction *saveAction;
0242 static void conf_changed(void);
0243 public:
0244 ConfigMainWindow(void);
0245 public slots:
0246 void changeMenu(struct menu *);
0247 void changeItens(struct menu *);
0248 void setMenuLink(struct menu *);
0249 void listFocusChanged(void);
0250 void goBack(void);
0251 void loadConfig(void);
0252 bool saveConfig(void);
0253 void saveConfigAs(void);
0254 void searchConfig(void);
0255 void showSingleView(void);
0256 void showSplitView(void);
0257 void showFullView(void);
0258 void showIntro(void);
0259 void showAbout(void);
0260 void saveSettings(void);
0261
0262 protected:
0263 void closeEvent(QCloseEvent *e);
0264
0265 ConfigSearchWindow *searchWindow;
0266 ConfigList *menuList;
0267 ConfigList *configList;
0268 ConfigInfoView *helpText;
0269 QAction *backAction;
0270 QAction *singleViewAction;
0271 QAction *splitViewAction;
0272 QAction *fullViewAction;
0273 QSplitter *split1;
0274 QSplitter *split2;
0275 };