0
+ − 1
/****************************************************************************
+ − 2
**
4
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
0
+ − 4
** All rights reserved.
+ − 5
** Contact: Nokia Corporation (qt-info@nokia.com)
+ − 6
**
+ − 7
** This file is part of the QtGui module of the Qt Toolkit.
+ − 8
**
+ − 9
** $QT_BEGIN_LICENSE:LGPL$
+ − 10
** No Commercial Usage
+ − 11
** This file contains pre-release code and may not be distributed.
+ − 12
** You may use this file in accordance with the terms and conditions
+ − 13
** contained in the Technology Preview License Agreement accompanying
+ − 14
** this package.
+ − 15
**
+ − 16
** GNU Lesser General Public License Usage
+ − 17
** Alternatively, this file may be used under the terms of the GNU Lesser
+ − 18
** General Public License version 2.1 as published by the Free Software
+ − 19
** Foundation and appearing in the file LICENSE.LGPL included in the
+ − 20
** packaging of this file. Please review the following information to
+ − 21
** ensure the GNU Lesser General Public License version 2.1 requirements
+ − 22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ − 23
**
+ − 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
**
+ − 28
** If you have questions regarding the use of this file, please contact
+ − 29
** Nokia at qt-info@nokia.com.
+ − 30
**
+ − 31
**
+ − 32
**
+ − 33
**
+ − 34
**
+ − 35
**
+ − 36
**
+ − 37
**
+ − 38
** $QT_END_LICENSE$
+ − 39
**
+ − 40
****************************************************************************/
+ − 41
+ − 42
#include "qcombobox.h"
+ − 43
+ − 44
#ifndef QT_NO_COMBOBOX
+ − 45
#include <qstylepainter.h>
+ − 46
#include <qlineedit.h>
+ − 47
#include <qapplication.h>
+ − 48
#include <qdesktopwidget.h>
+ − 49
#include <qlistview.h>
+ − 50
#include <qtableview.h>
+ − 51
#include <qitemdelegate.h>
+ − 52
#include <qmap.h>
+ − 53
#include <qmenu.h>
+ − 54
#include <qevent.h>
+ − 55
#include <qlayout.h>
+ − 56
#include <qscrollbar.h>
+ − 57
#include <qtreeview.h>
+ − 58
#include <qheaderview.h>
+ − 59
#ifndef QT_NO_IM
+ − 60
#include "qinputcontext.h"
+ − 61
#endif
+ − 62
#include <private/qapplication_p.h>
+ − 63
#include <private/qcombobox_p.h>
+ − 64
#include <private/qabstractitemmodel_p.h>
+ − 65
#include <private/qabstractscrollarea_p.h>
+ − 66
#include <private/qsoftkeymanager_p.h>
+ − 67
#include <qdebug.h>
+ − 68
#ifdef Q_WS_X11
+ − 69
#include <private/qt_x11_p.h>
+ − 70
#endif
+ − 71
#if defined(Q_WS_MAC) && !defined(QT_NO_EFFECTS) && !defined(QT_NO_STYLE_MAC)
+ − 72
#include <private/qcore_mac_p.h>
+ − 73
#include <QMacStyle>
+ − 74
#include <private/qt_cocoa_helpers_mac_p.h>
+ − 75
#endif
+ − 76
#ifndef QT_NO_EFFECTS
+ − 77
# include <private/qeffects_p.h>
+ − 78
#endif
13
+ − 79
#if defined(Q_WS_S60)
+ − 80
#include "private/qt_s60_p.h"
+ − 81
#endif
+ − 82
0
+ − 83
QT_BEGIN_NAMESPACE
+ − 84
+ − 85
QComboBoxPrivate::QComboBoxPrivate()
+ − 86
: QWidgetPrivate(),
+ − 87
model(0),
+ − 88
lineEdit(0),
+ − 89
container(0),
+ − 90
insertPolicy(QComboBox::InsertAtBottom),
+ − 91
sizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow),
+ − 92
minimumContentsLength(0),
+ − 93
shownOnce(false),
+ − 94
autoCompletion(true),
+ − 95
duplicatesEnabled(false),
+ − 96
frame(true),
+ − 97
maxVisibleItems(10),
+ − 98
maxCount(INT_MAX),
+ − 99
modelColumn(0),
+ − 100
inserting(false),
+ − 101
arrowState(QStyle::State_None),
+ − 102
hoverControl(QStyle::SC_None),
+ − 103
autoCompletionCaseSensitivity(Qt::CaseInsensitive),
+ − 104
indexBeforeChange(-1)
+ − 105
#ifndef QT_NO_COMPLETER
+ − 106
, completer(0)
+ − 107
#endif
+ − 108
{
+ − 109
}
+ − 110
+ − 111
QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewItem &option,
+ − 112
const QModelIndex &index) const
+ − 113
{
+ − 114
QStyleOptionMenuItem menuOption;
+ − 115
menuOption.palette = option.palette.resolve(QApplication::palette("QMenu"));
+ − 116
menuOption.state = QStyle::State_None;
+ − 117
if (mCombo->window()->isActiveWindow())
+ − 118
menuOption.state = QStyle::State_Active;
+ − 119
if ((option.state & QStyle::State_Enabled) && (index.model()->flags(index) & Qt::ItemIsEnabled))
+ − 120
menuOption.state |= QStyle::State_Enabled;
+ − 121
else
+ − 122
menuOption.palette.setCurrentColorGroup(QPalette::Disabled);
+ − 123
if (option.state & QStyle::State_Selected)
+ − 124
menuOption.state |= QStyle::State_Selected;
+ − 125
menuOption.checkType = QStyleOptionMenuItem::NonExclusive;
+ − 126
menuOption.checked = mCombo->currentIndex() == index.row();
+ − 127
if (QComboBoxDelegate::isSeparator(index))
+ − 128
menuOption.menuItemType = QStyleOptionMenuItem::Separator;
+ − 129
else
+ − 130
menuOption.menuItemType = QStyleOptionMenuItem::Normal;
+ − 131
+ − 132
QVariant variant = index.model()->data(index, Qt::DecorationRole);
+ − 133
switch (variant.type()) {
+ − 134
case QVariant::Icon:
+ − 135
menuOption.icon = qvariant_cast<QIcon>(variant);
+ − 136
break;
+ − 137
case QVariant::Color: {
+ − 138
static QPixmap pixmap(option.decorationSize);
+ − 139
pixmap.fill(qvariant_cast<QColor>(variant));
+ − 140
menuOption.icon = pixmap;
+ − 141
break; }
+ − 142
default:
+ − 143
menuOption.icon = qvariant_cast<QPixmap>(variant);
+ − 144
break;
+ − 145
}
+ − 146
+ − 147
menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()
+ − 148
.replace(QLatin1Char('&'), QLatin1String("&&"));
+ − 149
menuOption.tabWidth = 0;
+ − 150
menuOption.maxIconWidth = option.decorationSize.width() + 4;
+ − 151
menuOption.menuRect = option.rect;
+ − 152
menuOption.rect = option.rect;
+ − 153
+ − 154
// Make sure fonts set on the combo box also overrides the font for the popup menu.
+ − 155
if (mCombo->testAttribute(Qt::WA_SetFont)
+ − 156
|| mCombo->testAttribute(Qt::WA_MacSmallSize)
+ − 157
|| mCombo->testAttribute(Qt::WA_MacMiniSize)
+ − 158
|| mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont()))
+ − 159
menuOption.font = mCombo->font();
+ − 160
else
+ − 161
menuOption.font = qt_app_fonts_hash()->value("QComboMenuItem", mCombo->font());
+ − 162
+ − 163
menuOption.fontMetrics = QFontMetrics(menuOption.font);
+ − 164
+ − 165
return menuOption;
+ − 166
}
+ − 167
+ − 168
#ifdef QT_KEYPAD_NAVIGATION
+ − 169
void QComboBoxPrivate::_q_completerActivated()
+ − 170
{
+ − 171
Q_Q(QComboBox);
+ − 172
if ( QApplication::keypadNavigationEnabled()
+ − 173
&& q->isEditable()
+ − 174
&& q->completer()
+ − 175
&& q->completer()->completionMode() == QCompleter::UnfilteredPopupCompletion ) {
+ − 176
q->setEditFocus(false);
+ − 177
}
+ − 178
}
+ − 179
#endif
+ − 180
+ − 181
void QComboBoxPrivate::updateArrow(QStyle::StateFlag state)
+ − 182
{
+ − 183
Q_Q(QComboBox);
+ − 184
if (arrowState == state)
+ − 185
return;
+ − 186
arrowState = state;
+ − 187
QStyleOptionComboBox opt;
+ − 188
q->initStyleOption(&opt);
+ − 189
q->update(q->style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, q));
+ − 190
}
+ − 191
+ − 192
void QComboBoxPrivate::_q_modelReset()
+ − 193
{
+ − 194
Q_Q(QComboBox);
+ − 195
if (lineEdit) {
+ − 196
lineEdit->setText(QString());
+ − 197
updateLineEditGeometry();
+ − 198
}
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 199
if (currentIndex.row() != indexBeforeChange)
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 200
_q_emitCurrentIndexChanged(currentIndex);
0
+ − 201
q->update();
+ − 202
}
+ − 203
+ − 204
void QComboBoxPrivate::_q_modelDestroyed()
+ − 205
{
+ − 206
model = QAbstractItemModelPrivate::staticEmptyModel();
+ − 207
}
+ − 208
+ − 209
+ − 210
//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't
+ − 211
QRect QComboBoxPrivate::popupGeometry(int screen) const
+ − 212
{
+ − 213
#ifdef Q_WS_WIN
+ − 214
return QApplication::desktop()->screenGeometry(screen);
+ − 215
#elif defined Q_WS_X11
+ − 216
if (X11->desktopEnvironment == DE_KDE)
+ − 217
return QApplication::desktop()->screenGeometry(screen);
+ − 218
else
+ − 219
return QApplication::desktop()->availableGeometry(screen);
+ − 220
#else
+ − 221
return QApplication::desktop()->availableGeometry(screen);
+ − 222
#endif
+ − 223
}
+ − 224
+ − 225
bool QComboBoxPrivate::updateHoverControl(const QPoint &pos)
+ − 226
{
+ − 227
+ − 228
Q_Q(QComboBox);
+ − 229
QRect lastHoverRect = hoverRect;
+ − 230
QStyle::SubControl lastHoverControl = hoverControl;
+ − 231
bool doesHover = q->testAttribute(Qt::WA_Hover);
+ − 232
if (lastHoverControl != newHoverControl(pos) && doesHover) {
+ − 233
q->update(lastHoverRect);
+ − 234
q->update(hoverRect);
+ − 235
return true;
+ − 236
}
+ − 237
return !doesHover;
+ − 238
}
+ − 239
+ − 240
QStyle::SubControl QComboBoxPrivate::newHoverControl(const QPoint &pos)
+ − 241
{
+ − 242
Q_Q(QComboBox);
+ − 243
QStyleOptionComboBox opt;
+ − 244
q->initStyleOption(&opt);
+ − 245
opt.subControls = QStyle::SC_All;
+ − 246
hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, pos, q);
+ − 247
hoverRect = (hoverControl != QStyle::SC_None)
+ − 248
? q->style()->subControlRect(QStyle::CC_ComboBox, &opt, hoverControl, q)
+ − 249
: QRect();
+ − 250
return hoverControl;
+ − 251
}
+ − 252
+ − 253
/*
+ − 254
Computes a size hint based on the maximum width
+ − 255
for the items in the combobox.
+ − 256
*/
+ − 257
int QComboBoxPrivate::computeWidthHint() const
+ − 258
{
+ − 259
Q_Q(const QComboBox);
+ − 260
+ − 261
int width = 0;
+ − 262
const int count = q->count();
+ − 263
const int iconWidth = q->iconSize().width() + 4;
+ − 264
const QFontMetrics &fontMetrics = q->fontMetrics();
+ − 265
+ − 266
for (int i = 0; i < count; ++i) {
+ − 267
const int textWidth = fontMetrics.width(q->itemText(i));
+ − 268
if (q->itemIcon(i).isNull())
+ − 269
width = (qMax(width, textWidth));
+ − 270
else
+ − 271
width = (qMax(width, textWidth + iconWidth));
+ − 272
}
+ − 273
+ − 274
QStyleOptionComboBox opt;
+ − 275
q->initStyleOption(&opt);
+ − 276
QSize tmp(width, 0);
+ − 277
tmp = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, tmp, q);
+ − 278
return tmp.width();
+ − 279
}
+ − 280
+ − 281
QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const
+ − 282
{
+ − 283
Q_Q(const QComboBox);
+ − 284
if (!sh.isValid()) {
+ − 285
bool hasIcon = sizeAdjustPolicy == QComboBox::AdjustToMinimumContentsLengthWithIcon ? true : false;
+ − 286
int count = q->count();
+ − 287
QSize iconSize = q->iconSize();
+ − 288
const QFontMetrics &fm = q->fontMetrics();
+ − 289
+ − 290
// text width
+ − 291
if (&sh == &sizeHint || minimumContentsLength == 0) {
+ − 292
switch (sizeAdjustPolicy) {
+ − 293
case QComboBox::AdjustToContents:
+ − 294
case QComboBox::AdjustToContentsOnFirstShow:
+ − 295
if (count == 0) {
+ − 296
sh.rwidth() = 7 * fm.width(QLatin1Char('x'));
+ − 297
} else {
+ − 298
for (int i = 0; i < count; ++i) {
+ − 299
if (!q->itemIcon(i).isNull()) {
+ − 300
hasIcon = true;
+ − 301
sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width() + iconSize.width() + 4));
+ − 302
} else {
+ − 303
sh.setWidth(qMax(sh.width(), fm.boundingRect(q->itemText(i)).width()));
+ − 304
}
+ − 305
}
+ − 306
}
+ − 307
break;
+ − 308
case QComboBox::AdjustToMinimumContentsLength:
+ − 309
for (int i = 0; i < count && !hasIcon; ++i)
+ − 310
hasIcon = !q->itemIcon(i).isNull();
+ − 311
default:
+ − 312
;
+ − 313
}
+ − 314
} else {
+ − 315
for (int i = 0; i < count && !hasIcon; ++i)
+ − 316
hasIcon = !q->itemIcon(i).isNull();
+ − 317
}
+ − 318
if (minimumContentsLength > 0)
+ − 319
sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0)));
+ − 320
+ − 321
+ − 322
// height
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 323
sh.setHeight(qMax(fm.height(), 14) + 2);
0
+ − 324
if (hasIcon) {
+ − 325
sh.setHeight(qMax(sh.height(), iconSize.height() + 2));
+ − 326
}
+ − 327
+ − 328
// add style and strut values
+ − 329
QStyleOptionComboBox opt;
+ − 330
q->initStyleOption(&opt);
+ − 331
sh = q->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh, q);
+ − 332
}
+ − 333
return sh.expandedTo(QApplication::globalStrut());
+ − 334
}
+ − 335
+ − 336
void QComboBoxPrivate::adjustComboBoxSize()
+ − 337
{
+ − 338
viewContainer()->adjustSizeTimer.start(20, container);
+ − 339
}
+ − 340
+ − 341
void QComboBoxPrivate::updateLayoutDirection()
+ − 342
{
+ − 343
Q_Q(const QComboBox);
+ − 344
QStyleOptionComboBox opt;
+ − 345
q->initStyleOption(&opt);
+ − 346
Qt::LayoutDirection dir = Qt::LayoutDirection(
+ − 347
q->style()->styleHint(QStyle::SH_ComboBox_LayoutDirection, &opt, q));
+ − 348
if (lineEdit)
+ − 349
lineEdit->setLayoutDirection(dir);
+ − 350
if (container)
+ − 351
container->setLayoutDirection(dir);
+ − 352
}
+ − 353
+ − 354
+ − 355
void QComboBoxPrivateContainer::timerEvent(QTimerEvent *timerEvent)
+ − 356
{
+ − 357
if (timerEvent->timerId() == adjustSizeTimer.timerId()) {
+ − 358
adjustSizeTimer.stop();
+ − 359
if (combo->sizeAdjustPolicy() == QComboBox::AdjustToContents) {
+ − 360
combo->adjustSize();
+ − 361
combo->update();
+ − 362
}
+ − 363
}
+ − 364
}
+ − 365
+ − 366
void QComboBoxPrivateContainer::resizeEvent(QResizeEvent *e)
+ − 367
{
+ − 368
QStyleOptionComboBox opt = comboStyleOption();
+ − 369
if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)) {
+ − 370
QStyleOption myOpt;
+ − 371
myOpt.initFrom(this);
+ − 372
QStyleHintReturnMask mask;
+ − 373
if (combo->style()->styleHint(QStyle::SH_Menu_Mask, &myOpt, this, &mask)) {
+ − 374
setMask(mask.region);
+ − 375
}
+ − 376
} else {
+ − 377
clearMask();
+ − 378
}
+ − 379
QFrame::resizeEvent(e);
+ − 380
}
+ − 381
+ − 382
void QComboBoxPrivateContainer::leaveEvent(QEvent *)
+ − 383
{
+ − 384
// On Mac using the Mac style we want to clear the selection
+ − 385
// when the mouse moves outside the popup.
+ − 386
#ifdef Q_WS_MAC
+ − 387
QStyleOptionComboBox opt = comboStyleOption();
+ − 388
if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo))
+ − 389
view->clearSelection();
+ − 390
#endif
+ − 391
}
+ − 392
+ − 393
QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent)
+ − 394
: QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0)
+ − 395
{
+ − 396
// we need the combobox and itemview
+ − 397
Q_ASSERT(parent);
+ − 398
Q_ASSERT(itemView);
+ − 399
+ − 400
setAttribute(Qt::WA_WindowPropagation);
+ − 401
setAttribute(Qt::WA_X11NetWmWindowTypeCombo);
+ − 402
+ − 403
// setup container
+ − 404
blockMouseReleaseTimer.setSingleShot(true);
+ − 405
+ − 406
// we need a vertical layout
+ − 407
QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+ − 408
layout->setSpacing(0);
+ − 409
layout->setMargin(0);
+ − 410
+ − 411
// set item view
+ − 412
setItemView(itemView);
+ − 413
+ − 414
// add scroller arrows if style needs them
+ − 415
QStyleOptionComboBox opt = comboStyleOption();
+ − 416
const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
+ − 417
if (usePopup) {
+ − 418
top = new QComboBoxPrivateScroller(QAbstractSlider::SliderSingleStepSub, this);
+ − 419
bottom = new QComboBoxPrivateScroller(QAbstractSlider::SliderSingleStepAdd, this);
+ − 420
top->hide();
+ − 421
bottom->hide();
+ − 422
} else {
+ − 423
setLineWidth(1);
+ − 424
}
+ − 425
+ − 426
setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));
+ − 427
+ − 428
if (top) {
+ − 429
layout->insertWidget(0, top);
+ − 430
connect(top, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int)));
+ − 431
}
+ − 432
if (bottom) {
+ − 433
layout->addWidget(bottom);
+ − 434
connect(bottom, SIGNAL(doScroll(int)), this, SLOT(scrollItemView(int)));
+ − 435
}
+ − 436
+ − 437
// Some styles (Mac) have a margin at the top and bottom of the popup.
+ − 438
layout->insertSpacing(0, 0);
+ − 439
layout->addSpacing(0);
+ − 440
updateTopBottomMargin();
+ − 441
}
+ − 442
+ − 443
void QComboBoxPrivateContainer::scrollItemView(int action)
+ − 444
{
+ − 445
#ifndef QT_NO_SCROLLBAR
+ − 446
if (view->verticalScrollBar())
+ − 447
view->verticalScrollBar()->triggerAction(static_cast<QAbstractSlider::SliderAction>(action));
+ − 448
#endif
+ − 449
}
+ − 450
+ − 451
/*
+ − 452
Hides or shows the scrollers when we emulate a popupmenu
+ − 453
*/
+ − 454
void QComboBoxPrivateContainer::updateScrollers()
+ − 455
{
+ − 456
#ifndef QT_NO_SCROLLBAR
+ − 457
if (!top || !bottom)
+ − 458
return;
+ − 459
+ − 460
if (isVisible() == false)
+ − 461
return;
+ − 462
+ − 463
QStyleOptionComboBox opt = comboStyleOption();
+ − 464
if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo) &&
+ − 465
view->verticalScrollBar()->minimum() < view->verticalScrollBar()->maximum()) {
+ − 466
+ − 467
bool needTop = view->verticalScrollBar()->value()
+ − 468
> (view->verticalScrollBar()->minimum() + spacing());
+ − 469
bool needBottom = view->verticalScrollBar()->value()
+ − 470
< (view->verticalScrollBar()->maximum() - spacing()*2);
+ − 471
if (needTop)
+ − 472
top->show();
+ − 473
else
+ − 474
top->hide();
+ − 475
if (needBottom)
+ − 476
bottom->show();
+ − 477
else
+ − 478
bottom->hide();
+ − 479
} else {
+ − 480
top->hide();
+ − 481
bottom->hide();
+ − 482
}
+ − 483
#endif // QT_NO_SCROLLBAR
+ − 484
}
+ − 485
+ − 486
/*
+ − 487
Cleans up when the view is destroyed.
+ − 488
*/
+ − 489
void QComboBoxPrivateContainer::viewDestroyed()
+ − 490
{
+ − 491
view = 0;
+ − 492
setItemView(new QComboBoxListView());
+ − 493
}
+ − 494
+ − 495
/*
+ − 496
Returns the item view used for the combobox popup.
+ − 497
*/
+ − 498
QAbstractItemView *QComboBoxPrivateContainer::itemView() const
+ − 499
{
+ − 500
return view;
+ − 501
}
+ − 502
+ − 503
/*!
+ − 504
Sets the item view to be used for the combobox popup.
+ − 505
*/
+ − 506
void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView)
+ − 507
{
+ − 508
Q_ASSERT(itemView);
+ − 509
+ − 510
// clean up old one
+ − 511
if (view) {
+ − 512
view->removeEventFilter(this);
+ − 513
view->viewport()->removeEventFilter(this);
+ − 514
#ifndef QT_NO_SCROLLBAR
+ − 515
disconnect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
+ − 516
this, SLOT(updateScrollers()));
+ − 517
disconnect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)),
+ − 518
this, SLOT(updateScrollers()));
+ − 519
#endif
+ − 520
disconnect(view, SIGNAL(destroyed()),
+ − 521
this, SLOT(viewDestroyed()));
+ − 522
+ − 523
delete view;
+ − 524
view = 0;
+ − 525
}
+ − 526
+ − 527
// setup the item view
+ − 528
view = itemView;
+ − 529
view->setParent(this);
+ − 530
view->setAttribute(Qt::WA_MacShowFocusRect, false);
+ − 531
qobject_cast<QBoxLayout*>(layout())->insertWidget(top ? 2 : 0, view);
+ − 532
view->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+ − 533
view->installEventFilter(this);
+ − 534
view->viewport()->installEventFilter(this);
+ − 535
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ − 536
QStyleOptionComboBox opt = comboStyleOption();
+ − 537
const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
+ − 538
#ifndef QT_NO_SCROLLBAR
7
+ − 539
#ifndef Q_WS_S60
0
+ − 540
if (usePopup)
+ − 541
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ − 542
#endif
7
+ − 543
#endif
0
+ − 544
if (combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
+ − 545
usePopup) {
+ − 546
view->setMouseTracking(true);
+ − 547
}
+ − 548
view->setSelectionMode(QAbstractItemView::SingleSelection);
+ − 549
view->setFrameStyle(QFrame::NoFrame);
+ − 550
view->setLineWidth(0);
+ − 551
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ − 552
#ifndef QT_NO_SCROLLBAR
+ − 553
connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
+ − 554
this, SLOT(updateScrollers()));
+ − 555
connect(view->verticalScrollBar(), SIGNAL(rangeChanged(int,int)),
+ − 556
this, SLOT(updateScrollers()));
+ − 557
#endif
+ − 558
connect(view, SIGNAL(destroyed()),
+ − 559
this, SLOT(viewDestroyed()));
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 560
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 561
#ifdef QT_SOFTKEYS_ENABLED
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 562
selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, itemView);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 563
cancelAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::CancelSoftKey, Qt::Key_Escape, itemView);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 564
addAction(selectAction);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 565
addAction(cancelAction);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 566
#endif
0
+ − 567
}
+ − 568
+ − 569
/*!
+ − 570
Returns the spacing between the items in the view.
+ − 571
*/
+ − 572
int QComboBoxPrivateContainer::spacing() const
+ − 573
{
+ − 574
QListView *lview = qobject_cast<QListView*>(view);
+ − 575
if (lview)
+ − 576
return lview->spacing();
+ − 577
#ifndef QT_NO_TABLEVIEW
+ − 578
QTableView *tview = qobject_cast<QTableView*>(view);
+ − 579
if (tview)
+ − 580
return tview->showGrid() ? 1 : 0;
+ − 581
#endif
+ − 582
return 0;
+ − 583
}
+ − 584
+ − 585
void QComboBoxPrivateContainer::updateTopBottomMargin()
+ − 586
{
+ − 587
if (!layout() || layout()->count() < 1)
+ − 588
return;
+ − 589
+ − 590
QBoxLayout *boxLayout = qobject_cast<QBoxLayout *>(layout());
+ − 591
if (!boxLayout)
+ − 592
return;
+ − 593
+ − 594
const QStyleOptionComboBox opt = comboStyleOption();
+ − 595
const bool usePopup = combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo);
+ − 596
const int margin = usePopup ? combo->style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, combo) : 0;
+ − 597
+ − 598
QSpacerItem *topSpacer = boxLayout->itemAt(0)->spacerItem();
+ − 599
if (topSpacer)
+ − 600
topSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
+ − 601
+ − 602
QSpacerItem *bottomSpacer = boxLayout->itemAt(boxLayout->count() - 1)->spacerItem();
+ − 603
if (bottomSpacer && bottomSpacer != topSpacer)
+ − 604
bottomSpacer->changeSize(0, margin, QSizePolicy::Minimum, QSizePolicy::Fixed);
+ − 605
+ − 606
boxLayout->invalidate();
+ − 607
}
+ − 608
+ − 609
void QComboBoxPrivateContainer::changeEvent(QEvent *e)
+ − 610
{
+ − 611
if (e->type() == QEvent::StyleChange) {
+ − 612
QStyleOptionComboBox opt = comboStyleOption();
+ − 613
view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) ||
+ − 614
combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo));
+ − 615
setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));
7
+ − 616
#ifdef QT_SOFTKEYS_ENABLED
+ − 617
} else if (e->type() == QEvent::LanguageChange) {
+ − 618
selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey));
+ − 619
cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey));
+ − 620
#endif
0
+ − 621
}
7
+ − 622
0
+ − 623
QWidget::changeEvent(e);
+ − 624
}
+ − 625
+ − 626
+ − 627
bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
+ − 628
{
+ − 629
switch (e->type()) {
+ − 630
case QEvent::ShortcutOverride:
+ − 631
switch (static_cast<QKeyEvent*>(e)->key()) {
+ − 632
case Qt::Key_Enter:
+ − 633
case Qt::Key_Return:
+ − 634
#ifdef QT_KEYPAD_NAVIGATION
+ − 635
case Qt::Key_Select:
+ − 636
#endif
+ − 637
if (view->currentIndex().isValid() && (view->currentIndex().flags() & Qt::ItemIsEnabled) ) {
+ − 638
combo->hidePopup();
+ − 639
emit itemSelected(view->currentIndex());
+ − 640
}
+ − 641
return true;
+ − 642
case Qt::Key_Down:
+ − 643
if (!(static_cast<QKeyEvent*>(e)->modifiers() & Qt::AltModifier))
+ − 644
break;
+ − 645
// fall through
+ − 646
case Qt::Key_F4:
+ − 647
case Qt::Key_Escape:
+ − 648
combo->hidePopup();
+ − 649
return true;
+ − 650
default:
+ − 651
break;
+ − 652
}
+ − 653
break;
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 654
case QEvent::MouseMove:
0
+ − 655
if (isVisible()) {
+ − 656
QMouseEvent *m = static_cast<QMouseEvent *>(e);
+ − 657
QWidget *widget = static_cast<QWidget *>(o);
+ − 658
QPoint vector = widget->mapToGlobal(m->pos()) - initialClickPosition;
+ − 659
if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive())
+ − 660
blockMouseReleaseTimer.stop();
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 661
QModelIndex indexUnderMouse = view->indexAt(m->pos());
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 662
if (indexUnderMouse.isValid() && indexUnderMouse != view->currentIndex()
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 663
&& !QComboBoxDelegate::isSeparator(indexUnderMouse)) {
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 664
view->setCurrentIndex(indexUnderMouse);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 665
}
0
+ − 666
}
+ − 667
break;
+ − 668
case QEvent::MouseButtonRelease: {
+ − 669
QMouseEvent *m = static_cast<QMouseEvent *>(e);
+ − 670
if (isVisible() && view->rect().contains(m->pos()) && view->currentIndex().isValid()
+ − 671
&& !blockMouseReleaseTimer.isActive()
+ − 672
&& (view->currentIndex().flags() & Qt::ItemIsEnabled)
+ − 673
&& (view->currentIndex().flags() & Qt::ItemIsSelectable)) {
+ − 674
combo->hidePopup();
+ − 675
emit itemSelected(view->currentIndex());
+ − 676
return true;
+ − 677
}
+ − 678
break;
+ − 679
}
+ − 680
default:
+ − 681
break;
+ − 682
}
+ − 683
return QFrame::eventFilter(o, e);
+ − 684
}
+ − 685
+ − 686
void QComboBoxPrivateContainer::showEvent(QShowEvent *)
+ − 687
{
+ − 688
combo->update();
+ − 689
}
+ − 690
+ − 691
void QComboBoxPrivateContainer::hideEvent(QHideEvent *)
+ − 692
{
+ − 693
emit resetButton();
+ − 694
combo->update();
+ − 695
}
+ − 696
+ − 697
void QComboBoxPrivateContainer::mousePressEvent(QMouseEvent *e)
+ − 698
{
+ − 699
+ − 700
QStyleOptionComboBox opt = comboStyleOption();
+ − 701
opt.subControls = QStyle::SC_All;
+ − 702
opt.activeSubControls = QStyle::SC_ComboBoxArrow;
+ − 703
QStyle::SubControl sc = combo->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt,
+ − 704
combo->mapFromGlobal(e->globalPos()),
+ − 705
combo);
+ − 706
if ((combo->isEditable() && sc == QStyle::SC_ComboBoxArrow)
+ − 707
|| (!combo->isEditable() && sc != QStyle::SC_None))
+ − 708
setAttribute(Qt::WA_NoMouseReplay);
+ − 709
combo->hidePopup();
+ − 710
}
+ − 711
+ − 712
void QComboBoxPrivateContainer::mouseReleaseEvent(QMouseEvent *e)
+ − 713
{
+ − 714
Q_UNUSED(e);
+ − 715
if (!blockMouseReleaseTimer.isActive()){
+ − 716
combo->hidePopup();
+ − 717
emit resetButton();
+ − 718
}
+ − 719
}
+ − 720
+ − 721
QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
+ − 722
{
+ − 723
// ### This should use QComboBox's initStyleOption(), but it's protected
+ − 724
// perhaps, we could cheat by having the QCombo private instead?
+ − 725
QStyleOptionComboBox opt;
+ − 726
opt.initFrom(combo);
+ − 727
opt.subControls = QStyle::SC_All;
+ − 728
opt.activeSubControls = QStyle::SC_None;
+ − 729
opt.editable = combo->isEditable();
+ − 730
return opt;
+ − 731
}
+ − 732
+ − 733
/*!
+ − 734
\enum QComboBox::InsertPolicy
+ − 735
+ − 736
This enum specifies what the QComboBox should do when a new string is
+ − 737
entered by the user.
+ − 738
+ − 739
\value NoInsert The string will not be inserted into the combobox.
+ − 740
\value InsertAtTop The string will be inserted as the first item in the combobox.
+ − 741
\value InsertAtCurrent The current item will be \e replaced by the string.
+ − 742
\value InsertAtBottom The string will be inserted after the last item in the combobox.
+ − 743
\value InsertAfterCurrent The string is inserted after the current item in the combobox.
+ − 744
\value InsertBeforeCurrent The string is inserted before the current item in the combobox.
+ − 745
\value InsertAlphabetically The string is inserted in the alphabetic order in the combobox.
+ − 746
\omitvalue NoInsertion
+ − 747
\omitvalue AtTop
+ − 748
\omitvalue AtCurrent
+ − 749
\omitvalue AtBottom
+ − 750
\omitvalue AfterCurrent
+ − 751
\omitvalue BeforeCurrent
+ − 752
*/
+ − 753
+ − 754
/*!
+ − 755
\enum QComboBox::SizeAdjustPolicy
+ − 756
+ − 757
This enum specifies how the size hint of the QComboBox should
+ − 758
adjust when new content is added or content changes.
+ − 759
+ − 760
\value AdjustToContents The combobox will always adjust to the contents
+ − 761
\value AdjustToContentsOnFirstShow The combobox will adjust to its contents the first time it is shown.
+ − 762
\value AdjustToMinimumContentsLength Use AdjustToContents or AdjustToContentsOnFirstShow instead.
+ − 763
\value AdjustToMinimumContentsLengthWithIcon The combobox will adjust to \l minimumContentsLength plus space for an icon. For performance reasons use this policy on large models.
+ − 764
*/
+ − 765
+ − 766
/*!
+ − 767
\fn void QComboBox::activated(int index)
+ − 768
+ − 769
This signal is sent when the user chooses an item in the combobox.
+ − 770
The item's \a index is passed. Note that this signal is sent even
+ − 771
when the choice is not changed. If you need to know when the
+ − 772
choice actually changes, use signal currentIndexChanged().
+ − 773
+ − 774
*/
+ − 775
+ − 776
/*!
+ − 777
\fn void QComboBox::activated(const QString &text)
+ − 778
+ − 779
This signal is sent when the user chooses an item in the combobox.
+ − 780
The item's \a text is passed. Note that this signal is sent even
+ − 781
when the choice is not changed. If you need to know when the
+ − 782
choice actually changes, use signal currentIndexChanged().
+ − 783
+ − 784
*/
+ − 785
+ − 786
/*!
+ − 787
\fn void QComboBox::highlighted(int index)
+ − 788
+ − 789
This signal is sent when an item in the combobox popup list is
+ − 790
highlighted by the user. The item's \a index is passed.
+ − 791
*/
+ − 792
+ − 793
/*!
+ − 794
\fn void QComboBox::highlighted(const QString &text)
+ − 795
+ − 796
This signal is sent when an item in the combobox popup list is
+ − 797
highlighted by the user. The item's \a text is passed.
+ − 798
*/
+ − 799
+ − 800
/*!
+ − 801
\fn void QComboBox::currentIndexChanged(int index)
+ − 802
\since 4.1
+ − 803
+ − 804
This signal is sent whenever the currentIndex in the combobox
+ − 805
changes either through user interaction or programmatically. The
+ − 806
item's \a index is passed or -1 if the combobox becomes empty or the
+ − 807
currentIndex was reset.
+ − 808
*/
+ − 809
+ − 810
/*!
+ − 811
\fn void QComboBox::currentIndexChanged(const QString &text)
+ − 812
\since 4.1
+ − 813
+ − 814
This signal is sent whenever the currentIndex in the combobox
+ − 815
changes either through user interaction or programmatically. The
+ − 816
item's \a text is passed.
+ − 817
*/
+ − 818
+ − 819
/*!
+ − 820
Constructs a combobox with the given \a parent, using the default
+ − 821
model QStandardItemModel.
+ − 822
*/
+ − 823
QComboBox::QComboBox(QWidget *parent)
+ − 824
: QWidget(*new QComboBoxPrivate(), parent, 0)
+ − 825
{
+ − 826
Q_D(QComboBox);
+ − 827
d->init();
+ − 828
}
+ − 829
+ − 830
/*!
+ − 831
\internal
+ − 832
*/
+ − 833
QComboBox::QComboBox(QComboBoxPrivate &dd, QWidget *parent)
+ − 834
: QWidget(dd, parent, 0)
+ − 835
{
+ − 836
Q_D(QComboBox);
+ − 837
d->init();
+ − 838
}
+ − 839
+ − 840
#ifdef QT3_SUPPORT
+ − 841
/*!
+ − 842
Use one of the constructors that doesn't take the \a name
+ − 843
argument and then use setObjectName() instead.
+ − 844
*/
+ − 845
QComboBox::QComboBox(QWidget *parent, const char *name)
+ − 846
: QWidget(*new QComboBoxPrivate(), parent, 0)
+ − 847
{
+ − 848
Q_D(QComboBox);
+ − 849
d->init();
+ − 850
setObjectName(QString::fromAscii(name));
+ − 851
}
+ − 852
+ − 853
/*!
+ − 854
Use one of the constructors that doesn't take the \a name
+ − 855
argument and then use setObjectName() instead.
+ − 856
*/
+ − 857
QComboBox::QComboBox(bool rw, QWidget *parent, const char *name)
+ − 858
: QWidget(*new QComboBoxPrivate(), parent, 0)
+ − 859
{
+ − 860
Q_D(QComboBox);
+ − 861
d->init();
+ − 862
setEditable(rw);
+ − 863
setObjectName(QString::fromAscii(name));
+ − 864
}
+ − 865
+ − 866
#endif //QT3_SUPPORT
+ − 867
+ − 868
/*!
+ − 869
\class QComboBox
+ − 870
\brief The QComboBox widget is a combined button and popup list.
+ − 871
+ − 872
\ingroup basicwidgets
+ − 873
+ − 874
+ − 875
A QComboBox provides a means of presenting a list of options to the user
+ − 876
in a way that takes up the minimum amount of screen space.
+ − 877
+ − 878
A combobox is a selection widget that displays the current item,
+ − 879
and can pop up a list of selectable items. A combobox may be editable,
+ − 880
allowing the user to modify each item in the list.
+ − 881
+ − 882
Comboboxes can contain pixmaps as well as strings; the
+ − 883
insertItem() and setItemText() functions are suitably overloaded.
+ − 884
For editable comboboxes, the function clearEditText() is provided,
+ − 885
to clear the displayed string without changing the combobox's
+ − 886
contents.
+ − 887
+ − 888
There are two signals emitted if the current item of a combobox
+ − 889
changes, currentIndexChanged() and activated().
+ − 890
currentIndexChanged() is always emitted regardless if the change
+ − 891
was done programmatically or by user interaction, while
+ − 892
activated() is only emitted when the change is caused by user
+ − 893
interaction. The highlighted() signal is emitted when the user
+ − 894
highlights an item in the combobox popup list. All three signals
+ − 895
exist in two versions, one with a QString argument and one with an
+ − 896
\c int argument. If the user selectes or highlights a pixmap, only
+ − 897
the \c int signals are emitted. Whenever the text of an editable
+ − 898
combobox is changed the editTextChanged() signal is emitted.
+ − 899
+ − 900
When the user enters a new string in an editable combobox, the
+ − 901
widget may or may not insert it, and it can insert it in several
+ − 902
locations. The default policy is is \l AtBottom but you can change
+ − 903
this using setInsertPolicy().
+ − 904
+ − 905
It is possible to constrain the input to an editable combobox
+ − 906
using QValidator; see setValidator(). By default, any input is
+ − 907
accepted.
+ − 908
+ − 909
A combobox can be populated using the insert functions,
+ − 910
insertItem() and insertItems() for example. Items can be
+ − 911
changed with setItemText(). An item can be removed with
+ − 912
removeItem() and all items can be removed with clear(). The text
+ − 913
of the current item is returned by currentText(), and the text of
+ − 914
a numbered item is returned with text(). The current item can be
+ − 915
set with setCurrentIndex(). The number of items in the combobox is
+ − 916
returned by count(); the maximum number of items can be set with
+ − 917
setMaxCount(). You can allow editing using setEditable(). For
+ − 918
editable comboboxes you can set auto-completion using
+ − 919
setCompleter() and whether or not the user can add duplicates
+ − 920
is set with setDuplicatesEnabled().
+ − 921
+ − 922
QComboBox uses the \l{Model/View Programming}{model/view
+ − 923
framework} for its popup list and to store its items. By default
+ − 924
a QStandardItemModel stores the items and a QListView subclass
+ − 925
displays the popuplist. You can access the model and view directly
+ − 926
(with model() and view()), but QComboBox also provides functions
+ − 927
to set and get item data (e.g., setItemData() and itemText()). You
+ − 928
can also set a new model and view (with setModel() and setView()).
+ − 929
For the text and icon in the combobox label, the data in the model
+ − 930
that has the Qt::DisplayRole and Qt::DecorationRole is used.
+ − 931
+ − 932
\image qstyle-comboboxes.png Comboboxes in the different built-in styles.
+ − 933
+ − 934
\sa QLineEdit, QSpinBox, QRadioButton, QButtonGroup,
+ − 935
{fowler}{GUI Design Handbook: Combo Box, Drop-Down List Box}
+ − 936
*/
+ − 937
+ − 938
void QComboBoxPrivate::init()
+ − 939
{
+ − 940
Q_Q(QComboBox);
+ − 941
q->setFocusPolicy(Qt::WheelFocus);
+ − 942
q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,
+ − 943
QSizePolicy::ComboBox));
+ − 944
setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);
+ − 945
q->setModel(new QStandardItemModel(0, 1, q));
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 946
if (!q->isEditable())
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 947
q->setAttribute(Qt::WA_InputMethodEnabled, false);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 948
else
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 949
q->setAttribute(Qt::WA_InputMethodEnabled);
0
+ − 950
}
+ − 951
+ − 952
QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer()
+ − 953
{
+ − 954
if (container)
+ − 955
return container;
+ − 956
+ − 957
Q_Q(QComboBox);
+ − 958
container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q);
+ − 959
container->itemView()->setModel(model);
+ − 960
container->itemView()->setTextElideMode(Qt::ElideMiddle);
+ − 961
updateDelegate(true);
+ − 962
updateLayoutDirection();
+ − 963
updateViewContainerPaletteAndOpacity();
+ − 964
QObject::connect(container, SIGNAL(itemSelected(QModelIndex)),
+ − 965
q, SLOT(_q_itemSelected(QModelIndex)));
+ − 966
QObject::connect(container->itemView()->selectionModel(),
+ − 967
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
+ − 968
q, SLOT(_q_emitHighlighted(QModelIndex)));
+ − 969
QObject::connect(container, SIGNAL(resetButton()), q, SLOT(_q_resetButton()));
+ − 970
return container;
+ − 971
}
+ − 972
+ − 973
+ − 974
void QComboBoxPrivate::_q_resetButton()
+ − 975
{
+ − 976
updateArrow(QStyle::State_None);
+ − 977
}
+ − 978
+ − 979
void QComboBoxPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
+ − 980
{
+ − 981
Q_Q(QComboBox);
+ − 982
if (inserting || topLeft.parent() != root)
+ − 983
return;
+ − 984
+ − 985
if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
+ − 986
sizeHint = QSize();
+ − 987
adjustComboBoxSize();
+ − 988
q->updateGeometry();
+ − 989
}
+ − 990
+ − 991
if (currentIndex.row() >= topLeft.row() && currentIndex.row() <= bottomRight.row()) {
+ − 992
if (lineEdit) {
+ − 993
lineEdit->setText(q->itemText(currentIndex.row()));
+ − 994
updateLineEditGeometry();
+ − 995
}
+ − 996
q->update();
+ − 997
}
+ − 998
}
+ − 999
+ − 1000
void QComboBoxPrivate::_q_rowsInserted(const QModelIndex &parent, int start, int end)
+ − 1001
{
+ − 1002
Q_Q(QComboBox);
+ − 1003
if (inserting || parent != root)
+ − 1004
return;
+ − 1005
+ − 1006
if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
+ − 1007
sizeHint = QSize();
+ − 1008
adjustComboBoxSize();
+ − 1009
q->updateGeometry();
+ − 1010
}
+ − 1011
+ − 1012
// set current index if combo was previously empty
+ − 1013
if (start == 0 && (end - start + 1) == q->count() && !currentIndex.isValid()) {
+ − 1014
q->setCurrentIndex(0);
+ − 1015
// need to emit changed if model updated index "silently"
+ − 1016
} else if (currentIndex.row() != indexBeforeChange) {
+ − 1017
q->update();
+ − 1018
_q_emitCurrentIndexChanged(currentIndex);
+ − 1019
}
+ − 1020
}
+ − 1021
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1022
void QComboBoxPrivate::_q_updateIndexBeforeChange()
0
+ − 1023
{
+ − 1024
indexBeforeChange = currentIndex.row();
+ − 1025
}
+ − 1026
+ − 1027
void QComboBoxPrivate::_q_rowsRemoved(const QModelIndex &parent, int /*start*/, int /*end*/)
+ − 1028
{
+ − 1029
Q_Q(QComboBox);
+ − 1030
if (parent != root)
+ − 1031
return;
+ − 1032
+ − 1033
if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
+ − 1034
sizeHint = QSize();
+ − 1035
adjustComboBoxSize();
+ − 1036
q->updateGeometry();
+ − 1037
}
+ − 1038
+ − 1039
// model has changed the currentIndex
+ − 1040
if (currentIndex.row() != indexBeforeChange) {
+ − 1041
if (!currentIndex.isValid() && q->count()) {
+ − 1042
q->setCurrentIndex(qMin(q->count() - 1, qMax(indexBeforeChange, 0)));
+ − 1043
return;
+ − 1044
}
+ − 1045
if (lineEdit) {
+ − 1046
lineEdit->setText(q->itemText(currentIndex.row()));
+ − 1047
updateLineEditGeometry();
+ − 1048
}
+ − 1049
q->update();
+ − 1050
_q_emitCurrentIndexChanged(currentIndex);
+ − 1051
}
+ − 1052
}
+ − 1053
+ − 1054
+ − 1055
void QComboBoxPrivate::updateViewContainerPaletteAndOpacity()
+ − 1056
{
+ − 1057
if (!container)
+ − 1058
return;
+ − 1059
Q_Q(QComboBox);
+ − 1060
QStyleOptionComboBox opt;
+ − 1061
q->initStyleOption(&opt);
+ − 1062
#ifndef QT_NO_MENU
+ − 1063
if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
+ − 1064
QMenu menu;
+ − 1065
menu.ensurePolished();
+ − 1066
container->setPalette(menu.palette());
+ − 1067
container->setWindowOpacity(menu.windowOpacity());
+ − 1068
} else
+ − 1069
#endif
+ − 1070
{
+ − 1071
container->setPalette(q->palette());
+ − 1072
container->setWindowOpacity(1.0);
+ − 1073
}
+ − 1074
}
+ − 1075
+ − 1076
/*!
+ − 1077
Initialize \a option with the values from this QComboBox. This method
+ − 1078
is useful for subclasses when they need a QStyleOptionComboBox, but don't want
+ − 1079
to fill in all the information themselves.
+ − 1080
+ − 1081
\sa QStyleOption::initFrom()
+ − 1082
*/
+ − 1083
void QComboBox::initStyleOption(QStyleOptionComboBox *option) const
+ − 1084
{
+ − 1085
if (!option)
+ − 1086
return;
+ − 1087
+ − 1088
Q_D(const QComboBox);
+ − 1089
option->initFrom(this);
+ − 1090
option->editable = isEditable();
+ − 1091
option->frame = d->frame;
+ − 1092
if (hasFocus() && !option->editable)
+ − 1093
option->state |= QStyle::State_Selected;
+ − 1094
option->subControls = QStyle::SC_All;
+ − 1095
if (d->arrowState == QStyle::State_Sunken) {
+ − 1096
option->activeSubControls = QStyle::SC_ComboBoxArrow;
+ − 1097
option->state |= d->arrowState;
+ − 1098
} else {
+ − 1099
option->activeSubControls = d->hoverControl;
+ − 1100
}
+ − 1101
if (d->currentIndex.isValid()) {
+ − 1102
option->currentText = currentText();
+ − 1103
option->currentIcon = d->itemIcon(d->currentIndex);
+ − 1104
}
+ − 1105
option->iconSize = iconSize();
+ − 1106
if (d->container && d->container->isVisible())
+ − 1107
option->state |= QStyle::State_On;
+ − 1108
}
+ − 1109
+ − 1110
void QComboBoxPrivate::updateLineEditGeometry()
+ − 1111
{
+ − 1112
if (!lineEdit)
+ − 1113
return;
+ − 1114
+ − 1115
Q_Q(QComboBox);
+ − 1116
QStyleOptionComboBox opt;
+ − 1117
q->initStyleOption(&opt);
+ − 1118
QRect editRect = q->style()->subControlRect(QStyle::CC_ComboBox, &opt,
+ − 1119
QStyle::SC_ComboBoxEditField, q);
+ − 1120
if (!q->itemIcon(q->currentIndex()).isNull()) {
+ − 1121
QRect comboRect(editRect);
+ − 1122
editRect.setWidth(editRect.width() - q->iconSize().width() - 4);
+ − 1123
editRect = QStyle::alignedRect(q->layoutDirection(), Qt::AlignRight,
+ − 1124
editRect.size(), comboRect);
+ − 1125
}
+ − 1126
lineEdit->setGeometry(editRect);
+ − 1127
}
+ − 1128
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1129
Qt::MatchFlags QComboBoxPrivate::matchFlags() const
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1130
{
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1131
// Base how duplicates are determined on the autocompletion case sensitivity
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1132
Qt::MatchFlags flags = Qt::MatchFixedString;
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1133
#ifndef QT_NO_COMPLETER
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1134
if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive)
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1135
#endif
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1136
flags |= Qt::MatchCaseSensitive;
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1137
return flags;
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1138
}
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1139
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1140
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1141
void QComboBoxPrivate::_q_editingFinished()
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1142
{
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1143
Q_Q(QComboBox);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1144
if (lineEdit && !lineEdit->text().isEmpty()) {
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1145
//here we just check if the current item was entered
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1146
const int index = q_func()->findText(lineEdit->text(), matchFlags());
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1147
if (index != -1 && itemText(currentIndex) != lineEdit->text()) {
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1148
q->setCurrentIndex(index);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1149
emitActivated(currentIndex);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1150
}
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1151
}
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1152
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1153
}
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1154
0
+ − 1155
void QComboBoxPrivate::_q_returnPressed()
+ − 1156
{
+ − 1157
Q_Q(QComboBox);
+ − 1158
if (lineEdit && !lineEdit->text().isEmpty()) {
+ − 1159
if (q->count() >= maxCount && !(this->insertPolicy == QComboBox::InsertAtCurrent))
+ − 1160
return;
+ − 1161
lineEdit->deselect();
+ − 1162
lineEdit->end(false);
+ − 1163
QString text = lineEdit->text();
+ − 1164
// check for duplicates (if not enabled) and quit
+ − 1165
int index = -1;
+ − 1166
if (!duplicatesEnabled) {
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1167
index = q->findText(text, matchFlags());
0
+ − 1168
if (index != -1) {
+ − 1169
q->setCurrentIndex(index);
+ − 1170
emitActivated(currentIndex);
+ − 1171
return;
+ − 1172
}
+ − 1173
}
+ − 1174
switch (insertPolicy) {
+ − 1175
case QComboBox::InsertAtTop:
+ − 1176
index = 0;
+ − 1177
break;
+ − 1178
case QComboBox::InsertAtBottom:
+ − 1179
index = q->count();
+ − 1180
break;
+ − 1181
case QComboBox::InsertAtCurrent:
+ − 1182
case QComboBox::InsertAfterCurrent:
+ − 1183
case QComboBox::InsertBeforeCurrent:
+ − 1184
if (!q->count() || !currentIndex.isValid())
+ − 1185
index = 0;
+ − 1186
else if (insertPolicy == QComboBox::InsertAtCurrent)
+ − 1187
q->setItemText(q->currentIndex(), text);
+ − 1188
else if (insertPolicy == QComboBox::InsertAfterCurrent)
+ − 1189
index = q->currentIndex() + 1;
+ − 1190
else if (insertPolicy == QComboBox::InsertBeforeCurrent)
+ − 1191
index = q->currentIndex();
+ − 1192
break;
+ − 1193
case QComboBox::InsertAlphabetically:
+ − 1194
index = 0;
+ − 1195
for (int i=0; i< q->count(); i++, index++ ) {
+ − 1196
if (text.toLower() < q->itemText(i).toLower())
+ − 1197
break;
+ − 1198
}
+ − 1199
break;
+ − 1200
case QComboBox::NoInsert:
+ − 1201
default:
+ − 1202
break;
+ − 1203
}
+ − 1204
if (index >= 0) {
+ − 1205
q->insertItem(index, text);
+ − 1206
q->setCurrentIndex(index);
+ − 1207
emitActivated(currentIndex);
+ − 1208
}
+ − 1209
}
+ − 1210
}
+ − 1211
+ − 1212
void QComboBoxPrivate::_q_itemSelected(const QModelIndex &item)
+ − 1213
{
+ − 1214
Q_Q(QComboBox);
+ − 1215
if (item != currentIndex) {
+ − 1216
setCurrentIndex(item);
+ − 1217
} else if (lineEdit) {
+ − 1218
lineEdit->selectAll();
+ − 1219
lineEdit->setText(q->itemText(currentIndex.row()));
+ − 1220
}
+ − 1221
emitActivated(currentIndex);
+ − 1222
}
+ − 1223
+ − 1224
void QComboBoxPrivate::emitActivated(const QModelIndex &index)
+ − 1225
{
+ − 1226
Q_Q(QComboBox);
+ − 1227
if (!index.isValid())
+ − 1228
return;
+ − 1229
QString text(itemText(index));
+ − 1230
emit q->activated(index.row());
+ − 1231
emit q->activated(text);
+ − 1232
}
+ − 1233
+ − 1234
void QComboBoxPrivate::_q_emitHighlighted(const QModelIndex &index)
+ − 1235
{
+ − 1236
Q_Q(QComboBox);
+ − 1237
if (!index.isValid())
+ − 1238
return;
+ − 1239
QString text(itemText(index));
+ − 1240
emit q->highlighted(index.row());
+ − 1241
emit q->highlighted(text);
+ − 1242
}
+ − 1243
+ − 1244
void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index)
+ − 1245
{
+ − 1246
Q_Q(QComboBox);
+ − 1247
emit q->currentIndexChanged(index.row());
+ − 1248
emit q->currentIndexChanged(itemText(index));
+ − 1249
}
+ − 1250
+ − 1251
QString QComboBoxPrivate::itemText(const QModelIndex &index) const
+ − 1252
{
+ − 1253
return index.isValid() ? model->data(index, itemRole()).toString() : QString();
+ − 1254
}
+ − 1255
+ − 1256
int QComboBoxPrivate::itemRole() const
+ − 1257
{
+ − 1258
return q_func()->isEditable() ? Qt::EditRole : Qt::DisplayRole;
+ − 1259
}
+ − 1260
+ − 1261
/*!
+ − 1262
Destroys the combobox.
+ − 1263
*/
+ − 1264
QComboBox::~QComboBox()
+ − 1265
{
+ − 1266
// ### check delegateparent and delete delegate if us?
+ − 1267
Q_D(QComboBox);
+ − 1268
+ − 1269
QT_TRY {
+ − 1270
disconnect(d->model, SIGNAL(destroyed()),
+ − 1271
this, SLOT(_q_modelDestroyed()));
+ − 1272
} QT_CATCH(...) {
+ − 1273
; // objects can't throw in destructor
+ − 1274
}
+ − 1275
}
+ − 1276
+ − 1277
/*!
+ − 1278
\property QComboBox::maxVisibleItems
+ − 1279
\brief the maximum allowed size on screen of the combo box, measured in items
+ − 1280
+ − 1281
By default, this property has a value of 10.
+ − 1282
+ − 1283
\note This property is ignored for non-editable comboboxes in Mac style.
+ − 1284
*/
+ − 1285
int QComboBox::maxVisibleItems() const
+ − 1286
{
+ − 1287
Q_D(const QComboBox);
+ − 1288
return d->maxVisibleItems;
+ − 1289
}
+ − 1290
+ − 1291
void QComboBox::setMaxVisibleItems(int maxItems)
+ − 1292
{
+ − 1293
Q_D(QComboBox);
+ − 1294
if (maxItems < 0) {
+ − 1295
qWarning("QComboBox::setMaxVisibleItems: "
+ − 1296
"Invalid max visible items (%d) must be >= 0", maxItems);
+ − 1297
return;
+ − 1298
}
+ − 1299
d->maxVisibleItems = maxItems;
+ − 1300
}
+ − 1301
+ − 1302
/*!
+ − 1303
\property QComboBox::count
+ − 1304
\brief the number of items in the combobox
+ − 1305
+ − 1306
By default, for an empty combo box, this property has a value of 0.
+ − 1307
*/
+ − 1308
int QComboBox::count() const
+ − 1309
{
+ − 1310
Q_D(const QComboBox);
+ − 1311
return d->model->rowCount(d->root);
+ − 1312
}
+ − 1313
+ − 1314
/*!
+ − 1315
\property QComboBox::maxCount
+ − 1316
\brief the maximum number of items allowed in the combobox
+ − 1317
+ − 1318
\note If you set the maximum number to be less then the current
+ − 1319
amount of items in the combobox, the extra items will be
+ − 1320
truncated. This also applies if you have set an external model on
+ − 1321
the combobox.
+ − 1322
+ − 1323
By default, this property's value is derived from the highest
+ − 1324
signed integer available (typically 2147483647).
+ − 1325
*/
+ − 1326
void QComboBox::setMaxCount(int max)
+ − 1327
{
+ − 1328
Q_D(QComboBox);
+ − 1329
if (max < 0) {
+ − 1330
qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);
+ − 1331
return;
+ − 1332
}
+ − 1333
+ − 1334
if (max < count())
+ − 1335
d->model->removeRows(max, count() - max, d->root);
+ − 1336
+ − 1337
d->maxCount = max;
+ − 1338
}
+ − 1339
+ − 1340
int QComboBox::maxCount() const
+ − 1341
{
+ − 1342
Q_D(const QComboBox);
+ − 1343
return d->maxCount;
+ − 1344
}
+ − 1345
+ − 1346
#ifndef QT_NO_COMPLETER
+ − 1347
+ − 1348
/*!
+ − 1349
\property QComboBox::autoCompletion
+ − 1350
\brief whether the combobox provides auto-completion for editable items
+ − 1351
\since 4.1
+ − 1352
\obsolete
+ − 1353
+ − 1354
Use setCompleter() instead.
+ − 1355
+ − 1356
By default, this property is true.
+ − 1357
+ − 1358
\sa editable
+ − 1359
*/
+ − 1360
+ − 1361
/*!
+ − 1362
\obsolete
+ − 1363
+ − 1364
Use setCompleter() instead.
+ − 1365
*/
+ − 1366
bool QComboBox::autoCompletion() const
+ − 1367
{
+ − 1368
Q_D(const QComboBox);
+ − 1369
return d->autoCompletion;
+ − 1370
}
+ − 1371
+ − 1372
/*!
+ − 1373
\obsolete
+ − 1374
+ − 1375
Use setCompleter() instead.
+ − 1376
*/
+ − 1377
void QComboBox::setAutoCompletion(bool enable)
+ − 1378
{
+ − 1379
Q_D(QComboBox);
+ − 1380
+ − 1381
#ifdef QT_KEYPAD_NAVIGATION
+ − 1382
if (QApplication::keypadNavigationEnabled() && !enable && isEditable())
+ − 1383
qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable");
+ − 1384
#endif
+ − 1385
+ − 1386
d->autoCompletion = enable;
+ − 1387
if (!d->lineEdit)
+ − 1388
return;
+ − 1389
if (enable) {
+ − 1390
if (d->lineEdit->completer())
+ − 1391
return;
+ − 1392
d->completer = new QCompleter(d->model, d->lineEdit);
+ − 1393
d->completer->setCaseSensitivity(d->autoCompletionCaseSensitivity);
+ − 1394
d->completer->setCompletionMode(QCompleter::InlineCompletion);
+ − 1395
d->completer->setCompletionColumn(d->modelColumn);
+ − 1396
d->lineEdit->setCompleter(d->completer);
+ − 1397
d->completer->setWidget(this);
+ − 1398
} else {
+ − 1399
d->lineEdit->setCompleter(0);
+ − 1400
}
+ − 1401
}
+ − 1402
+ − 1403
/*!
+ − 1404
\property QComboBox::autoCompletionCaseSensitivity
+ − 1405
\brief whether string comparisons are case-sensitive or case-insensitive for auto-completion
+ − 1406
\obsolete
+ − 1407
+ − 1408
By default, this property is Qt::CaseInsensitive.
+ − 1409
+ − 1410
Use setCompleter() instead. Case sensitivity of the auto completion can be
+ − 1411
changed using QCompleter::setCaseSensitivity().
+ − 1412
+ − 1413
\sa autoCompletion
+ − 1414
*/
+ − 1415
+ − 1416
/*!
+ − 1417
\obsolete
+ − 1418
+ − 1419
Use setCompleter() and QCompleter::setCaseSensitivity() instead.
+ − 1420
*/
+ − 1421
Qt::CaseSensitivity QComboBox::autoCompletionCaseSensitivity() const
+ − 1422
{
+ − 1423
Q_D(const QComboBox);
+ − 1424
return d->autoCompletionCaseSensitivity;
+ − 1425
}
+ − 1426
+ − 1427
/*!
+ − 1428
\obsolete
+ − 1429
+ − 1430
Use setCompleter() and QCompleter::setCaseSensitivity() instead.
+ − 1431
*/
+ − 1432
void QComboBox::setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity)
+ − 1433
{
+ − 1434
Q_D(QComboBox);
+ − 1435
d->autoCompletionCaseSensitivity = sensitivity;
+ − 1436
if (d->lineEdit && d->lineEdit->completer())
+ − 1437
d->lineEdit->completer()->setCaseSensitivity(sensitivity);
+ − 1438
}
+ − 1439
+ − 1440
#endif // QT_NO_COMPLETER
+ − 1441
+ − 1442
/*!
+ − 1443
\property QComboBox::duplicatesEnabled
+ − 1444
\brief whether the user can enter duplicate items into the combobox
+ − 1445
+ − 1446
Note that it is always possible to programmatically insert duplicate items into the
+ − 1447
combobox.
+ − 1448
+ − 1449
By default, this property is false (duplicates are not allowed).
+ − 1450
*/
+ − 1451
bool QComboBox::duplicatesEnabled() const
+ − 1452
{
+ − 1453
Q_D(const QComboBox);
+ − 1454
return d->duplicatesEnabled;
+ − 1455
}
+ − 1456
+ − 1457
void QComboBox::setDuplicatesEnabled(bool enable)
+ − 1458
{
+ − 1459
Q_D(QComboBox);
+ − 1460
d->duplicatesEnabled = enable;
+ − 1461
}
+ − 1462
+ − 1463
/*! \fn int QComboBox::findText(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const
+ − 1464
+ − 1465
Returns the index of the item containing the given \a text; otherwise
+ − 1466
returns -1.
+ − 1467
+ − 1468
The \a flags specify how the items in the combobox are searched.
+ − 1469
*/
+ − 1470
+ − 1471
/*!
+ − 1472
Returns the index of the item containing the given \a data for the
+ − 1473
given \a role; otherwise returns -1.
+ − 1474
+ − 1475
The \a flags specify how the items in the combobox are searched.
+ − 1476
*/
+ − 1477
int QComboBox::findData(const QVariant &data, int role, Qt::MatchFlags flags) const
+ − 1478
{
+ − 1479
Q_D(const QComboBox);
+ − 1480
QModelIndexList result;
+ − 1481
QModelIndex start = d->model->index(0, d->modelColumn, d->root);
+ − 1482
result = d->model->match(start, role, data, 1, flags);
+ − 1483
if (result.isEmpty())
+ − 1484
return -1;
+ − 1485
return result.first().row();
+ − 1486
}
+ − 1487
+ − 1488
/*!
+ − 1489
\property QComboBox::insertPolicy
+ − 1490
\brief the policy used to determine where user-inserted items should
+ − 1491
appear in the combobox
+ − 1492
+ − 1493
The default value is \l AtBottom, indicating that new items will appear
+ − 1494
at the bottom of the list of items.
+ − 1495
+ − 1496
\sa InsertPolicy
+ − 1497
*/
+ − 1498
+ − 1499
QComboBox::InsertPolicy QComboBox::insertPolicy() const
+ − 1500
{
+ − 1501
Q_D(const QComboBox);
+ − 1502
return d->insertPolicy;
+ − 1503
}
+ − 1504
+ − 1505
void QComboBox::setInsertPolicy(InsertPolicy policy)
+ − 1506
{
+ − 1507
Q_D(QComboBox);
+ − 1508
d->insertPolicy = policy;
+ − 1509
}
+ − 1510
+ − 1511
/*!
+ − 1512
\property QComboBox::sizeAdjustPolicy
+ − 1513
\brief the policy describing how the size of the combobox changes
+ − 1514
when the content changes
+ − 1515
+ − 1516
The default value is \l AdjustToContentsOnFirstShow.
+ − 1517
+ − 1518
\sa SizeAdjustPolicy
+ − 1519
*/
+ − 1520
+ − 1521
QComboBox::SizeAdjustPolicy QComboBox::sizeAdjustPolicy() const
+ − 1522
{
+ − 1523
Q_D(const QComboBox);
+ − 1524
return d->sizeAdjustPolicy;
+ − 1525
}
+ − 1526
+ − 1527
void QComboBox::setSizeAdjustPolicy(QComboBox::SizeAdjustPolicy policy)
+ − 1528
{
+ − 1529
Q_D(QComboBox);
+ − 1530
if (policy == d->sizeAdjustPolicy)
+ − 1531
return;
+ − 1532
+ − 1533
d->sizeAdjustPolicy = policy;
+ − 1534
d->sizeHint = QSize();
+ − 1535
d->adjustComboBoxSize();
+ − 1536
updateGeometry();
+ − 1537
}
+ − 1538
+ − 1539
/*!
+ − 1540
\property QComboBox::minimumContentsLength
+ − 1541
\brief the minimum number of characters that should fit into the combobox.
+ − 1542
+ − 1543
The default value is 0.
+ − 1544
+ − 1545
If this property is set to a positive value, the
+ − 1546
minimumSizeHint() and sizeHint() take it into account.
+ − 1547
+ − 1548
\sa sizeAdjustPolicy
+ − 1549
*/
+ − 1550
int QComboBox::minimumContentsLength() const
+ − 1551
{
+ − 1552
Q_D(const QComboBox);
+ − 1553
return d->minimumContentsLength;
+ − 1554
}
+ − 1555
+ − 1556
void QComboBox::setMinimumContentsLength(int characters)
+ − 1557
{
+ − 1558
Q_D(QComboBox);
+ − 1559
if (characters == d->minimumContentsLength || characters < 0)
+ − 1560
return;
+ − 1561
+ − 1562
d->minimumContentsLength = characters;
+ − 1563
+ − 1564
if (d->sizeAdjustPolicy == AdjustToContents
+ − 1565
|| d->sizeAdjustPolicy == AdjustToMinimumContentsLength
+ − 1566
|| d->sizeAdjustPolicy == AdjustToMinimumContentsLengthWithIcon) {
+ − 1567
d->sizeHint = QSize();
+ − 1568
d->adjustComboBoxSize();
+ − 1569
updateGeometry();
+ − 1570
}
+ − 1571
}
+ − 1572
+ − 1573
/*!
+ − 1574
\property QComboBox::iconSize
+ − 1575
\brief the size of the icons shown in the combobox.
+ − 1576
+ − 1577
Unless explicitly set this returns the default value of the
+ − 1578
current style. This size is the maximum size that icons can have;
+ − 1579
icons of smaller size are not scaled up.
+ − 1580
*/
+ − 1581
+ − 1582
QSize QComboBox::iconSize() const
+ − 1583
{
+ − 1584
Q_D(const QComboBox);
+ − 1585
if (d->iconSize.isValid())
+ − 1586
return d->iconSize;
+ − 1587
+ − 1588
int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
+ − 1589
return QSize(iconWidth, iconWidth);
+ − 1590
}
+ − 1591
+ − 1592
void QComboBox::setIconSize(const QSize &size)
+ − 1593
{
+ − 1594
Q_D(QComboBox);
+ − 1595
if (size == d->iconSize)
+ − 1596
return;
+ − 1597
+ − 1598
view()->setIconSize(size);
+ − 1599
d->iconSize = size;
+ − 1600
d->sizeHint = QSize();
+ − 1601
updateGeometry();
+ − 1602
}
+ − 1603
+ − 1604
/*!
+ − 1605
\property QComboBox::editable
+ − 1606
\brief whether the combo box can be edited by the user
+ − 1607
+ − 1608
By default, this property is false.
+ − 1609
*/
+ − 1610
bool QComboBox::isEditable() const
+ − 1611
{
+ − 1612
Q_D(const QComboBox);
+ − 1613
return d->lineEdit != 0;
+ − 1614
}
+ − 1615
+ − 1616
/*! \internal
+ − 1617
update the default delegate
+ − 1618
depending on the style's SH_ComboBox_Popup hint, we use a different default delegate.
+ − 1619
+ − 1620
but we do not change the delegate is the combobox use a custom delegate,
+ − 1621
unless \a force is set to true.
+ − 1622
*/
+ − 1623
void QComboBoxPrivate::updateDelegate(bool force)
+ − 1624
{
+ − 1625
Q_Q(QComboBox);
+ − 1626
QStyleOptionComboBox opt;
+ − 1627
q->initStyleOption(&opt);
+ − 1628
if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) {
+ − 1629
if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate()))
+ − 1630
q->setItemDelegate(new QComboMenuDelegate(q->view(), q));
+ − 1631
} else {
+ − 1632
if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate()))
+ − 1633
q->setItemDelegate(new QComboBoxDelegate(q->view(), q));
+ − 1634
}
+ − 1635
}
+ − 1636
+ − 1637
QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const
+ − 1638
{
+ − 1639
QVariant decoration = model->data(index, Qt::DecorationRole);
+ − 1640
if (decoration.type() == QVariant::Pixmap)
+ − 1641
return QIcon(qvariant_cast<QPixmap>(decoration));
+ − 1642
else
+ − 1643
return qvariant_cast<QIcon>(decoration);
+ − 1644
}
+ − 1645
+ − 1646
void QComboBox::setEditable(bool editable)
+ − 1647
{
+ − 1648
Q_D(QComboBox);
+ − 1649
if (isEditable() == editable)
+ − 1650
return;
+ − 1651
+ − 1652
d->updateDelegate();
+ − 1653
+ − 1654
QStyleOptionComboBox opt;
+ − 1655
initStyleOption(&opt);
+ − 1656
if (editable) {
+ − 1657
if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
+ − 1658
d->viewContainer()->updateScrollers();
+ − 1659
view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ − 1660
}
+ − 1661
QLineEdit *le = new QLineEdit(this);
+ − 1662
setLineEdit(le);
+ − 1663
} else {
+ − 1664
if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
+ − 1665
d->viewContainer()->updateScrollers();
+ − 1666
view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ − 1667
}
+ − 1668
setAttribute(Qt::WA_InputMethodEnabled, false);
+ − 1669
d->lineEdit->hide();
+ − 1670
d->lineEdit->deleteLater();
+ − 1671
d->lineEdit = 0;
+ − 1672
}
+ − 1673
+ − 1674
d->viewContainer()->updateTopBottomMargin();
+ − 1675
if (!testAttribute(Qt::WA_Resized))
+ − 1676
adjustSize();
+ − 1677
}
+ − 1678
+ − 1679
/*!
+ − 1680
Sets the line \a edit to use instead of the current line edit widget.
+ − 1681
+ − 1682
The combo box takes ownership of the line edit.
+ − 1683
*/
+ − 1684
void QComboBox::setLineEdit(QLineEdit *edit)
+ − 1685
{
+ − 1686
Q_D(QComboBox);
+ − 1687
if (!edit) {
+ − 1688
qWarning("QComboBox::setLineEdit: cannot set a 0 line edit");
+ − 1689
return;
+ − 1690
}
+ − 1691
+ − 1692
if (edit == d->lineEdit)
+ − 1693
return;
+ − 1694
+ − 1695
edit->setText(currentText());
+ − 1696
delete d->lineEdit;
+ − 1697
+ − 1698
d->lineEdit = edit;
+ − 1699
if (d->lineEdit->parent() != this)
+ − 1700
d->lineEdit->setParent(this);
+ − 1701
connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed()));
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1702
connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished()));
0
+ − 1703
connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString)));
+ − 1704
#ifdef QT3_SUPPORT
+ − 1705
connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(textChanged(QString)));
+ − 1706
#endif
+ − 1707
d->lineEdit->setFrame(false);
+ − 1708
d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu);
+ − 1709
d->lineEdit->setFocusProxy(this);
+ − 1710
d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
+ − 1711
#ifndef QT_NO_COMPLETER
+ − 1712
setAutoCompletion(d->autoCompletion);
+ − 1713
#endif
+ − 1714
+ − 1715
#ifdef QT_KEYPAD_NAVIGATION
+ − 1716
#ifndef QT_NO_COMPLETER
+ − 1717
if (QApplication::keypadNavigationEnabled()) {
+ − 1718
// Editable combo boxes will have a completer that is set to UnfilteredPopupCompletion.
+ − 1719
// This means that when the user enters edit mode they are immediately presented with a
+ − 1720
// list of possible completions.
+ − 1721
setAutoCompletion(true);
+ − 1722
if (d->completer) {
+ − 1723
d->completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
+ − 1724
connect(d->completer, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated()));
+ − 1725
}
+ − 1726
}
+ − 1727
#endif
+ − 1728
#endif
+ − 1729
+ − 1730
setAttribute(Qt::WA_InputMethodEnabled);
+ − 1731
d->updateLayoutDirection();
+ − 1732
d->updateLineEditGeometry();
+ − 1733
if (isVisible())
+ − 1734
d->lineEdit->show();
+ − 1735
+ − 1736
update();
+ − 1737
}
+ − 1738
+ − 1739
/*!
+ − 1740
Returns the line edit used to edit items in the combobox, or 0 if there
+ − 1741
is no line edit.
+ − 1742
+ − 1743
Only editable combo boxes have a line edit.
+ − 1744
*/
+ − 1745
QLineEdit *QComboBox::lineEdit() const
+ − 1746
{
+ − 1747
Q_D(const QComboBox);
+ − 1748
return d->lineEdit;
+ − 1749
}
+ − 1750
+ − 1751
#ifndef QT_NO_VALIDATOR
+ − 1752
/*!
+ − 1753
\fn void QComboBox::setValidator(const QValidator *validator)
+ − 1754
+ − 1755
Sets the \a validator to use instead of the current validator.
+ − 1756
*/
+ − 1757
+ − 1758
void QComboBox::setValidator(const QValidator *v)
+ − 1759
{
+ − 1760
Q_D(QComboBox);
+ − 1761
if (d->lineEdit)
+ − 1762
d->lineEdit->setValidator(v);
+ − 1763
}
+ − 1764
+ − 1765
/*!
+ − 1766
Returns the validator that is used to constrain text input for the
+ − 1767
combobox.
+ − 1768
+ − 1769
\sa editable
+ − 1770
*/
+ − 1771
const QValidator *QComboBox::validator() const
+ − 1772
{
+ − 1773
Q_D(const QComboBox);
+ − 1774
return d->lineEdit ? d->lineEdit->validator() : 0;
+ − 1775
}
+ − 1776
#endif // QT_NO_VALIDATOR
+ − 1777
+ − 1778
#ifndef QT_NO_COMPLETER
+ − 1779
+ − 1780
/*!
+ − 1781
\fn void QComboBox::setCompleter(QCompleter *completer)
+ − 1782
\since 4.2
+ − 1783
+ − 1784
Sets the \a completer to use instead of the current completer.
+ − 1785
If \a completer is 0, auto completion is disabled.
+ − 1786
+ − 1787
By default, for an editable combo box, a QCompleter that
+ − 1788
performs case insensitive inline completion is automatically created.
+ − 1789
*/
+ − 1790
void QComboBox::setCompleter(QCompleter *c)
+ − 1791
{
+ − 1792
Q_D(QComboBox);
+ − 1793
if (!d->lineEdit)
+ − 1794
return;
+ − 1795
d->lineEdit->setCompleter(c);
+ − 1796
if (c)
+ − 1797
c->setWidget(this);
+ − 1798
}
+ − 1799
+ − 1800
/*!
+ − 1801
\since 4.2
+ − 1802
+ − 1803
Returns the completer that is used to auto complete text input for the
+ − 1804
combobox.
+ − 1805
+ − 1806
\sa editable
+ − 1807
*/
+ − 1808
QCompleter *QComboBox::completer() const
+ − 1809
{
+ − 1810
Q_D(const QComboBox);
+ − 1811
return d->lineEdit ? d->lineEdit->completer() : 0;
+ − 1812
}
+ − 1813
+ − 1814
#endif // QT_NO_COMPLETER
+ − 1815
+ − 1816
/*!
+ − 1817
Returns the item delegate used by the popup list view.
+ − 1818
+ − 1819
\sa setItemDelegate()
+ − 1820
*/
+ − 1821
QAbstractItemDelegate *QComboBox::itemDelegate() const
+ − 1822
{
+ − 1823
return view()->itemDelegate();
+ − 1824
}
+ − 1825
+ − 1826
/*!
+ − 1827
Sets the item \a delegate for the popup list view.
+ − 1828
The combobox takes ownership of the delegate.
+ − 1829
+ − 1830
\warning You should not share the same instance of a delegate between comboboxes,
+ − 1831
widget mappers or views. Doing so can cause incorrect or unintuitive editing behavior
+ − 1832
since each view connected to a given delegate may receive the
+ − 1833
\l{QAbstractItemDelegate::}{closeEditor()} signal, and attempt to access, modify or
+ − 1834
close an editor that has already been closed.
+ − 1835
+ − 1836
\sa itemDelegate()
+ − 1837
*/
+ − 1838
void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate)
+ − 1839
{
+ − 1840
if (!delegate) {
+ − 1841
qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate");
+ − 1842
return;
+ − 1843
}
+ − 1844
delete view()->itemDelegate();
+ − 1845
view()->setItemDelegate(delegate);
+ − 1846
}
+ − 1847
+ − 1848
/*!
+ − 1849
Returns the model used by the combobox.
+ − 1850
*/
+ − 1851
+ − 1852
QAbstractItemModel *QComboBox::model() const
+ − 1853
{
+ − 1854
Q_D(const QComboBox);
+ − 1855
if (d->model == QAbstractItemModelPrivate::staticEmptyModel()) {
+ − 1856
QComboBox *that = const_cast<QComboBox*>(this);
+ − 1857
that->setModel(new QStandardItemModel(0, 1, that));
+ − 1858
}
+ − 1859
return d->model;
+ − 1860
}
+ − 1861
+ − 1862
/*!
+ − 1863
Sets the model to be \a model. \a model must not be 0.
+ − 1864
If you want to clear the contents of a model, call clear().
+ − 1865
+ − 1866
\sa clear()
+ − 1867
*/
+ − 1868
void QComboBox::setModel(QAbstractItemModel *model)
+ − 1869
{
+ − 1870
Q_D(QComboBox);
+ − 1871
+ − 1872
if (!model) {
+ − 1873
qWarning("QComboBox::setModel: cannot set a 0 model");
+ − 1874
return;
+ − 1875
}
+ − 1876
+ − 1877
#ifndef QT_NO_COMPLETER
+ − 1878
if (d->lineEdit && d->lineEdit->completer()
+ − 1879
&& d->lineEdit->completer() == d->completer)
+ − 1880
d->lineEdit->completer()->setModel(model);
+ − 1881
#endif
+ − 1882
if (d->model) {
+ − 1883
disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+ − 1884
this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
+ − 1885
disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1886
this, SLOT(_q_updateIndexBeforeChange()));
0
+ − 1887
disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
+ − 1888
this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
+ − 1889
disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1890
this, SLOT(_q_updateIndexBeforeChange()));
0
+ − 1891
disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ − 1892
this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
+ − 1893
disconnect(d->model, SIGNAL(destroyed()),
+ − 1894
this, SLOT(_q_modelDestroyed()));
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1895
disconnect(d->model, SIGNAL(modelAboutToBeReset()),
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1896
this, SLOT(_q_updateIndexBeforeChange()));
0
+ − 1897
disconnect(d->model, SIGNAL(modelReset()),
+ − 1898
this, SLOT(_q_modelReset()));
+ − 1899
if (d->model->QObject::parent() == this)
+ − 1900
delete d->model;
+ − 1901
}
+ − 1902
+ − 1903
d->model = model;
+ − 1904
+ − 1905
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+ − 1906
this, SLOT(_q_dataChanged(QModelIndex,QModelIndex)));
+ − 1907
connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1908
this, SLOT(_q_updateIndexBeforeChange()));
0
+ − 1909
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
+ − 1910
this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
+ − 1911
connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1912
this, SLOT(_q_updateIndexBeforeChange()));
0
+ − 1913
connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ − 1914
this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
+ − 1915
connect(model, SIGNAL(destroyed()),
+ − 1916
this, SLOT(_q_modelDestroyed()));
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1917
connect(model, SIGNAL(modelAboutToBeReset()),
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1918
this, SLOT(_q_updateIndexBeforeChange()));
0
+ − 1919
connect(model, SIGNAL(modelReset()),
+ − 1920
this, SLOT(_q_modelReset()));
+ − 1921
+ − 1922
if (d->container)
+ − 1923
d->container->itemView()->setModel(model);
+ − 1924
+ − 1925
bool currentReset = false;
+ − 1926
+ − 1927
if (count()) {
+ − 1928
for (int pos=0; pos < count(); pos++) {
+ − 1929
if (d->model->index(pos, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled) {
+ − 1930
setCurrentIndex(pos);
+ − 1931
currentReset = true;
+ − 1932
break;
+ − 1933
}
+ − 1934
}
+ − 1935
}
+ − 1936
+ − 1937
if (!currentReset)
+ − 1938
setCurrentIndex(-1);
+ − 1939
+ − 1940
d->modelChanged();
+ − 1941
}
+ − 1942
+ − 1943
/*!
+ − 1944
Returns the root model item index for the items in the combobox.
+ − 1945
+ − 1946
\sa setRootModelIndex()
+ − 1947
*/
+ − 1948
+ − 1949
QModelIndex QComboBox::rootModelIndex() const
+ − 1950
{
+ − 1951
Q_D(const QComboBox);
+ − 1952
return QModelIndex(d->root);
+ − 1953
}
+ − 1954
+ − 1955
/*!
+ − 1956
Sets the root model item \a index for the items in the combobox.
+ − 1957
+ − 1958
\sa rootModelIndex()
+ − 1959
*/
+ − 1960
void QComboBox::setRootModelIndex(const QModelIndex &index)
+ − 1961
{
+ − 1962
Q_D(QComboBox);
+ − 1963
d->root = QPersistentModelIndex(index);
+ − 1964
view()->setRootIndex(index);
+ − 1965
update();
+ − 1966
}
+ − 1967
+ − 1968
/*!
+ − 1969
\property QComboBox::currentIndex
+ − 1970
\brief the index of the current item in the combobox.
+ − 1971
+ − 1972
The current index can change when inserting or removing items.
+ − 1973
+ − 1974
By default, for an empty combo box or a combo box in which no current
+ − 1975
item is set, this property has a value of -1.
+ − 1976
*/
+ − 1977
int QComboBox::currentIndex() const
+ − 1978
{
+ − 1979
Q_D(const QComboBox);
+ − 1980
return d->currentIndex.row();
+ − 1981
}
+ − 1982
+ − 1983
void QComboBox::setCurrentIndex(int index)
+ − 1984
{
+ − 1985
Q_D(QComboBox);
+ − 1986
QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
+ − 1987
d->setCurrentIndex(mi);
+ − 1988
}
+ − 1989
+ − 1990
void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)
+ − 1991
{
+ − 1992
Q_Q(QComboBox);
+ − 1993
bool indexChanged = (mi != currentIndex);
+ − 1994
if (indexChanged)
+ − 1995
currentIndex = QPersistentModelIndex(mi);
+ − 1996
if (lineEdit) {
+ − 1997
QString newText = q->itemText(currentIndex.row());
+ − 1998
if (lineEdit->text() != newText)
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 1999
lineEdit->setText(newText);
0
+ − 2000
updateLineEditGeometry();
+ − 2001
}
+ − 2002
if (indexChanged) {
+ − 2003
q->update();
+ − 2004
_q_emitCurrentIndexChanged(currentIndex);
+ − 2005
}
+ − 2006
}
+ − 2007
+ − 2008
/*!
+ − 2009
\property QComboBox::currentText
+ − 2010
\brief the text of the current item
+ − 2011
+ − 2012
By default, for an empty combo box or a combo box in which no current
+ − 2013
item is set, this property contains an empty string.
+ − 2014
*/
+ − 2015
QString QComboBox::currentText() const
+ − 2016
{
+ − 2017
Q_D(const QComboBox);
+ − 2018
if (d->lineEdit)
+ − 2019
return d->lineEdit->text();
+ − 2020
else if (d->currentIndex.isValid())
+ − 2021
return d->itemText(d->currentIndex);
+ − 2022
else
+ − 2023
return QString();
+ − 2024
}
+ − 2025
+ − 2026
/*!
+ − 2027
Returns the text for the given \a index in the combobox.
+ − 2028
*/
+ − 2029
QString QComboBox::itemText(int index) const
+ − 2030
{
+ − 2031
Q_D(const QComboBox);
+ − 2032
QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
+ − 2033
return d->itemText(mi);
+ − 2034
}
+ − 2035
+ − 2036
/*!
+ − 2037
Returns the icon for the given \a index in the combobox.
+ − 2038
*/
+ − 2039
QIcon QComboBox::itemIcon(int index) const
+ − 2040
{
+ − 2041
Q_D(const QComboBox);
+ − 2042
QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
+ − 2043
return d->itemIcon(mi);
+ − 2044
}
+ − 2045
+ − 2046
/*!
+ − 2047
Returns the data for the given \a role in the given \a index in the
+ − 2048
combobox, or QVariant::Invalid if there is no data for this role.
+ − 2049
*/
+ − 2050
QVariant QComboBox::itemData(int index, int role) const
+ − 2051
{
+ − 2052
Q_D(const QComboBox);
+ − 2053
QModelIndex mi = d->model->index(index, d->modelColumn, d->root);
+ − 2054
return d->model->data(mi, role);
+ − 2055
}
+ − 2056
+ − 2057
/*!
+ − 2058
\fn void QComboBox::insertItem(int index, const QString &text, const QVariant &userData)
+ − 2059
+ − 2060
Inserts the \a text and \a userData (stored in the Qt::UserRole)
+ − 2061
into the combobox at the given \a index.
+ − 2062
+ − 2063
If the index is equal to or higher than the total number of items,
+ − 2064
the new item is appended to the list of existing items. If the
+ − 2065
index is zero or negative, the new item is prepended to the list
+ − 2066
of existing items.
+ − 2067
+ − 2068
\sa insertItems()
+ − 2069
*/
+ − 2070
+ − 2071
/*!
+ − 2072
+ − 2073
Inserts the \a icon, \a text and \a userData (stored in the
+ − 2074
Qt::UserRole) into the combobox at the given \a index.
+ − 2075
+ − 2076
If the index is equal to or higher than the total number of items,
+ − 2077
the new item is appended to the list of existing items. If the
+ − 2078
index is zero or negative, the new item is prepended to the list
+ − 2079
of existing items.
+ − 2080
+ − 2081
\sa insertItems()
+ − 2082
*/
+ − 2083
void QComboBox::insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userData)
+ − 2084
{
+ − 2085
Q_D(QComboBox);
+ − 2086
int itemCount = count();
+ − 2087
index = qBound(0, index, itemCount);
+ − 2088
if (index >= d->maxCount)
+ − 2089
return;
+ − 2090
+ − 2091
// For the common case where we are using the built in QStandardItemModel
+ − 2092
// construct a QStandardItem, reducing the number of expensive signals from the model
+ − 2093
if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
+ − 2094
QStandardItem *item = new QStandardItem(text);
+ − 2095
if (!icon.isNull()) item->setData(icon, Qt::DecorationRole);
+ − 2096
if (userData.isValid()) item->setData(userData, Qt::UserRole);
+ − 2097
m->insertRow(index, item);
+ − 2098
++itemCount;
+ − 2099
} else {
+ − 2100
d->inserting = true;
+ − 2101
if (d->model->insertRows(index, 1, d->root)) {
+ − 2102
QModelIndex item = d->model->index(index, d->modelColumn, d->root);
+ − 2103
if (icon.isNull() && !userData.isValid()) {
+ − 2104
d->model->setData(item, text, Qt::EditRole);
+ − 2105
} else {
+ − 2106
QMap<int, QVariant> values;
+ − 2107
if (!text.isNull()) values.insert(Qt::EditRole, text);
+ − 2108
if (!icon.isNull()) values.insert(Qt::DecorationRole, icon);
+ − 2109
if (userData.isValid()) values.insert(Qt::UserRole, userData);
+ − 2110
if (!values.isEmpty()) d->model->setItemData(item, values);
+ − 2111
}
+ − 2112
d->inserting = false;
+ − 2113
d->_q_rowsInserted(d->root, index, index);
+ − 2114
++itemCount;
+ − 2115
} else {
+ − 2116
d->inserting = false;
+ − 2117
}
+ − 2118
}
+ − 2119
+ − 2120
if (itemCount > d->maxCount)
+ − 2121
d->model->removeRows(itemCount - 1, itemCount - d->maxCount, d->root);
+ − 2122
}
+ − 2123
+ − 2124
/*!
+ − 2125
Inserts the strings from the \a list into the combobox as separate items,
+ − 2126
starting at the \a index specified.
+ − 2127
+ − 2128
If the index is equal to or higher than the total number of items, the new items
+ − 2129
are appended to the list of existing items. If the index is zero or negative, the
+ − 2130
new items are prepended to the list of existing items.
+ − 2131
+ − 2132
\sa insertItem()
+ − 2133
*/
+ − 2134
void QComboBox::insertItems(int index, const QStringList &list)
+ − 2135
{
+ − 2136
Q_D(QComboBox);
+ − 2137
if (list.isEmpty())
+ − 2138
return;
+ − 2139
index = qBound(0, index, count());
+ − 2140
int insertCount = qMin(d->maxCount - index, list.count());
+ − 2141
if (insertCount <= 0)
+ − 2142
return;
+ − 2143
// For the common case where we are using the built in QStandardItemModel
+ − 2144
// construct a QStandardItem, reducing the number of expensive signals from the model
+ − 2145
if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) {
+ − 2146
QList<QStandardItem *> items;
+ − 2147
QStandardItem *hiddenRoot = m->invisibleRootItem();
+ − 2148
for (int i = 0; i < insertCount; ++i)
+ − 2149
items.append(new QStandardItem(list.at(i)));
+ − 2150
hiddenRoot->insertRows(index, items);
+ − 2151
} else {
+ − 2152
d->inserting = true;
+ − 2153
if (d->model->insertRows(index, insertCount, d->root)) {
+ − 2154
QModelIndex item;
+ − 2155
for (int i = 0; i < insertCount; ++i) {
+ − 2156
item = d->model->index(i+index, d->modelColumn, d->root);
+ − 2157
d->model->setData(item, list.at(i), Qt::EditRole);
+ − 2158
}
+ − 2159
d->inserting = false;
+ − 2160
d->_q_rowsInserted(d->root, index, index + insertCount - 1);
+ − 2161
} else {
+ − 2162
d->inserting = false;
+ − 2163
}
+ − 2164
}
+ − 2165
+ − 2166
int mc = count();
+ − 2167
if (mc > d->maxCount)
+ − 2168
d->model->removeRows(d->maxCount, mc - d->maxCount, d->root);
+ − 2169
}
+ − 2170
+ − 2171
/*!
+ − 2172
\since 4.4
+ − 2173
+ − 2174
Inserts a separator item into the combobox at the given \a index.
+ − 2175
+ − 2176
If the index is equal to or higher than the total number of items, the new item
+ − 2177
is appended to the list of existing items. If the index is zero or negative, the
+ − 2178
new item is prepended to the list of existing items.
+ − 2179
+ − 2180
\sa insertItem()
+ − 2181
*/
+ − 2182
void QComboBox::insertSeparator(int index)
+ − 2183
{
+ − 2184
Q_D(QComboBox);
+ − 2185
int itemCount = count();
+ − 2186
index = qBound(0, index, itemCount);
+ − 2187
if (index >= d->maxCount)
+ − 2188
return;
+ − 2189
insertItem(index, QIcon(), QString());
+ − 2190
QComboBoxDelegate::setSeparator(d->model, d->model->index(index, 0, d->root));
+ − 2191
}
+ − 2192
+ − 2193
/*!
+ − 2194
Removes the item at the given \a index from the combobox.
+ − 2195
This will update the current index if the index is removed.
+ − 2196
+ − 2197
This function does nothing if \a index is out of range.
+ − 2198
*/
+ − 2199
void QComboBox::removeItem(int index)
+ − 2200
{
+ − 2201
Q_D(QComboBox);
+ − 2202
if (index < 0 || index >= count())
+ − 2203
return;
+ − 2204
d->model->removeRows(index, 1, d->root);
+ − 2205
}
+ − 2206
+ − 2207
/*!
+ − 2208
Sets the \a text for the item on the given \a index in the combobox.
+ − 2209
*/
+ − 2210
void QComboBox::setItemText(int index, const QString &text)
+ − 2211
{
+ − 2212
Q_D(const QComboBox);
+ − 2213
QModelIndex item = d->model->index(index, d->modelColumn, d->root);
+ − 2214
if (item.isValid()) {
+ − 2215
d->model->setData(item, text, Qt::EditRole);
+ − 2216
}
+ − 2217
}
+ − 2218
+ − 2219
/*!
+ − 2220
Sets the \a icon for the item on the given \a index in the combobox.
+ − 2221
*/
+ − 2222
void QComboBox::setItemIcon(int index, const QIcon &icon)
+ − 2223
{
+ − 2224
Q_D(const QComboBox);
+ − 2225
QModelIndex item = d->model->index(index, d->modelColumn, d->root);
+ − 2226
if (item.isValid()) {
+ − 2227
d->model->setData(item, icon, Qt::DecorationRole);
+ − 2228
}
+ − 2229
}
+ − 2230
+ − 2231
/*!
+ − 2232
Sets the data \a role for the item on the given \a index in the combobox
+ − 2233
to the specified \a value.
+ − 2234
*/
+ − 2235
void QComboBox::setItemData(int index, const QVariant &value, int role)
+ − 2236
{
+ − 2237
Q_D(const QComboBox);
+ − 2238
QModelIndex item = d->model->index(index, d->modelColumn, d->root);
+ − 2239
if (item.isValid()) {
+ − 2240
d->model->setData(item, value, role);
+ − 2241
}
+ − 2242
}
+ − 2243
+ − 2244
/*!
+ − 2245
Returns the list view used for the combobox popup.
+ − 2246
*/
+ − 2247
QAbstractItemView *QComboBox::view() const
+ − 2248
{
+ − 2249
Q_D(const QComboBox);
+ − 2250
return const_cast<QComboBoxPrivate*>(d)->viewContainer()->itemView();
+ − 2251
}
+ − 2252
+ − 2253
/*!
+ − 2254
Sets the view to be used in the combobox popup to the given \a
+ − 2255
itemView. The combobox takes ownership of the view.
+ − 2256
+ − 2257
Note: If you want to use the convenience views (like QListWidget,
+ − 2258
QTableWidget or QTreeWidget), make sure to call setModel() on the
+ − 2259
combobox with the convenience widgets model before calling this
+ − 2260
function.
+ − 2261
*/
+ − 2262
void QComboBox::setView(QAbstractItemView *itemView)
+ − 2263
{
+ − 2264
Q_D(QComboBox);
+ − 2265
if (!itemView) {
+ − 2266
qWarning("QComboBox::setView: cannot set a 0 view");
+ − 2267
return;
+ − 2268
}
+ − 2269
+ − 2270
if (itemView->model() != d->model)
+ − 2271
itemView->setModel(d->model);
+ − 2272
d->viewContainer()->setItemView(itemView);
+ − 2273
}
+ − 2274
+ − 2275
/*!
+ − 2276
\reimp
+ − 2277
*/
+ − 2278
QSize QComboBox::minimumSizeHint() const
+ − 2279
{
+ − 2280
Q_D(const QComboBox);
+ − 2281
return d->recomputeSizeHint(d->minimumSizeHint);
+ − 2282
}
+ − 2283
+ − 2284
/*!
+ − 2285
\reimp
+ − 2286
+ − 2287
This implementation caches the size hint to avoid resizing when
+ − 2288
the contents change dynamically. To invalidate the cached value
+ − 2289
change the \l sizeAdjustPolicy.
+ − 2290
*/
+ − 2291
QSize QComboBox::sizeHint() const
+ − 2292
{
+ − 2293
Q_D(const QComboBox);
+ − 2294
return d->recomputeSizeHint(d->sizeHint);
+ − 2295
}
+ − 2296
+ − 2297
/*!
+ − 2298
Displays the list of items in the combobox. If the list is empty
+ − 2299
then the no items will be shown.
+ − 2300
+ − 2301
If you reimplement this function to show a custom pop-up, make
+ − 2302
sure you call hidePopup() to reset the internal state.
+ − 2303
+ − 2304
\sa hidePopup()
+ − 2305
*/
+ − 2306
void QComboBox::showPopup()
+ − 2307
{
+ − 2308
Q_D(QComboBox);
+ − 2309
if (count() <= 0)
+ − 2310
return;
+ − 2311
+ − 2312
#ifdef QT_KEYPAD_NAVIGATION
+ − 2313
#ifndef QT_NO_COMPLETER
+ − 2314
if (QApplication::keypadNavigationEnabled() && d->completer) {
+ − 2315
// editable combo box is line edit plus completer
+ − 2316
setEditFocus(true);
+ − 2317
d->completer->complete(); // show popup
+ − 2318
return;
+ − 2319
}
+ − 2320
#endif
+ − 2321
#endif
+ − 2322
+ − 2323
QStyle * const style = this->style();
+ − 2324
+ − 2325
// set current item and select it
+ − 2326
view()->selectionModel()->setCurrentIndex(d->currentIndex,
+ − 2327
QItemSelectionModel::ClearAndSelect);
+ − 2328
QComboBoxPrivateContainer* container = d->viewContainer();
+ − 2329
QStyleOptionComboBox opt;
+ − 2330
initStyleOption(&opt);
+ − 2331
QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
+ − 2332
QStyle::SC_ComboBoxListBoxPopup, this));
+ − 2333
QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this));
+ − 2334
QPoint below = mapToGlobal(listRect.bottomLeft());
+ − 2335
int belowHeight = screen.bottom() - below.y();
+ − 2336
QPoint above = mapToGlobal(listRect.topLeft());
+ − 2337
int aboveHeight = above.y() - screen.y();
+ − 2338
bool boundToScreen = !window()->testAttribute(Qt::WA_DontShowOnScreen);
+ − 2339
+ − 2340
const bool usePopup = style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this);
+ − 2341
{
+ − 2342
int listHeight = 0;
+ − 2343
int count = 0;
+ − 2344
QStack<QModelIndex> toCheck;
+ − 2345
toCheck.push(view()->rootIndex());
+ − 2346
#ifndef QT_NO_TREEVIEW
+ − 2347
QTreeView *treeView = qobject_cast<QTreeView*>(view());
+ − 2348
if (treeView && treeView->header() && !treeView->header()->isHidden())
+ − 2349
listHeight += treeView->header()->height();
+ − 2350
#endif
+ − 2351
while (!toCheck.isEmpty()) {
+ − 2352
QModelIndex parent = toCheck.pop();
+ − 2353
for (int i = 0; i < d->model->rowCount(parent); ++i) {
+ − 2354
QModelIndex idx = d->model->index(i, d->modelColumn, parent);
+ − 2355
if (!idx.isValid())
+ − 2356
continue;
+ − 2357
listHeight += view()->visualRect(idx).height() + container->spacing();
+ − 2358
#ifndef QT_NO_TREEVIEW
+ − 2359
if (d->model->hasChildren(idx) && treeView && treeView->isExpanded(idx))
+ − 2360
toCheck.push(idx);
+ − 2361
#endif
+ − 2362
++count;
+ − 2363
if (!usePopup && count > d->maxVisibleItems) {
+ − 2364
toCheck.clear();
+ − 2365
break;
+ − 2366
}
+ − 2367
}
+ − 2368
}
+ − 2369
listRect.setHeight(listHeight);
+ − 2370
}
+ − 2371
+ − 2372
{
+ − 2373
// add the spacing for the grid on the top and the bottom;
+ − 2374
int heightMargin = 2*container->spacing();
+ − 2375
+ − 2376
// add the frame of the container
+ − 2377
int marginTop, marginBottom;
+ − 2378
container->getContentsMargins(0, &marginTop, 0, &marginBottom);
+ − 2379
heightMargin += marginTop + marginBottom;
+ − 2380
+ − 2381
//add the frame of the view
+ − 2382
view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
+ − 2383
marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
+ − 2384
marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
+ − 2385
heightMargin += marginTop + marginBottom;
+ − 2386
+ − 2387
listRect.setHeight(listRect.height() + heightMargin);
+ − 2388
}
+ − 2389
+ − 2390
// Add space for margin at top and bottom if the style wants it.
+ − 2391
if (usePopup)
+ − 2392
listRect.setHeight(listRect.height() + style->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) * 2);
+ − 2393
+ − 2394
// Make sure the popup is wide enough to display its contents.
+ − 2395
if (usePopup) {
+ − 2396
const int diff = d->computeWidthHint() - width();
+ − 2397
if (diff > 0)
+ − 2398
listRect.setWidth(listRect.width() + diff);
+ − 2399
}
+ − 2400
+ − 2401
//we need to activate the layout to make sure the min/maximum size are set when the widget was not yet show
+ − 2402
container->layout()->activate();
+ − 2403
//takes account of the minimum/maximum size of the container
+ − 2404
listRect.setSize( listRect.size().expandedTo(container->minimumSize())
+ − 2405
.boundedTo(container->maximumSize()));
+ − 2406
+ − 2407
// make sure the widget fits on screen
+ − 2408
if (boundToScreen) {
+ − 2409
if (listRect.width() > screen.width() )
+ − 2410
listRect.setWidth(screen.width());
+ − 2411
if (mapToGlobal(listRect.bottomRight()).x() > screen.right()) {
+ − 2412
below.setX(screen.x() + screen.width() - listRect.width());
+ − 2413
above.setX(screen.x() + screen.width() - listRect.width());
+ − 2414
}
+ − 2415
if (mapToGlobal(listRect.topLeft()).x() < screen.x() ) {
+ − 2416
below.setX(screen.x());
+ − 2417
above.setX(screen.x());
+ − 2418
}
+ − 2419
}
+ − 2420
+ − 2421
if (usePopup) {
+ − 2422
// Position horizontally.
+ − 2423
listRect.moveLeft(above.x());
+ − 2424
7
+ − 2425
#ifndef Q_WS_S60
0
+ − 2426
// Position vertically so the curently selected item lines up
+ − 2427
// with the combo box.
+ − 2428
const QRect currentItemRect = view()->visualRect(view()->currentIndex());
+ − 2429
const int offset = listRect.top() - currentItemRect.top();
+ − 2430
listRect.moveTop(above.y() + offset - listRect.top());
7
+ − 2431
#endif
0
+ − 2432
+ − 2433
+ − 2434
// Clamp the listRect height and vertical position so we don't expand outside the
+ − 2435
// available screen geometry.This may override the vertical position, but it is more
+ − 2436
// important to show as much as possible of the popup.
+ − 2437
const int height = !boundToScreen ? listRect.height() : qMin(listRect.height(), screen.height());
7
+ − 2438
#ifdef Q_WS_S60
+ − 2439
//popup needs to be stretched with screen minimum dimension
+ − 2440
listRect.setHeight(qMin(screen.height(), screen.width()));
+ − 2441
#else
0
+ − 2442
listRect.setHeight(height);
7
+ − 2443
#endif
+ − 2444
0
+ − 2445
if (boundToScreen) {
+ − 2446
if (listRect.top() < screen.top())
+ − 2447
listRect.moveTop(screen.top());
+ − 2448
if (listRect.bottom() > screen.bottom())
+ − 2449
listRect.moveBottom(screen.bottom());
+ − 2450
}
7
+ − 2451
#ifdef Q_WS_S60
+ − 2452
if (screen.width() < screen.height()) {
+ − 2453
// in portait, menu should be positioned above softkeys
+ − 2454
listRect.moveBottom(screen.bottom());
+ − 2455
} else {
13
+ − 2456
TRect staConTopRect = TRect();
+ − 2457
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
7
+ − 2458
listRect.setWidth(listRect.height());
13
+ − 2459
//by default popup is centered on screen in landscape
7
+ − 2460
listRect.moveCenter(screen.center());
13
+ − 2461
if (staConTopRect.IsEmpty()) {
+ − 2462
// landscape without stacon, menu should be at the right
+ − 2463
(opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
+ − 2464
listRect.setLeft(screen.left());
+ − 2465
}
7
+ − 2466
}
+ − 2467
#endif
0
+ − 2468
} else if (!boundToScreen || listRect.height() <= belowHeight) {
+ − 2469
listRect.moveTopLeft(below);
+ − 2470
} else if (listRect.height() <= aboveHeight) {
+ − 2471
listRect.moveBottomLeft(above);
+ − 2472
} else if (belowHeight >= aboveHeight) {
+ − 2473
listRect.setHeight(belowHeight);
+ − 2474
listRect.moveTopLeft(below);
+ − 2475
} else {
+ − 2476
listRect.setHeight(aboveHeight);
+ − 2477
listRect.moveBottomLeft(above);
+ − 2478
}
+ − 2479
+ − 2480
#ifndef QT_NO_IM
+ − 2481
if (QInputContext *qic = inputContext())
+ − 2482
qic->reset();
+ − 2483
#endif
+ − 2484
QScrollBar *sb = view()->horizontalScrollBar();
+ − 2485
Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy();
+ − 2486
bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn)
+ − 2487
&& sb->minimum() < sb->maximum();
+ − 2488
if (needHorizontalScrollBar) {
+ − 2489
listRect.adjust(0, 0, 0, sb->height());
+ − 2490
}
+ − 2491
container->setGeometry(listRect);
+ − 2492
+ − 2493
#ifndef Q_WS_MAC
+ − 2494
const bool updatesEnabled = container->updatesEnabled();
+ − 2495
#endif
+ − 2496
+ − 2497
#if defined(Q_WS_WIN) && !defined(QT_NO_EFFECTS)
+ − 2498
bool scrollDown = (listRect.topLeft() == below);
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 2499
if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo)
0
+ − 2500
&& !style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this) && !window()->testAttribute(Qt::WA_DontShowOnScreen))
+ − 2501
qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150);
+ − 2502
#endif
+ − 2503
+ − 2504
// Don't disable updates on Mac OS X. Windows are displayed immediately on this platform,
+ − 2505
// which means that the window will be visible before the call to container->show() returns.
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 2506
// If updates are disabled at this point we'll miss our chance at painting the popup
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 2507
// menu before it's shown, causing flicker since the window then displays the standard gray
0
+ − 2508
// background.
+ − 2509
#ifndef Q_WS_MAC
+ − 2510
container->setUpdatesEnabled(false);
+ − 2511
#endif
+ − 2512
+ − 2513
container->raise();
+ − 2514
container->show();
+ − 2515
container->updateScrollers();
+ − 2516
view()->setFocus();
+ − 2517
+ − 2518
view()->scrollTo(view()->currentIndex(),
+ − 2519
style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)
+ − 2520
? QAbstractItemView::PositionAtCenter
+ − 2521
: QAbstractItemView::EnsureVisible);
+ − 2522
+ − 2523
#ifndef Q_WS_MAC
+ − 2524
container->setUpdatesEnabled(updatesEnabled);
+ − 2525
#endif
+ − 2526
+ − 2527
container->update();
+ − 2528
#ifdef QT_KEYPAD_NAVIGATION
+ − 2529
if (QApplication::keypadNavigationEnabled())
+ − 2530
view()->setEditFocus(true);
+ − 2531
#endif
+ − 2532
}
+ − 2533
+ − 2534
/*!
+ − 2535
Hides the list of items in the combobox if it is currently visible
+ − 2536
and resets the internal state, so that if the custom pop-up was
+ − 2537
shown inside the reimplemented showPopup(), then you also need to
+ − 2538
reimplement the hidePopup() function to hide your custom pop-up
+ − 2539
and call the base class implementation to reset the internal state
+ − 2540
whenever your custom pop-up widget is hidden.
+ − 2541
+ − 2542
\sa showPopup()
+ − 2543
*/
+ − 2544
void QComboBox::hidePopup()
+ − 2545
{
+ − 2546
Q_D(QComboBox);
+ − 2547
if (d->container && d->container->isVisible()) {
+ − 2548
#if !defined(QT_NO_EFFECTS)
+ − 2549
d->model->blockSignals(true);
+ − 2550
d->container->itemView()->blockSignals(true);
+ − 2551
d->container->blockSignals(true);
+ − 2552
// Flash selected/triggered item (if any).
+ − 2553
if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem)) {
+ − 2554
QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0;
+ − 2555
if (selectionModel && selectionModel->hasSelection()) {
+ − 2556
QEventLoop eventLoop;
+ − 2557
const QItemSelection selection = selectionModel->selection();
+ − 2558
+ − 2559
// Deselect item and wait 60 ms.
+ − 2560
selectionModel->select(selection, QItemSelectionModel::Toggle);
+ − 2561
QTimer::singleShot(60, &eventLoop, SLOT(quit()));
+ − 2562
eventLoop.exec();
+ − 2563
+ − 2564
// Select item and wait 20 ms.
+ − 2565
selectionModel->select(selection, QItemSelectionModel::Toggle);
+ − 2566
QTimer::singleShot(20, &eventLoop, SLOT(quit()));
+ − 2567
eventLoop.exec();
+ − 2568
}
+ − 2569
}
+ − 2570
+ − 2571
// Fade out.
+ − 2572
bool needFade = style()->styleHint(QStyle::SH_Menu_FadeOutOnHide);
+ − 2573
if (needFade) {
+ − 2574
#if defined(Q_WS_MAC)
+ − 2575
macWindowFade(qt_mac_window_for(d->container));
+ − 2576
#endif // Q_WS_MAC
+ − 2577
// Other platform implementations welcome :-)
+ − 2578
}
+ − 2579
d->model->blockSignals(false);
+ − 2580
d->container->itemView()->blockSignals(false);
+ − 2581
d->container->blockSignals(false);
+ − 2582
+ − 2583
if (!needFade)
+ − 2584
#endif // QT_NO_EFFECTS
+ − 2585
// Fade should implicitly hide as well ;-)
+ − 2586
d->container->hide();
+ − 2587
}
+ − 2588
#ifdef QT_KEYPAD_NAVIGATION
+ − 2589
if (QApplication::keypadNavigationEnabled() && isEditable() && hasFocus())
+ − 2590
setEditFocus(true);
+ − 2591
#endif
+ − 2592
d->_q_resetButton();
+ − 2593
}
+ − 2594
+ − 2595
/*!
+ − 2596
Clears the combobox, removing all items.
+ − 2597
+ − 2598
Note: If you have set an external model on the combobox this model
+ − 2599
will still be cleared when calling this function.
+ − 2600
*/
+ − 2601
void QComboBox::clear()
+ − 2602
{
+ − 2603
Q_D(QComboBox);
+ − 2604
d->model->removeRows(0, d->model->rowCount(d->root), d->root);
+ − 2605
}
+ − 2606
+ − 2607
/*!
+ − 2608
\fn void QComboBox::clearValidator()
+ − 2609
+ − 2610
Use setValidator(0) instead.
+ − 2611
*/
+ − 2612
+ − 2613
/*!
+ − 2614
Clears the contents of the line edit used for editing in the combobox.
+ − 2615
*/
+ − 2616
void QComboBox::clearEditText()
+ − 2617
{
+ − 2618
Q_D(QComboBox);
+ − 2619
if (d->lineEdit)
+ − 2620
d->lineEdit->clear();
+ − 2621
}
+ − 2622
+ − 2623
/*!
+ − 2624
Sets the \a text in the combobox's text edit.
+ − 2625
*/
+ − 2626
void QComboBox::setEditText(const QString &text)
+ − 2627
{
+ − 2628
Q_D(QComboBox);
+ − 2629
if (d->lineEdit)
+ − 2630
d->lineEdit->setText(text);
+ − 2631
}
+ − 2632
+ − 2633
/*!
+ − 2634
\reimp
+ − 2635
*/
+ − 2636
void QComboBox::focusInEvent(QFocusEvent *e)
+ − 2637
{
+ − 2638
Q_D(QComboBox);
+ − 2639
update();
+ − 2640
if (d->lineEdit) {
+ − 2641
d->lineEdit->event(e);
+ − 2642
#ifndef QT_NO_COMPLETER
+ − 2643
if (d->lineEdit->completer())
+ − 2644
d->lineEdit->completer()->setWidget(this);
+ − 2645
#endif
+ − 2646
}
+ − 2647
}
+ − 2648
+ − 2649
/*!
+ − 2650
\reimp
+ − 2651
*/
+ − 2652
void QComboBox::focusOutEvent(QFocusEvent *e)
+ − 2653
{
+ − 2654
Q_D(QComboBox);
+ − 2655
update();
+ − 2656
if (d->lineEdit)
+ − 2657
d->lineEdit->event(e);
+ − 2658
}
+ − 2659
+ − 2660
/*! \reimp */
+ − 2661
void QComboBox::changeEvent(QEvent *e)
+ − 2662
{
+ − 2663
Q_D(QComboBox);
+ − 2664
switch (e->type()) {
+ − 2665
case QEvent::StyleChange:
+ − 2666
d->updateDelegate();
+ − 2667
#ifdef Q_WS_MAC
+ − 2668
case QEvent::MacSizeChange:
+ − 2669
#endif
+ − 2670
d->sizeHint = QSize(); // invalidate size hint
+ − 2671
d->minimumSizeHint = QSize();
+ − 2672
d->updateLayoutDirection();
+ − 2673
if (d->lineEdit)
+ − 2674
d->updateLineEditGeometry();
+ − 2675
d->setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem);
7
+ − 2676
+ − 2677
#ifdef Q_WS_S60
+ − 2678
if (d->container) {
+ − 2679
QStyleOptionComboBox opt;
+ − 2680
initStyleOption(&opt);
+ − 2681
+ − 2682
if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
+ − 2683
const QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this));
+ − 2684
+ − 2685
QRect listRect(style()->subControlRect(QStyle::CC_ComboBox, &opt,
+ − 2686
QStyle::SC_ComboBoxListBoxPopup, this));
+ − 2687
listRect.setHeight(qMin(screen.height(), screen.width()));
+ − 2688
+ − 2689
if (screen.width() < screen.height()) {
+ − 2690
// in portait, menu should be positioned above softkeys
+ − 2691
listRect.moveBottom(screen.bottom());
+ − 2692
} else {
13
+ − 2693
TRect staConTopRect = TRect();
+ − 2694
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
7
+ − 2695
listRect.setWidth(listRect.height());
13
+ − 2696
//by default popup is centered on screen in landscape
7
+ − 2697
listRect.moveCenter(screen.center());
13
+ − 2698
if (staConTopRect.IsEmpty()) {
+ − 2699
// landscape without stacon, menu should be at the right
+ − 2700
(opt.direction == Qt::LeftToRight) ? listRect.setRight(screen.right()) :
+ − 2701
listRect.setLeft(screen.left());
+ − 2702
}
+ − 2703
d->container->setGeometry(listRect);
7
+ − 2704
}
+ − 2705
}
+ − 2706
}
+ − 2707
#endif
+ − 2708
0
+ − 2709
// ### need to update scrollers etc. as well here
+ − 2710
break;
+ − 2711
case QEvent::EnabledChange:
+ − 2712
if (!isEnabled())
+ − 2713
hidePopup();
+ − 2714
break;
+ − 2715
case QEvent::PaletteChange: {
+ − 2716
d->updateViewContainerPaletteAndOpacity();
+ − 2717
break;
+ − 2718
}
+ − 2719
case QEvent::FontChange:
+ − 2720
d->sizeHint = QSize(); // invalidate size hint
+ − 2721
d->viewContainer()->setFont(font());
+ − 2722
if (d->lineEdit)
+ − 2723
d->updateLineEditGeometry();
+ − 2724
break;
+ − 2725
default:
+ − 2726
break;
+ − 2727
}
+ − 2728
QWidget::changeEvent(e);
+ − 2729
}
+ − 2730
+ − 2731
/*!
+ − 2732
\reimp
+ − 2733
*/
+ − 2734
void QComboBox::resizeEvent(QResizeEvent *)
+ − 2735
{
+ − 2736
Q_D(QComboBox);
+ − 2737
d->updateLineEditGeometry();
+ − 2738
}
+ − 2739
+ − 2740
/*!
+ − 2741
\reimp
+ − 2742
*/
+ − 2743
void QComboBox::paintEvent(QPaintEvent *)
+ − 2744
{
+ − 2745
QStylePainter painter(this);
+ − 2746
painter.setPen(palette().color(QPalette::Text));
+ − 2747
+ − 2748
// draw the combobox frame, focusrect and selected etc.
+ − 2749
QStyleOptionComboBox opt;
+ − 2750
initStyleOption(&opt);
+ − 2751
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
+ − 2752
+ − 2753
// draw the icon and text
+ − 2754
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
+ − 2755
}
+ − 2756
+ − 2757
/*!
+ − 2758
\reimp
+ − 2759
*/
+ − 2760
void QComboBox::showEvent(QShowEvent *e)
+ − 2761
{
+ − 2762
Q_D(QComboBox);
+ − 2763
if (!d->shownOnce && d->sizeAdjustPolicy == QComboBox::AdjustToContentsOnFirstShow) {
+ − 2764
d->sizeHint = QSize();
+ − 2765
updateGeometry();
+ − 2766
}
+ − 2767
d->shownOnce = true;
+ − 2768
QWidget::showEvent(e);
+ − 2769
}
+ − 2770
+ − 2771
/*!
+ − 2772
\reimp
+ − 2773
*/
+ − 2774
void QComboBox::hideEvent(QHideEvent *)
+ − 2775
{
+ − 2776
hidePopup();
+ − 2777
}
+ − 2778
+ − 2779
/*!
+ − 2780
\reimp
+ − 2781
*/
+ − 2782
bool QComboBox::event(QEvent *event)
+ − 2783
{
+ − 2784
Q_D(QComboBox);
+ − 2785
switch(event->type()) {
+ − 2786
case QEvent::LayoutDirectionChange:
+ − 2787
case QEvent::ApplicationLayoutDirectionChange:
+ − 2788
d->updateLayoutDirection();
+ − 2789
d->updateLineEditGeometry();
+ − 2790
break;
+ − 2791
case QEvent::HoverEnter:
+ − 2792
case QEvent::HoverLeave:
+ − 2793
case QEvent::HoverMove:
+ − 2794
if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
+ − 2795
d->updateHoverControl(he->pos());
+ − 2796
break;
+ − 2797
case QEvent::ShortcutOverride:
+ − 2798
if (d->lineEdit)
+ − 2799
return d->lineEdit->event(event);
+ − 2800
break;
+ − 2801
#ifdef QT_KEYPAD_NAVIGATION
+ − 2802
case QEvent::EnterEditFocus:
+ − 2803
if (!d->lineEdit)
+ − 2804
setEditFocus(false); // We never want edit focus if we are not editable
+ − 2805
else
+ − 2806
d->lineEdit->event(event); //so cursor starts
+ − 2807
break;
+ − 2808
case QEvent::LeaveEditFocus:
+ − 2809
if (d->lineEdit)
+ − 2810
d->lineEdit->event(event); //so cursor stops
+ − 2811
break;
+ − 2812
#endif
+ − 2813
default:
+ − 2814
break;
+ − 2815
}
+ − 2816
return QWidget::event(event);
+ − 2817
}
+ − 2818
+ − 2819
/*!
+ − 2820
\reimp
+ − 2821
*/
+ − 2822
void QComboBox::mousePressEvent(QMouseEvent *e)
+ − 2823
{
+ − 2824
Q_D(QComboBox);
+ − 2825
QStyleOptionComboBox opt;
+ − 2826
initStyleOption(&opt);
+ − 2827
QStyle::SubControl sc = style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, e->pos(),
+ − 2828
this);
+ − 2829
if (e->button() == Qt::LeftButton && (sc == QStyle::SC_ComboBoxArrow || !isEditable())
+ − 2830
&& !d->viewContainer()->isVisible()) {
+ − 2831
if (sc == QStyle::SC_ComboBoxArrow)
+ − 2832
d->updateArrow(QStyle::State_Sunken);
+ − 2833
#ifdef QT_KEYPAD_NAVIGATION
+ − 2834
if (!d->lineEdit) {
+ − 2835
#endif
+ − 2836
// We've restricted the next couple of lines, because by not calling
+ − 2837
// viewContainer(), we avoid creating the QComboBoxPrivateContainer.
+ − 2838
d->viewContainer()->blockMouseReleaseTimer.start(QApplication::doubleClickInterval());
+ − 2839
d->viewContainer()->initialClickPosition = mapToGlobal(e->pos());
+ − 2840
#ifdef QT_KEYPAD_NAVIGATION
+ − 2841
}
+ − 2842
#endif
+ − 2843
showPopup();
+ − 2844
} else {
+ − 2845
#ifdef QT_KEYPAD_NAVIGATION
+ − 2846
if (QApplication::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && d->lineEdit) {
+ − 2847
d->lineEdit->event(e); //so lineedit can move cursor, etc
+ − 2848
return;
+ − 2849
}
+ − 2850
#endif
+ − 2851
QWidget::mousePressEvent(e);
+ − 2852
}
+ − 2853
}
+ − 2854
+ − 2855
/*!
+ − 2856
\reimp
+ − 2857
*/
+ − 2858
void QComboBox::mouseReleaseEvent(QMouseEvent *e)
+ − 2859
{
+ − 2860
Q_D(QComboBox);
+ − 2861
Q_UNUSED(e);
+ − 2862
d->updateArrow(QStyle::State_None);
+ − 2863
}
+ − 2864
+ − 2865
/*!
+ − 2866
\reimp
+ − 2867
*/
+ − 2868
void QComboBox::keyPressEvent(QKeyEvent *e)
+ − 2869
{
+ − 2870
Q_D(QComboBox);
+ − 2871
+ − 2872
#ifndef QT_NO_COMPLETER
+ − 2873
if (d->lineEdit
+ − 2874
&& d->lineEdit->completer()
+ − 2875
&& d->lineEdit->completer()->popup()
+ − 2876
&& d->lineEdit->completer()->popup()->isVisible()) {
+ − 2877
// provide same autocompletion support as line edit
+ − 2878
d->lineEdit->event(e);
+ − 2879
return;
+ − 2880
}
+ − 2881
#endif
+ − 2882
+ − 2883
enum Move { NoMove=0 , MoveUp , MoveDown , MoveFirst , MoveLast};
+ − 2884
+ − 2885
Move move = NoMove;
+ − 2886
int newIndex = currentIndex();
+ − 2887
switch (e->key()) {
+ − 2888
case Qt::Key_Up:
+ − 2889
if (e->modifiers() & Qt::ControlModifier)
+ − 2890
break; // pass to line edit for auto completion
+ − 2891
case Qt::Key_PageUp:
+ − 2892
#ifdef QT_KEYPAD_NAVIGATION
+ − 2893
if (QApplication::keypadNavigationEnabled())
+ − 2894
e->ignore();
+ − 2895
else
+ − 2896
#endif
+ − 2897
move = MoveUp;
+ − 2898
break;
+ − 2899
case Qt::Key_Down:
+ − 2900
if (e->modifiers() & Qt::AltModifier) {
+ − 2901
showPopup();
+ − 2902
return;
+ − 2903
} else if (e->modifiers() & Qt::ControlModifier)
+ − 2904
break; // pass to line edit for auto completion
+ − 2905
// fall through
+ − 2906
case Qt::Key_PageDown:
+ − 2907
#ifdef QT_KEYPAD_NAVIGATION
+ − 2908
if (QApplication::keypadNavigationEnabled())
+ − 2909
e->ignore();
+ − 2910
else
+ − 2911
#endif
+ − 2912
move = MoveDown;
+ − 2913
break;
+ − 2914
case Qt::Key_Home:
+ − 2915
if (!d->lineEdit)
+ − 2916
move = MoveFirst;
+ − 2917
break;
+ − 2918
case Qt::Key_End:
+ − 2919
if (!d->lineEdit)
+ − 2920
move = MoveLast;
+ − 2921
break;
+ − 2922
case Qt::Key_F4:
+ − 2923
if (!e->modifiers()) {
+ − 2924
showPopup();
+ − 2925
return;
+ − 2926
}
+ − 2927
break;
+ − 2928
case Qt::Key_Space:
+ − 2929
if (!d->lineEdit) {
+ − 2930
showPopup();
+ − 2931
return;
+ − 2932
}
+ − 2933
case Qt::Key_Enter:
+ − 2934
case Qt::Key_Return:
+ − 2935
case Qt::Key_Escape:
+ − 2936
if (!d->lineEdit)
+ − 2937
e->ignore();
+ − 2938
break;
+ − 2939
#ifdef QT_KEYPAD_NAVIGATION
+ − 2940
case Qt::Key_Select:
+ − 2941
if (QApplication::keypadNavigationEnabled()
+ − 2942
&& (!hasEditFocus() || !d->lineEdit)) {
+ − 2943
showPopup();
+ − 2944
return;
+ − 2945
}
+ − 2946
break;
+ − 2947
case Qt::Key_Left:
+ − 2948
case Qt::Key_Right:
+ − 2949
if (QApplication::keypadNavigationEnabled() && !hasEditFocus())
+ − 2950
e->ignore();
+ − 2951
break;
+ − 2952
case Qt::Key_Back:
+ − 2953
if (QApplication::keypadNavigationEnabled()) {
+ − 2954
if (!hasEditFocus() || !d->lineEdit)
+ − 2955
e->ignore();
+ − 2956
} else {
+ − 2957
e->ignore(); // let the surounding dialog have it
+ − 2958
}
+ − 2959
break;
+ − 2960
#endif
+ − 2961
default:
+ − 2962
if (!d->lineEdit) {
+ − 2963
if (!e->text().isEmpty())
+ − 2964
d->keyboardSearchString(e->text());
+ − 2965
else
+ − 2966
e->ignore();
+ − 2967
}
+ − 2968
}
+ − 2969
+ − 2970
if (move != NoMove) {
+ − 2971
e->accept();
+ − 2972
switch (move) {
+ − 2973
case MoveFirst:
+ − 2974
newIndex = -1;
+ − 2975
case MoveDown:
+ − 2976
newIndex++;
+ − 2977
while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
+ − 2978
newIndex++;
+ − 2979
break;
+ − 2980
case MoveLast:
+ − 2981
newIndex = count();
+ − 2982
case MoveUp:
+ − 2983
newIndex--;
+ − 2984
while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
+ − 2985
newIndex--;
+ − 2986
break;
+ − 2987
default:
+ − 2988
e->ignore();
+ − 2989
break;
+ − 2990
}
+ − 2991
+ − 2992
if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
+ − 2993
setCurrentIndex(newIndex);
+ − 2994
d->emitActivated(d->currentIndex);
+ − 2995
}
+ − 2996
} else if (d->lineEdit) {
+ − 2997
d->lineEdit->event(e);
+ − 2998
}
+ − 2999
}
+ − 3000
+ − 3001
+ − 3002
/*!
+ − 3003
\reimp
+ − 3004
*/
+ − 3005
void QComboBox::keyReleaseEvent(QKeyEvent *e)
+ − 3006
{
+ − 3007
Q_D(QComboBox);
+ − 3008
if (d->lineEdit)
+ − 3009
d->lineEdit->event(e);
+ − 3010
}
+ − 3011
+ − 3012
/*!
+ − 3013
\reimp
+ − 3014
*/
+ − 3015
#ifndef QT_NO_WHEELEVENT
+ − 3016
void QComboBox::wheelEvent(QWheelEvent *e)
+ − 3017
{
+ − 3018
Q_D(QComboBox);
+ − 3019
if (!d->viewContainer()->isVisible()) {
+ − 3020
int newIndex = currentIndex();
+ − 3021
+ − 3022
if (e->delta() > 0) {
+ − 3023
newIndex--;
+ − 3024
while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
+ − 3025
newIndex--;
+ − 3026
} else {
+ − 3027
newIndex++;
+ − 3028
while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
+ − 3029
newIndex++;
+ − 3030
}
+ − 3031
+ − 3032
if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
+ − 3033
setCurrentIndex(newIndex);
+ − 3034
d->emitActivated(d->currentIndex);
+ − 3035
}
+ − 3036
e->accept();
+ − 3037
}
+ − 3038
}
+ − 3039
#endif
+ − 3040
+ − 3041
#ifndef QT_NO_CONTEXTMENU
+ − 3042
/*!
+ − 3043
\reimp
+ − 3044
*/
+ − 3045
void QComboBox::contextMenuEvent(QContextMenuEvent *e)
+ − 3046
{
+ − 3047
Q_D(QComboBox);
+ − 3048
if (d->lineEdit) {
+ − 3049
Qt::ContextMenuPolicy p = d->lineEdit->contextMenuPolicy();
+ − 3050
d->lineEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
+ − 3051
d->lineEdit->event(e);
+ − 3052
d->lineEdit->setContextMenuPolicy(p);
+ − 3053
}
+ − 3054
}
+ − 3055
#endif // QT_NO_CONTEXTMENU
+ − 3056
+ − 3057
void QComboBoxPrivate::keyboardSearchString(const QString &text)
+ − 3058
{
+ − 3059
// use keyboardSearch from the listView so we do not duplicate code
+ − 3060
QAbstractItemView *view = viewContainer()->itemView();
+ − 3061
view->setCurrentIndex(currentIndex);
+ − 3062
int currentRow = view->currentIndex().row();
+ − 3063
view->keyboardSearch(text);
+ − 3064
if (currentRow != view->currentIndex().row()) {
+ − 3065
setCurrentIndex(view->currentIndex());
+ − 3066
emitActivated(currentIndex);
+ − 3067
}
+ − 3068
}
+ − 3069
+ − 3070
void QComboBoxPrivate::modelChanged()
+ − 3071
{
+ − 3072
Q_Q(QComboBox);
+ − 3073
+ − 3074
if (sizeAdjustPolicy == QComboBox::AdjustToContents) {
+ − 3075
sizeHint = QSize();
+ − 3076
adjustComboBoxSize();
+ − 3077
q->updateGeometry();
+ − 3078
}
+ − 3079
}
+ − 3080
+ − 3081
/*!
+ − 3082
\reimp
+ − 3083
*/
+ − 3084
void QComboBox::inputMethodEvent(QInputMethodEvent *e)
+ − 3085
{
+ − 3086
Q_D(QComboBox);
+ − 3087
if (d->lineEdit) {
+ − 3088
d->lineEdit->event(e);
+ − 3089
} else {
+ − 3090
if (!e->commitString().isEmpty())
+ − 3091
d->keyboardSearchString(e->commitString());
+ − 3092
else
+ − 3093
e->ignore();
+ − 3094
}
+ − 3095
}
+ − 3096
+ − 3097
/*!
+ − 3098
\reimp
+ − 3099
*/
+ − 3100
QVariant QComboBox::inputMethodQuery(Qt::InputMethodQuery query) const
+ − 3101
{
+ − 3102
Q_D(const QComboBox);
+ − 3103
if (d->lineEdit)
+ − 3104
return d->lineEdit->inputMethodQuery(query);
+ − 3105
return QWidget::inputMethodQuery(query);
+ − 3106
}
+ − 3107
+ − 3108
/*!
+ − 3109
\fn bool QComboBox::editable() const
+ − 3110
+ − 3111
Use isEditable() instead.
+ − 3112
*/
+ − 3113
+ − 3114
/*!
+ − 3115
\fn void QComboBox::insertItem(const QPixmap &pixmap, int index)
+ − 3116
+ − 3117
Use an insertItem() function that takes a QIcon instead, for
+ − 3118
example, insertItem(index, QIcon(pixmap)).
+ − 3119
*/
+ − 3120
+ − 3121
/*!
+ − 3122
\fn void QComboBox::insertItem(const QPixmap &pixmap, const QString &text, int index)
+ − 3123
+ − 3124
Use an insertItem() function that takes a QIcon instead, for
+ − 3125
example, insertItem(index, QIcon(pixmap), text).
+ − 3126
+ − 3127
\sa insertItems()
+ − 3128
*/
+ − 3129
+ − 3130
/*!
+ − 3131
\fn void QComboBox::changeItem(const QString &text, int index)
+ − 3132
+ − 3133
Use setItemText() instead.
+ − 3134
*/
+ − 3135
+ − 3136
/*!
+ − 3137
\fn void QComboBox::changeItem(const QPixmap &pixmap, int index)
+ − 3138
+ − 3139
Use setItemIcon() instead, for example,
+ − 3140
setItemIcon(index, QIcon(pixmap)).
+ − 3141
*/
+ − 3142
+ − 3143
/*!
+ − 3144
\fn void QComboBox::changeItem(const QPixmap &pixmap, const QString &text, int index)
+ − 3145
+ − 3146
Use setItem() instead, for example, setItem(index, QIcon(pixmap),text).
+ − 3147
*/
+ − 3148
+ − 3149
/*!
+ − 3150
\fn void QComboBox::addItem(const QString &text, const QVariant &userData)
+ − 3151
+ − 3152
Adds an item to the combobox with the given \a text, and
+ − 3153
containing the specified \a userData (stored in the Qt::UserRole).
+ − 3154
The item is appended to the list of existing items.
+ − 3155
*/
+ − 3156
+ − 3157
/*!
+ − 3158
\fn void QComboBox::addItem(const QIcon &icon, const QString &text,
+ − 3159
const QVariant &userData)
+ − 3160
+ − 3161
Adds an item to the combobox with the given \a icon and \a text,
+ − 3162
and containing the specified \a userData (stored in the
+ − 3163
Qt::UserRole). The item is appended to the list of existing items.
+ − 3164
*/
+ − 3165
+ − 3166
/*!
+ − 3167
\fn void QComboBox::addItems(const QStringList &texts)
+ − 3168
+ − 3169
Adds each of the strings in the given \a texts to the combobox. Each item
+ − 3170
is appended to the list of existing items in turn.
+ − 3171
*/
+ − 3172
+ − 3173
/*!
+ − 3174
\fn void QComboBox::editTextChanged(const QString &text)
+ − 3175
+ − 3176
This signal is emitted when the text in the combobox's line edit
+ − 3177
widget is changed. The new text is specified by \a text.
+ − 3178
*/
+ − 3179
+ − 3180
/*!
+ − 3181
\fn QComboBox::InsertPolicy QComboBox::insertionPolicy() const
+ − 3182
\compat
+ − 3183
+ − 3184
Use QComboBox::insertPolicy instead.
+ − 3185
*/
+ − 3186
+ − 3187
/*!
+ − 3188
\fn void QComboBox::setInsertionPolicy(InsertPolicy policy)
+ − 3189
\compat
+ − 3190
+ − 3191
Use QComboBox::insertPolicy instead.
+ − 3192
*/
+ − 3193
+ − 3194
/*!
+ − 3195
\fn void QComboBox::setCurrentText(const QString &text)
+ − 3196
\compat
+ − 3197
+ − 3198
Use setItemText() instead.
+ − 3199
+ − 3200
\sa currentIndex()
+ − 3201
*/
+ − 3202
+ − 3203
/*!
+ − 3204
\fn QString QComboBox::text(int index) const
+ − 3205
\compat
+ − 3206
+ − 3207
Use itemText() instead.
+ − 3208
*/
+ − 3209
+ − 3210
/*!
+ − 3211
\fn QPixmap QComboBox::pixmap(int index) const
+ − 3212
\compat
+ − 3213
+ − 3214
Use itemIcon() instead.
+ − 3215
*/
+ − 3216
+ − 3217
/*!
+ − 3218
\fn void QComboBox::insertStringList(const QStringList &list, int index)
+ − 3219
\compat
+ − 3220
+ − 3221
Use insertItems() instead.
+ − 3222
*/
+ − 3223
+ − 3224
/*!
+ − 3225
\fn void QComboBox::insertItem(const QString &text, int index)
+ − 3226
\compat
+ − 3227
*/
+ − 3228
+ − 3229
/*!
+ − 3230
\fn void QComboBox::clearEdit()
+ − 3231
\compat
+ − 3232
+ − 3233
Use clearEditText() instead.
+ − 3234
*/
+ − 3235
+ − 3236
+ − 3237
/*!
+ − 3238
\property QComboBox::frame
+ − 3239
\brief whether the combo box draws itself with a frame
+ − 3240
+ − 3241
+ − 3242
If enabled (the default) the combo box draws itself inside a
+ − 3243
frame, otherwise the combo box draws itself without any frame.
+ − 3244
*/
+ − 3245
bool QComboBox::hasFrame() const
+ − 3246
{
+ − 3247
Q_D(const QComboBox);
+ − 3248
return d->frame;
+ − 3249
}
+ − 3250
+ − 3251
+ − 3252
void QComboBox::setFrame(bool enable)
+ − 3253
{
+ − 3254
Q_D(QComboBox);
+ − 3255
d->frame = enable;
+ − 3256
update();
+ − 3257
updateGeometry();
+ − 3258
}
+ − 3259
+ − 3260
/*!
+ − 3261
\property QComboBox::modelColumn
+ − 3262
\brief the column in the model that is visible.
+ − 3263
+ − 3264
If set prior to populating the combo box, the pop-up view will
+ − 3265
not be affected and will show the first column (using this property's
+ − 3266
default value).
+ − 3267
+ − 3268
By default, this property has a value of 0.
+ − 3269
*/
+ − 3270
int QComboBox::modelColumn() const
+ − 3271
{
+ − 3272
Q_D(const QComboBox);
+ − 3273
return d->modelColumn;
+ − 3274
}
+ − 3275
+ − 3276
void QComboBox::setModelColumn(int visibleColumn)
+ − 3277
{
+ − 3278
Q_D(QComboBox);
+ − 3279
d->modelColumn = visibleColumn;
+ − 3280
QListView *lv = qobject_cast<QListView *>(d->viewContainer()->itemView());
+ − 3281
if (lv)
+ − 3282
lv->setModelColumn(visibleColumn);
+ − 3283
#ifndef QT_NO_COMPLETER
+ − 3284
if (d->lineEdit && d->lineEdit->completer()
+ − 3285
&& d->lineEdit->completer() == d->completer)
+ − 3286
d->lineEdit->completer()->setCompletionColumn(visibleColumn);
+ − 3287
#endif
+ − 3288
setCurrentIndex(currentIndex()); //update the text to the text of the new column;
+ − 3289
}
+ − 3290
+ − 3291
/*!
+ − 3292
\fn int QComboBox::currentItem() const
+ − 3293
+ − 3294
Use currentIndex() instead.
+ − 3295
*/
+ − 3296
+ − 3297
/*!
+ − 3298
\fn void QComboBox::setCurrentItem(int)
+ − 3299
+ − 3300
Use setCurrentIndex(int) instead.
+ − 3301
*/
+ − 3302
+ − 3303
/*!
+ − 3304
\fn void QComboBox::popup()
+ − 3305
+ − 3306
Use showPopup() instead.
+ − 3307
*/
+ − 3308
+ − 3309
/*!
+ − 3310
\fn void QComboBox::textChanged(const QString &text)
+ − 3311
+ − 3312
Use the editTextChanged(const QString &text) signal instead.
+ − 3313
*/
+ − 3314
+ − 3315
/*!
+ − 3316
\typedef QComboBox::Policy
+ − 3317
\compat
+ − 3318
+ − 3319
Use QComboBox::InsertPolicy instead.
+ − 3320
*/
+ − 3321
+ − 3322
QT_END_NAMESPACE
+ − 3323
+ − 3324
#include "moc_qcombobox.cpp"
+ − 3325
+ − 3326
#endif // QT_NO_COMBOBOX