Index: src/filewidgets/kfileplacesview.cpp =================================================================== --- src/filewidgets/kfileplacesview.cpp +++ src/filewidgets/kfileplacesview.cpp @@ -506,6 +506,8 @@ void fadeCapacityBar(const QModelIndex &index, FadeType fadeType); int sectionsCount() const; + void addDisappearingItem(KFilePlacesViewDelegate *delegate, const QModelIndex &index); + // based on dolphin urls QUrl convertUrl(const QUrl &url) const; QUrl createTimelineUrl(const QUrl &url) const; @@ -633,7 +635,6 @@ void KFilePlacesView::setUrl(const QUrl &url) { - QUrl oldUrl = d->currentUrl; KFilePlacesModel *placesModel = qobject_cast(model()); if (placesModel == nullptr) { @@ -646,22 +647,12 @@ if (index.isValid()) { if (current != index && placesModel->isHidden(current) && !d->showAll) { KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); - delegate->addDisappearingItem(current); - - if (d->itemDisappearTimeline.state() != QTimeLine::Running) { - delegate->setDisappearingItemProgress(0.0); - d->itemDisappearTimeline.start(); - } + d->addDisappearingItem(delegate, current); } if (current != index && placesModel->isHidden(index) && !d->showAll) { KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); - delegate->addAppearingItem(index); - - if (d->itemAppearTimeline.state() != QTimeLine::Running) { - delegate->setAppearingItemProgress(0.0); - d->itemAppearTimeline.start(); - } + d->addDisappearingItem(delegate, current); setRowHidden(index.row(), false); } @@ -733,14 +724,18 @@ void KFilePlacesView::contextMenuEvent(QContextMenuEvent *event) { KFilePlacesModel *placesModel = qobject_cast(model()); - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); - if (placesModel == nullptr) { + if (!placesModel) { + return; + } + + KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); + if (!delegate) { return; } QModelIndex index = indexAt(event->pos()); - QString label = placesModel->text(index).replace('&', QLatin1String("&&")); + const QString label = placesModel->text(index).replace('&', QLatin1String("&&")); QMenu menu; @@ -826,7 +821,7 @@ QAction *result = menu.exec(event->globalPos()); - if (emptyTrash != nullptr && result == emptyTrash) { + if (emptyTrash && (result == emptyTrash)) { KIO::JobUiDelegate uiDelegate; uiDelegate.setWindow(window()); @@ -835,7 +830,7 @@ KJobWidgets::setWindow(job, window()); job->uiDelegate()->setAutoErrorHandlingEnabled(true); } - } else if (edit != nullptr && result == edit) { + } else if (edit && (result == edit)) { KBookmark bookmark = placesModel->bookmarkForIndex(index); QUrl url = bookmark.url(); QString label = bookmark.text(); @@ -859,31 +854,22 @@ placesModel->setPlaceGroupHidden(type, hideSection->isChecked()); if (!d->showAll && hideSection->isChecked()) { - delegate->addDisappearingItemGroup(index); - if (d->itemDisappearTimeline.state() != QTimeLine::Running) { - delegate->setDisappearingItemProgress(0.0); - d->itemDisappearTimeline.start(); - } + d->addDisappearingItem(delegate, index); } } else if (hide && (result == hide)) { placesModel->setPlaceHidden(index, hide->isChecked()); QModelIndex current = placesModel->closestItem(d->currentUrl); if (index != current && !d->showAll && hide->isChecked()) { - delegate->addDisappearingItem(index); - - if (d->itemDisappearTimeline.state() != QTimeLine::Running) { - delegate->setDisappearingItemProgress(0.0); - d->itemDisappearTimeline.start(); - } + d->addDisappearingItem(delegate, index); } - } else if (showAll != nullptr && result == showAll) { + } else if (showAll && (result == showAll)) { setShowAll(showAll->isChecked()); - } else if (teardown != nullptr && result == teardown) { + } else if (teardown && (result == teardown)) { placesModel->requestTeardown(index); - } else if (eject != nullptr && result == eject) { + } else if (eject && (result == eject)) { placesModel->requestEject(index); - } else if (add != nullptr && result == add) { + } else if (add && (result == add)) { QUrl url = d->currentUrl; QString label; QString iconName = QStringLiteral("folder"); @@ -926,7 +912,7 @@ QListView::dragEnterEvent(event); d->dragging = true; - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(false); d->dropRect = QRect(); @@ -937,7 +923,7 @@ QListView::dragLeaveEvent(event); d->dragging = false; - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(true); setDirtyRegion(d->dropRect); @@ -988,7 +974,7 @@ QListView::dropEvent(event); d->dragging = false; - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); delegate->setShowHoverIndication(true); } @@ -1071,8 +1057,8 @@ QListView::rowsInserted(parent, start, end); setUrl(d->currentUrl); - KFilePlacesViewDelegate *delegate = dynamic_cast(itemDelegate()); - KFilePlacesModel *placesModel = qobject_cast(model()); + KFilePlacesViewDelegate *delegate = static_cast(itemDelegate()); + KFilePlacesModel *placesModel = static_cast(model()); for (int i = start; i <= end; ++i) { QModelIndex index = placesModel->index(i, 0, parent); @@ -1112,6 +1098,15 @@ return QSize(iconSize + textWidth + fm.height() / 2, height); } +void KFilePlacesView::Private::addDisappearingItem(KFilePlacesViewDelegate *delegate, const QModelIndex &index) +{ + delegate->addDisappearingItem(index); + if (itemDisappearTimeline.state() != QTimeLine::Running) { + delegate->setDisappearingItemProgress(0.0); + itemDisappearTimeline.start(); + } +} + void KFilePlacesView::Private::setCurrentIndex(const QModelIndex &index) { KFilePlacesModel *placesModel = qobject_cast(q->model()); @@ -1467,14 +1462,14 @@ int size = oldSize + add; - KFilePlacesViewDelegate *delegate = dynamic_cast(q->itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setIconSize(size); q->scheduleDelayedItemsLayout(); } void KFilePlacesView::Private::_k_itemAppearUpdate(qreal value) { - KFilePlacesViewDelegate *delegate = dynamic_cast(q->itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setAppearingItemProgress(value); q->scheduleDelayedItemsLayout(); @@ -1482,7 +1477,7 @@ void KFilePlacesView::Private::_k_itemDisappearUpdate(qreal value) { - KFilePlacesViewDelegate *delegate = dynamic_cast(q->itemDelegate()); + KFilePlacesViewDelegate *delegate = static_cast(q->itemDelegate()); delegate->setDisappearingItemProgress(value);