VirtualBox

Changeset 77932 in vbox


Ignore:
Timestamp:
Mar 28, 2019 10:17:11 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. Adding a simple breadcrumbs navigation widget to the file manager.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.cpp

    r77377 r77932  
    207207const char *UIExtraDataDefs::GUI_GuestControl_FileManagerShowHumanReadableSizes = "ShowHumanReadableSizes";
    208208const char *UIExtraDataDefs::GUI_GuestControl_FileManagerShowHiddenObjects = "ShowHiddenObjects";
     209const char *UIExtraDataDefs::GUI_GuestControl_FileManagerShowBreadCrumbs = "ShowBreadCrumbs";
    209210
    210211/* Virtual Machine: Close dialog: */
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataDefs.h

    r77822 r77932  
    383383        extern const char *GUI_GuestControl_FileManagerShowHumanReadableSizes;
    384384        extern const char *GUI_GuestControl_FileManagerShowHiddenObjects;
     385        extern const char *GUI_GuestControl_FileManagerShowBreadCrumbs;
    385386    /** @} */
    386387
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r77845 r77932  
    42744274                                               bool fShowDeleteConfirmation,
    42754275                                               bool fShowHumanReadableSizes,
    4276                                                bool fShowHiddenObjects)
     4276                                               bool fShowHiddenObjects,
     4277                                               bool fShowBreadCrumbs)
    42774278{
    42784279    /* Serialize passed values: */
     
    42874288    if (fShowHiddenObjects)
    42884289        data << GUI_GuestControl_FileManagerShowHiddenObjects;
     4290    if (fShowBreadCrumbs)
     4291        data << GUI_GuestControl_FileManagerShowBreadCrumbs;
     4292
    42894293    /* Re-cache corresponding extra-data: */
    42904294    setExtraDataStringList(GUI_GuestControl_FileManagerOptions, data);
     
    43304334    {
    43314335        if (data[i] == GUI_GuestControl_FileManagerShowHiddenObjects)
     4336            return true;
     4337    }
     4338    return false;
     4339}
     4340
     4341bool UIExtraDataManager::fileManagerShowBreadCrumbs()
     4342{
     4343    const QStringList data = extraDataStringList(GUI_GuestControl_FileManagerOptions);
     4344    for (int i = 0; i < data.size(); ++i)
     4345    {
     4346        if (data[i] == GUI_GuestControl_FileManagerShowBreadCrumbs)
    43324347            return true;
    43334348    }
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r77845 r77932  
    670670                                   bool fShowDeleteConfirmation,
    671671                                   bool fshowHumanReadableSizes,
    672                                    bool fShowHiddenObjects);
     672                                   bool fShowHiddenObjects,
     673                                   bool fShowBreadCrumbs);
    673674        bool fileManagerListDirectoriesFirst();
    674675        bool fileManagerShowDeleteConfirmation();
    675676        bool fileManagerShowHumanReadableSizes();
    676677        bool fileManagerShowHiddenObjects();
     678        bool fileManagerShowBreadCrumbs();
    677679    /** @} */
    678680
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManager.cpp

    r77870 r77932  
    9494    , fShowHumanReadableSizes(true)
    9595    , fShowHiddenObjects(true)
     96    , fShowBreadCrumbs(false)
    9697{
    9798}
     
    690691                                             pOptions->fAskDeleteConfirmation,
    691692                                             pOptions->fShowHumanReadableSizes,
    692                                              pOptions->fShowHiddenObjects);
     693                                             pOptions->fShowHiddenObjects,
     694                                             pOptions->fShowBreadCrumbs);
    693695    }
    694696}
     
    733735        pOptions->fShowHumanReadableSizes = gEDataManager->fileManagerShowHumanReadableSizes();
    734736        pOptions->fShowHiddenObjects = gEDataManager->fileManagerShowHiddenObjects();
     737        pOptions->fShowBreadCrumbs = gEDataManager->fileManagerShowBreadCrumbs();
    735738    }
    736739}
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManager.h

    r77528 r77932  
    6868    bool fShowHumanReadableSizes;
    6969    bool fShowHiddenObjects;
     70    bool fShowBreadCrumbs;
    7071
    7172private:
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerGuestTable.cpp

    r77647 r77932  
    164164{
    165165    if (m_pLocationLabel)
    166         m_pLocationLabel->setText(UIFileManager::tr("Guest System"));
     166        m_pLocationLabel->setText(UIFileManager::tr("Guest File System"));
    167167    UIFileManagerTable::retranslateUi();
    168168}
     
    170170void UIFileManagerGuestTable::readDirectory(const QString& strPath,
    171171                                     UICustomFileSystemItem *parent, bool isStartDir /*= false*/)
    172 
    173172{
    174173    if (!parent)
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerHostTable.cpp

    r77871 r77932  
    172172{
    173173    if (m_pLocationLabel)
    174         m_pLocationLabel->setText(UIFileManager::tr("Host System"));
     174        m_pLocationLabel->setText(UIFileManager::tr("Host File System"));
    175175    UIFileManagerTable::retranslateUi();
    176176}
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerOptionsPanel.cpp

    r77528 r77932  
    3131    , m_pHumanReabableSizesCheckBox(0)
    3232    , m_pShowHiddenObjectsCheckBox(0)
     33    , m_pShowBreadCrumbsCheckBox(0)
    3334    , m_pFileManagerOptions(pFileManagerOptions)
    3435{
     
    8283    m_pListDirectoriesOnTopCheckBox = new QCheckBox;
    8384    if (m_pListDirectoriesOnTopCheckBox)
    84     {
    8585        mainLayout()->addWidget(m_pListDirectoriesOnTopCheckBox, 0, Qt::AlignLeft);
    86     }
    8786
    8887    m_pDeleteConfirmationCheckBox = new QCheckBox;
    8988    if (m_pDeleteConfirmationCheckBox)
    90     {
    9189        mainLayout()->addWidget(m_pDeleteConfirmationCheckBox, 0, Qt::AlignLeft);
    92     }
    9390
    9491    m_pHumanReabableSizesCheckBox = new QCheckBox;
    9592    if (m_pHumanReabableSizesCheckBox)
    96     {
    9793        mainLayout()->addWidget(m_pHumanReabableSizesCheckBox, 0, Qt::AlignLeft);
    98     }
    9994
    10095    m_pShowHiddenObjectsCheckBox = new QCheckBox;
    10196    if (m_pShowHiddenObjectsCheckBox)
    102     {
    10397        mainLayout()->addWidget(m_pShowHiddenObjectsCheckBox, 0, Qt::AlignLeft);
    104     }
     98
     99    m_pShowBreadCrumbsCheckBox = new QCheckBox;
     100    if (m_pShowBreadCrumbsCheckBox)
     101        mainLayout()->addWidget(m_pShowBreadCrumbsCheckBox, 0, Qt::AlignLeft);
    105102
    106103    /* Set initial checkbox status wrt. options: */
     
    115112        if (m_pShowHiddenObjectsCheckBox)
    116113            m_pShowHiddenObjectsCheckBox->setChecked(m_pFileManagerOptions->fShowHiddenObjects);
     114        if (m_pShowBreadCrumbsCheckBox)
     115            m_pShowBreadCrumbsCheckBox->setChecked(m_pFileManagerOptions->fShowBreadCrumbs);
    117116
    118117    }
     
    153152}
    154153
     154void UIFileManagerOptionsPanel::sltShowBreadCrumbsCheckBoxToggled(bool bChecked)
     155{
     156    if (!m_pFileManagerOptions)
     157        return;
     158    m_pFileManagerOptions->fShowBreadCrumbs = bChecked;
     159    emit sigOptionsChanged();
     160}
     161
    155162void UIFileManagerOptionsPanel::prepareConnections()
    156163{
     
    169176                this, &UIFileManagerOptionsPanel::sltShowHiddenObjectsCheckBoxToggled);
    170177
     178    if (m_pShowBreadCrumbsCheckBox)
     179        connect(m_pShowBreadCrumbsCheckBox, &QCheckBox::toggled,
     180                this, &UIFileManagerOptionsPanel::sltShowBreadCrumbsCheckBoxToggled);
    171181}
    172182
     
    199209        m_pShowHiddenObjectsCheckBox->setToolTip(UIFileManager::tr("Show hidden files/directories"));
    200210    }
    201 }
     211
     212    if (m_pShowBreadCrumbsCheckBox)
     213    {
     214        m_pShowBreadCrumbsCheckBox->setText(UIFileManager::tr("Bread crumbs instead of location widget"));
     215        m_pShowBreadCrumbsCheckBox->setToolTip(UIFileManager::tr("Bread crumbs instead of location widget"));
     216    }
     217}
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerOptionsPanel.h

    r77528 r77932  
    6363    void sltHumanReabableSizesCheckBoxToogled(bool bChecked);
    6464    void sltShowHiddenObjectsCheckBoxToggled(bool bChecked);
     65    void sltShowBreadCrumbsCheckBoxToggled(bool bChecked);
    6566
    6667private:
     
    7071    QCheckBox  *m_pHumanReabableSizesCheckBox;
    7172    QCheckBox  *m_pShowHiddenObjectsCheckBox;
     73    QCheckBox  *m_pShowBreadCrumbsCheckBox;
    7274    UIFileManagerOptions *m_pFileManagerOptions;
    7375};
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp

    r77904 r77932  
    3030#include "QILabel.h"
    3131#include "QILineEdit.h"
     32#include "QIToolButton.h"
    3233#include "VBoxGlobal.h"
    3334#include "UIActionPool.h"
     
    4950
    5051/*********************************************************************************************************************************
     52*   UIFileManagerBreadCrumbs definition.                                                                                         *
     53*********************************************************************************************************************************/
     54/** A QLineEdit extension. It shows the current path as text and hightligts the folder name
     55  *  as the mouse hovers over it. Clicking on the highlighted folder name make the file table tp
     56  *  navigate to that folder. */
     57class UIFileManagerBreadCrumbs : public QLineEdit
     58{
     59    Q_OBJECT;
     60
     61signals:
     62
     63    void sigNavitatePath(const QString &strPath);
     64
     65public:
     66
     67    UIFileManagerBreadCrumbs(QWidget *pParent = 0);
     68    void setPath(const QString &strPath);
     69
     70protected:
     71
     72    virtual void mouseMoveEvent(QMouseEvent *pEvent) /* override */;
     73    virtual void mousePressEvent(QMouseEvent *pEvent) /* override */;
     74    virtual void focusOutEvent(QFocusEvent *pEvent) /* override */;
     75
     76private:
     77};
     78
     79
     80/*********************************************************************************************************************************
    5181*   UIGuestControlFileView definition.                                                                                           *
    5282*********************************************************************************************************************************/
     
    138168    QILabel   *m_pQuestionLabel;
    139169};
     170
     171
     172/*********************************************************************************************************************************
     173*   UIFileManagerBreadCrumbs implementation.                                                                                     *
     174*********************************************************************************************************************************/
     175
     176UIFileManagerBreadCrumbs::UIFileManagerBreadCrumbs(QWidget *pParent /* = 0 */)
     177    :QLineEdit(pParent)
     178{
     179
     180}
     181
     182void UIFileManagerBreadCrumbs::setPath(const QString &strPath)
     183{
     184    clear();
     185    setText(strPath);
     186}
     187
     188void UIFileManagerBreadCrumbs::mouseMoveEvent(QMouseEvent *pEvent)
     189{
     190    QChar cSeparator('/');
     191    int iCharPos = this->cursorPositionAt(pEvent->pos());
     192    QString strLeft = text().left(iCharPos);
     193    int iLeftSeparator = strLeft.lastIndexOf(cSeparator);
     194    int iRightSeparator = text().indexOf(cSeparator, iLeftSeparator + 1);
     195    if (iRightSeparator == -1)
     196        iRightSeparator = text().length();
     197    /* A special case for leading sperator aka. root folder: */
     198    if (iRightSeparator == 0)
     199        setSelection(iLeftSeparator + 1, 1);
     200    else
     201        setSelection(iLeftSeparator + 1, iRightSeparator - iLeftSeparator - 1);
     202}
     203
     204void UIFileManagerBreadCrumbs::mousePressEvent(QMouseEvent *pEvent)
     205{
     206    QChar cSeparator('/');
     207    int iCharPos = this->cursorPositionAt(pEvent->pos());
     208    // QString strLeft = text().left(iCharPos);
     209    // int iLeftSeparator = strLeft.lastIndexOf(cSeparator);
     210    int iRightSeparator = text().indexOf(cSeparator, iCharPos);
     211    QString strPath;
     212    if (iRightSeparator == 0)
     213        strPath = cSeparator;
     214    else
     215        strPath = text().left(iRightSeparator);
     216    emit sigNavitatePath(strPath);
     217}
     218
     219void UIFileManagerBreadCrumbs::focusOutEvent(QFocusEvent *pEvent)
     220{
     221    deselect();
     222    QLineEdit::focusOutEvent(pEvent);
     223}
     224
     225
     226/*********************************************************************************************************************************
     227*   UIFileManagerPathButton implementation.                                                                                      *
     228*********************************************************************************************************************************/
     229
     230// UIFileManagerPathButton::UIFileManagerPathButton(QWidget *pParent /* = 0 */, const QString &strPath /* = QString() */)
     231//     :QIToolButton(pParent)
     232//     , m_strPath(strPath)
     233// {
     234//     setText(m_strPath);
     235// }
    140236
    141237
     
    379475    , m_pLocationComboBox(0)
    380476    , m_pWarningLabel(0)
     477    , m_pBreadCrumbsWidget(0)
    381478{
    382479    prepareObjects();
     
    437534    }
    438535
    439 
     536    m_pBreadCrumbsWidget = new UIFileManagerBreadCrumbs;
     537    if (m_pBreadCrumbsWidget)
     538    {
     539        m_pMainLayout->addWidget(m_pBreadCrumbsWidget, 1, 1, 1, 4);
     540        m_pBreadCrumbsWidget->setReadOnly(true);
     541        QSizePolicy sizePolicy;
     542        sizePolicy.setControlType(QSizePolicy::ComboBox);
     543        m_pBreadCrumbsWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     544        connect(m_pBreadCrumbsWidget, &UIFileManagerBreadCrumbs::sigNavitatePath,
     545                this, &UIFileManagerTable::sltHandleBreadCrumbsClick);
     546    }
     547
     548    UIFileManagerOptions *pOptions = UIFileManagerOptions::instance();
     549    if (pOptions)
     550        showHideBreadCrumbs(pOptions->fShowBreadCrumbs);
     551    else
     552        showHideBreadCrumbs(false);
    440553    m_pModel = new UICustomFileSystemModel(this);
    441554    if (!m_pModel)
     
    519632    }
    520633    m_pLocationComboBox->setCurrentIndex(itemIndex);
     634
     635    if (m_pBreadCrumbsWidget)
     636    {
     637        m_pBreadCrumbsWidget->setPath(strLocation);
     638    }
    521639}
    522640
     
    8951013        sigLogOutput(QString(pItem->path()).append(" could not be renamed"), FileManagerLogType_Error);
    8961014    }
     1015}
     1016
     1017void UIFileManagerTable::sltHandleBreadCrumbsClick(const QString& strPath)
     1018{
     1019    goIntoDirectory(UIPathOperations::pathTrail(strPath));
    8971020}
    8981021
     
    11701293        if (m_pModel)
    11711294            m_pModel->setShowHumanReadableSizes(pOptions->fShowHumanReadableSizes);
     1295        showHideBreadCrumbs(pOptions->fShowBreadCrumbs);
    11721296    }
    11731297    relist();
     
    12561380}
    12571381
     1382void UIFileManagerTable::showHideBreadCrumbs(bool fShow)
     1383{
     1384    if (m_pLocationComboBox)
     1385        m_pLocationComboBox->setVisible(!fShow);
     1386    if (m_pBreadCrumbsWidget)
     1387        m_pBreadCrumbsWidget->setVisible(fShow);
     1388}
     1389
    12581390#include "UIFileManagerTable.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r77868 r77932  
    5252class UICustomFileSystemModel;
    5353class UICustomFileSystemProxyModel;
     54class UIFileManagerBreadCrumbs;
    5455class UIGuestControlFileView;
    5556class UIToolBar;
     
    258259     *  sltRename() for more details. */
    259260    void sltHandleItemRenameAttempt(UICustomFileSystemItem *pItem, QString strOldName, QString strNewName);
     261    void sltHandleBreadCrumbsClick(const QString& strPath);
    260262
    261263private:
     
    282284     *  if deletion can continue */
    283285    bool            checkIfDeleteOK();
     286    void            showHideBreadCrumbs(bool fShow);
    284287
    285288    UICustomFileSystemModel      *m_pModel;
     
    292295    QILabel         *m_pWarningLabel;
    293296
     297    UIFileManagerBreadCrumbs *m_pBreadCrumbsWidget;
     298
    294299    friend class     UICustomFileSystemModel;
    295300};
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