searchresultwindow.h 4.06 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11 12 13 14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32 33 34 35 36 37
#ifndef SEARCHRESULTWINDOW_H
#define SEARCHRESULTWINDOW_H

#include "find_global.h"
#include "searchresulttreeview.h"

#include <coreplugin/ioutputpane.h>

38 39 40 41 42 43 44

QT_BEGIN_NAMESPACE
class QStackedWidget;
class QListWidget;
class QToolButton;
class QLabel;
QT_END_NAMESPACE
con's avatar
con committed
45 46 47 48 49

namespace Find {

class SearchResultWindow;

50
struct FIND_EXPORT SearchResultItem
con's avatar
con committed
51
{
52 53 54 55 56 57 58 59 60
    QString fileName;
    int lineNumber;
    QString lineText;
    int searchTermStart;
    int searchTermLength;
    int index;
    QVariant userData;
    // whatever information we also need here
};
con's avatar
con committed
61

62 63 64
class FIND_EXPORT SearchResult : public QObject
{
    Q_OBJECT
con's avatar
con committed
65

con's avatar
con committed
66
signals:
67 68
    void activated(const Find::SearchResultItem &item);
    void replaceButtonClicked(const QString &replaceText, const QList<Find::SearchResultItem> &checkedItems);
con's avatar
con committed
69

con's avatar
con committed
70 71 72 73 74 75 76 77
    friend class SearchResultWindow;
};

class FIND_EXPORT SearchResultWindow : public Core::IOutputPane
{
    Q_OBJECT

public:
78 79 80 81 82
    enum SearchMode {
        SearchOnly,
        SearchAndReplace
    };

83
    SearchResultWindow();
con's avatar
con committed
84 85 86
    ~SearchResultWindow();

    QWidget *outputWidget(QWidget *);
Thorbjørn Lindeijer's avatar
Thorbjørn Lindeijer committed
87
    QList<QWidget*> toolBarWidgets() const;
con's avatar
con committed
88 89 90 91 92 93 94 95 96 97

    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();

98 99 100 101 102 103
    bool canNext();
    bool canPrevious();
    void goToNext();
    void goToPrev();
    bool canNavigate();

104 105
    void setTextEditorFont(const QFont &font);

106 107 108
    void setShowReplaceUI(bool show);
    bool isShowingReplaceUI() const;

109 110 111
    void setTextToReplace(const QString &textToReplace);
    QString textToReplace() const;

112 113
    // search result object only lives till next startnewsearch call
    SearchResult *startNewSearch(SearchMode searchOrSearchAndReplace = SearchOnly);
114

con's avatar
con committed
115 116 117
public slots:
    void clearContents();
    void showNoMatchesFound();
118 119
    void addResult(const QString &fileName, int lineNumber, const QString &lineText,
                   int searchTermStart, int searchTermLength, const QVariant &userData = QVariant());
con's avatar
con committed
120 121 122

private slots:
    void handleExpandCollapseToolButton(bool checked);
123
    void handleJumpToSearchResult(int index, bool checked);
124
    void handleReplaceButton();
125
    void setReplaceUIEnabled(bool enabled);
con's avatar
con committed
126 127

private:
hjk's avatar
hjk committed
128 129
    void readSettings();
    void writeSettings();
130
    QList<SearchResultItem> checkedItems() const;
con's avatar
con committed
131 132 133 134

    Internal::SearchResultTreeView *m_searchResultTreeView;
    QListWidget *m_noMatchesFoundDisplay;
    QToolButton *m_expandCollapseToolButton;
135 136 137
    QLabel *m_replaceLabel;
    QLineEdit *m_replaceTextEdit;
    QToolButton *m_replaceButton;
con's avatar
con committed
138 139
    static const bool m_initiallyExpand = false;
    QStackedWidget *m_widget;
140 141
    SearchResult *m_currentSearch;
    QList<SearchResultItem> m_items;
142
    bool m_isShowingReplaceUI;
con's avatar
con committed
143 144 145 146 147
};

} // namespace Find

#endif // SEARCHRESULTWINDOW_H