Changeset 561 for trunk/src/gui/widgets/qcombobox.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/widgets/qcombobox.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 60 60 #include "qinputcontext.h" 61 61 #endif 62 62 63 #include <private/qcombobox_p.h> 63 64 #include <private/qabstractitemmodel_p.h> 64 65 #include <private/qabstractscrollarea_p.h> 66 65 67 #include <qdebug.h> 66 67 68 #ifdef Q_WS_X11 68 69 #include <private/qt_x11_p.h> … … 77 78 #endif 78 79 QT_BEGIN_NAMESPACE 79 80 extern QHash<QByteArray, QFont> *qt_app_fonts_hash();81 80 82 81 QComboBoxPrivate::QComboBoxPrivate() … … 150 149 151 150 // Make sure fonts set on the combo box also overrides the font for the popup menu. 152 if (mCombo->testAttribute(Qt::WA_SetFont) || mCombo->testAttribute(Qt::WA_MacSmallSize) 153 || mCombo->testAttribute(Qt::WA_MacMiniSize)) 151 if (mCombo->testAttribute(Qt::WA_SetFont) 152 || mCombo->testAttribute(Qt::WA_MacSmallSize) 153 || mCombo->testAttribute(Qt::WA_MacMiniSize) 154 || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont())) 154 155 menuOption.font = mCombo->font(); 155 156 else … … 192 193 updateLineEditGeometry(); 193 194 } 195 196 194 197 q->update(); 195 198 } … … 314 317 315 318 // height 316 sh.setHeight(qMax(fm. lineSpacing(), 14) + 2);319 sh.setHeight(qMax(fm.(), 14) + 2); 317 320 if (hasIcon) { 318 321 sh.setHeight(qMax(sh.height(), iconSize.height() + 2)); … … 487 490 488 491 /* 489 Sets currentIndex on entered if the LeftButton is not pressed. This490 means that if mouseTracking(...) is on, we setCurrentIndex and select491 even when LeftButton is not pressed.492 */493 void QComboBoxPrivateContainer::setCurrentIndex(const QModelIndex &index)494 {495 if (QComboBoxDelegate::isSeparator(index))496 return;497 view->setCurrentIndex(index);498 }499 500 /*501 492 Returns the item view used for the combobox popup. 502 493 */ … … 523 514 this, SLOT(updateScrollers())); 524 515 #endif 525 disconnect(view, SIGNAL(entered(QModelIndex)),526 this, SLOT(setCurrentIndex(QModelIndex)));527 516 disconnect(view, SIGNAL(destroyed()), 528 517 this, SLOT(viewDestroyed())); 518 529 519 delete view; 530 520 view = 0; … … 560 550 this, SLOT(updateScrollers())); 561 551 #endif 562 connect(view, SIGNAL(entered(QModelIndex)),563 this, SLOT(setCurrentIndex(QModelIndex)));564 552 connect(view, SIGNAL(destroyed()), 565 553 this, SLOT(viewDestroyed())); 554 555 556 557 558 559 560 566 561 } 567 562 … … 639 634 case Qt::Key_F4: 640 635 case Qt::Key_Escape: 641 #ifdef QT_KEYPAD_NAVIGATION642 case Qt::Key_Back:643 #endif644 636 combo->hidePopup(); 645 637 return true; … … 648 640 } 649 641 break; 650 case QEvent::MouseMove: {642 case QEvent::MouseMove: 651 643 if (isVisible()) { 652 644 QMouseEvent *m = static_cast<QMouseEvent *>(e); … … 655 647 if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive()) 656 648 blockMouseReleaseTimer.stop(); 649 650 651 652 653 657 654 } 658 655 break; 659 }660 656 case QEvent::MouseButtonRelease: { 661 657 QMouseEvent *m = static_cast<QMouseEvent *>(e); … … 863 859 864 860 \ingroup basicwidgets 865 \mainclass 861 866 862 867 863 A QComboBox provides a means of presenting a list of options to the user … … 936 932 setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem); 937 933 q->setModel(new QStandardItemModel(0, 1, q)); 938 q->setAttribute(Qt::WA_InputMethodEnabled); 934 if (!q->isEditable()) 935 q->setAttribute(Qt::WA_InputMethodEnabled, false); 936 else 937 q->setAttribute(Qt::WA_InputMethodEnabled); 939 938 } 940 939 … … 948 947 container->itemView()->setModel(model); 949 948 container->itemView()->setTextElideMode(Qt::ElideMiddle); 950 updateDelegate( );949 updateDelegate(); 951 950 updateLayoutDirection(); 951 952 952 QObject::connect(container, SIGNAL(itemSelected(QModelIndex)), 953 953 q, SLOT(_q_itemSelected(QModelIndex))); … … 986 986 } 987 987 988 void QComboBoxPrivate::_q_rowsAboutToBeInserted(const QModelIndex & parent,989 int /*start*/, int /*end*/)990 {991 if (parent != root)992 return;993 indexBeforeChange = currentIndex.row();994 }995 996 988 void QComboBoxPrivate::_q_rowsInserted(const QModelIndex &parent, int start, int end) 997 989 { … … 1016 1008 } 1017 1009 1018 void QComboBoxPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &parent, int /*start*/, int /*end*/) 1019 { 1020 if (parent != root) 1021 return; 1022 1010 void QComboBoxPrivate::_q_updateIndexBeforeChange() 1011 { 1023 1012 indexBeforeChange = currentIndex.row(); 1024 1013 } … … 1051 1040 } 1052 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1053 1063 1054 1064 /*! … … 1105 1115 } 1106 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1107 1143 void QComboBoxPrivate::_q_returnPressed() 1108 1144 { … … 1117 1153 int index = -1; 1118 1154 if (!duplicatesEnabled) { 1119 // Base how duplicates are determined on the autocompletion case sensitivity 1120 Qt::MatchFlags flags = Qt::MatchFixedString; 1121 #ifndef QT_NO_COMPLETER 1122 if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive) 1123 #endif 1124 flags |= Qt::MatchCaseSensitive; 1125 index = q->findText(text, flags); 1155 index = q->findText(text, matchFlags()); 1126 1156 if (index != -1) { 1127 1157 q->setCurrentIndex(index); … … 1225 1255 Q_D(QComboBox); 1226 1256 1227 disconnect(d->model, SIGNAL(destroyed()), 1228 this, SLOT(_q_modelDestroyed())); 1257 QT_TRY { 1258 disconnect(d->model, SIGNAL(destroyed()), 1259 this, SLOT(_q_modelDestroyed())); 1260 } QT_CATCH(...) { 1261 ; // objects can't throw in destructor 1262 } 1229 1263 } 1230 1264 … … 1568 1602 } 1569 1603 1570 void QComboBoxPrivate::updateDelegate() 1604 /*! \internal 1605 update the default delegate 1606 depending on the style's SH_ComboBox_Popup hint, we use a different default delegate. 1607 1608 but we do not change the delegate is the combobox use a custom delegate, 1609 unless \a force is set to true. 1610 */ 1611 void QComboBoxPrivate::updateDelegate(bool force) 1571 1612 { 1572 1613 Q_Q(QComboBox); 1573 1614 QStyleOptionComboBox opt; 1574 1615 q->initStyleOption(&opt); 1575 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) 1576 q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); 1577 else 1578 q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); 1616 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) { 1617 if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate())) 1618 q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); 1619 } else { 1620 if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate())) 1621 q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); 1622 } 1579 1623 } 1580 1624 … … 1644 1688 d->lineEdit->setParent(this); 1645 1689 connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed())); 1690 1646 1691 connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString))); 1647 1692 #ifdef QT3_SUPPORT … … 1827 1872 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); 1828 1873 disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), 1829 this, SLOT(_q_ rowsAboutToBeInserted(QModelIndex,int,int)));1874 this, SLOT(_q_))); 1830 1875 disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), 1831 1876 this, SLOT(_q_rowsInserted(QModelIndex,int,int))); 1832 1877 disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), 1833 this, SLOT(_q_ rowsAboutToBeRemoved(QModelIndex,int,int)));1878 this, SLOT(_q_))); 1834 1879 disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), 1835 1880 this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); 1836 1881 disconnect(d->model, SIGNAL(destroyed()), 1837 1882 this, SLOT(_q_modelDestroyed())); 1883 1884 1838 1885 disconnect(d->model, SIGNAL(modelReset()), 1839 1886 this, SLOT(_q_modelReset())); … … 1847 1894 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); 1848 1895 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), 1849 this, SLOT(_q_ rowsAboutToBeInserted(QModelIndex,int,int)));1896 this, SLOT(_q_))); 1850 1897 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), 1851 1898 this, SLOT(_q_rowsInserted(QModelIndex,int,int))); 1852 1899 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), 1853 this, SLOT(_q_ rowsAboutToBeRemoved(QModelIndex,int,int)));1900 this, SLOT(_q_))); 1854 1901 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), 1855 1902 this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); 1856 1903 connect(model, SIGNAL(destroyed()), 1857 1904 this, SLOT(_q_modelDestroyed())); 1905 1906 1858 1907 connect(model, SIGNAL(modelReset()), 1859 1908 this, SLOT(_q_modelReset())); … … 1936 1985 QString newText = q->itemText(currentIndex.row()); 1937 1986 if (lineEdit->text() != newText) 1938 lineEdit->setText( q->itemText(currentIndex.row()));1987 lineEdit->setText(); 1939 1988 updateLineEditGeometry(); 1940 1989 } … … 2133 2182 Removes the item at the given \a index from the combobox. 2134 2183 This will update the current index if the index is removed. 2184 2185 2135 2186 */ 2136 2187 void QComboBox::removeItem(int index) 2137 2188 { 2138 Q_ASSERT(index >= 0 && index < count()); 2139 Q_D(QComboBox); 2189 Q_D(QComboBox); 2190 if (index < 0 || index >= count()) 2191 return; 2140 2192 d->model->removeRows(index, 1, d->root); 2141 2193 } … … 2402 2454 container->setGeometry(listRect); 2403 2455 2404 bool updatesEnabled = container->updatesEnabled(); 2456 #ifndef Q_WS_MAC 2457 const bool updatesEnabled = container->updatesEnabled(); 2458 #endif 2459 2405 2460 #if defined(Q_WS_WIN) && !defined(QT_NO_EFFECTS) 2406 2461 bool scrollDown = (listRect.topLeft() == below); 2407 if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo) 2462 if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo) 2408 2463 && !style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this) && !window()->testAttribute(Qt::WA_DontShowOnScreen)) 2409 2464 qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150); 2410 2465 #endif 2466 2467 2468 2469 2470 2471 2472 2411 2473 container->setUpdatesEnabled(false); 2474 2475 2412 2476 container->raise(); 2413 2477 container->show(); … … 2420 2484 : QAbstractItemView::EnsureVisible); 2421 2485 2486 2422 2487 container->setUpdatesEnabled(updatesEnabled); 2488 2489 2423 2490 container->update(); 2491 2492 2493 2494 2424 2495 } 2425 2496 … … 2573 2644 break; 2574 2645 case QEvent::PaletteChange: { 2575 QStyleOptionComboBox opt; 2576 initStyleOption(&opt); 2577 #ifndef QT_NO_MENU 2578 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) { 2579 QMenu menu; 2580 menu.ensurePolished(); 2581 d->viewContainer()->setPalette(menu.palette()); 2582 d->viewContainer()->setWindowOpacity(menu.windowOpacity()); 2583 } else 2584 #endif 2585 { 2586 d->viewContainer()->setPalette(palette()); 2587 d->viewContainer()->setWindowOpacity(1.0); 2588 } 2646 d->updateViewContainerPaletteAndOpacity(); 2589 2647 break; 2590 2648 }
Note:
See TracChangeset
for help on using the changeset viewer.