diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-10 10:01:53 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-10 10:01:53 (GMT) |
commit | 3308925558677f1882f1c70ef6b86f8a83fa8b65 (patch) | |
tree | 38afacf496400fbd33ee2a5821a5369910421639 /tools | |
parent | f74029e286e97067ac39086955481bf979af69dc (diff) | |
parent | 54290ef776a311f0c303e2a8df4de5e39e9a032a (diff) | |
download | Qt-3308925558677f1882f1c70ef6b86f8a83fa8b65.zip Qt-3308925558677f1882f1c70ef6b86f8a83fa8b65.tar.gz Qt-3308925558677f1882f1c70ef6b86f8a83fa8b65.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/berlin-staging-1 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/berlin-staging-1:
Added method to clear the undo/redo stacks.
Fixed setting back spaces when streaming a QPointF
Move find widget in it's own source file. Some further cleanup.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/assistant/tools/assistant/assistant.pro | 2 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/centralwidget.cpp | 250 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/centralwidget.h | 74 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/findwidget.cpp | 233 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/findwidget.h | 101 |
5 files changed, 394 insertions, 266 deletions
diff --git a/tools/assistant/tools/assistant/assistant.pro b/tools/assistant/tools/assistant/assistant.pro index e62d30c..edaf076 100644 --- a/tools/assistant/tools/assistant/assistant.pro +++ b/tools/assistant/tools/assistant/assistant.pro @@ -25,6 +25,7 @@ HEADERS += aboutdialog.h \ centralwidget.h \ cmdlineparser.h \ contentwindow.h \ + findwidget.h \ filternamedialog.h \ helpenginewrapper.h \ helpviewer.h \ @@ -50,6 +51,7 @@ SOURCES += aboutdialog.cpp \ centralwidget.cpp \ cmdlineparser.cpp \ contentwindow.cpp \ + findwidget.cpp \ filternamedialog.cpp \ helpenginewrapper.cpp \ helpviewer.cpp \ diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index 8bb2ffe..03af06c 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -41,34 +41,26 @@ #include "tracer.h" #include "centralwidget.h" +#include "findwidget.h" #include "helpenginewrapper.h" #include "helpviewer.h" #include "searchwidget.h" #include "mainwindow.h" -#include "preferencesdialog.h" #include "../shared/collectionconfiguration.h" -#include <QtCore/QDir> -#include <QtCore/QEvent> #include <QtCore/QTimer> -#include <QtGui/QMenu> -#include <QtGui/QLabel> +#include <QtGui/QApplication> +#include <QtGui/QKeyEvent> #include <QtGui/QLayout> +#include <QtGui/QMenu> #include <QtGui/QPrinter> -#include <QtGui/QLineEdit> -#include <QtGui/QCheckBox> #include <QtGui/QTabBar> #include <QtGui/QTabWidget> #include <QtGui/QToolButton> -#include <QtGui/QMouseEvent> -#include <QtGui/QSpacerItem> -#include <QtGui/QTextCursor> +#include <QtGui/QPageSetupDialog> #include <QtGui/QPrintDialog> -#include <QtGui/QApplication> -#include <QtGui/QTextDocumentFragment> #include <QtGui/QPrintPreviewDialog> -#include <QtGui/QPageSetupDialog> #include <QtHelp/QHelpSearchEngine> @@ -88,135 +80,13 @@ namespace { CentralWidget *staticCentralWidget = 0; } -FindWidget::FindWidget(QWidget *parent) - : QWidget(parent) - , appPalette(qApp->palette()) -{ - TRACE_OBJ - QHBoxLayout *hboxLayout = new QHBoxLayout(this); - QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); - -#ifndef Q_OS_MAC - hboxLayout->setMargin(0); - hboxLayout->setSpacing(6); - resourcePath.append(QLatin1String("win")); -#else - resourcePath.append(QLatin1String("mac")); -#endif - - toolClose = setupToolButton(QLatin1String(""), - resourcePath + QLatin1String("/closetab.png")); - hboxLayout->addWidget(toolClose); - - editFind = new QLineEdit(this); - hboxLayout->addWidget(editFind); - editFind->setMinimumSize(QSize(150, 0)); - connect(editFind, SIGNAL(textChanged(QString)), this, SLOT(updateButtons())); - toolPrevious = setupToolButton(tr("Previous"), - resourcePath + QLatin1String("/previous.png")); - hboxLayout->addWidget(toolPrevious); - - toolNext = setupToolButton(tr("Next"), - resourcePath + QLatin1String("/next.png")); - hboxLayout->addWidget(toolNext); - - checkCase = new QCheckBox(tr("Case Sensitive"), this); - hboxLayout->addWidget(checkCase); - - checkWholeWords = new QCheckBox(tr("Whole words"), this); - hboxLayout->addWidget(checkWholeWords); -#if !defined(QT_NO_WEBKIT) - checkWholeWords->hide(); -#endif - - labelWrapped = new QLabel(this); - labelWrapped->setScaledContents(true); - labelWrapped->setTextFormat(Qt::RichText); - labelWrapped->setMinimumSize(QSize(0, 20)); - labelWrapped->setMaximumSize(QSize(105, 20)); - labelWrapped->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); - labelWrapped->setText(tr("<img src=\":/trolltech/assistant/images/wrap.png\"" - "> Search wrapped")); - hboxLayout->addWidget(labelWrapped); - - QSpacerItem *spacerItem = new QSpacerItem(20, 20, QSizePolicy::Expanding, - QSizePolicy::Minimum); - hboxLayout->addItem(spacerItem); - setMinimumWidth(minimumSizeHint().width()); - labelWrapped->hide(); - - updateButtons(); -} - -FindWidget::~FindWidget() -{ - TRACE_OBJ -} - -void FindWidget::hideEvent(QHideEvent* event) -{ - TRACE_OBJ -#if !defined(QT_NO_WEBKIT) - // TODO: remove this once webkit supports setting the palette - if (!event->spontaneous()) - qApp->setPalette(appPalette); -#else - Q_UNUSED(event); -#endif -} - -void FindWidget::showEvent(QShowEvent* event) -{ - TRACE_OBJ -#if !defined(QT_NO_WEBKIT) - // TODO: remove this once webkit supports setting the palette - if (!event->spontaneous()) { - QPalette p = appPalette; - p.setColor(QPalette::Inactive, QPalette::Highlight, - p.color(QPalette::Active, QPalette::Highlight)); - p.setColor(QPalette::Inactive, QPalette::HighlightedText, - p.color(QPalette::Active, QPalette::HighlightedText)); - qApp->setPalette(p); - } -#else - Q_UNUSED(event); -#endif -} - -void FindWidget::updateButtons() -{ - TRACE_OBJ - if (editFind->text().isEmpty()) { - toolPrevious->setEnabled(false); - toolNext->setEnabled(false); - } else { - toolPrevious->setEnabled(true); - toolNext->setEnabled(true); - } -} - -QToolButton* FindWidget::setupToolButton(const QString &text, const QString &icon) -{ - TRACE_OBJ - QToolButton *toolButton = new QToolButton(this); - - toolButton->setText(text); - toolButton->setAutoRaise(true); - toolButton->setIcon(QIcon(icon)); - toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - - return toolButton; -} - - -// -- +// -- CentralWidget CentralWidget::CentralWidget(MainWindow *parent) : QWidget(parent) , lastTabPage(0) - , findBar(0) , tabWidget(0) , findWidget(0) , printer(0) @@ -260,20 +130,15 @@ CentralWidget::CentralWidget(MainWindow *parent) vboxLayout->addWidget(tabWidget); - findBar = new QWidget(this); - findWidget = new FindWidget(findBar); - findBar->setMinimumHeight(findWidget->minimumSizeHint().height()); - findWidget->move(0, 0); - vboxLayout->addWidget(findBar); - findBar->hide(); - findWidget->editFind->installEventFilter(this); - - connect(findWidget->toolClose, SIGNAL(clicked()), findBar, SLOT(hide())); - connect(findWidget->toolNext, SIGNAL(clicked()), this, SLOT(findNext())); - connect(findWidget->editFind, SIGNAL(returnPressed()), this, SLOT(findNext())); - connect(findWidget->editFind, SIGNAL(textChanged(QString)), this, - SLOT(findCurrentText(QString))); - connect(findWidget->toolPrevious, SIGNAL(clicked()), this, SLOT(findPrevious())); + findWidget = new FindWidget(this); + vboxLayout->addWidget(findWidget); + findWidget->hide(); + + connect(findWidget, SIGNAL(findNext()), this, SLOT(findNext())); + connect(findWidget, SIGNAL(findPrevious()), this, SLOT(findPrevious())); + connect(findWidget, SIGNAL(find(QString, bool)), this, + SLOT(find(QString, bool))); + connect(findWidget, SIGNAL(escapePressed()), this, SLOT(activateTab())); QTabBar *tabBar = qFindChild<QTabBar*>(tabWidget); if (tabBar) { @@ -360,12 +225,6 @@ void CentralWidget::zoomOut() m_searchWidget->zoomOut(); } -void CentralWidget::findNext() -{ - TRACE_OBJ - find(findWidget->editFind->text(), true); -} - void CentralWidget::nextPage() { TRACE_OBJ @@ -395,12 +254,6 @@ void CentralWidget::previousPage() tabWidget->setCurrentIndex(index); } -void CentralWidget::findPrevious() -{ - TRACE_OBJ - find(findWidget->editFind->text(), false); -} - void CentralWidget::closeTab() { TRACE_OBJ @@ -527,9 +380,7 @@ void CentralWidget::copySelection() void CentralWidget::showTextSearch() { TRACE_OBJ - findBar->show(); - findWidget->editFind->selectAll(); - findWidget->editFind->setFocus(Qt::ShortcutFocusReason); + findWidget->show(); } void CentralWidget::initPrinter() @@ -708,12 +559,6 @@ HelpViewer *CentralWidget::newEmptyTab() return viewer; } -void CentralWidget::findCurrentText(const QString &text) -{ - TRACE_OBJ - find(text, true); -} - void CentralWidget::connectSignals() { TRACE_OBJ @@ -855,14 +700,6 @@ bool CentralWidget::eventFilter(QObject *object, QEvent *e) return QWidget::eventFilter(object, e); } break; - case Qt::Key_Escape: { - if (findWidget->editFind == object) { - findBar->hide(); - if (HelpViewer *viewer = currentHelpViewer()) - viewer->setFocus(); - } - } break; - case Qt::Key_Backspace: { HelpViewer *viewer = currentHelpViewer(); if (viewer == object) { @@ -906,38 +743,43 @@ void CentralWidget::keyPressEvent(QKeyEvent *e) TRACE_OBJ const QString &text = e->text(); if (text.startsWith(QLatin1Char('/'))) { - if (!findBar->isVisible()) { - findBar->show(); - findWidget->editFind->clear(); + if (!findWidget->isVisible()) { + findWidget->showAndClear(); } else { - findWidget->editFind->selectAll(); + findWidget->show(); } - findWidget->editFind->setFocus(); - return; + } else { + QWidget::keyPressEvent(e); } - QWidget::keyPressEvent(e); } -void CentralWidget::find(const QString &ttf, bool forward) +void CentralWidget::findNext() +{ + find(findWidget->text(), true); +} + +void CentralWidget::findPrevious() { TRACE_OBJ - QPalette p = findWidget->editFind->palette(); - p.setColor(QPalette::Active, QPalette::Base, Qt::white); + find(findWidget->text(), false); +} +void CentralWidget::find(const QString &ttf, bool forward) +{ + TRACE_OBJ bool found = false; - #if defined(QT_NO_WEBKIT) found = findInTextBrowser(ttf, forward); #else found = findInWebPage(ttf, forward); #endif - if (!found && !ttf.isEmpty()) - p.setColor(QPalette::Active, QPalette::Base, QColor(255, 102, 102)); + if (!found && ttf.isEmpty()) + found = true; // the line edit is empty, no need to mark it red... if (!findWidget->isVisible()) findWidget->show(); - findWidget->editFind->setPalette(p); + findWidget->setPalette(found); } bool CentralWidget::findInWebPage(const QString &ttf, bool forward) @@ -951,21 +793,23 @@ bool CentralWidget::findInWebPage(const QString &ttf, bool forward) if (!forward) options |= QWebPage::FindBackward; - if (findWidget->checkCase->isChecked()) + if (findWidget->caseSensitive()) options |= QWebPage::FindCaseSensitively; found = viewer->findText(ttf, options); - findWidget->labelWrapped->hide(); + findWidget->setTextWrappedVisible(false); if (!found) { options |= QWebPage::FindWrapsAroundDocument; found = viewer->findText(ttf, options); if (found) - findWidget->labelWrapped->show(); + findWidget->setTextWrappedVisible(true); } } // force highlighting of all other matches, also when empty (clear) options = QWebPage::HighlightAllOccurrences; + if (findWidget->caseSensitive()) + options |= QWebPage::FindCaseSensitively; viewer->findText(QLatin1String(""), options); viewer->findText(ttf, options); return found; @@ -1006,13 +850,10 @@ bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward) if (!forward) options |= QTextDocument::FindBackward; - if (findWidget->checkCase->isChecked()) + if (findWidget->caseSensitive()) options |= QTextDocument::FindCaseSensitively; - if (findWidget->checkWholeWords->isChecked()) - options |= QTextDocument::FindWholeWords; - - findWidget->labelWrapped->hide(); + findWidget->setTextWrappedVisible(false); bool found = true; QTextCursor newCursor = doc->find(ttf, cursor, options); @@ -1025,7 +866,7 @@ bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward) found = false; newCursor = cursor; } else { - findWidget->labelWrapped->show(); + findWidget->setTextWrappedVisible(true); } } browser->setTextCursor(newCursor); @@ -1048,6 +889,11 @@ void CentralWidget::updateBrowserFont() setBrowserFontFor(tabWidget->widget(i), font); } +bool CentralWidget::searchWidgetAttached() const +{ + return m_searchWidget && m_searchWidget->isAttached(); +} + void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine) { TRACE_OBJ diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h index a7c0d6f..6c3e93c 100644 --- a/tools/assistant/tools/assistant/centralwidget.h +++ b/tools/assistant/tools/assistant/centralwidget.h @@ -38,72 +38,20 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #ifndef CENTRALWIDGET_H #define CENTRALWIDGET_H -#include <QtCore/QList> #include <QtCore/QUrl> -#include <QtCore/QPoint> -#include <QtCore/QObject> - #include <QtGui/QWidget> -#include "searchwidget.h" - QT_BEGIN_NAMESPACE -class QEvent; -class QLabel; -class QAction; -class QCheckBox; -class QLineEdit; -class QTextBrowser; -class QToolButton; - +class FindWidget; class HelpViewer; -class QTabWidget; -class QHelpEngine; -class CentralWidget; -class PrintHelper; class MainWindow; - class QHelpSearchEngine; - -class FindWidget : public QWidget -{ - Q_OBJECT - -public: - FindWidget(QWidget *parent = 0); - ~FindWidget(); - -signals: - void findNext(); - void findPrevious(); - -protected: - void hideEvent(QHideEvent* event); - void showEvent(QShowEvent * event); - -private slots: - void updateButtons(); - -private: - QToolButton* setupToolButton(const QString &text, const QString &icon); - -private: - QLineEdit *editFind; - QCheckBox *checkCase; - QLabel *labelWrapped; - QToolButton *toolNext; - QToolButton *toolClose; - QToolButton *toolPrevious; - QCheckBox *checkWholeWords; - - QPalette appPalette; - friend class CentralWidget; -}; +class QTabWidget; +class SearchWidget; class CentralWidget : public QWidget { @@ -123,11 +71,8 @@ public: QList<QAction*> globalActions() const; void setGlobalActions(const QList<QAction*> &actions); HelpViewer *currentHelpViewer() const; - void activateTab(bool onlyHelpViewer = false); - bool searchWidgetAttached() const { - return m_searchWidget && m_searchWidget->isAttached(); - } + bool searchWidgetAttached() const; void createSearchWidget(QHelpSearchEngine *searchEngine); void activateSearchWidget(bool updateLastTabPage = false); void removeSearchWidget(); @@ -144,11 +89,9 @@ public: public slots: void zoomIn(); void zoomOut(); - void findNext(); void nextPage(); void resetZoom(); void previousPage(); - void findPrevious(); void copySelection(); void showTextSearch(); void print(); @@ -157,12 +100,17 @@ public slots: void updateBrowserFont(); void setSource(const QUrl &url); void setSourceInNewTab(const QUrl &url, qreal zoom = 0.0); - void findCurrentText(const QString &text); HelpViewer *newEmptyTab(); void home(); void forward(); void backward(); + void activateTab(bool onlyHelpViewer = false); + + void findNext(); + void findPrevious(); + void find(const QString &text, bool forward); + signals: void currentViewerChanged(); void copyAvailable(bool yes); @@ -189,7 +137,6 @@ private slots: private: void connectSignals(); bool eventFilter(QObject *object, QEvent *e); - void find(const QString &ttf, bool forward); bool findInWebPage(const QString &ttf, bool forward); bool findInTextBrowser(const QString &ttf, bool forward); void initPrinter(); @@ -203,7 +150,6 @@ private: int lastTabPage; QList<QAction*> globalActionList; - QWidget *findBar; QTabWidget *tabWidget; FindWidget *findWidget; QPrinter *printer; diff --git a/tools/assistant/tools/assistant/findwidget.cpp b/tools/assistant/tools/assistant/findwidget.cpp new file mode 100644 index 0000000..2e40ab0 --- /dev/null +++ b/tools/assistant/tools/assistant/findwidget.cpp @@ -0,0 +1,233 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Assistant of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "tracer.h" +#include "findwidget.h" + +#include <QtGui/QApplication> +#include <QtGui/QCheckBox> +#include <QtGui/QHideEvent> +#include <QtGui/QKeyEvent> +#include <QtGui/QLabel> +#include <QtGui/QLayout> +#include <QtGui/QLineEdit> +#include <QtGui/QToolButton> + +QT_BEGIN_NAMESPACE + +FindWidget::FindWidget(QWidget *parent) + : QWidget(parent) + , appPalette(qApp->palette()) +{ + TRACE_OBJ + installEventFilter(this); + QHBoxLayout *hboxLayout = new QHBoxLayout(this); + QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); + +#ifndef Q_OS_MAC + hboxLayout->setMargin(0); + hboxLayout->setSpacing(6); + resourcePath.append(QLatin1String("win")); +#else + resourcePath.append(QLatin1String("mac")); +#endif + + toolClose = setupToolButton(QLatin1String(""), + resourcePath + QLatin1String("/closetab.png")); + hboxLayout->addWidget(toolClose); + + editFind = new QLineEdit(this); + hboxLayout->addWidget(editFind); + editFind->setMinimumSize(QSize(150, 0)); + connect(editFind, SIGNAL(textChanged(QString)), this, + SLOT(textChanged(QString))); + connect(editFind, SIGNAL(returnPressed()), this, SIGNAL(findNext())); + connect(editFind, SIGNAL(textChanged(QString)), this, SLOT(updateButtons())); + + toolPrevious = setupToolButton(tr("Previous"), + resourcePath + QLatin1String("/previous.png")); + connect(toolPrevious, SIGNAL(clicked()), this, SIGNAL(findPrevious())); + + hboxLayout->addWidget(toolPrevious); + + toolNext = setupToolButton(tr("Next"), + resourcePath + QLatin1String("/next.png")); + hboxLayout->addWidget(toolNext); + connect(toolNext, SIGNAL(clicked()), this, SIGNAL(findNext())); + + checkCase = new QCheckBox(tr("Case Sensitive"), this); + hboxLayout->addWidget(checkCase); + + labelWrapped = new QLabel(this); + labelWrapped->setScaledContents(true); + labelWrapped->setTextFormat(Qt::RichText); + labelWrapped->setMinimumSize(QSize(0, 20)); + labelWrapped->setMaximumSize(QSize(105, 20)); + labelWrapped->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); + labelWrapped->setText(tr("<img src=\":/trolltech/assistant/images/wrap.png\"" + "> Search wrapped")); + hboxLayout->addWidget(labelWrapped); + + QSpacerItem *spacerItem = new QSpacerItem(20, 20, QSizePolicy::Expanding, + QSizePolicy::Minimum); + hboxLayout->addItem(spacerItem); + setMinimumWidth(minimumSizeHint().width()); + labelWrapped->hide(); + + updateButtons(); +} + +FindWidget::~FindWidget() +{ + TRACE_OBJ +} + +void FindWidget::show() +{ + TRACE_OBJ + QWidget::show(); + editFind->selectAll(); + editFind->setFocus(Qt::ShortcutFocusReason); +} + +void FindWidget::showAndClear() +{ + TRACE_OBJ + show(); + editFind->clear(); +} + +QString FindWidget::text() const +{ + TRACE_OBJ + return editFind->text(); +} + +bool FindWidget::caseSensitive() const +{ + TRACE_OBJ + return checkCase->isChecked(); +} + +void FindWidget::setPalette(bool found) +{ + TRACE_OBJ + QPalette palette = editFind->palette(); + palette.setColor(QPalette::Active, QPalette::Base, found ? Qt::white + : QColor(255, 102, 102)); + editFind->setPalette(palette); +} + +void FindWidget::setTextWrappedVisible(bool visible) +{ + TRACE_OBJ + labelWrapped->setVisible(visible); +} + +void FindWidget::hideEvent(QHideEvent* event) +{ + TRACE_OBJ +#if !defined(QT_NO_WEBKIT) + // TODO: remove this once webkit supports setting the palette + if (!event->spontaneous()) + qApp->setPalette(appPalette); +#else + Q_UNUSED(event); +#endif +} + +void FindWidget::showEvent(QShowEvent* event) +{ + TRACE_OBJ +#if !defined(QT_NO_WEBKIT) + // TODO: remove this once webkit supports setting the palette + if (!event->spontaneous()) { + QPalette p = appPalette; + p.setColor(QPalette::Inactive, QPalette::Highlight, + p.color(QPalette::Active, QPalette::Highlight)); + p.setColor(QPalette::Inactive, QPalette::HighlightedText, + p.color(QPalette::Active, QPalette::HighlightedText)); + qApp->setPalette(p); + } +#else + Q_UNUSED(event); +#endif +} + +void FindWidget::updateButtons() +{ + TRACE_OBJ + const bool enable = !editFind->text().isEmpty(); + toolNext->setEnabled(enable); + toolPrevious->setEnabled(enable); +} + +void FindWidget::textChanged(const QString &text) +{ + TRACE_OBJ + emit find(text, true); +} + +bool FindWidget::eventFilter(QObject *object, QEvent *e) +{ + TRACE_OBJ + if (e->type() == QEvent::KeyPress) { + if ((static_cast<QKeyEvent*>(e))->key() == Qt::Key_Escape) { + hide(); + emit escapePressed(); + } + } + return QWidget::eventFilter(object, e); +} + +QToolButton* FindWidget::setupToolButton(const QString &text, const QString &icon) +{ + TRACE_OBJ + QToolButton *toolButton = new QToolButton(this); + + toolButton->setText(text); + toolButton->setAutoRaise(true); + toolButton->setIcon(QIcon(icon)); + toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + + return toolButton; +} + +QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/findwidget.h b/tools/assistant/tools/assistant/findwidget.h new file mode 100644 index 0000000..cf78003 --- /dev/null +++ b/tools/assistant/tools/assistant/findwidget.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Assistant of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef FINDWIDGET_H +#define FINDWIDGET_H + +#include <QtGui/QWidget> + +QT_BEGIN_NAMESPACE + +class QCheckBox; +class QLabel; +class QLineEdit; +class QToolButton; + +class FindWidget : public QWidget +{ + Q_OBJECT +public: + FindWidget(QWidget *parent = 0); + ~FindWidget(); + + void show(); + void showAndClear(); + + QString text() const; + bool caseSensitive() const; + + void setPalette(bool found); + void setTextWrappedVisible(bool visible); + +signals: + void escapePressed(); + + void findNext(); + void findPrevious(); + void find(const QString &text, bool forward); + +protected: + void hideEvent(QHideEvent* event); + void showEvent(QShowEvent * event); + +private slots: + void updateButtons(); + void textChanged(const QString &text); + +private: + bool eventFilter(QObject *object, QEvent *e); + QToolButton* setupToolButton(const QString &text, const QString &icon); + +private: + QPalette appPalette; + + QLineEdit *editFind; + QCheckBox *checkCase; + QLabel *labelWrapped; + QToolButton *toolNext; + QToolButton *toolClose; + QToolButton *toolPrevious; +}; + +QT_END_NAMESPACE + +#endif // FINDWIDGET_H |