Files
qt-creator/src/plugins/find/currentdocumentfind.cpp

200 lines
5.7 KiB
C++
Raw Normal View History

2008-12-02 12:01:29 +01:00
/***************************************************************************
**
** 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
**
2008-12-02 12:01:29 +01:00
** 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
**
2008-12-02 12:01:29 +01:00
** 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.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
2008-12-02 15:08:31 +01:00
2008-12-02 12:01:29 +01:00
#include "currentdocumentfind.h"
2008-12-02 15:08:31 +01:00
2008-12-02 12:01:29 +01:00
#include <aggregation/aggregate.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
2008-12-09 15:25:01 +01:00
#include <utils/qtcassert.h>
2008-12-02 12:01:29 +01:00
2008-12-09 15:25:01 +01:00
#include <QtCore/QDebug>
2008-12-02 12:01:29 +01:00
#include <QtGui/QApplication>
using namespace Core;
using namespace Find;
using namespace Find::Internal;
CurrentDocumentFind::CurrentDocumentFind(ICore *core)
2008-12-09 15:25:01 +01:00
: m_core(core), m_currentFind(0)
2008-12-02 12:01:29 +01:00
{
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)),
this, SLOT(updateCurrentFindFilter(QWidget*,QWidget*)));
}
void CurrentDocumentFind::removeConnections()
{
disconnect(qApp, 0, this, 0);
removeFindSupportConnections();
}
void CurrentDocumentFind::resetIncrementalSearch()
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return);
m_currentFind->resetIncrementalSearch();
2008-12-02 12:01:29 +01:00
}
void CurrentDocumentFind::clearResults()
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return);
m_currentFind->clearResults();
2008-12-02 12:01:29 +01:00
}
bool CurrentDocumentFind::isEnabled() const
{
return m_currentFind && (!m_currentWidget || m_currentWidget->isVisible());
}
bool CurrentDocumentFind::supportsReplace() const
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return false);
return m_currentFind->supportsReplace();
2008-12-02 12:01:29 +01:00
}
QString CurrentDocumentFind::currentFindString() const
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return QString());
return m_currentFind->currentFindString();
2008-12-02 12:01:29 +01:00
}
QString CurrentDocumentFind::completedFindString() const
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return QString());
return m_currentFind->completedFindString();
2008-12-02 12:01:29 +01:00
}
void CurrentDocumentFind::highlightAll(const QString &txt, QTextDocument::FindFlags findFlags)
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return);
m_currentFind->highlightAll(txt, findFlags);
2008-12-02 12:01:29 +01:00
}
bool CurrentDocumentFind::findIncremental(const QString &txt, QTextDocument::FindFlags findFlags)
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return false);
return m_currentFind->findIncremental(txt, findFlags);
2008-12-02 12:01:29 +01:00
}
bool CurrentDocumentFind::findStep(const QString &txt, QTextDocument::FindFlags findFlags)
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return false);
return m_currentFind->findStep(txt, findFlags);
2008-12-02 12:01:29 +01:00
}
bool CurrentDocumentFind::replaceStep(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags)
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return false);
return m_currentFind->replaceStep(before, after, findFlags);
2008-12-02 12:01:29 +01:00
}
int CurrentDocumentFind::replaceAll(const QString &before, const QString &after,
QTextDocument::FindFlags findFlags)
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return 0);
return m_currentFind->replaceAll(before, after, findFlags);
2008-12-02 12:01:29 +01:00
}
void CurrentDocumentFind::defineFindScope()
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return);
m_currentFind->defineFindScope();
2008-12-02 12:01:29 +01:00
}
void CurrentDocumentFind::clearFindScope()
{
2008-12-09 15:25:01 +01:00
QTC_ASSERT(m_currentFind, return);
m_currentFind->clearFindScope();
2008-12-02 12:01:29 +01:00
}
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);
}