| 197 | } |
| 198 | |
| 199 | Uint32 UITableView::onKeyDown( const KeyEvent& event ) { |
| 200 | bool isJump = ( event.getKeyCode() == KEY_LEFT || event.getKeyCode() == KEY_RIGHT || |
| 201 | event.getKeyCode() == KEY_UP || event.getKeyCode() == KEY_DOWN ) && |
| 202 | ( event.getSanitizedMod() & KeyMod::getDefaultModifier() ); |
| 203 | if ( !isJump && ( event.getMod() & KEYMOD_CTRL_SHIFT_ALT_META ) ) |
| 204 | return UIAbstractTableView::onKeyDown( event ); |
| 205 | auto curIndex = getSelection().first(); |
| 206 | int pageSize = eefloor( getVisibleArea().getHeight() / getRowHeight() ) - 1; |
| 207 | |
| 208 | switch ( event.getKeyCode() ) { |
| 209 | case KEY_UP: { |
| 210 | // Fallback to home if using modifier key |
| 211 | if ( !( event.getSanitizedMod() & KeyMod::getDefaultModifier() ) ) { |
| 212 | if ( !getModel() || isEditing() ) |
| 213 | return 0; |
| 214 | auto& model = *this->getModel(); |
| 215 | ModelIndex foundIndex; |
| 216 | if ( !getSelection().isEmpty() ) { |
| 217 | auto oldIndex = getSelection().first(); |
| 218 | foundIndex = model.index( oldIndex.row() - 1, oldIndex.column() ); |
| 219 | } else { |
| 220 | foundIndex = model.index( |
| 221 | 0, getSelection().first().isValid() ? getSelection().first().column() : 0 ); |
| 222 | } |
| 223 | if ( model.isValid( foundIndex ) ) { |
| 224 | Float curY = getHeaderHeight() + getRowHeight() * foundIndex.row(); |
| 225 | getSelection().set( foundIndex ); |
| 226 | if ( curY < mScrollOffset.y + getHeaderHeight() + getRowHeight() || |
| 227 | curY > mScrollOffset.y + getPixelsSize().getHeight() - mPaddingPx.Top - |
| 228 | mPaddingPx.Bottom - getRowHeight() ) { |
| 229 | curY -= getHeaderHeight(); |
| 230 | mVScroll->setValue( curY / getScrollableArea().getHeight() ); |
| 231 | } |
| 232 | } |
| 233 | return 1; |
| 234 | } |
| 235 | } |
| 236 | case KEY_HOME: { |
| 237 | getSelection().set( getModel()->index( |
| 238 | 0, getSelection().first().isValid() ? getSelection().first().column() : 0 ) ); |
| 239 | scrollToTop(); |
| 240 | return 1; |
| 241 | } |
| 242 | case KEY_PAGEUP: { |
| 243 | if ( curIndex.row() - pageSize < 0 ) { |
| 244 | getSelection().set( getModel()->index( |
| 245 | 0, getSelection().first().isValid() ? getSelection().first().column() : 0 ) ); |
| 246 | scrollToTop(); |
| 247 | } else { |
| 248 | moveSelection( -pageSize ); |
| 249 | } |
| 250 | return 1; |
| 251 | } |
| 252 | case KEY_DOWN: { |
| 253 | if ( !getModel() || isEditing() ) |
| 254 | return 0; |
| 255 | // Fallback to end if using modifier key |
| 256 | if ( !( event.getSanitizedMod() & KeyMod::getDefaultModifier() ) ) { |
nothing calls this directly
no test coverage detected