VirtualBox

Ignore:
Timestamp:
Jul 8, 2020 5:57:16 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9515: A bit of cleanup for UIPasswordLineEdit which is embedded editor of UIUserNamePasswordEditor; Fixing look&feel for macOS first of all.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.cpp

    r85115 r85118  
    2020#include <QLabel>
    2121#include <QStyle>
    22 #include <QToolButton>
    2322#include <QVBoxLayout>
    2423
    2524/* GUI includes: */
    2625#include "QIRichTextLabel.h"
     26#include "QIToolButton.h"
    2727#include "UICommon.h"
    2828#include "UIIconPool.h"
     
    3131
    3232UIPasswordLineEdit::UIPasswordLineEdit(QWidget *pParent /*= 0 */)
    33     :QLineEdit(pParent)
     33    : QLineEdit(pParent)
    3434    , m_pTextVisibilityButton(0)
    3535{
     
    3939void UIPasswordLineEdit::toggleTextVisibility(bool fTextVisible)
    4040{
     41    AssertPtrReturnVoid(m_pTextVisibilityButton);
     42
    4143    if (fTextVisible)
    4244    {
    4345        setEchoMode(QLineEdit::Normal);
    44         if(m_pTextVisibilityButton)
     46        if (m_pTextVisibilityButton)
    4547            m_pTextVisibilityButton->setIcon(UIIconPool::iconSet(":/eye_closed_10px.png"));
    46         return;
    47     }
    48     setEchoMode(QLineEdit::Password);
    49     if(m_pTextVisibilityButton)
    50         m_pTextVisibilityButton->setIcon(UIIconPool::iconSet(":/eye_10px.png"));
     48    }
     49    else
     50    {
     51        setEchoMode(QLineEdit::Password);
     52        if (m_pTextVisibilityButton)
     53            m_pTextVisibilityButton->setIcon(UIIconPool::iconSet(":/eye_10px.png"));
     54    }
    5155}
    5256
    5357void UIPasswordLineEdit::prepare()
    5458{
    55     m_pTextVisibilityButton = new QToolButton(this);
    56     m_pTextVisibilityButton->setIconSize(QSize(10, 10));
    57     m_pTextVisibilityButton->setFocusPolicy(Qt::ClickFocus);
    58     m_pTextVisibilityButton->setAutoRaise(true);
    59     m_pTextVisibilityButton->setCursor(Qt::ArrowCursor);
    60     m_pTextVisibilityButton->show();
    61     connect(m_pTextVisibilityButton, &QToolButton::clicked, this, &UIPasswordLineEdit::sltHandleTextVisibilityChange);
     59    /* Prepare text visibility button: */
     60    m_pTextVisibilityButton = new QIToolButton(this);
     61    if (m_pTextVisibilityButton)
     62    {
     63        m_pTextVisibilityButton->setIconSize(QSize(10, 10));
     64        m_pTextVisibilityButton->setFocusPolicy(Qt::ClickFocus);
     65        m_pTextVisibilityButton->setCursor(Qt::ArrowCursor);
     66        m_pTextVisibilityButton->show();
     67        connect(m_pTextVisibilityButton, &QToolButton::clicked, this, &UIPasswordLineEdit::sltHandleTextVisibilityChange);
     68    }
     69
    6270    toggleTextVisibility(false);
    63 }
    64 
    65 void UIPasswordLineEdit::paintEvent(QPaintEvent *pevent)
    66 {
    67     QLineEdit::paintEvent(pevent);
     71    adjustTextVisibilityButtonGeometry();
     72}
     73
     74void UIPasswordLineEdit::adjustTextVisibilityButtonGeometry()
     75{
     76    AssertPtrReturnVoid(m_pTextVisibilityButton);
     77
     78#ifdef VBOX_WS_MAC
     79    /* Do not forget to update QIToolButton size on macOS, it's FIXED: */
     80    m_pTextVisibilityButton->setFixedSize(m_pTextVisibilityButton->minimumSizeHint());
     81    /* Calculate suitable position for a QIToolButton, it's FRAMELESS: */
     82    const int iWidth = m_pTextVisibilityButton->width();
     83    const int iMinHeight = qMin(height(), m_pTextVisibilityButton->height());
     84    const int iMaxHeight = qMax(height(), m_pTextVisibilityButton->height());
     85    const int iHalfHeightDiff = (iMaxHeight - iMinHeight) / 2;
     86    m_pTextVisibilityButton->setGeometry(width() - iWidth - iHalfHeightDiff, iHalfHeightDiff, iWidth, iWidth);
     87#else
    6888    int iFrameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    6989    int iSize = height() - 2 * iFrameWidth;
    7090    m_pTextVisibilityButton->setGeometry(width() - iSize, iFrameWidth, iSize, iSize);
    71 
     91#endif
     92}
     93
     94void UIPasswordLineEdit::resizeEvent(QResizeEvent *pEvent)
     95{
     96    /* Call to base-class: */
     97    QLineEdit::resizeEvent(pEvent);
     98
     99    adjustTextVisibilityButtonGeometry();
    72100}
    73101
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.h

    r85110 r85118  
    3232class QGridLayout;
    3333class QLabel;
     34class QIToolButton;
    3435
    3536class UIPasswordLineEdit : public QLineEdit
     
    4849protected:
    4950
    50     virtual void paintEvent(QPaintEvent *pevent) /* override */;
     51    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
    5152
    5253private:
    5354
    5455    void prepare();
     56    void adjustTextVisibilityButtonGeometry();
    5557
    56     QToolButton *m_pTextVisibilityButton;
     58    QIToolButton *m_pTextVisibilityButton;
    5759
    5860private slots:
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