VirtualBox

Changeset 90642 in vbox for trunk


Ignore:
Timestamp:
Aug 12, 2021 6:47:02 AM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: QILineEdit and UIUserNamePasswordEditor: There should NO be logic other than painting inside paintEvent.

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

Legend:

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

    r90641 r90642  
    2424#include <QPalette>
    2525#include <QStyleOptionFrame>
    26 #include <QTime>
    2726
    2827/* GUI includes: */
     
    6766void QILineEdit::mark(bool fError, const QString &strErrorMessage /* = QString() */)
    6867{
     68    /* Check if something really changed: */
    6969    if (fError == m_fMarkForError && m_strErrorMessage == strErrorMessage)
    7070        return;
     71
     72    /* Save new values: */
    7173    m_fMarkForError = fError;
    7274    m_strErrorMessage = strErrorMessage;
    73     update();
     75
     76    /* Update accordingly: */
     77    if (m_fMarkForError)
     78    {
     79        /* Create label if absent: */
     80        if (!m_pIconLabel)
     81            m_pIconLabel = new QLabel(this);
     82
     83        /* Update label content, visibility & position: */
     84        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * .625;
     85        const int iShift = height() > iIconMetric ? (height() - iIconMetric) / 2 : 0;
     86        m_pIconLabel->setPixmap(m_markIcon.pixmap(windowHandle(), QSize(iIconMetric, iIconMetric)));
     87        m_pIconLabel->setToolTip(m_strErrorMessage);
     88        m_pIconLabel->move(width() - iIconMetric - iShift, iShift);
     89        m_pIconLabel->show();
     90    }
     91    else
     92    {
     93        /* Hide label: */
     94        if (m_pIconLabel)
     95            m_pIconLabel->hide();
     96    }
    7497}
    7598
     
    99122}
    100123
    101 void QILineEdit::paintEvent(QPaintEvent *pPaintEvent)
     124void QILineEdit::resizeEvent(QResizeEvent *pResizeEvent)
    102125{
    103     QLineEdit::paintEvent(pPaintEvent);
     126    /* Call to base-class: */
     127    QLineEdit::resizeEvent(pResizeEvent);
    104128
    105     if (m_fMarkForError)
     129    /* Update error label position: */
     130    if (m_pIconLabel)
    106131    {
    107         if (!m_pIconLabel)
    108             m_pIconLabel = new QLabel(this);
    109 
    110         if (m_pIconLabel && m_pIconLabel->isHidden())
    111         {
    112             const int iIconMargin = 1. * QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
    113             int iIconSize = height() - 2 * iIconMargin;
    114             m_pIconLabel->setPixmap(m_markIcon.pixmap(windowHandle(), QSize(iIconSize, iIconSize)));
    115             m_pIconLabel->setToolTip(m_strErrorMessage);
    116             m_pIconLabel->move(width() - iIconSize - iIconMargin, iIconMargin);
    117             m_pIconLabel->show();
    118         }
    119     }
    120     else
    121     {
    122         if (m_pIconLabel && m_pIconLabel->isVisible())
    123             m_pIconLabel->hide();
     132        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * .625;
     133        const int iShift = height() > iIconMetric ? (height() - iIconMetric) / 2 : 0;
     134        m_pIconLabel->move(width() - iIconMetric - iShift, iShift);
    124135    }
    125136}
     
    134145void QILineEdit::prepare()
    135146{
    136     m_markIcon = UIIconPool::iconSet(":/status_error_16px.png");
    137 
    138147    /* Prepare invisible copy action: */
    139148    m_pCopyAction = new QAction(this);
     
    145154        addAction(m_pCopyAction);
    146155    }
     156
     157    /* Prepare warning icon: */
     158    m_markIcon = UIIconPool::iconSet(":/status_error_16px.png");
    147159}
    148160
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.h

    r88860 r90642  
    5959    /** Handles any Qt @a pEvent. */
    6060    virtual bool event(QEvent *pEvent) /* override */;
    61     virtual void paintEvent(QPaintEvent *pPaintEvent) /* override */;
     61
     62    /** Handles resize @a pEvent. */
     63    virtual void resizeEvent(QResizeEvent *pResizeEvent) /* override */;
    6264
    6365private slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIUserNamePasswordEditor.cpp

    r90193 r90642  
    5353
    5454    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
    55     virtual void paintEvent(QPaintEvent *pPaintEvent) /* override */;
    5655
    5756private slots:
     
    106105void UIPasswordLineEdit::mark(bool fError, const QString &strErrorToolTip)
    107106{
     107    /* Check if something really changed: */
    108108    if (m_fMarkForError == fError &&  m_strErrorToolTip == strErrorToolTip)
    109109        return;
     110
     111    /* Save new values: */
    110112    m_fMarkForError = fError;
    111113    m_strErrorToolTip = strErrorToolTip;
    112     update();
     114
     115    /* Update accordingly: */
     116    if (m_fMarkForError)
     117    {
     118        /* Create label if absent: */
     119        if (!m_pErrorIconLabel)
     120            m_pErrorIconLabel = new QLabel(this);
     121
     122        /* Update label content, visibility & position: */
     123        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * .625;
     124        const int iShift = height() > iIconMetric ? (height() - iIconMetric) / 2 : 0;
     125        m_pErrorIconLabel->setPixmap(m_markIcon.pixmap(windowHandle(), QSize(iIconMetric, iIconMetric)));
     126        m_pErrorIconLabel->setToolTip(m_strErrorToolTip);
     127        int iIconX = width() - iIconMetric - iShift;
     128        if (m_pTextVisibilityButton)
     129            iIconX -= m_pTextVisibilityButton->width() - iShift;
     130        m_pErrorIconLabel->move(iIconX, iShift);
     131        m_pErrorIconLabel->show();
     132    }
     133    else
     134    {
     135        /* Hide label: */
     136        if (m_pErrorIconLabel)
     137            m_pErrorIconLabel->hide();
     138    }
    113139}
    114140
     
    156182    QLineEdit::resizeEvent(pEvent);
    157183    adjustTextVisibilityButtonGeometry();
    158 }
    159 
    160 void UIPasswordLineEdit::paintEvent(QPaintEvent *pPaintEvent)
    161 {
    162     QLineEdit::paintEvent(pPaintEvent);
    163     if (m_fMarkForError)
    164     {
    165         const int iIconMargin = 1. * QApplication::style()->pixelMetric(QStyle::PM_LayoutTopMargin);
    166         int iIconSize = height() - 2 * iIconMargin;
    167         if (!m_pErrorIconLabel)
    168             m_pErrorIconLabel = new QLabel(this);
    169         m_pErrorIconLabel->setPixmap(m_markIcon.pixmap(windowHandle(), QSize(iIconSize, iIconSize)));
    170         int iIconX = width() - iIconSize - iIconMargin;
     184
     185    /* Update error label position: */
     186    if (m_pErrorIconLabel)
     187    {
     188        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) * .625;
     189        const int iShift = height() > iIconMetric ? (height() - iIconMetric) / 2 : 0;
     190        int iIconX = width() - iIconMetric - iShift;
    171191        if (m_pTextVisibilityButton)
    172             iIconX -= m_pTextVisibilityButton->width() - iIconMargin;
    173         m_pErrorIconLabel->move(iIconX, iIconMargin);
    174         m_pErrorIconLabel->setToolTip(m_strErrorToolTip);
    175         m_pErrorIconLabel->show();
    176     }
    177     else
    178     {
    179         if (m_pErrorIconLabel)
    180             m_pErrorIconLabel->hide();
     192            iIconX -= m_pTextVisibilityButton->width() - iShift;
     193        m_pErrorIconLabel->move(iIconX, iShift);
    181194    }
    182195}
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