7#include <QtCore/qcoreevent.h>
8#include <QtCore/qlist.h>
9#include <QtCore/qpointer.h>
10#include <QtCore/qtextstream.h>
11#include <QtWidgets/qlabel.h>
12#include <QtWidgets/qlayout.h>
13#include <QtWidgets/qlayoutitem.h>
14#include <QtWidgets/qtoolbutton.h>
15#include <QtWidgets/qtextbrowser.h>
24 Q_PROPERTY(QColor linkColor READ linkColor WRITE setLinkColor)
39#if QT_CONFIG(cssparser)
50 str <<
"<html><head><title>" <<
tr(
"Search Results") <<
"</title></head><body>";
55 str <<
"<div style=\"text-align:left;"
56 " font-weight:bold; color:red\">" <<
tr(
"Note:")
57 <<
" <span style=\"font-weight:normal; color:black\">"
58 <<
tr(
"The search results may not be complete since the "
59 "documentation is still being indexed.")
60 <<
"</span></div></div><br>";
64 str <<
"<div style=\"text-align:left\"><a href=\""
67 "<div style =\"margin:5px\">" <<
result.
snippet() <<
"</div>";
70 str <<
"<div align=\"center\"><br><br><h2>"
71 <<
tr(
"Your search did not match any documents.")
74 str <<
"<div align=\"center\"><h3>"
75 <<
tr(
"(The reason for this might be that the documentation "
76 "is still being indexed.)") <<
"</h3><div>";
80 str <<
"</body></html>";
81#if QT_CONFIG(texthtmlparser)
108 QToolButton *button =
new QToolButton;
109 button->setEnabled(
false);
110 button->setAutoRaise(
true);
111 button->setIcon(QIcon(iconPath));
112 button->setIconSize({12, 12});
113 button->setMaximumSize({16, 16});
123 if (!searchEngine.isNull()) {
124 count = searchEngine->searchResultCount();
129 resultTextBrowser->showResultPage(searchEngine->searchResults(resultFirstToShow, last),
133 hitsLabel->setText(QHelpSearchResultWidget::tr(
"%1 - %2 of %n Hits",
nullptr, count)
134 .arg(first).arg(last));
135 firstResultPage->setEnabled(resultFirstToShow);
136 previousResultPage->setEnabled(resultFirstToShow);
137 lastResultPage->setEnabled(count - last);
138 nextResultPage->setEnabled(count - last);
156
157
158
159
160
161
164
165
166
167
168
170QHelpSearchResultWidget::QHelpSearchResultWidget(QHelpSearchEngine *engine)
172 , d(
new QHelpSearchResultWidgetPrivate)
175 d->searchEngine = engine;
177 connect(engine, &QHelpSearchEngine::indexingStarted,
this, [
this] { d->isIndexing =
true; });
178 connect(engine, &QHelpSearchEngine::indexingFinished,
this, [
this] { d->isIndexing =
false; });
180 QVBoxLayout *vLayout =
new QVBoxLayout(
this);
181 vLayout->setContentsMargins({});
182 vLayout->setSpacing(0);
184 QHBoxLayout *hBoxLayout =
new QHBoxLayout();
186 hBoxLayout->setContentsMargins({});
187 hBoxLayout->setSpacing(0);
189 hBoxLayout->addWidget(d->firstResultPage = d->setupToolButton(
190 QString::fromUtf8(
":/qt-project.org/assistant/images/3leftarrow.png")));
192 hBoxLayout->addWidget(d->previousResultPage = d->setupToolButton(
193 QString::fromUtf8(
":/qt-project.org/assistant/images/1leftarrow.png")));
195 d->hitsLabel =
new QLabel(tr(
"0 - 0 of 0 Hits"),
this);
196 hBoxLayout->addWidget(d->hitsLabel);
197 d->hitsLabel->setAlignment(Qt::AlignCenter);
198 d->hitsLabel->setMinimumSize(QSize(150, d->hitsLabel->height()));
200 hBoxLayout->addWidget(d->nextResultPage = d->setupToolButton(
201 QString::fromUtf8(
":/qt-project.org/assistant/images/1rightarrow.png")));
203 hBoxLayout->addWidget(d->lastResultPage = d->setupToolButton(
204 QString::fromUtf8(
":/qt-project.org/assistant/images/3rightarrow.png")));
206 QSpacerItem *spacer =
new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
207 hBoxLayout->addItem(spacer);
209 vLayout->addLayout(hBoxLayout);
211 d->resultTextBrowser =
new QResultWidget(
this);
212 vLayout->addWidget(d->resultTextBrowser);
214 connect(d->resultTextBrowser, &QResultWidget::requestShowLink,
215 this, &QHelpSearchResultWidget::requestShowLink);
217 connect(d->nextResultPage, &QAbstractButton::clicked,
this, [
this] {
218 if (!d->searchEngine.isNull()
219 && d->resultFirstToShow + ResultsRange < d->searchEngine->searchResultCount()) {
220 d->resultFirstToShow += ResultsRange;
224 connect(d->previousResultPage, &QAbstractButton::clicked,
this, [
this] {
225 if (!d->searchEngine.isNull()) {
226 d->resultFirstToShow -= ResultsRange;
227 if (d->resultFirstToShow < 0)
228 d->resultFirstToShow = 0;
232 connect(d->lastResultPage, &QAbstractButton::clicked,
this, [
this] {
233 if (!d->searchEngine.isNull())
234 d->resultFirstToShow = (d->searchEngine->searchResultCount() - 1) / ResultsRange * ResultsRange;
237 const auto showFirstPage = [
this] {
238 if (!d->searchEngine.isNull())
239 d->resultFirstToShow = 0;
242 connect(d->firstResultPage, &QAbstractButton::clicked,
this, showFirstPage);
243 connect(engine, &QHelpSearchEngine::searchingFinished,
this, showFirstPage);
247
248void QHelpSearchResultWidget::changeEvent(QEvent *event)
250 if (event->type() == QEvent::LanguageChange)
255
256
257QHelpSearchResultWidget::~QHelpSearchResultWidget()
263
264
265
266QUrl QHelpSearchResultWidget::linkAt(
const QPoint &point)
268 if (d->resultTextBrowser)
269 return QUrl(d->resultTextBrowser->anchorAt(point));
275#include "qhelpsearchresultwidget.moc"
Combined button and popup list for selecting options.