Changeset 84578 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- May 27, 2020 5:49:22 PM (5 years ago)
- 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 204 204 void UIChooser::prepareModel() 205 205 { 206 /* Prepare Chooser-model: */ 206 207 m_pChooserModel = new UIChooserModel(this); 207 208 } … … 216 217 pMainLayout->setSpacing(0); 217 218 218 /* Prepare chooser-view: */219 /* Prepare Chooser-view: */ 219 220 m_pChooserView = new UIChooserView(this); 220 221 if (m_pChooserView) 221 222 { 222 223 AssertPtrReturnVoid(model()); 224 m_pChooserView->setModel(model()); 223 225 m_pChooserView->setScene(model()->scene()); 224 226 m_pChooserView->show(); -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp
r84462 r84578 568 568 if (isRoot()) 569 569 { 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: */ 571 571 const int iMinimumWidthHint = minimumWidthHint(); 572 572 if (m_iPreviousMinimumWidthHint != iMinimumWidthHint) -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.cpp
r84518 r84578 21 21 22 22 /* GUI includes: */ 23 #include "UIChooser.h"24 23 #include "UIChooserItem.h" 25 24 #include "UIChooserModel.h" … … 58 57 AssertPtrReturn(view(), 0); 59 58 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; 62 61 } 63 62 … … 70 69 AssertReturn(iIndex >= 0 && iIndex < childCount(), 0); 71 70 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); 74 73 } 75 74 … … 92 91 93 92 94 UIChooserView::UIChooserView( UIChooser*pParent)93 UIChooserView::UIChooserView(QWidget *pParent) 95 94 : QIWithRetranslateUI<QIGraphicsView>(pParent) 96 , m_pChooser (pParent)95 , m_pChooserModel(0) 97 96 , m_pSearchWidget(0) 98 97 , m_iMinimumWidthHint(0) 99 98 { 100 /* Prepare: */101 99 prepare(); 102 100 } 103 101 102 void UIChooserView::setModel(UIChooserModel *pChooserModel) 103 { 104 m_pChooserModel = pChooserModel; 105 } 106 107 UIChooserModel *UIChooserView::model() const 108 { 109 return m_pChooserModel; 110 } 111 104 112 bool UIChooserView::isSearchWidgetVisible() const 105 113 { 106 if (!m_pSearchWidget)107 return false;114 /* Make sure search widget exists: */ 115 AssertPtrReturn(m_pSearchWidget, false); 108 116 109 117 /* Return widget visibility state: */ … … 113 121 void UIChooserView::setSearchWidgetVisible(bool fVisible) 114 122 { 115 if (!m_pSearchWidget)116 return;123 /* Make sure search widget exists: */ 124 AssertPtrReturnVoid(m_pSearchWidget); 117 125 118 126 /* Make sure keyboard focus is managed correctly: */ … … 136 144 updateSearchWidgetGeometry(); 137 145 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 152 void 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); 150 159 m_pSearchWidget->setScroolToIndex(iCurrentlyScrolledItemIndex); 151 160 } … … 153 162 void UIChooserView::appendToSearchString(const QString &strSearchText) 154 163 { 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: */ 158 168 m_pSearchWidget->appendToSearchString(strSearchText); 159 169 } … … 171 181 setMinimumWidth(2 * frameWidth() + m_iMinimumWidthHint + verticalScrollBar()->sizeHint().width()); 172 182 173 /* Update scene -rect: */183 /* Update scene rectangle: */ 174 184 updateSceneRect(); 175 185 } 176 186 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); 187 void 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 197 void 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 207 void UIChooserView::sltHandleSearchWidgetVisibilityToggle(bool fVisible) 208 { 209 setSearchWidgetVisible(fVisible); 202 210 } 203 211 … … 229 237 /* Create the search widget (hidden): */ 230 238 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: */ 240 251 updateSceneRect(); 241 252 /* Update the location and size of the search widget: */ … … 248 259 void UIChooserView::preparePalette() 249 260 { 250 /* Setup palette: */251 261 QPalette pal = qApp->palette(); 252 262 const QColor bodyColor = pal.color(QPalette::Active, QPalette::Midlight).darker(110); … … 262 272 emit sigResized(); 263 273 264 /* Update scene -rect: */274 /* Update scene rectangle: */ 265 275 updateSceneRect(); 266 /* Update the location and size of the search widget: */276 /* Update search widget geometry: */ 267 277 updateSearchWidgetGeometry(); 268 278 } … … 275 285 void UIChooserView::updateSearchWidgetGeometry() 276 286 { 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 27 27 28 28 /* Forward declarations: */ 29 class UIChooser ;29 class UIChooserModel; 30 30 class UIChooserSearchWidget; 31 31 … … 45 45 public: 46 46 47 /** Constructs a chooser-view passing @a pParent to the base-class.47 /** Constructs a Chooser-view passing @a pParent to the base-class. 48 48 * @param pParent Brings the chooser container to embed into. */ 49 UIChooserView( UIChooser*pParent);49 UIChooserView(QWidget *pParent); 50 50 51 51 /** @name General stuff. 52 52 * @{ */ 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; 55 57 /** @} */ 56 58 57 59 /** @name Search stuff. 58 60 * @{ */ 59 /** Returns if the search widget is visible or not. */61 /** Returns whether search widget visible. */ 60 62 bool isSearchWidgetVisible() const; 61 /** Shows/hides wrt. @a fVisible machine search widget. */63 /** Makes search widget @a fVisible. */ 62 64 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. */ 66 71 void appendToSearchString(const QString &strSearchText); 67 72 /** @} */ … … 88 93 private slots: 89 94 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 /** @} */ 95 106 96 107 private: … … 118 129 /** @name General stuff. 119 130 * @{ */ 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. */ 123 138 UIChooserSearchWidget *m_pSearchWidget; 124 139 /** @} */
Note:
See TracChangeset
for help on using the changeset viewer.