VirtualBox

Changeset 84578 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
May 27, 2020 5:49:22 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Cleanup for Chooser-view related classes.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooser.cpp

    r84557 r84578  
    204204void UIChooser::prepareModel()
    205205{
     206    /* Prepare Chooser-model: */
    206207    m_pChooserModel = new UIChooserModel(this);
    207208}
     
    216217        pMainLayout->setSpacing(0);
    217218
    218         /* Prepare chooser-view: */
     219        /* Prepare Chooser-view: */
    219220        m_pChooserView = new UIChooserView(this);
    220221        if (m_pChooserView)
    221222        {
    222223            AssertPtrReturnVoid(model());
     224            m_pChooserView->setModel(model());
    223225            m_pChooserView->setScene(model()->scene());
    224226            m_pChooserView->show();
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r84462 r84578  
    568568    if (isRoot())
    569569    {
    570         /* Root-group should notify chooser-view if minimum-width-hint was changed: */
     570        /* Root-group should notify Chooser-view if minimum-width-hint was changed: */
    571571        const int iMinimumWidthHint = minimumWidthHint();
    572572        if (m_iPreviousMinimumWidthHint != iMinimumWidthHint)
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.cpp

    r84518 r84578  
    2121
    2222/* GUI includes: */
    23 #include "UIChooser.h"
    2423#include "UIChooserItem.h"
    2524#include "UIChooserModel.h"
     
    5857        AssertPtrReturn(view(), 0);
    5958
    60         /* Return the number of children: */
    61         return view()->chooser()->model()->root()->items().size();
     59        /* Return the number of model children if model really assigned: */
     60        return view()->model() ? view()->model()->root()->items().size() : 0;
    6261    }
    6362
     
    7069        AssertReturn(iIndex >= 0 && iIndex < childCount(), 0);
    7170
    72         /* Return the child with the passed iIndex: */
    73         return QAccessible::queryAccessibleInterface(view()->chooser()->model()->root()->items().at(iIndex));
     71        /* Return the model child with the passed iIndex if model really assigned: */
     72        return QAccessible::queryAccessibleInterface(view()->model() ? view()->model()->root()->items().at(iIndex) : 0);
    7473    }
    7574
     
    9291
    9392
    94 UIChooserView::UIChooserView(UIChooser *pParent)
     93UIChooserView::UIChooserView(QWidget *pParent)
    9594    : QIWithRetranslateUI<QIGraphicsView>(pParent)
    96     , m_pChooser(pParent)
     95    , m_pChooserModel(0)
    9796    , m_pSearchWidget(0)
    9897    , m_iMinimumWidthHint(0)
    9998{
    100     /* Prepare: */
    10199    prepare();
    102100}
    103101
     102void UIChooserView::setModel(UIChooserModel *pChooserModel)
     103{
     104    m_pChooserModel = pChooserModel;
     105}
     106
     107UIChooserModel *UIChooserView::model() const
     108{
     109    return m_pChooserModel;
     110}
     111
    104112bool UIChooserView::isSearchWidgetVisible() const
    105113{
    106     if (!m_pSearchWidget)
    107         return false;
     114    /* Make sure search widget exists: */
     115    AssertPtrReturn(m_pSearchWidget, false);
    108116
    109117    /* Return widget visibility state: */
     
    113121void UIChooserView::setSearchWidgetVisible(bool fVisible)
    114122{
    115     if (!m_pSearchWidget)
    116         return;
     123    /* Make sure search widget exists: */
     124    AssertPtrReturnVoid(m_pSearchWidget);
    117125
    118126    /* Make sure keyboard focus is managed correctly: */
     
    136144        updateSearchWidgetGeometry();
    137145
    138     /* Reset search each time widget visibility changed: */
    139     UIChooserModel *pModel = m_pChooser->model();
    140     if (pModel)
    141         pModel->resetSearch();
    142 }
    143 
    144 void UIChooserView::setSearchResultsCount(int iTotalMacthCount, int iCurrentlyScrolledItemIndex)
    145 {
    146     if (!m_pSearchWidget)
    147         return;
    148 
    149     m_pSearchWidget->setMatchCount(iTotalMacthCount);
     146    /* Reset search each time widget visibility changed,
     147     * Model can be undefined.. */
     148    if (model())
     149        model()->resetSearch();
     150}
     151
     152void UIChooserView::setSearchResultsCount(int iTotalMatchCount, int iCurrentlyScrolledItemIndex)
     153{
     154    /* Make sure search widget exists: */
     155    AssertPtrReturnVoid(m_pSearchWidget);
     156
     157    /* Update count of search results and scroll to certain result: */
     158    m_pSearchWidget->setMatchCount(iTotalMatchCount);
    150159    m_pSearchWidget->setScroolToIndex(iCurrentlyScrolledItemIndex);
    151160}
     
    153162void UIChooserView::appendToSearchString(const QString &strSearchText)
    154163{
    155     if (!m_pSearchWidget)
    156         return;
    157 
     164    /* Make sure search widget exists: */
     165    AssertPtrReturnVoid(m_pSearchWidget);
     166
     167    /* Update search string with passed text: */
    158168    m_pSearchWidget->appendToSearchString(strSearchText);
    159169}
     
    171181    setMinimumWidth(2 * frameWidth() + m_iMinimumWidthHint + verticalScrollBar()->sizeHint().width());
    172182
    173     /* Update scene-rect: */
     183    /* Update scene rectangle: */
    174184    updateSceneRect();
    175185}
    176186
    177 void UIChooserView::sltRedoSearch(const QString &strSearchTerm, int iItemSearchFlags)
    178 {
    179     if (!m_pChooser)
    180         return;
    181     UIChooserModel *pModel =  m_pChooser->model();
    182     if (!pModel)
    183         return;
    184 
    185     pModel->performSearch(strSearchTerm, iItemSearchFlags);
    186 }
    187 
    188 void UIChooserView::sltHandleScrollToSearchResult(bool fIsNext)
    189 {
    190     if (!m_pChooser)
    191         return;
    192     UIChooserModel *pModel =  m_pChooser->model();
    193     if (!pModel)
    194         return;
    195 
    196     pModel->selectSearchResult(fIsNext);
    197 }
    198 
    199 void UIChooserView::sltHandleSearchWidgetVisibilityToggle(bool fIsVisible)
    200 {
    201     setSearchWidgetVisible(fIsVisible);
     187void UIChooserView::sltRedoSearch(const QString &strSearchTerm, int iSearchFlags)
     188{
     189    /* Model can be undefined: */
     190    if (!model())
     191        return;
     192
     193    /* Perform search: */
     194    model()->performSearch(strSearchTerm, iSearchFlags);
     195}
     196
     197void UIChooserView::sltHandleScrollToSearchResult(bool fNext)
     198{
     199    /* Model can be undefined: */
     200    if (!model())
     201        return;
     202
     203    /* Move to requested search result: */
     204    model()->selectSearchResult(fNext);
     205}
     206
     207void UIChooserView::sltHandleSearchWidgetVisibilityToggle(bool fVisible)
     208{
     209    setSearchWidgetVisible(fVisible);
    202210}
    203211
     
    229237    /* Create the search widget (hidden): */
    230238    m_pSearchWidget = new UIChooserSearchWidget(this);
    231     m_pSearchWidget->hide();
    232     connect(m_pSearchWidget, &UIChooserSearchWidget::sigRedoSearch,
    233             this, &UIChooserView::sltRedoSearch);
    234     connect(m_pSearchWidget, &UIChooserSearchWidget::sigScrollToMatch,
    235             this, &UIChooserView::sltHandleScrollToSearchResult);
    236     connect(m_pSearchWidget, &UIChooserSearchWidget::sigToggleVisibility,
    237             this, &UIChooserView::sltHandleSearchWidgetVisibilityToggle);
    238 
    239     /* Update scene-rect: */
     239    if (m_pSearchWidget)
     240    {
     241        m_pSearchWidget->hide();
     242        connect(m_pSearchWidget, &UIChooserSearchWidget::sigRedoSearch,
     243                this, &UIChooserView::sltRedoSearch);
     244        connect(m_pSearchWidget, &UIChooserSearchWidget::sigScrollToMatch,
     245                this, &UIChooserView::sltHandleScrollToSearchResult);
     246        connect(m_pSearchWidget, &UIChooserSearchWidget::sigToggleVisibility,
     247                this, &UIChooserView::sltHandleSearchWidgetVisibilityToggle);
     248    }
     249
     250    /* Update scene rectangle: */
    240251    updateSceneRect();
    241252    /* Update the location and size of the search widget: */
     
    248259void UIChooserView::preparePalette()
    249260{
    250     /* Setup palette: */
    251261    QPalette pal = qApp->palette();
    252262    const QColor bodyColor = pal.color(QPalette::Active, QPalette::Midlight).darker(110);
     
    262272    emit sigResized();
    263273
    264     /* Update scene-rect: */
     274    /* Update scene rectangle: */
    265275    updateSceneRect();
    266     /* Update the location and size of the search widget: */
     276    /* Update search widget geometry: */
    267277    updateSearchWidgetGeometry();
    268278}
     
    275285void UIChooserView::updateSearchWidgetGeometry()
    276286{
    277     if (!m_pSearchWidget || !m_pSearchWidget->isVisible())
    278         return;
    279 
    280     const int iHeight = m_pSearchWidget->height();
    281     m_pSearchWidget->setGeometry(QRect(0, height() - iHeight, width(), iHeight));
    282 }
     287    /* Make sure search widget exists: */
     288    AssertPtrReturnVoid(m_pSearchWidget);
     289
     290    /* Update visible widget only: */
     291    if (m_pSearchWidget->isVisible())
     292    {
     293        const int iHeight = m_pSearchWidget->height();
     294        m_pSearchWidget->setGeometry(QRect(0, height() - iHeight, width(), iHeight));
     295    }
     296}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.h

    r84518 r84578  
    2727
    2828/* Forward declarations: */
    29 class UIChooser;
     29class UIChooserModel;
    3030class UIChooserSearchWidget;
    3131
     
    4545public:
    4646
    47     /** Constructs a chooser-view passing @a pParent to the base-class.
     47    /** Constructs a Chooser-view passing @a pParent to the base-class.
    4848      * @param  pParent  Brings the chooser container to embed into. */
    49     UIChooserView(UIChooser *pParent);
     49    UIChooserView(QWidget *pParent);
    5050
    5151    /** @name General stuff.
    5252      * @{ */
    53         /** Returns the chooser reference. */
    54         UIChooser *chooser() const { return m_pChooser; }
     53        /** Defines @a pChooserModel reference. */
     54        void setModel(UIChooserModel *pChooserModel);
     55        /** Returns Chooser-model reference. */
     56        UIChooserModel *model() const;
    5557    /** @} */
    5658
    5759    /** @name Search stuff.
    5860      * @{ */
    59         /** Returns if the search widget is visible or not. */
     61        /** Returns whether search widget visible. */
    6062        bool isSearchWidgetVisible() const;
    61         /** Shows/hides wrt. @a fVisible machine search widget. */
     63        /** Makes search widget @a fVisible. */
    6264        void setSearchWidgetVisible(bool fVisible);
    63         /** Updates the search widget's counts. */
    64         void setSearchResultsCount(int iTotalMacthCount, int iCurrentlyScrolledItemIndex);
    65         /** Forwards @a strSearchText to the search widget which in turn appends it to the current (if any) search term. */
     65        /** Updates search widget's results count.
     66          * @param  iTotalMatchCount             Brings total search results count.
     67          * @param  iCurrentlyScrolledItemIndex  Brings the item index search currently scrolled to. */
     68        void setSearchResultsCount(int iTotalMatchCount, int iCurrentlyScrolledItemIndex);
     69        /** Forwards @a strSearchText to the search widget which in
     70          * turn appends it to the current (if any) search term. */
    6671        void appendToSearchString(const QString &strSearchText);
    6772    /** @} */
     
    8893private slots:
    8994
    90     /** Is connected to search widget's signal for a new search. */
    91     void sltRedoSearch(const QString &strSearchTerm, int iItemSearchFlags);
    92     /** Is connected to search widget's scroll to next/prev search result signal. */
    93     void sltHandleScrollToSearchResult(bool fIsNext);
    94     void sltHandleSearchWidgetVisibilityToggle(bool fIsVisible);
     95    /** @name Search stuff.
     96      * @{ */
     97        /** Handles request for a new search.
     98          * @param  strSearchTerm  Brings the search term.
     99          * @param  iSearchFlags   Brings the item search flags. */
     100        void sltRedoSearch(const QString &strSearchTerm, int iSearchFlags);
     101        /** Handles request to scroll to @a fNext search result. */
     102        void sltHandleScrollToSearchResult(bool fNext);
     103        /** Handles request to scroll to make search widget @a fVisible. */
     104        void sltHandleSearchWidgetVisibilityToggle(bool fVisible);
     105    /** @} */
    95106
    96107private:
     
    118129    /** @name General stuff.
    119130      * @{ */
    120         /** Holds the chooser pane reference. */
    121         UIChooser *m_pChooser;
    122         /** Holds the search widget instance reference. */
     131        /** Holds the Chooser-model reference. */
     132        UIChooserModel *m_pChooserModel;
     133    /** @} */
     134
     135    /** @name Search stuff.
     136      * @{ */
     137        /** Holds the search widget instance. */
    123138        UIChooserSearchWidget *m_pSearchWidget;
    124139    /** @} */
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