Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kfileplacesview.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
56 | #define CAPACITYBAR_HEIGHT 6 | 56 | #define CAPACITYBAR_HEIGHT 6 | ||
57 | 57 | | |||
58 | class KFilePlacesViewDelegate : public QAbstractItemDelegate | 58 | class KFilePlacesViewDelegate : public QAbstractItemDelegate | ||
59 | { | 59 | { | ||
60 | Q_OBJECT | 60 | Q_OBJECT | ||
61 | public: | 61 | public: | ||
62 | KFilePlacesViewDelegate(KFilePlacesView *parent); | 62 | KFilePlacesViewDelegate(KFilePlacesView *parent); | ||
63 | virtual ~KFilePlacesViewDelegate(); | 63 | virtual ~KFilePlacesViewDelegate(); | ||
64 | virtual QSize sizeHint(const QStyleOptionViewItem &option, | 64 | QSize sizeHint(const QStyleOptionViewItem &option, | ||
65 | const QModelIndex &index) const Q_DECL_OVERRIDE; | 65 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||
66 | virtual void paint(QPainter *painter, | 66 | void paint(QPainter *painter, | ||
dfaure: re-indent after the removal of "virtual" | |||||
67 | const QStyleOptionViewItem &option, | 67 | const QStyleOptionViewItem &option, | ||
68 | const QModelIndex &index) const Q_DECL_OVERRIDE; | 68 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||
dfaure: same here, please re-indent after the removal of "virtual" | |||||
69 | 69 | | |||
70 | int iconSize() const; | 70 | int iconSize() const; | ||
71 | void setIconSize(int newSize); | 71 | void setIconSize(int newSize); | ||
72 | 72 | | |||
73 | void addAppearingItem(const QModelIndex &index); | 73 | void addAppearingItem(const QModelIndex &index); | ||
74 | void setAppearingItemProgress(qreal value); | 74 | void setAppearingItemProgress(qreal value); | ||
75 | void addDisappearingItem(const QModelIndex &index); | 75 | void addDisappearingItem(const QModelIndex &index); | ||
76 | void addDisappearingItemGroup(const QModelIndex &index); | 76 | void addDisappearingItemGroup(const QModelIndex &index); | ||
▲ Show 20 Lines • Show All 414 Lines • ▼ Show 20 Line(s) | 483 | public: | |||
491 | KFilePlacesView *const q; | 491 | KFilePlacesView *const q; | ||
492 | 492 | | |||
493 | QUrl currentUrl; | 493 | QUrl currentUrl; | ||
494 | bool autoResizeItems; | 494 | bool autoResizeItems; | ||
495 | bool showAll; | 495 | bool showAll; | ||
496 | bool smoothItemResizing; | 496 | bool smoothItemResizing; | ||
497 | bool dropOnPlace; | 497 | bool dropOnPlace; | ||
498 | bool dragging; | 498 | bool dragging; | ||
499 | Solid::StorageAccess *lastClickedStorage; | 499 | Solid::StorageAccess *lastClickedStorage = nullptr; | ||
500 | QPersistentModelIndex lastClickedIndex; | 500 | QPersistentModelIndex lastClickedIndex; | ||
501 | 501 | | |||
502 | QRect dropRect; | 502 | QRect dropRect; | ||
503 | 503 | | |||
504 | void setCurrentIndex(const QModelIndex &index); | 504 | void setCurrentIndex(const QModelIndex &index); | ||
505 | void adaptItemSize(); | 505 | void adaptItemSize(); | ||
506 | void updateHiddenRows(); | 506 | void updateHiddenRows(); | ||
507 | bool insertAbove(const QRect &itemRect, const QPoint &pos) const; | 507 | bool insertAbove(const QRect &itemRect, const QPoint &pos) const; | ||
508 | bool insertBelow(const QRect &itemRect, const QPoint &pos) const; | 508 | bool insertBelow(const QRect &itemRect, const QPoint &pos) const; | ||
509 | int insertIndicatorHeight(int itemHeight) const; | 509 | int insertIndicatorHeight(int itemHeight) const; | ||
510 | void fadeCapacityBar(const QModelIndex &index, FadeType fadeType); | 510 | void fadeCapacityBar(const QModelIndex &index, FadeType fadeType); | ||
511 | int sectionsCount() const; | 511 | int sectionsCount() const; | ||
512 | | ||||
513 | void addDisappearingItem(KFilePlacesViewDelegate *delegate, const QModelIndex &index); | ||||
514 | | ||||
512 | void triggerItemAppearingAnimation(); | 515 | void triggerItemAppearingAnimation(); | ||
513 | void triggerItemDisappearingAnimation(); | 516 | void triggerItemDisappearingAnimation(); | ||
514 | 517 | | |||
515 | void _k_placeClicked(const QModelIndex &index); | 518 | void _k_placeClicked(const QModelIndex &index); | ||
516 | void _k_placeEntered(const QModelIndex &index); | 519 | void _k_placeEntered(const QModelIndex &index); | ||
517 | void _k_placeLeft(const QModelIndex &index); | 520 | void _k_placeLeft(const QModelIndex &index); | ||
518 | void _k_storageSetupDone(const QModelIndex &index, bool success); | 521 | void _k_storageSetupDone(const QModelIndex &index, bool success); | ||
519 | void _k_adaptItemsUpdate(qreal value); | 522 | void _k_adaptItemsUpdate(qreal value); | ||
520 | void _k_itemAppearUpdate(qreal value); | 523 | void _k_itemAppearUpdate(qreal value); | ||
521 | void _k_itemDisappearUpdate(qreal value); | 524 | void _k_itemDisappearUpdate(qreal value); | ||
522 | void _k_enableSmoothItemResizing(); | 525 | void _k_enableSmoothItemResizing(); | ||
523 | void _k_capacityBarFadeValueChanged(); | 526 | void _k_capacityBarFadeValueChanged(); | ||
524 | void _k_triggerDevicePolling(); | 527 | void _k_triggerDevicePolling(); | ||
525 | 528 | | |||
526 | QTimeLine adaptItemsTimeline; | 529 | QTimeLine adaptItemsTimeline; | ||
527 | int oldSize, endSize; | 530 | int oldSize, endSize; | ||
528 | 531 | | |||
529 | QTimeLine itemAppearTimeline; | 532 | QTimeLine itemAppearTimeline; | ||
530 | QTimeLine itemDisappearTimeline; | 533 | QTimeLine itemDisappearTimeline; | ||
531 | 534 | | |||
532 | KFilePlacesEventWatcher *const watcher; | 535 | KFilePlacesEventWatcher *const watcher; | ||
533 | KFilePlacesViewDelegate *delegate; | 536 | KFilePlacesViewDelegate *delegate = nullptr; | ||
534 | QTimer pollDevices; | 537 | QTimer pollDevices; | ||
535 | int pollingRequestCount; | 538 | int pollingRequestCount; | ||
536 | }; | 539 | }; | ||
537 | 540 | | |||
538 | KFilePlacesView::KFilePlacesView(QWidget *parent) | 541 | KFilePlacesView::KFilePlacesView(QWidget *parent) | ||
539 | : QListView(parent), d(new Private(this)) | 542 | : QListView(parent), d(new Private(this)) | ||
540 | { | 543 | { | ||
541 | d->showAll = false; | 544 | d->showAll = false; | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
627 | 630 | | |||
628 | bool KFilePlacesView::isAutoResizeItemsEnabled() const | 631 | bool KFilePlacesView::isAutoResizeItemsEnabled() const | ||
629 | { | 632 | { | ||
630 | return d->autoResizeItems; | 633 | return d->autoResizeItems; | ||
631 | } | 634 | } | ||
632 | 635 | | |||
633 | void KFilePlacesView::setUrl(const QUrl &url) | 636 | void KFilePlacesView::setUrl(const QUrl &url) | ||
634 | { | 637 | { | ||
635 | QUrl oldUrl = d->currentUrl; | | |||
636 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(model()); | 638 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(model()); | ||
637 | 639 | | |||
638 | if (placesModel == nullptr) { | 640 | if (placesModel == nullptr) { | ||
639 | return; | 641 | return; | ||
640 | } | 642 | } | ||
641 | 643 | | |||
642 | QModelIndex index = placesModel->closestItem(url); | 644 | QModelIndex index = placesModel->closestItem(url); | ||
643 | QModelIndex current = selectionModel()->currentIndex(); | 645 | QModelIndex current = selectionModel()->currentIndex(); | ||
644 | 646 | | |||
645 | if (index.isValid()) { | 647 | if (index.isValid()) { | ||
646 | if (current != index && placesModel->isHidden(current) && !d->showAll) { | 648 | if (current != index && placesModel->isHidden(current) && !d->showAll) { | ||
647 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | 649 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | ||
648 | delegate->addDisappearingItem(current); | 650 | d->addDisappearingItem(delegate, current); | ||
649 | d->triggerItemDisappearingAnimation(); | | |||
650 | } | 651 | } | ||
651 | 652 | | |||
652 | if (current != index && placesModel->isHidden(index) && !d->showAll) { | 653 | if (current != index && placesModel->isHidden(index) && !d->showAll) { | ||
653 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | 654 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | ||
654 | delegate->addAppearingItem(index); | 655 | delegate->addAppearingItem(index); | ||
655 | d->triggerItemAppearingAnimation(); | 656 | d->triggerItemAppearingAnimation(); | ||
656 | setRowHidden(index.row(), false); | 657 | setRowHidden(index.row(), false); | ||
657 | } | 658 | } | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 709 | { | |||
710 | if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)) { | 711 | if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)) { | ||
711 | d->_k_placeClicked(currentIndex()); | 712 | d->_k_placeClicked(currentIndex()); | ||
712 | } | 713 | } | ||
713 | } | 714 | } | ||
714 | 715 | | |||
715 | void KFilePlacesView::contextMenuEvent(QContextMenuEvent *event) | 716 | void KFilePlacesView::contextMenuEvent(QContextMenuEvent *event) | ||
716 | { | 717 | { | ||
717 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(model()); | 718 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(model()); | ||
718 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(itemDelegate()); | | |||
719 | 719 | | |||
720 | if (placesModel == nullptr) { | 720 | if (!placesModel) { | ||
721 | return; | 721 | return; | ||
722 | } | 722 | } | ||
723 | 723 | | |||
724 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | ||||
725 | | ||||
724 | QModelIndex index = indexAt(event->pos()); | 726 | QModelIndex index = indexAt(event->pos()); | ||
725 | QString label = placesModel->text(index).replace('&', QLatin1String("&&")); | 727 | const QString label = placesModel->text(index).replace(QLatin1Char('&'), QLatin1String("&&")); | ||
726 | 728 | | |||
727 | QMenu menu; | 729 | QMenu menu; | ||
728 | 730 | | |||
729 | QAction *edit = nullptr; | 731 | QAction *edit = nullptr; | ||
730 | QAction *hide = nullptr; | 732 | QAction *hide = nullptr; | ||
731 | QAction *emptyTrash = nullptr; | 733 | QAction *emptyTrash = nullptr; | ||
732 | QAction *eject = nullptr; | 734 | QAction *eject = nullptr; | ||
733 | QAction *teardown = nullptr; | 735 | QAction *teardown = nullptr; | ||
734 | QAction *add = nullptr; | 736 | QAction *add = nullptr; | ||
735 | QAction *mainSeparator = nullptr; | 737 | QAction *mainSeparator = nullptr; | ||
You use qobject_cast elsewhere, why not here too? Or even... you use static_cast for the delegate in 90% of the code, why two uses of qobject_cast? If it's mandatory for the delegate to be a KFilePlacesViewDelegate, it's mandatory everywhere, right? (too bad setItemDelegate isn't virtual, we could have caught it there...) dfaure: You use qobject_cast elsewhere, why not here too?
Or even... you use static_cast for the… | |||||
736 | QAction *hideSection = nullptr; | 738 | QAction *hideSection = nullptr; | ||
737 | 739 | | |||
738 | const bool clickOverHeader = delegate->pointIsHeaderArea(event->pos()); | 740 | const bool clickOverHeader = delegate->pointIsHeaderArea(event->pos()); | ||
739 | if (clickOverHeader) { | 741 | if (clickOverHeader) { | ||
740 | const KFilePlacesModel::GroupType type = placesModel->groupType(index); | 742 | const KFilePlacesModel::GroupType type = placesModel->groupType(index); | ||
741 | hideSection = menu.addAction(i18n("Hide Section")); | 743 | hideSection = menu.addAction(i18n("Hide Section")); | ||
742 | hideSection->setCheckable(true); | 744 | hideSection->setCheckable(true); | ||
743 | hideSection->setChecked(placesModel->isGroupHidden(type)); | 745 | hideSection->setChecked(placesModel->isGroupHidden(type)); | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
803 | menu.addActions(actions()); | 805 | menu.addActions(actions()); | ||
804 | 806 | | |||
805 | if (menu.isEmpty()) { | 807 | if (menu.isEmpty()) { | ||
806 | return; | 808 | return; | ||
807 | } | 809 | } | ||
808 | 810 | | |||
809 | QAction *result = menu.exec(event->globalPos()); | 811 | QAction *result = menu.exec(event->globalPos()); | ||
810 | 812 | | |||
811 | if (emptyTrash != nullptr && result == emptyTrash) { | 813 | if (emptyTrash && (result == emptyTrash)) { | ||
812 | 814 | | |||
813 | KIO::JobUiDelegate uiDelegate; | 815 | KIO::JobUiDelegate uiDelegate; | ||
814 | uiDelegate.setWindow(window()); | 816 | uiDelegate.setWindow(window()); | ||
815 | if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { | 817 | if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { | ||
816 | KIO::Job* job = KIO::emptyTrash(); | 818 | KIO::Job* job = KIO::emptyTrash(); | ||
817 | KJobWidgets::setWindow(job, window()); | 819 | KJobWidgets::setWindow(job, window()); | ||
818 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | 820 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | ||
819 | } | 821 | } | ||
820 | } else if (edit != nullptr && result == edit) { | 822 | } else if (edit && (result == edit)) { | ||
821 | KBookmark bookmark = placesModel->bookmarkForIndex(index); | 823 | KBookmark bookmark = placesModel->bookmarkForIndex(index); | ||
822 | QUrl url = bookmark.url(); | 824 | QUrl url = bookmark.url(); | ||
823 | QString label = bookmark.text(); | 825 | QString label = bookmark.text(); | ||
824 | QString iconName = bookmark.icon(); | 826 | QString iconName = bookmark.icon(); | ||
825 | bool appLocal = !bookmark.metaDataItem(QStringLiteral("OnlyInApp")).isEmpty(); | 827 | bool appLocal = !bookmark.metaDataItem(QStringLiteral("OnlyInApp")).isEmpty(); | ||
826 | 828 | | |||
827 | if (KFilePlaceEditDialog::getInformation(true, url, label, | 829 | if (KFilePlaceEditDialog::getInformation(true, url, label, | ||
828 | iconName, false, appLocal, 64, this)) { | 830 | iconName, false, appLocal, 64, this)) { | ||
Show All 18 Lines | |||||
847 | } else if (hide && (result == hide)) { | 849 | } else if (hide && (result == hide)) { | ||
848 | placesModel->setPlaceHidden(index, hide->isChecked()); | 850 | placesModel->setPlaceHidden(index, hide->isChecked()); | ||
849 | QModelIndex current = placesModel->closestItem(d->currentUrl); | 851 | QModelIndex current = placesModel->closestItem(d->currentUrl); | ||
850 | 852 | | |||
851 | if (index != current && !d->showAll && hide->isChecked()) { | 853 | if (index != current && !d->showAll && hide->isChecked()) { | ||
852 | delegate->addDisappearingItem(index); | 854 | delegate->addDisappearingItem(index); | ||
853 | d->triggerItemDisappearingAnimation(); | 855 | d->triggerItemDisappearingAnimation(); | ||
854 | } | 856 | } | ||
855 | } else if (showAll != nullptr && result == showAll) { | 857 | } else if (showAll && (result == showAll)) { | ||
856 | setShowAll(showAll->isChecked()); | 858 | setShowAll(showAll->isChecked()); | ||
857 | } else if (teardown != nullptr && result == teardown) { | 859 | } else if (teardown && (result == teardown)) { | ||
858 | placesModel->requestTeardown(index); | 860 | placesModel->requestTeardown(index); | ||
859 | } else if (eject != nullptr && result == eject) { | 861 | } else if (eject && (result == eject)) { | ||
860 | placesModel->requestEject(index); | 862 | placesModel->requestEject(index); | ||
861 | } else if (add != nullptr && result == add) { | 863 | } else if (add && (result == add)) { | ||
862 | QUrl url = d->currentUrl; | 864 | QUrl url = d->currentUrl; | ||
863 | QString label; | 865 | QString label; | ||
864 | QString iconName = QStringLiteral("folder"); | 866 | QString iconName = QStringLiteral("folder"); | ||
865 | bool appLocal = true; | 867 | bool appLocal = true; | ||
866 | if (KFilePlaceEditDialog::getInformation(true, url, label, | 868 | if (KFilePlaceEditDialog::getInformation(true, url, label, | ||
867 | iconName, true, appLocal, 64, this)) { | 869 | iconName, true, appLocal, 64, this)) { | ||
868 | QString appName; | 870 | QString appName; | ||
869 | if (appLocal) { | 871 | if (appLocal) { | ||
Show All 26 Lines | 896 | { | |||
896 | d->smoothItemResizing = false; | 898 | d->smoothItemResizing = false; | ||
897 | } | 899 | } | ||
898 | 900 | | |||
899 | void KFilePlacesView::dragEnterEvent(QDragEnterEvent *event) | 901 | void KFilePlacesView::dragEnterEvent(QDragEnterEvent *event) | ||
900 | { | 902 | { | ||
901 | QListView::dragEnterEvent(event); | 903 | QListView::dragEnterEvent(event); | ||
902 | d->dragging = true; | 904 | d->dragging = true; | ||
903 | 905 | | |||
904 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(itemDelegate()); | 906 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | ||
905 | delegate->setShowHoverIndication(false); | 907 | delegate->setShowHoverIndication(false); | ||
906 | 908 | | |||
907 | d->dropRect = QRect(); | 909 | d->dropRect = QRect(); | ||
908 | } | 910 | } | ||
909 | 911 | | |||
910 | void KFilePlacesView::dragLeaveEvent(QDragLeaveEvent *event) | 912 | void KFilePlacesView::dragLeaveEvent(QDragLeaveEvent *event) | ||
911 | { | 913 | { | ||
912 | QListView::dragLeaveEvent(event); | 914 | QListView::dragLeaveEvent(event); | ||
913 | d->dragging = false; | 915 | d->dragging = false; | ||
914 | 916 | | |||
915 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(itemDelegate()); | 917 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | ||
916 | delegate->setShowHoverIndication(true); | 918 | delegate->setShowHoverIndication(true); | ||
917 | 919 | | |||
918 | setDirtyRegion(d->dropRect); | 920 | setDirtyRegion(d->dropRect); | ||
919 | } | 921 | } | ||
920 | 922 | | |||
921 | void KFilePlacesView::dragMoveEvent(QDragMoveEvent *event) | 923 | void KFilePlacesView::dragMoveEvent(QDragMoveEvent *event) | ||
922 | { | 924 | { | ||
923 | QListView::dragMoveEvent(event); | 925 | QListView::dragMoveEvent(event); | ||
Show All 34 Lines | 957 | if (!d->insertAbove(rect, pos) && !d->insertBelow(rect, pos)) { | |||
958 | emit urlsDropped(placesModel->url(index), event, this); | 960 | emit urlsDropped(placesModel->url(index), event, this); | ||
959 | event->acceptProposedAction(); | 961 | event->acceptProposedAction(); | ||
960 | } | 962 | } | ||
961 | } | 963 | } | ||
962 | 964 | | |||
963 | QListView::dropEvent(event); | 965 | QListView::dropEvent(event); | ||
964 | d->dragging = false; | 966 | d->dragging = false; | ||
965 | 967 | | |||
966 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(itemDelegate()); | 968 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | ||
967 | delegate->setShowHoverIndication(true); | 969 | delegate->setShowHoverIndication(true); | ||
968 | } | 970 | } | ||
969 | 971 | | |||
970 | void KFilePlacesView::paintEvent(QPaintEvent *event) | 972 | void KFilePlacesView::paintEvent(QPaintEvent *event) | ||
971 | { | 973 | { | ||
972 | QListView::paintEvent(event); | 974 | QListView::paintEvent(event); | ||
973 | if (d->dragging && !d->dropRect.isEmpty()) { | 975 | if (d->dragging && !d->dropRect.isEmpty()) { | ||
974 | // draw drop indicator | 976 | // draw drop indicator | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 1042 | connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), | |||
1041 | d->watcher, SLOT(currentIndexChanged(QModelIndex))); | 1043 | d->watcher, SLOT(currentIndexChanged(QModelIndex))); | ||
1042 | } | 1044 | } | ||
1043 | 1045 | | |||
1044 | void KFilePlacesView::rowsInserted(const QModelIndex &parent, int start, int end) | 1046 | void KFilePlacesView::rowsInserted(const QModelIndex &parent, int start, int end) | ||
1045 | { | 1047 | { | ||
1046 | QListView::rowsInserted(parent, start, end); | 1048 | QListView::rowsInserted(parent, start, end); | ||
1047 | setUrl(d->currentUrl); | 1049 | setUrl(d->currentUrl); | ||
1048 | 1050 | | |||
1049 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(itemDelegate()); | 1051 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(itemDelegate()); | ||
1050 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(model()); | 1052 | KFilePlacesModel *placesModel = static_cast<KFilePlacesModel *>(model()); | ||
1051 | 1053 | | |||
1052 | for (int i = start; i <= end; ++i) { | 1054 | for (int i = start; i <= end; ++i) { | ||
1053 | QModelIndex index = placesModel->index(i, 0, parent); | 1055 | QModelIndex index = placesModel->index(i, 0, parent); | ||
1054 | if (d->showAll || !placesModel->isHidden(index)) { | 1056 | if (d->showAll || !placesModel->isHidden(index)) { | ||
1055 | delegate->addAppearingItem(index); | 1057 | delegate->addAppearingItem(index); | ||
1056 | d->triggerItemAppearingAnimation(); | 1058 | d->triggerItemAppearingAnimation(); | ||
1057 | } else { | 1059 | } else { | ||
1058 | setRowHidden(i, true); | 1060 | setRowHidden(i, true); | ||
Show All 21 Lines | 1081 | if (!placesModel->isHidden(index)) { | |||
1080 | textWidth = qMax(textWidth, fm.width(index.data(Qt::DisplayRole).toString())); | 1082 | textWidth = qMax(textWidth, fm.width(index.data(Qt::DisplayRole).toString())); | ||
1081 | } | 1083 | } | ||
1082 | } | 1084 | } | ||
1083 | 1085 | | |||
1084 | const int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small) + 3 * LATERAL_MARGIN; | 1086 | const int iconSize = KIconLoader::global()->currentSize(KIconLoader::Small) + 3 * LATERAL_MARGIN; | ||
1085 | return QSize(iconSize + textWidth + fm.height() / 2, height); | 1087 | return QSize(iconSize + textWidth + fm.height() / 2, height); | ||
1086 | } | 1088 | } | ||
1087 | 1089 | | |||
1090 | void KFilePlacesView::Private::addDisappearingItem(KFilePlacesViewDelegate *delegate, const QModelIndex &index) | ||||
1091 | { | ||||
1092 | delegate->addDisappearingItem(index); | ||||
1093 | if (itemDisappearTimeline.state() != QTimeLine::Running) { | ||||
1094 | delegate->setDisappearingItemProgress(0.0); | ||||
1095 | itemDisappearTimeline.start(); | ||||
1096 | } | ||||
1097 | } | ||||
1098 | | ||||
1088 | void KFilePlacesView::Private::setCurrentIndex(const QModelIndex &index) | 1099 | void KFilePlacesView::Private::setCurrentIndex(const QModelIndex &index) | ||
1089 | { | 1100 | { | ||
1090 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(q->model()); | 1101 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(q->model()); | ||
1091 | 1102 | | |||
1092 | if (placesModel == nullptr) { | 1103 | if (placesModel == nullptr) { | ||
1093 | return; | 1104 | return; | ||
1094 | } | 1105 | } | ||
1095 | 1106 | | |||
1096 | QUrl url = placesModel->url(index); | 1107 | QUrl url = placesModel->url(index); | ||
1097 | 1108 | | |||
1098 | if (url.isValid()) { | 1109 | if (url.isValid()) { | ||
1099 | currentUrl = url; | 1110 | currentUrl = url; | ||
1100 | updateHiddenRows(); | 1111 | updateHiddenRows(); | ||
1101 | emit q->urlChanged(KFilePlacesModel::convertedUrl(url)); | 1112 | emit q->urlChanged(KFilePlacesModel::convertedUrl(url)); | ||
1102 | if (showAll) { | 1113 | if (showAll) { | ||
1103 | q->setShowAll(false); | 1114 | q->setShowAll(false); | ||
1104 | } | 1115 | } | ||
1105 | } else { | 1116 | } else { | ||
1106 | q->setUrl(currentUrl); | 1117 | q->setUrl(currentUrl); | ||
1107 | } | 1118 | } | ||
1108 | } | 1119 | } | ||
1109 | 1120 | | |||
1110 | void KFilePlacesView::Private::adaptItemSize() | 1121 | void KFilePlacesView::Private::adaptItemSize() | ||
1111 | { | 1122 | { | ||
1112 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(q->itemDelegate()); | 1123 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(q->itemDelegate()); | ||
1113 | if (!delegate) { | | |||
1114 | return; | | |||
1115 | } | | |||
1116 | 1124 | | |||
1117 | if (!autoResizeItems) { | 1125 | if (!autoResizeItems) { | ||
1118 | int size = q->iconSize().width(); // Assume width == height | 1126 | const int size = q->iconSize().width(); // Assume width == height | ||
1119 | delegate->setIconSize(size); | 1127 | delegate->setIconSize(size); | ||
1120 | q->scheduleDelayedItemsLayout(); | 1128 | q->scheduleDelayedItemsLayout(); | ||
1121 | return; | 1129 | return; | ||
1122 | } | 1130 | } | ||
1123 | 1131 | | |||
1124 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(q->model()); | 1132 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(q->model()); | ||
1125 | 1133 | | |||
1126 | if (placesModel == nullptr) { | 1134 | if (placesModel == nullptr) { | ||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Line(s) | |||||
1342 | void KFilePlacesView::Private::_k_storageSetupDone(const QModelIndex &index, bool success) | 1350 | void KFilePlacesView::Private::_k_storageSetupDone(const QModelIndex &index, bool success) | ||
1343 | { | 1351 | { | ||
1344 | if (index != lastClickedIndex) { | 1352 | if (index != lastClickedIndex) { | ||
1345 | return; | 1353 | return; | ||
1346 | } | 1354 | } | ||
1347 | 1355 | | |||
1348 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(q->model()); | 1356 | KFilePlacesModel *placesModel = qobject_cast<KFilePlacesModel *>(q->model()); | ||
1349 | 1357 | | |||
1358 | if (placesModel) { | ||||
1350 | QObject::disconnect(placesModel, SIGNAL(setupDone(QModelIndex,bool)), | 1359 | QObject::disconnect(placesModel, SIGNAL(setupDone(QModelIndex,bool)), | ||
1351 | q, SLOT(_k_storageSetupDone(QModelIndex,bool))); | 1360 | q, SLOT(_k_storageSetupDone(QModelIndex,bool))); | ||
1361 | } | ||||
1352 | 1362 | | |||
1353 | if (success) { | 1363 | if (success) { | ||
1354 | setCurrentIndex(lastClickedIndex); | 1364 | setCurrentIndex(lastClickedIndex); | ||
1355 | } else { | 1365 | } else { | ||
1356 | q->setUrl(currentUrl); | 1366 | q->setUrl(currentUrl); | ||
1357 | } | 1367 | } | ||
1358 | 1368 | | |||
1359 | lastClickedIndex = QPersistentModelIndex(); | 1369 | lastClickedIndex = QPersistentModelIndex(); | ||
1360 | } | 1370 | } | ||
1361 | 1371 | | |||
1362 | void KFilePlacesView::Private::_k_adaptItemsUpdate(qreal value) | 1372 | void KFilePlacesView::Private::_k_adaptItemsUpdate(qreal value) | ||
1363 | { | 1373 | { | ||
1364 | int add = (endSize - oldSize) * value; | 1374 | int add = (endSize - oldSize) * value; | ||
1365 | 1375 | | |||
1366 | int size = oldSize + add; | 1376 | int size = oldSize + add; | ||
1367 | 1377 | | |||
1368 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(q->itemDelegate()); | 1378 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(q->itemDelegate()); | ||
1369 | delegate->setIconSize(size); | 1379 | delegate->setIconSize(size); | ||
1370 | q->scheduleDelayedItemsLayout(); | 1380 | q->scheduleDelayedItemsLayout(); | ||
1371 | } | 1381 | } | ||
1372 | 1382 | | |||
1373 | void KFilePlacesView::Private::_k_itemAppearUpdate(qreal value) | 1383 | void KFilePlacesView::Private::_k_itemAppearUpdate(qreal value) | ||
1374 | { | 1384 | { | ||
1375 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(q->itemDelegate()); | 1385 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(q->itemDelegate()); | ||
1376 | 1386 | | |||
1377 | delegate->setAppearingItemProgress(value); | 1387 | delegate->setAppearingItemProgress(value); | ||
1378 | q->scheduleDelayedItemsLayout(); | 1388 | q->scheduleDelayedItemsLayout(); | ||
1379 | } | 1389 | } | ||
1380 | 1390 | | |||
1381 | void KFilePlacesView::Private::_k_itemDisappearUpdate(qreal value) | 1391 | void KFilePlacesView::Private::_k_itemDisappearUpdate(qreal value) | ||
1382 | { | 1392 | { | ||
1383 | KFilePlacesViewDelegate *delegate = dynamic_cast<KFilePlacesViewDelegate *>(q->itemDelegate()); | 1393 | KFilePlacesViewDelegate *delegate = static_cast<KFilePlacesViewDelegate *>(q->itemDelegate()); | ||
1384 | 1394 | | |||
1385 | delegate->setDisappearingItemProgress(value); | 1395 | delegate->setDisappearingItemProgress(value); | ||
1386 | 1396 | | |||
1387 | if (value >= 1.0) { | 1397 | if (value >= 1.0) { | ||
1388 | updateHiddenRows(); | 1398 | updateHiddenRows(); | ||
1389 | } | 1399 | } | ||
1390 | 1400 | | |||
1391 | q->scheduleDelayedItemsLayout(); | 1401 | q->scheduleDelayedItemsLayout(); | ||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |
re-indent after the removal of "virtual"