VirtualBox

Changeset 87731 in vbox for trunk


Ignore:
Timestamp:
Feb 12, 2021 11:00:29 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: Working on the error indicators of UIUserNamePasswordEditor

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
5 edited

Legend:

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

    r87656 r87731  
    956956        src/widgets/UIMenuToolBar.cpp \
    957957        src/widgets/UITabBar.cpp \
     958        src/widgets/UIUserNamePasswordEditor.cpp \
    958959        src/widgets/graphics/UIGraphicsScrollBar.cpp \
    959960        src/wizards/importappliance/UIWizardImportApp.cpp
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.cpp

    r87348 r87731  
    1919#include <QGridLayout>
    2020#include <QLabel>
     21#include <QLineEdit>
    2122#include <QStyle>
    2223#include <QVBoxLayout>
     
    3031#include "UIWizardNewVM.h"
    3132
     33/*********************************************************************************************************************************
     34*   UIPasswordLineEdit definition.                                                                                        *
     35*********************************************************************************************************************************/
     36
     37class UIPasswordLineEdit : public QLineEdit
     38{
     39    Q_OBJECT;
     40
     41signals:
     42
     43    void sigTextVisibilityToggled(bool fTextVisible);
     44
     45public:
     46
     47    UIPasswordLineEdit(QWidget *pParent = 0);
     48    void toggleTextVisibility(bool fTextVisible);
     49    void mark(bool fError, const QString &strErrorToolTip);
     50
     51protected:
     52
     53    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     54    virtual void paintEvent(QPaintEvent *pPaintEvent) /* override */;
     55
     56private slots:
     57
     58    void sltHandleTextVisibilityChange();
     59
     60private:
     61
     62    void prepare();
     63    void adjustTextVisibilityButtonGeometry();
     64
     65    QIToolButton *m_pTextVisibilityButton;
     66    QIcon m_markIcon;
     67    QLabel *m_pErrorIconLabel;
     68    QString m_strErrorToolTip;
     69    /** When true the line edit is marked with some icon to indicate some error. */
     70    bool m_fMarkForError;
     71};
     72
     73
     74/*********************************************************************************************************************************
     75*   UIPasswordLineEdit implementation.                                                                                           *
     76*********************************************************************************************************************************/
     77
    3278UIPasswordLineEdit::UIPasswordLineEdit(QWidget *pParent /*= 0 */)
    3379    : QLineEdit(pParent)
    3480    , m_pTextVisibilityButton(0)
     81    , m_pErrorIconLabel(0)
     82    , m_fMarkForError(false)
    3583{
    3684    prepare();
     
    55103}
    56104
     105void UIPasswordLineEdit::mark(bool fError, const QString &strErrorToolTip)
     106{
     107    if (m_fMarkForError == fError &&  m_strErrorToolTip == strErrorToolTip)
     108        return;
     109    m_fMarkForError = fError;
     110    m_strErrorToolTip = strErrorToolTip;
     111    update();
     112}
     113
    57114void UIPasswordLineEdit::prepare()
    58115{
     116    m_markIcon = UIIconPool::iconSet(":/status_error_16px.png");
    59117    /* Prepare text visibility button: */
    60118    m_pTextVisibilityButton = new QIToolButton(this);
     
    67125        connect(m_pTextVisibilityButton, &QToolButton::clicked, this, &UIPasswordLineEdit::sltHandleTextVisibilityChange);
    68126    }
    69 
     127    m_pErrorIconLabel = new QLabel(this);
    70128    toggleTextVisibility(false);
    71129    adjustTextVisibilityButtonGeometry();
     
    96154    /* Call to base-class: */
    97155    QLineEdit::resizeEvent(pEvent);
    98 
    99156    adjustTextVisibilityButtonGeometry();
     157}
     158
     159void UIPasswordLineEdit::paintEvent(QPaintEvent *pPaintEvent)
     160{
     161    QLineEdit::paintEvent(pPaintEvent);
     162    if (m_fMarkForError)
     163    {
     164        const int iIconMargin = 0.5 * QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
     165        int iIconSize = height() - 2 * iIconMargin;
     166        if (!m_pErrorIconLabel)
     167            m_pErrorIconLabel = new QLabel(this);
     168        m_pErrorIconLabel->setPixmap(m_markIcon.pixmap(windowHandle(), QSize(iIconSize, iIconSize)));
     169        int iIconX = width() - iIconSize - iIconMargin;
     170        if (m_pTextVisibilityButton)
     171            iIconX -= m_pTextVisibilityButton->width() - iIconMargin;
     172        m_pErrorIconLabel->move(iIconX, iIconMargin);
     173        m_pErrorIconLabel->setToolTip(m_strErrorToolTip);
     174        m_pErrorIconLabel->show();
     175    }
     176    else
     177    {
     178        if (m_pErrorIconLabel)
     179            m_pErrorIconLabel->hide();
     180    }
    100181}
    101182
     
    110191    emit sigTextVisibilityToggled(fTextVisible);
    111192}
     193
     194
     195/*********************************************************************************************************************************
     196*   UIUserNamePasswordEditor implementation.                                                                                     *
     197*********************************************************************************************************************************/
    112198
    113199UIUserNamePasswordEditor::UIUserNamePasswordEditor(QWidget *pParent /*  = 0 */)
     
    170256        if (m_pPasswordLineEdit->text().isEmpty())
    171257            fPasswordOK = false;
    172     }
    173     markLineEdit(m_pPasswordLineEdit, !fPasswordOK);
    174     markLineEdit(m_pPasswordRepeatLineEdit, !fPasswordOK);
     258
     259        m_pPasswordLineEdit->mark(!fPasswordOK, m_strPasswordError);
     260        m_pPasswordRepeatLineEdit->mark(!fPasswordOK, m_strPasswordError);
     261    }
    175262    return fPasswordOK;
    176263}
     
    211298void UIUserNamePasswordEditor::retranslateUi()
    212299{
    213     QString strPassword = UIWizardNewVM::tr("Password:");
    214     QString strRepeatPassword = UIWizardNewVM::tr("Repeat Password:");
    215     QString strUsername = UIWizardNewVM::tr("Username:");
     300    QString strPassword = UIUserNamePasswordEditor::tr("Password");
     301    QString strRepeatPassword = UIUserNamePasswordEditor::tr("Repeat Password");
     302    QString strUsername = UIUserNamePasswordEditor::tr("Username");
    216303    if (m_pUserNameLabel)
    217304    {
    218         m_pUserNameLabel->setText(strUsername);
    219         m_pUserNameLabel->setToolTip(UIWizardNewVM::tr("Type the user name which will be used in attended install:"));
     305        m_pUserNameLabel->setText(QString("%1%2").arg(strUsername).arg(":"));
     306        m_pUserNameLabel->setToolTip(UIUserNamePasswordEditor::tr("Type the user name which will be used in attended install:"));
    220307
    221308    }
    222309    if (m_pPasswordLabel)
    223310    {
    224         m_pPasswordLabel->setText(strPassword);
    225         m_pPasswordLabel->setToolTip(UIWizardNewVM::tr("Type the password for the user name"));
     311        m_pPasswordLabel->setText(QString("%1%2").arg(strPassword).arg(":"));
     312        m_pPasswordLabel->setToolTip(UIUserNamePasswordEditor::tr("Type the password for the user name"));
    226313
    227314    }
    228315    if (m_pPasswordRepeatLabel)
    229316    {
    230         m_pPasswordRepeatLabel->setText(strRepeatPassword);
    231         m_pPasswordRepeatLabel->setToolTip(UIWizardNewVM::tr("Retype the password:"));
     317        m_pPasswordRepeatLabel->setText(QString("%1%2").arg(strRepeatPassword).arg(":"));
     318        m_pPasswordRepeatLabel->setToolTip(UIUserNamePasswordEditor::tr("Retype the password:"));
    232319    }
    233320
     
    250337            m_pPasswordRepeatLineEdit->setPlaceholderText(QString());
    251338    }
     339    m_strPasswordError = UIUserNamePasswordEditor::tr("Invalid password pair");
    252340}
    253341
     
    326414    emit sigSomeTextChanged();
    327415}
     416
     417#include "UIUserNamePasswordEditor.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.h

    r87348 r87731  
    2323
    2424/* Qt includes: */
    25 #include <QLineEdit>
     25#include <QIcon>
    2626#include <QWidget>
    2727
     
    3232class QGridLayout;
    3333class QLabel;
    34 class QIToolButton;
    35 
    36 class UIPasswordLineEdit : public QLineEdit
    37 {
    38     Q_OBJECT;
    39 
    40 signals:
    41 
    42     void sigTextVisibilityToggled(bool fTextVisible);
    43 
    44 public:
    45 
    46     UIPasswordLineEdit(QWidget *pParent = 0);
    47     void toggleTextVisibility(bool fTextVisible);
    48 
    49 protected:
    50 
    51     virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
    52 
    53 private:
    54 
    55     void prepare();
    56     void adjustTextVisibilityButtonGeometry();
    57 
    58     QIToolButton *m_pTextVisibilityButton;
    59 
    60 private slots:
    61 
    62     void sltHandleTextVisibilityChange();
    63 };
     34class QLineEdit;
     35class UIPasswordLineEdit;
    6436
    6537class UIUserNamePasswordEditor : public QIWithRetranslateUI<QWidget>
     
    12496    bool m_fShowPlaceholderText;
    12597    bool m_fLabelsVisible;
     98
     99    QString m_strPasswordError;
    126100};
    127101
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic2.cpp

    r87592 r87731  
    2222#include <QGroupBox>
    2323#include <QLabel>
     24#include <QLineEdit>
    2425#include <QSpacerItem>
    2526#include <QToolBox>
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp

    r87724 r87731  
    2323#include <QHBoxLayout>
    2424#include <QLabel>
     25#include <QLineEdit>
    2526#include <QRadioButton>
    2627#include <QSpinBox>
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