VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp@ 102493

Last change on this file since 102493 was 98844, checked in by vboxsync, 19 months ago

FE/Qt: Some small cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/* $Id: UIVMLogPage.cpp 98844 2023-03-06 17:21:13Z 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#if defined(RT_OS_SOLARIS)
31# include <QFontDatabase>
32#endif
33#include <QScrollBar>
34
35/* GUI includes: */
36#include "UIVMLogPage.h"
37#include "UIVMLogViewerTextEdit.h"
38
39
40/*********************************************************************************************************************************
41* UIVMLogTab implementation. *
42*********************************************************************************************************************************/
43
44UIVMLogTab::UIVMLogTab(QWidget *pParent, const QUuid &uMachineId, const QString &strMachineName)
45 : QIWithRetranslateUI<QWidget>(pParent)
46 , m_uMachineId(uMachineId)
47 , m_strMachineName(strMachineName)
48{
49}
50const QUuid &UIVMLogTab::machineId() const
51{
52 return m_uMachineId;
53}
54
55const QString UIVMLogTab::machineName() const
56{
57 return m_strMachineName;
58}
59
60
61/*********************************************************************************************************************************
62* UIVMLogPage implementation. *
63*********************************************************************************************************************************/
64
65UIVMLogPage::UIVMLogPage(QWidget *pParent, const QUuid &uMachineId, const QString &strMachineName)
66 : UIVMLogTab(pParent, uMachineId, strMachineName)
67 , m_pMainLayout(0)
68 , m_pTextEdit(0)
69 , m_iSelectedBookmarkIndex(-1)
70 , m_bFiltered(false)
71 , m_iLogFileId(-1)
72{
73 prepare();
74}
75
76UIVMLogPage::~UIVMLogPage()
77{
78 cleanup();
79}
80
81int UIVMLogPage::defaultLogPageWidth() const
82{
83 if (!m_pTextEdit)
84 return 0;
85
86 /* Compute a width for 132 characters plus scrollbar and frame width: */
87#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
88 int iDefaultWidth = m_pTextEdit->fontMetrics().horizontalAdvance(QChar('x')) * 132 +
89#else
90 int iDefaultWidth = m_pTextEdit->fontMetrics().width(QChar('x')) * 132 +
91#endif
92 m_pTextEdit->verticalScrollBar()->width() +
93 m_pTextEdit->frameWidth() * 2;
94
95 return iDefaultWidth;
96}
97
98
99void UIVMLogPage::prepare()
100{
101 prepareWidgets();
102 retranslateUi();
103}
104
105void UIVMLogPage::prepareWidgets()
106{
107 m_pMainLayout = new QHBoxLayout();
108 setLayout(m_pMainLayout);
109 m_pMainLayout->setSpacing(0);
110 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
111
112 m_pTextEdit = new UIVMLogViewerTextEdit(this);
113 m_pMainLayout->addWidget(m_pTextEdit);
114
115 connect(m_pTextEdit, &UIVMLogViewerTextEdit::sigAddBookmark, this, &UIVMLogPage::sltAddBookmark);
116 connect(m_pTextEdit, &UIVMLogViewerTextEdit::sigDeleteBookmark, this, &UIVMLogPage::sltDeleteBookmark);
117}
118
119QPlainTextEdit *UIVMLogPage::textEdit()
120{
121 return m_pTextEdit;
122}
123
124QTextDocument* UIVMLogPage::document()
125{
126 if (!m_pTextEdit)
127 return 0;
128 return m_pTextEdit->document();
129}
130
131void UIVMLogPage::retranslateUi()
132{
133}
134
135void UIVMLogPage::cleanup()
136{
137}
138
139void UIVMLogPage::setLogContent(const QString &strLogContent, bool fError)
140{
141 if (!fError)
142 {
143 m_strLog = strLogContent;
144 setTextEditText(strLogContent);
145 }
146 else
147 {
148 markForError();
149 setTextEditTextAsHtml(strLogContent);
150 }
151}
152
153const QString& UIVMLogPage::logString() const
154{
155 return m_strLog;
156}
157
158void UIVMLogPage::setLogFileName(const QString &strLogFileName)
159{
160 m_strLogFileName = strLogFileName;
161}
162
163const QString& UIVMLogPage::logFileName() const
164{
165 return m_strLogFileName;
166}
167
168void UIVMLogPage::setTextEditText(const QString &strText)
169{
170 if (!m_pTextEdit)
171 return;
172
173 m_pTextEdit->setPlainText(strText);
174 /* Move the cursor position to end: */
175 QTextCursor cursor = m_pTextEdit->textCursor();
176 cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
177 m_pTextEdit->setTextCursor(cursor);
178 update();
179}
180
181void UIVMLogPage::setTextEditTextAsHtml(const QString &strText)
182{
183 if (!m_pTextEdit)
184 return;
185 if (document())
186 document()->setHtml(strText);
187 update();
188}
189
190void UIVMLogPage::markForError()
191{
192 if (!m_pTextEdit)
193 return;
194 m_pTextEdit->setWrapLines(true);
195}
196
197void UIVMLogPage::setScrollBarMarkingsVector(const QVector<float> &vector)
198{
199 if (!m_pTextEdit)
200 return;
201 m_pTextEdit->setScrollBarMarkingsVector(vector);
202 update();
203}
204
205void UIVMLogPage::clearScrollBarMarkingsVector()
206{
207 if (!m_pTextEdit)
208 return;
209 m_pTextEdit->clearScrollBarMarkingsVector();
210 update();
211}
212
213void UIVMLogPage::documentUndo()
214{
215 if (!m_pTextEdit)
216 return;
217 if (m_pTextEdit->document())
218 m_pTextEdit->document()->undo();
219}
220
221
222
223void UIVMLogPage::deleteAllBookmarks()
224{
225 m_bookmarkManager.deleteAllBookmarks();
226 updateTextEditBookmarkLineSet();
227}
228
229void UIVMLogPage::scrollToBookmark(int bookmarkIndex)
230{
231 if (!m_pTextEdit)
232 return;
233 m_pTextEdit->setCursorPosition(m_bookmarkManager.cursorPosition(bookmarkIndex));
234}
235
236const QVector<UIVMLogBookmark>& UIVMLogPage::bookmarkList() const
237{
238 return m_bookmarkManager.bookmarkList();
239}
240
241void UIVMLogPage::sltAddBookmark(const UIVMLogBookmark& bookmark)
242{
243 m_bookmarkManager.addBookmark(bookmark);
244 updateTextEditBookmarkLineSet();
245 emit sigBookmarksUpdated();
246}
247
248void UIVMLogPage::sltDeleteBookmark(const UIVMLogBookmark& bookmark)
249{
250 m_bookmarkManager.deleteBookmark(bookmark);
251 updateTextEditBookmarkLineSet();
252 emit sigBookmarksUpdated();
253}
254
255void UIVMLogPage::deleteBookmarkByIndex(int iIndex)
256{
257 m_bookmarkManager.deleteBookmarkByIndex(iIndex);
258 updateTextEditBookmarkLineSet();
259 emit sigBookmarksUpdated();
260}
261
262void UIVMLogPage::updateTextEditBookmarkLineSet()
263{
264 if (!m_pTextEdit)
265 return;
266 m_pTextEdit->setBookmarkLineSet(m_bookmarkManager.lineSet());
267}
268
269bool UIVMLogPage::isFiltered() const
270{
271 return m_bFiltered;
272}
273
274void UIVMLogPage::setFiltered(bool filtered)
275{
276 if (m_bFiltered == filtered)
277 return;
278 m_bFiltered = filtered;
279 if (m_pTextEdit)
280 {
281 m_pTextEdit->setShownTextIsFiltered(m_bFiltered);
282 m_pTextEdit->update();
283 }
284 emit sigLogPageFilteredChanged(m_bFiltered);
285}
286
287void UIVMLogPage::setShowLineNumbers(bool bShowLineNumbers)
288{
289 if (!m_pTextEdit)
290 return;
291 m_pTextEdit->setShowLineNumbers(bShowLineNumbers);
292}
293
294void UIVMLogPage::setWrapLines(bool bWrapLines)
295{
296 if (!m_pTextEdit)
297 return;
298 m_pTextEdit->setWrapLines(bWrapLines);
299}
300
301QFont UIVMLogPage::currentFont() const
302{
303 if (!m_pTextEdit)
304 return QFont();
305 return m_pTextEdit->font();
306}
307
308void UIVMLogPage::setCurrentFont(QFont font)
309{
310 if (m_pTextEdit)
311 m_pTextEdit->setCurrentFont(font);
312}
313
314void UIVMLogPage::setLogFileId(int iLogFileId)
315{
316 m_iLogFileId = iLogFileId;
317}
318
319int UIVMLogPage::logFileId() const
320{
321 return m_iLogFileId;
322}
323
324void UIVMLogPage::scrollToEnd()
325{
326 if (m_pTextEdit)
327 m_pTextEdit->scrollToEnd();
328}
329
330void UIVMLogPage::saveScrollBarPosition()
331{
332 if (m_pTextEdit)
333 m_pTextEdit->saveScrollBarPosition();
334}
335
336void UIVMLogPage::restoreScrollBarPosition()
337{
338 if (m_pTextEdit)
339 m_pTextEdit->restoreScrollBarPosition();
340}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette