📄 qconf.cc
字号:
/* * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> * Released under the terms of the GNU GPL v2.0. */#include <qapplication.h>#include <qmainwindow.h>#include <qtoolbar.h>#include <qlayout.h>#include <qvbox.h>#include <qsplitter.h>#include <qlistview.h>#include <qtextbrowser.h>#include <qlineedit.h>#include <qlabel.h>#include <qpushbutton.h>#include <qmenubar.h>#include <qmessagebox.h>#include <qaction.h>#include <qheader.h>#include <qfiledialog.h>#include <qdragobject.h>#include <qregexp.h>#include <stdlib.h>#include "lkc.h"#include "qconf.h"#include "qconf.moc"#include "images.c"#ifdef _# undef _# define _ qgettext#endifstatic QApplication *configApp;static ConfigSettings *configSettings;QAction *ConfigMainWindow::saveAction;static inline QString qgettext(const char* str){ return QString::fromLocal8Bit(gettext(str));}static inline QString qgettext(const QString& str){ return QString::fromLocal8Bit(gettext(str.latin1()));}/** * Reads a list of integer values from the application settings. */QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok){ QValueList<int> result; QStringList entryList = readListEntry(key, ok); if (ok) { QStringList::Iterator it; for (it = entryList.begin(); it != entryList.end(); ++it) result.push_back((*it).toInt()); } return result;}/** * Writes a list of integer values to the application settings. */bool ConfigSettings::writeSizes(const QString& key, const QValueList<int>& value){ QStringList stringList; QValueList<int>::ConstIterator it; for (it = value.begin(); it != value.end(); ++it) stringList.push_back(QString::number(*it)); return writeEntry(key, stringList);}#if QT_VERSION >= 300/* * set the new data * TODO check the value */void ConfigItem::okRename(int col){ Parent::okRename(col); sym_set_string_value(menu->sym, text(dataColIdx).latin1()); listView()->updateList(this);}#endif/* * update the displayed of a menu entry */void ConfigItem::updateMenu(void){ ConfigList* list; struct symbol* sym; struct property *prop; QString prompt; int type; tristate expr; list = listView(); if (goParent) { setPixmap(promptColIdx, list->menuBackPix); prompt = ".."; goto set_prompt; } sym = menu->sym; prop = menu->prompt; prompt = QString::fromLocal8Bit(menu_get_prompt(menu)); if (prop) switch (prop->type) { case P_MENU: if (list->mode == singleMode || list->mode == symbolMode) { /* a menuconfig entry is displayed differently * depending whether it's at the view root or a child. */ if (sym && list->rootEntry == menu) break; setPixmap(promptColIdx, list->menuPix); } else { if (sym) break; setPixmap(promptColIdx, 0); } goto set_prompt; case P_COMMENT: setPixmap(promptColIdx, 0); goto set_prompt; default: ; } if (!sym) goto set_prompt; setText(nameColIdx, QString::fromLocal8Bit(sym->name)); type = sym_get_type(sym); switch (type) { case S_BOOLEAN: case S_TRISTATE: char ch; if (!sym_is_changable(sym) && !list->showAll) { setPixmap(promptColIdx, 0); setText(noColIdx, QString::null); setText(modColIdx, QString::null); setText(yesColIdx, QString::null); break; } expr = sym_get_tristate_value(sym); switch (expr) { case yes: if (sym_is_choice_value(sym) && type == S_BOOLEAN) setPixmap(promptColIdx, list->choiceYesPix); else setPixmap(promptColIdx, list->symbolYesPix); setText(yesColIdx, "Y"); ch = 'Y'; break; case mod: setPixmap(promptColIdx, list->symbolModPix); setText(modColIdx, "M"); ch = 'M'; break; default: if (sym_is_choice_value(sym) && type == S_BOOLEAN) setPixmap(promptColIdx, list->choiceNoPix); else setPixmap(promptColIdx, list->symbolNoPix); setText(noColIdx, "N"); ch = 'N'; break; } if (expr != no) setText(noColIdx, sym_tristate_within_range(sym, no) ? "_" : 0); if (expr != mod) setText(modColIdx, sym_tristate_within_range(sym, mod) ? "_" : 0); if (expr != yes) setText(yesColIdx, sym_tristate_within_range(sym, yes) ? "_" : 0); setText(dataColIdx, QChar(ch)); break; case S_INT: case S_HEX: case S_STRING: const char* data; data = sym_get_string_value(sym);#if QT_VERSION >= 300 int i = list->mapIdx(dataColIdx); if (i >= 0) setRenameEnabled(i, TRUE);#endif setText(dataColIdx, data); if (type == S_STRING) prompt = QString("%1: %2").arg(prompt).arg(data); else prompt = QString("(%2) %1").arg(prompt).arg(data); break; } if (!sym_has_value(sym) && visible) prompt += " (NEW)";set_prompt: setText(promptColIdx, prompt);}void ConfigItem::testUpdateMenu(bool v){ ConfigItem* i; visible = v; if (!menu) return; sym_calc_value(menu->sym); if (menu->flags & MENU_CHANGED) { /* the menu entry changed, so update all list items */ menu->flags &= ~MENU_CHANGED; for (i = (ConfigItem*)menu->data; i; i = i->nextItem) i->updateMenu(); } else if (listView()->updateAll) updateMenu();}void ConfigItem::paintCell(QPainter* p, const QColorGroup& cg, int column, int width, int align){ ConfigList* list = listView(); if (visible) { if (isSelected() && !list->hasFocus() && list->mode == menuMode) Parent::paintCell(p, list->inactivedColorGroup, column, width, align); else Parent::paintCell(p, cg, column, width, align); } else Parent::paintCell(p, list->disabledColorGroup, column, width, align);}/* * construct a menu entry */void ConfigItem::init(void){ if (menu) { ConfigList* list = listView(); nextItem = (ConfigItem*)menu->data; menu->data = this; if (list->mode != fullMode) setOpen(TRUE); sym_calc_value(menu->sym); } updateMenu();}/* * destruct a menu entry */ConfigItem::~ConfigItem(void){ if (menu) { ConfigItem** ip = (ConfigItem**)&menu->data; for (; *ip; ip = &(*ip)->nextItem) { if (*ip == this) { *ip = nextItem; break; } } }}ConfigLineEdit::ConfigLineEdit(ConfigView* parent) : Parent(parent){ connect(this, SIGNAL(lostFocus()), SLOT(hide()));}void ConfigLineEdit::show(ConfigItem* i){ item = i; if (sym_get_string_value(item->menu->sym)) setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym))); else setText(QString::null); Parent::show(); setFocus();}void ConfigLineEdit::keyPressEvent(QKeyEvent* e){ switch (e->key()) { case Key_Escape: break; case Key_Return: case Key_Enter: sym_set_string_value(item->menu->sym, text().latin1()); parent()->updateList(item); break; default: Parent::keyPressEvent(e); return; } e->accept(); parent()->list->setFocus(); hide();}ConfigList::ConfigList(ConfigView* p, const char *name) : Parent(p, name), updateAll(false), symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no), choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no), menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void), showAll(false), showName(false), showRange(false), showData(false), rootEntry(0), headerPopup(0){ int i; setSorting(-1); setRootIsDecorated(TRUE); disabledColorGroup = palette().active(); disabledColorGroup.setColor(QColorGroup::Text, palette().disabled().text()); inactivedColorGroup = palette().active(); inactivedColorGroup.setColor(QColorGroup::Highlight, palette().disabled().highlight()); connect(this, SIGNAL(selectionChanged(void)), SLOT(updateSelection(void))); if (name) { configSettings->beginGroup(name); showAll = configSettings->readBoolEntry("/showAll", false); showName = configSettings->readBoolEntry("/showName", false); showRange = configSettings->readBoolEntry("/showRange", false); showData = configSettings->readBoolEntry("/showData", false); configSettings->endGroup(); connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); } for (i = 0; i < colNr; i++) colMap[i] = colRevMap[i] = -1; addColumn(promptColIdx, "Option"); reinit();}void ConfigList::reinit(void){ removeColumn(dataColIdx); removeColumn(yesColIdx); removeColumn(modColIdx); removeColumn(noColIdx); removeColumn(nameColIdx); if (showName) addColumn(nameColIdx, "Name"); if (showRange) { addColumn(noColIdx, "N"); addColumn(modColIdx, "M"); addColumn(yesColIdx, "Y"); } if (showData) addColumn(dataColIdx, "Value"); updateListAll();}void ConfigList::saveSettings(void){ if (name()) { configSettings->beginGroup(name()); configSettings->writeEntry("/showName", showName); configSettings->writeEntry("/showRange", showRange); configSettings->writeEntry("/showData", showData); configSettings->writeEntry("/showAll", showAll); configSettings->endGroup(); }}ConfigItem* ConfigList::findConfigItem(struct menu *menu){ ConfigItem* item = (ConfigItem*)menu->data; for (; item; item = item->nextItem) { if (this == item->listView()) break; } return item;}void ConfigList::updateSelection(void){ struct menu *menu; enum prop_type type; ConfigItem* item = (ConfigItem*)selectedItem(); if (!item) return; menu = item->menu; emit menuChanged(menu); if (!menu) return; type = menu->prompt ? menu->prompt->type : P_UNKNOWN; if (mode == menuMode && type == P_MENU) emit menuSelected(menu);}void ConfigList::updateList(ConfigItem* item){ ConfigItem* last = 0; if (!rootEntry) { if (mode != listMode) goto update; QListViewItemIterator it(this); ConfigItem* item; for (; it.current(); ++it) { item = (ConfigItem*)it.current(); if (!item->menu) continue; item->testUpdateMenu(menu_is_visible(item->menu)); } return; } if (rootEntry != &rootmenu && (mode == singleMode || (mode == symbolMode && rootEntry->parent != &rootmenu))) { item = firstChild(); if (!item) item = new ConfigItem(this, 0, true); last = item; } if ((mode == singleMode || (mode == symbolMode && !(rootEntry->flags & MENU_ROOT))) && rootEntry->sym && rootEntry->prompt) { item = last ? last->nextSibling() : firstChild(); if (!item) item = new ConfigItem(this, last, rootEntry, true); else item->testUpdateMenu(true); updateMenuList(item, rootEntry); triggerUpdate(); return; }update: updateMenuList(this, rootEntry); triggerUpdate();}void ConfigList::setValue(ConfigItem* item, tristate val){ struct symbol* sym; int type; tristate oldval; sym = item->menu ? item->menu->sym : 0; if (!sym) return; type = sym_get_type(sym); switch (type) { case S_BOOLEAN: case S_TRISTATE: oldval = sym_get_tristate_value(sym); if (!sym_set_tristate_value(sym, val)) return; if (oldval == no && item->menu->list) item->setOpen(TRUE); parent()->updateList(item); break; }}void ConfigList::changeValue(ConfigItem* item){ struct symbol* sym; struct menu* menu; int type, oldexpr, newexpr; menu = item->menu; if (!menu) return; sym = menu->sym; if (!sym) { if (item->menu->list) item->setOpen(!item->isOpen()); return; } type = sym_get_type(sym); switch (type) { case S_BOOLEAN: case S_TRISTATE: oldexpr = sym_get_tristate_value(sym); newexpr = sym_toggle_tristate_value(sym); if (item->menu->list) { if (oldexpr == newexpr) item->setOpen(!item->isOpen()); else if (oldexpr == no) item->setOpen(TRUE); } if (oldexpr != newexpr) parent()->updateList(item); break; case S_INT: case S_HEX: case S_STRING:#if QT_VERSION >= 300 if (colMap[dataColIdx] >= 0) item->startRename(colMap[dataColIdx]); else#endif parent()->lineEdit->show(item); break; }}void ConfigList::setRootMenu(struct menu *menu){ enum prop_type type; if (rootEntry == menu) return; type = menu && menu->prompt ? menu->prompt->type : P_UNKNOWN; if (type != P_MENU) return; updateMenuList(this, 0); rootEntry = menu; updateListAll(); setSelected(currentItem(), hasFocus()); ensureItemVisible(currentItem());}void ConfigList::setParentMenu(void){ ConfigItem* item; struct menu *oldroot; oldroot = rootEntry; if (rootEntry == &rootmenu) return; setRootMenu(menu_get_parent_menu(rootEntry->parent)); QListViewItemIterator it(this); for (; (item = (ConfigItem*)it.current()); it++) { if (item->menu == oldroot) { setCurrentItem(item); ensureItemVisible(item); break; } }}/* * update all the children of a menu entry * removes/adds the entries from the parent widget as necessary * * parent: either the menu list widget or a menu entry widget * menu: entry to be updated */template <class P>void ConfigList::updateMenuList(P* parent, struct menu* menu){ struct menu* child; ConfigItem* item; ConfigItem* last; bool visible; enum prop_type type; if (!menu) { while ((item = parent->firstChild())) delete item; return; } last = parent->firstChild();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -