VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: QIInputDialog.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIInputDialog class implementation.
4 */
5
6/*
7 * Copyright (C) 2008-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 <QLabel>
30#include <QLineEdit>
31#include <QPushButton>
32#include <QVBoxLayout>
33
34/* GUI includes: */
35#include "QIDialogButtonBox.h"
36#include "QIInputDialog.h"
37
38
39QIInputDialog::QIInputDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = Qt::WindowFlags() */)
40 : QDialog(pParent, enmFlags)
41 , m_fDefaultLabelTextRedefined(false)
42 , m_pLabel(0)
43 , m_pTextValueEditor(0)
44 , m_pButtonBox(0)
45{
46 /* Prepare: */
47 prepare();
48}
49
50QString QIInputDialog::labelText() const
51{
52 return m_pLabel ? m_pLabel->text() : QString();
53}
54
55void QIInputDialog::resetLabelText()
56{
57 m_fDefaultLabelTextRedefined = false;
58 retranslateUi();
59}
60
61void QIInputDialog::setLabelText(const QString &strText)
62{
63 m_fDefaultLabelTextRedefined = true;
64 if (m_pLabel)
65 m_pLabel->setText(strText);
66}
67
68QString QIInputDialog::textValue() const
69{
70 return m_pTextValueEditor ? m_pTextValueEditor->text() : QString();
71}
72
73void QIInputDialog::setTextValue(const QString &strText)
74{
75 if (m_pTextValueEditor)
76 m_pTextValueEditor->setText(strText);
77}
78
79void QIInputDialog::retranslateUi()
80{
81 if (m_pLabel && !m_fDefaultLabelTextRedefined)
82 m_pLabel->setText(tr("Name:"));
83}
84
85void QIInputDialog::sltTextChanged()
86{
87 if (m_pButtonBox)
88 m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!textValue().isEmpty());
89}
90
91void QIInputDialog::prepare()
92{
93 /* Do not count that window as important for application,
94 * it will NOT be taken into account when other
95 * top-level windows will be closed: */
96 setAttribute(Qt::WA_QuitOnClose, false);
97
98 /* Create main layout: */
99 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
100 if (pMainLayout)
101 {
102 /* Create label: */
103 m_pLabel = new QLabel(this);
104 if (m_pLabel)
105 pMainLayout->addWidget(m_pLabel);
106
107 /* Create text value editor: */
108 m_pTextValueEditor = new QLineEdit(this);
109 if (m_pTextValueEditor)
110 {
111 connect(m_pTextValueEditor, &QLineEdit::textChanged, this, &QIInputDialog::sltTextChanged);
112 pMainLayout->addWidget(m_pTextValueEditor);
113 }
114
115 /* Create button-box: */
116 m_pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
117 if (m_pButtonBox)
118 {
119 connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &QIInputDialog::accept);
120 connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &QIInputDialog::reject);
121 pMainLayout->addWidget(m_pButtonBox);
122 }
123 }
124
125 /* Apply language settings: */
126 retranslateUi();
127
128 /* Initialize editors: */
129 sltTextChanged();
130}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use