[26714] | 1 | /* $Id: QIInputDialog.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
[25177] | 2 | /** @file
|
---|
[75222] | 3 | * VBox Qt GUI - Qt extensions: QIInputDialog class implementation.
|
---|
[25177] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2008-2023 Oracle and/or its affiliates.
|
---|
[25177] | 8 | *
|
---|
[96407] | 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
|
---|
[25177] | 26 | */
|
---|
| 27 |
|
---|
[71355] | 28 | /* Qt includes: */
|
---|
[75222] | 29 | #include <QLabel>
|
---|
| 30 | #include <QLineEdit>
|
---|
| 31 | #include <QPushButton>
|
---|
| 32 | #include <QVBoxLayout>
|
---|
[71355] | 33 |
|
---|
[45162] | 34 | /* GUI includes: */
|
---|
[76606] | 35 | #include "QIDialogButtonBox.h"
|
---|
| 36 | #include "QIInputDialog.h"
|
---|
[25177] | 37 |
|
---|
[52730] | 38 |
|
---|
[87718] | 39 | QIInputDialog::QIInputDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = Qt::WindowFlags() */)
|
---|
[71396] | 40 | : QDialog(pParent, enmFlags)
|
---|
[75222] | 41 | , m_fDefaultLabelTextRedefined(false)
|
---|
| 42 | , m_pLabel(0)
|
---|
| 43 | , m_pTextValueEditor(0)
|
---|
| 44 | , m_pButtonBox(0)
|
---|
[25177] | 45 | {
|
---|
[75222] | 46 | /* Prepare: */
|
---|
| 47 | prepare();
|
---|
[25177] | 48 | }
|
---|
| 49 |
|
---|
[75222] | 50 | QString QIInputDialog::labelText() const
|
---|
[45162] | 51 | {
|
---|
[75222] | 52 | return m_pLabel ? m_pLabel->text() : QString();
|
---|
| 53 | }
|
---|
[25177] | 54 |
|
---|
[75222] | 55 | void QIInputDialog::resetLabelText()
|
---|
| 56 | {
|
---|
| 57 | m_fDefaultLabelTextRedefined = false;
|
---|
| 58 | retranslateUi();
|
---|
[25177] | 59 | }
|
---|
| 60 |
|
---|
[75222] | 61 | void QIInputDialog::setLabelText(const QString &strText)
|
---|
[25177] | 62 | {
|
---|
[75222] | 63 | m_fDefaultLabelTextRedefined = true;
|
---|
| 64 | if (m_pLabel)
|
---|
| 65 | m_pLabel->setText(strText);
|
---|
| 66 | }
|
---|
[54538] | 67 |
|
---|
[75222] | 68 | QString QIInputDialog::textValue() const
|
---|
| 69 | {
|
---|
| 70 | return m_pTextValueEditor ? m_pTextValueEditor->text() : QString();
|
---|
| 71 | }
|
---|
[25177] | 72 |
|
---|
[75222] | 73 | void QIInputDialog::setTextValue(const QString &strText)
|
---|
| 74 | {
|
---|
| 75 | if (m_pTextValueEditor)
|
---|
| 76 | m_pTextValueEditor->setText(strText);
|
---|
| 77 | }
|
---|
[45166] | 78 |
|
---|
[75222] | 79 | void QIInputDialog::retranslateUi()
|
---|
| 80 | {
|
---|
| 81 | if (m_pLabel && !m_fDefaultLabelTextRedefined)
|
---|
| 82 | m_pLabel->setText(tr("Name:"));
|
---|
| 83 | }
|
---|
[25177] | 84 |
|
---|
[75222] | 85 | void QIInputDialog::sltTextChanged()
|
---|
| 86 | {
|
---|
| 87 | if (m_pButtonBox)
|
---|
| 88 | m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!textValue().isEmpty());
|
---|
| 89 | }
|
---|
[45162] | 90 |
|
---|
[75222] | 91 | void 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)
|
---|
[45166] | 101 | {
|
---|
[75222] | 102 | /* Create label: */
|
---|
| 103 | m_pLabel = new QLabel(this);
|
---|
| 104 | if (m_pLabel)
|
---|
| 105 | pMainLayout->addWidget(m_pLabel);
|
---|
[45162] | 106 |
|
---|
[75222] | 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 | }
|
---|
[45162] | 114 |
|
---|
[75222] | 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 | }
|
---|
[45166] | 123 | }
|
---|
| 124 |
|
---|
[75222] | 125 | /* Apply language settings: */
|
---|
| 126 | retranslateUi();
|
---|
[45162] | 127 |
|
---|
[75222] | 128 | /* Initialize editors: */
|
---|
| 129 | sltTextChanged();
|
---|
[25177] | 130 | }
|
---|