- Timestamp:
- Aug 29, 2008 6:50:53 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxFilePathSelectorWidget.h
r11511 r11845 68 68 void focusInEvent (QFocusEvent *aEvent); 69 69 void focusOutEvent (QFocusEvent *aEvent); 70 bool eventFilter (QObject *aObj, QEvent *aEv); 70 71 void retranslateUi(); 71 72 … … 74 75 void onActivated (int aIndex); 75 76 void copyToClipboard(); 77 void refreshText(); 76 78 77 79 private: … … 81 83 QString fullPath (bool aAbsolute = true) const; 82 84 QString shrinkText (int aWidth) const; 83 void refreshText();84 85 85 86 /* Private member vars */ … … 92 93 QString mNoneTip; 93 94 bool mIsEditableMode; 95 bool mIsMouseAwaited; 94 96 }; 95 97 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFilePathSelectorWidget.cpp
r11653 r11845 31 31 #include <QFileIconProvider> 32 32 #include <QLineEdit> 33 #include <QTimer> 33 34 34 35 enum … … 38 39 ResetId 39 40 }; 41 42 /** 43 * Returns first position of difference between passed strings. 44 */ 45 static int differFrom (const QString &aS1, const QString &aS2) 46 { 47 if (aS1 == aS2) 48 return -1; 49 50 int minLength = qMin (aS1.size(), aS2.size()); 51 int index = 0; 52 for (index = 0; index < minLength ; ++ index) 53 if (aS1 [index] != aS2 [index]) 54 break; 55 return index; 56 } 40 57 41 58 VBoxFilePathSelectorWidget::VBoxFilePathSelectorWidget (QWidget *aParent) … … 46 63 , mHomeDir (QDir::current().absolutePath()) 47 64 , mIsEditableMode (false) 65 , mIsMouseAwaited (false) 48 66 { 49 67 /* Populate items */ … … 76 94 /* Applying language settings */ 77 95 retranslateUi(); 96 97 /* Installing necessary event filters */ 98 lineEdit()->installEventFilter (this); 78 99 } 79 100 … … 156 177 { 157 178 mIsEditableMode = true; 158 refreshText(); 179 if (aEvent->reason() == Qt::MouseFocusReason) 180 mIsMouseAwaited = true; 181 else 182 refreshText(); 159 183 } 160 184 QIWithRetranslateUI<QComboBox>::focusInEvent (aEvent); … … 169 193 } 170 194 QIWithRetranslateUI<QComboBox>::focusOutEvent (aEvent); 195 } 196 197 bool VBoxFilePathSelectorWidget::eventFilter (QObject *aObj, QEvent *aEv) 198 { 199 if (mIsMouseAwaited && (aEv->type() == QEvent::MouseButtonPress)) 200 QTimer::singleShot (0, this, SLOT (refreshText())); 201 202 return QIWithRetranslateUI<QComboBox>::eventFilter (aObj, aEv); 171 203 } 172 204 … … 353 385 if (mIsEditableMode) 354 386 { 387 /* Cursor positioning variables */ 388 int curPos = -1; 389 int diffPos = -1; 390 int fromRight = -1; 391 392 if (mIsMouseAwaited) 393 { 394 /* Store the cursor position */ 395 curPos = lineEdit()->cursorPosition(); 396 diffPos = differFrom (lineEdit()->text(), mPath); 397 fromRight = lineEdit()->text().size() - curPos; 398 } 399 355 400 /* In editable mode there should be no any icon 356 401 * and text have be corresponding real stored path … … 361 406 tr ("Please type the desired folder path here.") : 362 407 tr ("Please type the desired file path here.")); 408 409 if (mIsMouseAwaited) 410 { 411 mIsMouseAwaited = false; 412 413 /* Restore the position to the right of dots */ 414 if (diffPos != -1 && curPos >= diffPos + 3) 415 lineEdit()->setCursorPosition (lineEdit()->text().size() - 416 fromRight); 417 /* Restore the position to the center of text */ 418 else if (diffPos != -1 && curPos > diffPos) 419 lineEdit()->setCursorPosition (lineEdit()->text().size() / 2); 420 /* Restore the position to the left of dots */ 421 else 422 lineEdit()->setCursorPosition (curPos); 423 } 363 424 } 364 425 else if (mPath.isNull())
Note:
See TracChangeset
for help on using the changeset viewer.