From c41c4d971bb17ac1596a684760717a8f449cad8f Mon Sep 17 00:00:00 2001 From: con <qtc-committer@nokia.com> Date: Thu, 13 Jan 2011 17:34:41 +0100 Subject: [PATCH] Show wrap indicator when searching in text edits. Adds a showWrapIndicator(parent) method to IFindSupport, to be used by implementations. First implementation is given for the BaseFindSupport that's used for all searches in Q(Plain)TextEdits. Task-number: QTCREATORBUG-2753 --- src/plugins/find/basetextfind.cpp | 38 ++++++-- src/plugins/find/basetextfind.h | 3 +- src/plugins/find/find.pro | 3 +- src/plugins/find/find.qrc | 3 +- src/plugins/find/ifindsupport.cpp | 102 ++++++++++++++++++++++ src/plugins/find/ifindsupport.h | 2 + src/plugins/find/images/wrapindicator.png | Bin 0 -> 1949 bytes 7 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 src/plugins/find/ifindsupport.cpp create mode 100644 src/plugins/find/images/wrapindicator.png diff --git a/src/plugins/find/basetextfind.cpp b/src/plugins/find/basetextfind.cpp index 9b3a3c2293e..ea24a667298 100644 --- a/src/plugins/find/basetextfind.cpp +++ b/src/plugins/find/basetextfind.cpp @@ -50,26 +50,32 @@ struct BaseTextFindPrivate { QPointer<QTextEdit> m_editor; QPointer<QPlainTextEdit> m_plaineditor; + QPointer<QWidget> m_widget; QTextCursor m_findScopeStart; QTextCursor m_findScopeEnd; int m_findScopeVerticalBlockSelectionFirstColumn; int m_findScopeVerticalBlockSelectionLastColumn; int m_incrementalStartPos; + bool m_incrementalWrappedState; }; BaseTextFindPrivate::BaseTextFindPrivate(QTextEdit *editor) : m_editor(editor) + , m_widget(editor) , m_findScopeVerticalBlockSelectionFirstColumn(-1) , m_findScopeVerticalBlockSelectionLastColumn(-1) , m_incrementalStartPos(-1) + , m_incrementalWrappedState(false) { } BaseTextFindPrivate::BaseTextFindPrivate(QPlainTextEdit *editor) : m_plaineditor(editor) + , m_widget(editor) , m_findScopeVerticalBlockSelectionFirstColumn(-1) , m_findScopeVerticalBlockSelectionLastColumn(-1) , m_incrementalStartPos(-1) + , m_incrementalWrappedState(false) { } @@ -127,6 +133,7 @@ Find::FindFlags BaseTextFind::supportedFindFlags() const void BaseTextFind::resetIncrementalSearch() { d->m_incrementalStartPos = -1; + d->m_incrementalWrappedState = false; } void BaseTextFind::clearResults() @@ -174,7 +181,13 @@ IFindSupport::Result BaseTextFind::findIncremental(const QString &txt, Find::Fin if (d->m_incrementalStartPos < 0) d->m_incrementalStartPos = cursor.selectionStart(); cursor.setPosition(d->m_incrementalStartPos); - bool found = find(txt, findFlags, cursor); + bool wrapped = false; + bool found = find(txt, findFlags, cursor, &wrapped); + if (wrapped != d->m_incrementalWrappedState) { + d->m_incrementalWrappedState = wrapped; + if (found) + showWrapIndicator(d->m_widget); + } if (found) emit highlightAll(txt, findFlags); else @@ -184,9 +197,14 @@ IFindSupport::Result BaseTextFind::findIncremental(const QString &txt, Find::Fin IFindSupport::Result BaseTextFind::findStep(const QString &txt, Find::FindFlags findFlags) { - bool found = find(txt, findFlags, textCursor()); - if (found) + bool wrapped = false; + bool found = find(txt, findFlags, textCursor(), &wrapped); + if (wrapped) + showWrapIndicator(d->m_widget); + if (found) { d->m_incrementalStartPos = textCursor().selectionStart(); + d->m_incrementalWrappedState = false; + } return found ? Found : NotFound; } @@ -220,7 +238,11 @@ bool BaseTextFind::replaceStep(const QString &before, const QString &after, Find::FindFlags findFlags) { QTextCursor cursor = replaceInternal(before, after, findFlags); - return find(before, findFlags, cursor); + bool wrapped = false; + bool found = find(before, findFlags, cursor, &wrapped); + if (wrapped) + showWrapIndicator(d->m_widget); + return found; } int BaseTextFind::replaceAll(const QString &before, const QString &after, @@ -254,7 +276,7 @@ int BaseTextFind::replaceAll(const QString &before, const QString &after, bool BaseTextFind::find(const QString &txt, Find::FindFlags findFlags, - QTextCursor start) + QTextCursor start, bool *wrapped) { if (txt.isEmpty()) { setTextCursor(start); @@ -264,11 +286,15 @@ bool BaseTextFind::find(const QString &txt, regexp.setPatternSyntax((findFlags&Find::FindRegularExpression) ? QRegExp::RegExp : QRegExp::FixedString); regexp.setCaseSensitivity((findFlags&Find::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); QTextCursor found = findOne(regexp, start, Find::textDocumentFlagsForFindFlags(findFlags)); + if (wrapped) + *wrapped = false; if (!d->m_findScopeStart.isNull()) { // scoped if (found.isNull() || !inScope(found.selectionStart(), found.selectionEnd())) { + if (wrapped) + *wrapped = true; if ((findFlags&Find::FindBackward) == 0) start.setPosition(d->m_findScopeStart.position()); else @@ -281,6 +307,8 @@ bool BaseTextFind::find(const QString &txt, // entire document if (found.isNull()) { + if (wrapped) + *wrapped = true; if ((findFlags&Find::FindBackward) == 0) start.movePosition(QTextCursor::Start); else diff --git a/src/plugins/find/basetextfind.h b/src/plugins/find/basetextfind.h index 69a9225664d..e61d171b019 100644 --- a/src/plugins/find/basetextfind.h +++ b/src/plugins/find/basetextfind.h @@ -85,7 +85,8 @@ signals: private: bool find(const QString &txt, Find::FindFlags findFlags, - QTextCursor start); + QTextCursor start, + bool *wrapped); QTextCursor replaceInternal(const QString &before, const QString &after, Find::FindFlags findFlags); diff --git a/src/plugins/find/find.pro b/src/plugins/find/find.pro index c0c93d36258..ba9f99fcf29 100644 --- a/src/plugins/find/find.pro +++ b/src/plugins/find/find.pro @@ -28,7 +28,8 @@ SOURCES += findtoolwindow.cpp \ searchresulttreemodel.cpp \ searchresulttreeview.cpp \ searchresultwindow.cpp \ - ifindfilter.cpp + ifindfilter.cpp \ + ifindsupport.cpp FORMS += findwidget.ui \ finddialog.ui RESOURCES += find.qrc diff --git a/src/plugins/find/find.qrc b/src/plugins/find/find.qrc index 2461cde7be1..52d7a810bfc 100644 --- a/src/plugins/find/find.qrc +++ b/src/plugins/find/find.qrc @@ -1,8 +1,9 @@ <RCC> - <qresource prefix="/find" > + <qresource prefix="/find"> <file>images/casesensitively.png</file> <file>images/wholewords.png</file> <file>images/regexp.png</file> <file>images/expand.png</file> + <file>images/wrapindicator.png</file> </qresource> </RCC> diff --git a/src/plugins/find/ifindsupport.cpp b/src/plugins/find/ifindsupport.cpp new file mode 100644 index 00000000000..4eb5ac2796b --- /dev/null +++ b/src/plugins/find/ifindsupport.cpp @@ -0,0 +1,102 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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. +** +**************************************************************************/ + +#include "ifindsupport.h" + +#include <QtCore/QTimer> +#include <QtCore/QPropertyAnimation> +#include <QtGui/QWidget> +#include <QtGui/QPaintEvent> +#include <QtGui/QPainter> + +namespace Find { +namespace Internal { + +class WrapIndicator : public QWidget +{ + Q_OBJECT + Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity USER true) + +public: + WrapIndicator(QWidget *parent = 0) + : QWidget(parent), + m_opacity(1.0) + { + if (parent) + setGeometry(QRect(parent->rect().center() - QPoint(25, 25), + parent->rect().center() + QPoint(25, 25))); + } + + qreal opacity() const { return m_opacity; } + void setOpacity(qreal value) { m_opacity = value; update(); } + + void run() + { + show(); + QTimer::singleShot(300, this, SLOT(runInternal())); + } + +protected: + void paintEvent(QPaintEvent *) + { + static QPixmap foreground(QLatin1String(":/find/images/wrapindicator.png")); + QPainter p(this); + p.setOpacity(m_opacity); + p.drawPixmap(rect(), foreground); + } + +private slots: + void runInternal() + { + QPropertyAnimation *anim = new QPropertyAnimation(this, "opacity", this); + anim->setDuration(200); + anim->setEndValue(0.); + connect(anim, SIGNAL(finished()), this, SLOT(deleteLater())); + anim->start(QAbstractAnimation::DeleteWhenStopped); + } + +private: + qreal m_opacity; +}; + +} // Internal +} // Find + +using namespace Find; + +void IFindSupport::showWrapIndicator(QWidget *parent) +{ + (new Internal::WrapIndicator(parent))->run(); +} + +#include "ifindsupport.moc" diff --git a/src/plugins/find/ifindsupport.h b/src/plugins/find/ifindsupport.h index b9fa85dffb9..5ca361a8d30 100644 --- a/src/plugins/find/ifindsupport.h +++ b/src/plugins/find/ifindsupport.h @@ -73,6 +73,8 @@ public: virtual void defineFindScope(){} virtual void clearFindScope(){} + static void showWrapIndicator(QWidget *parent); + signals: void changed(); }; diff --git a/src/plugins/find/images/wrapindicator.png b/src/plugins/find/images/wrapindicator.png new file mode 100644 index 0000000000000000000000000000000000000000..a4f8ddf41779e8e845dc9eabfbccb864bc4f593e GIT binary patch literal 1949 zcmV;O2V(e%P)<h;3K|Lk000e1NJLTq001%o001%w1^@s69zTe&00004b3#c}2nYxW zd<bNS00009a7bBm000fw000fw0YWI7cmMzZ8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H12O3F4K~!jg)mlqa8&?)S_o`bGEszk12q-;_<XBcYB>{yq2@n_g z3A4Z^l^>9mx3f)Uo2^&*0aKR4ddgMV#8rcnjSDPQTmmyv2EjlCSgmfP?w0y-XJIR0 zNIz~%Kr-J>>T~Y-zP_(>&uv5q0W&;#@+7ST<PkuY7)BNlN&`Zysqs~T5ETfiAdJfd zpzHxCK6vn;VrGgi3Rz!YAL?q_Lxj*OAcU@gE&>4aw|NnS5JJehmth{QuCB`GAK~*q z3WdU)s_Tyt#`mv71j{g<Pghn_)S(bU2;=*zu0Jjm3UlWl{VJqTD9jlMeFF%^E|;z~ zQZqB7Q_<+?{Os(sD@TN4214JQ7l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