Changeset 60828 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- May 4, 2016 1:23:50 PM (9 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilePathSelector.cpp
r60827 r60828 53 53 54 54 /** Returns first position of difference between passed strings. */ 55 static int differFrom (const QString &aS1, const QString &aS2)56 { 57 if ( aS1 == aS2)55 static int differFrom(const QString &str1, const QString &str2) 56 { 57 if (str1 == str2) 58 58 return -1; 59 59 60 int minLength = qMin (aS1.size(), aS2.size());61 int i ndex = 0;62 for (i ndex = 0; index < minLength ; ++ index)63 if ( aS1 [index] != aS2 [index])64 break; 65 return i ndex;66 } 67 68 UIFilePathSelector::UIFilePathSelector (QWidget *aParent)69 : QIWithRetranslateUI<QComboBox> (aParent)70 , m CopyAction (new QAction(this))71 , m Mode(Mode_Folder)72 , m HomeDir(QDir::current().absolutePath())73 , m IsEditable(true)74 , m IsEditableMode(false)75 , m IsMouseAwaited(false)76 , m Modified(false)77 { 78 /* Populate items */79 insertItem 80 insertItem 81 insertItem 82 83 /* Attaching known icons */60 int iMinLength = qMin(str1.size(), str2.size()); 61 int iIndex = 0; 62 for (iIndex = 0; iIndex < iMinLength; ++iIndex) 63 if (str1[iIndex] != str2[iIndex]) 64 break; 65 return iIndex; 66 } 67 68 UIFilePathSelector::UIFilePathSelector(QWidget *pParent /* = 0 */) 69 : QIWithRetranslateUI<QComboBox>(pParent) 70 , m_pCopyAction(new QAction(this)) 71 , m_enmMode(Mode_Folder) 72 , m_strHomeDir(QDir::current().absolutePath()) 73 , m_fEditable(true) 74 , m_fEditableMode(false) 75 , m_fMouseAwaited(false) 76 , m_fModified(false) 77 { 78 /* Populate items: */ 79 insertItem(PathId, ""); 80 insertItem(SelectId, ""); 81 insertItem(ResetId, ""); 82 83 /* Attaching known icons: */ 84 84 setItemIcon(SelectId, UIIconPool::iconSet(":/select_file_16px.png")); 85 85 setItemIcon(ResetId, UIIconPool::iconSet(":/eraser_16px.png")); 86 86 87 /* Setup context menu */88 addAction (mCopyAction);89 m CopyAction->setShortcut (QKeySequence(QKeySequence::Copy));90 m CopyAction->setShortcutContext(Qt::WidgetShortcut);91 92 /* Initial Setup*/93 setInsertPolicy 94 setContextMenuPolicy 95 setMinimumWidth 96 97 /* Setup connections */98 connect (this, SIGNAL (activated (int)), this, SLOT (onActivated(int)));99 connect (mCopyAction, SIGNAL (triggered (bool)), this, SLOT(copyToClipboard()));100 101 /* Editable by default */102 setEditable 103 104 /* Applying language settings */87 /* Setup context menu: */ 88 addAction(m_pCopyAction); 89 m_pCopyAction->setShortcut(QKeySequence(QKeySequence::Copy)); 90 m_pCopyAction->setShortcutContext(Qt::WidgetShortcut); 91 92 /* Initial setup: */ 93 setInsertPolicy(QComboBox::NoInsert); 94 setContextMenuPolicy(Qt::ActionsContextMenu); 95 setMinimumWidth(200); 96 97 /* Setup connections: */ 98 connect(this, SIGNAL(activated(int)), this, SLOT(onActivated(int))); 99 connect(m_pCopyAction, SIGNAL(triggered(bool)), this, SLOT(copyToClipboard())); 100 101 /* Editable by default: */ 102 setEditable(true); 103 104 /* Applying language settings: */ 105 105 retranslateUi(); 106 106 } … … 110 110 } 111 111 112 void UIFilePathSelector::setMode (Mode aMode)113 { 114 m Mode = aMode;112 void UIFilePathSelector::setMode(Mode enmMode) 113 { 114 m_enmMode = enmMode; 115 115 } 116 116 117 117 UIFilePathSelector::Mode UIFilePathSelector::mode() const 118 118 { 119 return m Mode;120 } 121 122 void UIFilePathSelector::setEditable (bool aOn)123 { 124 m IsEditable = aOn;125 126 if (m IsEditable)127 { 128 QComboBox::setEditable 129 Assert 130 connect (lineEdit(), SIGNAL (textEdited(const QString &)),131 this, SLOT (onTextEdited(const QString &)));132 133 /* Installing necessary event filters */134 lineEdit()->installEventFilter 119 return m_enmMode; 120 } 121 122 void UIFilePathSelector::setEditable(bool fEditable) 123 { 124 m_fEditable = fEditable; 125 126 if (m_fEditable) 127 { 128 QComboBox::setEditable(true); 129 Assert(lineEdit()); 130 connect(lineEdit(), SIGNAL(textEdited(const QString &)), 131 this, SLOT(onTextEdited(const QString &))); 132 133 /* Installing necessary event filters: */ 134 lineEdit()->installEventFilter(this); 135 135 } 136 136 else … … 138 138 if (lineEdit()) 139 139 { 140 /* Installing necessary event filters */141 lineEdit()->installEventFilter 142 disconnect (lineEdit(), SIGNAL (textEdited(const QString &)),143 this, SLOT (onTextEdited(const QString &)));144 } 145 QComboBox::setEditable 140 /* Installing necessary event filters: */ 141 lineEdit()->installEventFilter(this); 142 disconnect(lineEdit(), SIGNAL(textEdited(const QString &)), 143 this, SLOT(onTextEdited(const QString &))); 144 } 145 QComboBox::setEditable(false); 146 146 } 147 147 } … … 149 149 bool UIFilePathSelector::isEditable() const 150 150 { 151 return m IsEditable;152 } 153 154 void UIFilePathSelector::setResetEnabled (bool aEnabled)155 { 156 if (! aEnabled && count() - 1 == ResetId)157 removeItem 158 else if ( aEnabled && count() - 1 == ResetId - 1)159 { 160 insertItem 151 return m_fEditable; 152 } 153 154 void UIFilePathSelector::setResetEnabled(bool fEnabled) 155 { 156 if (!fEnabled && count() - 1 == ResetId) 157 removeItem(ResetId); 158 else if (fEnabled && count() - 1 == ResetId - 1) 159 { 160 insertItem(ResetId, ""); 161 161 setItemIcon(ResetId, UIIconPool::iconSet(":/eraser_16px.png")); 162 162 } … … 171 171 void UIFilePathSelector::resetModified() 172 172 { 173 m Modified = false;173 m_fModified = false; 174 174 } 175 175 176 176 bool UIFilePathSelector::isModified() const 177 177 { 178 return m Modified;179 } 180 181 void UIFilePathSelector::setFileDialogTitle (const QString& aTitle)182 { 183 m FileDialogTitle = aTitle;178 return m_fModified; 179 } 180 181 void UIFilePathSelector::setFileDialogTitle(const QString& strTitle) 182 { 183 m_strFileDialogTitle = strTitle; 184 184 } 185 185 186 186 QString UIFilePathSelector::fileDialogTitle() const 187 187 { 188 return m FileDialogTitle;189 } 190 191 void UIFilePathSelector::setFile Filters (const QString& aFilters)192 { 193 m FileFilters = aFilters;194 } 195 196 QString UIFilePathSelector::file Filters() const197 { 198 return m FileFilters;199 } 200 201 void UIFilePathSelector::set DefaultSaveExt (const QString &aExt)202 { 203 m DefaultSaveExt = aExt;204 } 205 206 QString UIFilePathSelector:: defaultSaveExt() const207 { 208 return m DefaultSaveExt;188 return m_strFileDialogTitle; 189 } 190 191 void UIFilePathSelector::setFileDialogFilters(const QString& strFilters) 192 { 193 m_strFileDialogFilters = strFilters; 194 } 195 196 QString UIFilePathSelector::fileDialogFilters() const 197 { 198 return m_strFileDialogFilters; 199 } 200 201 void UIFilePathSelector::setFileDialogDefaultSaveExtension(const QString &strDefaultSaveExtension) 202 { 203 m_strFileDialogDefaultSaveExtension = strDefaultSaveExtension; 204 } 205 206 QString UIFilePathSelector::fileDialogDefaultSaveExtension() const 207 { 208 return m_strFileDialogDefaultSaveExtension; 209 209 } 210 210 … … 216 216 QString UIFilePathSelector::path() const 217 217 { 218 return m Path;219 } 220 221 void UIFilePathSelector::setPath (const QString &aPath, bool aRefreshText /* = true */)222 { 223 m Path = aPath.isEmpty() ? QString::null :224 QDir::toNativeSeparators (aPath);225 if ( aRefreshText)218 return m_strPath; 219 } 220 221 void UIFilePathSelector::setPath(const QString &strPath, bool fRefreshText /* = true */) 222 { 223 m_strPath = strPath.isEmpty() ? QString::null : 224 QDir::toNativeSeparators(strPath); 225 if (fRefreshText) 226 226 refreshText(); 227 227 } 228 228 229 void UIFilePathSelector::setHomeDir (const QString &aHomeDir)230 { 231 m HomeDir = aHomeDir;232 } 233 234 void UIFilePathSelector::resizeEvent (QResizeEvent *aEvent)235 { 236 QIWithRetranslateUI<QComboBox>::resizeEvent (aEvent);229 void UIFilePathSelector::setHomeDir(const QString &strHomeDir) 230 { 231 m_strHomeDir = strHomeDir; 232 } 233 234 void UIFilePathSelector::resizeEvent(QResizeEvent *pEvent) 235 { 236 QIWithRetranslateUI<QComboBox>::resizeEvent(pEvent); 237 237 refreshText(); 238 238 } 239 239 240 void UIFilePathSelector::focusInEvent (QFocusEvent *aEvent)240 void UIFilePathSelector::focusInEvent(QFocusEvent *pEvent) 241 241 { 242 242 if (isPathSelected()) 243 243 { 244 if (m IsEditable)245 m IsEditableMode = true;246 if ( aEvent->reason() == Qt::MouseFocusReason)247 m IsMouseAwaited = true;244 if (m_fEditable) 245 m_fEditableMode = true; 246 if (pEvent->reason() == Qt::MouseFocusReason) 247 m_fMouseAwaited = true; 248 248 else 249 249 refreshText(); 250 250 } 251 QIWithRetranslateUI<QComboBox>::focusInEvent (aEvent);252 } 253 254 void UIFilePathSelector::focusOutEvent (QFocusEvent *aEvent)251 QIWithRetranslateUI<QComboBox>::focusInEvent(pEvent); 252 } 253 254 void UIFilePathSelector::focusOutEvent(QFocusEvent *pEvent) 255 255 { 256 256 if (isPathSelected()) 257 257 { 258 m IsEditableMode = false;258 m_fEditableMode = false; 259 259 refreshText(); 260 260 } 261 QIWithRetranslateUI<QComboBox>::focusOutEvent (aEvent);262 } 263 264 bool UIFilePathSelector::eventFilter (QObject *aObj, QEvent *aEv)265 { 266 if (m IsMouseAwaited && (aEv->type() == QEvent::MouseButtonPress))267 QTimer::singleShot (0, this, SLOT(refreshText()));268 269 return QIWithRetranslateUI<QComboBox>::eventFilter (aObj, aEv);261 QIWithRetranslateUI<QComboBox>::focusOutEvent(pEvent); 262 } 263 264 bool UIFilePathSelector::eventFilter(QObject *pObject, QEvent *pEvent) 265 { 266 if (m_fMouseAwaited && (pEvent->type() == QEvent::MouseButtonPress)) 267 QTimer::singleShot(0, this, SLOT(refreshText())); 268 269 return QIWithRetranslateUI<QComboBox>::eventFilter(pObject, pEvent); 270 270 } 271 271 … … 275 275 if (isResetEnabled()) 276 276 { 277 m NoneStr = tr("<reset to default>");278 m NoneTip = tr("The actual default path value will be displayed after "279 "accepting the changes and opening this window again.");277 m_strNoneText = tr("<reset to default>"); 278 m_strNoneToolTip = tr("The actual default path value will be displayed after " 279 "accepting the changes and opening this window again."); 280 280 } 281 281 else 282 282 { 283 m NoneStr = tr("<not selected>");284 m NoneTip = tr("Please use the <b>Other...</b> item from the drop-down "285 "list to select a path.");286 } 287 288 /* Retranslate 'path' item */289 if (m Path.isNull())290 { 291 setItemText (PathId, mNoneStr);292 setItemData (PathId, mNoneTip, Qt::ToolTipRole);293 setToolTip (mNoneTip);294 } 295 296 /* Retranslate 'select' item */297 setItemText (SelectId, tr("Other..."));298 299 /* Retranslate 'reset' item */283 m_strNoneText = tr("<not selected>"); 284 m_strNoneToolTip = tr("Please use the <b>Other...</b> item from the drop-down " 285 "list to select a path."); 286 } 287 288 /* Retranslate 'path' item: */ 289 if (m_strPath.isNull()) 290 { 291 setItemText(PathId, m_strNoneText); 292 setItemData(PathId, m_strNoneToolTip, Qt::ToolTipRole); 293 setToolTip(m_strNoneToolTip); 294 } 295 296 /* Retranslate 'select' item: */ 297 setItemText(SelectId, tr("Other...")); 298 299 /* Retranslate 'reset' item: */ 300 300 if (count() - 1 == ResetId) 301 setItemText (ResetId, tr("Reset"));302 303 /* Set tooltips of the above two items based on the mode */304 switch (m Mode)301 setItemText(ResetId, tr("Reset")); 302 303 /* Set tooltips of the above two items based on the mode: */ 304 switch (m_enmMode) 305 305 { 306 306 case Mode_Folder: 307 setItemData 308 tr("Displays a window to select a different folder."),309 310 setItemData 311 tr("Resets the folder path to the default value."),312 307 setItemData(SelectId, 308 tr("Displays a window to select a different folder."), 309 Qt::ToolTipRole); 310 setItemData(ResetId, 311 tr("Resets the folder path to the default value."), 312 Qt::ToolTipRole); 313 313 break; 314 314 case Mode_File_Open: 315 315 case Mode_File_Save: 316 setItemData 317 tr("Displays a window to select a different file."),318 319 setItemData 320 tr("Resets the file path to the default value."),321 316 setItemData(SelectId, 317 tr("Displays a window to select a different file."), 318 Qt::ToolTipRole); 319 setItemData(ResetId, 320 tr("Resets the file path to the default value."), 321 Qt::ToolTipRole); 322 322 break; 323 323 default: … … 325 325 } 326 326 327 /* Retranslate copy action */328 m CopyAction->setText (tr("&Copy"));329 } 330 331 void UIFilePathSelector::onActivated (int aIndex)332 { 333 switch ( aIndex)327 /* Retranslate copy action: */ 328 m_pCopyAction->setText(tr("&Copy")); 329 } 330 331 void UIFilePathSelector::onActivated(int iIndex) 332 { 333 switch (iIndex) 334 334 { 335 335 case SelectId: … … 340 340 case ResetId: 341 341 { 342 changePath 342 changePath(QString::null); 343 343 break; 344 344 } … … 346 346 break; 347 347 } 348 setCurrentIndex 348 setCurrentIndex(PathId); 349 349 setFocus(); 350 350 } 351 351 352 void UIFilePathSelector::onTextEdited (const QString &aPath)353 { 354 changePath (aPath, false /* refresh text? */);352 void UIFilePathSelector::onTextEdited(const QString &strPath) 353 { 354 changePath(strPath, false /* refresh text? */); 355 355 } 356 356 357 357 void UIFilePathSelector::copyToClipboard() 358 358 { 359 QString text 359 QString text(fullPath()); 360 360 /* Copy the current text to the selection and global clipboard. */ 361 361 if (QApplication::clipboard()->supportsSelection()) 362 QApplication::clipboard()->setText 363 QApplication::clipboard()->setText 364 } 365 366 void UIFilePathSelector::changePath (const QString &aPath,367 bool aRefreshText /* = true */)368 { 369 QString oldPath = mPath;370 setPath (aPath, aRefreshText);371 if (!m Modified && mPath != oldPath)372 m Modified = true;373 emit pathChanged (aPath);362 QApplication::clipboard()->setText(text, QClipboard::Selection); 363 QApplication::clipboard()->setText(text, QClipboard::Clipboard); 364 } 365 366 void UIFilePathSelector::changePath(const QString &strPath, 367 bool fRefreshText /* = true */) 368 { 369 const QString strOldPath = m_strPath; 370 setPath(strPath, fRefreshText); 371 if (!m_fModified && m_strPath != strOldPath) 372 m_fModified = true; 373 emit pathChanged(strPath); 374 374 } 375 375 … … 377 377 { 378 378 /* Preparing initial directory. */ 379 QString initDir = mPath.isNull() ? mHomeDir :380 QIFileDialog::getFirstExistingDir (mPath);381 if ( initDir.isNull())382 initDir = mHomeDir;383 384 QString s elPath;385 switch (m Mode)379 QString strInitDir = m_strPath.isNull() ? m_strHomeDir : 380 QIFileDialog::getFirstExistingDir(m_strPath); 381 if (strInitDir.isNull()) 382 strInitDir = m_strHomeDir; 383 384 QString strSelPath; 385 switch (m_enmMode) 386 386 { 387 387 case Mode_File_Open: 388 s elPath = QIFileDialog::getOpenFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle); break;388 strSelPath = QIFileDialog::getOpenFileName(strInitDir, m_strFileDialogFilters, parentWidget(), m_strFileDialogTitle); break; 389 389 case Mode_File_Save: 390 391 selPath = QIFileDialog::getSaveFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle);392 if (!selPath.isEmpty() && QFileInfo (selPath).suffix().isEmpty())393 selPath = QString ("%1.%2").arg (selPath).arg (mDefaultSaveExt);394 395 390 { 391 strSelPath = QIFileDialog::getSaveFileName(strInitDir, m_strFileDialogFilters, parentWidget(), m_strFileDialogTitle); 392 if (!strSelPath.isEmpty() && QFileInfo(strSelPath).suffix().isEmpty()) 393 strSelPath = QString("%1.%2").arg(strSelPath).arg(m_strFileDialogDefaultSaveExtension); 394 break; 395 } 396 396 case Mode_Folder: 397 s elPath = QIFileDialog::getExistingDirectory (initDir, parentWidget(), mFileDialogTitle); break;398 } 399 400 if (s elPath.isNull())397 strSelPath = QIFileDialog::getExistingDirectory(strInitDir, parentWidget(), m_strFileDialogTitle); break; 398 } 399 400 if (strSelPath.isNull()) 401 401 return; 402 402 403 s elPath.remove (QRegExp("[\\\\/]$"));404 changePath (selPath);403 strSelPath.remove(QRegExp("[\\\\/]$")); 404 changePath(strSelPath); 405 405 } 406 406 407 407 QIcon UIFilePathSelector::defaultIcon() const 408 408 { 409 if (m Mode == Mode_Folder)409 if (m_enmMode == Mode_Folder) 410 410 return vboxGlobal().icon(QFileIconProvider::Folder); 411 411 else … … 413 413 } 414 414 415 QString UIFilePathSelector::fullPath (bool aAbsolute /* = true */) const416 { 417 if (m Path.isNull())418 return m Path;419 420 QString result;421 switch (m Mode)415 QString UIFilePathSelector::fullPath(bool fAbsolute /* = true */) const 416 { 417 if (m_strPath.isNull()) 418 return m_strPath; 419 420 QString strResult; 421 switch (m_enmMode) 422 422 { 423 423 case Mode_Folder: 424 result = aAbsolute ? QDir (mPath).absolutePath() :425 QDir (mPath).path();424 strResult = fAbsolute ? QDir(m_strPath).absolutePath() : 425 QDir(m_strPath).path(); 426 426 break; 427 427 case Mode_File_Open: 428 428 case Mode_File_Save: 429 result = aAbsolute ? QFileInfo (mPath).absoluteFilePath() :430 QFileInfo (mPath).filePath();429 strResult = fAbsolute ? QFileInfo(m_strPath).absoluteFilePath() : 430 QFileInfo(m_strPath).filePath(); 431 431 break; 432 432 default: 433 433 AssertFailedBreak(); 434 434 } 435 return QDir::toNativeSeparators (result);436 } 437 438 QString UIFilePathSelector::shrinkText (int aWidth) const439 { 440 QString fullText (fullPath(false));441 if ( fullText.isEmpty())442 return fullText;443 444 int oldSize = fontMetrics().width (fullText);445 int i ndentSize = fontMetrics().width("x...x");446 447 /* Compress text */448 int start = 0;449 int finish = 0;450 int position = 0;451 int textWidth = 0;435 return QDir::toNativeSeparators(strResult); 436 } 437 438 QString UIFilePathSelector::shrinkText(int iWidth) const 439 { 440 QString strFullText(fullPath(false)); 441 if (strFullText.isEmpty()) 442 return strFullText; 443 444 int iOldSize = fontMetrics().width(strFullText); 445 int iIndentSize = fontMetrics().width("x...x"); 446 447 /* Compress text: */ 448 int iStart = 0; 449 int iFinish = 0; 450 int iPosition = 0; 451 int iTextWidth = 0; 452 452 do { 453 textWidth = fontMetrics().width (fullText);454 if ( textWidth + indentSize > aWidth)455 { 456 start = 0;457 finish = fullText.length();458 459 /* Selecting remove position */460 QRegExp regExp 461 int newFinish = regExp.indexIn (fullText);462 if ( newFinish != -1)463 finish = newFinish;464 position = (finish - start) / 2;465 466 if ( position == finish)453 iTextWidth = fontMetrics().width(strFullText); 454 if (iTextWidth + iIndentSize > iWidth) 455 { 456 iStart = 0; 457 iFinish = strFullText.length(); 458 459 /* Selecting remove position: */ 460 QRegExp regExp("([\\\\/][^\\\\^/]+[\\\\/]?$)"); 461 int iNewFinish = regExp.indexIn(strFullText); 462 if (iNewFinish != -1) 463 iFinish = iNewFinish; 464 iPosition = (iFinish - iStart) / 2; 465 466 if (iPosition == iFinish) 467 467 break; 468 468 469 fullText.remove (position, 1);470 } 471 } while ( textWidth + indentSize > aWidth);472 473 fullText.insert (position, "...");474 int newSize = fontMetrics().width (fullText);475 476 return newSize < oldSize ? fullText : fullPath(false);469 strFullText.remove(iPosition, 1); 470 } 471 } while (iTextWidth + iIndentSize > iWidth); 472 473 strFullText.insert(iPosition, "..."); 474 int newSize = fontMetrics().width(strFullText); 475 476 return newSize < iOldSize ? strFullText : fullPath(false); 477 477 } 478 478 479 479 void UIFilePathSelector::refreshText() 480 480 { 481 if (m IsEditable && mIsEditableMode)482 { 483 /* Cursor positioning variables */484 int curPos = -1;485 int diffPos = -1;486 int fromRight = -1;487 488 if (m IsMouseAwaited)489 { 490 /* Store the cursor position */491 curPos = lineEdit()->cursorPosition();492 diffPos = differFrom (lineEdit()->text(), mPath);493 fromRight = lineEdit()->text().size() - curPos;481 if (m_fEditable && m_fEditableMode) 482 { 483 /* Cursor positioning variables: */ 484 int iCurPos = -1; 485 int iDiffPos = -1; 486 int iFromRight = -1; 487 488 if (m_fMouseAwaited) 489 { 490 /* Store the cursor position: */ 491 iCurPos = lineEdit()->cursorPosition(); 492 iDiffPos = differFrom(lineEdit()->text(), m_strPath); 493 iFromRight = lineEdit()->text().size() - iCurPos; 494 494 } 495 495 … … 497 497 * and text have be corresponding real stored path 498 498 * which can be absolute or relative. */ 499 if (lineEdit()->text() != m Path)500 setItemText (PathId, mPath);501 setItemIcon 502 setToolTip (mMode == Mode_Folder ?503 tr("Holds the folder path.") :504 tr("Holds the file path."));505 506 if (m IsMouseAwaited)507 { 508 m IsMouseAwaited = false;509 510 /* Restore the position to the right of dots */511 if ( diffPos != -1 && curPos >= diffPos + 3)512 lineEdit()->setCursorPosition 513 fromRight);514 /* Restore the position to the center of text */515 else if ( diffPos != -1 && curPos > diffPos)516 lineEdit()->setCursorPosition 517 /* Restore the position to the left of dots */499 if (lineEdit()->text() != m_strPath) 500 setItemText(PathId, m_strPath); 501 setItemIcon(PathId, QIcon()); 502 setToolTip(m_enmMode == Mode_Folder ? 503 tr("Holds the folder path.") : 504 tr("Holds the file path.")); 505 506 if (m_fMouseAwaited) 507 { 508 m_fMouseAwaited = false; 509 510 /* Restore the position to the right of dots: */ 511 if (iDiffPos != -1 && iCurPos >= iDiffPos + 3) 512 lineEdit()->setCursorPosition(lineEdit()->text().size() - 513 iFromRight); 514 /* Restore the position to the center of text: */ 515 else if (iDiffPos != -1 && iCurPos > iDiffPos) 516 lineEdit()->setCursorPosition(lineEdit()->text().size() / 2); 517 /* Restore the position to the left of dots: */ 518 518 else 519 lineEdit()->setCursorPosition (curPos);520 } 521 } 522 else if (m Path.isNull())519 lineEdit()->setCursorPosition(iCurPos); 520 } 521 } 522 else if (m_strPath.isNull()) 523 523 { 524 524 /* If we are not in editable mode and no path is 525 525 * stored here - show the translated 'none' string. */ 526 if (itemText (PathId) != mNoneStr)527 { 528 setItemText (PathId, mNoneStr);529 setItemIcon 530 setItemData (PathId, mNoneTip, Qt::ToolTipRole);531 setToolTip (mNoneTip);526 if (itemText(PathId) != m_strNoneText) 527 { 528 setItemText(PathId, m_strNoneText); 529 setItemIcon(PathId, QIcon()); 530 setItemData(PathId, m_strNoneToolTip, Qt::ToolTipRole); 531 setToolTip(m_strNoneToolTip); 532 532 } 533 533 } 534 534 else 535 535 { 536 /* Compress text in combobox */536 /* Compress text in combobox: */ 537 537 QStyleOptionComboBox options; 538 options.initFrom 539 QRect rect = QApplication::style()->subControlRect 538 options.initFrom(this); 539 QRect rect = QApplication::style()->subControlRect( 540 540 QStyle::CC_ComboBox, &options, QStyle::SC_ComboBoxEditField); 541 setItemText (PathId, shrinkText(rect.width() - iconSize().width()));542 543 /* Attach corresponding icon */544 setItemIcon (PathId, QFileInfo (mPath).exists() ?545 vboxGlobal().icon(QFileInfo (mPath)) :546 547 548 /* Set the tooltip */549 setToolTip 550 setItemData 551 } 552 } 553 541 setItemText(PathId, shrinkText(rect.width() - iconSize().width())); 542 543 /* Attach corresponding icon: */ 544 setItemIcon(PathId, QFileInfo(m_strPath).exists() ? 545 vboxGlobal().icon(QFileInfo(m_strPath)) : 546 defaultIcon()); 547 548 /* Set the tooltip: */ 549 setToolTip(fullPath()); 550 setItemData(PathId, toolTip(), Qt::ToolTipRole); 551 } 552 } 553 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilePathSelector.h
r60827 r60828 49 49 }; 50 50 51 /** Constructs file-path selector passing @a aParent to QComboBox base-class. */52 UIFilePathSelector (QWidget *aParent);51 /** Constructs file-path selector passing @a pParent to QComboBox base-class. */ 52 UIFilePathSelector(QWidget *pParent = 0); 53 53 /** Destructs file-path selector. */ 54 ~UIFilePathSelector();54 ~UIFilePathSelector(); 55 55 56 /** Defines the @a aMode to operate in. */57 void setMode (Mode aMode);56 /** Defines the @a enmMode to operate in. */ 57 void setMode(Mode enmMode); 58 58 /** Returns the mode to operate in. */ 59 59 Mode mode() const; 60 60 61 /** Defines whether the p ossibility to edit the path is @a aOn. */62 void setEditable (bool aOn);61 /** Defines whether the path is @a fEditable. */ 62 void setEditable(bool fEditable); 63 63 /** Returns whether the path is editable. */ 64 64 bool isEditable() const; 65 65 66 /** Defines whether the reseting to defauilt path is @a aEnabled. */67 void setResetEnabled (bool aEnabled);66 /** Defines whether the reseting to defauilt path is @a fEnabled. */ 67 void setResetEnabled(bool fEnabled); 68 68 /** Returns whether the reseting to defauilt path is enabled. */ 69 bool isResetEnabled 69 bool isResetEnabled() const; 70 70 71 /** Defines the file-dialog @a aTitle. */72 void setFileDialogTitle (const QString& aTitle);71 /** Defines the file-dialog @a strTitle. */ 72 void setFileDialogTitle(const QString &strTitle); 73 73 /** Returns the file-dialog title. */ 74 74 QString fileDialogTitle() const; 75 75 76 /** Defines the file-dialog @a aFilters. */77 void setFile Filters (const QString& aFilters);76 /** Defines the file-dialog @a strFilters. */ 77 void setFileDialogFilters(const QString &strFilters); 78 78 /** Returns the file-dialog filters. */ 79 QString file Filters() const;79 QString fileDialogFilters() const; 80 80 81 /** Defines the file-dialog default save @a aExt. */82 void set DefaultSaveExt (const QString &aExt);81 /** Defines the file-dialog @a strDefaultSaveExtension. */ 82 void setFileDialogDefaultSaveExtension(const QString &strDefaultSaveExtension); 83 83 /** Returns the file-dialog default save extension. */ 84 QString defaultSaveExt() const;84 QString fileDialogDefaultSaveExtension() const; 85 85 86 86 /** Resets path modified state to false. */ … … 96 96 signals: 97 97 98 /** Notify listeners about path changed. */99 void pathChanged (const QString &);98 /** Notify listeners about @a strPath changed. */ 99 void pathChanged(const QString &strPath); 100 100 101 101 public slots: 102 102 103 /** Defines the @a aPath and @a aRefreshText after that. */104 void setPath (const QString &aPath, bool aRefreshText = true);103 /** Defines the @a strPath and @a fRefreshText after that. */ 104 void setPath(const QString &strPath, bool fRefreshText = true); 105 105 106 /** Defines the @a aHomeDir. */107 void setHomeDir (const QString &aHomeDir);106 /** Defines the @a strHomeDir. */ 107 void setHomeDir(const QString &strHomeDir); 108 108 109 109 protected: 110 110 111 /** Handles resize @a aEvent. */112 void resizeEvent (QResizeEvent *aEvent);111 /** Handles resize @a pEvent. */ 112 void resizeEvent(QResizeEvent *pEvent); 113 113 114 /** Handles focus-in @a aEvent. */115 void focusInEvent (QFocusEvent *aEvent);116 /** Handles focus-out @a aEvent. */117 void focusOutEvent (QFocusEvent *aEvent);114 /** Handles focus-in @a pEvent. */ 115 void focusInEvent(QFocusEvent *pEvent); 116 /** Handles focus-out @a pEvent. */ 117 void focusOutEvent(QFocusEvent *pEvent); 118 118 119 /** Preprocesses every @a aEv sent to @a aObj. */120 bool eventFilter (QObject *aObj, QEvent *aEv);119 /** Preprocesses every @a pEvent sent to @a pObject. */ 120 bool eventFilter(QObject *pObject, QEvent *pEvent); 121 121 122 122 /** Handles translation event. */ … … 125 125 private slots: 126 126 127 /** Handles combo-box activation. */128 void onActivated (int aIndex);127 /** Handles combo-box @a iIndex activation. */ 128 void onActivated(int iIndex); 129 129 130 /** Handles combo-box text editing. */131 void onTextEdited (const QString &aPath);130 /** Handles combo-box @a strText editing. */ 131 void onTextEdited(const QString &strText); 132 132 133 133 /** Handles combo-box text copying. */ … … 139 139 private: 140 140 141 /** Provokes change to @a aPath and @a aRefreshText after that. */142 void changePath (const QString &aPath, bool aRefreshText = true);141 /** Provokes change to @a strPath and @a fRefreshText after that. */ 142 void changePath(const QString &strPath, bool fRefreshText = true); 143 143 144 144 /** Call for file-dialog to choose path. */ … … 148 148 QIcon defaultIcon() const; 149 149 150 /** Returns full path @a aAbsolute if necessary. */151 QString fullPath (bool aAbsolute = true) const;150 /** Returns full path @a fAbsolute if necessary. */ 151 QString fullPath(bool fAbsolute = true) const; 152 152 153 /** Shrinks the reflected text to @a aWidth pixels. */154 QString shrinkText (int aWidth) const;153 /** Shrinks the reflected text to @a iWidth pixels. */ 154 QString shrinkText(int iWidth) const; 155 155 156 156 /** Holds the copy action instance. */ 157 QAction *m CopyAction;157 QAction *m_pCopyAction; 158 158 159 159 /** Holds the mode to operate in. */ 160 Mode mMode;160 Mode m_enmMode; 161 161 162 162 /** Holds the path. */ 163 QString mPath;164 /** Holds the home dir ectory. */165 QString mHomeDir;163 QString m_strPath; 164 /** Holds the home dir. */ 165 QString m_strHomeDir; 166 166 167 167 /** Holds the file-dialog filters. */ 168 QString mFileFilters;168 QString m_strFileDialogFilters; 169 169 /** Holds the file-dialog default save extension. */ 170 QString mDefaultSaveExt;170 QString m_strFileDialogDefaultSaveExtension; 171 171 /** Holds the file-dialog title. */ 172 QString mFileDialogTitle;172 QString m_strFileDialogTitle; 173 173 174 174 /** Holds the cached text for empty path. */ 175 QString mNoneStr;175 QString m_strNoneText; 176 176 /** Holds the cached tool-tip for empty path. */ 177 QString mNoneTip;177 QString m_strNoneToolTip; 178 178 179 179 /** Holds whether the path is editable. */ 180 bool mIsEditable;180 bool m_fEditable; 181 181 182 182 /** Holds whether we are in editable mode. */ 183 bool mIsEditableMode;183 bool m_fEditableMode; 184 184 /** Holds whether we are expecting mouse events. */ 185 bool mIsMouseAwaited;185 bool m_fMouseAwaited; 186 186 187 187 /** Holds whether the path is modified. */ 188 bool mModified;188 bool m_fModified; 189 189 }; 190 190
Note:
See TracChangeset
for help on using the changeset viewer.