From af30aeb6a1ebb7307f06c122c0c93d152f4d958c Mon Sep 17 00:00:00 2001 From: ck Date: Thu, 21 Jan 2010 12:46:38 +0100 Subject: QtHelp: Enable dynamic translation. Task-number: QTBUG-7420 Reviewed-by: kh1 --- tools/assistant/lib/qhelpsearchquerywidget.cpp | 71 ++++++++++++++++++------- tools/assistant/lib/qhelpsearchquerywidget.h | 3 +- tools/assistant/lib/qhelpsearchresultwidget.cpp | 8 +++ tools/assistant/lib/qhelpsearchresultwidget.h | 1 + 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/tools/assistant/lib/qhelpsearchquerywidget.cpp b/tools/assistant/lib/qhelpsearchquerywidget.cpp index a2b3ca2..b614cb4 100644 --- a/tools/assistant/lib/qhelpsearchquerywidget.cpp +++ b/tools/assistant/lib/qhelpsearchquerywidget.cpp @@ -120,6 +120,22 @@ private: // nothing todo } + void retranslate() + { + simpleSearchLabel->setText(tr("Search for:")); + prevQueryButton->setToolTip(tr("Previous search")); + nextQueryButton->setToolTip(tr("Next search")); + searchButton->setText(tr("Search")); +#ifdef QT_CLUCENE_SUPPORT + advancedSearchLabel->setText(tr("Advanced search")); + similarLabel->setText(tr("words similar to:")); + withoutLabel->setText(tr("without the words:")); + exactLabel->setText(tr("with exact phrase:")); + allLabel->setText(tr("with all of the words:")); + atLeastLabel->setText(tr("with at least one of the words:")); +#endif + } + QString escapeString(const QString &text) { QString retValue = text; @@ -360,6 +376,13 @@ private: friend class QHelpSearchQueryWidget; bool simpleSearch; + QLabel *simpleSearchLabel; + QLabel *advancedSearchLabel; + QLabel *similarLabel; + QLabel *withoutLabel; + QLabel *exactLabel; + QLabel *allLabel; + QLabel *atLeastLabel; QPushButton *searchButton; QWidget* advancedSearchWidget; QToolButton *showHideAdvancedSearchButton; @@ -408,19 +431,17 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent) vLayout->setMargin(0); QHBoxLayout* hBoxLayout = new QHBoxLayout(); - QLabel *label = new QLabel(tr("Search for:"), this); + d->simpleSearchLabel = new QLabel(this); d->defaultQuery = new QLineEdit(this); d->defaultQuery->setCompleter(&d->searchCompleter); d->prevQueryButton = new QToolButton(this); d->prevQueryButton->setArrowType(Qt::LeftArrow); - d->prevQueryButton->setToolTip(tr("Previous search")); d->prevQueryButton->setEnabled(false); d->nextQueryButton = new QToolButton(this); d->nextQueryButton->setArrowType(Qt::RightArrow); - d->nextQueryButton->setToolTip(tr("Next search")); d->nextQueryButton->setEnabled(false); - d->searchButton = new QPushButton(tr("Search"), this); - hBoxLayout->addWidget(label); + d->searchButton = new QPushButton(this); + hBoxLayout->addWidget(d->simpleSearchLabel); hBoxLayout->addWidget(d->defaultQuery); hBoxLayout->addWidget(d->prevQueryButton); hBoxLayout->addWidget(d->nextQueryButton); @@ -439,15 +460,15 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent) d->showHideAdvancedSearchButton->setText(QLatin1String("+")); d->showHideAdvancedSearchButton->setMinimumSize(25, 20); - label = new QLabel(tr("Advanced search"), this); + d->advancedSearchLabel = new QLabel(this); QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); - sizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth()); - label->setSizePolicy(sizePolicy); + sizePolicy.setHeightForWidth(d->advancedSearchLabel->sizePolicy().hasHeightForWidth()); + d->advancedSearchLabel->setSizePolicy(sizePolicy); QFrame* hLine = new QFrame(this); hLine->setFrameStyle(QFrame::HLine); hBoxLayout->addWidget(d->showHideAdvancedSearchButton); - hBoxLayout->addWidget(label); + hBoxLayout->addWidget(d->advancedSearchLabel); hBoxLayout->addWidget(hLine); vLayout->addLayout(hBoxLayout); @@ -457,32 +478,32 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent) QGridLayout *gLayout = new QGridLayout(d->advancedSearchWidget); gLayout->setMargin(0); - label = new QLabel(tr("words similar to:"), this); - gLayout->addWidget(label, 0, 0); + d->similarLabel = new QLabel(this); + gLayout->addWidget(d->similarLabel, 0, 0); d->similarQuery = new QLineEdit(this); d->similarQuery->setCompleter(&d->searchCompleter); gLayout->addWidget(d->similarQuery, 0, 1); - label = new QLabel(tr("without the words:"), this); - gLayout->addWidget(label, 1, 0); + d->withoutLabel = new QLabel(this); + gLayout->addWidget(d->withoutLabel, 1, 0); d->withoutQuery = new QLineEdit(this); d->withoutQuery->setCompleter(&d->searchCompleter); gLayout->addWidget(d->withoutQuery, 1, 1); - label = new QLabel(tr("with exact phrase:"), this); - gLayout->addWidget(label, 2, 0); + d->exactLabel = new QLabel(this); + gLayout->addWidget(d->exactLabel, 2, 0); d->exactQuery = new QLineEdit(this); d->exactQuery->setCompleter(&d->searchCompleter); gLayout->addWidget(d->exactQuery, 2, 1); - label = new QLabel(tr("with all of the words:"), this); - gLayout->addWidget(label, 3, 0); + d->allLabel = new QLabel(this); + gLayout->addWidget(d->allLabel, 3, 0); d->allQuery = new QLineEdit(this); d->allQuery->setCompleter(&d->searchCompleter); gLayout->addWidget(d->allQuery, 3, 1); - label = new QLabel(tr("with at least one of the words:"), this); - gLayout->addWidget(label, 4, 0); + d->atLeastLabel = new QLabel(this); + gLayout->addWidget(d->atLeastLabel, 4, 0); d->atLeastQuery = new QLineEdit(this); d->atLeastQuery->setCompleter(&d->searchCompleter); gLayout->addWidget(d->atLeastQuery, 4, 1); @@ -490,6 +511,8 @@ QHelpSearchQueryWidget::QHelpSearchQueryWidget(QWidget *parent) vLayout->addWidget(d->advancedSearchWidget); d->advancedSearchWidget->hide(); + d->retranslate(); + connect(d->exactQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); connect(d->similarQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); connect(d->withoutQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); @@ -531,4 +554,14 @@ void QHelpSearchQueryWidget::focusInEvent(QFocusEvent *focusEvent) } } +/*! \reimp +*/ +void QHelpSearchQueryWidget::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + d->retranslate(); + else + QWidget::changeEvent(event); +} + QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchquerywidget.h b/tools/assistant/lib/qhelpsearchquerywidget.h index a99bae0..2afc4b4 100644 --- a/tools/assistant/lib/qhelpsearchquerywidget.h +++ b/tools/assistant/lib/qhelpsearchquerywidget.h @@ -74,7 +74,8 @@ Q_SIGNALS: void search(); private: - void focusInEvent(QFocusEvent *focusEvent); + virtual void focusInEvent(QFocusEvent *focusEvent); + virtual void changeEvent(QEvent *event); private: QHelpSearchQueryWidgetPrivate *d; diff --git a/tools/assistant/lib/qhelpsearchresultwidget.cpp b/tools/assistant/lib/qhelpsearchresultwidget.cpp index 3cac880..a3f5aed 100644 --- a/tools/assistant/lib/qhelpsearchresultwidget.cpp +++ b/tools/assistant/lib/qhelpsearchresultwidget.cpp @@ -408,6 +408,14 @@ QHelpSearchResultWidget::QHelpSearchResultWidget(QHelpSearchEngine *engine) connect(engine, SIGNAL(searchingFinished(int)), d, SLOT(setResults(int))); } +/*! \reimp +*/ +void QHelpSearchResultWidget::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + d->setResults(d->searchEngine->hitCount()); +} + /*! Destroys the search result widget. */ diff --git a/tools/assistant/lib/qhelpsearchresultwidget.h b/tools/assistant/lib/qhelpsearchresultwidget.h index d078079..ff29adc 100644 --- a/tools/assistant/lib/qhelpsearchresultwidget.h +++ b/tools/assistant/lib/qhelpsearchresultwidget.h @@ -75,6 +75,7 @@ private: QHelpSearchResultWidgetPrivate *d; QHelpSearchResultWidget(QHelpSearchEngine *engine); + virtual void changeEvent(QEvent *event); }; QT_END_NAMESPACE -- cgit v0.12