77 QString path = url.path(QUrl::FullyEncoded);
78 static const char simpleCss[] =
"/offline-simple.css";
79 if (path.endsWith(simpleCss)) {
80 path.replace(simpleCss,
"/offline.css");
81 actualUrl.setPath(path);
84 if (actualUrl.isValid())
87 const bool isAbout = (actualUrl.toString() ==
"about:blank"_L1);
88 return isAbout ? HelpViewerImpl::AboutBlank.toUtf8()
89 : HelpViewerImpl::PageNotFoundMessage.arg(url.toString()).toUtf8();
120 QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
122 const bool isHelp = (url.toString() ==
"help"_L1);
123 const QUrl resolvedUrl = (isHelp ? HelpViewerImpl::LocalHelpFile
124 : HelpEngineWrapper::instance().findFile(url));
126 QUrl currentUrlWithoutFragment = m_viewer->url();
127 currentUrlWithoutFragment.setFragment({});
128 QUrl newUrlWithoutFragment = resolvedUrl;
129 newUrlWithoutFragment.setFragment({});
131 m_viewer->setUrl(resolvedUrl);
132 if (currentUrlWithoutFragment != newUrlWithoutFragment || reload)
133 m_viewer->setHtml(QString::fromUtf8(getData(resolvedUrl)));
135 m_viewer->verticalScrollBar()->setValue(*vscroll);
137 m_viewer->scrollToAnchor(resolvedUrl.fragment(QUrl::FullyEncoded));
139 QGuiApplication::restoreOverrideCursor();
141 emit q->sourceChanged(q->source());
142 emit q->loadFinished();
143 emit q->titleChanged();
166 auto layout =
new QVBoxLayout;
168 d->m_viewer =
new QLiteHtmlWidget(
this);
169 d->m_viewer->setResourceHandler([](
const QUrl &url) {
return getData(url); });
170 d->m_viewer->viewport()->installEventFilter(
this);
171 const int zoomPercentage = zoom == 0 ? 100 : zoom * 100;
173 connect(d->m_viewer, &QLiteHtmlWidget::linkClicked,
this, &HelpViewer::setSource);
174 connect(d->m_viewer, &QLiteHtmlWidget::linkHighlighted,
this, &HelpViewer::highlighted);
175#if QT_CONFIG(clipboard)
176 connect(d->m_viewer, &QLiteHtmlWidget::copyAvailable,
this, &HelpViewer::copyAvailable);
179 layout->setContentsMargins(0, 0, 0, 0);
180 layout->addWidget(d->m_viewer, 10);
183 QPalette p = palette();
184 p.setColor(QPalette::Inactive, QPalette::Highlight,
185 p.color(QPalette::Active, QPalette::Highlight));
186 p.setColor(QPalette::Inactive, QPalette::HighlightedText,
187 p.color(QPalette::Active, QPalette::HighlightedText));
188 p.setColor(QPalette::Base, Qt::white);
189 p.setColor(QPalette::Text, Qt::black);
289 QTextDocument::FindFlags textDocFlags;
290 if (flags & HelpViewer::FindBackward)
291 textDocFlags |= QTextDocument::FindBackward;
292 if (flags & HelpViewer::FindCaseSensitively)
293 textDocFlags |= QTextDocument::FindCaseSensitively;
318 if (d->m_forwardItems.empty())
320 d->m_backItems.push_back(nextItem);
321 nextItem = d->m_forwardItems.front();
322 d->m_forwardItems.erase(d->m_forwardItems.begin());
324 emit backwardAvailable(isBackwardAvailable());
325 emit forwardAvailable(isForwardAvailable());
326 d->setSourceInternal(nextItem.url, &nextItem
.vscroll);
332 if (d->m_backItems.empty())
334 d->m_forwardItems.insert(d->m_forwardItems.begin(), previousItem);
335 previousItem = d->m_backItems.back();
336 d->m_backItems.pop_back();
338 emit backwardAvailable(isBackwardAvailable());
339 emit forwardAvailable(isForwardAvailable());
340 d->setSourceInternal(previousItem.url, &previousItem
.vscroll);
345 if (event->type() == QEvent::Wheel) {
346 auto we =
static_cast<QWheelEvent *>(event);
347 if (we->modifiers() == Qt::ControlModifier) {
349 const int deltaY = we->angleDelta().y();
355 return QWidget::eventFilter(src, event);
395 if (isLocalUrl(url)) {
397 const QUrl &resolvedUrl = helpEngine.findFile(url);
398 if (!resolvedUrl.isValid())
401 const QString& path = resolvedUrl.toLocalFile();
402 if (!canOpenPage(path)) {
403 QTemporaryFile tmpTmpFile;
404 if (!tmpTmpFile.open())
407 const QString &extension = QFileInfo(path).completeSuffix();
408 QFile actualTmpFile(tmpTmpFile.fileName() %
"."_L1 % extension);
409 if (!actualTmpFile.open(QIODevice::ReadWrite | QIODevice::Truncate))
412 actualTmpFile.write(helpEngine.fileData(resolvedUrl));
413 actualTmpFile.close();
414 return QDesktopServices::openUrl(QUrl::fromLocalFile(actualTmpFile.fileName()));
418 return QDesktopServices::openUrl(url);