📄 qconf.cc
字号:
if (last && !last->goParent) last = 0; for (child = menu->list; child; child = child->next) { item = last ? last->nextSibling() : parent->firstChild(); type = child->prompt ? child->prompt->type : P_UNKNOWN; switch (mode) { case menuMode: if (!(child->flags & MENU_ROOT)) goto hide; break; case symbolMode: if (child->flags & MENU_ROOT) goto hide; break; default: break; } visible = menu_is_visible(child); if (showAll || visible) { if (!child->sym && !child->list && !child->prompt) continue; if (!item || item->menu != child) item = new ConfigItem(parent, last, child, visible); else item->testUpdateMenu(visible); if (mode == fullMode || mode == menuMode || type != P_MENU) updateMenuList(item, child); else updateMenuList(item, 0); last = item; continue; } hide: if (item && item->menu == child) { last = parent->firstChild(); if (last == item) last = 0; else while (last->nextSibling() != item) last = last->nextSibling(); delete item; } }}void ConfigList::keyPressEvent(QKeyEvent* ev){ QListViewItem* i = currentItem(); ConfigItem* item; struct menu *menu; enum prop_type type; if (ev->key() == Key_Escape && mode != fullMode && mode != listMode) { emit parentSelected(); ev->accept(); return; } if (!i) { Parent::keyPressEvent(ev); return; } item = (ConfigItem*)i; switch (ev->key()) { case Key_Return: case Key_Enter: if (item->goParent) { emit parentSelected(); break; } menu = item->menu; if (!menu) break; type = menu->prompt ? menu->prompt->type : P_UNKNOWN; if (type == P_MENU && rootEntry != menu && mode != fullMode && mode != menuMode) { emit menuSelected(menu); break; } case Key_Space: changeValue(item); break; case Key_N: setValue(item, no); break; case Key_M: setValue(item, mod); break; case Key_Y: setValue(item, yes); break; default: Parent::keyPressEvent(ev); return; } ev->accept();}void ConfigList::contentsMousePressEvent(QMouseEvent* e){ //QPoint p(contentsToViewport(e->pos())); //printf("contentsMousePressEvent: %d,%d\n", p.x(), p.y()); Parent::contentsMousePressEvent(e);}void ConfigList::contentsMouseReleaseEvent(QMouseEvent* e){ QPoint p(contentsToViewport(e->pos())); ConfigItem* item = (ConfigItem*)itemAt(p); struct menu *menu; enum prop_type ptype; const QPixmap* pm; int idx, x; if (!item) goto skip; menu = item->menu; x = header()->offset() + p.x(); idx = colRevMap[header()->sectionAt(x)]; switch (idx) { case promptColIdx: pm = item->pixmap(promptColIdx); if (pm) { int off = header()->sectionPos(0) + itemMargin() + treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0)); if (x >= off && x < off + pm->width()) { if (item->goParent) { emit parentSelected(); break; } else if (!menu) break; ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; if (ptype == P_MENU && rootEntry != menu && mode != fullMode && mode != menuMode) emit menuSelected(menu); else changeValue(item); } } break; case noColIdx: setValue(item, no); break; case modColIdx: setValue(item, mod); break; case yesColIdx: setValue(item, yes); break; case dataColIdx: changeValue(item); break; }skip: //printf("contentsMouseReleaseEvent: %d,%d\n", p.x(), p.y()); Parent::contentsMouseReleaseEvent(e);}void ConfigList::contentsMouseMoveEvent(QMouseEvent* e){ //QPoint p(contentsToViewport(e->pos())); //printf("contentsMouseMoveEvent: %d,%d\n", p.x(), p.y()); Parent::contentsMouseMoveEvent(e);}void ConfigList::contentsMouseDoubleClickEvent(QMouseEvent* e){ QPoint p(contentsToViewport(e->pos())); ConfigItem* item = (ConfigItem*)itemAt(p); struct menu *menu; enum prop_type ptype; if (!item) goto skip; if (item->goParent) { emit parentSelected(); goto skip; } menu = item->menu; if (!menu) goto skip; ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; if (ptype == P_MENU && (mode == singleMode || mode == symbolMode)) emit menuSelected(menu); else if (menu->sym) changeValue(item);skip: //printf("contentsMouseDoubleClickEvent: %d,%d\n", p.x(), p.y()); Parent::contentsMouseDoubleClickEvent(e);}void ConfigList::focusInEvent(QFocusEvent *e){ struct menu *menu = NULL; Parent::focusInEvent(e); ConfigItem* item = (ConfigItem *)currentItem(); if (item) { setSelected(item, TRUE); menu = item->menu; } emit gotFocus(menu);}void ConfigList::contextMenuEvent(QContextMenuEvent *e){ if (e->y() <= header()->geometry().bottom()) { if (!headerPopup) { QAction *action; headerPopup = new QPopupMenu(this); action = new QAction(NULL, "Show Name", 0, this); action->setToggleAction(TRUE); connect(action, SIGNAL(toggled(bool)), parent(), SLOT(setShowName(bool))); connect(parent(), SIGNAL(showNameChanged(bool)), action, SLOT(setOn(bool))); action->setOn(showName); action->addTo(headerPopup); action = new QAction(NULL, "Show Range", 0, this); action->setToggleAction(TRUE); connect(action, SIGNAL(toggled(bool)), parent(), SLOT(setShowRange(bool))); connect(parent(), SIGNAL(showRangeChanged(bool)), action, SLOT(setOn(bool))); action->setOn(showRange); action->addTo(headerPopup); action = new QAction(NULL, "Show Data", 0, this); action->setToggleAction(TRUE); connect(action, SIGNAL(toggled(bool)), parent(), SLOT(setShowData(bool))); connect(parent(), SIGNAL(showDataChanged(bool)), action, SLOT(setOn(bool))); action->setOn(showData); action->addTo(headerPopup); } headerPopup->exec(e->globalPos()); e->accept(); } else e->ignore();}ConfigView* ConfigView::viewList;ConfigView::ConfigView(QWidget* parent, const char *name) : Parent(parent, name){ list = new ConfigList(this, name); lineEdit = new ConfigLineEdit(this); lineEdit->hide(); this->nextView = viewList; viewList = this;}ConfigView::~ConfigView(void){ ConfigView** vp; for (vp = &viewList; *vp; vp = &(*vp)->nextView) { if (*vp == this) { *vp = nextView; break; } }}void ConfigView::setShowAll(bool b){ if (list->showAll != b) { list->showAll = b; list->updateListAll(); emit showAllChanged(b); }}void ConfigView::setShowName(bool b){ if (list->showName != b) { list->showName = b; list->reinit(); emit showNameChanged(b); }}void ConfigView::setShowRange(bool b){ if (list->showRange != b) { list->showRange = b; list->reinit(); emit showRangeChanged(b); }}void ConfigView::setShowData(bool b){ if (list->showData != b) { list->showData = b; list->reinit(); emit showDataChanged(b); }}void ConfigList::setAllOpen(bool open){ QListViewItemIterator it(this); for (; it.current(); it++) it.current()->setOpen(open);}void ConfigView::updateList(ConfigItem* item){ ConfigView* v; for (v = viewList; v; v = v->nextView) v->list->updateList(item);}void ConfigView::updateListAll(void){ ConfigView* v; for (v = viewList; v; v = v->nextView) v->list->updateListAll();}ConfigInfoView::ConfigInfoView(QWidget* parent, const char *name) : Parent(parent, name), menu(0), sym(0){ if (name) { configSettings->beginGroup(name); _showDebug = configSettings->readBoolEntry("/showDebug", false); configSettings->endGroup(); connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); }}void ConfigInfoView::saveSettings(void){ if (name()) { configSettings->beginGroup(name()); configSettings->writeEntry("/showDebug", showDebug()); configSettings->endGroup(); }}void ConfigInfoView::setShowDebug(bool b){ if (_showDebug != b) { _showDebug = b; if (menu) menuInfo(); else if (sym) symbolInfo(); emit showDebugChanged(b); }}void ConfigInfoView::setInfo(struct menu *m){ if (menu == m) return; menu = m; sym = NULL; if (!menu) clear(); else menuInfo();}void ConfigInfoView::setSource(const QString& name){ const char *p = name.latin1(); menu = NULL; sym = NULL; switch (p[0]) { case 'm': struct menu *m; if (sscanf(p, "m%p", &m) == 1 && menu != m) { menu = m; menuInfo(); emit menuSelected(menu); } break; case 's': struct symbol *s; if (sscanf(p, "s%p", &s) == 1 && sym != s) { sym = s; symbolInfo(); } break; }}void ConfigInfoView::symbolInfo(void){ QString str; str += "<big>Symbol: <b>"; str += print_filter(sym->name); str += "</b></big><br><br>value: "; str += print_filter(sym_get_string_value(sym)); str += "<br>visibility: "; str += sym->visible == yes ? "y" : sym->visible == mod ? "m" : "n"; str += "<br>"; str += debug_info(sym); setText(str);}void ConfigInfoView::menuInfo(void){ struct symbol* sym; QString head, debug, help; sym = menu->sym; if (sym) { if (menu->prompt) { head += "<big><b>"; head += print_filter(_(menu->prompt->text)); head += "</b></big>"; if (sym->name) { head += " ("; if (showDebug()) head += QString().sprintf("<a href=\"s%p\">", sym); head += print_filter(sym->name); if (showDebug()) head += "</a>"; head += ")"; } } else if (sym->name) { head += "<big><b>"; if (showDebug()) head += QString().sprintf("<a href=\"s%p\">", sym); head += print_filter(sym->name); if (showDebug()) head += "</a>"; head += "</b></big>"; } head += "<br><br>"; if (showDebug()) debug = debug_info(sym); help = print_filter(_(menu_get_help(menu))); } else if (menu->prompt) { head += "<big><b>"; head += print_filter(_(menu->prompt->text)); head += "</b></big><br><br>"; if (showDebug()) { if (menu->prompt->visible.expr) { debug += " dep: "; expr_print(menu->prompt->visible.expr, expr_print_help, &debug, E_NONE); debug += "<br><br>"; } } } if (showDebug()) debug += QString().sprintf("defined at %s:%d<br><br>", menu->file->name, menu->lineno); setText(head + debug + help);}QString ConfigInfoView::debug_info(struct symbol *sym){ QString debug; debug += "type: "; debug += print_filter(sym_type_name(sym->type)); if (sym_is_choice(sym)) debug += " (choice)"; debug += "<br>"; if (sym->rev_dep.expr) { debug += "reverse dep: "; expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE); debug += "<br>"; } for (struct property *prop = sym->prop; prop; prop = prop->next) { switch (prop->type) { case P_PROMPT: case P_MENU: debug += QString().sprintf("prompt: <a href=\"m%p\">", prop->menu); debug += print_filter(_(prop->text)); debug += "</a><br>"; break; case P_DEFAULT: debug += "default: "; expr_print(prop->expr, expr_print_help, &debug, E_NONE); debug += "<br>"; break; case P_CHOICE: if (sym_is_choice(sym)) { debug += "choice: "; expr_print(prop->expr, expr_print_help, &debug, E_NONE); debug += "<br>"; } break; case P_SELECT: debug += "select: "; expr_print(prop->expr, expr_print_help, &debug, E_NONE); debug += "<br>"; break; case P_RANGE: debug += "range: "; expr_print(prop->expr, expr_print_help, &debug, E_NONE); debug += "<br>"; break; default: debug += "unknown property: "; debug += prop_get_type_name(prop->type); debug += "<br>"; } if (prop->visible.expr) { debug += " dep: "; expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE); debug += "<br>"; } } debug += "<br>"; return debug;}QString ConfigInfoView::print_filter(const QString &str){ QRegExp re("[<>&\"\\n]"); QString res = str; for (int i = 0; (i = res.find(re, i)) >= 0;) { switch (res[i].latin1()) { case '<': res.replace(i, 1, "<"); i += 4; break; case '>': res.replace(i, 1, ">"); i += 4; break; case '&': res.replace(i, 1, "&"); i += 5; break; case '"': res.replace(i, 1, """); i += 6; break; case '\n': res.replace(i, 1, "<br>"); i += 4; break; } } return res;}void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str){ QString* text = reinterpret_cast<QString*>(data); QString str2 = print_filter(str); if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) { *text += QString().sprintf("<a href=\"s%p\">", sym); *text += str2; *text += "</a>"; } else *text += str2;}QPopupMenu* ConfigInfoView::createPopupMenu(const QPoint& pos){ QPopupMenu* popup = Parent::createPopupMenu(pos); QAction* action = new QAction(NULL,"Show Debug Info", 0, popup); action->setToggleAction(TRUE); connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool))); connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool))); action->setOn(showDebug());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -