Changeset 43552 in vbox
- Timestamp:
- Oct 5, 2012 10:52:56 AM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserHandlerMouse.cpp
r43549 r43552 134 134 if (!pClickedItem->isRoot()) 135 135 { 136 /* Is clicked item in selection list: */137 bool fIsClickedItemInSelectionList = model()->currentItems().contains(pClickedItem);138 136 /* Move focus to clicked item (with selection if not selected yet): */ 139 model()->set FocusItem(pClickedItem, !fIsClickedItemInSelectionList);137 model()->setCurrentItem(pClickedItem); 140 138 } 141 139 } -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp
r43544 r43552 211 211 } 212 212 213 void UIGChooserModel::setCurrentItems(const QList<UIGChooserItem*> &items) 214 { 215 /* Is there something seems to be changed? */ 216 if (m_currentItems == items) 217 return; 218 219 /* Remember old current-item list: */ 220 QList<UIGChooserItem*> oldCurrentItems = m_currentItems; 221 222 /* Clear current current-item list: */ 223 m_currentItems.clear(); 224 225 /* Iterate over all the passed items: */ 226 foreach (UIGChooserItem *pItem, items) 227 { 228 /* If navigation list contains iterated-item: */ 229 if (pItem && navigationList().contains(pItem)) 230 { 231 /* Add that item to current: */ 232 m_currentItems << pItem; 233 } 234 else 235 AssertMsgFailed(("Passed item not in navigation list!")); 236 } 237 238 /* Is there something really changed? */ 239 if (oldCurrentItems == m_currentItems) 240 return; 241 242 /* Update all the old items (they are no longer selected): */ 243 foreach (UIGChooserItem *pItem, oldCurrentItems) 244 pItem->update(); 245 246 /* Update all the new items (they are selected): */ 247 foreach (UIGChooserItem *pItem, m_currentItems) 248 pItem->update(); 249 250 /* Notify about selection changes: */ 251 notifyCurrentItemChanged(); 252 } 253 213 254 void UIGChooserModel::setCurrentItem(UIGChooserItem *pItem) 214 255 { 215 /* If navigation list contains passed item: */ 216 if (navigationList().contains(pItem)) 217 { 218 /* Pass focus/selection to that item: */ 219 setFocusItem(pItem, true); 220 } 221 else 222 AssertMsgFailed(("Passed item not in navigation list!")); 223 } 224 225 void UIGChooserModel::setCurrentItem(int iItemIndex) 226 { 227 /* Make sure passed index feats the bounds: */ 228 if (iItemIndex >= 0 && iItemIndex < navigationList().size()) 229 { 230 /* And call for other wrapper: */ 231 setCurrentItem(navigationList().at(iItemIndex)); 232 } 233 else 234 AssertMsgFailed(("Passed index out of bounds!")); 256 /* Call for wrapper above: */ 257 setCurrentItems(QList<UIGChooserItem*>() << pItem); 258 /* Move focus to current-item: */ 259 setFocusItem(currentItem()); 235 260 } 236 261 … … 263 288 } 264 289 265 /* Some item found? */ 266 if (pItem) 267 { 268 /* This item should be in navigation list: */ 269 AssertMsg(navigationList().contains(pItem), 270 ("Passed item is NOT in navigation list!")); 271 /* Make this item current: */ 272 setCurrentItem(pItem); 273 } 290 /* Make sure found item is in navigation list: */ 291 if (!pItem || !navigationList().contains(pItem)) 292 return; 293 294 /* Call for wrapper above: */ 295 setCurrentItem(pItem); 274 296 } 275 297 276 298 void UIGChooserModel::unsetCurrentItem() 277 299 { 278 /* C lear focus/selection: */279 set FocusItem(0, true);300 /* Call for wrapper above: */ 301 setCurrentItem(0); 280 302 } 281 303 282 304 void UIGChooserModel::addToCurrentItems(UIGChooserItem *pItem) 283 305 { 284 AssertMsg(pItem, ("Passed item is invalid!")); 285 m_currentItems << pItem; 286 pItem->update(); 306 /* Call for wrapper above: */ 307 setCurrentItems(QList<UIGChooserItem*>(m_currentItems) << pItem); 287 308 } 288 309 289 310 void UIGChooserModel::removeFromCurrentItems(UIGChooserItem *pItem) 290 311 { 291 AssertMsg(pItem, ("Passed item is invalid!")); 292 m_currentItems.removeAll(pItem); 293 pItem->update(); 312 /* Prepare filtered list: */ 313 QList<UIGChooserItem*> list(m_currentItems); 314 list.removeAll(pItem); 315 /* Call for wrapper above: */ 316 setCurrentItems(list); 294 317 } 295 318 … … 306 329 /* Make sure selection item list is never empty 307 330 * if at least one item (for example 'focus') present: */ 308 if ( currentItems().isEmpty() && focusItem())309 addToCurrentItems(focusItem());331 if (!currentItem() && focusItem()) 332 setCurrentItem(focusItem()); 310 333 /* Notify listeners about selection change: */ 311 334 emit sigSelectionChanged(); … … 350 373 } 351 374 352 void UIGChooserModel::setFocusItem(UIGChooserItem *pItem , bool fWithSelection /* = false */)375 void UIGChooserModel::setFocusItem(UIGChooserItem *pItem) 353 376 { 354 377 /* Make sure real focus unset: */ 355 378 clearRealFocus(); 356 379 357 /* Something changed? */ 358 if (m_pFocusItem != pItem || !pItem) 359 { 360 /* Remember previous focus item: */ 361 QPointer<UIGChooserItem> pPreviousFocusItem = m_pFocusItem; 362 /* Set new focus item: */ 363 m_pFocusItem = pItem; 364 365 /* Should we move selection too? */ 366 if (fWithSelection) 367 { 368 /* Clear selection: */ 369 clearSelectionList(); 370 /* Add focus item into selection (if any): */ 371 if (m_pFocusItem) 372 addToCurrentItems(m_pFocusItem); 373 /* Notify selection changed: */ 374 notifyCurrentItemChanged(); 375 } 376 377 /* Update previous focus item (if any): */ 378 if (pPreviousFocusItem) 379 { 380 disconnect(pPreviousFocusItem, SIGNAL(destroyed(QObject*)), this, SLOT(sltFocusItemDestroyed())); 381 pPreviousFocusItem->update(); 382 } 383 /* Update new focus item (if any): */ 384 if (m_pFocusItem) 385 { 386 connect(m_pFocusItem, SIGNAL(destroyed(QObject*)), this, SLOT(sltFocusItemDestroyed())); 387 m_pFocusItem->update(); 388 } 389 390 /* Notify focus changed: */ 391 emit sigFocusChanged(m_pFocusItem); 392 } 380 /* Is there something changed? */ 381 if (m_pFocusItem == pItem) 382 return; 383 384 /* Remember old focus-item: */ 385 UIGChooserItem *pOldFocusItem = m_pFocusItem; 386 387 /* Set new focus-item: */ 388 m_pFocusItem = pItem; 389 390 /* Disconnect old focus-item (if any): */ 391 if (pOldFocusItem) 392 disconnect(pOldFocusItem, SIGNAL(destroyed(QObject*)), this, SLOT(sltFocusItemDestroyed())); 393 /* Connect new focus item (if any): */ 394 if (m_pFocusItem) 395 connect(m_pFocusItem, SIGNAL(destroyed(QObject*)), this, SLOT(sltFocusItemDestroyed())); 396 397 /* Notify listeners about focus change: */ 398 emit sigFocusChanged(m_pFocusItem); 393 399 } 394 400 … … 602 608 updateNavigation(); 603 609 updateLayout(); 604 /* Make sure focus-item present, if possible: */605 if (!focusItem() && currentItem())606 setFocusItem(currentItem());607 610 /* Make sure current-item present, if possible: */ 608 611 if (!currentItem() && !navigationList().isEmpty()) 609 setCurrentItem(0); 612 setCurrentItem(navigationList().first()); 613 /* Make sure focus-item present, if possible: */ 614 else if (!focusItem() && currentItem()) 615 setFocusItem(currentItem()); 610 616 /* Notify about current-item change: */ 611 617 notifyCurrentItemChanged(); … … 672 678 else 673 679 { 674 if ( root()->hasItems())675 setCurrentItem( root()->items().first());680 if (!navigationList().isEmpty()) 681 setCurrentItem(navigationList().first()); 676 682 else 677 683 unsetCurrentItem(); … … 814 820 updateNavigation(); 815 821 updateLayout(); 816 setCurrentItem( 0);822 setCurrentItem(navigationList().first()); 817 823 saveGroupSettings(); 818 824 } … … 1204 1210 setCurrentItem(vboxGlobal().virtualBox().GetExtraData(GUI_LastItemSelected)); 1205 1211 if (!currentItem() && !navigationList().isEmpty()) 1206 setCurrentItem( 0);1212 setCurrentItem(navigationList().first()); 1207 1213 } 1208 1214 … … 1580 1586 updateLayout(); 1581 1587 if (!navigationList().isEmpty()) 1582 setCurrentItem( 0);1588 setCurrentItem(navigationList().first()); 1583 1589 else 1584 1590 unsetCurrentItem(); -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h
r43544 r43552 114 114 UIGChooserItem* currentItem() const; 115 115 const QList<UIGChooserItem*>& currentItems() const; 116 void setCurrentItems(const QList<UIGChooserItem*> &items); 116 117 void setCurrentItem(UIGChooserItem *pItem); 117 void setCurrentItem(int iItemIndex);118 118 void setCurrentItem(const QString &strDefinition); 119 119 void unsetCurrentItem(); … … 127 127 /* API: Focus-item stuff: */ 128 128 UIGChooserItem* focusItem() const; 129 void setFocusItem(UIGChooserItem *pItem , bool fWithSelection = false);129 void setFocusItem(UIGChooserItem *pItem); 130 130 131 131 /* API: Root-item stuff: */
Note:
See TracChangeset
for help on using the changeset viewer.