VirtualBox

Ignore:
Timestamp:
Apr 5, 2019 10:19:23 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. Improvements on the bread crumbs widget.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl
Files:
2 edited

Legend:

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

    r78010 r78024  
    8383
    8484    UIFileManagerBreadCrumbs(QWidget *pParent = 0);
    85     void setPath(const QString &strPath, bool fUnderlineLast = false);
     85    void setPath(const QString &strPath);
    8686};
    8787
     
    9090*   UIFileManagerNavigationWidget definition.                                                                                    *
    9191*********************************************************************************************************************************/
    92 
     92/** UIFileManagerNavigationWidget contains a UIFileManagerBreadCrumbs, QComboBox for history and a QToolButton.
     93  * basically it is a container for these mentioned widgets. */
    9394class UIFileManagerNavigationWidget : public QWidget
    9495{
     
    105106    void reset();
    106107
     108protected:
     109
     110    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     111
    107112private slots:
    108113
     
    115120    void prepare();
    116121
    117     QStackedWidget *m_pContainer;
    118     UIFileManagerBreadCrumbs *m_pBreadCrumbs;
     122    QStackedWidget               *m_pContainer;
     123    UIFileManagerBreadCrumbs     *m_pBreadCrumbs;
    119124    UIFileManagerHistoryComboBox *m_pHistoryComboBox;
    120     QToolButton    *m_pSwitchButton;
     125    QToolButton                  *m_pSwitchButton;
     126    QString                       m_strPath;
    121127};
    122128
     
    238244    :QWidget(pParent)
    239245    , m_pContainer(0)
     246    , m_pBreadCrumbs(0)
     247    , m_pHistoryComboBox(0)
    240248    , m_pSwitchButton(0)
    241249{
     
    245253void UIFileManagerNavigationWidget::setPath(const QString &strLocation)
    246254{
     255    m_strPath = strLocation;
     256
    247257    if (m_pBreadCrumbs)
    248258        m_pBreadCrumbs->setPath(strLocation);
     
    265275    if (m_pHistoryComboBox)
    266276    {
    267         /** @todo disconnect here. */
     277        disconnect(m_pHistoryComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
     278                   this, &UIFileManagerNavigationWidget::sigPathChanged);
    268279        m_pHistoryComboBox->clear();
    269     }
     280        connect(m_pHistoryComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
     281                this, &UIFileManagerNavigationWidget::sigPathChanged);
     282    }
     283
     284    if (m_pBreadCrumbs)
     285        m_pBreadCrumbs->setPath(QString());
     286}
     287
     288void UIFileManagerNavigationWidget::resizeEvent(QResizeEvent *pEvent)
     289{
     290    if (m_pBreadCrumbs)
     291        m_pBreadCrumbs->setPath(m_strPath);
     292
     293    QWidget::resizeEvent(pEvent);
    270294}
    271295
     
    279303
    280304    m_pContainer = new QStackedWidget;
    281 
    282305    if (m_pContainer)
    283306    {
     
    285308        m_pHistoryComboBox = new UIFileManagerHistoryComboBox;
    286309
    287         connect(m_pBreadCrumbs, &UIFileManagerBreadCrumbs::linkActivated,
    288                 this, &UIFileManagerNavigationWidget::sigPathChanged);
    289 
    290         connect(m_pHistoryComboBox, &UIFileManagerHistoryComboBox::sigHidePopup,
    291                 this, &UIFileManagerNavigationWidget::sltHandleHidePopup);
    292 
    293         connect(m_pHistoryComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
    294                 this, &UIFileManagerNavigationWidget::sigPathChanged);
    295 
    296         m_pContainer->addWidget(m_pBreadCrumbs);
    297         m_pContainer->addWidget(m_pHistoryComboBox);
    298         m_pContainer->setCurrentIndex(0);
    299 
     310        if (m_pBreadCrumbs && m_pHistoryComboBox)
     311        {
     312            m_pBreadCrumbs->setIndent(0.5 * qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin));
     313
     314            connect(m_pBreadCrumbs, &UIFileManagerBreadCrumbs::linkActivated,
     315                    this, &UIFileManagerNavigationWidget::sigPathChanged);
     316            connect(m_pHistoryComboBox, &UIFileManagerHistoryComboBox::sigHidePopup,
     317                    this, &UIFileManagerNavigationWidget::sltHandleHidePopup);
     318            connect(m_pHistoryComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
     319                    this, &UIFileManagerNavigationWidget::sigPathChanged);
     320
     321            m_pContainer->addWidget(m_pBreadCrumbs);
     322            m_pContainer->addWidget(m_pHistoryComboBox);
     323            m_pContainer->setCurrentIndex(0);
     324        }
    300325        pLayout->addWidget(m_pContainer);
    301326    }
    302327
    303328    m_pSwitchButton = new QToolButton;
    304 
    305329    if (m_pSwitchButton)
    306330    {
     
    318342                this, &UIFileManagerNavigationWidget::sltHandleSwitch);
    319343    }
    320 
    321344    setLayout(pLayout);
    322345}
     
    357380    setFont(mFont);
    358381
    359 }
    360 
    361 void UIFileManagerBreadCrumbs::setPath(const QString &strPath, bool fUnderlineLast /* = false */)
     382    setFrameShape(QFrame::Box);
     383    setLineWidth(1);
     384    //setFixedHeight(10);
     385    setAutoFillBackground(true);
     386    QPalette newPalette = palette();
     387    newPalette.setColor(QPalette::Background, qApp->palette().color(QPalette::Light));
     388
     389    setPalette(newPalette);
     390}
     391
     392void UIFileManagerBreadCrumbs::setPath(const QString &strPath)
    362393{
    363394    const QChar separator('/');
     
    365396    QStringList folderList = UIPathOperations::pathTrail(strPath);
    366397    folderList.push_front(separator);
     398
    367399    QString strLabelText;
    368     QString strPathUpto;
     400    QVector<QString> strPathUpto;
     401    strPathUpto.resize(folderList.size());
     402
    369403    for (int i = 0; i < folderList.size(); ++i)
    370404    {
    371405        QString strFolder = UIPathOperations::removeTrailingDelimiters(folderList.at(i));
     406        if (i != 0)
     407            strPathUpto[i] = strPathUpto[i - 1];
    372408        if (i == 0 || i == folderList.size() - 1)
    373             strPathUpto.append(QString("%1").arg(strFolder));
     409            strPathUpto[i].append(QString("%1").arg(strFolder));
    374410        else
    375             strPathUpto.append(QString("%1%2").arg(strFolder).arg(separator));
    376         if (fUnderlineLast && i == folderList.size() - 1)
    377             strLabelText.append(QString("<a href=\"%1\" style=\"color:black;text-decoration:underline;\">%2</a>").arg(strPathUpto).arg(strFolder));
    378         else
    379             strLabelText.append(QString("<a href=\"%1\" style=\"color:black;text-decoration:none;\">%2</a>").arg(strPathUpto).arg(strFolder));
     411            strPathUpto[i].append(QString("%1%2").arg(strFolder).arg(separator));
     412    }
     413
     414    int iWidth = 0;
     415    for (int i = folderList.size() - 1; i >= 0; --i)
     416    {
     417        QString strFolder = UIPathOperations::removeTrailingDelimiters(folderList.at(i));
     418        QString strWord = QString("<a href=\"%1\" style=\"color:black;text-decoration:none;\">%2</a>").arg(strPathUpto[i]).arg(strFolder);
     419
    380420        if (i < folderList.size() - 1)
    381             strLabelText.append("<b> > </b>");
     421        {
     422            iWidth += fontMetrics().width(" > ");
     423            strWord.append("<b> > </b>");
     424        }
     425        iWidth += fontMetrics().width(strFolder);
     426
     427        if (iWidth < width())
     428            strLabelText.prepend(strWord);
     429
    382430    }
    383431    setText(strLabelText);
    384 
    385432}
    386433
     
    612659*********************************************************************************************************************************/
    613660const unsigned UIFileManagerTable::m_iKiloByte = 1024; /**< Our kilo bytes are a power of two! (bird) */
     661
    614662UIFileManagerTable::UIFileManagerTable(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
    615663    :QIWithRetranslateUI<QWidget>(pParent)
     
    659707    if (m_pToolBar)
    660708    {
    661         m_pMainLayout->addWidget(m_pToolBar, 0, 0, 1, 5);
     709        m_pMainLayout->addWidget(m_pToolBar, 0, 0, 1, 7);
    662710    }
    663711
    664712    m_pLocationLabel = new QILabel;
    665713    if (m_pLocationLabel)
    666     {
    667714        m_pMainLayout->addWidget(m_pLocationLabel, 1, 0, 1, 1);
    668     }
    669715
    670716    m_pNavigationWidget = new UIFileManagerNavigationWidget;
    671717    if (m_pNavigationWidget)
    672718    {
    673         m_pNavigationWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
     719        m_pNavigationWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
    674720        connect(m_pNavigationWidget, &UIFileManagerNavigationWidget::sigPathChanged,
    675721                this, &UIFileManagerTable::sltHandleNavigationWidgetPathChange);
    676         m_pMainLayout->addWidget(m_pNavigationWidget, 1, 1, 1, 4);
     722        m_pMainLayout->addWidget(m_pNavigationWidget, 1, 1, 1, 6);
    677723    }
    678724
     
    691737    if (m_pView)
    692738    {
    693         m_pMainLayout->addWidget(m_pView, 2, 0, 5, 5);
     739        m_pMainLayout->addWidget(m_pView, 2, 0, 5, 7);
    694740
    695741        QHeaderView *pHorizontalHeader = m_pView->horizontalHeader();
     
    719765    if (m_pWarningLabel)
    720766    {
    721         m_pMainLayout->addWidget(m_pWarningLabel, 2, 0, 5, 5);
     767        m_pMainLayout->addWidget(m_pWarningLabel, 2, 0, 5, 7);
    722768        QFont labelFont = m_pWarningLabel->font();
    723769        float fSizeMultiplier = 1.5f;
     
    737783    if (m_pSearchLineEdit)
    738784    {
    739         m_pMainLayout->addWidget(m_pSearchLineEdit, 8, 0, 1, 5);
     785        m_pMainLayout->addWidget(m_pSearchLineEdit, 8, 0, 1, 7);
    740786        m_pSearchLineEdit->hide();
    741787        m_pSearchLineEdit->setClearButtonEnabled(true);
  • trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h

    r78010 r78024  
    239239    UIActionPool            *m_pActionPool;
    240240    UIToolBar               *m_pToolBar;
    241 
    242241    /** Stores the drive letters the file system has (for windows system). For non-windows
    243242     *  systems this is empty and for windows system it should at least contain C:/ */
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