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

198 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) 2009 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
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()
: 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, IFindSupport::FindFlags findFlags)
2008-12-02 12:01:29 +01:00
{
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, IFindSupport::FindFlags findFlags)
2008-12-02 12:01:29 +01:00
{
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, IFindSupport::FindFlags findFlags)
2008-12-02 12:01:29 +01:00
{
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,
IFindSupport::FindFlags findFlags)
2008-12-02 12:01:29 +01:00
{
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,
IFindSupport::FindFlags findFlags)
2008-12-02 12:01:29 +01:00
{
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 || impl == m_currentFind)
2008-12-02 12:01:29 +01:00
return;
removeFindSupportConnections();
if (m_currentFind)
m_currentFind->highlightAll(QString(), 0);
2008-12-02 12:01:29 +01:00
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);
}