VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialogContainer.cpp

Last change on this file was 104358, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: QIDialogContainer.cpp 104358 2024-04-18 05:33:40Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIDialogContainer class implementation.
4 */
5
6/*
7 * Copyright (C) 2019-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 <QGridLayout>
30#include <QLabel>
31#include <QProgressBar>
32#include <QPushButton>
33
34/* GUI includes: */
35#include "QIDialogButtonBox.h"
36#include "QIDialogContainer.h"
37#include "UITranslationEventListener.h"
38
39/* Other VBox includes: */
40#include "iprt/assert.h"
41
42
43QIDialogContainer::QIDialogContainer(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = Qt::WindowFlags() */)
44 : QDialog(pParent, enmFlags)
45 , m_pLayout(0)
46 , m_pWidget(0)
47 , m_pProgressLabel(0)
48 , m_pProgressBar(0)
49 , m_pButtonBox(0)
50{
51 prepare();
52}
53
54void QIDialogContainer::setWidget(QWidget *pWidget)
55{
56 delete m_pWidget;
57 m_pWidget = pWidget;
58 if (m_pWidget)
59 m_pLayout->addWidget(m_pWidget, 0, 0);
60}
61
62void QIDialogContainer::setProgressBarHidden(bool fHidden)
63{
64 AssertPtrReturnVoid(m_pProgressLabel);
65 AssertPtrReturnVoid(m_pProgressBar);
66 m_pProgressLabel->setHidden(fHidden);
67 m_pProgressBar->setHidden(fHidden);
68}
69
70void QIDialogContainer::setOkButtonEnabled(bool fEnabled)
71{
72 AssertPtrReturnVoid(m_pButtonBox);
73 AssertPtrReturnVoid(m_pButtonBox->button(QDialogButtonBox::Ok));
74 m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(fEnabled);
75}
76
77void QIDialogContainer::sltRetranslateUI()
78{
79 m_pProgressLabel->setText(tr("Loading"));
80}
81
82void QIDialogContainer::prepare()
83{
84 /* Prepare layout: */
85 m_pLayout = new QGridLayout(this);
86 if (m_pLayout)
87 {
88 /* Prepare dialog button-box: */
89 m_pButtonBox = new QIDialogButtonBox(this);
90 if (m_pButtonBox)
91 {
92 m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok);
93 connect(m_pButtonBox, &QIDialogButtonBox::accepted,
94 this, &QDialog::accept);
95 connect(m_pButtonBox, &QIDialogButtonBox::rejected,
96 this, &QDialog::reject);
97
98 /* Prepare progress-layout: */
99 QHBoxLayout *pHLayout = new QHBoxLayout;
100 if (pHLayout)
101 {
102 pHLayout->setContentsMargins(0, 0, 0, 0);
103
104 /* Prepare progress-label: */
105 m_pProgressLabel = new QLabel(this);
106 if (m_pProgressLabel)
107 {
108 m_pProgressLabel->setHidden(true);
109
110 /* Add into layout: */
111 pHLayout->addWidget(m_pProgressLabel);
112 }
113 /* Prepare progress-bar: */
114 m_pProgressBar = new QProgressBar(this);
115 if (m_pProgressBar)
116 {
117 m_pProgressBar->setHidden(true);
118 m_pProgressBar->setTextVisible(false);
119 m_pProgressBar->setMinimum(0);
120 m_pProgressBar->setMaximum(0);
121
122 /* Add into layout: */
123 pHLayout->addWidget(m_pProgressBar);
124 }
125
126 /* Add into button-box: */
127 m_pButtonBox->addExtraLayout(pHLayout);
128 }
129
130 /* Add into layout: */
131 m_pLayout->addWidget(m_pButtonBox, 1, 0);
132 }
133 }
134
135 /* Apply language settings: */
136 sltRetranslateUI();
137 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
138 this, &QIDialogContainer::sltRetranslateUI);
139}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use