6#include <QtCore/qcoreevent.h>
7#include <QtCore/qlist.h>
8#include <QtCore/qpointer.h>
9#include <QtCore/qtextstream.h>
10#include <QtWidgets/qlabel.h>
11#include <QtWidgets/qlayout.h>
12#include <QtWidgets/qlayoutitem.h>
13#include <QtWidgets/qtoolbutton.h>
14#include <QtWidgets/qtextbrowser.h>
23 Q_PROPERTY(QColor linkColor READ linkColor WRITE setLinkColor)
47 str <<
"<html><head><title>" <<
tr(
"Search Results") <<
"</title></head><body>";
52 str <<
"<div style=\"text-align:left;"
53 " font-weight:bold; color:red\">" <<
tr(
"Note:")
54 <<
" <span style=\"font-weight:normal; color:black\">"
55 <<
tr(
"The search results may not be complete since the "
56 "documentation is still being indexed.")
57 <<
"</span></div></div><br>";
61 str <<
"<div style=\"text-align:left\"><a href=\""
64 "<div style =\"margin:5px\">" <<
result.
snippet() <<
"</div>";
67 str <<
"<div align=\"center\"><br><br><h2>"
68 <<
tr(
"Your search did not match any documents.")
71 str <<
"<div align=\"center\"><h3>"
72 <<
tr(
"(The reason for this might be that the documentation "
73 "is still being indexed.)") <<
"</h3><div>";
77 str <<
"</body></html>";
101 QToolButton *button =
new QToolButton;
102 button->setEnabled(
false);
103 button->setAutoRaise(
true);
104 button->setIcon(QIcon(iconPath));
105 button->setIconSize({12, 12});
106 button->setMaximumSize({16, 16});
116 if (!searchEngine.isNull()) {
117 count = searchEngine->searchResultCount();
122 resultTextBrowser->showResultPage(searchEngine->searchResults(resultFirstToShow, last),
126 hitsLabel->setText(QHelpSearchResultWidget::tr(
"%1 - %2 of %n Hits",
nullptr, count)
127 .arg(first).arg(last));
128 firstResultPage->setEnabled(resultFirstToShow);
129 previousResultPage->setEnabled(resultFirstToShow);
130 lastResultPage->setEnabled(count - last);
131 nextResultPage->setEnabled(count - last);
149
150
151
152
153
154
157
158
159
160
161
163QHelpSearchResultWidget::QHelpSearchResultWidget(QHelpSearchEngine *engine)
165 , d(
new QHelpSearchResultWidgetPrivate)
168 d->searchEngine = engine;
170 connect(engine, &QHelpSearchEngine::indexingStarted,
this, [
this] { d->isIndexing =
true; });
171 connect(engine, &QHelpSearchEngine::indexingFinished,
this, [
this] { d->isIndexing =
false; });
173 QVBoxLayout *vLayout =
new QVBoxLayout(
this);
174 vLayout->setContentsMargins({});
175 vLayout->setSpacing(0);
177 QHBoxLayout *hBoxLayout =
new QHBoxLayout();
179 hBoxLayout->setContentsMargins({});
180 hBoxLayout->setSpacing(0);
182 hBoxLayout->addWidget(d->firstResultPage = d->setupToolButton(
183 QString::fromUtf8(
":/qt-project.org/assistant/images/3leftarrow.png")));
185 hBoxLayout->addWidget(d->previousResultPage = d->setupToolButton(
186 QString::fromUtf8(
":/qt-project.org/assistant/images/1leftarrow.png")));
188 d->hitsLabel =
new QLabel(tr(
"0 - 0 of 0 Hits"),
this);
189 hBoxLayout->addWidget(d->hitsLabel);
190 d->hitsLabel->setAlignment(Qt::AlignCenter);
191 d->hitsLabel->setMinimumSize(QSize(150, d->hitsLabel->height()));
193 hBoxLayout->addWidget(d->nextResultPage = d->setupToolButton(
194 QString::fromUtf8(
":/qt-project.org/assistant/images/1rightarrow.png")));
196 hBoxLayout->addWidget(d->lastResultPage = d->setupToolButton(
197 QString::fromUtf8(
":/qt-project.org/assistant/images/3rightarrow.png")));
199 QSpacerItem *spacer =
new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
200 hBoxLayout->addItem(spacer);
202 vLayout->addLayout(hBoxLayout);
204 d->resultTextBrowser =
new QResultWidget(
this);
205 vLayout->addWidget(d->resultTextBrowser);
207 connect(d->resultTextBrowser, &QResultWidget::requestShowLink,
208 this, &QHelpSearchResultWidget::requestShowLink);
210 connect(d->nextResultPage, &QAbstractButton::clicked,
this, [
this] {
211 if (!d->searchEngine.isNull()
212 && d->resultFirstToShow + ResultsRange < d->searchEngine->searchResultCount()) {
213 d->resultFirstToShow += ResultsRange;
217 connect(d->previousResultPage, &QAbstractButton::clicked,
this, [
this] {
218 if (!d->searchEngine.isNull()) {
219 d->resultFirstToShow -= ResultsRange;
220 if (d->resultFirstToShow < 0)
221 d->resultFirstToShow = 0;
225 connect(d->lastResultPage, &QAbstractButton::clicked,
this, [
this] {
226 if (!d->searchEngine.isNull())
227 d->resultFirstToShow = (d->searchEngine->searchResultCount() - 1) / ResultsRange * ResultsRange;
230 const auto showFirstPage = [
this] {
231 if (!d->searchEngine.isNull())
232 d->resultFirstToShow = 0;
235 connect(d->firstResultPage, &QAbstractButton::clicked,
this, showFirstPage);
236 connect(engine, &QHelpSearchEngine::searchingFinished,
this, showFirstPage);
240
241void QHelpSearchResultWidget::changeEvent(QEvent *event)
243 if (event->type() == QEvent::LanguageChange)
248
249
250QHelpSearchResultWidget::~QHelpSearchResultWidget()
256
257
258
259QUrl QHelpSearchResultWidget::linkAt(
const QPoint &point)
261 if (d->resultTextBrowser)
262 return d->resultTextBrowser->anchorAt(point);
268#include "qhelpsearchresultwidget.moc"
Combined button and popup list for selecting options.