Changeset 85118 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jul 8, 2020 5:57:16 PM (5 years ago)
- 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 20 20 #include <QLabel> 21 21 #include <QStyle> 22 #include <QToolButton>23 22 #include <QVBoxLayout> 24 23 25 24 /* GUI includes: */ 26 25 #include "QIRichTextLabel.h" 26 #include "QIToolButton.h" 27 27 #include "UICommon.h" 28 28 #include "UIIconPool.h" … … 31 31 32 32 UIPasswordLineEdit::UIPasswordLineEdit(QWidget *pParent /*= 0 */) 33 : QLineEdit(pParent)33 : QLineEdit(pParent) 34 34 , m_pTextVisibilityButton(0) 35 35 { … … 39 39 void UIPasswordLineEdit::toggleTextVisibility(bool fTextVisible) 40 40 { 41 AssertPtrReturnVoid(m_pTextVisibilityButton); 42 41 43 if (fTextVisible) 42 44 { 43 45 setEchoMode(QLineEdit::Normal); 44 if (m_pTextVisibilityButton)46 if (m_pTextVisibilityButton) 45 47 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 } 51 55 } 52 56 53 57 void UIPasswordLineEdit::prepare() 54 58 { 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 62 70 toggleTextVisibility(false); 63 } 64 65 void UIPasswordLineEdit::paintEvent(QPaintEvent *pevent) 66 { 67 QLineEdit::paintEvent(pevent); 71 adjustTextVisibilityButtonGeometry(); 72 } 73 74 void 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 68 88 int iFrameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); 69 89 int iSize = height() - 2 * iFrameWidth; 70 90 m_pTextVisibilityButton->setGeometry(width() - iSize, iFrameWidth, iSize, iSize); 71 91 #endif 92 } 93 94 void UIPasswordLineEdit::resizeEvent(QResizeEvent *pEvent) 95 { 96 /* Call to base-class: */ 97 QLineEdit::resizeEvent(pEvent); 98 99 adjustTextVisibilityButtonGeometry(); 72 100 } 73 101 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIUserNamePasswordEditor.h
r85110 r85118 32 32 class QGridLayout; 33 33 class QLabel; 34 class QIToolButton; 34 35 35 36 class UIPasswordLineEdit : public QLineEdit … … 48 49 protected: 49 50 50 virtual void paintEvent(QPaintEvent *pevent) /* override */;51 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 51 52 52 53 private: 53 54 54 55 void prepare(); 56 void adjustTextVisibilityButtonGeometry(); 55 57 56 Q ToolButton *m_pTextVisibilityButton;58 QIToolButton *m_pTextVisibilityButton; 57 59 58 60 private slots:
Note:
See TracChangeset
for help on using the changeset viewer.