VirtualBox

Changeset 100210 in vbox


Ignore:
Timestamp:
Jun 19, 2023 2:39:07 PM (18 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. Now the address bar of the file table can be edited.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r100082 r100210  
    3030#include <QComboBox>
    3131#include <QCheckBox>
     32#include <QDir>
    3233#include <QHBoxLayout>
    3334#include <QHeaderView>
     
    8687*********************************************************************************************************************************/
    8788/** 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 tp
     89  *  as the mouse hovers over it. Clicking on the highlighted folder name make the file table to
    8990  *  navigate to that folder. */
    9091class UIFileManagerBreadCrumbs : public QLabel
     
    128129    void reset();
    129130    void setPathSeparator(const QChar &separator);
     131    bool eventFilter(QObject *pObject, QEvent *pEvent) override;
    130132
    131133private slots:
    132 
    133134    void sltHandleSwitch();
    134135    /* Makes sure that we switch to breadcrumbs widget as soon as the combo box popup is hidden. */
    135136    void sltHandleHidePopup();
    136137    void sltHandlePathChange(const QString &strPath);
     138    void sltAddressLineEdited();
    137139
    138140private:
     141
     142    enum StackedWidgets
     143    {
     144        StackedWidgets_History = 0,
     145        StackedWidgets_BreadCrumbs,
     146        StackedWidgets_AddressLine
     147    };
    139148
    140149    void prepare();
     
    143152    UIFileManagerBreadCrumbs     *m_pBreadCrumbs;
    144153    UIFileManagerHistoryComboBox *m_pHistoryComboBox;
     154    QLineEdit                    *m_pAddressLineEdit;
    145155    QToolButton                  *m_pSwitchButton;
    146156    QChar                         m_pathSeparator;
     157    /* With non-native separators. */
     158    QString                       m_strCurrentPath;
    147159};
    148160
     
    271283    , m_pBreadCrumbs(0)
    272284    , m_pHistoryComboBox(0)
     285    , m_pAddressLineEdit(0)
    273286    , m_pSwitchButton(0)
    274287    , m_pathSeparator('/')
     
    279292void UIFileManagerNavigationWidget::setPath(const QString &strLocation)
    280293{
     294    if (m_strCurrentPath == QDir::fromNativeSeparators(strLocation))
     295        return;
     296
     297    m_strCurrentPath = QDir::fromNativeSeparators(strLocation);
     298
    281299    if (m_pBreadCrumbs)
    282300        m_pBreadCrumbs->setPath(strLocation);
     
    330348        m_pBreadCrumbs = new UIFileManagerBreadCrumbs;
    331349        m_pHistoryComboBox = new UIFileManagerHistoryComboBox;
    332 
     350        m_pAddressLineEdit = new QLineEdit;
    333351        if (m_pBreadCrumbs && m_pHistoryComboBox)
    334352        {
    335353            m_pBreadCrumbs->setIndent(0.5 * qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin));
     354            m_pBreadCrumbs->installEventFilter(this);
     355            m_pAddressLineEdit->installEventFilter(this);
    336356            connect(m_pBreadCrumbs, &UIFileManagerBreadCrumbs::linkActivated,
    337357                    this, &UIFileManagerNavigationWidget::sltHandlePathChange);
     
    340360            connect(m_pHistoryComboBox, &UIFileManagerHistoryComboBox::currentTextChanged,
    341361                    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);
    346368        }
    347369        pLayout->addWidget(m_pContainer);
     
    365387}
    366388
     389bool 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
    367404void UIFileManagerNavigationWidget::sltHandleHidePopup()
    368405{
    369     m_pContainer->setCurrentIndex(0);
     406    m_pContainer->setCurrentIndex(StackedWidgets_BreadCrumbs);
    370407}
    371408
    372409void UIFileManagerNavigationWidget::sltHandlePathChange(const QString &strPath)
    373410{
    374     QString strNonNativePath(strPath);
    375     strNonNativePath.replace(m_pathSeparator, '/');
    376     emit sigPathChanged(strNonNativePath);
     411    emit sigPathChanged(QDir::fromNativeSeparators(strPath));
    377412}
    378413
    379414void UIFileManagerNavigationWidget::sltHandleSwitch()
    380415{
    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);
    384419        m_pHistoryComboBox->showPopup();
    385420    }
    386421    else
    387422    {
    388         m_pContainer->setCurrentIndex(0);
     423        m_pContainer->setCurrentIndex(StackedWidgets_BreadCrumbs);
    389424        m_pHistoryComboBox->hidePopup();
    390425    }
     426}
     427
     428void UIFileManagerNavigationWidget::sltAddressLineEdited()
     429{
     430    sigPathChanged(QDir::fromNativeSeparators(m_pAddressLineEdit->text()));
    391431}
    392432
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette