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)
48 str <<
"<html><head><title>" <<
tr(
"Search Results") <<
"</title></head><body>";
53 str <<
"<div style=\"text-align:left;"
54 " font-weight:bold; color:red\">" <<
tr(
"Note:")
55 <<
" <span style=\"font-weight:normal; color:black\">"
56 <<
tr(
"The search results may not be complete since the "
57 "documentation is still being indexed.")
58 <<
"</span></div></div><br>";
62 str <<
"<div style=\"text-align:left\"><a href=\""
65 "<div style =\"margin:5px\">" <<
result.
snippet() <<
"</div>";
68 str <<
"<div align=\"center\"><br><br><h2>"
69 <<
tr(
"Your search did not match any documents.")
72 str <<
"<div align=\"center\"><h3>"
73 <<
tr(
"(The reason for this might be that the documentation "
74 "is still being indexed.)") <<
"</h3><div>";
78 str <<
"</body></html>";
102 QToolButton *button =
new QToolButton;
103 button->setEnabled(
false);
104 button->setAutoRaise(
true);
105 button->setIcon(QIcon(iconPath));
106 button->setIconSize({12, 12});
107 button->setMaximumSize({16, 16});
117 if (!searchEngine.isNull()) {
118 count = searchEngine->searchResultCount();
123 resultTextBrowser->showResultPage(searchEngine->searchResults(resultFirstToShow, last),
127 hitsLabel->setText(QHelpSearchResultWidget::tr(
"%1 - %2 of %n Hits",
nullptr, count)
128 .arg(first).arg(last));
129 firstResultPage->setEnabled(resultFirstToShow);
130 previousResultPage->setEnabled(resultFirstToShow);
131 lastResultPage->setEnabled(count - last);
132 nextResultPage->setEnabled(count - last);
150
151
152
153
154
155
158
159
160
161
162
164QHelpSearchResultWidget::QHelpSearchResultWidget(QHelpSearchEngine *engine)
166 , d(
new QHelpSearchResultWidgetPrivate)
169 d->searchEngine = engine;
171 connect(engine, &QHelpSearchEngine::indexingStarted,
this, [
this] { d->isIndexing =
true; });
172 connect(engine, &QHelpSearchEngine::indexingFinished,
this, [
this] { d->isIndexing =
false; });
174 QVBoxLayout *vLayout =
new QVBoxLayout(
this);
175 vLayout->setContentsMargins({});
176 vLayout->setSpacing(0);
178 QHBoxLayout *hBoxLayout =
new QHBoxLayout();
180 hBoxLayout->setContentsMargins({});
181 hBoxLayout->setSpacing(0);
183 hBoxLayout->addWidget(d->firstResultPage = d->setupToolButton(
184 QString::fromUtf8(
":/qt-project.org/assistant/images/3leftarrow.png")));
186 hBoxLayout->addWidget(d->previousResultPage = d->setupToolButton(
187 QString::fromUtf8(
":/qt-project.org/assistant/images/1leftarrow.png")));
189 d->hitsLabel =
new QLabel(tr(
"0 - 0 of 0 Hits"),
this);
190 hBoxLayout->addWidget(d->hitsLabel);
191 d->hitsLabel->setAlignment(Qt::AlignCenter);
192 d->hitsLabel->setMinimumSize(QSize(150, d->hitsLabel->height()));
194 hBoxLayout->addWidget(d->nextResultPage = d->setupToolButton(
195 QString::fromUtf8(
":/qt-project.org/assistant/images/1rightarrow.png")));
197 hBoxLayout->addWidget(d->lastResultPage = d->setupToolButton(
198 QString::fromUtf8(
":/qt-project.org/assistant/images/3rightarrow.png")));
200 QSpacerItem *spacer =
new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
201 hBoxLayout->addItem(spacer);
203 vLayout->addLayout(hBoxLayout);
205 d->resultTextBrowser =
new QResultWidget(
this);
206 vLayout->addWidget(d->resultTextBrowser);
208 connect(d->resultTextBrowser, &QResultWidget::requestShowLink,
209 this, &QHelpSearchResultWidget::requestShowLink);
211 connect(d->nextResultPage, &QAbstractButton::clicked,
this, [
this] {
212 if (!d->searchEngine.isNull()
213 && d->resultFirstToShow + ResultsRange < d->searchEngine->searchResultCount()) {
214 d->resultFirstToShow += ResultsRange;
218 connect(d->previousResultPage, &QAbstractButton::clicked,
this, [
this] {
219 if (!d->searchEngine.isNull()) {
220 d->resultFirstToShow -= ResultsRange;
221 if (d->resultFirstToShow < 0)
222 d->resultFirstToShow = 0;
226 connect(d->lastResultPage, &QAbstractButton::clicked,
this, [
this] {
227 if (!d->searchEngine.isNull())
228 d->resultFirstToShow = (d->searchEngine->searchResultCount() - 1) / ResultsRange * ResultsRange;
231 const auto showFirstPage = [
this] {
232 if (!d->searchEngine.isNull())
233 d->resultFirstToShow = 0;
236 connect(d->firstResultPage, &QAbstractButton::clicked,
this, showFirstPage);
237 connect(engine, &QHelpSearchEngine::searchingFinished,
this, showFirstPage);
241
242void QHelpSearchResultWidget::changeEvent(QEvent *event)
244 if (event->type() == QEvent::LanguageChange)
249
250
251QHelpSearchResultWidget::~QHelpSearchResultWidget()
257
258
259
260QUrl QHelpSearchResultWidget::linkAt(
const QPoint &point)
262 if (d->resultTextBrowser)
263 return QUrl(d->resultTextBrowser->anchorAt(point));
269#include "qhelpsearchresultwidget.moc"
Combined button and popup list for selecting options.