Changeset 43631 in vbox
- Timestamp:
- Oct 12, 2012 12:03:00 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserHandlerKeyboard.cpp
r43614 r43631 30 30 , m_pModel(pParent) 31 31 { 32 /* Setup shift map: */ 33 m_shiftMap[Qt::Key_Up] = UIItemShiftSize_Item; 34 m_shiftMap[Qt::Key_Down] = UIItemShiftSize_Item; 35 m_shiftMap[Qt::Key_Home] = UIItemShiftSize_Full; 36 m_shiftMap[Qt::Key_End] = UIItemShiftSize_Full; 32 37 } 33 38 … … 71 76 #endif /* !Q_WS_MAC */ 72 77 { 73 /* Get focus and his parent: */ 74 UIGChooserItem *pFocusItem = model()->focusItem(); 75 UIGChooserItem *pParentItem = pFocusItem->parentItem(); 76 UIGChooserItemType type = (UIGChooserItemType)pFocusItem->type(); 77 QList<UIGChooserItem*> items = pParentItem->items(type); 78 int iFocusPosition = items.indexOf(pFocusItem); 79 if (iFocusPosition > 0) 80 { 81 if (pEvent->key() == Qt::Key_Up) 82 items.move(iFocusPosition, iFocusPosition - 1); 83 else if (pEvent->key() == Qt::Key_Home) 84 items.move(iFocusPosition, 0); 85 pParentItem->setItems(items, type); 86 model()->updateNavigation(); 87 model()->updateLayout(); 88 } 89 /* Filter-out this event: */ 78 /* Shift item up: */ 79 shift(UIItemShiftDirection_Up, m_shiftMap[pEvent->key()]); 90 80 return true; 91 81 } 82 92 83 /* Was shift modifier pressed? */ 93 84 #ifdef Q_WS_MAC … … 133 124 } 134 125 } 126 135 127 /* There is no modifiers pressed? */ 136 128 #ifdef Q_WS_MAC … … 181 173 #endif /* !Q_WS_MAC */ 182 174 { 183 /* Get focus and his parent: */ 184 UIGChooserItem *pFocusItem = model()->focusItem(); 185 UIGChooserItem *pParentItem = pFocusItem->parentItem(); 186 UIGChooserItemType type = (UIGChooserItemType)pFocusItem->type(); 187 QList<UIGChooserItem*> items = pParentItem->items(type); 188 int iFocusPosition = items.indexOf(pFocusItem); 189 if (iFocusPosition < items.size() - 1) 190 { 191 if (pEvent->key() == Qt::Key_Down) 192 items.move(iFocusPosition, iFocusPosition + 1); 193 else if (pEvent->key() == Qt::Key_End) 194 items.move(iFocusPosition, items.size() - 1); 195 pParentItem->setItems(items, type); 196 model()->updateNavigation(); 197 model()->updateLayout(); 198 } 199 /* Filter-out this event: */ 175 /* Shift item down: */ 176 shift(UIItemShiftDirection_Down, m_shiftMap[pEvent->key()]); 200 177 return true; 201 178 } 179 202 180 /* Was shift modifier pressed? */ 203 181 #ifdef Q_WS_MAC … … 243 221 } 244 222 } 223 245 224 /* There is no modifiers pressed? */ 246 225 #ifdef Q_WS_MAC … … 384 363 } 385 364 365 void UIGChooserHandlerKeyboard::shift(UIItemShiftDirection direction, UIItemShiftSize size) const 366 { 367 /* Get focus-item and his parent: */ 368 UIGChooserItem *pFocusItem = model()->focusItem(); 369 UIGChooserItem *pParentItem = pFocusItem->parentItem(); 370 /* Get the list of focus-item neighbours: */ 371 UIGChooserItemType type = (UIGChooserItemType)pFocusItem->type(); 372 QList<UIGChooserItem*> items = pParentItem->items(type); 373 /* Get focus-item position: */ 374 int iFocusPosition = items.indexOf(pFocusItem); 375 376 /* Depending on direction: */ 377 switch (direction) 378 { 379 case UIItemShiftDirection_Up: 380 { 381 /* Is focus-item shiftable? */ 382 if (iFocusPosition == 0) 383 return; 384 /* Shift item: */ 385 switch (size) 386 { 387 case UIItemShiftSize_Item: items.move(iFocusPosition, iFocusPosition - 1); break; 388 case UIItemShiftSize_Full: items.move(iFocusPosition, 0); break; 389 default: break; 390 } 391 break; 392 } 393 case UIItemShiftDirection_Down: 394 { 395 /* Is focus-item shiftable? */ 396 if (iFocusPosition == items.size() - 1) 397 return; 398 /* Shift item: */ 399 switch (size) 400 { 401 case UIItemShiftSize_Item: items.move(iFocusPosition, iFocusPosition + 1); break; 402 case UIItemShiftSize_Full: items.move(iFocusPosition, items.size() - 1); break; 403 default: break; 404 } 405 break; 406 } 407 default: 408 break; 409 } 410 411 /* Reassign items: */ 412 pParentItem->setItems(items, type); 413 /* Update model: */ 414 model()->updateNavigation(); 415 model()->updateLayout(); 416 } 417 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserHandlerKeyboard.h
r42529 r43631 22 22 /* Qt includes: */ 23 23 #include <QObject> 24 #include <QMap> 24 25 25 26 /* Forward declarations: */ … … 32 33 UIKeyboardEventType_Press, 33 34 UIKeyboardEventType_Release 35 }; 36 37 /* Item shift direction: */ 38 enum UIItemShiftDirection 39 { 40 UIItemShiftDirection_Up, 41 UIItemShiftDirection_Down 42 }; 43 44 /* Item shift size: */ 45 enum UIItemShiftSize 46 { 47 UIItemShiftSize_Item, 48 UIItemShiftSize_Full 34 49 }; 35 50 … … 56 71 bool handleKeyRelease(QKeyEvent *pEvent) const; 57 72 73 /* Helper: Item shift delegate: */ 74 void shift(UIItemShiftDirection direction, UIItemShiftSize size) const; 75 58 76 /* Variables: */ 59 77 UIGChooserModel *m_pModel; 78 QMap<int, UIItemShiftSize> m_shiftMap; 60 79 }; 61 80
Note:
See TracChangeset
for help on using the changeset viewer.