From kde-commits Mon Jul 26 20:29:25 2010 From: =?utf-8?q?Aaron=20J=2E=20Seigo?= Date: Mon, 26 Jul 2010 20:29:25 +0000 To: kde-commits Subject: KDE/kdebase/apps/plasma/applets/folderview Message-Id: <20100726202925.E2917AC779 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=128017613310665 SVN commit 1155060 by aseigo: patch by Iamluc to show when a folder is empty; maintainer said he considers this a bugfix. certainly a ++elegance. M +30 -10 iconview.cpp M +1 -0 iconview.h --- trunk/KDE/kdebase/apps/plasma/applets/folderview/iconview.cpp #1155059:1155060 @@ -83,6 +83,7 @@ m_alignToGrid(false), m_wordWrap(false), m_popupShowPreview(true), + m_folderIsEmpty(false), m_flow(layoutDirection() == Qt::LeftToRight ? LeftToRight : RightToLeft), m_popupCausedWidget(0), m_dropOperation(0), @@ -91,9 +92,6 @@ { m_actionOverlay = new ActionOverlay(this); - // Added for later use - Q_UNUSED(I18N_NOOP("This folder is empty.")) - setAcceptHoverEvents(true); setAcceptDrops(true); setCacheMode(NoCache); @@ -483,8 +481,9 @@ Q_UNUSED(url) // Reset any error message that may have resulted from an earlier listing - if (!m_errorMessage.isEmpty()) { + if (!m_errorMessage.isEmpty() || m_folderIsEmpty) { m_errorMessage.clear(); + m_folderIsEmpty = false; update(); } @@ -505,7 +504,15 @@ if (m_validRows == m_model->rowCount()) { emit busy(false); } + + if (!m_model->rowCount() && !m_folderIsEmpty) { + m_folderIsEmpty = true; + update(); + } else if (m_model->rowCount() && m_folderIsEmpty) { + m_folderIsEmpty = false; + update(); } +} void IconView::listingCanceled() { @@ -534,7 +541,11 @@ const QString path = m_dirModel->dirLister()->url().toLocalFile(); listingError(KIO::buildErrorString(KIO::ERR_DOES_NOT_EXIST, path)); } + + if (!m_model->rowCount()) { + m_folderIsEmpty = true; } +} int IconView::columnsForWidth(qreal width) const { @@ -1227,8 +1238,13 @@ if (!m_errorMessage.isEmpty()) { paintMessage(painter, cr, m_errorMessage, KIcon("dialog-error")); + } else if (m_folderIsEmpty) { + Plasma::Containment *containment = qobject_cast(parentWidget()); + if (!containment || !containment->isContainment()) { + paintMessage(painter, cr, i18n( "This folder is empty." ), KIcon() ); } } +} bool IconView::indexIntersectsRect(const QModelIndex &index, const QRect &rect) const { @@ -1614,26 +1630,29 @@ void IconView::keyPressEvent(QKeyEvent *event) { - if (m_columns == 0) //The layout isn't done until items are actually inserted into the model, so until that happens, m_columns will be 0 + if (m_columns == 0) { + //The layout isn't done until items are actually inserted into the model, so until that happens, m_columns will be 0 return; + } int hdirection = 0; int vdirection = 0; QModelIndex currentIndex = m_selectionModel->currentIndex(); + if (!event->text().isEmpty()) { bool sameKeyWasPressed = m_searchQuery.endsWith(event->text()); m_searchQuery.append(event->text()); - m_searchQueryTimer.start(2000, this); //clears search query when the user doesn't press any key + m_searchQueryTimer.start(1500, this); //clears search query when the user doesn't press any key // First try to match the exact icon string - QModelIndexList matches = m_model->match(currentIndex, Qt::DisplayRole, m_searchQuery, - 1, Qt::MatchFixedString | Qt::MatchWrap); + QModelIndexList matches = m_model->match(currentIndex, Qt::DisplayRole, m_searchQuery, 1, + Qt::MatchFixedString | Qt::MatchWrap); if (matches.count()<=0) { // Exact match failed, try matching the beginning of the icon string - matches = m_model->match(currentIndex, Qt::DisplayRole, m_searchQuery, - 1, Qt::MatchStartsWith | Qt::MatchWrap); + matches = m_model->match(currentIndex, Qt::DisplayRole, m_searchQuery, 1, + Qt::MatchStartsWith | Qt::MatchWrap); if (matches.count()<=0 && sameKeyWasPressed) { // Didn't even match beginning, try next icon string starting with the same letter @@ -1645,6 +1664,7 @@ if (matches.count()>0) { selectIcon(matches.at(0)); } + } switch (event->key()) { case Qt::Key_Home: --- trunk/KDE/kdebase/apps/plasma/applets/folderview/iconview.h #1155059:1155060 @@ -236,6 +236,7 @@ bool m_alignToGrid; bool m_wordWrap; bool m_popupShowPreview; + bool m_folderIsEmpty; QPersistentModelIndex m_hoveredIndex; QPersistentModelIndex m_pressedIndex; QPersistentModelIndex m_editorIndex;