Changeset 100210 in vbox
- Timestamp:
- Jun 19, 2023 2:39:07 PM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp
r100082 r100210 30 30 #include <QComboBox> 31 31 #include <QCheckBox> 32 #include <QDir> 32 33 #include <QHBoxLayout> 33 34 #include <QHeaderView> … … 86 87 *********************************************************************************************************************************/ 87 88 /** A QLabel extension. It shows the current path as text and hightligts the folder name 88 * as the mouse hovers over it. Clicking on the highlighted folder name make the file table t p89 * as the mouse hovers over it. Clicking on the highlighted folder name make the file table to 89 90 * navigate to that folder. */ 90 91 class UIFileManagerBreadCrumbs : public QLabel … … 128 129 void reset(); 129 130 void setPathSeparator(const QChar &separator); 131 bool eventFilter(QObject *pObject, QEvent *pEvent) override; 130 132 131 133 private slots: 132 133 134 void sltHandleSwitch(); 134 135 /* Makes sure that we switch to breadcrumbs widget as soon as the combo box popup is hidden. */ 135 136 void sltHandleHidePopup(); 136 137 void sltHandlePathChange(const QString &strPath); 138 void sltAddressLineEdited(); 137 139 138 140 private: 141 142 enum StackedWidgets 143 { 144 StackedWidgets_History = 0, 145 StackedWidgets_BreadCrumbs, 146 StackedWidgets_AddressLine 147 }; 139 148 140 149 void prepare(); … … 143 152 UIFileManagerBreadCrumbs *m_pBreadCrumbs; 144 153 UIFileManagerHistoryComboBox *m_pHistoryComboBox; 154 QLineEdit *m_pAddressLineEdit; 145 155 QToolButton *m_pSwitchButton; 146 156 QChar m_pathSeparator; 157 /* With non-native separators. */ 158 QString m_strCurrentPath; 147 159 }; 148 160 … … 271 283 , m_pBreadCrumbs(0) 272 284 , m_pHistoryComboBox(0) 285 , m_pAddressLineEdit(0) 273 286 , m_pSwitchButton(0) 274 287 , m_pathSeparator('/') … … 279 292 void UIFileManagerNavigationWidget::setPath(const QString &strLocation) 280 293 { 294 if (m_strCurrentPath == QDir::fromNativeSeparators(strLocation)) 295 return; 296 297 m_strCurrentPath = QDir::fromNativeSeparators(strLocation); 298 281 299 if (m_pBreadCrumbs) 282 300 m_pBreadCrumbs->setPath(strLocation); … … 330 348 m_pBreadCrumbs = new UIFileManagerBreadCrumbs; 331 349 m_pHistoryComboBox = new UIFileManagerHistoryComboBox; 332 350 m_pAddressLineEdit = new QLineEdit; 333 351 if (m_pBreadCrumbs && m_pHistoryComboBox) 334 352 { 335 353 m_pBreadCrumbs->setIndent(0.5 * qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin)); 354 m_pBreadCrumbs->installEventFilter(this); 355 m_pAddressLineEdit->installEventFilter(this); 336 356 connect(m_pBreadCrumbs, &UIFileManagerBreadCrumbs::linkActivated, 337 357 this, &UIFileManagerNavigationWidget::sltHandlePathChange); … … 340 360 connect(m_pHistoryComboBox, &UIFileManagerHistoryComboBox::currentTextChanged, 341 361 this, &UIFileManagerNavigationWidget::sltHandlePathChange); 342 343 m_pContainer->addWidget(m_pBreadCrumbs); 344 m_pContainer->addWidget(m_pHistoryComboBox); 345 m_pContainer->setCurrentIndex(0); 362 connect(m_pAddressLineEdit, &QLineEdit::returnPressed, 363 this, &UIFileManagerNavigationWidget::sltAddressLineEdited); 364 m_pContainer->insertWidget(StackedWidgets_BreadCrumbs, m_pBreadCrumbs); 365 m_pContainer->insertWidget(StackedWidgets_History, m_pHistoryComboBox); 366 m_pContainer->insertWidget(StackedWidgets_AddressLine, m_pAddressLineEdit); 367 m_pContainer->setCurrentIndex(StackedWidgets_BreadCrumbs); 346 368 } 347 369 pLayout->addWidget(m_pContainer); … … 365 387 } 366 388 389 bool UIFileManagerNavigationWidget::eventFilter(QObject *pObject, QEvent *pEvent) 390 { 391 if (pObject == m_pBreadCrumbs && pEvent && pEvent->type() == QEvent::MouseButtonDblClick) 392 { 393 m_pContainer->setCurrentIndex(StackedWidgets_AddressLine); 394 m_pAddressLineEdit->setText(QDir::toNativeSeparators(m_strCurrentPath)); 395 m_pAddressLineEdit->setFocus(); 396 397 } 398 else if(pObject == m_pAddressLineEdit && pEvent && pEvent->type() == QEvent::FocusOut) 399 m_pContainer->setCurrentIndex(StackedWidgets_BreadCrumbs); 400 401 return QWidget::eventFilter(pObject, pEvent); 402 } 403 367 404 void UIFileManagerNavigationWidget::sltHandleHidePopup() 368 405 { 369 m_pContainer->setCurrentIndex( 0);406 m_pContainer->setCurrentIndex(StackedWidgets_BreadCrumbs); 370 407 } 371 408 372 409 void UIFileManagerNavigationWidget::sltHandlePathChange(const QString &strPath) 373 410 { 374 QString strNonNativePath(strPath); 375 strNonNativePath.replace(m_pathSeparator, '/'); 376 emit sigPathChanged(strNonNativePath); 411 emit sigPathChanged(QDir::fromNativeSeparators(strPath)); 377 412 } 378 413 379 414 void UIFileManagerNavigationWidget::sltHandleSwitch() 380 415 { 381 if (m_pContainer->currentIndex() == 0)382 { 383 m_pContainer->setCurrentIndex( 1);416 if (m_pContainer->currentIndex() == StackedWidgets_BreadCrumbs) 417 { 418 m_pContainer->setCurrentIndex(StackedWidgets_History); 384 419 m_pHistoryComboBox->showPopup(); 385 420 } 386 421 else 387 422 { 388 m_pContainer->setCurrentIndex( 0);423 m_pContainer->setCurrentIndex(StackedWidgets_BreadCrumbs); 389 424 m_pHistoryComboBox->hidePopup(); 390 425 } 426 } 427 428 void UIFileManagerNavigationWidget::sltAddressLineEdited() 429 { 430 sigPathChanged(QDir::fromNativeSeparators(m_pAddressLineEdit->text())); 391 431 } 392 432
Note:
See TracChangeset
for help on using the changeset viewer.