Changeset 104546 in vbox
- Timestamp:
- May 8, 2024 12:20:28 PM (7 months ago)
- 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 201 201 202 202 UIMarkableLineEdit::UIMarkableLineEdit(QWidget *pParent /* = 0 */) 203 :QWidget(pParent) 204 , m_pLineEdit(0) 203 : QLineEdit(pParent) 205 204 , m_pIconLabel(0) 206 205 { … … 208 207 } 209 208 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 210 void 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 226 void UIMarkableLineEdit::paintEvent(QPaintEvent *pEvent) 227 { 228 QLineEdit::paintEvent(pEvent); 229 moveIconLabel(); 230 } 231 void UIMarkableLineEdit::moveIconLabel() 249 232 { 250 233 AssertPtrReturnVoid(m_pIconLabel); 251 234 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 239 void UIMarkableLineEdit::resizeEvent(QResizeEvent *pResizeEvent) 240 { 241 /* Call to base-class: */ 242 QLineEdit::resizeEvent(pResizeEvent); 243 moveIconLabel(); 257 244 } 258 245 … … 262 249 AssertReturnVoid(pMainLayout); 263 250 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); 267 252 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 97 97 }; 98 98 99 class SHARED_LIBRARY_STUFF UIMarkableLineEdit : public Q Widget99 class SHARED_LIBRARY_STUFF UIMarkableLineEdit : public QLineEdit 100 100 { 101 101 Q_OBJECT; … … 103 103 signals: 104 104 105 void textChanged(const QString &strText);106 105 107 106 public: 108 107 109 108 UIMarkableLineEdit(QWidget *pParent = 0); 110 void mark(bool fError, const QString &strErrorMessage = QString());109 void mark(bool fError, const QString &strErrorMessage, const QString &strNoErrorMessage); 111 110 112 111 /** @name Pass through functions for QILineEdit. 113 112 * @{ */ 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 120 115 /** @} */ 121 116 122 117 private: 123 118 119 /** Handles resize @a pEvent. */ 120 virtual void resizeEvent(QResizeEvent *pResizeEvent) RT_OVERRIDE; 121 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE; 122 void moveIconLabel(); 124 123 void prepare(); 125 124 126 QILineEdit *m_pLineEdit;127 125 QLabel *m_pIconLabel; 126 int m_iIconMargin; 128 127 }; 129 128 -
trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UINameAndSystemEditor.cpp
r104313 r104546 237 237 { 238 238 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")); 240 240 } 241 241 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIHostnameDomainNameEditor.cpp
r104534 r104546 75 75 m_pHostnameLineEdit->mark(!m_pHostnameLineEdit->hasAcceptableInput(), 76 76 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")); 78 79 if (m_pDomainNameLineEdit) 79 80 m_pDomainNameLineEdit->mark(!m_pDomainNameLineEdit->hasAcceptableInput(), 80 81 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")); 82 84 } 83 85 … … 136 138 } 137 139 138 template<class T> 139 void UIHostnameDomainNameEditor::addLineEdit(int &iRow, QLabel *&pLabel, T *&pLineEdit, QGridLayout *pLayout) 140 void UIHostnameDomainNameEditor::addLineEdit(int &iRow, QLabel *&pLabel, UIMarkableLineEdit *&pLineEdit, QGridLayout *pLayout) 140 141 { 141 142 AssertReturnVoid(pLayout); … … 146 147 AssertReturnVoid(pLabel); 147 148 pLabel->setAlignment(Qt::AlignRight); 148 //pLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);149 150 149 pLayout->addWidget(pLabel, iRow, 0, 1, 1); 151 150 152 pLineEdit = new T;151 pLineEdit = new UIMarkableLineEdit; 153 152 AssertReturnVoid(pLineEdit); 154 153 … … 156 155 pLabel->setBuddy(pLineEdit); 157 156 ++iRow; 158 return;159 157 } 160 158 … … 168 166 setLayout(m_pMainLayout); 169 167 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); 172 170 173 171 /* Host name and domain should be strings of minimum length of 2 and composed of alpha numerics, '-', and '.' … … 190 188 m_pHostnameLineEdit->mark(!m_pHostnameLineEdit->hasAcceptableInput(), 191 189 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")); 193 192 emit sigHostnameDomainNameChanged(hostnameDomainName(), isComplete()); 194 193 } … … 198 197 m_pDomainNameLineEdit->mark(!m_pDomainNameLineEdit->hasAcceptableInput(), 199 198 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")); 201 201 emit sigHostnameDomainNameChanged(hostnameDomainName(), isComplete()); 202 202 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIHostnameDomainNameEditor.h
r104534 r104546 79 79 80 80 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); 83 82 84 83 UIMarkableLineEdit *m_pHostnameLineEdit; -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIUserNamePasswordEditor.cpp
r104358 r104546 228 228 bool fComplete = (m_pUserNameLineEdit && !m_pUserNameLineEdit->text().isEmpty()); 229 229 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")); 231 232 return fComplete; 232 233 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardCloneVMEditors.cpp
r103950 r104546 70 70 71 71 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")); 73 73 74 74 const QString &strPath = m_pPathSelector->path(); … … 85 85 vbox.ComposeMachineFilename(m_pNameLineEdit->text(), strMachineGroup, QString(), m_pPathSelector->path()); 86 86 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")); 88 88 } 89 89
Note:
See TracChangeset
for help on using the changeset viewer.