VirtualBox

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

Last change on this file since 102493 was 101563, checked in by vboxsync, 11 months ago

FE/Qt: bugref:10450: Get rid of Qt5 stuff; This one is about signal connection ambiguity stuff.

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