Initial import

This commit is contained in:
con
2008-12-02 12:01:29 +01:00
commit 05c35356ab
1675 changed files with 229938 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<plugin name="Find" version="0.9.1" compatVersion="0.9.1">
<vendor>Nokia Corporation</vendor>
<copyright>(C) 2008 Nokia Corporation</copyright>
<license>Nokia Technology Preview License Agreement</license>
<description>Provides the find widget and the hooks for find implementations.</description>
<url>http://www.trolltech.com/</url>
<dependencyList>
<dependency name="Core" version="0.9.1"/>
</dependencyList>
</plugin>

View File

@@ -0,0 +1,246 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "basetextfind.h"
#include <QtGui/QTextBlock>
using namespace Find;
BaseTextFind::BaseTextFind(QTextEdit *editor)
: m_editor(editor), m_incrementalStartPos(-1)
{
}
BaseTextFind::BaseTextFind(QPlainTextEdit *editor)
: m_plaineditor(editor), m_incrementalStartPos(-1)
{
}
QTextCursor BaseTextFind::textCursor() const
{
Q_ASSERT(m_editor || m_plaineditor);
return m_editor ? m_editor->textCursor() : m_plaineditor->textCursor();
}
void BaseTextFind::setTextCursor(const QTextCursor& cursor)
{
Q_ASSERT(m_editor || m_plaineditor);
m_editor ? m_editor->setTextCursor(cursor) : m_plaineditor->setTextCursor(cursor);
}
QTextDocument *BaseTextFind::document() const
{
Q_ASSERT(m_editor || m_plaineditor);
return m_editor ? m_editor->document() : m_plaineditor->document();
}
bool BaseTextFind::isReadOnly() const
{
Q_ASSERT(m_editor || m_plaineditor);
return m_editor ? m_editor->isReadOnly() : m_plaineditor->isReadOnly();
}
bool BaseTextFind::supportsReplace() const
{
return !isReadOnly();
}
void BaseTextFind::resetIncrementalSearch()
{
m_incrementalStartPos = -1;
}
void BaseTextFind::clearResults()
{
emit highlightAll(QString(), 0);
}
QString BaseTextFind::currentFindString() const
{
QTextCursor cursor = textCursor();
if (cursor.hasSelection() && cursor.block() != cursor.document()->findBlock(cursor.anchor())) {
return QString(); // multi block selection
}
if (cursor.hasSelection())
return cursor.selectedText();
if (!cursor.atBlockEnd() && !cursor.hasSelection()) {
cursor.movePosition(QTextCursor::StartOfWord);
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
QString s = cursor.selectedText();
foreach(QChar c, s) {
if (!c.isLetterOrNumber() && c != QLatin1Char('_')) {
s.clear();
break;
}
}
return s;
}
return QString();
}
QString BaseTextFind::completedFindString() const
{
QTextCursor cursor = textCursor();
cursor.setPosition(textCursor().selectionStart());
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
return cursor.selectedText();
}
bool BaseTextFind::findIncremental(const QString &txt, QTextDocument::FindFlags findFlags)
{
QTextCursor cursor = textCursor();
if (m_incrementalStartPos < 0)
m_incrementalStartPos = cursor.selectionStart();
cursor.setPosition(m_incrementalStartPos);
findFlags &= ~QTextDocument::FindBackward;
bool found = find(txt, findFlags, cursor);
if (found)
emit highlightAll(txt, findFlags);
else
emit highlightAll(QString(), 0);
return found;
}
bool BaseTextFind::findStep(const QString &txt, QTextDocument::FindFlags findFlags)
{
bool found = find(txt, findFlags, textCursor());
if (found)
m_incrementalStartPos = textCursor().selectionStart();
return found;
}
bool BaseTextFind::replaceStep(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags)
{
QTextCursor cursor = textCursor();
if (cursor.selectedText().compare(before,
((findFlags&QTextDocument::FindCaseSensitively)!=0) ? Qt::CaseSensitive : Qt::CaseInsensitive) == 0) {
int start = cursor.selectionStart();
cursor.insertText(after);
if ((findFlags&QTextDocument::FindBackward) != 0)
cursor.setPosition(start);
}
return find(before, findFlags, cursor);
}
int BaseTextFind::replaceAll(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags)
{
QTextCursor editCursor = textCursor();
editCursor.movePosition(QTextCursor::Start);
editCursor.beginEditBlock();
int count = 0;
QTextCursor found;
found = document()->find(before, editCursor, findFlags);
while (!found.isNull() && inScope(found.selectionStart(), found.selectionEnd())) {
++count;
editCursor.setPosition(found.selectionStart());
editCursor.setPosition(found.selectionEnd(), QTextCursor::KeepAnchor);
editCursor.insertText(after);
found = document()->find(before, editCursor, findFlags);
}
editCursor.endEditBlock();
return count;
}
bool BaseTextFind::find(const QString &txt,
QTextDocument::FindFlags findFlags,
QTextCursor start)
{
if (txt.isEmpty()) {
setTextCursor(start);
return true;
}
QTextCursor found = document()->find(txt, start, findFlags);
if (!m_findScope.isNull()) {
// scoped
if (found.isNull() || !inScope(found.selectionStart(), found.selectionEnd())) {
if ((findFlags&QTextDocument::FindBackward) == 0)
start.setPosition(m_findScope.selectionStart());
else
start.setPosition(m_findScope.selectionEnd());
found = document()->find(txt, start, findFlags);
if (found.isNull() || !inScope(found.selectionStart(), found.selectionEnd()))
return false;
}
} else {
// entire document
if (found.isNull()) {
if ((findFlags&QTextDocument::FindBackward) == 0)
start.movePosition(QTextCursor::Start);
else
start.movePosition(QTextCursor::End);
found = document()->find(txt, start, findFlags);
if (found.isNull()) {
return false;
}
}
}
if (!found.isNull()) {
setTextCursor(found);
}
return true;
}
bool BaseTextFind::inScope(int startPosition, int endPosition) const
{
if (m_findScope.isNull())
return true;
return (m_findScope.selectionStart() <= startPosition
&& m_findScope.selectionEnd() >= endPosition);
}
void BaseTextFind::defineFindScope()
{
QTextCursor cursor = textCursor();
if (cursor.hasSelection() && cursor.block() != cursor.document()->findBlock(cursor.anchor())) {
m_findScope = cursor;
emit findScopeChanged(m_findScope);
cursor.setPosition(cursor.selectionStart());
setTextCursor(cursor);
} else {
clearFindScope();
}
}
void BaseTextFind::clearFindScope()
{
m_findScope = QTextCursor();
emit findScopeChanged(m_findScope);
}

View File

@@ -0,0 +1,90 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef BASETEXTFIND_H
#define BASETEXTFIND_H
#include "find_global.h"
#include "ifindsupport.h"
#include <QtCore/QPointer>
#include <QtGui/QPlainTextEdit>
namespace Find {
class FIND_EXPORT BaseTextFind : public Find::IFindSupport
{
Q_OBJECT
public:
BaseTextFind(QPlainTextEdit *editor);
BaseTextFind(QTextEdit *editor);
bool supportsReplace() const;
void resetIncrementalSearch();
void clearResults();
QString currentFindString() const;
QString completedFindString() const;
bool findIncremental(const QString &txt, QTextDocument::FindFlags findFlags);
bool findStep(const QString &txt, QTextDocument::FindFlags findFlags);
bool replaceStep(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags);
int replaceAll(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags);
void defineFindScope();
void clearFindScope();
signals:
void highlightAll(const QString &txt, QTextDocument::FindFlags findFlags);
void findScopeChanged(const QTextCursor &);
private:
bool find(const QString &txt,
QTextDocument::FindFlags findFlags,
QTextCursor start);
QTextCursor textCursor() const;
void setTextCursor(const QTextCursor&);
QTextDocument *document() const;
bool isReadOnly() const;
QPointer<QTextEdit> m_editor;
QPointer<QPlainTextEdit> m_plaineditor;
QTextCursor m_findScope;
bool inScope(int startPosition, int endPosition) const;
int m_incrementalStartPos;
};
} // namespace Find
#endif // BASETEXTFIND_H

View File

