VirtualBox

Changeset 104546 in vbox


Ignore:
Timestamp:
May 8, 2024 12:20:28 PM (7 months ago)
Author:
vboxsync
Message:

FE/Qt:bugref:10667

  • Show marker incon in both error and no error cases
  • Draw marker icon inside the line edit, not next to it
Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.cpp

    r104041 r104546  
    201201
    202202UIMarkableLineEdit::UIMarkableLineEdit(QWidget *pParent /* = 0 */)
    203     :QWidget(pParent)
    204     , m_pLineEdit(0)
     203    : QLineEdit(pParent)
    205204    , m_pIconLabel(0)
    206205{
     
    208207}
    209208
    210 void UIMarkableLineEdit::setText(const QString &strText)
    211 {
    212     if (m_pLineEdit)
    213         m_pLineEdit->setText(strText);
    214 }
    215 
    216 void UIMarkableLineEdit::setToolTip(const QString &strText)
    217 {
    218     if (m_pLineEdit)
    219         m_pLineEdit->setToolTip(strText);
    220 }
    221 
    222 QString UIMarkableLineEdit::text() const
    223 {
    224     if (!m_pLineEdit)
    225         return QString();
    226     return m_pLineEdit->text();
    227 }
    228 
    229 void UIMarkableLineEdit::setValidator(const QValidator *pValidator)
    230 {
    231     if (m_pLineEdit)
    232         m_pLineEdit->setValidator(pValidator);
    233 }
    234 
    235 bool UIMarkableLineEdit::hasAcceptableInput() const
    236 {
    237     if (!m_pLineEdit)
    238         return false;
    239     return m_pLineEdit->hasAcceptableInput();
    240 }
    241 
    242 void UIMarkableLineEdit::setPlaceholderText(const QString &strText)
    243 {
    244     if (m_pLineEdit)
    245         m_pLineEdit->setPlaceholderText(strText);
    246 }
    247 
    248 void UIMarkableLineEdit::mark(bool fError, const QString &strErrorMessage /* = QString() */)
     209
     210void UIMarkableLineEdit::mark(bool fError, const QString &strErrorMessage, const QString &strNoErrorMessage)
     211{
     212    const QIcon icon = fError ? UIIconPool::iconSet(":/status_error_16px.png") : UIIconPool::iconSet(":/status_check_16px.png");
     213    const QString strToolTip = fError ? strErrorMessage : strNoErrorMessage;
     214    const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
     215    const qreal fDevicePixelRatio = gpDesktop->devicePixelRatio(m_pIconLabel);
     216    QPixmap iconPixmap = icon.pixmap(QSize(iIconMetric, iIconMetric), fDevicePixelRatio);
     217    m_iIconMargin = QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
     218    int iHeight = height() -  m_iIconMargin;
     219    iconPixmap = iconPixmap.scaledToHeight(iHeight, Qt::SmoothTransformation);
     220    m_pIconLabel->setPixmap(iconPixmap);
     221    m_pIconLabel->setToolTip(strToolTip);
     222
     223    update();
     224}
     225
     226void UIMarkableLineEdit::paintEvent(QPaintEvent *pEvent)
     227{
     228    QLineEdit::paintEvent(pEvent);
     229    moveIconLabel();
     230}
     231void UIMarkableLineEdit::moveIconLabel()
    249232{
    250233    AssertPtrReturnVoid(m_pIconLabel);
    251234    m_pIconLabel->setVisible(true);
    252     const QIcon icon = fError ? UIIconPool::iconSet(":/status_error_16px.png") : UIIconPool::iconSet(":/status_check_16px.png");
    253     const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    254     const qreal fDevicePixelRatio = gpDesktop->devicePixelRatio(m_pIconLabel);
    255     m_pIconLabel->setPixmap(icon.pixmap(QSize(iIconMetric, iIconMetric), fDevicePixelRatio));
    256     m_pIconLabel->setToolTip(strErrorMessage);
     235    int iHeight = height() -  m_iIconMargin;
     236    m_pIconLabel->setGeometry(width() - iHeight - 0.5 * m_iIconMargin, 0.5 * m_iIconMargin, iHeight, iHeight);
     237}
     238
     239void UIMarkableLineEdit::resizeEvent(QResizeEvent *pResizeEvent)
     240{
     241    /* Call to base-class: */
     242    QLineEdit::resizeEvent(pResizeEvent);
     243    moveIconLabel();
    257244}
    258245
     
    262249    AssertReturnVoid(pMainLayout);
    263250    pMainLayout->setContentsMargins(0, 0, 0, 0);
    264     m_pLineEdit = new QILineEdit;
    265     AssertReturnVoid(m_pLineEdit);
    266     m_pIconLabel = new QLabel;
     251    m_pIconLabel = new QLabel(this);
    267252    AssertReturnVoid(m_pIconLabel);
    268     /* Show the icon label only if line edit is marked for error/no error.*/
    269     m_pIconLabel->hide();
    270     pMainLayout->addWidget(m_pLineEdit);
    271     pMainLayout->addWidget(m_pIconLabel);
    272     setFocusProxy(m_pLineEdit);
    273     connect(m_pLineEdit, &QILineEdit::textChanged, this, &UIMarkableLineEdit::textChanged);
    274 }
     253}
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.h

    r104041 r104546  
    9797};
    9898
    99 class SHARED_LIBRARY_STUFF UIMarkableLineEdit : public QWidget
     99class SHARED_LIBRARY_STUFF UIMarkableLineEdit : public QLineEdit
    100100{
    101101    Q_OBJECT;
     
    103103signals:
    104104
    105     void textChanged(const QString &strText);
    106105
    107106public:
    108107
    109108    UIMarkableLineEdit(QWidget *pParent = 0);
    110     void mark(bool fError, const QString &strErrorMessage = QString());
     109    void mark(bool fError, const QString &strErrorMessage, const QString &strNoErrorMessage);
    111110
    112111    /** @name Pass through functions for QILineEdit.
    113112      * @{ */
    114         void setText(const QString &strText);
    115         void setToolTip(const QString &strText);
    116         QString text() const;
    117         void setValidator(const QValidator *pValidator);
    118         bool hasAcceptableInput() const;
    119         void setPlaceholderText(const QString &strText);
     113
     114
    120115    /** @} */
    121116
    122117private:
    123118
     119    /** Handles resize @a pEvent. */
     120    virtual void resizeEvent(QResizeEvent *pResizeEvent) RT_OVERRIDE;
     121    virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
     122    void moveIconLabel();
    124123    void prepare();
    125124
    126     QILineEdit *m_pLineEdit;
    127125    QLabel *m_pIconLabel;
     126    int m_iIconMargin;
    128127};
    129128
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UINameAndSystemEditor.cpp

    r104313 r104546  
    237237{
    238238    if (m_pEditorName)
    239         m_pEditorName->mark(fError, fError ? tr("Invalid name") : QString("Name is valid"));
     239        m_pEditorName->mark(fError, tr("Invalid guest machine name"), tr("Guest machine name is valid"));
    240240}
    241241
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIHostnameDomainNameEditor.cpp

    r104534 r104546  
    7575        m_pHostnameLineEdit->mark(!m_pHostnameLineEdit->hasAcceptableInput(),
    7676                                  tr("Hostname should be at least 2 character long. "
    77                                      "Allowed characters are alphanumerics, \"-\" and \".\""));
     77                                     "Allowed characters are alphanumerics, \"-\" and \".\""),
     78                                  tr("Hostname is valid"));
    7879    if (m_pDomainNameLineEdit)
    7980        m_pDomainNameLineEdit->mark(!m_pDomainNameLineEdit->hasAcceptableInput(),
    8081                                    tr("Domain name should be at least 2 character long. "
    81                                        "Allowed characters are alphanumerics, \"-\" and \".\""));
     82                                       "Allowed characters are alphanumerics, \"-\" and \".\""),
     83                                    tr("Domain name is valid"));
    8284}
    8385
     
    136138}
    137139
    138 template<class T>
    139 void UIHostnameDomainNameEditor::addLineEdit(int &iRow, QLabel *&pLabel, T *&pLineEdit, QGridLayout *pLayout)
     140void UIHostnameDomainNameEditor::addLineEdit(int &iRow, QLabel *&pLabel, UIMarkableLineEdit *&pLineEdit, QGridLayout *pLayout)
    140141{
    141142    AssertReturnVoid(pLayout);
     
    146147    AssertReturnVoid(pLabel);
    147148    pLabel->setAlignment(Qt::AlignRight);
    148     //pLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    149 
    150149    pLayout->addWidget(pLabel, iRow, 0, 1, 1);
    151150
    152     pLineEdit = new T;
     151    pLineEdit = new UIMarkableLineEdit;
    153152    AssertReturnVoid(pLineEdit);
    154153
     
    156155    pLabel->setBuddy(pLineEdit);
    157156    ++iRow;
    158     return;
    159157}
    160158
     
    168166    setLayout(m_pMainLayout);
    169167    int iRow = 0;
    170     addLineEdit<UIMarkableLineEdit>(iRow, m_pHostnameLabel, m_pHostnameLineEdit, m_pMainLayout);
    171     addLineEdit<UIMarkableLineEdit>(iRow, m_pDomainNameLabel, m_pDomainNameLineEdit, m_pMainLayout);
     168    addLineEdit(iRow, m_pHostnameLabel, m_pHostnameLineEdit, m_pMainLayout);
     169    addLineEdit(iRow, m_pDomainNameLabel, m_pDomainNameLineEdit, m_pMainLayout);
    172170
    173171    /* Host name and domain should be strings of minimum length of 2 and composed of alpha numerics, '-', and '.'
     
    190188    m_pHostnameLineEdit->mark(!m_pHostnameLineEdit->hasAcceptableInput(),
    191189                              tr("Hostname should be at least 2 character long. "
    192                                  "Allowed characters are alphanumerics, \"-\" and \".\""));
     190                                 "Allowed characters are alphanumerics, \"-\" and \".\""),
     191                              tr("Hostname is valid"));
    193192    emit sigHostnameDomainNameChanged(hostnameDomainName(), isComplete());
    194193}
     
    198197    m_pDomainNameLineEdit->mark(!m_pDomainNameLineEdit->hasAcceptableInput(),
    199198                                tr("Domain name should be at least 2 character long. "
    200                                    "Allowed characters are alphanumerics, \"-\" and \".\""));
     199                                   "Allowed characters are alphanumerics, \"-\" and \".\""),
     200                                tr("Domain name is valid"));
    201201    emit sigHostnameDomainNameChanged(hostnameDomainName(), isComplete());
    202202}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIHostnameDomainNameEditor.h

    r104534 r104546  
    7979
    8080    void prepare();
    81     template<class T>
    82     void addLineEdit(int &iRow, QLabel *&pLabel, T *&pLineEdit, QGridLayout *pLayout);
     81    void addLineEdit(int &iRow, QLabel *&pLabel, UIMarkableLineEdit *&pLineEdit, QGridLayout *pLayout);
    8382
    8483    UIMarkableLineEdit *m_pHostnameLineEdit;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIUserNamePasswordEditor.cpp

    r104358 r104546  
    228228    bool fComplete = (m_pUserNameLineEdit && !m_pUserNameLineEdit->text().isEmpty());
    229229    if (m_pUserNameLineEdit)
    230         m_pUserNameLineEdit->mark(!fComplete, UIUserNamePasswordEditor::tr("Invalid username"));
     230        m_pUserNameLineEdit->mark(!fComplete, UIUserNamePasswordEditor::tr("Username cannot be an empty string."),
     231                                  UIUserNamePasswordEditor::tr("Username is valid"));
    231232    return fComplete;
    232233}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardCloneVMEditors.cpp

    r103950 r104546  
    7070
    7171    bool fInvalidName = m_pNameLineEdit->text().isEmpty();
    72     m_pNameLineEdit->mark(fInvalidName, UIWizardCloneVM::tr("Clone name cannot be empty"));
     72    m_pNameLineEdit->mark(fInvalidName, UIWizardCloneVM::tr("Clone name cannot be empty"), UIWizardCloneVM::tr("Clone name is valid"));
    7373
    7474    const QString &strPath = m_pPathSelector->path();
     
    8585            vbox.ComposeMachineFilename(m_pNameLineEdit->text(), strMachineGroup, QString(), m_pPathSelector->path());
    8686        fExists = QDir(QDir::toNativeSeparators(QFileInfo(strCloneFilePath).absolutePath())).exists();
    87         m_pNameLineEdit->mark(fExists, UIWizardCloneVM::tr("The clone name is not unique"));
     87        m_pNameLineEdit->mark(fExists, UIWizardCloneVM::tr("The clone name is not unique"), UIWizardCloneVM::tr("The clone name is valid"));
    8888    }
    8989
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