diff options
| author | Peter Penz <[email protected]> | 2011-11-20 19:32:52 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-11-20 19:35:01 +0100 |
| commit | b27e599429731337af4bb18b986933c968bea279 (patch) | |
| tree | e807863400a9c3f6f48194a0f69f4c3d450ca092 /src/kitemviews | |
| parent | 693f254252da3932d1307f65bc2a1bcaaad566ac (diff) | |
Initial draft for bringing back the "Folders" panel
The folders panel has been adjusted to use the new view-engine.
A lot of things don't work yet, but are mostly minor issues that
should be fixable during the next 10 days.
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kfileitemlistview.cpp | 34 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 59 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodel.h | 11 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistcontainer.cpp | 9 | ||||
| -rw-r--r-- | src/kitemviews/kitemliststyleoption.cpp | 4 | ||||
| -rw-r--r-- | src/kitemviews/kitemlistview.cpp | 12 |
6 files changed, 107 insertions, 22 deletions
diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp index a7fa27f0d..b0ffd3c20 100644 --- a/src/kitemviews/kfileitemlistview.cpp +++ b/src/kitemviews/kfileitemlistview.cpp @@ -65,6 +65,8 @@ KFileItemListView::KFileItemListView(QGraphicsWidget* parent) : m_updateIconSizeTimer->setInterval(ShortInterval); connect(m_updateIconSizeTimer, SIGNAL(timeout()), this, SLOT(updateIconSize())); + setVisibleRoles(QList<QByteArray>() << "name"); + updateMinimumRolesWidths(); } @@ -302,7 +304,8 @@ void KFileItemListView::initializeItemListWidget(KItemListWidget* item) default: Q_ASSERT(false); break; } - fileItemListWidget->setAlternatingBackgroundColors(m_itemLayout == DetailsLayout); + fileItemListWidget->setAlternatingBackgroundColors(m_itemLayout == DetailsLayout && + visibleRoles().count() > 1); } bool KFileItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const @@ -332,6 +335,8 @@ void KFileItemListView::onModelChanged(KItemModelBase* current, KItemModelBase* m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast<KFileItemModel*>(current), this); const int size = styleOption().iconSize; m_modelRolesUpdater->setIconSize(QSize(size, size)); + + applyRolesToModel(); } void KFileItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) @@ -360,6 +365,19 @@ void KFileItemListView::onVisibleRolesChanged(const QList<QByteArray>& current, Q_UNUSED(current); Q_UNUSED(previous); applyRolesToModel(); + + if (m_itemLayout == DetailsLayout) { + // Only enable the alternating background colors if more than one role + // is visible + const int previousCount = previous.count(); + const int currentCount = current.count(); + if ((previousCount <= 1 && currentCount > 1) || (previousCount > 1 && currentCount <= 1)) { + const bool enabled = (currentCount > 1); + foreach (KItemListWidget* widget, visibleItemListWidgets()) { + widget->setAlternatingBackgroundColors(enabled); + } + } + } } void KFileItemListView::onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) @@ -410,6 +428,9 @@ void KFileItemListView::slotSortRoleChanged(const QByteArray& current, const QBy void KFileItemListView::triggerVisibleIndexRangeUpdate() { + if (!model()) { + return; + } m_modelRolesUpdater->setPaused(true); m_updateVisibleIndexRangeTimer->start(); } @@ -439,6 +460,9 @@ void KFileItemListView::updateVisibleIndexRange() void KFileItemListView::triggerIconSizeUpdate() { + if (!model()) { + return; + } m_modelRolesUpdater->setPaused(true); m_updateIconSizeTimer->start(); } @@ -494,6 +518,10 @@ QSizeF KFileItemListView::visibleRoleSizeHint(int index, const QByteArray& role) void KFileItemListView::updateLayoutOfVisibleItems() { + if (!model()) { + return; + } + foreach (KItemListWidget* widget, visibleItemListWidgets()) { initializeItemListWidget(widget); } @@ -528,6 +556,10 @@ void KFileItemListView::updateMinimumRolesWidths() void KFileItemListView::applyRolesToModel() { + if (!model()) { + return; + } + Q_ASSERT(qobject_cast<KFileItemModel*>(model())); KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(model()); diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index d46bfc8da..363503b02 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -49,7 +49,7 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) : m_groups(), m_rootExpansionLevel(-1), m_expandedUrls(), - m_restoredExpandedUrls() + m_urlsToExpand() { // Apply default roles that should be determined resetRoles(); @@ -431,9 +431,43 @@ QSet<KUrl> KFileItemModel::expandedUrls() const return m_expandedUrls; } -void KFileItemModel::restoreExpandedUrls(const QSet<KUrl>& urls) +void KFileItemModel::setExpanded(const QSet<KUrl>& urls) { - m_restoredExpandedUrls = urls; + + const KDirLister* dirLister = m_dirLister.data(); + if (!dirLister) { + return; + } + + const int pos = dirLister->url().url().length(); + + // Assure that each sub-path of the URLs that should be + // expanded is added to m_urlsToExpand too. KDirLister + // does not care whether the parent-URL has already been + // expanded. + QSetIterator<KUrl> it1(urls); + while (it1.hasNext()) { + const KUrl& url = it1.next(); + + KUrl urlToExpand = dirLister->url(); + const QStringList subDirs = url.url().mid(pos).split(QDir::separator()); + for (int i = 0; i < subDirs.count(); ++i) { + urlToExpand.addPath(subDirs.at(i)); + m_urlsToExpand.insert(urlToExpand); + } + } + + // KDirLister::open() must called at least once to trigger an initial + // loading. The pending URLs that must be restored are handled + // in slotCompleted(). + QSetIterator<KUrl> it2(m_urlsToExpand); + while (it2.hasNext()) { + const int idx = index(it2.next()); + if (idx >= 0 && !isExpanded(idx)) { + setExpanded(idx, true); + break; + } + } } void KFileItemModel::onGroupedSortingChanged(bool current) @@ -520,7 +554,7 @@ void KFileItemModel::resortAllItems() void KFileItemModel::slotCompleted() { - if (m_restoredExpandedUrls.isEmpty() && m_minimumUpdateIntervalTimer->isActive()) { + if (m_urlsToExpand.isEmpty() && m_minimumUpdateIntervalTimer->isActive()) { // dispatchPendingItems() will be called when the timer // has been expired. m_pendingEmitLoadingCompleted = true; @@ -530,25 +564,26 @@ void KFileItemModel::slotCompleted() m_pendingEmitLoadingCompleted = false; dispatchPendingItemsToInsert(); - if (!m_restoredExpandedUrls.isEmpty()) { + if (!m_urlsToExpand.isEmpty()) { // Try to find a URL that can be expanded. // Note that the parent folder must be expanded before any of its subfolders become visible. // Therefore, some URLs in m_restoredExpandedUrls might not be visible yet // -> we expand the first visible URL we find in m_restoredExpandedUrls. - foreach(const KUrl& url, m_restoredExpandedUrls) { + foreach(const KUrl& url, m_urlsToExpand) { const int index = m_items.value(url, -1); if (index >= 0) { - // We have found an expandable URL. Expand it and return - when - // the dir lister has finished, this slot will be called again. - m_restoredExpandedUrls.remove(url); - setExpanded(index, true); - return; + m_urlsToExpand.remove(url); + if (setExpanded(index, true)) { + // The dir lister has been triggered. This slot will be called + // again after the directory has been expanded. + return; + } } } // None of the URLs in m_restoredExpandedUrls could be found in the model. This can happen // if these URLs have been deleted in the meantime. - m_restoredExpandedUrls.clear(); + m_urlsToExpand.clear(); } emit loadingCompleted(); diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index b28887b2c..a049f6766 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -120,7 +120,11 @@ public: bool isExpanded(int index) const; bool isExpandable(int index) const; QSet<KUrl> expandedUrls() const; - void restoreExpandedUrls(const QSet<KUrl>& urls); + + /** + * Expands all parent-items of each URL given by \a urls. + */ + void setExpanded(const QSet<KUrl>& urls); signals: void loadingCompleted(); @@ -291,8 +295,9 @@ private: // Stores the URLs of the expanded folders. QSet<KUrl> m_expandedUrls; - // Stores the URLs which have to be expanded in order to restore a previous state of the model. - QSet<KUrl> m_restoredExpandedUrls; + // URLs that must be expanded. The expanding is initially triggered in setExpanded() + // and done step after step in slotCompleted(). + QSet<KUrl> m_urlsToExpand; friend class KFileItemModelTest; // For unit testing }; diff --git a/src/kitemviews/kitemlistcontainer.cpp b/src/kitemviews/kitemlistcontainer.cpp index d006e2c4d..8ca983acd 100644 --- a/src/kitemviews/kitemlistcontainer.cpp +++ b/src/kitemviews/kitemlistcontainer.cpp @@ -314,7 +314,14 @@ void KItemListContainer::updateSmoothScrollers(Qt::Orientation orientation) void KItemListContainer::initialize() { - if (!m_controller) { + if (m_controller) { + if (m_controller->model()) { + slotModelChanged(m_controller->model(), 0); + } + if (m_controller->view()) { + slotViewChanged(m_controller->view(), 0); + } + } else { m_controller = new KItemListController(this); } diff --git a/src/kitemviews/kitemliststyleoption.cpp b/src/kitemviews/kitemliststyleoption.cpp index f26b220bc..83af31202 100644 --- a/src/kitemviews/kitemliststyleoption.cpp +++ b/src/kitemviews/kitemliststyleoption.cpp @@ -19,13 +19,15 @@ #include "kitemliststyleoption.h" +#include <KIconLoader> + KItemListStyleOption::KItemListStyleOption() : rect(), font(), fontMetrics(QFont()), palette(), margin(0), - iconSize(0) + iconSize(KIconLoader::SizeMedium) { } diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 4ded4a93e..389069ce3 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -1196,7 +1196,7 @@ void KItemListView::setModel(KItemModelBase* model) } m_model = model; - m_layouter->setModel(model); + m_layouter->setModel(model); m_grouped = model->groupedSorting(); if (m_model) { @@ -1231,7 +1231,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha m_layoutTimer->stop(); } - if (m_model->count() < 0 || m_activeTransactions > 0) { + if (!m_model || m_model->count() < 0 || m_activeTransactions > 0) { return; } @@ -1675,6 +1675,10 @@ void KItemListView::updateVisibleRolesSizes(const KItemRangeList& itemRanges) void KItemListView::updateVisibleRolesSizes() { + if (!m_model) { + return; + } + const int itemCount = m_model->count(); if (itemCount > 0) { updateVisibleRolesSizes(KItemRangeList() << KItemRange(0, itemCount)); @@ -1683,7 +1687,7 @@ void KItemListView::updateVisibleRolesSizes() void KItemListView::updateStretchedVisibleRolesSizes() { - if (!m_itemSize.isEmpty() || m_useHeaderWidths) { + if (!m_itemSize.isEmpty() || m_useHeaderWidths || m_visibleRoles.isEmpty()) { return; } @@ -1692,7 +1696,7 @@ void KItemListView::updateStretchedVisibleRolesSizes() // size does not use the available view-size it the size of the // first role will get stretched. m_stretchedVisibleRolesSizes = m_visibleRolesSizes; - const QByteArray role = visibleRoles().first(); + const QByteArray role = m_visibleRoles.first(); QSizeF firstRoleSize = m_stretchedVisibleRolesSizes.value(role); QSizeF dynamicItemSize = m_itemSize; |
