2018-12-18 15:13:35 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
|
|
|
|
*/
|
|
|
|
|
2020-06-30 09:26:35 +03:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QDialog>
|
2015-09-22 21:36:15 +03:00
|
|
|
#include <QHeaderView>
|
2020-06-30 09:26:35 +03:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QMainWindow>
|
2015-09-22 21:36:15 +03:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QSplitter>
|
kconfig: qconf: allow to edit "int", "hex", "string" menus in-place
Previously, when you double-clicked the "int", "hex", or "string" menus,
a line-edit gadget showed up to allow you to input the value, which
looked clumsy.
Also, it was buggy; the editor opened even if the config option was not
editable. For example, just try to double-click CC_VERSION_TEXT, which
has no prompt.
This commit sub-classes QStyleItemDelegate to allow users to edit
"int", "hex", "string" menus in-place. Just double-click (or press
the F2 key) in the data column. Then, an editor widget is placed on
top of the item view.
The two methods are overridden:
createEditor - process only when the data column is being accessed
and the menu is visible. Otherwise, return nullptr to disallow editing.
setModelData - take the new data from the editor, and set it to the
addressed symbol. If it was successful, update all the list windows.
Otherwise, (the reason for the failure is possibly the input data was
out of range), set the old value back to the editor.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2020-08-29 11:14:12 +03:00
|
|
|
#include <QStyledItemDelegate>
|
2020-06-30 09:26:35 +03:00
|
|
|
#include <QTextBrowser>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
|
2015-09-22 21:36:15 +03:00
|
|
|
#include "expr.h"
|
2010-08-31 19:34:37 +04:00
|
|
|
|
2015-09-22 21:36:17 +03:00
|
|
|
class ConfigList;
|
|
|
|
class ConfigItem;
|
2005-04-17 02:20:36 +04:00
|
|
|
class ConfigMainWindow;
|
|
|
|
|
|
|
|
class ConfigSettings : public QSettings {
|
|
|
|
public:
|
2013-10-06 22:21:31 +04:00
|
|
|
ConfigSettings();
|
2015-09-22 21:36:05 +03:00
|
|
|
QList<int> readSizes(const QString& key, bool *ok);
|
|
|
|
bool writeSizes(const QString& key, const QList<int>& value);
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum colIdx {
|
2020-08-17 19:36:31 +03:00
|
|
|
promptColIdx, nameColIdx, noColIdx, modColIdx, yesColIdx, dataColIdx
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
enum listMode {
|
2006-06-09 09:12:45 +04:00
|
|
|
singleMode, menuMode, symbolMode, fullMode, listMode
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
2010-05-10 12:33:41 +04:00
|
|
|
enum optionMode {
|
|
|
|
normalOpt = 0, allOpt, promptOpt
|
|
|
|
};
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2015-09-22 21:36:17 +03:00
|
|
|
class ConfigList : public QTreeWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
typedef class QTreeWidget Parent;
|
|
|
|
public:
|
2020-08-29 11:14:15 +03:00
|
|
|
ConfigList(QWidget *parent, const char *name = 0);
|
2020-08-29 11:14:10 +03:00
|
|
|
~ConfigList();
|
2015-09-22 21:36:18 +03:00
|
|
|
void reinit(void);
|
2020-06-30 09:26:38 +03:00
|
|
|
ConfigItem* findConfigItem(struct menu *);
|
|
|
|
void setSelected(QTreeWidgetItem *item, bool enable) {
|
|
|
|
for (int i = 0; i < selectedItems().size(); i++)
|
|
|
|
selectedItems().at(i)->setSelected(false);
|
|
|
|
|
|
|
|
item->setSelected(enable);
|
|
|
|
}
|
2015-09-22 21:36:18 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void keyPressEvent(QKeyEvent *e);
|
2015-09-22 21:36:19 +03:00
|
|
|
void mousePressEvent(QMouseEvent *e);
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e);
|
|
|
|
void mouseMoveEvent(QMouseEvent *e);
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *e);
|
2015-09-22 21:36:18 +03:00
|
|
|
void focusInEvent(QFocusEvent *e);
|
|
|
|
void contextMenuEvent(QContextMenuEvent *e);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setRootMenu(struct menu *menu);
|
|
|
|
|
2020-08-07 12:18:59 +03:00
|
|
|
void updateList();
|
2015-09-22 21:36:18 +03:00
|
|
|
void setValue(ConfigItem* item, tristate val);
|
|
|
|
void changeValue(ConfigItem* item);
|
|
|
|
void updateSelection(void);
|
|
|
|
void saveSettings(void);
|
2020-08-07 12:19:09 +03:00
|
|
|
void setOptionMode(QAction *action);
|
2020-08-29 11:14:14 +03:00
|
|
|
void setShowName(bool on);
|
|
|
|
void setShowRange(bool on);
|
2020-08-07 12:19:09 +03:00
|
|
|
|
2015-09-22 21:36:18 +03:00
|
|
|
signals:
|
|
|
|
void menuChanged(struct menu *menu);
|
|
|
|
void menuSelected(struct menu *menu);
|
2020-04-02 12:28:01 +03:00
|
|
|
void itemSelected(struct menu *menu);
|
2015-09-22 21:36:18 +03:00
|
|
|
void parentSelected(void);
|
|
|
|
void gotFocus(struct menu *);
|
2020-08-29 11:14:14 +03:00
|
|
|
void showNameChanged(bool on);
|
|
|
|
void showRangeChanged(bool on);
|
2015-09-22 21:36:18 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
void updateListAll(void)
|
|
|
|
{
|
|
|
|
updateAll = true;
|
2020-08-07 12:18:59 +03:00
|
|
|
updateList();
|
2015-09-22 21:36:18 +03:00
|
|
|
updateAll = false;
|
|
|
|
}
|
|
|
|
void setAllOpen(bool open);
|
|
|
|
void setParentMenu(void);
|
|
|
|
|
|
|
|
bool menuSkip(struct menu *);
|
|
|
|
|
2015-09-22 21:36:27 +03:00
|
|
|
void updateMenuList(ConfigItem *parent, struct menu*);
|
2020-08-07 12:19:01 +03:00
|
|
|
void updateMenuList(struct menu *menu);
|
2015-09-22 21:36:18 +03:00
|
|
|
|
|
|
|
bool updateAll;
|
|
|
|
|
2020-08-29 11:14:11 +03:00
|
|
|
bool showName, showRange;
|
2015-09-22 21:36:18 +03:00
|
|
|
enum listMode mode;
|
|
|
|
enum optionMode optMode;
|
|
|
|
struct menu *rootEntry;
|
|
|
|
QPalette disabledColorGroup;
|
|
|
|
QPalette inactivedColorGroup;
|
|
|
|
QMenu* headerPopup;
|
2020-08-07 12:19:09 +03:00
|
|
|
|
2020-08-29 11:14:10 +03:00
|
|
|
static QList<ConfigList *> allLists;
|
|
|
|
static void updateListForAll();
|
|
|
|
static void updateListAllForAll();
|
|
|
|
|
2020-08-07 12:19:09 +03:00
|
|
|
static QAction *showNormalAction, *showAllAction, *showPromptAction;
|
2015-09-22 21:36:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ConfigItem : public QTreeWidgetItem {
|
|
|
|
typedef class QTreeWidgetItem Parent;
|
|
|
|
public:
|
2015-09-22 21:36:30 +03:00
|
|
|
ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v)
|
2015-09-22 21:36:25 +03:00
|
|
|
: Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
|
2015-09-22 21:36:17 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v)
|
2015-09-22 21:36:25 +03:00
|
|
|
: Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false)
|
2015-09-22 21:36:17 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
2015-09-22 21:36:30 +03:00
|
|
|
ConfigItem(ConfigList *parent, ConfigItem *after, bool v)
|
2015-09-22 21:36:25 +03:00
|
|
|
: Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true)
|
2015-09-22 21:36:17 +03:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
~ConfigItem(void);
|
|
|
|
void init(void);
|
2015-09-22 21:36:18 +03:00
|
|
|
void updateMenu(void);
|
|
|
|
void testUpdateMenu(bool v);
|
|
|
|
ConfigList* listView() const
|
|
|
|
{
|
|
|
|
return (ConfigList*)Parent::treeWidget();
|
|
|
|
}
|
|
|
|
ConfigItem* firstChild() const
|
|
|
|
{
|
|
|
|
return (ConfigItem *)Parent::child(0);
|
|
|
|
}
|
2015-09-22 21:36:19 +03:00
|
|
|
ConfigItem* nextSibling()
|
2015-09-22 21:36:18 +03:00
|
|
|
{
|
2015-09-22 21:36:19 +03:00
|
|
|
ConfigItem *ret = NULL;
|
|
|
|
ConfigItem *_parent = (ConfigItem *)parent();
|
|
|
|
|
|
|
|
if(_parent) {
|
2015-09-22 21:36:32 +03:00
|
|
|
ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1);
|
2015-09-22 21:36:19 +03:00
|
|
|
} else {
|
2015-09-22 21:36:32 +03:00
|
|
|
QTreeWidget *_treeWidget = treeWidget();
|
|
|
|
ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1);
|
2015-09-22 21:36:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-09-22 21:36:18 +03:00
|
|
|
}
|
2015-09-22 21:36:19 +03:00
|
|
|
// TODO: Implement paintCell
|
2015-09-22 21:36:17 +03:00
|
|
|
|
|
|
|
ConfigItem* nextItem;
|
|
|
|
struct menu *menu;
|
|
|
|
bool visible;
|
|
|
|
bool goParent;
|
2020-08-07 12:19:07 +03:00
|
|
|
|
|
|
|
static QIcon symbolYesIcon, symbolModIcon, symbolNoIcon;
|
|
|
|
static QIcon choiceYesIcon, choiceNoIcon;
|
|
|
|
static QIcon menuIcon, menubackIcon;
|
2015-09-22 21:36:17 +03:00
|
|
|
};
|
|
|
|
|
kconfig: qconf: allow to edit "int", "hex", "string" menus in-place
Previously, when you double-clicked the "int", "hex", or "string" menus,
a line-edit gadget showed up to allow you to input the value, which
looked clumsy.
Also, it was buggy; the editor opened even if the config option was not
editable. For example, just try to double-click CC_VERSION_TEXT, which
has no prompt.
This commit sub-classes QStyleItemDelegate to allow users to edit
"int", "hex", "string" menus in-place. Just double-click (or press
the F2 key) in the data column. Then, an editor widget is placed on
top of the item view.
The two methods are overridden:
createEditor - process only when the data column is being accessed
and the menu is visible. Otherwise, return nullptr to disallow editing.
setModelData - take the new data from the editor, and set it to the
addressed symbol. If it was successful, update all the list windows.
Otherwise, (the reason for the failure is possibly the input data was
out of range), set the old value back to the editor.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2020-08-29 11:14:12 +03:00
|
|
|
class ConfigItemDelegate : public QStyledItemDelegate
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
struct menu *menu;
|
|
|
|
public:
|
|
|
|
ConfigItemDelegate(QObject *parent = nullptr)
|
|
|
|
: QStyledItemDelegate(parent) {}
|
|
|
|
QWidget *createEditor(QWidget *parent,
|
|
|
|
const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const override;
|
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
|
|
|
const QModelIndex &index) const override;
|
|
|
|
};
|
|
|
|
|
2015-09-22 21:36:06 +03:00
|
|
|
class ConfigInfoView : public QTextBrowser {
|
2006-06-09 09:12:45 +04:00
|
|
|
Q_OBJECT
|
2015-09-22 21:36:06 +03:00
|
|
|
typedef class QTextBrowser Parent;
|
2020-08-17 19:36:30 +03:00
|
|
|
QMenu *contextMenu;
|
2006-06-09 09:12:45 +04:00
|
|
|
public:
|
|
|
|
ConfigInfoView(QWidget* parent, const char *name = 0);
|
|
|
|
bool showDebug(void) const { return _showDebug; }
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setInfo(struct menu *menu);
|
2006-06-09 09:12:46 +04:00
|
|
|
void saveSettings(void);
|
2006-06-09 09:12:45 +04:00
|
|
|
void setShowDebug(bool);
|
2020-06-30 09:26:37 +03:00
|
|
|
void clicked (const QUrl &url);
|
2006-06-09 09:12:45 +04:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void showDebugChanged(bool);
|
2006-06-09 09:12:47 +04:00
|
|
|
void menuSelected(struct menu *);
|
2006-06-09 09:12:45 +04:00
|
|
|
|
|
|
|
protected:
|
2006-06-09 09:12:47 +04:00
|
|
|
void symbolInfo(void);
|
2006-06-09 09:12:45 +04:00
|
|
|
void menuInfo(void);
|
|
|
|
QString debug_info(struct symbol *sym);
|
|
|
|
static QString print_filter(const QString &str);
|
2006-06-09 09:12:47 +04:00
|
|
|
static void expr_print_help(void *data, struct symbol *sym, const char *str);
|
2020-08-17 19:36:30 +03:00
|
|
|
void contextMenuEvent(QContextMenuEvent *event);
|
2006-06-09 09:12:45 +04:00
|
|
|
|
2006-06-09 09:12:47 +04:00
|
|
|
struct symbol *sym;
|
2010-08-31 19:34:37 +04:00
|
|
|
struct menu *_menu;
|
2006-06-09 09:12:45 +04:00
|
|
|
bool _showDebug;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConfigSearchWindow : public QDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
typedef class QDialog Parent;
|
|
|
|
public:
|
2020-08-07 12:18:57 +03:00
|
|
|
ConfigSearchWindow(ConfigMainWindow *parent);
|
2006-06-09 09:12:46 +04:00
|
|
|
|
2006-06-09 09:12:45 +04:00
|
|
|
public slots:
|
2006-06-09 09:12:46 +04:00
|
|
|
void saveSettings(void);
|
2006-06-09 09:12:45 +04:00
|
|
|
void search(void);
|
2006-06-09 09:12:46 +04:00
|
|
|
|
2006-06-09 09:12:45 +04:00
|
|
|
protected:
|
|
|
|
QLineEdit* editField;
|
|
|
|
QPushButton* searchButton;
|
2006-06-09 09:12:46 +04:00
|
|
|
QSplitter* split;
|
2020-08-29 11:14:15 +03:00
|
|
|
ConfigList *list;
|
2006-06-09 09:12:45 +04:00
|
|
|
ConfigInfoView* info;
|
|
|
|
|
|
|
|
struct symbol **result;
|
|
|
|
};
|
|
|
|
|
2015-09-22 21:36:02 +03:00
|
|
|
class ConfigMainWindow : public QMainWindow {
|
2005-04-17 02:20:36 +04:00
|
|
|
Q_OBJECT
|
2006-12-13 11:34:08 +03:00
|
|
|
|
2019-03-10 19:13:15 +03:00
|
|
|
char *configname;
|
2015-09-22 21:36:03 +03:00
|
|
|
static QAction *saveAction;
|
2006-12-13 11:34:08 +03:00
|
|
|
static void conf_changed(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
public:
|
|
|
|
ConfigMainWindow(void);
|
|
|
|
public slots:
|
|
|
|
void changeMenu(struct menu *);
|
2020-04-02 12:28:01 +03:00
|
|
|
void changeItens(struct menu *);
|
2006-06-09 09:12:47 +04:00
|
|
|
void setMenuLink(struct menu *);
|
2005-04-17 02:20:36 +04:00
|
|
|
void listFocusChanged(void);
|
|
|
|
void goBack(void);
|
|
|
|
void loadConfig(void);
|
2011-05-25 17:10:25 +04:00
|
|
|
bool saveConfig(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
void saveConfigAs(void);
|
2006-06-09 09:12:45 +04:00
|
|
|
void searchConfig(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
void showSingleView(void);
|
|
|
|
void showSplitView(void);
|
|
|
|
void showFullView(void);
|
|
|
|
void showIntro(void);
|
|
|
|
void showAbout(void);
|
|
|
|
void saveSettings(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void closeEvent(QCloseEvent *e);
|
|
|
|
|
2006-06-09 09:12:45 +04:00
|
|
|
ConfigSearchWindow *searchWindow;
|
2015-09-22 21:36:17 +03:00
|
|
|
ConfigList *menuList;
|
|
|
|
ConfigList *configList;
|
2006-06-09 09:12:45 +04:00
|
|
|
ConfigInfoView *helpText;
|
2015-09-22 21:36:03 +03:00
|
|
|
QAction *backAction;
|
2015-09-22 21:36:13 +03:00
|
|
|
QAction *singleViewAction;
|
|
|
|
QAction *splitViewAction;
|
|
|
|
QAction *fullViewAction;
|
2015-09-22 21:36:14 +03:00
|
|
|
QSplitter *split1;
|
|
|
|
QSplitter *split2;
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|