1 | /* $Id: UIVMLogViewerPanel.cpp 101092 2023-09-12 12:54:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMLogViewer class implementation.
|
---|
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 | /* Qt includes: */
|
---|
29 | #include <QHBoxLayout>
|
---|
30 | #include <QPlainTextEdit>
|
---|
31 | #include <QPushButton>
|
---|
32 |
|
---|
33 | /* GUI includes: */
|
---|
34 | #include "UIIconPool.h"
|
---|
35 | #include "UIVMLogPage.h"
|
---|
36 | #include "UIVMLogViewerPanel.h"
|
---|
37 | #include "UIVMLogViewerWidget.h"
|
---|
38 | #include "UIVMLogViewerSearchWidget.h"
|
---|
39 | #include "UIVMLogViewerFilterWidget.h"
|
---|
40 | #include "UIVMLogViewerBookmarksWidget.h"
|
---|
41 | #include "UIVMLogViewerPreferencesWidget.h"
|
---|
42 |
|
---|
43 | #ifdef VBOX_WS_MAC
|
---|
44 | # include "VBoxUtils-darwin.h"
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | UIVMLogViewerPaneContainer::UIVMLogViewerPaneContainer(QWidget *pParent, UIVMLogViewerWidget *pViewer)
|
---|
48 | : UIPaneContainer(pParent)
|
---|
49 | , m_pViewer(pViewer)
|
---|
50 | , m_pSearchWidget(0)
|
---|
51 | , m_pFilterWidget(0)
|
---|
52 | , m_pBookmarksWidget(0)
|
---|
53 | , m_pPreferencesWidget(0)
|
---|
54 | {
|
---|
55 | prepare();
|
---|
56 | }
|
---|
57 |
|
---|
58 | void UIVMLogViewerPaneContainer::prepare()
|
---|
59 | {
|
---|
60 | /* Search tab: */
|
---|
61 | m_pSearchWidget = new UIVMLogViewerSearchWidget(0, m_pViewer);
|
---|
62 | insertTab(Page_Search, m_pSearchWidget);
|
---|
63 |
|
---|
64 | connect(m_pSearchWidget, &UIVMLogViewerSearchWidget::sigHighlightingUpdated,
|
---|
65 | this, &UIVMLogViewerPaneContainer::sigHighlightingUpdated);
|
---|
66 | connect(m_pSearchWidget, &UIVMLogViewerSearchWidget::sigSearchUpdated,
|
---|
67 | this, &UIVMLogViewerPaneContainer::sigSearchUpdated);
|
---|
68 | connect(m_pSearchWidget, &UIVMLogViewerSearchWidget::sigShowPane,
|
---|
69 | this, &UIVMLogViewerPaneContainer::sigShowSearchPane);
|
---|
70 |
|
---|
71 | /* Filter tab: */
|
---|
72 | m_pFilterWidget = new UIVMLogViewerFilterWidget(0, m_pViewer);
|
---|
73 | insertTab(Page_Filter, m_pFilterWidget);
|
---|
74 |
|
---|
75 | connect(m_pFilterWidget, &UIVMLogViewerFilterWidget::sigFilterApplied,
|
---|
76 | this, &UIVMLogViewerPaneContainer::sigFilterApplied);
|
---|
77 |
|
---|
78 | /* Bookmark tab: */
|
---|
79 | m_pBookmarksWidget = new UIVMLogViewerBookmarksWidget(0, m_pViewer);
|
---|
80 | insertTab(Page_Bookmark, m_pBookmarksWidget);
|
---|
81 |
|
---|
82 | connect(m_pBookmarksWidget, &UIVMLogViewerBookmarksWidget::sigDeleteBookmarkByIndex,
|
---|
83 | this, &UIVMLogViewerPaneContainer::sigDeleteBookmarkByIndex);
|
---|
84 | connect(m_pBookmarksWidget, &UIVMLogViewerBookmarksWidget::sigDeleteAllBookmarks,
|
---|
85 | this, &UIVMLogViewerPaneContainer::sigDeleteAllBookmarks);
|
---|
86 | connect(m_pBookmarksWidget, &UIVMLogViewerBookmarksWidget::sigBookmarkSelected,
|
---|
87 | this, &UIVMLogViewerPaneContainer::sigBookmarkSelected);
|
---|
88 |
|
---|
89 | /* Preferences tab: */
|
---|
90 | m_pPreferencesWidget = new UIVMLogViewerPreferencesWidget(0, m_pViewer);
|
---|
91 | insertTab(Page_Preferences, m_pPreferencesWidget);
|
---|
92 |
|
---|
93 | connect(m_pPreferencesWidget, &UIVMLogViewerPreferencesWidget::sigShowLineNumbers,
|
---|
94 | this, &UIVMLogViewerPaneContainer::sigShowLineNumbers);
|
---|
95 | connect(m_pPreferencesWidget, &UIVMLogViewerPreferencesWidget::sigWrapLines,
|
---|
96 | this, &UIVMLogViewerPaneContainer::sigWrapLines);
|
---|
97 | connect(m_pPreferencesWidget, &UIVMLogViewerPreferencesWidget::sigChangeFontSizeInPoints,
|
---|
98 | this, &UIVMLogViewerPaneContainer::sigChangeFontSizeInPoints);
|
---|
99 | connect(m_pPreferencesWidget, &UIVMLogViewerPreferencesWidget::sigChangeFont,
|
---|
100 | this, &UIVMLogViewerPaneContainer::sigChangeFont);
|
---|
101 | connect(m_pPreferencesWidget, &UIVMLogViewerPreferencesWidget::sigResetToDefaults,
|
---|
102 | this, &UIVMLogViewerPaneContainer::sigResetToDefaults);
|
---|
103 |
|
---|
104 | retranslateUi();
|
---|
105 | }
|
---|
106 |
|
---|
107 | void UIVMLogViewerPaneContainer::refreshSearch()
|
---|
108 | {
|
---|
109 | if (m_pSearchWidget)
|
---|
110 | m_pSearchWidget->refreshSearch();
|
---|
111 | }
|
---|
112 |
|
---|
113 | QVector<float> UIVMLogViewerPaneContainer::matchLocationVector() const
|
---|
114 | {
|
---|
115 | if (!m_pSearchWidget)
|
---|
116 | return QVector<float>();
|
---|
117 | return m_pSearchWidget->matchLocationVector();
|
---|
118 | }
|
---|
119 |
|
---|
120 | int UIVMLogViewerPaneContainer::matchCount() const
|
---|
121 | {
|
---|
122 | if (!m_pSearchWidget)
|
---|
123 | return 0;
|
---|
124 | return m_pSearchWidget->matchCount();
|
---|
125 | }
|
---|
126 |
|
---|
127 | void UIVMLogViewerPaneContainer::applyFilter()
|
---|
128 | {
|
---|
129 | if (m_pFilterWidget)
|
---|
130 | m_pFilterWidget->applyFilter();
|
---|
131 | }
|
---|
132 |
|
---|
133 | void UIVMLogViewerPaneContainer::updateBookmarkList(const QVector<UIVMLogBookmark>& bookmarkList)
|
---|
134 | {
|
---|
135 | if (m_pBookmarksWidget)
|
---|
136 | m_pBookmarksWidget->updateBookmarkList(bookmarkList);
|
---|
137 | }
|
---|
138 |
|
---|
139 | void UIVMLogViewerPaneContainer::disableEnableBookmarking(bool flag)
|
---|
140 | {
|
---|
141 | if (m_pBookmarksWidget)
|
---|
142 | m_pBookmarksWidget->disableEnableBookmarking(flag);
|
---|
143 | }
|
---|
144 |
|
---|
145 | void UIVMLogViewerPaneContainer::setShowLineNumbers(bool bShowLineNumbers)
|
---|
146 | {
|
---|
147 | if (m_pPreferencesWidget)
|
---|
148 | m_pPreferencesWidget->setShowLineNumbers(bShowLineNumbers);
|
---|
149 | }
|
---|
150 |
|
---|
151 | void UIVMLogViewerPaneContainer::setWrapLines(bool bWrapLines)
|
---|
152 | {
|
---|
153 | if (m_pPreferencesWidget)
|
---|
154 | m_pPreferencesWidget->setWrapLines(bWrapLines);
|
---|
155 | }
|
---|
156 |
|
---|
157 | void UIVMLogViewerPaneContainer::setFontSizeInPoints(int fontSizeInPoints)
|
---|
158 | {
|
---|
159 | if (m_pPreferencesWidget)
|
---|
160 | m_pPreferencesWidget->setFontSizeInPoints(fontSizeInPoints);
|
---|
161 | }
|
---|
162 |
|
---|
163 | void UIVMLogViewerPaneContainer::retranslateUi()
|
---|
164 | {
|
---|
165 | setTabText(Page_Search, "Find");
|
---|
166 | setTabText(Page_Filter, "Filter");
|
---|
167 | setTabText(Page_Bookmark, "Bookmarks");
|
---|
168 | setTabText(Page_Preferences, "Preferences");
|
---|
169 | }
|
---|
170 |
|
---|
171 | bool UIVMLogViewerPaneContainer::eventFilter(QObject *pObject, QEvent *pEvent)
|
---|
172 | {
|
---|
173 | /* Check if the search panel is interested in the event (most prob. key event): */
|
---|
174 | if (m_pSearchWidget && m_pSearchWidget->handleSearchRelatedEvents(pObject, pEvent))
|
---|
175 | return true;
|
---|
176 |
|
---|
177 | return UIPaneContainer::eventFilter(pObject, pEvent);
|
---|
178 | }
|
---|
179 |
|
---|
180 |
|
---|
181 | /*********************************************************************************************************************************
|
---|
182 | * UIVMLogViewerPanel implementation. *
|
---|
183 | *********************************************************************************************************************************/
|
---|
184 |
|
---|
185 | UIVMLogViewerPane::UIVMLogViewerPane(QWidget *pParent, UIVMLogViewerWidget *pViewer)
|
---|
186 | : QIWithRetranslateUI<QWidget>(pParent)
|
---|
187 | , m_pViewer(pViewer)
|
---|
188 | {
|
---|
189 | }
|
---|
190 |
|
---|
191 | void UIVMLogViewerPane::retranslateUi()
|
---|
192 | {
|
---|
193 | }
|
---|
194 |
|
---|
195 | UIVMLogViewerWidget* UIVMLogViewerPane::viewer()
|
---|
196 | {
|
---|
197 | return m_pViewer;
|
---|
198 | }
|
---|
199 |
|
---|
200 | const UIVMLogViewerWidget* UIVMLogViewerPane::viewer() const
|
---|
201 | {
|
---|
202 | return m_pViewer;
|
---|
203 | }
|
---|
204 |
|
---|
205 | QTextDocument *UIVMLogViewerPane::textDocument()
|
---|
206 | {
|
---|
207 | QPlainTextEdit *pEdit = textEdit();
|
---|
208 | if (!pEdit)
|
---|
209 | return 0;
|
---|
210 | return textEdit()->document();
|
---|
211 | }
|
---|
212 |
|
---|
213 | QPlainTextEdit *UIVMLogViewerPane::textEdit()
|
---|
214 | {
|
---|
215 | if (!viewer())
|
---|
216 | return 0;
|
---|
217 | UIVMLogPage *logPage = viewer()->currentLogPage();
|
---|
218 | if (!logPage)
|
---|
219 | return 0;
|
---|
220 | return logPage->textEdit();
|
---|
221 | }
|
---|
222 |
|
---|
223 | const QString* UIVMLogViewerPane::logString() const
|
---|
224 | {
|
---|
225 | if (!viewer())
|
---|
226 | return 0;
|
---|
227 | const UIVMLogPage* const page = qobject_cast<const UIVMLogPage* const>(viewer()->currentLogPage());
|
---|
228 | if (!page)
|
---|
229 | return 0;
|
---|
230 | return &(page->logString());
|
---|
231 | }
|
---|