VirtualBox

Ignore:
Timestamp:
Feb 14, 2019 7:56:39 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128850
Message:

FE/Qt: bugref:9080. Redesigning VISO creator by hiding the ugly tree viewer. part 2.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoBrowserBase.cpp

    r77309 r77321  
    102102bool UILocationSelector::eventFilter(QObject *pObj, QEvent *pEvent)
    103103{
    104     if (pObj == m_pLineEdit && pEvent->type() == QEvent::MouseButtonPress)
    105     {
    106         emit sigExpandCollapseTreeView();
     104    if (pObj == m_pLineEdit)
     105    {
     106        if(pEvent->type() == QEvent::MouseButtonPress)
     107        {
     108            QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);
     109            if (pMouseEvent && pMouseEvent->button() == Qt::LeftButton)
     110                emit sigExpandCollapseTreeView();
     111        }
    107112    }
    108113    /* Pass the events to event system for further processing: */
    109114    return false;
    110115}
     116
    111117void UILocationSelector::prepareWidget()
    112118{
     
    155161}
    156162
     163bool UIVisoBrowserBase::isTreeViewVisible() const
     164{
     165    if (!m_pTreeView)
     166        return false;
     167    return m_pTreeView->isVisible();
     168}
     169
     170void UIVisoBrowserBase::hideTreeView()
     171{
     172    if (isTreeViewVisible())
     173        sltExpandCollapseTreeView();
     174}
     175
    157176void UIVisoBrowserBase::prepareObjects()
    158177{
     
    179198        m_pTreeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
    180199        m_pTreeView->setFrameStyle(QFrame::Panel | QFrame::Plain);
     200        m_pTreeView->installEventFilter(this);
    181201    }
    182202
     
    217237}
    218238
     239/* Close the tree view when it recieves focus-out and enter key press event: */
     240bool UIVisoBrowserBase::eventFilter(QObject *pObj, QEvent *pEvent)
     241{
     242    if (pObj == m_pTreeView)
     243    {
     244        if(pEvent->type() == QEvent::KeyPress)
     245        {
     246            QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent);
     247            if (pKeyEvent &&
     248                (pKeyEvent->key() == Qt::Key_Return ||
     249                 pKeyEvent->key() == Qt::Key_Enter))
     250            {
     251                sltExpandCollapseTreeView();
     252            }
     253        }
     254        else if (pEvent->type() == QEvent::FocusOut)
     255        {
     256                sltExpandCollapseTreeView();
     257        }
     258    }
     259    return false;
     260}
     261
     262void UIVisoBrowserBase::keyPressEvent(QKeyEvent *pEvent)
     263{
     264    if (pEvent->key() == Qt::Key_Escape)
     265    {
     266        if (m_pTreeView->isVisible())
     267            updateTreeViewGeometry(false);
     268
     269    }
     270    QIWithRetranslateUI<QWidget>::keyPressEvent(pEvent);
     271}
     272
     273
    219274void UIVisoBrowserBase::sltHandleTableViewItemDoubleClick(const QModelIndex &index)
    220275{
     
    232287}
    233288
    234 
    235289void UIVisoBrowserBase::sltHandleTreeItemClicked(const QModelIndex &modelIndex)
    236290{
     
    239293    m_pTreeView->setExpanded(modelIndex, true);
    240294    m_pTreeView->hide();
     295    emit sigTreeViewVisibilityChanged(m_pTreeView->isVisible());
    241296}
    242297
     
    256311    {
    257312        m_pTreeView->hide();
    258         return;
     313        emit sigTreeViewVisibilityChanged(m_pTreeView->isVisible());
     314        m_pTreeView->clearFocus();
     315            return;
    259316    }
    260317    if (!m_pLocationSelector)
     
    264321    int ix = m_pLocationSelector->x();
    265322    int iWidth = m_pLocationSelector->lineEditWidth();
    266 
    267323    m_pTreeView-> move(ix, iy);
    268324    m_pTreeView->raise();
    269325    m_pTreeView->resize(iWidth, 0.75 * height());
    270326    m_pTreeView->show();
    271 
    272     //m_pTreeView->scrollTo(m_pTreeView->currentIndex(), QAbstractItemView::PositionAtTop);
     327    m_pTreeView->setFocus();
     328    emit sigTreeViewVisibilityChanged(m_pTreeView->isVisible());
    273329}
    274330
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoBrowserBase.h

    r77308 r77321  
    4545    Q_OBJECT;
    4646
     47signals:
     48
     49    void sigTreeViewVisibilityChanged(bool fVisible);
     50
    4751public:
    4852    /** @p pMenu is the pointer to the menu related to this browser widget.
     
    5155    ~UIVisoBrowserBase();
    5256    virtual void showHideHiddenObjects(bool bShow) = 0;
     57    /* Returns true if tree view is currently visible: */
     58    bool isTreeViewVisible() const;
     59    void hideTreeView();
    5360
    5461public slots:
     
    6875
    6976    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     77    virtual bool eventFilter(QObject *pObj, QEvent *pEvent) /* override */;
     78    virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
    7079
    7180    QTreeView          *m_pTreeView;
     
    7382    QMenu              *m_pMenu;
    7483    QGridLayout       *m_pMainLayout;
    75 
    76 private:
    7784
    7885private slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoContentBrowser.cpp

    r77308 r77321  
    586586        {
    587587            QString strPath = pItem->data(UICustomFileSystemModelColumn_Path).toString();
    588             if (strPath == QDir::fromNativeSeparators("/"))
    589                 strPath += m_strVisoName;
    590588            updateLocationSelectorText(strPath);
    591589        }
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.cpp

    r77308 r77321  
    120120}
    121121
     122// bool UIVisoCreator::event(QEvent *pEvent)
     123// {
     124
     125//     if (pEvent->type() == QEvent::KeyPress)
     126//     {
     127//         printf("key press %d\n", pEvent->type());
     128//     }
     129//     return false;
     130// }
     131
     132// bool UIVisoCreator::eventFilter(QObject *, QEvent *pEvent)
     133// {
     134//     if (pEvent->type() == QEvent::KeyPress)
     135//     {
     136//         printf("key press in filter %d\n", pEvent->type());
     137//     }
     138
     139//     return false;
     140// }
     141
    122142void UIVisoCreator::sltHandleAddObjectsToViso(QStringList pathList)
    123143{
     
    174194{
    175195    hidePanel(pPanel);
     196}
     197
     198void UIVisoCreator::sltHandleBrowserTreeViewVisibilityChanged(bool fVisible)
     199{
     200    Q_UNUSED(fVisible);
     201    manageEscapeShortCut();
    176202}
    177203
     
    220246        if (m_pActionOptions)
    221247            m_pToolBar->addAction(m_pActionOptions);
    222 
    223248        m_pMainLayout->addWidget(m_pToolBar);
    224249    }
     
    240265        connect(m_pHostBrowser, &UIVisoHostBrowser::sigAddObjectsToViso,
    241266                this, &UIVisoCreator::sltHandleAddObjectsToViso);
     267        connect(m_pHostBrowser, &UIVisoHostBrowser::sigTreeViewVisibilityChanged,
     268                this, &UIVisoCreator::sltHandleBrowserTreeViewVisibilityChanged);
    242269    }
    243270
     
    275302        m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
    276303        m_pMainLayout->addWidget(m_pButtonBox);
    277 
    278304    }
    279305    retranslateUi();
     
    365391}
    366392
    367 
    368 
    369393void UIVisoCreator::manageEscapeShortCut()
    370394{
     395    /* Take the escape key from m_pButtonBox and from the panels in case treeview(s) in
     396       host and/or content browser is open. We use the escape key to close those first: */
     397    if ((m_pHostBrowser && m_pHostBrowser->isTreeViewVisible()) ||
     398        (m_pVisoBrowser && m_pVisoBrowser->isTreeViewVisible()))
     399    {
     400        if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel))
     401            m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence());
     402        for (int i = 0; i < m_visiblePanelsList.size(); ++i)
     403            m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence());
     404        return;
     405    }
     406
    371407    /* if there are no visible panels then assign esc. key to cancel button of the button box: */
    372408    if (m_visiblePanelsList.isEmpty())
     
    382418       panel which made visible latest */
    383419    for (int i = 0; i < m_visiblePanelsList.size() - 1; ++i)
    384     {
    385420        m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence());
    386     }
    387421    m_visiblePanelsList.back()->setCloseButtonShortCut(QKeySequence(Qt::Key_Escape));
    388422}
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.h

    r77308 r77321  
    7070protected:
    7171
    72     void retranslateUi();
     72    virtual void retranslateUi() /* override */;
     73    // virtual bool event(QEvent *pEvent) /* override */;
     74    // virtual bool eventFilter(QObject *pObj, QEvent *pEvent) /* override */;
    7375
    7476private slots:
     
    8082    void sltHandleShowHiddenObjectsChange(bool fShow);
    8183    void sltHandleHidePanel(UIDialogPanel *pPanel);
     84    void sltHandleBrowserTreeViewVisibilityChanged(bool fVisible);
    8285
    8386private:
     
    108111    /** Makes sure escape key is assigned to only a single widget. This is done by checking
    109112        several things in the following order:
     113        - when tree views of browser panes are visible esc. key used to close those. thus it is taken from the dialog and panels
    110114        - when there are no more panels visible assign it to the parent dialog
    111115        - grab it from the dialog as soon as a panel becomes visible again
Note: See TracChangeset for help on using the changeset viewer.

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