@@ -0,0 +1,201 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "currentdocumentfind.h"
#include <aggregation/aggregate.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
#include <QtGui/QApplication>
#include <QtDebug>
using namespace Core;
using namespace Find;
using namespace Find::Internal;
CurrentDocumentFind::CurrentDocumentFind(ICore *core)
: m_core(core), m_currentFind(0)
{
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)),
this, SLOT(updateCurrentFindFilter(QWidget*,QWidget*)));
}
void CurrentDocumentFind::removeConnections()
{
disconnect(qApp, 0, this, 0);
removeFindSupportConnections();
}
void CurrentDocumentFind::resetIncrementalSearch()
{
Q_ASSERT(m_currentFind);
if (m_currentFind)
m_currentFind->resetIncrementalSearch();
}
void CurrentDocumentFind::clearResults()
{
Q_ASSERT(m_currentFind);
if (m_currentFind)
m_currentFind->clearResults();
}
bool CurrentDocumentFind::isEnabled() const
{
return m_currentFind && (!m_currentWidget || m_currentWidget->isVisible());
}
bool CurrentDocumentFind::supportsReplace() const
{
Q_ASSERT(m_currentFind);
return m_currentFind ? m_currentFind->supportsReplace() : false;
}
QString CurrentDocumentFind::currentFindString() const
{
Q_ASSERT(m_currentFind);
return m_currentFind ? m_currentFind->currentFindString() : QString();
}
QString CurrentDocumentFind::completedFindString() const
{
Q_ASSERT(m_currentFind);
return m_currentFind ? m_currentFind->completedFindString() : QString();
}
void CurrentDocumentFind::highlightAll(const QString &txt, QTextDocument::FindFlags findFlags)
{
Q_ASSERT(m_currentFind);
if (m_currentFind)
m_currentFind->highlightAll(txt, findFlags);
}
bool CurrentDocumentFind::findIncremental(const QString &txt, QTextDocument::FindFlags findFlags)
{
Q_ASSERT(m_currentFind);
return (m_currentFind? m_currentFind->findIncremental(txt, findFlags) : false);
}
bool CurrentDocumentFind::findStep(const QString &txt, QTextDocument::FindFlags findFlags)
{
Q_ASSERT(m_currentFind);
return (m_currentFind? m_currentFind->findStep(txt, findFlags) : false);
}
bool CurrentDocumentFind::replaceStep(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags)
{
Q_ASSERT(m_currentFind);
return (m_currentFind? m_currentFind->replaceStep(before, after, findFlags) : false);
}
int CurrentDocumentFind::replaceAll(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags)
{
Q_ASSERT(m_currentFind);
return (m_currentFind? m_currentFind->replaceAll(before, after, findFlags) : 0);
}
void CurrentDocumentFind::defineFindScope()
{
Q_ASSERT(m_currentFind);
if (m_currentFind)
m_currentFind->defineFindScope();
}
void CurrentDocumentFind::clearFindScope()
{
Q_ASSERT(m_currentFind);
if (m_currentFind)
m_currentFind->clearFindScope();
}
void CurrentDocumentFind::updateCurrentFindFilter(QWidget *old, QWidget *now)
{
Q_UNUSED(old);
QWidget *candidate = now;
QPointer<IFindSupport> impl = 0;
while (!impl && candidate) {
impl = Aggregation::query<IFindSupport>(candidate);
if (!impl)
candidate = candidate->parentWidget();
}
if (!impl)
return;
removeFindSupportConnections();
m_currentWidget = candidate;
m_currentFind = impl;
if (m_currentFind) {
connect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed()));
connect(m_currentFind, SIGNAL(destroyed(QObject*)), SLOT(findSupportDestroyed()));
}
if (m_currentWidget)
m_currentWidget->installEventFilter(this);
emit changed();
}
void CurrentDocumentFind::removeFindSupportConnections()
{
if (m_currentFind) {
disconnect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed()));
disconnect(m_currentFind, SIGNAL(destroyed(QObject*)), this, SLOT(findSupportDestroyed()));
}
if (m_currentWidget)
m_currentWidget->removeEventFilter(this);
}
void CurrentDocumentFind::findSupportDestroyed()
{
removeFindSupportConnections();
m_currentWidget = 0;
m_currentFind = 0;
emit changed();
}
bool CurrentDocumentFind::setFocusToCurrentFindSupport()
{
if (m_currentFind && m_currentWidget) {
m_currentWidget->setFocus();
return true;
}
return false;
}
bool CurrentDocumentFind::eventFilter(QObject *obj, QEvent *event)
{
if (m_currentWidget && obj == m_currentWidget) {
if (event->type() == QEvent::Hide || event->type() == QEvent::Show) {
emit changed();
}
}
return QObject::eventFilter(obj, event);
}

View File

@@ -0,0 +1,93 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef CURRENTDOCUMENTFIND_H
#define CURRENTDOCUMENTFIND_H
#include "ifindfilter.h"
#include <coreplugin/icore.h>
#include <QtCore/QPointer>
#include <QtGui/QWidget>
namespace Find {
namespace Internal {
class CurrentDocumentFind : public QObject
{
Q_OBJECT
public:
CurrentDocumentFind(Core::ICore *core);
void resetIncrementalSearch();
void clearResults();
bool supportsReplace() const;
QString currentFindString() const;
QString completedFindString() const;
bool isEnabled() const;
void highlightAll(const QString &txt, QTextDocument::FindFlags findFlags);
bool findIncremental(const QString &txt, QTextDocument::FindFlags findFlags);
bool findStep(const QString &txt, QTextDocument::FindFlags findFlags);
bool replaceStep(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags);
int replaceAll(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags);
void defineFindScope();
void clearFindScope();
void removeConnections();
bool setFocusToCurrentFindSupport();
bool eventFilter(QObject *obj, QEvent *event);
signals:
void changed();
private slots:
void updateCurrentFindFilter(QWidget *old, QWidget *now);
void findSupportDestroyed();
private:
void removeFindSupportConnections();
Core::ICore *m_core;
QPointer<IFindSupport> m_currentFind;
QPointer<QWidget> m_currentWidget;
};
} // namespace Internal
} // namespace Find
#endif // CURRENTDOCUMENTFIND_H

View File

@@ -0,0 +1,3 @@
include(find_dependencies.pri)
LIBS *= -l$$qtLibraryTarget(Find)

33
src/plugins/find/find.pro Normal file
View File

@@ -0,0 +1,33 @@
TEMPLATE = lib
TARGET = Find
include(../../qworkbenchplugin.pri)
include(find_dependencies.pri)
DEFINES += FIND_LIBRARY
HEADERS += findtoolwindow.h \
textfindconstants.h \
ifindsupport.h \
ifindfilter.h \
currentdocumentfind.h \
basetextfind.h \
find_global.h \
findtoolbar.h \
findplugin.h \
searchresulttreeitemdelegate.h \
searchresulttreeitemroles.h \
searchresulttreeitems.h \
searchresulttreemodel.h \
searchresulttreeview.h \
searchresultwindow.h
SOURCES += findtoolwindow.cpp \
currentdocumentfind.cpp \
basetextfind.cpp \
findtoolbar.cpp \
findplugin.cpp \
searchresulttreeitemdelegate.cpp \
searchresulttreeitems.cpp \
searchresulttreemodel.cpp \
searchresulttreeview.cpp \
searchresultwindow.cpp
FORMS += findwidget.ui \
finddialog.ui
RESOURCES += find.qrc

13
src/plugins/find/find.qrc Normal file
View File

@@ -0,0 +1,13 @@
<RCC>
<qresource prefix="/find" >
<file>images/all.png</file>
<file>images/casesensitively.png</file>
<file>images/empty.png</file>
<file>images/expand.png</file>
<file>images/next.png</file>
<file>images/previous.png</file>
<file>images/replace_all.png</file>
<file>images/wholewords.png</file>
<file>images/wordandcase.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1 @@
include(../../plugins/coreplugin/coreplugin.pri)

View File

