src/gui/itemviews/qabstractitemview.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   144 {
   144 {
   145     Q_Q(QAbstractItemView);
   145     Q_Q(QAbstractItemView);
   146     if (hover == index)
   146     if (hover == index)
   147         return;
   147         return;
   148 
   148 
   149     q->update(hover); //update the old one
   149     if (selectionBehavior != QAbstractItemView::SelectRows) {
       
   150         q->update(hover); //update the old one
       
   151         q->update(index); //update the new one
       
   152     } else {
       
   153         QRect oldHoverRect = q->visualRect(hover);
       
   154         QRect newHoverRect = q->visualRect(index);
       
   155         viewport->update(QRect(0, newHoverRect.y(), viewport->width(), newHoverRect.height()));
       
   156         viewport->update(QRect(0, oldHoverRect.y(), viewport->width(), oldHoverRect.height()));
       
   157     }
   150     hover = index;
   158     hover = index;
   151     q->update(hover); //update the new one
       
   152 }
   159 }
   153 
   160 
   154 void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index)
   161 void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index)
   155 {
   162 {
   156     //we take a persistent model index because the model might change by emitting signals
   163     //we take a persistent model index because the model might change by emitting signals
  1531         d->checkPersistentEditorFocus();
  1538         d->checkPersistentEditorFocus();
  1532         break;
  1539         break;
  1533     case QEvent::FontChange:
  1540     case QEvent::FontChange:
  1534         d->doDelayedItemsLayout(); // the size of the items will change
  1541         d->doDelayedItemsLayout(); // the size of the items will change
  1535         break;
  1542         break;
       
  1543 #ifdef QT_SOFTKEYS_ENABLED
       
  1544     case QEvent::LanguageChange:
       
  1545         d->doneSoftKey->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::DoneSoftKey));
       
  1546         break;
       
  1547 #endif
  1536     default:
  1548     default:
  1537         break;
  1549         break;
  1538     }
  1550     }
  1539     return QAbstractScrollArea::event(event);
  1551     return QAbstractScrollArea::event(event);
  1540 }
  1552 }
  2105 void QAbstractItemView::focusOutEvent(QFocusEvent *event)
  2117 void QAbstractItemView::focusOutEvent(QFocusEvent *event)
  2106 {
  2118 {
  2107     Q_D(QAbstractItemView);
  2119     Q_D(QAbstractItemView);
  2108     QAbstractScrollArea::focusOutEvent(event);
  2120     QAbstractScrollArea::focusOutEvent(event);
  2109     d->viewport->update();
  2121     d->viewport->update();
       
  2122 
       
  2123 #ifdef QT_SOFTKEYS_ENABLED
       
  2124     if(!hasEditFocus())
       
  2125         removeAction(d->doneSoftKey);
       
  2126 #endif
  2110 }
  2127 }
  2111 
  2128 
  2112 /*!
  2129 /*!
  2113     This function is called with the given \a event when a key event is sent to
  2130     This function is called with the given \a event when a key event is sent to
  2114     the widget. The default implementation handles basic cursor movement, e.g. Up,
  2131     the widget. The default implementation handles basic cursor movement, e.g. Up,
  2130     case Qt::Key_Select:
  2147     case Qt::Key_Select:
  2131         if (QApplication::keypadNavigationEnabled()) {
  2148         if (QApplication::keypadNavigationEnabled()) {
  2132             if (!hasEditFocus()) {
  2149             if (!hasEditFocus()) {
  2133                 setEditFocus(true);
  2150                 setEditFocus(true);
  2134 #ifdef QT_SOFTKEYS_ENABLED
  2151 #ifdef QT_SOFTKEYS_ENABLED
  2135                 addAction(d->doneSoftKey);
  2152                 // If we can't keypad navigate to any direction, there is no sense to add
       
  2153                 // "Done" softkey, since it basically does nothing when there is
       
  2154                 // only one widget in screen
       
  2155                 if(QWidgetPrivate::canKeypadNavigate(Qt::Horizontal)
       
  2156                         || QWidgetPrivate::canKeypadNavigate(Qt::Vertical))
       
  2157                     addAction(d->doneSoftKey);
  2136 #endif
  2158 #endif
  2137                 return;
  2159                 return;
  2138             }
  2160             }
  2139         }
  2161         }
  2140         break;
  2162         break;
  2146             setEditFocus(false);
  2168             setEditFocus(false);
  2147         } else {
  2169         } else {
  2148             event->ignore();
  2170             event->ignore();
  2149         }
  2171         }
  2150         return;
  2172         return;
       
  2173     case Qt::Key_Down:
       
  2174     case Qt::Key_Up:
       
  2175         // Let's ignore vertical navigation events, only if there is no other widget
       
  2176         // what can take the focus in vertical direction. This means widget can handle navigation events
       
  2177         // even the widget don't have edit focus, and there is no other widget in requested direction.
       
  2178         if(QApplication::keypadNavigationEnabled() && !hasEditFocus()
       
  2179                 && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
       
  2180             event->ignore();
       
  2181             return;
       
  2182         }
       
  2183         break;
       
  2184     case Qt::Key_Left:
       
  2185     case Qt::Key_Right:
       
  2186         // Similar logic as in up and down events
       
  2187         if(QApplication::keypadNavigationEnabled() && !hasEditFocus()
       
  2188                 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this))) {
       
  2189             event->ignore();
       
  2190             return;
       
  2191         }
       
  2192         break;
  2151     default:
  2193     default:
  2152         if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
  2194         if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
  2153             event->ignore();
  2195             event->ignore();
  2154             return;
  2196             return;
  2155         }
  2197         }
  2231     switch (event->key()) {
  2273     switch (event->key()) {
  2232     // ignored keys
  2274     // ignored keys
  2233     case Qt::Key_Down:
  2275     case Qt::Key_Down:
  2234     case Qt::Key_Up:
  2276     case Qt::Key_Up:
  2235 #ifdef QT_KEYPAD_NAVIGATION
  2277 #ifdef QT_KEYPAD_NAVIGATION
  2236         if (QApplication::keypadNavigationEnabled()) {
  2278         if (QApplication::keypadNavigationEnabled() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
  2237             event->accept(); // don't change focus
  2279             event->accept(); // don't change focus
  2238             break;
  2280             break;
  2239         }
  2281         }
  2240 #endif
  2282 #endif
  2241     case Qt::Key_Left:
  2283     case Qt::Key_Left:
  2242     case Qt::Key_Right:
  2284     case Qt::Key_Right:
  2243 #ifdef QT_KEYPAD_NAVIGATION
  2285 #ifdef QT_KEYPAD_NAVIGATION
  2244         if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
  2286         if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
  2245             event->accept(); // don't change horizontal focus in directional mode
  2287                 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal)
       
  2288                 || (QWidgetPrivate::inTabWidget(this) && d->model->columnCount(d->root) > 1))) {
       
  2289             event->accept(); // don't change focus
  2246             break;
  2290             break;
  2247         }
  2291         }
  2248 #endif // QT_KEYPAD_NAVIGATION
  2292 #endif // QT_KEYPAD_NAVIGATION
  2249     case Qt::Key_Home:
  2293     case Qt::Key_Home:
  2250     case Qt::Key_End:
  2294     case Qt::Key_End:
  2522     if(d->editors.isEmpty())
  2566     if(d->editors.isEmpty())
  2523         return;
  2567         return;
  2524     QStyleOptionViewItemV4 option = d->viewOptionsV4();
  2568     QStyleOptionViewItemV4 option = d->viewOptionsV4();
  2525     QList<QEditorInfo>::iterator it = d->editors.begin();
  2569     QList<QEditorInfo>::iterator it = d->editors.begin();
  2526     QWidgetList editorsToRelease;
  2570     QWidgetList editorsToRelease;
       
  2571     QWidgetList editorsToHide;
  2527     while (it != d->editors.end()) {
  2572     while (it != d->editors.end()) {
  2528         QModelIndex index = it->index;
  2573         QModelIndex index = it->index;
  2529         QWidget *editor = it->editor;
  2574         QWidget *editor = it->editor;
  2530         if (index.isValid() && editor) {
  2575         if (index.isValid() && editor) {
  2531             option.rect = visualRect(index);
  2576             option.rect = visualRect(index);
  2533                 editor->show();
  2578                 editor->show();
  2534                 QAbstractItemDelegate *delegate = d->delegateForIndex(index);
  2579                 QAbstractItemDelegate *delegate = d->delegateForIndex(index);
  2535                 if (delegate)
  2580                 if (delegate)
  2536                     delegate->updateEditorGeometry(editor, option, index);
  2581                     delegate->updateEditorGeometry(editor, option, index);
  2537             } else {
  2582             } else {
  2538                 editor->hide();
  2583                 editorsToHide << editor;
  2539             }
  2584             }
  2540             ++it;
  2585             ++it;
  2541         } else {
  2586         } else {
  2542             it = d->editors.erase(it);
  2587             it = d->editors.erase(it);
  2543             editorsToRelease << editor;
  2588             editorsToRelease << editor;
  2544         }
  2589         }
  2545     }
  2590     }
  2546 
  2591 
  2547     //we release the editor outside of the loop because it might change the focus and try
  2592     //we hide and release the editor outside of the loop because it might change the focus and try
  2548     //to change the d->editors list.
  2593     //to change the d->editors list.
       
  2594     for (int i = 0; i < editorsToHide.count(); ++i) {
       
  2595         editorsToHide.at(i)->hide();
       
  2596     }
  2549     for (int i = 0; i < editorsToRelease.count(); ++i) {
  2597     for (int i = 0; i < editorsToRelease.count(); ++i) {
  2550         d->releaseEditor(editorsToRelease.at(i));
  2598         d->releaseEditor(editorsToRelease.at(i));
  2551     }
  2599     }
  2552 }
  2600 }
  2553 
  2601 
  3000 {
  3048 {
  3001     Q_D(QAbstractItemView);
  3049     Q_D(QAbstractItemView);
  3002     if (!d->isIndexValid(index))
  3050     if (!d->isIndexValid(index))
  3003         return;
  3051         return;
  3004     if (QWidget *oldWidget = indexWidget(index)) {
  3052     if (QWidget *oldWidget = indexWidget(index)) {
       
  3053         d->persistent.remove(oldWidget);
  3005         d->removeEditor(oldWidget);
  3054         d->removeEditor(oldWidget);
  3006         oldWidget->deleteLater();
  3055         oldWidget->deleteLater();
  3007     }
  3056     }
  3008     if (widget) {
  3057     if (widget) {
  3009         widget->setParent(viewport());
  3058         widget->setParent(viewport());