void ChatView::settingsChanged(const QString &key, const QVariant &value) { if (key == SETTINGS_DISPLAY_SECONDS) { m_seconds->setChecked(value.toBool()); evaluateJavaScript(LS("showSeconds"), value); } else if (key == SETTINGS_DISPLAY_SERVICE) { m_service->setChecked(value.toBool()); evaluateJavaScript(LS("showService"), value); } else if (key == SETTINGS_AUTO_SCROLL) m_autoscroll->setChecked(value.toBool()); }
void ChatController::clearChat() { Q_ASSERT(m_session); m_last = Message(); m_isLoading = true; QString serverUrl = m_client->serverUrl().toString(); QString html = m_style.baseTemplateForChat(m_session, m_id, serverUrl); emit htmlRequested(html, m_style.baseUrl()); evaluateJavaScript(m_style.scriptForSettingCustomStyle()); evaluateJavaScript(scriptForFontUpdate()); }
bool RichEditorWidget::QueryCommandState (const QString& cmd) { auto frame = Ui_.View_->page ()->mainFrame (); const QString& js = QString ("document.queryCommandState(\"%1\", false, null)").arg (cmd); auto res = frame->evaluateJavaScript (js); return res.toString ().simplified ().toLower () == "true"; }
void FB::BrowserHost::initJS(const void* inst) { assertMainThread(); // Inject javascript helper function into the page; this is neccesary to help // with some browser compatibility issues. const char* javascriptMethod = "window.__FB_CALL_%1% = " "function(delay, f, args, fname) {" " if (arguments.length == 3)" " return setTimeout(function() { f.apply(null, args); }, delay);" " else" " return setTimeout(function() { f[fname].apply(f, args); }, delay);" "};"; // I'm open to suggestions on a better way to get a unique key for this plugin instance uint32_t inst_key; memcpy(&inst_key, &inst, 4); inst_key >>= 1; // Make sure nobody could use this to get a valid pointer inst_key *= 2.5; unique_key = boost::lexical_cast<std::string>(inst_key); call_delegate = (boost::format("__FB_CALL_%1%") % inst_key).str(); evaluateJavaScript((boost::format(javascriptMethod) % inst_key).str()); }
void FB::BrowserHost::initJS(const void* inst) { assertMainThread(); // Inject javascript helper function into the page; this is neccesary to help // with some browser compatibility issues. const char* javascriptMethod = "window.__FB_CALL_%1% = " "function(delay, f, args, fname) {" " if (arguments.length == 3)" " return setTimeout(function() { f.apply(null, args); }, delay);" " else" " return setTimeout(function() { f[fname].apply(f, args); }, delay);" "};"; // hash pointer to get a unique key for this plugin instance std::size_t inst_key = static_cast<std::size_t>( reinterpret_cast<std::ptrdiff_t>(inst)); inst_key += (inst_key >> 3); unique_key = boost::lexical_cast<std::string>(inst_key); call_delegate = (boost::format("__FB_CALL_%1%") % inst_key).str(); evaluateJavaScript((boost::format(javascriptMethod) % inst_key).str()); }
bool ZoomEventFilter::eventFilter (QObject *viewObj, QEvent *someEvent) { if (someEvent->type () != QEvent::Wheel) return false; QWheelEvent *e = static_cast<QWheelEvent*> (someEvent); if (!(e->modifiers () & Qt::ControlModifier)) return false; int degrees = e->delta () / 8; int steps = static_cast<qreal> (degrees) / 15; QWebView *view = qobject_cast<QWebView*> (viewObj); if (e->modifiers () & Qt::ShiftModifier) { auto multiplier = view->textSizeMultiplier (); multiplier += steps * 0.1; view->setTextSizeMultiplier (multiplier); } else { QWebSettings *settings = view->settings (); settings->setFontSize (QWebSettings::DefaultFontSize, std::max (6, settings->fontSize (QWebSettings::DefaultFontSize) + steps)); auto frame = view->page ()->mainFrame (); frame->evaluateJavaScript ("setTimeout(ScrollToBottom,0);"); } return true; }
void RichEditorWidget::ExecCommand (const QString& cmd, const QString& arg) { auto frame = Ui_.View_->page ()->mainFrame (); const QString& js = arg.isEmpty () ? QString ("document.execCommand('%1', false, null)").arg (cmd) : QString ("document.execCommand('%1', false, '%2')").arg (cmd, arg); frame->evaluateJavaScript (js); }
bool ChatController::eventFilter(QObject *obj, QEvent *ev) { if (obj == m_session && ev->type() == MessageReceiptEvent::eventType()) { MessageReceiptEvent *msgEvent = static_cast<MessageReceiptEvent *>(ev); evaluateJavaScript(QStringLiteral("client.markMessage(%1, %2);") .arg(QString::number(msgEvent->id()), msgEvent->success() ? QStringLiteral("true") : QStringLiteral("false")) ); return true; } return QObject::eventFilter(obj, ev); }
/*! * Завершение загрузки документа. */ void ChatView::loadFinished() { m_loaded = true; m_autoscroll->setChecked(ChatCore::settings()->value(SETTINGS_AUTO_SCROLL).toBool()); m_seconds->setChecked(ChatCore::settings()->value(SETTINGS_DISPLAY_SECONDS).toBool()); m_service->setChecked(ChatCore::settings()->value(SETTINGS_DISPLAY_SERVICE).toBool()); evaluateJavaScript("showSeconds", m_seconds->isChecked()); evaluateJavaScript("showService", m_service->isChecked()); setId(m_id); ChatViewHooks::loadFinished(this); while (!m_pendingJs.isEmpty()) page()->mainFrame()->evaluateJavaScript(m_pendingJs.dequeue()); QTimer::singleShot(0, this, SLOT(startTasks())); while (!m_pendingFeeds.isEmpty()) emit feed(m_pendingFeeds.dequeue()); QTimer::singleShot(0, this, SLOT(alignChat())); }
void QtWebKitWebWidget::setUrl(const QUrl &url, bool typed) { if (url.scheme() == QLatin1String("javascript")) { evaluateJavaScript(url.path()); return; } if (!url.fragment().isEmpty() && url.matches(getUrl(), (QUrl::RemoveFragment | QUrl::StripTrailingSlash | QUrl::NormalizePathSegments))) { m_webView->page()->mainFrame()->scrollToAnchor(url.fragment()); return; } m_isTyped = typed; if (url.isValid() && url.scheme().isEmpty() && !url.path().startsWith('/')) { QUrl httpUrl = url; httpUrl.setScheme(QLatin1String("http")); m_webView->setUrl(httpUrl); } else if (url.isValid() && (url.scheme().isEmpty() || url.scheme() == "file")) { QUrl localUrl = url; localUrl.setScheme(QLatin1String("file")); m_webView->setUrl(localUrl); } else { m_webView->setUrl(url); } notifyTitleChanged(); notifyIconChanged(); }
void ChatController::onMessageAppended(const qutim_sdk_0_3::Message &msg) { Message copy = msg; QString html = UrlParser::parseUrls(copy.html(), UrlParser::Html); copy.setProperty("messageId", msg.id()); if (msg.property("topic", false)) { copy.setHtml(html); m_topic = copy; // if (!m_isLoading) // updateTopic(); return; } if (msg.property("firstFocus", false)) clearFocusClass(); // We don't want emoticons in topic html = Emoticons::theme().parseEmoticons(html); copy.setHtml(html); bool similiar = isContentSimiliar(m_last, msg); QString script = m_style.scriptForAppendingContent(copy, similiar, false, false); m_last = msg; evaluateJavaScript(script); }
void FB::BrowserHost::evaluateJavaScript(const std::wstring &script) { evaluateJavaScript(FB::wstring_to_utf8(script)); }
int QWebFrame::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: javaScriptWindowObjectCleared(); break; case 1: provisionalLoad(); break; case 2: titleChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 3: urlChanged((*reinterpret_cast< const QUrl(*)>(_a[1]))); break; case 4: initialLayoutCompleted(); break; case 5: iconChanged(); break; case 6: contentsSizeChanged((*reinterpret_cast< const QSize(*)>(_a[1]))); break; case 7: loadStarted(); break; case 8: loadFinished((*reinterpret_cast< bool(*)>(_a[1]))); break; case 9: { QVariant _r = evaluateJavaScript((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< QVariant*>(_a[0]) = _r; } break; case 10: print((*reinterpret_cast< QPrinter*(*)>(_a[1]))); break; default: ; } _id -= 11; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< qreal*>(_v) = textSizeMultiplier(); break; case 1: *reinterpret_cast< qreal*>(_v) = zoomFactor(); break; case 2: *reinterpret_cast< QString*>(_v) = title(); break; case 3: *reinterpret_cast< QUrl*>(_v) = url(); break; case 4: *reinterpret_cast< QUrl*>(_v) = requestedUrl(); break; case 5: *reinterpret_cast< QUrl*>(_v) = baseUrl(); break; case 6: *reinterpret_cast< QIcon*>(_v) = icon(); break; case 7: *reinterpret_cast< QSize*>(_v) = contentsSize(); break; case 8: *reinterpret_cast< QPoint*>(_v) = scrollPosition(); break; case 9: *reinterpret_cast< bool*>(_v) = hasFocus(); break; } _id -= 10; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setTextSizeMultiplier(*reinterpret_cast< qreal*>(_v)); break; case 1: setZoomFactor(*reinterpret_cast< qreal*>(_v)); break; case 3: setUrl(*reinterpret_cast< QUrl*>(_v)); break; case 8: setScrollPosition(*reinterpret_cast< QPoint*>(_v)); break; } _id -= 10; } else if (_c == QMetaObject::ResetProperty) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 10; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 10; } #endif // QT_NO_PROPERTIES return _id; }
void ChatView::evaluateJavaScript(const QString &func, const QVariant ¶m) { evaluateJavaScript(func + LS("(") + param.toString() + LS(");")); }
void FbTextElement::select() { QString javascript = jScript("set_cursor.js"); evaluateJavaScript(javascript); }
QString FbTextElement::location() { return evaluateJavaScript("location(this)").toString(); }
/*! * Добавление нового CSS файла. */ void ChatView::addCSS(const QString &file) { evaluateJavaScript(LS("Loader.loadCSS(\"") + file + LS("\");")); }
void ChatView::setId(const QByteArray &id) { m_id = id; evaluateJavaScript(LS("Settings.id = \"") + SimpleID::encode(m_id) + LS("\";")); }
void ChatView::showEvent(QShowEvent *event) { evaluateJavaScript(LS("alignChat();")); QWebView::showEvent(event); }