void QtWebKitHelpViewer::highlightId(const QString &id) { if (m_oldHighlightId == id) return; const QWebElement &document = m_webView->page()->mainFrame()->documentElement(); const QWebElementCollection &collection = document.findAll(QLatin1String("h3.fn a")); const QLatin1String property("background-color"); foreach (const QWebElement &element, collection) { const QString &name = element.attribute(QLatin1String("name")); if (name.isEmpty()) continue; if (m_oldHighlightId == name || name.startsWith(m_oldHighlightId + QLatin1Char('-'))) { QWebElement parent = element.parent(); parent.setStyleProperty(property, m_oldHighlightStyle); } if (id == name || name.startsWith(id + QLatin1Char('-'))) { QWebElement parent = element.parent(); m_oldHighlightStyle = parent.styleProperty(property, QWebElement::ComputedStyle); parent.setStyleProperty(property, QLatin1String("yellow")); } } m_oldHighlightId = id; }
void WebView::Private::showFullScreen() { //normal -> full QWebFrame *frame = q->page()->mainFrame(); //スクロールバー非表示 QWebElement element = frame->findFirstElement(QStringLiteral("body")); if (element.isNull()) { qDebug() << "failed find target"; return; } QHash<QString, QString> properties; properties.insert(QStringLiteral("overflow"), QStringLiteral("hidden")); if(body.isEmpty()){ foreach (const QString &key, properties.keys()) { body.insert(key, element.styleProperty(key, QWebElement::InlineStyle)); } qDebug() << element.styleProperty(QStringLiteral("overflow"), QWebElement::InlineStyle); }
WebElementStruct PhpWebView::createWebElementStruct(QWebElement elem, int i) { WebElementStruct we; we.el = elem; we.position = elem.styleProperty("position", QWebElement::ComputedStyle); we.z_index = 0; we.i = i; QWebElement cur = elem; while (!cur.isNull()) { QString z = cur.styleProperty("z-index", QWebElement::ComputedStyle); bool res; int zi = z.toInt(&res); if (res) { we.z_index = zi; break; } cur = cur.parent(); } cur = elem; while (!cur.isNull()) { QString pos = cur.styleProperty("position", QWebElement::ComputedStyle); if (pos != "inherit") { we.position = pos; break; } cur = cur.parent(); } return we; }
bool PhpWebView::findElementByCoord(QWebElement & root, QPoint & point, QList<WebElementStruct> & list) { QWebElement child = root.lastChild(); bool isfind = false; while (!child.isNull()) { if (findElementByCoord(child, point, list)) isfind = true; child = child.previousSibling(); } QString display = root.styleProperty("display", QWebElement::ComputedStyle); if (display != "none" && root.geometry().contains(point) && !isfind) { list.append(createWebElementStruct(root, list.count())); return true; } else return false; }
bool HistoryChatView::onContextMenu(ChatView *view, QMenu *menu, const QWebHitTestResult &result) { ChatId id(view->id()); if (id.type() != ChatId::ChannelId && id.type() != ChatId::UserId) return false; QWebElement block = result.enclosingBlockElement(); if (block.styleProperty("display", QWebElement::CascadedStyle) == LS("inline-block")) block = block.parent(); if (!(block.hasClass(LS("blocks")) || block.hasClass(LS("panel-body")) || block.hasClass(LS("panel-heading"))) || block.hasClass("removed")) return false; const QWebElement container = block.parent(); const qint64 mdate = container.attribute(LS("data-mdate")).toLongLong(); if (!mdate) return false; id.init(container.attribute(LS("id")).toLatin1()); id.setDate(mdate); if (id.type() != ChatId::MessageId) return false; const int permissions = this->permissions(HistoryDB::get(id)); if (permissions == NoPermissions) return false; if (permissions & Remove) { QVariantList data; data << view->id() << (id.hasOid() ? ChatId::toBase32(id.oid().byteArray()) : id.toString()); menu->insertAction(menu->actions().first(), removeAction(data)); } return true; }
void MWBotWin::doTaxi() { if (curTime.date().dayOfWeek() != 1) return; if (opt.taxi.time > curTime) return; QWebElement elm; QWebElement sub; int time; int count; int loop; setBusy(true); loadPage("arbat"); // check taxi chest and take it elm = frm->findFirstElement("div.auto-bombila table.collectbar td.actions button.button"); if (elm.isNull()) { count = 0; } else { count = elm.classes().contains("disabled") ? 0 : 1; } if (count) { sub = elm.findFirst("div.c"); clickElement(sub); log(trUtf8("Забран сундук бомбилы"),"chest.png"); } // check taxi timer, send a car & charge it if it needs elm = frm->findFirstElement("div.auto-bombila table.process td#cooldown"); if (elm.styleProperty("display",QWebElement::ComputedStyle) == "none") { time = 0; } else { time = elm.attribute("timer").toInt(); } if (time != 0) { time += (30 + (random() % 30)); opt.taxi.time = curTime.addSecs(time); log(trUtf8("До следующей бомбилки %0 сек").arg(time),"taxi.png"); } else { do { loop = 0; elm= frm->findFirstElement("div.auto-bombila table.action button.ride-button span.f div.c"); clickElement(elm); elm = frm->findFirstElement("div.alert.alert-error h2#alert-title"); if (elm.isNull()) { elm = frm->findFirstElement("div.auto-bombila table.process td#cooldown"); time = elm.attribute("timer").toInt(); time += 30 + random() % 30; opt.taxi.time = curTime.addSecs(time); log(trUtf8("Авто отправлено бомбить. До следующего раза %0 сек").arg(time),"taxi.png"); } else { elm = frm->findFirstElement("div.alert.alert-error div.actions div.button div.c"); sub = elm.findFirst("span"); count = sub.toPlainText().remove("\"").toInt(); getFastRes(); if (sub.classes().contains("ruda")) { count = (info.ore >= count) ? 1 : 0; } else if (sub.classes().contains("oil")) { count = (info.oil >= count) ? 1 : 0; } else { count = 0; } if (count) { clickElement(elm); log(trUtf8("Машина заправлена"),"taxi.png"); loop = 1; } else { time = 15 * 60; opt.taxi.time = curTime.addSecs(time); log(trUtf8("Не хватает ресурсов для заправки. Ждём 15 мин"),"taxi.png"); } } } while (loop); } setBusy(false); }
QString getSelectElementDisplayProperty() const { const QWebElement select = getElement(HTTP_SELECT_SELECTOR); BOOST_REQUIRE( !select.isNull( )); return select.styleProperty(DISPLAY_STYLE_PROPERTY_NAME, QWebElement::InlineStyle); }