VirtualBox

Changeset 75222 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Nov 2, 2018 12:37:05 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: Extensions: QIInputDialog initial implementation.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r75220 r75222  
    764764        src/extensions/QIFileDialog.h \
    765765        src/extensions/QIFlowLayout.h \
     766        src/extensions/QIInputDialog.h \
    766767        src/extensions/QILabel.h \
    767768        src/extensions/QILabelSeparator.h \
     
    10511052        src/extensions/QIFileDialog.h \
    10521053        src/extensions/QIFlowLayout.h \
     1054        src/extensions/QIInputDialog.h \
    10531055        src/extensions/QILabel.h \
    10541056        src/extensions/QILabelSeparator.h \
     
    14641466        src/extensions/QIFileDialog.cpp \
    14651467        src/extensions/QIFlowLayout.cpp \
     1468        src/extensions/QIInputDialog.cpp \
    14661469        src/extensions/QILabel.cpp \
    14671470        src/extensions/QILabelSeparator.cpp \
     
    18031806        src/extensions/QIFileDialog.cpp \
    18041807        src/extensions/QIFlowLayout.cpp \
     1808        src/extensions/QIInputDialog.cpp \
    18051809        src/extensions/QILabel.cpp \
    18061810        src/extensions/QILabelSeparator.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIInputDialog.cpp

    r75215 r75222  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - Qt extensions: QIDialog class implementation.
     3 * VBox Qt GUI - Qt extensions: QIInputDialog class implementation.
    44 */
    55
     
    2121
    2222/* Qt includes: */
    23 # include <QEventLoop>
     23#include <QLabel>
     24#include <QLineEdit>
     25#include <QPushButton>
     26#include <QVBoxLayout>
    2427
    2528/* GUI includes: */
    26 # include "QIDialog.h"
    27 # include "VBoxGlobal.h"
     29# include "QIDialogButtonBox.h"
     30# include "QIInputDialog.h"
    2831
    2932#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3033
    3134
    32 QIDialog::QIDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = 0 */)
     35QIInputDialog::QIInputDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = 0 */)
    3336    : QDialog(pParent, enmFlags)
    34     , m_fPolished(false)
     37    , m_fDefaultLabelTextRedefined(false)
     38    , m_pLabel(0)
     39    , m_pTextValueEditor(0)
     40    , m_pButtonBox(0)
     41{
     42    /* Prepare: */
     43    prepare();
     44}
     45
     46QString QIInputDialog::labelText() const
     47{
     48    return m_pLabel ? m_pLabel->text() : QString();
     49}
     50
     51void QIInputDialog::resetLabelText()
     52{
     53    m_fDefaultLabelTextRedefined = false;
     54    retranslateUi();
     55}
     56
     57void QIInputDialog::setLabelText(const QString &strText)
     58{
     59    m_fDefaultLabelTextRedefined = true;
     60    if (m_pLabel)
     61        m_pLabel->setText(strText);
     62}
     63
     64QString QIInputDialog::textValue() const
     65{
     66    return m_pTextValueEditor ? m_pTextValueEditor->text() : QString();
     67}
     68
     69void QIInputDialog::setTextValue(const QString &strText)
     70{
     71    if (m_pTextValueEditor)
     72        m_pTextValueEditor->setText(strText);
     73}
     74
     75void QIInputDialog::retranslateUi()
     76{
     77    if (m_pLabel && !m_fDefaultLabelTextRedefined)
     78        m_pLabel->setText(tr("Name:"));
     79}
     80
     81void QIInputDialog::sltTextChanged()
     82{
     83    if (m_pButtonBox)
     84        m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!textValue().isEmpty());
     85}
     86
     87void QIInputDialog::prepare()
    3588{
    3689    /* Do not count that window as important for application,
    37      * it will NOT be taken into account when other top-level windows will be closed: */
     90     * it will NOT be taken into account when other
     91     * top-level windows will be closed: */
    3892    setAttribute(Qt::WA_QuitOnClose, false);
    39 }
    4093
    41 void QIDialog::setVisible(bool fVisible)
    42 {
    43     /* Call to base-class: */
    44     QDialog::setVisible(fVisible);
     94    /* Create main layout: */
     95    QVBoxLayout *pMainLayout = new QVBoxLayout(this);
     96    if (pMainLayout)
     97    {
     98        /* Create label: */
     99        m_pLabel = new QLabel(this);
     100        if (m_pLabel)
     101            pMainLayout->addWidget(m_pLabel);
    45102
    46     /* Exit from the event-loop if there is any and
    47      * we are changing our state from visible to hidden. */
    48     if (m_pEventLoop && !fVisible)
    49         m_pEventLoop->exit();
    50 }
     103        /* Create text value editor: */
     104        m_pTextValueEditor = new QLineEdit(this);
     105        if (m_pTextValueEditor)
     106        {
     107            connect(m_pTextValueEditor, &QLineEdit::textChanged, this, &QIInputDialog::sltTextChanged);
     108            pMainLayout->addWidget(m_pTextValueEditor);
     109        }
    51110
    52 int QIDialog::execute(bool fShow /* = true */, bool fApplicationModal /* = false */)
    53 {
    54     /* Check for the recursive run: */
    55     AssertMsgReturn(!m_pEventLoop, ("QIDialog::execute() is called recursively!\n"), QDialog::Rejected);
    56 
    57     /* Reset the result-code: */
    58     setResult(QDialog::Rejected);
    59 
    60     /* Should we delete ourself on close in theory? */
    61     const bool fOldDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
    62     /* For the exec() time, set this attribute to 'false': */
    63     setAttribute(Qt::WA_DeleteOnClose, false);
    64 
    65     /* Which is the current window-modality? */
    66     const Qt::WindowModality oldModality = windowModality();
    67     /* For the exec() time, set this attribute to 'window-modal' or 'application-modal': */
    68     setWindowModality(!fApplicationModal ? Qt::WindowModal : Qt::ApplicationModal);
    69 
    70     /* Show ourself if requested: */
    71     if (fShow)
    72         show();
    73 
    74     /* Create a local event-loop: */
    75     {
    76         QEventLoop eventLoop;
    77         m_pEventLoop = &eventLoop;
    78 
    79         /* Guard ourself for the case
    80          * we destroyed ourself in our event-loop: */
    81         QPointer<QIDialog> guard = this;
    82 
    83         /* Start the blocking event-loop: */
    84         eventLoop.exec();
    85 
    86         /* Are we still valid? */
    87         if (guard.isNull())
    88             return QDialog::Rejected;
    89 
    90         m_pEventLoop = 0;
     111        /* Create button-box: */
     112        m_pButtonBox = new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
     113        if (m_pButtonBox)
     114        {
     115            connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &QIInputDialog::accept);
     116            connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &QIInputDialog::reject);
     117            pMainLayout->addWidget(m_pButtonBox);
     118        }
    91119    }
    92120
    93     /* Save the result-code early (we can delete ourself on close): */
    94     const int iResultCode = result();
     121    /* Apply language settings: */
     122    retranslateUi();
    95123
    96     /* Return old modality: */
    97     setWindowModality(oldModality);
    98 
    99     /* Reset attribute to previous value: */
    100     setAttribute(Qt::WA_DeleteOnClose, fOldDeleteOnClose);
    101     /* Delete ourself if we should do that on close: */
    102     if (fOldDeleteOnClose)
    103         delete this;
    104 
    105     /* Return the result-code: */
    106     return iResultCode;
     124    /* Initialize editors: */
     125    sltTextChanged();
    107126}
    108 
    109 void QIDialog::showEvent(QShowEvent *pEvent)
    110 {
    111     /* Make sure we should polish dialog: */
    112     if (m_fPolished)
    113         return;
    114 
    115     /* Call to polish-event: */
    116     polishEvent(pEvent);
    117 
    118     /* Mark dialog as polished: */
    119     m_fPolished = true;
    120 }
    121 
    122 void QIDialog::polishEvent(QShowEvent *)
    123 {
    124     /* Make sure layout is polished: */
    125     adjustSize();
    126 #ifdef VBOX_WS_MAC
    127     /* And dialog have fixed size: */
    128     setFixedSize(size());
    129 #endif /* VBOX_WS_MAC */
    130 
    131     /* Explicit centering according to our parent: */
    132     VBoxGlobal::centerWidget(this, parentWidget(), false);
    133 }
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIInputDialog.h

    r75215 r75222  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - Qt extensions: QIDialog class declaration.
     3 * VBox Qt GUI - Qt extensions: QIInputDialog class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef ___QIDialog_h___
    19 #define ___QIDialog_h___
     18#ifndef ___QIInputDialog_h___
     19#define ___QIInputDialog_h___
    2020
    2121/* Qt includes: */
     
    2424
    2525/* GUI includes: */
     26#include "QIWithRetranslateUI.h"
    2627#include "UILibraryDefs.h"
    2728
    2829/* Forward declarations: */
    29 class QEventLoop;
     30class QLabel;
     31class QLineEdit;
     32class QIDialogButtonBox;
    3033
    3134/** QDialog extension providing the GUI with
    32   * the advanced capabilities like delayed show. */
    33 class SHARED_LIBRARY_STUFF QIDialog : public QDialog
     35  * the advanced input dialog capabilities. */
     36class SHARED_LIBRARY_STUFF QIInputDialog : public QDialog
    3437{
    3538    Q_OBJECT;
     
    3841
    3942    /** Constructs the dialog passing @a pParent and @a enmFlags to the base-class. */
    40     QIDialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = 0);
     43    QIInputDialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = 0);
    4144
    42     /** Defines whether the dialog is @a fVisible. */
    43     void setVisible(bool fVisible);
     45    /** Returns label text. */
     46    QString labelText() const;
     47    /** Undefines label text. */
     48    void resetLabelText();
     49    /** Defines label @a strText. */
     50    void setLabelText(const QString &strText);
    4451
    45 public slots:
    46 
    47     /** Shows the dialog as a modal one, blocking until the user closes it.
    48       * @param  fShow              Brings whether the dialog should be shown instantly.
    49       * @param  fApplicationModal  Brings whether the dialog should be application-modal. */
    50     virtual int execute(bool fShow = true, bool fApplicationModal = false);
    51 
    52     /** Shows the dialog as a modal one, blocking until the user closes it. */
    53     virtual int exec() /* override */ { return execute(); }
     52    /** Returns text value. */
     53    QString textValue() const;
     54    /** Defines @a strText value. */
     55    void setTextValue(const QString &strText);
    5456
    5557protected:
    5658
    57     /** Handles show @a pEvent. */
    58     virtual void showEvent(QShowEvent *pEvent) /* override */;
    59     /** Handles show @a pEvent sent for the first time. */
    60     virtual void polishEvent(QShowEvent *pEvent);
     59    /** Handles translation event. */
     60    virtual void retranslateUi() /* override */;
     61
     62private slots:
     63
     64    /** Handles text value change. */
     65    void sltTextChanged();
    6166
    6267private:
    6368
    64     /** Holds whether the dialog is polished. */
    65     bool m_fPolished;
     69    /** Prepared all. */
     70    void prepare();
    6671
    67     /** Holds the separate event-loop instance.
    68       * @note  This event-loop is only used when the dialog being executed via the execute()
    69       *        functionality, allowing for the delayed show and advanced modality flag. */
    70     QPointer<QEventLoop> m_pEventLoop;
     72    /** Holds whether label text redefined. */
     73    bool  m_fDefaultLabelTextRedefined;
     74
     75    /** Holds the label instance. */
     76    QLabel            *m_pLabel;
     77    /** Holds the text value editor instance. */
     78    QLineEdit         *m_pTextValueEditor;
     79    /** Holds the button-box instance. */
     80    QIDialogButtonBox *m_pButtonBox;
    7181};
    7282
    73 /** Safe pointer to the QIDialog class. */
    74 typedef QPointer<QIDialog> UISafePointerDialog;
     83/** Safe pointer to the QIInputDialog class. */
     84typedef QPointer<QIInputDialog> QISafePointerInputDialog;
    7585
    76 #endif /* !___QIDialog_h___ */
     86#endif /* !___QIInputDialog_h___ */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette