Changeset View
Changeset View
Standalone View
Standalone View
src/khistorycombobox.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 36 | public: | |||
---|---|---|---|---|---|
71 | int currentIndex; | 71 | int currentIndex; | ||
72 | 72 | | |||
73 | /** | 73 | /** | ||
74 | * Indicates that the user at least once rotated Up through the entire list | 74 | * Indicates that the user at least once rotated Up through the entire list | ||
75 | * Needed to allow going back after rotation. | 75 | * Needed to allow going back after rotation. | ||
76 | */ | 76 | */ | ||
77 | bool rotated = false; | 77 | bool rotated = false; | ||
78 | 78 | | |||
79 | std::function<QIcon(QString)> iconProvider; | ||||
80 | | ||||
79 | Q_DECLARE_PUBLIC(KHistoryComboBox) | 81 | Q_DECLARE_PUBLIC(KHistoryComboBox) | ||
80 | }; | 82 | }; | ||
81 | 83 | | |||
82 | void KHistoryComboBoxPrivate::init(bool useCompletion) | 84 | void KHistoryComboBoxPrivate::init(bool useCompletion) | ||
83 | { | 85 | { | ||
84 | Q_Q(KHistoryComboBox); | 86 | Q_Q(KHistoryComboBox); | ||
85 | // Set a default history size to something reasonable, Qt sets it to INT_MAX by default | 87 | // Set a default history size to something reasonable, Qt sets it to INT_MAX by default | ||
86 | q->setMaxCount(50); | 88 | q->setMaxCount(50); | ||
▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Line(s) | 229 | if (itemText(i) == item) { | |||
232 | --itemCount; | 234 | --itemCount; | ||
233 | } else { | 235 | } else { | ||
234 | ++i; | 236 | ++i; | ||
235 | } | 237 | } | ||
236 | } | 238 | } | ||
237 | } | 239 | } | ||
238 | 240 | | |||
239 | // now add the item | 241 | // now add the item | ||
240 | if (d->pixmapProvider) { | 242 | if (d->iconProvider) { | ||
243 | insertItem(0, d->iconProvider(item), item); | ||||
244 | } else if (d->pixmapProvider) { | ||||
241 | insertItem(0, d->pixmapProvider->pixmapFor(item, iconSize().height()), item); | 245 | insertItem(0, d->pixmapProvider->pixmapFor(item, iconSize().height()), item); | ||
242 | } else { | 246 | } else { | ||
243 | insertItem(0, item); | 247 | insertItem(0, item); | ||
244 | } | 248 | } | ||
245 | 249 | | |||
246 | if (wasCurrent) { | 250 | if (wasCurrent) { | ||
247 | setCurrentIndex(0); | 251 | setCurrentIndex(0); | ||
248 | } | 252 | } | ||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | 398 | { | |||
403 | if (ev->angleDelta().y() > 0) { | 407 | if (ev->angleDelta().y() > 0) { | ||
404 | d->rotateUp(); | 408 | d->rotateUp(); | ||
405 | } else { | 409 | } else { | ||
406 | d->rotateDown(); | 410 | d->rotateDown(); | ||
407 | } | 411 | } | ||
408 | ev->accept(); | 412 | ev->accept(); | ||
409 | } | 413 | } | ||
410 | 414 | | |||
415 | #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 65) | ||||
dfaure: s/ENABLE/BUILD/ in .cpp files | |||||
411 | void KHistoryComboBox::setPixmapProvider(KPixmapProvider *provider) | 416 | void KHistoryComboBox::setPixmapProvider(KPixmapProvider *provider) | ||
412 | { | 417 | { | ||
413 | Q_D(KHistoryComboBox); | 418 | Q_D(KHistoryComboBox); | ||
414 | if (d->pixmapProvider == provider) { | 419 | if (d->pixmapProvider == provider) { | ||
415 | return; | 420 | return; | ||
416 | } | 421 | } | ||
417 | 422 | | |||
418 | delete d->pixmapProvider; | 423 | delete d->pixmapProvider; | ||
419 | d->pixmapProvider = provider; | 424 | d->pixmapProvider = provider; | ||
420 | 425 | | |||
421 | // re-insert all the items with/without pixmap | 426 | // re-insert all the items with/without pixmap | ||
422 | // I would prefer to use changeItem(), but that doesn't honor the pixmap | 427 | // I would prefer to use changeItem(), but that doesn't honor the pixmap | ||
423 | // when using an editable combobox (what we do) | 428 | // when using an editable combobox (what we do) | ||
424 | if (count() > 0) { | 429 | if (count() > 0) { | ||
425 | QStringList items(historyItems()); | 430 | QStringList items(historyItems()); | ||
426 | clear(); | 431 | clear(); | ||
427 | insertItems(items); | 432 | insertItems(items); | ||
428 | } | 433 | } | ||
429 | } | 434 | } | ||
435 | #endif | ||||
436 | | ||||
437 | void KHistoryComboBox::setIconProvider(std::function<QIcon(const QString &)> providerFunction) | ||||
438 | { | ||||
439 | Q_D(KHistoryComboBox); | ||||
440 | d->iconProvider = providerFunction; | ||||
441 | } | ||||
430 | 442 | | |||
431 | void KHistoryComboBox::insertItems(const QStringList &items) | 443 | void KHistoryComboBox::insertItems(const QStringList &items) | ||
432 | { | 444 | { | ||
433 | Q_D(KHistoryComboBox); | 445 | Q_D(KHistoryComboBox); | ||
434 | QStringList::ConstIterator it = items.constBegin(); | 446 | QStringList::ConstIterator it = items.constBegin(); | ||
435 | const QStringList::ConstIterator itEnd = items.constEnd(); | 447 | const QStringList::ConstIterator itEnd = items.constEnd(); | ||
436 | 448 | | |||
437 | while (it != itEnd) { | 449 | while (it != itEnd) { | ||
438 | const QString item = *it; | 450 | const QString item = *it; | ||
439 | if (!item.isEmpty()) { // only insert non-empty items | 451 | if (!item.isEmpty()) { // only insert non-empty items | ||
440 | if (d->pixmapProvider) | 452 | | ||
453 | if (d->iconProvider) { | ||||
454 | addItem(d->iconProvider(item), item); | ||||
455 | } else if (d->pixmapProvider) { | ||||
441 | addItem(d->pixmapProvider->pixmapFor(item, iconSize().height()), | 456 | addItem(d->pixmapProvider->pixmapFor(item, iconSize().height()), | ||
442 | item); | 457 | item); | ||
443 | else { | 458 | } else { | ||
444 | addItem(item); | 459 | addItem(item); | ||
445 | } | 460 | } | ||
446 | } | 461 | } | ||
447 | ++it; | 462 | ++it; | ||
448 | } | 463 | } | ||
449 | } | 464 | } | ||
450 | 465 | | |||
451 | void KHistoryComboBoxPrivate::_k_clear() | 466 | void KHistoryComboBoxPrivate::_k_clear() | ||
Show All 28 Lines | 494 | #if QT_DEPRECATED_SINCE(5, 15) || QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | |||
480 | emit q->activated(text); | 495 | emit q->activated(text); | ||
481 | #endif | 496 | #endif | ||
482 | #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) | 497 | #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) | ||
483 | emit q->textActivated(text); | 498 | emit q->textActivated(text); | ||
484 | #endif | 499 | #endif | ||
485 | } | 500 | } | ||
486 | } | 501 | } | ||
487 | 502 | | |||
503 | #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 65) | ||||
dfaure: BUILD | |||||
488 | KPixmapProvider *KHistoryComboBox::pixmapProvider() const | 504 | KPixmapProvider *KHistoryComboBox::pixmapProvider() const | ||
489 | { | 505 | { | ||
490 | Q_D(const KHistoryComboBox); | 506 | Q_D(const KHistoryComboBox); | ||
491 | return d->pixmapProvider; | 507 | return d->pixmapProvider; | ||
492 | } | 508 | } | ||
509 | #endif | ||||
493 | 510 | | |||
494 | void KHistoryComboBox::reset() | 511 | void KHistoryComboBox::reset() | ||
495 | { | 512 | { | ||
496 | Q_D(KHistoryComboBox); | 513 | Q_D(KHistoryComboBox); | ||
497 | d->currentIndex = -1; | 514 | d->currentIndex = -1; | ||
498 | d->rotated = false; | 515 | d->rotated = false; | ||
499 | } | 516 | } | ||
500 | 517 | | |||
501 | #include "moc_khistorycombobox.cpp" | 518 | #include "moc_khistorycombobox.cpp" |
s/ENABLE/BUILD/ in .cpp files