VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerPreferencesWidget.cpp

Last change on this file was 103923, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in log viewer classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: UIVMLogViewerPreferencesWidget.cpp 103923 2024-03-19 17:01:11Z 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 <QFontDatabase>
31#include <QFontDialog>
32#include <QCheckBox>
33#include <QLabel>
34#include <QPushButton>
35#include <QSpinBox>
36
37/* GUI includes: */
38#include "QIToolButton.h"
39#include "UIIconPool.h"
40#include "UITranslationEventListener.h"
41#include "UIVMLogViewerPreferencesWidget.h"
42#include "UIVMLogViewerWidget.h"
43
44/* Other VBox includes: */
45#include <iprt/assert.h>
46
47
48UIVMLogViewerPreferencesWidget::UIVMLogViewerPreferencesWidget(QWidget *pParent, UIVMLogViewerWidget *pViewer)
49 : UIVMLogViewerPane(pParent, pViewer)
50 , m_pLineNumberCheckBox(0)
51 , m_pWrapLinesCheckBox(0)
52 , m_pFontSizeSpinBox(0)
53 , m_pFontSizeLabel(0)
54 , m_pOpenFontDialogButton(0)
55 , m_pResetToDefaultsButton(0)
56 , m_iDefaultFontSize(9)
57{
58 prepareWidgets();
59 prepareConnections();
60 sltRetranslateUI();
61 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
62 this, &UIVMLogViewerPreferencesWidget::sltRetranslateUI);
63}
64
65void UIVMLogViewerPreferencesWidget::setShowLineNumbers(bool bShowLineNumbers)
66{
67 if (!m_pLineNumberCheckBox)
68 return;
69 if (m_pLineNumberCheckBox->isChecked() == bShowLineNumbers)
70 return;
71 m_pLineNumberCheckBox->setChecked(bShowLineNumbers);
72}
73
74void UIVMLogViewerPreferencesWidget::setWrapLines(bool bWrapLines)
75{
76 if (!m_pWrapLinesCheckBox)
77 return;
78 if (m_pWrapLinesCheckBox->isChecked() == bWrapLines)
79 return;
80 m_pWrapLinesCheckBox->setChecked(bWrapLines);
81}
82
83void UIVMLogViewerPreferencesWidget::setFontSizeInPoints(int fontSizeInPoints)
84{
85 if (!m_pFontSizeSpinBox)
86 return;
87 if (m_pFontSizeSpinBox->value() == fontSizeInPoints)
88 return;
89 m_pFontSizeSpinBox->setValue(fontSizeInPoints);
90}
91
92void UIVMLogViewerPreferencesWidget::prepareWidgets()
93{
94 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
95 AssertReturnVoid(pMainLayout);
96
97 QHBoxLayout *pContainerLayout = new QHBoxLayout;
98
99 /* Create line-number check-box: */
100 m_pLineNumberCheckBox = new QCheckBox;
101 AssertReturnVoid(m_pLineNumberCheckBox);
102 m_pLineNumberCheckBox->setChecked(true);
103 pContainerLayout->addWidget(m_pLineNumberCheckBox, 0, Qt::AlignLeft);
104
105
106 /* Create wrap-lines check-box: */
107 m_pWrapLinesCheckBox = new QCheckBox;
108 AssertReturnVoid(m_pWrapLinesCheckBox);
109 m_pWrapLinesCheckBox->setChecked(false);
110 pContainerLayout->addWidget(m_pWrapLinesCheckBox, 0, Qt::AlignLeft);
111
112 /* Create font-size spin-box: */
113 m_pFontSizeSpinBox = new QSpinBox;
114 AssertReturnVoid(m_pFontSizeSpinBox);
115 pContainerLayout->addWidget(m_pFontSizeSpinBox, 0, Qt::AlignLeft);
116 m_pFontSizeSpinBox->setValue(m_iDefaultFontSize);
117 m_pFontSizeSpinBox->setMaximum(44);
118 m_pFontSizeSpinBox->setMinimum(6);
119
120
121 /* Create font-size label: */
122 m_pFontSizeLabel = new QLabel;
123 if (m_pFontSizeLabel)
124 {
125 pContainerLayout->addWidget(m_pFontSizeLabel, 0, Qt::AlignLeft);
126 if (m_pFontSizeSpinBox)
127 m_pFontSizeLabel->setBuddy(m_pFontSizeSpinBox);
128 }
129
130 /* Create combo/button layout: */
131 QHBoxLayout *pButtonLayout = new QHBoxLayout;
132 if (pButtonLayout)
133 {
134 pButtonLayout->setContentsMargins(0, 0, 0, 0);
135 pButtonLayout->setSpacing(0);
136
137 /* Create open font dialog button: */
138 m_pOpenFontDialogButton = new QIToolButton;
139 if (m_pOpenFontDialogButton)
140 {
141 pButtonLayout->addWidget(m_pOpenFontDialogButton, 0);
142 m_pOpenFontDialogButton->setIcon(UIIconPool::iconSet(":/log_viewer_choose_font_16px.png"));
143 }
144
145 /* Create reset font to default button: */
146 m_pResetToDefaultsButton = new QIToolButton;
147 if (m_pResetToDefaultsButton)
148 {
149 pButtonLayout->addWidget(m_pResetToDefaultsButton, 0);
150 m_pResetToDefaultsButton->setIcon(UIIconPool::iconSet(":/log_viewer_reset_font_16px.png"));
151 }
152
153 pContainerLayout->addLayout(pButtonLayout);
154 }
155
156 pContainerLayout->addStretch(1);
157 pMainLayout->addLayout(pContainerLayout);
158 pMainLayout->addStretch(1);
159}
160
161void UIVMLogViewerPreferencesWidget::prepareConnections()
162{
163 if (m_pLineNumberCheckBox)
164 connect(m_pLineNumberCheckBox, &QCheckBox::toggled, this, &UIVMLogViewerPreferencesWidget::sigShowLineNumbers);
165 if (m_pWrapLinesCheckBox)
166 connect(m_pWrapLinesCheckBox, &QCheckBox::toggled, this, &UIVMLogViewerPreferencesWidget::sigWrapLines);
167 if (m_pFontSizeSpinBox)
168 connect(m_pFontSizeSpinBox, &QSpinBox::valueChanged, this, &UIVMLogViewerPreferencesWidget::sigChangeFontSizeInPoints);
169 if (m_pOpenFontDialogButton)
170 connect(m_pOpenFontDialogButton, &QIToolButton::clicked, this, &UIVMLogViewerPreferencesWidget::sltOpenFontDialog);
171 if (m_pResetToDefaultsButton)
172 connect(m_pResetToDefaultsButton, &QIToolButton::clicked, this, &UIVMLogViewerPreferencesWidget::sigResetToDefaults);
173}
174
175void UIVMLogViewerPreferencesWidget::sltRetranslateUI()
176{
177 m_pLineNumberCheckBox->setText(UIVMLogViewerWidget::tr("Show Line Numbers"));
178 m_pLineNumberCheckBox->setToolTip(UIVMLogViewerWidget::tr("When checked, show line numbers"));
179
180 m_pWrapLinesCheckBox->setText(UIVMLogViewerWidget::tr("Wrap Lines"));
181 m_pWrapLinesCheckBox->setToolTip(UIVMLogViewerWidget::tr("When checked, wrap lines"));
182
183 m_pFontSizeLabel->setText(UIVMLogViewerWidget::tr("Font Size"));
184 m_pFontSizeSpinBox->setToolTip(UIVMLogViewerWidget::tr("Log viewer font size"));
185
186 m_pOpenFontDialogButton->setToolTip(UIVMLogViewerWidget::tr("Open a font dialog to select font face for the logviewer"));
187 m_pResetToDefaultsButton->setToolTip(UIVMLogViewerWidget::tr("Reset options to application defaults"));
188}
189
190void UIVMLogViewerPreferencesWidget::sltOpenFontDialog()
191{
192 QObject *pParent = parent();
193 UIVMLogViewerWidget *pLogViewer = 0;
194 while(pParent)
195 {
196 pLogViewer = qobject_cast<UIVMLogViewerWidget*>(pParent);
197 if (pLogViewer)
198 break;
199 pParent = pParent->parent();
200 }
201
202 if (!pLogViewer)
203 return;
204 QFont currentFont;
205 currentFont = pLogViewer->currentFont();
206 bool ok;
207 QFont font =
208 QFontDialog::getFont(&ok, currentFont, this, "Logviewer font");
209
210 if (ok)
211 emit sigChangeFont(font);
212}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use