@@ -0,0 +1,57 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
/****************************************************************************
**
** Copyright (C) 1992-$THISYEAR$ Trolltech AS. All rights reserved.
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $LICENSE$
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef FIND_GLOBAL_H
#define FIND_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(FIND_LIBRARY)
# define FIND_EXPORT Q_DECL_EXPORT
#else
# define FIND_EXPORT Q_DECL_IMPORT
#endif
#endif // FIND_GLOBAL_H

View File

@@ -0,0 +1,146 @@
<ui version="4.0" >
<class>Find::Internal::FindDialog</class>
<widget class="QDialog" name="Find::Internal::FindDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>426</width>
<height>168</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Minimum" hsizetype="Minimum" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle" >
<string>Search for...</string>
</property>
<property name="sizeGripEnabled" >
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="text" >
<string>Sc&amp;ope:</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>filterList</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="filterList" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QPushButton" name="searchButton" >
<property name="text" >
<string>&amp;Search</string>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Search &amp;for:</string>
</property>
<property name="alignment" >
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>searchTerm</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="searchTerm" />
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="closeButton" >
<property name="text" >
<string>&amp;Close</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2" >
<widget class="QWidget" native="1" name="configWidget" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QCheckBox" name="matchCase" >
<property name="text" >
<string>Match &amp;case</string>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QCheckBox" name="wholeWords" >
<property name="text" >
<string>&amp;Whole words only</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<tabstops>
<tabstop>filterList</tabstop>
<tabstop>searchTerm</tabstop>
<tabstop>searchButton</tabstop>
<tabstop>closeButton</tabstop>
<tabstop>matchCase</tabstop>
<tabstop>wholeWords</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,272 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "findplugin.h"
#include "textfindconstants.h"
#include "currentdocumentfind.h"
#include "findtoolwindow.h"
#include "searchresultwindow.h"
#include <coreplugin/actionmanager/actionmanagerinterface.h>
#include <coreplugin/actionmanager/iactioncontainer.h>
#include <coreplugin/actionmanager/icommand.h>
#include <coreplugin/coreconstants.h>
#include <QtCore/qplugin.h>
#include <QtCore/QSettings>
Q_DECLARE_METATYPE(Find::IFindFilter*)
namespace {
const int MAX_COMPLETIONS = 50;
}
using namespace Find;
using namespace Find::Internal;
FindPlugin::FindPlugin()
: m_core(0),
m_currentDocumentFind(0),
m_findToolBar(0),
m_findDialog(0),
m_findCompletionModel(new QStringListModel(this)),
m_replaceCompletionModel(new QStringListModel(this))
{
}
FindPlugin::~FindPlugin()
{
delete m_currentDocumentFind;
delete m_findToolBar;
delete m_findDialog;
}
bool FindPlugin::initialize(const QStringList &, QString *)
{
m_core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>();
setupMenu();
m_currentDocumentFind = new CurrentDocumentFind(m_core);
m_findToolBar = new FindToolBar(this, m_currentDocumentFind);
m_findDialog = new FindToolWindow(this);
SearchResultWindow *searchResultWindow = new SearchResultWindow(m_core);
addAutoReleasedObject(searchResultWindow);
return true;
}
void FindPlugin::extensionsInitialized()
{
setupFilterMenuItems();
readSettings();
}
void FindPlugin::shutdown()
{
m_findToolBar->setParent(0);
m_currentDocumentFind->removeConnections();
writeSettings();
}
void FindPlugin::filterChanged()
{
IFindFilter *changedFilter = qobject_cast<IFindFilter *>(sender());
QAction *action = m_filterActions.value(changedFilter);
Q_ASSERT(changedFilter);
Q_ASSERT(action);
if (!changedFilter || !action)
return;
action->setEnabled(changedFilter->isEnabled());
}
void FindPlugin::openFindFilter()
{
QAction *action = qobject_cast<QAction*>(sender());
Q_ASSERT(action);
if (!action)
return;
IFindFilter *filter = action->data().value<IFindFilter *>();
Q_ASSERT(filter);
Q_ASSERT(filter->isEnabled());
if (!filter || !filter->isEnabled())
return;
QString currentFindString = (m_currentDocumentFind->isEnabled() ? m_currentDocumentFind->currentFindString() : "");
if (!currentFindString.isEmpty())
m_findDialog->setFindText(currentFindString);
m_findDialog->open(filter);
}
void FindPlugin::setupMenu()
{
Core::ActionManagerInterface *am = m_core->actionManager();
Core::IActionContainer *medit = am->actionContainer(Core::Constants::M_EDIT);
Core::IActionContainer *mfind = am->createMenu(Constants::M_FIND);
medit->addMenu(mfind, Core::Constants::G_EDIT_FIND);
mfind->menu()->setTitle(tr("&Find/Replace"));
mfind->appendGroup(Constants::G_FIND_FILTERS);
mfind->appendGroup(Constants::G_FIND_FLAGS);
mfind->appendGroup(Constants::G_FIND_ACTIONS);
QList<int> globalcontext = QList<int>() << Core::Constants::C_GLOBAL_ID;
Core::ICommand *cmd;
QAction *separator;
separator = new QAction(this);
separator->setSeparator(true);
cmd = am->registerAction(separator, QLatin1String("Find.Sep.Flags"), globalcontext);
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
separator = new QAction(this);
separator->setSeparator(true);
cmd = am->registerAction(separator, QLatin1String("Find.Sep.Actions"), globalcontext);
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
}
void FindPlugin::setupFilterMenuItems()
{
Core::ActionManagerInterface *am = m_core->actionManager();
QList<IFindFilter*> findInterfaces =
ExtensionSystem::PluginManager::instance()->getObjects<IFindFilter>();
Core::ICommand *cmd;
QList<int> globalcontext = QList<int>() << Core::Constants::C_GLOBAL_ID;
Core::IActionContainer *mfind = am->actionContainer(Constants::M_FIND);
m_filterActions.clear();
foreach (IFindFilter *filter, findInterfaces) {
QAction *action = new QAction(filter->name(), this);
action->setEnabled(filter->isEnabled());
action->setData(qVariantFromValue(filter));
cmd = am->registerAction(action, QLatin1String("FindFilter.")+filter->name(), globalcontext);
cmd->setDefaultKeySequence(filter->defaultShortcut());
mfind->addAction(cmd, Constants::G_FIND_FILTERS);
m_filterActions.insert(filter, action);
connect(action, SIGNAL(triggered(bool)), this, SLOT(openFindFilter()));
connect(filter, SIGNAL(changed()), this, SLOT(filterChanged()));
}
m_findDialog->setFindFilters(findInterfaces);
}
Core::ICore *FindPlugin::core()
{
return m_core;
}
QTextDocument::FindFlags FindPlugin::findFlags() const
{
return m_findFlags;
}
void FindPlugin::setCaseSensitive(bool sensitive)
{
setFindFlag(QTextDocument::FindCaseSensitively, sensitive);
}
void FindPlugin::setWholeWord(bool wholeOnly)
{
setFindFlag(QTextDocument::FindWholeWords, wholeOnly);
}
void FindPlugin::setBackward(bool backward)
{
setFindFlag(QTextDocument::FindBackward, backward);
}
void FindPlugin::setFindFlag(QTextDocument::FindFlag flag, bool enabled)
{
bool hasFlag = hasFindFlag(flag);
if ((hasFlag && enabled) || (!hasFlag && !enabled))
return;
if (enabled)
m_findFlags |= flag;
else
m_findFlags &= ~flag;
if (flag != QTextDocument::FindBackward)
emit findFlagsChanged();
}
bool FindPlugin::hasFindFlag(QTextDocument::FindFlag flag)
{
return m_findFlags & flag;
}
void FindPlugin::writeSettings()
{
QSettings *settings = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>()->settings();
settings->beginGroup("Find");
settings->setValue("Backward", QVariant((m_findFlags & QTextDocument::FindBackward) != 0));
settings->setValue("CaseSensitively", QVariant((m_findFlags & QTextDocument::FindCaseSensitively) != 0));
settings->setValue("WholeWords", QVariant((m_findFlags & QTextDocument::FindWholeWords) != 0));
settings->setValue("FindStrings", m_findCompletions);
settings->setValue("ReplaceStrings", m_replaceCompletions);
settings->endGroup();
m_findDialog->writeSettings();
}
void FindPlugin::readSettings()
{
QSettings *settings = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>()->settings();
settings->beginGroup("Find");
bool block = blockSignals(true);
setBackward(settings->value("Backward", false).toBool());
setCaseSensitive(settings->value("CaseSensitively", false).toBool());
setWholeWord(settings->value("WholeWords", false).toBool());
blockSignals(block);
m_findCompletions = settings->value("FindStrings").toStringList();
m_replaceCompletions = settings->value("ReplaceStrings").toStringList();
m_findCompletionModel->setStringList(m_findCompletions);
m_replaceCompletionModel->setStringList(m_replaceCompletions);
settings->endGroup();
m_findDialog->readSettings();
emit findFlagsChanged(); // would have been done in the setXXX methods above
}
void FindPlugin::updateFindCompletion(const QString &text)
{
updateCompletion(text, m_findCompletions, m_findCompletionModel);
}
void FindPlugin::updateReplaceCompletion(const QString &text)
{
updateCompletion(text, m_replaceCompletions, m_replaceCompletionModel);
}
void FindPlugin::updateCompletion(const QString &text, QStringList &completions, QStringListModel *model)
{
if (text.isEmpty())
return;
completions.removeAll(text);
completions.prepend(text);
while (completions.size() > MAX_COMPLETIONS)
completions.removeLast();
model->setStringList(completions);
}
Q_EXPORT_PLUGIN(FindPlugin)

View File

@@ -0,0 +1,111 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef FINDPLUGIN_H
#define FINDPLUGIN_H
#include "ui_findwidget.h"
#include "ifindfilter.h"
#include "findtoolbar.h"
#include <coreplugin/icore.h>
#include <extensionsystem/iplugin.h>
#include <QtCore/QHash>
#include <QtCore/QStringList>
#include <QtGui/QAction>
#include <QtGui/QTextDocument>
namespace Find {
namespace Internal {
class FindToolWindow;
class FindPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
FindPlugin();
virtual ~FindPlugin();
// IPlugin
bool initialize(const QStringList &arguments, QString *error_message);
void extensionsInitialized();
void shutdown();
Core::ICore *core();
QTextDocument::FindFlags findFlags() const;
void updateFindCompletion(const QString &text);
void updateReplaceCompletion(const QString &text);
QStringListModel *findCompletionModel() { return m_findCompletionModel; }
QStringListModel *replaceCompletionModel() { return m_replaceCompletionModel; }
public slots:
void setCaseSensitive(bool sensitive);
void setWholeWord(bool wholeOnly);
void setBackward(bool backward);
signals:
void findFlagsChanged();
private slots:
void filterChanged();
void openFindFilter();
private:
void setFindFlag(QTextDocument::FindFlag flag, bool enabled);
bool hasFindFlag(QTextDocument::FindFlag flag);
void updateCompletion(const QString &text, QStringList &completions, QStringListModel *model);
void setupMenu();
void setupFilterMenuItems();
void writeSettings();
void readSettings();
//variables
Core::ICore *m_core;
QHash<IFindFilter *, QAction *> m_filterActions;
CurrentDocumentFind *m_currentDocumentFind;
FindToolBar *m_findToolBar;
FindToolWindow *m_findDialog;
QTextDocument::FindFlags m_findFlags;
QStringListModel *m_findCompletionModel;
QStringListModel *m_replaceCompletionModel;
QStringList m_findCompletions;
QStringList m_replaceCompletions;
};
} // namespace Internal
} // namespace Find
#endif // FINDPLUGIN_H

View File

@@ -0,0 +1,482 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "findtoolbar.h"
#include "findplugin.h"
#include "textfindconstants.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/actionmanager/actionmanagerinterface.h>
#include <coreplugin/actionmanager/iactioncontainer.h>
#include <coreplugin/actionmanager/icommand.h>
#include <QtCore/QSettings>
#include <QtGui/QPushButton>
#include <QtGui/QMenu>
#include <QtGui/QToolButton>
#include <QtGui/QLineEdit>
#include <QtGui/QKeyEvent>
#include <QtGui/QClipboard>
#include <QtGui/QPainter>
#include <QtGui/QCompleter>
#include <QDebug>
Q_DECLARE_METATYPE(QStringList)
Q_DECLARE_METATYPE(Find::IFindFilter*)
using namespace Find;
using namespace Find::Internal;
FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind)
: m_plugin(plugin),
m_currentDocumentFind(currentDocumentFind),
m_findCompleter(new QCompleter(this)),
m_replaceCompleter(new QCompleter(this)),
m_enterFindStringAction(0),
m_findNextAction(0),
m_findPreviousAction(0),
m_replaceNextAction(0),
m_widget(new QWidget)
{
//setup ui
m_ui.setupUi(m_widget);
addWidget(m_widget);
setFocusProxy(m_ui.findEdit);
connect(m_ui.findEdit, SIGNAL(editingFinished()), this, SLOT(invokeResetIncrementalSearch()));
QWidget *spacerItem = new QWidget;
spacerItem->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
addWidget(spacerItem);
QToolButton *close = new QToolButton;
close->setProperty("type", QLatin1String("dockbutton"));
close->setIcon(QIcon(":/qworkbench/images/closebutton.png"));
connect(close, SIGNAL(clicked()), this, SLOT(hideAndResetFocus()));
addWidget(close);
m_ui.findPreviousButton->setProperty("type", QLatin1String("dockbutton"));
m_ui.findNextButton->setProperty("type", QLatin1String("dockbutton"));
m_ui.replacePreviousButton->setProperty("type", QLatin1String("dockbutton"));
m_ui.replaceNextButton->setProperty("type", QLatin1String("dockbutton"));
m_ui.replaceAllButton->setProperty("type", QLatin1String("dockbutton"));
m_findCompleter->setModel(m_plugin->findCompletionModel());
m_replaceCompleter->setModel(m_plugin->replaceCompletionModel());
m_ui.findEdit->setCompleter(m_findCompleter);
m_findCompleter->popup()->installEventFilter(this);
m_ui.replaceEdit->setCompleter(m_replaceCompleter);
m_ui.findEdit->setSide(qApp->layoutDirection() == Qt::LeftToRight ? Core::Utils::FancyLineEdit::Right : Core::Utils::FancyLineEdit::Left);
QMenu *lineEditMenu = new QMenu(m_ui.findEdit);
m_ui.findEdit->setMenu(lineEditMenu);
m_ui.findEdit->installEventFilter(this);
m_ui.replaceEdit->installEventFilter(this);
m_widget->installEventFilter(this);
connect(m_ui.findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(invokeFindIncremental()));
connect(m_ui.findEdit, SIGNAL(returnPressed()), this, SLOT(invokeFindEnter()));
connect(m_ui.replaceEdit, SIGNAL(returnPressed()), this, SLOT(invokeReplaceEnter()));
QAction *shiftEnterAction = new QAction(m_ui.findEdit);
shiftEnterAction->setShortcut(QKeySequence("Shift+Enter"));
shiftEnterAction->setShortcutContext(Qt::WidgetShortcut);
connect(shiftEnterAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
m_ui.findEdit->addAction(shiftEnterAction);
QAction *shiftReturnAction = new QAction(m_ui.findEdit);
shiftReturnAction->setShortcut(QKeySequence("Shift+Return"));
shiftReturnAction->setShortcutContext(Qt::WidgetShortcut);
connect(shiftReturnAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
m_ui.findEdit->addAction(shiftReturnAction);
QAction *shiftEnterReplaceAction = new QAction(m_ui.replaceEdit);
shiftEnterReplaceAction->setShortcut(QKeySequence("Shift+Enter"));
shiftEnterReplaceAction->setShortcutContext(Qt::WidgetShortcut);
connect(shiftEnterReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
m_ui.replaceEdit->addAction(shiftEnterReplaceAction);
QAction *shiftReturnReplaceAction = new QAction(m_ui.replaceEdit);
shiftReturnReplaceAction->setShortcut(QKeySequence("Shift+Return"));
shiftReturnReplaceAction->setShortcutContext(Qt::WidgetShortcut);
connect(shiftReturnReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
m_ui.replaceEdit->addAction(shiftReturnReplaceAction);
// need to make sure QStringList is registered as metatype
QMetaTypeId<QStringList>::qt_metatype_id();
//register actions
QList<int> globalcontext;
globalcontext << Core::Constants::C_GLOBAL_ID;
Core::ActionManagerInterface *am = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>()->actionManager();
Core::IActionContainer *mfind = am->actionContainer(Constants::M_FIND);
Core::ICommand *cmd;
m_findInDocumentAction = new QAction(tr("Current Document"), this);
cmd = am->registerAction(m_findInDocumentAction, Constants::FIND_IN_DOCUMENT, globalcontext);
cmd->setDefaultKeySequence(QKeySequence::Find);
mfind->addAction(cmd, Constants::G_FIND_FILTERS);
connect(m_findInDocumentAction, SIGNAL(triggered()), this, SLOT(openFind()));
if (QApplication::clipboard()->supportsFindBuffer()) {
m_enterFindStringAction = new QAction(tr("Enter Find String"), this);
cmd = am->registerAction(m_enterFindStringAction, tr("Find.EnterFindString"), globalcontext);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E")));
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
connect(m_enterFindStringAction, SIGNAL(triggered()), this, SLOT(putSelectionToFindClipboard()));
connect(QApplication::clipboard(), SIGNAL(findBufferChanged()), this, SLOT(updateFromFindClipboard()));
}
m_findNextAction = new QAction(tr("Find Next"), this);
cmd = am->registerAction(m_findNextAction, Constants::FIND_NEXT, globalcontext);
cmd->setDefaultKeySequence(QKeySequence::FindNext);
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
connect(m_findNextAction, SIGNAL(triggered()), this, SLOT(invokeFindNext()));
m_ui.findNextButton->setDefaultAction(cmd->action());
m_findPreviousAction = new QAction(tr("Find Previous"), this);
cmd = am->registerAction(m_findPreviousAction, Constants::FIND_PREVIOUS, globalcontext);
cmd->setDefaultKeySequence(QKeySequence::FindPrevious);
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
m_ui.findPreviousButton->setDefaultAction(cmd->action());
m_replaceNextAction = new QAction(tr("Replace && Find Next"), this);
cmd = am->registerAction(m_replaceNextAction, Constants::REPLACE_NEXT, globalcontext);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+=")));
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
connect(m_replaceNextAction, SIGNAL(triggered()), this, SLOT(invokeReplaceNext()));
m_ui.replaceNextButton->setDefaultAction(cmd->action());
m_replacePreviousAction = new QAction(tr("Replace && Find Previous"), this);
cmd = am->registerAction(m_replacePreviousAction, Constants::REPLACE_PREVIOUS, globalcontext);
// shortcut removed, clashes with Ctrl++ on many keyboard layouts
//cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+=")));
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
connect(m_replacePreviousAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious()));
m_ui.replacePreviousButton->setDefaultAction(cmd->action());
m_replaceAllAction = new QAction(tr("Replace All"), this);
cmd = am->registerAction(m_replaceAllAction, Constants::REPLACE_ALL, globalcontext);
mfind->addAction(cmd, Constants::G_FIND_ACTIONS);
connect(m_replaceAllAction, SIGNAL(triggered()), this, SLOT(invokeReplaceAll()));
m_ui.replaceAllButton->setDefaultAction(cmd->action());
m_caseSensitiveAction = new QAction(tr("Case Sensitive"), this);
m_caseSensitiveAction->setIcon(QIcon(":/find/images/casesensitively.png"));
m_caseSensitiveAction->setCheckable(true);
m_caseSensitiveAction->setChecked(false);
cmd = am->registerAction(m_caseSensitiveAction, Constants::CASE_SENSITIVE, globalcontext);
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
connect(m_caseSensitiveAction, SIGNAL(triggered(bool)), m_plugin, SLOT(setCaseSensitive(bool)));
lineEditMenu->addAction(m_caseSensitiveAction);
m_wholeWordAction = new QAction(tr("Whole Words Only"), this);
m_wholeWordAction->setIcon(QIcon(":/find/images/wholewords.png"));
m_wholeWordAction->setCheckable(true);
m_wholeWordAction->setChecked(false);
cmd = am->registerAction(m_wholeWordAction, Constants::WHOLE_WORDS, globalcontext);
mfind->addAction(cmd, Constants::G_FIND_FLAGS);
connect(m_wholeWordAction, SIGNAL(triggered(bool)), m_plugin, SLOT(setWholeWord(bool)));
lineEditMenu->addAction(m_wholeWordAction);
connect(m_currentDocumentFind, SIGNAL(changed()), this, SLOT(updateActions()));
updateActions();
updateIcons();
connect(m_plugin, SIGNAL(findFlagsChanged()), this, SLOT(findFlagsChanged()));
}
FindToolBar::~FindToolBar()
{
}
bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
{
if ((obj == m_ui.findEdit || obj == m_findCompleter->popup())
&& event->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
#ifdef Q_OS_MAC
if (ke->key() == Qt::Key_Space && (ke->modifiers() & Qt::MetaModifier)) {
#else
if (ke->key() == Qt::Key_Space && (ke->modifiers() & Qt::ControlModifier)) {
#endif
QString completedText = m_currentDocumentFind->completedFindString();
if (!completedText.isEmpty()) {
setFindText(completedText);
ke->accept();
return true;
}
}
} else if (obj == m_widget && event->type() == QEvent::ShortcutOverride) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
if (ke->key() == Qt::Key_Escape && !ke->modifiers()
&& !m_findCompleter->popup()->isVisible()
&& !m_replaceCompleter->popup()->isVisible()) {
if (setFocusToCurrentFindSupport()) {
event->accept();
return true;
}
#ifdef Q_OS_MAC
} else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Qt::MetaModifier)) {
#else
} else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Qt::ControlModifier)) {
#endif
event->accept();
return true;
}
} else if (obj == m_widget && event->type() == QEvent::Hide) {
invokeClearResults();
if (m_currentDocumentFind->isEnabled()) {
m_currentDocumentFind->clearFindScope();
}
}
return QToolBar::eventFilter(obj, event);
}
void FindToolBar::updateActions()
{
bool enabled = m_currentDocumentFind->isEnabled();
bool replaceEnabled = enabled && m_currentDocumentFind->supportsReplace();
m_findInDocumentAction->setEnabled(enabled);
m_findNextAction->setEnabled(enabled);
m_findPreviousAction->setEnabled(enabled);
m_replaceNextAction->setEnabled(replaceEnabled);
m_replacePreviousAction->setEnabled(replaceEnabled);
m_replaceAllAction->setEnabled(replaceEnabled);
m_caseSensitiveAction->setEnabled(enabled);
m_wholeWordAction->setEnabled(enabled);
if (QApplication::clipboard()->supportsFindBuffer())
m_enterFindStringAction->setEnabled(enabled);
bool replaceFocus = m_ui.replaceEdit->hasFocus();
m_ui.findEdit->setEnabled(enabled);
m_ui.findLabel->setEnabled(enabled);
m_ui.replaceEdit->setEnabled(replaceEnabled);
m_ui.replaceLabel->setEnabled(replaceEnabled);
if (!replaceEnabled && enabled && replaceFocus)
m_ui.findEdit->setFocus();
}
void FindToolBar::invokeFindEnter()
{
if (m_currentDocumentFind->isEnabled()) {
invokeFindNext();
}
}
void FindToolBar::invokeReplaceEnter()
{
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) {
invokeReplaceNext();
}
}
void FindToolBar::invokeClearResults()
{
if (m_currentDocumentFind->isEnabled()) {
m_currentDocumentFind->clearResults();
}
}
void FindToolBar::invokeFindNext()
{
m_plugin->setBackward(false);
invokeFindStep();
}
void FindToolBar::invokeFindPrevious()
{
m_plugin->setBackward(true);
invokeFindStep();
}
QString FindToolBar::getFindText()
{
return m_ui.findEdit->text();
}
QString FindToolBar::getReplaceText()
{
return m_ui.replaceEdit->text();
}
void FindToolBar::setFindText(const QString &text)
{
disconnect(m_ui.findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(invokeFindIncremental()));
m_ui.findEdit->setText(text);
connect(m_ui.findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(invokeFindIncremental()));
}
void FindToolBar::selectFindText()
{
m_ui.findEdit->selectAll();
}
void FindToolBar::invokeFindStep()
{
if (m_currentDocumentFind->isEnabled()) {
m_plugin->updateFindCompletion(getFindText());
m_currentDocumentFind->findStep(getFindText(), m_plugin->findFlags());
}
}
void FindToolBar::invokeFindIncremental()
{
if (m_currentDocumentFind->isEnabled()) {
QString text = getFindText();
m_currentDocumentFind->findIncremental(text, m_plugin->findFlags());
if (text.isEmpty())
m_currentDocumentFind->clearResults();
}
}
void FindToolBar::invokeReplaceNext()
{
m_plugin->setBackward(false);
invokeReplaceStep();
}
void FindToolBar::invokeReplacePrevious()
{
m_plugin->setBackward(true);
invokeReplaceStep();
}
void FindToolBar::invokeReplaceStep()
{
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) {
m_plugin->updateFindCompletion(getFindText());
m_plugin->updateReplaceCompletion(getReplaceText());
m_currentDocumentFind->replaceStep(getFindText(), getReplaceText(), m_plugin->findFlags());
}
}
void FindToolBar::invokeReplaceAll()
{
m_plugin->updateFindCompletion(getFindText());
m_plugin->updateReplaceCompletion(getReplaceText());
if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) {
m_currentDocumentFind->replaceAll(getFindText(), getReplaceText(), m_plugin->findFlags());
}
}
void FindToolBar::invokeResetIncrementalSearch()
{
if (m_currentDocumentFind->isEnabled())
m_currentDocumentFind->resetIncrementalSearch();
}
void FindToolBar::putSelectionToFindClipboard()
{
const QString text = m_currentDocumentFind->currentFindString();
QApplication::clipboard()->setText(text, QClipboard::FindBuffer);
setFindText(text);
}
void FindToolBar::updateFromFindClipboard()
{
if (QApplication::clipboard()->supportsFindBuffer()) {
const bool blocks = m_ui.findEdit->blockSignals(true);
setFindText(QApplication::clipboard()->text(QClipboard::FindBuffer));
m_ui.findEdit->blockSignals(blocks);
}
}
void FindToolBar::findFlagsChanged()
{
updateIcons();
updateFlagMenus();
invokeClearResults();
}
void FindToolBar::updateIcons()
{
bool casesensitive = m_plugin->findFlags() & QTextDocument::FindCaseSensitively;
bool wholewords = m_plugin->findFlags() & QTextDocument::FindWholeWords;
if (casesensitive && wholewords) {
QPixmap image = QPixmap(":/find/images/wordandcase.png");
m_ui.findEdit->setPixmap(image);
} else if (casesensitive) {
QPixmap image = QPixmap(":/find/images/casesensitively.png");
m_ui.findEdit->setPixmap(image);
} else if (wholewords) {
QPixmap image = QPixmap(":/find/images/wholewords.png");
m_ui.findEdit->setPixmap(image);
} else {
m_ui.findEdit->setPixmap(QPixmap(Core::Constants::ICON_MAGNIFIER));
}
}
void FindToolBar::updateFlagMenus()
{
bool wholeOnly = ((m_plugin->findFlags() & QTextDocument::FindWholeWords));
bool sensitive = ((m_plugin->findFlags() & QTextDocument::FindCaseSensitively));
if (m_wholeWordAction->isChecked() != wholeOnly)
m_wholeWordAction->setChecked(wholeOnly);
if (m_caseSensitiveAction->isChecked() != sensitive)
m_caseSensitiveAction->setChecked(sensitive);
}
bool FindToolBar::setFocusToCurrentFindSupport()
{
return m_currentDocumentFind->setFocusToCurrentFindSupport();
}
void FindToolBar::hideAndResetFocus()
{
m_currentDocumentFind->setFocusToCurrentFindSupport();
hide();
}
void FindToolBar::openFind()
{
if (!m_currentDocumentFind->isEnabled())
return;
Core::FindToolBarPlaceHolder *holder = Core::FindToolBarPlaceHolder::getCurrent();
QLayout *findContainerLayout = holder ? holder->layout() : 0;
if (findContainerLayout) {
findContainerLayout->addWidget(this);
holder->setVisible(true);
setVisible(true);
setFocus();
}
QString text = m_currentDocumentFind->currentFindString();
if (!text.isEmpty())
setFindText(text);
m_currentDocumentFind->defineFindScope();
m_currentDocumentFind->highlightAll(getFindText(), m_plugin->findFlags());
selectFindText();
}

View File

@@ -0,0 +1,112 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef FINDTOOLBAR_H
#define FINDTOOLBAR_H
#include "ui_findwidget.h"
#include "ifindfilter.h"
#include "currentdocumentfind.h"
#include <QtGui/QStringListModel>
#include <QtGui/QWidget>
#include <QtGui/QToolBar>
#include <QtGui/QLabel>
namespace Find {
namespace Internal {
class FindPlugin;
class FindToolBar : public QToolBar
{
Q_OBJECT
public:
FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind);
~FindToolBar();
void invokeClearResults();
private slots:
void invokeFindNext();
void invokeFindPrevious();
void invokeFindStep();
void invokeReplaceNext();
void invokeReplacePrevious();
void invokeReplaceStep();
void invokeReplaceAll();
void invokeResetIncrementalSearch();
void invokeFindIncremental();
void invokeFindEnter();
void invokeReplaceEnter();
void putSelectionToFindClipboard();
void updateFromFindClipboard();
void hideAndResetFocus();
void openFind();
void updateActions();
void findFlagsChanged();
private:
bool setFocusToCurrentFindSupport();
bool eventFilter(QObject *obj, QEvent *event);
void setFindText(const QString &text);
QString getFindText();
QString getReplaceText();
void selectFindText();
void updateIcons();
void updateFlagMenus();
FindPlugin *m_plugin;
CurrentDocumentFind *m_currentDocumentFind;
Ui::FindWidget m_ui;
QCompleter *m_findCompleter;
QCompleter *m_replaceCompleter;
QAction *m_findInDocumentAction;
QAction *m_enterFindStringAction;
QAction *m_findNextAction;
QAction *m_findPreviousAction;
QAction *m_replaceNextAction;
QAction *m_replacePreviousAction;
QAction *m_replaceAllAction;
QAction *m_caseSensitiveAction;
QAction *m_wholeWordAction;
QWidget *m_widget;
};
} // namespace Internal
} // namespace Find
#endif // FINDTOOLBAR_H

View File

@@ -0,0 +1,140 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "findtoolwindow.h"
#include "findplugin.h"
#include <coreplugin/icore.h>
#include <QtGui/QMainWindow>
using namespace Find;
using namespace Find::Internal;
FindToolWindow::FindToolWindow(FindPlugin *plugin)
: QDialog(plugin->core()->mainWindow()),
m_plugin(plugin),
m_findCompleter(new QCompleter(this))
{
m_ui.setupUi(this);
connect(m_ui.closeButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(m_ui.searchButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(m_ui.matchCase, SIGNAL(toggled(bool)), m_plugin, SLOT(setCaseSensitive(bool)));
connect(m_ui.wholeWords, SIGNAL(toggled(bool)), m_plugin, SLOT(setWholeWord(bool)));
connect(m_ui.filterList, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentFilter(int)));
connect(this, SIGNAL(accepted()), this, SLOT(search()));
m_findCompleter->setModel(m_plugin->findCompletionModel());
m_ui.searchTerm->setCompleter(m_findCompleter);
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
m_ui.configWidget->setLayout(layout);
}
FindToolWindow::~FindToolWindow()
{
qDeleteAll(m_configWidgets);
}
void FindToolWindow::setFindFilters(const QList<IFindFilter *> &filters)
{
qDeleteAll(m_configWidgets);
m_configWidgets.clear();
m_filters = filters;
m_ui.filterList->clear();
QStringList names;
foreach (IFindFilter *filter, filters) {
names << filter->name();
m_configWidgets.append(filter->createConfigWidget());
}
m_ui.filterList->addItems(names);
}
void FindToolWindow::setFindText(const QString &text)
{
m_ui.searchTerm->setText(text);
}
void FindToolWindow::open(IFindFilter *filter)
{
int index = m_filters.indexOf(filter);
if (index >= 0) {
m_ui.filterList->setCurrentIndex(index);
}
m_ui.matchCase->setChecked(m_plugin->findFlags() & QTextDocument::FindCaseSensitively);
m_ui.wholeWords->setChecked(m_plugin->findFlags() & QTextDocument::FindWholeWords);
m_ui.searchTerm->setFocus();
m_ui.searchTerm->selectAll();
exec();
}
void FindToolWindow::setCurrentFilter(int index)
{
for (int i = 0; i < m_configWidgets.size(); ++i) {
QWidget *configWidget = m_configWidgets.at(i);
if (!configWidget)
continue;
if (i == index)
m_ui.configWidget->layout()->addWidget(configWidget);
else
configWidget->setParent(0);
}
}
void FindToolWindow::search()
{
m_plugin->updateFindCompletion(m_ui.searchTerm->text());
int index = m_ui.filterList->currentIndex();
QString term = m_ui.searchTerm->text();
if (term.isEmpty() || index < 0)
return;
IFindFilter *filter = m_filters.at(index);
filter->findAll(term, m_plugin->findFlags());
}
void FindToolWindow::writeSettings()
{
QSettings *settings = m_plugin->core()->settings();
settings->beginGroup("Find");
foreach (IFindFilter *filter, m_filters)
filter->writeSettings(settings);
settings->endGroup();
}
void FindToolWindow::readSettings()
{
QSettings *settings = m_plugin->core()->settings();
settings->beginGroup("Find");
foreach (IFindFilter *filter, m_filters)
filter->readSettings(settings);
settings->endGroup();
}

View File

@@ -0,0 +1,78 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef FINDTOOLWINDOW_H
#define FINDTOOLWINDOW_H
#include "ui_finddialog.h"
#include "ifindfilter.h"
#include <QtCore/QList>
#include <QtGui/QCompleter>
#include <QtGui/QWidget>
namespace Find {
namespace Internal {
class FindPlugin;
class FindToolWindow : public QDialog
{
Q_OBJECT
public:
FindToolWindow(FindPlugin *plugin);
~FindToolWindow();
void setFindFilters(const QList<IFindFilter *> &filters);
void setFindText(const QString &text);
void open(IFindFilter *filter);
void readSettings();
void writeSettings();
private slots:
void search();
void setCurrentFilter(int index);
private:
Ui::FindDialog m_ui;
FindPlugin *m_plugin;
QList<IFindFilter *> m_filters;
QCompleter *m_findCompleter;
QList<QWidget *> m_configWidgets;
};
} // namespace Internal
} // namespace Find
#endif // FINDTOOLWINDOW_H

View File

@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Find::Internal::FindWidget</class>
<widget class="QWidget" name="Find::Internal::FindWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>71</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Find</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>15</number>
</property>
<property name="margin">
<number>1</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="findLabel">
<property name="text">
<string>Find:</string>
</property>
</widget>
</item>
<item>
<widget class="Core::Utils::FancyLineEdit" name="findEdit">
<property name="minimumSize">
<size>
<width>160</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>160</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="findPreviousButton">
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="findNextButton">
<property name="font">
<font/>
</property>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="replaceLabel">
<property name="text">
<string>Replace with:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="replaceEdit">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replacePreviousButton">
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replaceNextButton">
<property name="font">
<font/>
</property>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replaceAllButton">
<property name="font">
<font/>
</property>
<property name="text">
<string>All</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Core::Utils::FancyLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/fancylineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,66 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef IFINDFILTER_H
#define IFINDFILTER_H
#include "ifindsupport.h"
#include <QtCore/QSettings>
#include <QtGui/QIcon>
#include <QtGui/QKeySequence>
#include <QtGui/QWidget>
namespace Find {
class FIND_EXPORT IFindFilter : public QObject
{
Q_OBJECT
public:
virtual ~IFindFilter() {}
virtual QString name() const = 0;
virtual bool isEnabled() const = 0;
virtual QKeySequence defaultShortcut() const = 0;
virtual void findAll(const QString &txt, QTextDocument::FindFlags findFlags) = 0;
virtual QWidget *createConfigWidget() { return 0; }
virtual void writeSettings(QSettings *settings) { Q_UNUSED(settings); }
virtual void readSettings(QSettings *settings) { Q_UNUSED(settings); }
signals:
void changed();
};
} // namespace Find
#endif // IFINDFILTER_H

View File

@@ -0,0 +1,76 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef IFINDSUPPORT_H
#define IFINDSUPPORT_H
#include "find_global.h"
#include <QtGui/QTextDocument>
namespace Find {
class FIND_EXPORT IFindSupport : public QObject
{
Q_OBJECT
public:
IFindSupport() : QObject(0) {}
virtual ~IFindSupport() {}
virtual bool supportsReplace() const = 0;
virtual void resetIncrementalSearch() = 0;
virtual void clearResults() = 0;
virtual QString currentFindString() const = 0;
virtual QString completedFindString() const = 0;
virtual void highlightAll(const QString &txt, QTextDocument::FindFlags findFlags);
virtual bool findIncremental(const QString &txt, QTextDocument::FindFlags findFlags) = 0;
virtual bool findStep(const QString &txt, QTextDocument::FindFlags findFlags) = 0;
virtual bool replaceStep(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags) = 0;
virtual int replaceAll(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags) = 0;
virtual void defineFindScope(){}
virtual void clearFindScope(){}
signals:
void changed();
};
inline void IFindSupport::highlightAll(const QString &, QTextDocument::FindFlags){}
} // namespace Find
#endif // IFINDSUPPORT_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 931 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 934 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

View File

@@ -0,0 +1,121 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "searchresulttreeitemdelegate.h"
#include "searchresulttreeitemroles.h"
#include <math.h>
#include <QModelIndex>
#include <QTextDocument>
#include <QPainter>
#include <QAbstractTextDocumentLayout>
#include <QApplication>
using namespace Find::Internal;
SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.model()->data(index, ItemDataRoles::TypeRole).toString().compare("file") == 0)
{
QItemDelegate::paint(painter, option, index);
}
else
{
painter->save();
QStyleOptionViewItemV3 opt = setOptions(index, option);
painter->setFont(opt.font);
QItemDelegate::drawBackground(painter, opt, index);
int lineNumberAreaWidth = drawLineNumber(painter, opt, index);
QRect resultRowRect(opt.rect.adjusted(lineNumberAreaWidth, 0, 0, 0));
QString displayString = index.model()->data(index, Qt::DisplayRole).toString();
drawMarker(painter, index, displayString, resultRowRect);
// Draw the text and focus/selection
QItemDelegate::drawDisplay(painter, opt, resultRowRect, displayString);
QItemDelegate::drawFocus(painter, opt, opt.rect);
painter->restore();
}
}
int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option,
const QModelIndex &index) const
{
static const int lineNumberAreaHorizontalPadding = 4;
const bool isSelected = option.state & QStyle::State_Selected;
int lineNumber = index.model()->data(index, ItemDataRoles::ResultLineNumberRole).toInt();
int lineNumberDigits = (int)floor(log10((double)lineNumber)) + 1;
int minimumLineNumberDigits = qMax((int)m_minimumLineNumberDigits, lineNumberDigits);
int fontWidth = painter->fontMetrics().width(QString(minimumLineNumberDigits, '0'));
int lineNumberAreaWidth = lineNumberAreaHorizontalPadding + fontWidth + lineNumberAreaHorizontalPadding;
QRect lineNumberAreaRect(option.rect);
lineNumberAreaRect.setWidth(lineNumberAreaWidth);
QPalette::ColorGroup cg = QPalette::Normal;
if (!(option.state & QStyle::State_Active))
cg = QPalette::Inactive;
else if (!(option.state & QStyle::State_Enabled))
cg = QPalette::Disabled;
painter->fillRect(lineNumberAreaRect, QBrush(isSelected?
option.palette.brush(cg, QPalette::Highlight):QBrush(qRgb(230, 230, 230))));
painter->setPen(isSelected?
option.palette.color(cg, QPalette::HighlightedText):Qt::darkGray);
painter->drawText(lineNumberAreaRect.adjusted(0, 0, -lineNumberAreaHorizontalPadding, 0),
Qt::AlignRight, QString::number(lineNumber));
return lineNumberAreaWidth;
}
void SearchResultTreeItemDelegate::drawMarker(QPainter *painter, const QModelIndex &index, const QString text,
const QRect &rect) const
{
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
int searchTermStart = index.model()->data(index, ItemDataRoles::SearchTermStartRole).toInt();
int searchTermStartPixels = painter->fontMetrics().width(text.left(searchTermStart));
int searchTermLength = index.model()->data(index, ItemDataRoles::SearchTermLengthRole).toInt();
int searchTermLengthPixels = painter->fontMetrics().width(text.mid(searchTermStart, searchTermLength));
QRect resultHighlightRect(rect);
resultHighlightRect.setLeft(resultHighlightRect.left() + searchTermStartPixels + textMargin - 1); // -1: Cosmetics
resultHighlightRect.setRight(resultHighlightRect.left() + searchTermLengthPixels + 1); // +1: Cosmetics
painter->fillRect(resultHighlightRect, QBrush(qRgb(255, 240, 120)));
}

View File

@@ -0,0 +1,57 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef SEARCHRESULTTREEITEMDELEGATE_H
#define SEARCHRESULTTREEITEMDELEGATE_H
#include <QtGui/QItemDelegate>
namespace Find {
namespace Internal {
class SearchResultTreeItemDelegate: public QItemDelegate
{
public:
SearchResultTreeItemDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
int drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, const QModelIndex &index) const;
void drawMarker(QPainter *painter, const QModelIndex &index, const QString text, const QRect &rect) const;
static const int m_minimumLineNumberDigits = 6;
};
} //Internal
} //Find
#endif

View File

@@ -0,0 +1,57 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef SEARCHRESULTTREEITEMROLES_H
#define SEARCHRESULTTREEITEMROLES_H
namespace Find {
namespace Internal {
namespace ItemDataRoles {
enum roles
{
TypeRole = Qt::UserRole,
FileNameRole,
ResultLinesCountRole,
ResultIndexRole,
ResultLineRole,
ResultLineNumberRole,
SearchTermStartRole,
SearchTermLengthRole,
RowOfItem // The ?-th child of its parent is this this item
};
} //Internal
} //Find
} //itemDataRoles
#endif

View File

@@ -0,0 +1,136 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "searchresulttreeitems.h"
using namespace Find::Internal;
SearchResultTreeItem::SearchResultTreeItem(SearchResultTreeItem::itemType type, const SearchResultTreeItem *parent)
: m_type(type)
, m_parent(parent)
{
}
SearchResultTreeItem::~SearchResultTreeItem()
{
clearChildren();
}
void SearchResultTreeItem::clearChildren(void)
{
qDeleteAll(m_children);
m_children.clear();
}
SearchResultTreeItem::itemType SearchResultTreeItem::getItemType(void) const
{
return m_type;
}
int SearchResultTreeItem::getChildrenCount(void) const
{
return m_children.count();
}
int SearchResultTreeItem::getRowOfItem(void) const
{
return (m_parent?m_parent->m_children.indexOf(const_cast<SearchResultTreeItem*>(this)):0);
}
const SearchResultTreeItem* SearchResultTreeItem::getChild(int index) const
{
return m_children.at(index);
}
const SearchResultTreeItem *SearchResultTreeItem::getParent(void) const
{
return m_parent;
}
void SearchResultTreeItem::appendChild(SearchResultTreeItem *child)
{
m_children.append(child);
}
SearchResultTextRow::SearchResultTextRow(int index, int lineNumber,
const QString &rowText, int searchTermStart, int searchTermLength, const SearchResultTreeItem *parent)
: SearchResultTreeItem(resultRow, parent),
m_index(index),
m_lineNumber(lineNumber),
m_rowText(rowText),
m_searchTermStart(searchTermStart),
m_searchTermLength(searchTermLength)
{
}
int SearchResultTextRow::index() const
{
return m_index;
}
QString SearchResultTextRow::rowText() const
{
return m_rowText;
}
int SearchResultTextRow::lineNumber() const
{
return m_lineNumber;
}
int SearchResultTextRow::searchTermStart() const
{
return m_searchTermStart;
}
int SearchResultTextRow::searchTermLength() const
{
return m_searchTermLength;
}
SearchResultFile::SearchResultFile(const QString &fileName, const SearchResultTreeItem *parent)
: SearchResultTreeItem(resultFile, parent)
, m_fileName(fileName)
{
}
QString SearchResultFile::getFileName(void) const
{
return m_fileName;
}
void SearchResultFile::appendResultLine(int index, int lineNumber, const QString &rowText, int searchTermStart,
int searchTermLength)
{
SearchResultTreeItem *child = new SearchResultTextRow(index, lineNumber, rowText, searchTermStart, searchTermLength, this);
appendChild(child);
}

View File

@@ -0,0 +1,106 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef SEARCHRESULTTREEITEMS_H
#define SEARCHRESULTTREEITEMS_H
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QList>
namespace Find {
namespace Internal {
class SearchResultTreeItem;
class SearchResultTreeItem
{
public:
enum itemType
{
root,
resultRow,
resultFile
};
SearchResultTreeItem(itemType type = root, const SearchResultTreeItem *parent = NULL);
virtual ~SearchResultTreeItem();
itemType getItemType(void) const;
const SearchResultTreeItem *getParent(void) const;
const SearchResultTreeItem *getChild(int index) const;
void appendChild(SearchResultTreeItem *child);
int getChildrenCount(void) const;
int getRowOfItem(void) const;
void clearChildren(void);
private:
itemType m_type;
const SearchResultTreeItem *m_parent;
QList<SearchResultTreeItem *> m_children;
};
class SearchResultTextRow: public SearchResultTreeItem
{
public:
SearchResultTextRow(int index, int lineNumber, const QString &rowText, int searchTermStart,
int searchTermLength, const SearchResultTreeItem *parent);
int index() const;
QString rowText() const;
int lineNumber() const;
int searchTermStart() const;
int searchTermLength() const;
private:
int m_index;
int m_lineNumber;
QString m_rowText;
int m_searchTermStart;
int m_searchTermLength;
};
class SearchResultFile: public SearchResultTreeItem
{
public:
SearchResultFile(const QString &fileName, const SearchResultTreeItem *parent);
QString getFileName(void) const;
void appendResultLine(int index, int lineNumber, const QString &rowText, int searchTermStart,
int searchTermLength);
private:
QString m_fileName;
};
} //Internal
} //Find
#endif

View File

@@ -0,0 +1,260 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "searchresulttreemodel.h"
#include "searchresulttreeitems.h"
#include "searchresulttreeitemroles.h"
#include <QtGui/QFont>
#include <QtGui/QColor>
using namespace Find::Internal;
SearchResultTreeModel::SearchResultTreeModel(QObject *parent)
: QAbstractItemModel(parent)
, m_lastAppendedResultFile(NULL)
{
m_rootItem = new SearchResultTreeItem();
}
SearchResultTreeModel::~SearchResultTreeModel()
{
delete m_rootItem;
}
QModelIndex SearchResultTreeModel::index(int row, int column,
const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
const SearchResultTreeItem *parentItem;
if (!parent.isValid())
parentItem = m_rootItem;
else
parentItem = static_cast<const SearchResultTreeItem*>(parent.internalPointer());
const SearchResultTreeItem *childItem = parentItem->getChild(row);
if (childItem)
return createIndex(row, column, (void *)childItem);
else
return QModelIndex();
}
QModelIndex SearchResultTreeModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QModelIndex();
const SearchResultTreeItem *childItem = static_cast<const SearchResultTreeItem*>(index.internalPointer());
const SearchResultTreeItem *parentItem = childItem->getParent();
if (parentItem == m_rootItem)
return QModelIndex();
return createIndex(parentItem->getRowOfItem(), 0, (void *)parentItem);
}
int SearchResultTreeModel::rowCount(const QModelIndex &parent) const
{
if (parent.column() > 0)
return 0;
const SearchResultTreeItem *parentItem;
if (!parent.isValid())
parentItem = m_rootItem;
else
parentItem = static_cast<const SearchResultTreeItem*>(parent.internalPointer());
return parentItem->getChildrenCount();
}
int SearchResultTreeModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
QVariant SearchResultTreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
const SearchResultTreeItem *item = static_cast<const SearchResultTreeItem*>(index.internalPointer());
QVariant result;
if (item->getItemType() == SearchResultTreeItem::resultRow)
{
const SearchResultTextRow *row = static_cast<const SearchResultTextRow *>(item);
result = data(row, role);
}
else if (item->getItemType() == SearchResultTreeItem::resultFile)
{
const SearchResultFile *file = static_cast<const SearchResultFile *>(item);
result = data(file, role);
}
return result;
}
QVariant SearchResultTreeModel::data(const SearchResultTextRow *row, int role) const
{
QVariant result;
switch (role)
{
case Qt::ToolTipRole:
result = row->rowText().trimmed();
break;
case Qt::FontRole:
result = QFont("courier");
break;
case ItemDataRoles::ResultLineRole:
case Qt::DisplayRole:
result = row->rowText();
break;
case ItemDataRoles::ResultIndexRole:
result = row->index();
break;
case ItemDataRoles::ResultLineNumberRole:
result = row->lineNumber();
break;
case ItemDataRoles::SearchTermStartRole:
result = row->searchTermStart();
break;
case ItemDataRoles::SearchTermLengthRole:
result = row->searchTermLength();
break;
case ItemDataRoles::TypeRole:
result = "row";
break;
case ItemDataRoles::FileNameRole:
{
const SearchResultFile *file = dynamic_cast<const SearchResultFile *>(row->getParent());
result = file->getFileName();
break;
}
default:
result = QVariant();
break;
}
return result;
}
QVariant SearchResultTreeModel::data(const SearchResultFile *file, int role) const
{
QVariant result;
switch (role)
{
case Qt::BackgroundRole:
result = QColor(qRgb(245, 245, 245));
break;
case Qt::FontRole:
{
QFont font;
font.setPointSize(font.pointSize() + 1);
result = font;
break;
}
case Qt::DisplayRole:
result = file->getFileName() + " (" + QString::number(file->getChildrenCount()) + ")";
break;
case ItemDataRoles::FileNameRole:
case Qt::ToolTipRole:
result = file->getFileName();
break;
case ItemDataRoles::ResultLinesCountRole:
result = file->getChildrenCount();
break;
case ItemDataRoles::TypeRole:
result = "file";
break;
default:
result = QVariant();
break;
}
return result;
}
QVariant SearchResultTreeModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
Q_UNUSED(section);
Q_UNUSED(orientation);
Q_UNUSED(role);
return QVariant();
}
void SearchResultTreeModel::appendResultFile(const QString &fileName)
{
m_lastAppendedResultFile = new SearchResultFile(fileName, m_rootItem);
beginInsertRows(QModelIndex(), m_rootItem->getChildrenCount(), m_rootItem->getChildrenCount());
m_rootItem->appendChild(m_lastAppendedResultFile);
endInsertRows();
}
void SearchResultTreeModel::appendResultLine(int index, int lineNumber, const QString &rowText, int searchTermStart,
int searchTermLength)
{
if (!m_lastAppendedResultFile)
return;
QModelIndex lastFile(createIndex(m_lastAppendedResultFile->getRowOfItem(), 0, m_lastAppendedResultFile));
beginInsertRows(lastFile, m_lastAppendedResultFile->getChildrenCount(), m_lastAppendedResultFile->getChildrenCount());
m_lastAppendedResultFile->appendResultLine(index, lineNumber, rowText, searchTermStart, searchTermLength);
endInsertRows();
dataChanged(lastFile, lastFile); // Make sure that the number after the file name gets updated
}
void SearchResultTreeModel::appendResultLine(int index, const QString &fileName, int lineNumber, const QString &rowText,
int searchTermStart, int searchTermLength)
{
if (!m_lastAppendedResultFile || (m_lastAppendedResultFile->getFileName() != fileName))
appendResultFile(fileName);
appendResultLine(index, lineNumber, rowText, searchTermStart, searchTermLength);
}
void SearchResultTreeModel::clear(void)
{
m_lastAppendedResultFile = NULL;
m_rootItem->clearChildren();
reset();
}

View File

@@ -0,0 +1,87 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef SEARCHRESULTTREEMODEL_H
#define SEARCHRESULTTREEMODEL_H
#include <QtCore/QAbstractItemModel>
namespace Find{
namespace Internal {
class SearchResultTreeItem;
class SearchResultTextRow;
class SearchResultFile;
class SearchResultTreeModel: public QAbstractItemModel
{
Q_OBJECT
public:
SearchResultTreeModel(QObject *parent = 0);
~SearchResultTreeModel();
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
signals:
void jumpToSearchResult(const QString &fileName, int lineNumber,
int searchTermStart, int searchTermLength);
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
public slots:
void clear();
void appendResultLine(int index, int lineNumber, const QString &rowText, int searchTermStart,
int searchTermLength);
void appendResultLine(int index, const QString &fileName, int lineNumber, const QString &rowText, int searchTermStart,
int searchTermLength);
private:
void appendResultFile(const QString &fileName);
QVariant data(const SearchResultTextRow *row, int role) const;
QVariant data(const SearchResultFile *file, int role) const;
void initializeData(void);
void disposeData(void);
SearchResultTreeItem *m_rootItem;
SearchResultFile *m_lastAppendedResultFile;
};
} //Internal
} //Find
#endif

View File

@@ -0,0 +1,99 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "searchresulttreeview.h"
#include "searchresulttreeitemroles.h"
#include "searchresulttreemodel.h"
#include "searchresulttreeitemdelegate.h"
#include <QtGui/QHeaderView>
using namespace Find::Internal;
SearchResultTreeView::SearchResultTreeView(QWidget *parent)
: QTreeView(parent)
, m_autoExpandResults(false)
{
m_model = new SearchResultTreeModel(this);
setModel(m_model);
setItemDelegate(new SearchResultTreeItemDelegate(this));
setIndentation(14);
header()->hide();
connect (this, SIGNAL(activated(const QModelIndex&)), this, SLOT(emitJumpToSearchResult(const QModelIndex&)));
}
void SearchResultTreeView::setAutoExpandResults(bool expand)
{
m_autoExpandResults = expand;
}
void SearchResultTreeView::clear(void)
{
m_model->clear();
}
void SearchResultTreeView::appendResultLine(int index, const QString &fileName, int lineNumber, const QString &rowText,
int searchTermStart, int searchTermLength)
{
int rowsBefore = m_model->rowCount();
m_model->appendResultLine(index, fileName, lineNumber, rowText, searchTermStart, searchTermLength);
int rowsAfter = m_model->rowCount();
if (m_autoExpandResults && (rowsAfter > rowsBefore))
setExpanded(model()->index(model()->rowCount()-1, 0), true);
}
void SearchResultTreeView::emitJumpToSearchResult(const QModelIndex &index)
{
if (model()->data(index, ItemDataRoles::TypeRole).toString().compare("row") != 0)
return;
QString fileName(model()->data(index, ItemDataRoles::FileNameRole).toString());
int position = model()->data(index, ItemDataRoles::ResultIndexRole).toInt();
int lineNumber = model()->data(index, ItemDataRoles::ResultLineNumberRole).toInt();
int searchTermStart = model()->data(index, ItemDataRoles::SearchTermStartRole).toInt();
int searchTermLength = model()->data(index, ItemDataRoles::SearchTermLengthRole).toInt();
emit jumpToSearchResult(position, fileName, lineNumber, searchTermStart, searchTermLength);
}
void SearchResultTreeView::keyPressEvent(QKeyEvent *e)
{
if (!e->modifiers() && e->key() == Qt::Key_Return) {
emit activated(currentIndex());
e->accept();
return;
}
QTreeView::keyPressEvent(e);
}

View File

@@ -0,0 +1,74 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef SEARCHRESULTTREEVIEW_H
#define SEARCHRESULTTREEVIEW_H
#include <QtGui/QTreeView>
#include <QtGui/QKeyEvent>
namespace Find {
namespace Internal {
class SearchResultTreeModel;
class SearchResultTreeView: public QTreeView
{
Q_OBJECT
public:
SearchResultTreeView(QWidget *parent = 0);
void setAutoExpandResults(bool expand);
signals:
void jumpToSearchResult(int index, const QString &fileName, int lineNumber,
int searchTermStart, int searchTermLength);
public slots:
void clear();
void appendResultLine(int index, const QString &fileName, int lineNumber, const QString &lineText,
int searchTermStart, int searchTermLength);
private slots:
void emitJumpToSearchResult(const QModelIndex &index);
protected:
void keyPressEvent(QKeyEvent *e);
SearchResultTreeModel *m_model;
bool m_autoExpandResults;
};
} // namespace Internal
} // namespace Find
#endif // SEARCHRESULTTREEVIEW_H

View File

@@ -0,0 +1,196 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "searchresultwindow.h"
#include "searchresulttreemodel.h"
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include <QtCore/QSettings>
#include <QtGui/QListWidget>
#include <QtGui/QToolButton>
using namespace Find;
using namespace Find::Internal;
static const QString SETTINGSKEYSECTIONNAME("SearchResults");
static const QString SETTINGSKEYEXPANDRESULTS("ExpandResults");
SearchResultWindow::SearchResultWindow(Core::ICore *core):
m_core(core),
m_widget(new QStackedWidget())
{
m_widget->setWindowTitle(name());
m_searchResultTreeView = new SearchResultTreeView(m_widget);
m_searchResultTreeView->setUniformRowHeights(true);
m_searchResultTreeView->setFrameStyle(QFrame::NoFrame);
m_widget->addWidget(m_searchResultTreeView);
m_noMatchesFoundDisplay = new QListWidget(m_widget);
m_noMatchesFoundDisplay->addItem(tr("No matches found!"));
m_noMatchesFoundDisplay->setFrameStyle(QFrame::NoFrame);
m_widget->addWidget(m_noMatchesFoundDisplay);
m_expandCollapseToolButton = new QToolButton(m_widget);
m_expandCollapseToolButton->setAutoRaise(true);
m_expandCollapseToolButton->setCheckable(true);
m_expandCollapseToolButton->setIcon(QIcon(":/find/images/expand.png"));
m_expandCollapseToolButton->setToolTip(tr("Expand All"));
connect(m_searchResultTreeView, SIGNAL(jumpToSearchResult(int,const QString&,int,int,int)),
this, SLOT(handleJumpToSearchResult(int,const QString&,int,int,int)));
connect(m_expandCollapseToolButton, SIGNAL(toggled(bool)), this, SLOT(handleExpandCollapseToolButton(bool)));
readSettings();
}
SearchResultWindow::~SearchResultWindow()
{
writeSettings();
delete m_widget;
m_widget = 0;
qDeleteAll(m_items);
m_items.clear();
}
bool SearchResultWindow::hasFocus()
{
return m_searchResultTreeView->hasFocus();
}
bool SearchResultWindow::canFocus()
{
return !m_items.isEmpty();
}
void SearchResultWindow::setFocus()
{
if (!m_items.isEmpty())
m_searchResultTreeView->setFocus();
}
void SearchResultWindow::visibilityChanged(bool /*visible*/)
{
}
QWidget *SearchResultWindow::outputWidget(QWidget *)
{
return m_widget;
}
QList<QWidget*> SearchResultWindow::toolBarWidgets(void) const
{
return QList<QWidget*>() << m_expandCollapseToolButton;
}
void SearchResultWindow::clearContents()
{
m_widget->setCurrentWidget(m_searchResultTreeView);
m_searchResultTreeView->clear();
qDeleteAll(m_items);
m_items.clear();
}
void SearchResultWindow::showNoMatchesFound(void)
{
m_widget->setCurrentWidget(m_noMatchesFoundDisplay);
}
bool SearchResultWindow::isEmpty() const
{
return (m_searchResultTreeView->model()->rowCount() < 1);
}
int SearchResultWindow::numberOfResults() const
{
return m_searchResultTreeView->model()->rowCount();
}
void SearchResultWindow::handleJumpToSearchResult(int index, const QString &fileName, int lineNumber,
int searchTermStart, int searchTermLength)
{
Q_UNUSED(searchTermLength);
ResultWindowItem *item = m_items.at(index);
emit item->activated(fileName, lineNumber, searchTermStart);
}
ResultWindowItem *SearchResultWindow::addResult(const QString &fileName, int lineNumber, const QString &rowText,
int searchTermStart, int searchTermLength)
{
m_widget->setCurrentWidget(m_searchResultTreeView);
int index = m_items.size();
ResultWindowItem *item = new ResultWindowItem;
m_items.append(item);
m_searchResultTreeView->appendResultLine(index, fileName, lineNumber, rowText, searchTermStart, searchTermLength);
if (index == 0) {
// We didn't have an item before, set the focus to the m_searchResultTreeView
m_searchResultTreeView->setFocus();
m_searchResultTreeView->selectionModel()->select(m_searchResultTreeView->model()->index(0, 0, QModelIndex()), QItemSelectionModel::Select);
}
return item;
}
void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
{
m_searchResultTreeView->setAutoExpandResults(checked);
if (checked)
m_searchResultTreeView->expandAll();
else
m_searchResultTreeView->collapseAll();
}
void SearchResultWindow::readSettings(void)
{
if (m_core && m_core->settings()) {
QSettings *s = m_core->settings();
s->beginGroup(SETTINGSKEYSECTIONNAME);
m_expandCollapseToolButton->setChecked(s->value(SETTINGSKEYEXPANDRESULTS, m_initiallyExpand).toBool());
s->endGroup();
}
}
void SearchResultWindow::writeSettings(void)
{
if (m_core && m_core->settings()) {
QSettings *s = m_core->settings();
s->beginGroup(SETTINGSKEYSECTIONNAME);
s->setValue(SETTINGSKEYEXPANDRESULTS, m_expandCollapseToolButton->isChecked());
s->endGroup();
}
}
int SearchResultWindow::priorityInStatusBar() const
{
return 80;
}

