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_BUILD_DEPRECATED_SINCE(5, 66) | ||||
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 | 446 | | |||
435 | for (const QString item : items) { | 447 | for (const QString item : items) { | ||
436 | if (item.isEmpty()) { | 448 | if (item.isEmpty()) { | ||
437 | continue; | 449 | continue; | ||
438 | } | 450 | } | ||
439 | 451 | | |||
440 | if (d->pixmapProvider) { | 452 | if (d->iconProvider) { | ||
453 | addItem(d->iconProvider(item), item); | ||||
454 | } else if (d->pixmapProvider) { | ||||
441 | addItem(d->pixmapProvider->pixmapFor(item, iconSize().height()), item); | 455 | addItem(d->pixmapProvider->pixmapFor(item, iconSize().height()), item); | ||
442 | } else { | 456 | } else { | ||
443 | addItem(item); | 457 | addItem(item); | ||
444 | } | 458 | } | ||
445 | } | 459 | } | ||
446 | } | 460 | } | ||
447 | 461 | | |||
448 | void KHistoryComboBoxPrivate::_k_clear() | 462 | void KHistoryComboBoxPrivate::_k_clear() | ||
Show All 28 Lines | 490 | #if QT_DEPRECATED_SINCE(5, 15) || QT_VERSION < QT_VERSION_CHECK(5, 14, 0) | |||
477 | emit q->activated(text); | 491 | emit q->activated(text); | ||
478 | #endif | 492 | #endif | ||
479 | #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) | 493 | #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) | ||
480 | emit q->textActivated(text); | 494 | emit q->textActivated(text); | ||
481 | #endif | 495 | #endif | ||
482 | } | 496 | } | ||
483 | } | 497 | } | ||
484 | 498 | | |||
499 | #if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 66) | ||||
dfaure: BUILD | |||||
485 | KPixmapProvider *KHistoryComboBox::pixmapProvider() const | 500 | KPixmapProvider *KHistoryComboBox::pixmapProvider() const | ||
486 | { | 501 | { | ||
487 | Q_D(const KHistoryComboBox); | 502 | Q_D(const KHistoryComboBox); | ||
488 | return d->pixmapProvider; | 503 | return d->pixmapProvider; | ||
489 | } | 504 | } | ||
505 | #endif | ||||
490 | 506 | | |||
491 | void KHistoryComboBox::reset() | 507 | void KHistoryComboBox::reset() | ||
492 | { | 508 | { | ||
493 | Q_D(KHistoryComboBox); | 509 | Q_D(KHistoryComboBox); | ||
494 | d->currentIndex = -1; | 510 | d->currentIndex = -1; | ||
495 | d->rotated = false; | 511 | d->rotated = false; | ||
496 | } | 512 | } | ||
497 | 513 | | |||
498 | #include "moc_khistorycombobox.cpp" | 514 | #include "moc_khistorycombobox.cpp" |
s/ENABLE/BUILD/ in .cpp files