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