View File

@@ -0,0 +1,108 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef SEARCHRESULTWINDOW_H
#define SEARCHRESULTWINDOW_H
#include "find_global.h"
#include "searchresulttreeview.h"
#include <coreplugin/ioutputpane.h>
#include <coreplugin/icore.h>
#include <QtCore/QThread>
#include <QtCore/QStringList>
#include <QtGui/QStackedWidget>
#include <QtGui/QListWidget>
#include <QtGui/QToolButton>
namespace Find {
class SearchResultWindow;
class FIND_EXPORT ResultWindowItem : public QObject
{
Q_OBJECT
signals:
void activated(const QString &fileName, int lineNumber, int column);
friend class SearchResultWindow;
};
class FIND_EXPORT SearchResultWindow : public Core::IOutputPane
{
Q_OBJECT
public:
SearchResultWindow(Core::ICore *core);
~SearchResultWindow();
QWidget *outputWidget(QWidget *);
QList<QWidget*> toolBarWidgets(void) const;
QString name() const { return tr("Search Results"); }
int priorityInStatusBar() const;
void visibilityChanged(bool visible);
bool isEmpty() const;
int numberOfResults() const;
bool hasFocus();
bool canFocus();
void setFocus();
public slots:
void clearContents();
void showNoMatchesFound();
ResultWindowItem *addResult(const QString &fileName, int lineNumber, const QString &lineText,
int searchTermStart, int searchTermLength);
private slots:
void handleExpandCollapseToolButton(bool checked);
void handleJumpToSearchResult(int index, const QString &fileName, int lineNumber,
int searchTermStart, int searchTermLength);
private:
void readSettings(void);
void writeSettings(void);
Internal::SearchResultTreeView *m_searchResultTreeView;
QListWidget *m_noMatchesFoundDisplay;
Core::ICore *m_core;
QToolButton *m_expandCollapseToolButton;
static const bool m_initiallyExpand = false;
QStackedWidget *m_widget;
QList<ResultWindowItem *> m_items;
};
} // namespace Find
#endif // SEARCHRESULTWINDOW_H

View File

@@ -0,0 +1,57 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef TEXTFINDCONSTANTS_H
#define TEXTFINDCONSTANTS_H
namespace Find {
namespace Constants {
const char * const M_FIND = "Find.FindMenu";
const char * const G_FIND_FILTERS = "Find.FindMenu.Filters";
const char * const G_FIND_FLAGS = "Find.FindMenu.Flags";
const char * const G_FIND_ACTIONS = "Find.FindMenu.Actions";
const char * const FIND = "Find.FindReplace";
const char * const FIND_IN_DOCUMENT = "Find.FindInCurrentDocument";
const char * const FIND_NEXT = "Find.FindNext";
const char * const FIND_PREVIOUS = "Find.FindPrevious";
const char * const FIND_ALL = "Find.FindAll";
const char * const REPLACE_NEXT = "Find.ReplaceNext";
const char * const REPLACE_PREVIOUS = "Find.ReplacePrevious";
const char * const REPLACE_ALL = "Find.ReplaceAll";
const char * const CASE_SENSITIVE = "Find.CaseSensitive";
const char * const WHOLE_WORDS = "Find.WholeWords";
const char * const TASK_SEARCH = "Find.Task.Search";
}
} //Find
#endif //TEXTFINDCONSTANTS_H