VirtualBox

Ignore:
Timestamp:
Jun 26, 2020 1:56:07 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
138847
Message:

FE/Qt: bugref:9515. Splitting UIUserNamePasswordEditor class into its own file.

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

Legend:

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

    r84964 r84969  
    651651        src/widgets/UISlidingWidget.h \
    652652        src/widgets/UITabBar.h \
     653        src/widgets/UIUserNamePasswordEditor.h \
    653654        src/widgets/UIMenuToolBar.h \
    654655        src/widgets/graphics/UIGraphicsButton.h \
     
    11141115        src/widgets/UISlidingWidget.cpp \
    11151116        src/widgets/UITabBar.cpp \
     1117        src/widgets/UIUserNamePasswordEditor.cpp \
    11161118        src/widgets/UIMenuToolBar.cpp \
    11171119        src/widgets/graphics/UIGraphicsButton.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.cpp

    r84965 r84969  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIWizardNewVMPageBasicInstallSetup class implementation.
     3 * VBox Qt GUI - UIUserNamePasswordEditor class implementation.
    44 */
    55
     
    2727#include "UICommon.h"
    2828#include "UIIconPool.h"
    29 #include "UIWizardNewVMPageBasicInstallSetup.h"
     29#include "UIUserNamePasswordEditor.h"
    3030#include "UIWizardNewVM.h"
    3131
     
    228228        m_pPasswordRepeatLineEdit->toggleTextVisibility(fPasswordVisible);
    229229}
    230 
    231 UIWizardNewVMPageInstallSetup::UIWizardNewVMPageInstallSetup()
    232     : m_pUserNamePasswordEditor(0)
    233     , m_pHostnameLineEdit(0)
    234     , m_pHostnameLabel(0)
    235 {
    236 }
    237 
    238 QString UIWizardNewVMPageInstallSetup::userName() const
    239 {
    240     if (m_pUserNamePasswordEditor)
    241         return m_pUserNamePasswordEditor->userName();
    242     return QString();
    243 }
    244 
    245 QString UIWizardNewVMPageInstallSetup::password() const
    246 {
    247     if (m_pUserNamePasswordEditor)
    248         return m_pUserNamePasswordEditor->password();
    249     return QString();
    250 }
    251 
    252 QString UIWizardNewVMPageInstallSetup::hostname() const
    253 {
    254     if (m_pHostnameLineEdit)
    255         return m_pHostnameLineEdit->text();
    256     return QString();
    257 }
    258 
    259 UIWizardNewVMPageBasicInstallSetup::UIWizardNewVMPageBasicInstallSetup()
    260     : m_pLabel(0)
    261 {
    262     /* Create widget: */
    263     QVBoxLayout *pMainLayout = new QVBoxLayout(this);
    264     {
    265         m_pLabel = new QIRichTextLabel(this);
    266         QGridLayout *pGridLayout = new QGridLayout;
    267         {
    268             m_pUserNamePasswordEditor = new UIUserNamePasswordEditor;
    269             pGridLayout->addWidget(m_pUserNamePasswordEditor, 0, 0, 3, 4);
    270             connect(m_pUserNamePasswordEditor, &UIUserNamePasswordEditor::sigSomeTextChanged,
    271                     this, &UIWizardNewVMPageBasicInstallSetup::completeChanged);
    272             m_pHostnameLabel = new QLabel;
    273             m_pHostnameLineEdit = new QLineEdit;
    274             pGridLayout->addWidget(m_pHostnameLabel, 3, 0, 1, 1, Qt::AlignRight);
    275             pGridLayout->addWidget(m_pHostnameLineEdit, 3, 1, 1, 3);
    276         }
    277         if (m_pLabel)
    278             pMainLayout->addWidget(m_pLabel);
    279         pMainLayout->addLayout(pGridLayout);
    280         pMainLayout->addStretch();
    281     }
    282 
    283     /* Register fields: */
    284     registerField("userName", this, "userName");
    285     registerField("password", this, "password");
    286     registerField("hostname", this, "hostname");
    287 }
    288 
    289 void UIWizardNewVMPageBasicInstallSetup::setDefaultUnattendedInstallData(const UIUnattendedInstallData &unattendedInstallData)
    290 {
    291     /* Initialize the widget data: */
    292     if (m_pUserNamePasswordEditor)
    293     {
    294         m_pUserNamePasswordEditor->setUserName(unattendedInstallData.m_strUserName);
    295         m_pUserNamePasswordEditor->setPassword(unattendedInstallData.m_strPassword);
    296     }
    297     if (m_pHostnameLineEdit)
    298         m_pHostnameLineEdit->setText(unattendedInstallData.m_strHostname);
    299 }
    300 
    301 void UIWizardNewVMPageBasicInstallSetup::retranslateUi()
    302 {
    303     /* Translate page: */
    304     setTitle(UIWizardNewVM::tr("User Name/Password and Hostname Settings"));
    305 
    306     /* Translate widgets: */
    307     if (m_pLabel)
    308         m_pLabel->setText(UIWizardNewVM::tr("<p>Here you can specify the user name/password and hostname. "
    309                                             "The values you enter here will be used during the unattended install.</p>"));
    310     if (m_pHostnameLabel)
    311         m_pHostnameLabel->setText(UIWizardNewVM::tr("Hostname:"));
    312 }
    313 
    314 void UIWizardNewVMPageBasicInstallSetup::initializePage()
    315 {
    316     /* Translate page: */
    317     retranslateUi();
    318 }
    319 
    320 bool UIWizardNewVMPageBasicInstallSetup::isComplete() const
    321 {
    322     if (m_pUserNamePasswordEditor)
    323         return m_pUserNamePasswordEditor->isComplete();
    324     return true;
    325 }
    326 
    327 int UIWizardNewVMPageBasicInstallSetup::nextId() const
    328 {
    329     UIWizardNewVM *pWizard = qobject_cast<UIWizardNewVM*>(wizard());
    330     if (!pWizard || !pWizard->isUnattendedInstallEnabled() || !pWizard->isGuestOSTypeWindows())
    331         return UIWizardNewVM::PageHardware;
    332     return UIWizardNewVM::PageProductKey;
    333 }
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.h

    r84965 r84969  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIWizardNewVMPageBasicInstallSetup class declaration.
     3 * VBox Qt GUI - UIUserNamePasswordEditor class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef FEQT_INCLUDED_SRC_wizards_newvm_UIWizardNewVMPageBasicInstallSetup_h
    19 #define FEQT_INCLUDED_SRC_wizards_newvm_UIWizardNewVMPageBasicInstallSetup_h
     18#ifndef FEQT_INCLUDED_SRC_widgets_UIUserNamePasswordEditor_h
     19#define FEQT_INCLUDED_SRC_widgets_UIUserNamePasswordEditor_h
    2020#ifndef RT_WITHOUT_PRAGMA_ONCE
    2121# pragma once
     
    2828/* Local includes: */
    2929#include "QIWithRetranslateUI.h"
    30 #include "UIWizardPage.h"
    3130
    3231/* Forward declarations: */
    3332class QGridLayout;
    3433class QLabel;
    35 class QSpinBox;
    36 class QIRichTextLabel;
    37 struct UIUnattendedInstallData;
    3834
    3935class UIPasswordLineEdit : public QLineEdit
     
    114110};
    115111
    116 /* 2nd page of the New Virtual Machine wizard (base part): */
    117 class UIWizardNewVMPageInstallSetup : public UIWizardPageBase
    118 {
    119 public:
    120 
    121     UIWizardNewVMPageInstallSetup();
    122 
    123     /** @name Property getters
    124       * @{ */
    125         QString userName() const;
    126         QString password() const;
    127         QString hostname() const;
    128     /** @} */
    129 
    130 protected:
    131 
    132     /* Widgets: */
    133     UIUserNamePasswordEditor *m_pUserNamePasswordEditor;
    134     QLineEdit *m_pHostnameLineEdit;
    135     QLabel  *m_pHostnameLabel;
    136 };
    137 
    138 class UIWizardNewVMPageBasicInstallSetup : public UIWizardPage, public UIWizardNewVMPageInstallSetup
    139 {
    140     Q_OBJECT;
    141     Q_PROPERTY(QString userName READ userName);
    142     Q_PROPERTY(QString password READ password);
    143     Q_PROPERTY(QString hostname READ hostname);
    144 
    145 public:
    146 
    147     /* Constructor: */
    148     UIWizardNewVMPageBasicInstallSetup();
    149     void setDefaultUnattendedInstallData(const UIUnattendedInstallData &unattendedInstallData);
    150     virtual int nextId() const /* override */;
    151 
    152 private slots:
    153 
    154 private:
    155 
    156     /* Translation stuff: */
    157     void retranslateUi();
    158 
    159     /* Prepare stuff: */
    160     void initializePage();
    161 
    162     /* Validation stuff: */
    163     bool isComplete() const;
    164 
    165     /* Widgets: */
    166     QIRichTextLabel *m_pLabel;
    167 };
    168 
    169 #endif /* !FEQT_INCLUDED_SRC_wizards_newvm_UIWizardNewVMPageBasicInstallSetup_h */
     112#endif /* !FEQT_INCLUDED_SRC_widgets_UIUserNamePasswordEditor_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasicInstallSetup.cpp

    r84965 r84969  
    1919#include <QGridLayout>
    2020#include <QLabel>
    21 #include <QStyle>
    22 #include <QToolButton>
    2321#include <QVBoxLayout>
    2422
    2523/* GUI includes: */
    2624#include "QIRichTextLabel.h"
    27 #include "UICommon.h"
    28 #include "UIIconPool.h"
     25#include "UIUserNamePasswordEditor.h"
    2926#include "UIWizardNewVMPageBasicInstallSetup.h"
    3027#include "UIWizardNewVM.h"
    3128
    32 UIPasswordLineEdit::UIPasswordLineEdit(QWidget *pParent /*= 0 */)
    33     :QLineEdit(pParent)
    34     , m_pTextVisibilityButton(0)
    35 {
    36     prepare();
    37 }
    38 
    39 void UIPasswordLineEdit::toggleTextVisibility(bool fTextVisible)
    40 {
    41     if (fTextVisible)
    42     {
    43         setEchoMode(QLineEdit::Normal);
    44         if(m_pTextVisibilityButton)
    45             m_pTextVisibilityButton->setIcon(UIIconPool::iconSet(":/eye-off.png"));
    46         return;
    47     }
    48     setEchoMode(QLineEdit::Password);
    49     if(m_pTextVisibilityButton)
    50         m_pTextVisibilityButton->setIcon(UIIconPool::iconSet(":/eye-on.png"));
    51 }
    52 
    53 void UIPasswordLineEdit::prepare()
    54 {
    55     m_pTextVisibilityButton = new QToolButton(this);
    56     m_pTextVisibilityButton->setFocusPolicy(Qt::ClickFocus);
    57     m_pTextVisibilityButton->setAutoRaise(true);
    58     m_pTextVisibilityButton->setCursor(Qt::ArrowCursor);
    59     m_pTextVisibilityButton->show();
    60     connect(m_pTextVisibilityButton, &QToolButton::clicked, this, &UIPasswordLineEdit::sltHandleTextVisibilityChange);
    61     toggleTextVisibility(false);
    62 }
    63 
    64 void UIPasswordLineEdit::paintEvent(QPaintEvent *pevent)
    65 {
    66     QLineEdit::paintEvent(pevent);
    67     int iFrameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    68     int iSize = height() - 2 * iFrameWidth;
    69     m_pTextVisibilityButton->setGeometry(width() - iSize, iFrameWidth, iSize, iSize);
    70 
    71 }
    72 
    73 void UIPasswordLineEdit::sltHandleTextVisibilityChange()
    74 {
    75     bool fTextVisible = false;
    76     if (echoMode() == QLineEdit::Normal)
    77         fTextVisible = false;
    78     else
    79         fTextVisible = true;
    80     toggleTextVisibility(fTextVisible);
    81     emit sigTextVisibilityToggled(fTextVisible);
    82 }
    83 
    84 UIUserNamePasswordEditor::UIUserNamePasswordEditor(QWidget *pParent /*  = 0 */)
    85     : QIWithRetranslateUI<QWidget>(pParent)
    86     , m_pUserNameLineEdit(0)
    87     , m_pPasswordLineEdit(0)
    88     , m_pPasswordRepeatLineEdit(0)
    89     , m_pUserNameLabel(0)
    90     , m_pPasswordLabel(0)
    91     , m_pPasswordRepeatLabel(0)
    92 {
    93     prepare();
    94 }
    95 
    96 QString UIUserNamePasswordEditor::userName() const
    97 {
    98     if (m_pUserNameLineEdit)
    99         return m_pUserNameLineEdit->text();
    100     return QString();
    101 }
    102 
    103 void UIUserNamePasswordEditor::setUserName(const QString &strUserName)
    104 {
    105     if (m_pUserNameLineEdit)
    106         return m_pUserNameLineEdit->setText(strUserName);
    107 }
    108 
    109 QString UIUserNamePasswordEditor::password() const
    110 {
    111     if (m_pPasswordLineEdit)
    112         return m_pPasswordLineEdit->text();
    113     return QString();
    114 }
    115 
    116 void UIUserNamePasswordEditor::setPassword(const QString &strPassword)
    117 {
    118     if (m_pPasswordLineEdit)
    119         m_pPasswordLineEdit->setText(strPassword);
    120     if (m_pPasswordRepeatLineEdit)
    121         m_pPasswordRepeatLineEdit->setText(strPassword);
    122 }
    123 
    124 bool UIUserNamePasswordEditor::isComplete()
    125 {
    126     if (m_pUserNameLineEdit && m_pUserNameLineEdit->text().isEmpty())
    127     {
    128         markLineEdit(m_pUserNameLineEdit, true);
    129         return false;
    130     }
    131     else
    132         markLineEdit(m_pUserNameLineEdit, false);
    133     bool fPasswordOK = true;
    134     if (m_pPasswordLineEdit && m_pPasswordRepeatLineEdit)
    135     {
    136         if (m_pPasswordLineEdit->text() != m_pPasswordRepeatLineEdit->text())
    137             fPasswordOK = false;
    138         if (m_pPasswordLineEdit->text().isEmpty())
    139             fPasswordOK = false;
    140     }
    141     markLineEdit(m_pPasswordLineEdit, !fPasswordOK);
    142     markLineEdit(m_pPasswordRepeatLineEdit, !fPasswordOK);
    143     return fPasswordOK;
    144 }
    145 
    146 void UIUserNamePasswordEditor::retranslateUi()
    147 {
    148     if (m_pUserNameLabel)
    149     {
    150         m_pUserNameLabel->setText(UIWizardNewVM::tr("User Name:"));
    151         m_pUserNameLabel->setToolTip(UIWizardNewVM::tr("Type the user name which will be used in attended install:"));
    152 
    153     }
    154     if (m_pPasswordLabel)
    155     {
    156         m_pPasswordLabel->setText(UIWizardNewVM::tr("Password:"));
    157         m_pPasswordLabel->setToolTip(UIWizardNewVM::tr("Type the password for the user name"));
    158 
    159     }
    160     if (m_pPasswordRepeatLabel)
    161     {
    162         m_pPasswordRepeatLabel->setText(UIWizardNewVM::tr("Repeat Password:"));
    163         m_pPasswordRepeatLabel->setToolTip(UIWizardNewVM::tr("Retype the password:"));
    164     }
    165 }
    166 
    167 template <class T>
    168 void UIUserNamePasswordEditor::addLineEdit(int &iRow, QLabel *&pLabel, T *&pLineEdit, QGridLayout *pLayout)
    169 {
    170     if (!pLayout || pLabel || pLineEdit)
    171         return;
    172     pLabel = new QLabel;
    173     if (!pLabel)
    174         return;
    175     pLayout->addWidget(pLabel, iRow, 0, 1, 1, Qt::AlignRight);
    176 
    177     pLineEdit = new T;
    178     if (!pLineEdit)
    179         return;
    180     pLayout->addWidget(pLineEdit, iRow, 1, 1, 3);
    181 
    182     pLabel->setBuddy(pLineEdit);
    183     ++iRow;
    184     connect(pLineEdit, &T::textChanged, this, &UIUserNamePasswordEditor::sigSomeTextChanged);
    185     return;
    186 }
    187 
    188 void UIUserNamePasswordEditor::markLineEdit(QLineEdit *pLineEdit, bool fError)
    189 {
    190     if (!pLineEdit)
    191         return;
    192     QPalette palette = pLineEdit->palette();
    193     if (fError)
    194         palette.setColor(QPalette::Base, QColor(255, 180, 180));
    195     else
    196         palette.setColor(QPalette::Base, m_orginalLineEditBaseColor);
    197     pLineEdit->setPalette(palette);
    198 }
    199 
    200 void UIUserNamePasswordEditor::prepare()
    201 {
    202     QGridLayout *pMainLayout = new QGridLayout;
    203     pMainLayout->setContentsMargins(0, 0, 0, 0);
    204     if (!pMainLayout)
    205         return;
    206     setLayout(pMainLayout);
    207     int iRow = 0;
    208     addLineEdit<QLineEdit>(iRow, m_pUserNameLabel, m_pUserNameLineEdit, pMainLayout);
    209     addLineEdit<UIPasswordLineEdit>(iRow, m_pPasswordLabel, m_pPasswordLineEdit, pMainLayout);
    210     addLineEdit<UIPasswordLineEdit>(iRow, m_pPasswordRepeatLabel, m_pPasswordRepeatLineEdit, pMainLayout);
    211 
    212     connect(m_pPasswordLineEdit, &UIPasswordLineEdit::sigTextVisibilityToggled,
    213             this, &UIUserNamePasswordEditor::sltHandlePasswordVisibility);
    214     connect(m_pPasswordRepeatLineEdit, &UIPasswordLineEdit::sigTextVisibilityToggled,
    215             this, &UIUserNamePasswordEditor::sltHandlePasswordVisibility);
    216     /* Cache the original back color of the line edit to restore it correctly: */
    217     if (m_pUserNameLineEdit)
    218         m_orginalLineEditBaseColor = m_pUserNameLineEdit->palette().color(QPalette::Base);
    219 
    220     retranslateUi();
    221 }
    222 
    223 void UIUserNamePasswordEditor::sltHandlePasswordVisibility(bool fPasswordVisible)
    224 {
    225     if (m_pPasswordLineEdit)
    226         m_pPasswordLineEdit->toggleTextVisibility(fPasswordVisible);
    227     if (m_pPasswordRepeatLineEdit)
    228         m_pPasswordRepeatLineEdit->toggleTextVisibility(fPasswordVisible);
    229 }
    23029
    23130UIWizardNewVMPageInstallSetup::UIWizardNewVMPageInstallSetup()
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasicInstallSetup.h

    r84965 r84969  
    2222#endif
    2323
    24 /* Qt includes: */
    25 #include <QLineEdit>
    26 #include <QWidget>
    27 
    2824/* Local includes: */
    2925#include "QIWithRetranslateUI.h"
     
    3329class QGridLayout;
    3430class QLabel;
    35 class QSpinBox;
     31class QLineEdit;
    3632class QIRichTextLabel;
     33class UIUserNamePasswordEditor;
    3734struct UIUnattendedInstallData;
    3835
    39 class UIPasswordLineEdit : public QLineEdit
    40 {
    41     Q_OBJECT;
    4236
    43 signals:
    44 
    45     void sigTextVisibilityToggled(bool fTextVisible);
    46 
    47 public:
    48 
    49     UIPasswordLineEdit(QWidget *pParent = 0);
    50     void toggleTextVisibility(bool fTextVisible);
    51 
    52 protected:
    53 
    54     virtual void paintEvent(QPaintEvent *pevent) /* override */;
    55 
    56 private:
    57 
    58     void prepare();
    59 
    60     QToolButton *m_pTextVisibilityButton;
    61 
    62 private slots:
    63 
    64     void sltHandleTextVisibilityChange();
    65 };
    66 
    67 class UIUserNamePasswordEditor : public QIWithRetranslateUI<QWidget>
    68 {
    69 
    70     Q_OBJECT;
    71 
    72 signals:
    73 
    74     /** this is emitted whenever the content of one of the line edits is changed. */
    75     void sigSomeTextChanged();
    76 
    77 public:
    78 
    79     UIUserNamePasswordEditor(QWidget *pParent = 0);
    80 
    81     QString userName() const;
    82     void setUserName(const QString &strUserName);
    83 
    84     QString password() const;
    85     void setPassword(const QString &strPassword);
    86 
    87     /** Returns false if username or password fields are empty, or password fields do not match. */
    88     bool isComplete();
    89 
    90 protected:
    91 
    92     void retranslateUi();
    93 
    94 private slots:
    95 
    96     void sltHandlePasswordVisibility(bool fPasswordVisible);
    97 
    98 private:
    99 
    100     void prepare();
    101     template <class T>
    102     void addLineEdit(int &iRow, QLabel *&pLabel, T *&pLineEdit, QGridLayout *pLayout);
    103     /** Changes @p pLineEdit's base color to indicate an error or reverts it to the original color. */
    104     void markLineEdit(QLineEdit *pLineEdit, bool fError);
    105 
    106     QLineEdit          *m_pUserNameLineEdit;
    107     UIPasswordLineEdit *m_pPasswordLineEdit;
    108     UIPasswordLineEdit *m_pPasswordRepeatLineEdit;
    109 
    110     QLabel *m_pUserNameLabel;
    111     QLabel *m_pPasswordLabel;
    112     QLabel *m_pPasswordRepeatLabel;
    113     QColor m_orginalLineEditBaseColor;
    114 };
    115 
    116 /* 2nd page of the New Virtual Machine wizard (base part): */
    11737class UIWizardNewVMPageInstallSetup : public UIWizardPageBase
    11838{
Note: See TracChangeset for help on using the changeset viewer.

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