B Graph::walkBreadthFirst(int from, B body) const { std::vector<bool> was(numVertices(), false); std::queue<int> vertices; was[from] = true; vertices.push(from); while (!vertices.empty()) { int vertex = vertices.front(); vertices.pop(); std::list<GraphEdge>::const_iterator edge = edges_[vertex].begin(); for (; edge != edges_[vertex].end(); ++edge) { if (!was[edge->to]) { body(*edge); was[edge->to] = true; vertices.push(edge->to); } } } return body; }
void FlatInput::onTextEdited() { QString was(_oldtext); correctValue(_kev, was); _oldtext = text(); if (was != _oldtext) emit changed(); updatePlaceholder(); }
// suppose dynamic code represented as (codesAm * 3) + (codesCt) * 3 * 2 // where codesAm - alphabet for HC codes // codesCt - number of switches of length (count 2 if switches on 0) // 3 - length of one code, 2 - rough estimated length of additional info for each code int deflate_dynamic_estimate(vector<int> litLen, vector<int> dstLen) { int codesCt = 0; int codesAm = 0; int cur = -1; vector<bool> was(19, false); for (int i = 0; i < litLen.size(); ++i) { if (litLen[i] != cur) { if (!was[litLen[i]]) { was[litLen[i]] = true; codesAm++; } if (litLen[i] == 0) codesCt++; codesCt++; cur = litLen[i]; } } for (int i = 0; i < dstLen.size(); ++i) { if (dstLen[i] != cur) { if (!was[dstLen[i]]) { was[dstLen[i]] = true; codesAm++; } if (dstLen[i] == 0) codesCt++; codesCt++; cur = dstLen[i]; } } return codesAm * 3 + codesCt * 3 * 2; }
void PhoneInput::addedToNumber(const QString &added) { setFocus(); QString was(text()); setText(added + text()); setCursorPosition(added.length()); correctValue(0, was); updatePlaceholder(); }
void FlatInput::keyPressEvent(QKeyEvent *e) { QString was(text()); _kev = e; if (_customUpDown && (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down)) { e->ignore(); } else { QLineEdit::keyPressEvent(e); } if (was == text()) { // call correct manually correctValue(_kev, was); _oldtext = text(); if (was != _oldtext) emit changed(); updatePlaceholder(); } if (e->key() == Qt::Key_Escape) { emit cancelled(); } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { emit accepted(); } _kev = 0; }
void RadialAnimation::draw(Painter &p, const QRect &inner, int32 thickness, const style::color &color) { float64 o = p.opacity(); p.setOpacity(o * _opacity); QPen pen(color->p), was(p.pen()); pen.setWidth(thickness); p.setPen(pen); int32 len = MinArcLength + a_arcEnd.current(); int32 from = QuarterArcLength - a_arcStart.current() - len; if (rtl()) { from = QuarterArcLength - (from - QuarterArcLength) - len; if (from < 0) from += FullArcLength; } p.setRenderHint(QPainter::HighQualityAntialiasing); p.drawArc(inner, from, len); p.setRenderHint(QPainter::HighQualityAntialiasing, false); p.setPen(was); p.setOpacity(o); }
void RadialAnimation::draw(Painter &p, const QRect &inner, int32 thickness, style::color color) { float64 o = p.opacity(); p.setOpacity(o * _opacity); QPen pen(color->p), was(p.pen()); pen.setWidth(thickness); pen.setCapStyle(Qt::RoundCap); p.setPen(pen); auto len = MinArcLength + qRound(a_arcEnd.current()); auto from = QuarterArcLength - qRound(a_arcStart.current()) - len; if (rtl()) { from = QuarterArcLength - (from - QuarterArcLength) - len; if (from < 0) from += FullArcLength; } { PainterHighQualityEnabler hq(p); p.drawArc(inner, from, len); } p.setPen(was); p.setOpacity(o); }
bool LauncherProfile(const wchar_t *cf,LauncherStructure &config) { std::wstring pfile; if(cf==nullptr){ std::wstring folder; if(!GetProcessImageFileFolder(folder)){ MessageBoxW(nullptr, L"GetModuleFileNameW Failed!", L"Internal System Error", MB_OK|MB_ICONERROR); return false; } pfile=folder+L"/launcher.toml"; if(!PathFileExistsW(pfile.c_str())){ pfile=folder+L"/launcher.exe.toml"; if(!PathFileExistsW(pfile.c_str())){ MessageBoxW(nullptr, folder.c_str(), L"Cannot open launcher.toml or launcher.exe.toml on this path", MB_OK|MB_ICONERROR); return false; } } }else{ pfile=cf; } Characters chars(pfile.c_str()); std::shared_ptr<cpptoml::table> g; try { g = cpptoml::parse_file(chars.Get()); std::cout << (*g) << std::endl; } catch (const cpptoml::parse_exception &e) { (void)e; MessageBoxW(nullptr, pfile.c_str(), L"Cannot parser toml-format profile!", MB_OK|MB_ICONERROR); return false; } auto Strings = [&](const char *key, const wchar_t *v, std::wstring &sv) { if (g->contains_qualified(key)) { std::string astr = g->get_qualified(key)->as<std::string>()->get(); WCharacters was(astr.c_str()); sv=was.Get(); return; } if(v){ sv = v; } }; auto Boolean = [&](const char *key, bool b) { if (g->contains_qualified(key)) { return g->get_qualified(key)->as<bool>()->get(); } return b; }; auto Vector = [&](const char *key, std::vector<std::wstring> &v) { if (g->contains_qualified(key) && g->get_qualified(key)->is_array()) { auto av = g->get_qualified(key)->as_array(); for (auto &e : av->get()) { WCharacters was(e->as<std::string>()->get().c_str()); v.push_back(was.Get()); } } }; Strings("Launcher.MSYSTEM",L"MINGW64",config.env); Strings("Launcher.Root",L"C:/MSYS2",config.root); Strings("Launcher.WD",L"C:/MSYS2/usr/bin",config.wd); Strings("Launcher.Mintty",L"C:/MSYS2/usr/bin/mintty.exe",config.mintty); Strings("Launcher.ICONPath",L"/msys2.ico",config.icon); Strings("Launcher.Shell",L"bash",config.otherShell); Strings("Launcher.AppendShellArgs",nullptr,config.shellArgs); Vector("Launcher.AppendPath",config.appendPath); config.enableZshell=Boolean("Launcher.EnableZshell",false); config.clearEnvironment=Boolean("Launcher.UseClearEnv",false); return true; }