1 | /* $Id: UIVMLogViewerSearchWidget.h 103923 2024-03-19 17:01:11Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMLogViewer class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerSearchWidget_h
|
---|
29 | #define FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerSearchWidget_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QTextDocument>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "UIVMLogViewerPanel.h"
|
---|
39 |
|
---|
40 | /* Forward declarations: */
|
---|
41 | class QCheckBox;
|
---|
42 | class QHBoxLayout;
|
---|
43 | class QLabel;
|
---|
44 | class QWidget;
|
---|
45 | class QIToolButton;
|
---|
46 | class UISearchLineEdit;
|
---|
47 | class UIVMLogViewerWidget;
|
---|
48 |
|
---|
49 | /** UIVMLogViewerPanel extension
|
---|
50 | * providing GUI for search-panel in VM Log-Viewer. */
|
---|
51 | class UIVMLogViewerSearchWidget : public UIVMLogViewerPane
|
---|
52 | {
|
---|
53 | Q_OBJECT;
|
---|
54 |
|
---|
55 | signals:
|
---|
56 |
|
---|
57 | void sigHighlightingUpdated();
|
---|
58 | void sigSearchUpdated();
|
---|
59 | void sigShowPane();
|
---|
60 |
|
---|
61 | public:
|
---|
62 |
|
---|
63 | /** Constructs search-panel by passing @a pParent to the QWidget base-class constructor.
|
---|
64 | * @param pViewer Specifies instance of VM Log-Viewer. */
|
---|
65 | UIVMLogViewerSearchWidget(QWidget *pParent, UIVMLogViewerWidget *pViewer);
|
---|
66 | /** Resets the search position and starts a new search. */
|
---|
67 | void refreshSearch();
|
---|
68 | const QVector<float> &matchLocationVector() const;
|
---|
69 | /** Returns the number of the matches to the current search. */
|
---|
70 | int matchCount() const;
|
---|
71 | /** Handles Qt @a pEvent, used for keyboard processing. */
|
---|
72 | bool handleSearchRelatedEvents(QObject *pObject, QEvent *pEvent);
|
---|
73 |
|
---|
74 | protected:
|
---|
75 |
|
---|
76 | virtual void prepareWidgets() RT_OVERRIDE;
|
---|
77 | virtual void prepareConnections() RT_OVERRIDE;
|
---|
78 | /** Handles Qt key-press @a pEevent. */
|
---|
79 | virtual void keyPressEvent(QKeyEvent *pEvent) RT_OVERRIDE;
|
---|
80 | virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
|
---|
81 | virtual void hideEvent(QHideEvent* pEvent) RT_OVERRIDE;
|
---|
82 |
|
---|
83 | private slots:
|
---|
84 |
|
---|
85 | /** Handles textchanged signal from search-editor.
|
---|
86 | * @param strSearchString Specifies search-string. */
|
---|
87 | void sltSearchTextChanged(const QString &strSearchString);
|
---|
88 | void sltHighlightAllCheckBox();
|
---|
89 | void sltCaseSentitiveCheckBox();
|
---|
90 | void sltMatchWholeWordCheckBox();
|
---|
91 | void sltSelectNextPreviousMatch();
|
---|
92 | void sltRetranslateUI();
|
---|
93 |
|
---|
94 | private:
|
---|
95 |
|
---|
96 | enum SearchDirection { ForwardSearch, BackwardSearch };
|
---|
97 |
|
---|
98 | /** Clear the highlighting */
|
---|
99 | void clearHighlighting();
|
---|
100 |
|
---|
101 | /** Search routine.
|
---|
102 | * @param eDirection Specifies the seach direction
|
---|
103 | * @param highlight if false highlight function is not called
|
---|
104 | thus we avoid calling highlighting for the same string repeatedly. */
|
---|
105 | void performSearch(SearchDirection eDirection, bool highlight);
|
---|
106 | void highlightAll(const QString &searchString);
|
---|
107 | void findAll(QTextDocument *pDocument, const QString &searchString);
|
---|
108 | void selectMatch(int iMatchIndex, const QString &searchString);
|
---|
109 | void moveSelection(bool fForward);
|
---|
110 |
|
---|
111 | /** Constructs the find flags for QTextDocument::find function. */
|
---|
112 | QTextDocument::FindFlags constructFindFlags(SearchDirection eDirection) const;
|
---|
113 | /** Searches the whole document and return the number of matches to the current search term. */
|
---|
114 | int countMatches(QTextDocument *pDocument, const QString &searchString) const;
|
---|
115 | void reset();
|
---|
116 |
|
---|
117 | /** Holds the instance of search-editor we create. */
|
---|
118 | UISearchLineEdit *m_pSearchEditor;
|
---|
119 |
|
---|
120 | QIToolButton *m_pNextButton;
|
---|
121 | QIToolButton *m_pPreviousButton;
|
---|
122 | /** Holds the instance of case-sensitive checkbox we create. */
|
---|
123 | QCheckBox *m_pCaseSensitiveCheckBox;
|
---|
124 | QCheckBox *m_pMatchWholeWordCheckBox;
|
---|
125 | QCheckBox *m_pHighlightAllCheckBox;
|
---|
126 | /** Stores relative positions of the lines of the matches wrt. total # of lines. The values are in [0,1]
|
---|
127 | 0 being the first line 1 being the last. */
|
---|
128 | QVector<float> m_matchLocationVector;
|
---|
129 | /** Document positions of the cursors within th document for all matches. */
|
---|
130 | QVector<int> m_matchedCursorPosition;
|
---|
131 | /** The index of the curently selected item within m_matchedCursorPosition. */
|
---|
132 | int m_iSelectedMatchIndex;
|
---|
133 | };
|
---|
134 |
|
---|
135 |
|
---|
136 | #endif /* !FEQT_INCLUDED_SRC_logviewer_UIVMLogViewerSearchWidget_h */
|
---|