┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp35
-rw-r--r--src/kitemviews/kfileitemmodel.h6
-rw-r--r--src/kitemviews/kitemlistcontainer.cpp5
-rw-r--r--src/kitemviews/kitemlistview.cpp11
-rw-r--r--src/kitemviews/kitemlistview.h6
-rw-r--r--src/kitemviews/kstandarditemlistwidget.cpp1
-rw-r--r--src/kitemviews/private/kfileitemmodeldirlister.cpp5
-rw-r--r--src/kitemviews/private/kitemlistroleeditor.cpp26
-rw-r--r--src/kitemviews/private/kitemlistroleeditor.h20
-rw-r--r--src/kitemviews/private/kitemlistsmoothscroller.cpp3
-rw-r--r--src/kitemviews/private/kitemlistsmoothscroller.h5
11 files changed, 108 insertions, 15 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index da15ccbdd..a6c5e48ec 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -1015,6 +1015,8 @@ void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemLis
// emitted during the maximum update interval.
m_maximumUpdateIntervalTimer->start();
}
+
+ Q_EMIT fileItemsChanged({KFileItem(directoryUrl)});
}
void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
@@ -1023,6 +1025,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
QVector<int> indexesToRemove;
indexesToRemove.reserve(items.count());
+ KFileItemList dirsChanged;
for (const KFileItem& item : items) {
const int indexForItem = index(item);
@@ -1036,6 +1039,11 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
m_filteredItems.erase(it);
}
}
+
+ QUrl parentUrl = item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash);
+ if (dirsChanged.findByUrl(parentUrl).isNull()) {
+ dirsChanged << KFileItem(parentUrl);
+ }
}
std::sort(indexesToRemove.begin(), indexesToRemove.end());
@@ -1063,6 +1071,8 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items)
const KItemRangeList itemRanges = KItemRangeList::fromSortedContainer(indexesToRemove);
removeFilteredChildren(itemRanges);
removeItems(itemRanges, DeleteItemData);
+
+ Q_EMIT fileItemsChanged(dirsChanged);
}
void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& items)
@@ -1077,6 +1087,7 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
indexes.reserve(items.count());
QSet<QByteArray> changedRoles;
+ KFileItemList changedFiles;
QListIterator<QPair<KFileItem, KFileItem> > it(items);
while (it.hasNext()) {
@@ -1102,6 +1113,7 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
m_items.remove(oldItem.url());
m_items.insert(newItem.url(), indexForItem);
+ changedFiles.append(newItem);
indexes.append(indexForItem);
} else {
// Check if 'oldItem' is one of the filtered items.
@@ -1130,6 +1142,8 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >&
std::sort(indexes.begin(), indexes.end());
const KItemRangeList itemRangeList = KItemRangeList::fromSortedContainer(indexes);
emitItemsChangedAndTriggerResorting(itemRangeList, changedRoles);
+
+ Q_EMIT fileItemsChanged(changedFiles);
}
void KFileItemModel::slotClear()
@@ -1719,6 +1733,15 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla
}
}
+ // Show hidden files and folders last
+ const bool isHiddenA = a->item.isHidden();
+ const bool isHiddenB = b->item.isHidden();
+ if (isHiddenA && !isHiddenB) {
+ return false;
+ } else if (!isHiddenA && isHiddenB) {
+ return true;
+ }
+
if (m_sortDirsFirst || (DetailsModeSettings::directorySizeCount() && m_sortRole == SizeRole)) {
const bool isDirA = a->item.isDir();
const bool isDirB = b->item.isDir();
@@ -2090,7 +2113,7 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<
if (daysDistance == 1) {
const KLocalizedString format = ki18nc("@title:group Date: "
"MMMM is full month name in current locale, and yyyy is "
- "full year number", "'Yesterday' (MMMM, yyyy)");
+ "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'Yesterday' (MMMM, yyyy)");
const QString translatedFormat = format.toString();
if (translatedFormat.count(QLatin1Char('\'')) == 2) {
newGroupValue = fileTime.toString(translatedFormat);
@@ -2105,7 +2128,7 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<
} else if (daysDistance <= 7) {
newGroupValue = fileTime.toString(i18nc("@title:group Date: "
"The week day name: dddd, MMMM is full month name "
- "in current locale, and yyyy is full year number",
+ "in current locale, and yyyy is full year number.",
"dddd (MMMM, yyyy)"));
newGroupValue = i18nc("Can be used to script translation of "
"\"dddd (MMMM, yyyy)\" with context @title:group Date",
@@ -2113,7 +2136,7 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<
} else if (daysDistance <= 7 * 2) {
const KLocalizedString format = ki18nc("@title:group Date: "
"MMMM is full month name in current locale, and yyyy is "
- "full year number", "'One Week Ago' (MMMM, yyyy)");
+ "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'One Week Ago' (MMMM, yyyy)");
const QString translatedFormat = format.toString();
if (translatedFormat.count(QLatin1Char('\'')) == 2) {
newGroupValue = fileTime.toString(translatedFormat);
@@ -2128,7 +2151,7 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<
} else if (daysDistance <= 7 * 3) {
const KLocalizedString format = ki18nc("@title:group Date: "
"MMMM is full month name in current locale, and yyyy is "
- "full year number", "'Two Weeks Ago' (MMMM, yyyy)");
+ "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'Two Weeks Ago' (MMMM, yyyy)");
const QString translatedFormat = format.toString();
if (translatedFormat.count(QLatin1Char('\'')) == 2) {
newGroupValue = fileTime.toString(translatedFormat);
@@ -2143,7 +2166,7 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<
} else if (daysDistance <= 7 * 4) {
const KLocalizedString format = ki18nc("@title:group Date: "
"MMMM is full month name in current locale, and yyyy is "
- "full year number", "'Three Weeks Ago' (MMMM, yyyy)");
+ "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'Three Weeks Ago' (MMMM, yyyy)");
const QString translatedFormat = format.toString();
if (translatedFormat.count(QLatin1Char('\'')) == 2) {
newGroupValue = fileTime.toString(translatedFormat);
@@ -2158,7 +2181,7 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<
} else {
const KLocalizedString format = ki18nc("@title:group Date: "
"MMMM is full month name in current locale, and yyyy is "
- "full year number", "'Earlier on' MMMM, yyyy");
+ "full year number. You must keep the ' don't use any fancy \" or « or similar. The ' is not shown to the user, it's there to mark a part of the text that should not be formatted as a date", "'Earlier on' MMMM, yyyy");
const QString translatedFormat = format.toString();
if (translatedFormat.count(QLatin1Char('\'')) == 2) {
newGroupValue = fileTime.toString(translatedFormat);
diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h
index 886a1c6de..acf4b761c 100644
--- a/src/kitemviews/kfileitemmodel.h
+++ b/src/kitemviews/kfileitemmodel.h
@@ -245,6 +245,12 @@ Q_SIGNALS:
*/
void urlIsFileError(const QUrl& url);
+ /**
+ * It is emitted for files when they change and
+ * for dirs when files are added or removed.
+ */
+ void fileItemsChanged(const KFileItemList &changedFileItems);
+
protected:
void onGroupedSortingChanged(bool current) override;
void onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems = true) override;
diff --git a/src/kitemviews/kitemlistcontainer.cpp b/src/kitemviews/kitemlistcontainer.cpp
index f253cda53..10b9f1415 100644
--- a/src/kitemviews/kitemlistcontainer.cpp
+++ b/src/kitemviews/kitemlistcontainer.cpp
@@ -208,6 +208,8 @@ void KItemListContainer::slotViewChanged(KItemListView* current, KItemListView*
disconnect(previous, &KItemListView::maximumItemOffsetChanged,
this, &KItemListContainer::updateItemOffsetScrollBar);
disconnect(previous, &KItemListView::scrollTo, this, &KItemListContainer::scrollTo);
+ disconnect(m_horizontalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, previous, &KItemListView::scrollingStopped);
+ disconnect(m_verticalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, previous, &KItemListView::scrollingStopped);
m_horizontalSmoothScroller->setTargetObject(nullptr);
m_verticalSmoothScroller->setTargetObject(nullptr);
}
@@ -224,6 +226,9 @@ void KItemListContainer::slotViewChanged(KItemListView* current, KItemListView*
connect(current, &KItemListView::maximumItemOffsetChanged,
this, &KItemListContainer::updateItemOffsetScrollBar);
connect(current, &KItemListView::scrollTo, this, &KItemListContainer::scrollTo);
+ connect(m_horizontalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, current, &KItemListView::scrollingStopped);
+ connect(m_verticalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, current, &KItemListView::scrollingStopped);
+
m_horizontalSmoothScroller->setTargetObject(current);
m_verticalSmoothScroller->setTargetObject(current);
updateSmoothScrollers(current->scrollOrientation());
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp
index 56cede2fd..5c8c712e8 100644
--- a/src/kitemviews/kitemlistview.cpp
+++ b/src/kitemviews/kitemlistview.cpp
@@ -526,8 +526,11 @@ void KItemListView::scrollToItem(int index)
if (newOffset != scrollOffset()) {
Q_EMIT scrollTo(newOffset);
+ return;
}
}
+
+ Q_EMIT scrollingStopped();
}
void KItemListView::beginTransaction()
@@ -1602,16 +1605,16 @@ void KItemListView::slotRoleEditingCanceled(int index, const QByteArray& role, c
{
disconnectRoleEditingSignals(index);
- Q_EMIT roleEditingCanceled(index, role, value);
m_editingRole = false;
+ Q_EMIT roleEditingCanceled(index, role, value);
}
void KItemListView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
{
disconnectRoleEditingSignals(index);
- Q_EMIT roleEditingFinished(index, role, value);
m_editingRole = false;
+ Q_EMIT roleEditingFinished(index, role, value);
}
void KItemListView::setController(KItemListController* controller)
@@ -1750,13 +1753,11 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha
const bool animate = (hint == Animation);
for (int i = firstVisibleIndex; i <= lastVisibleIndex; ++i) {
bool applyNewPos = true;
- bool wasHidden = false;
const QRectF itemBounds = m_layouter->itemRect(i);
const QPointF newPos = itemBounds.topLeft();
KItemListWidget* widget = m_visibleItems.value(i);
if (!widget) {
- wasHidden = true;
if (!reusableItems.isEmpty()) {
// Reuse a KItemListWidget instance from an invisible item
const int oldIndex = reusableItems.takeLast();
@@ -2551,7 +2552,7 @@ void KItemListView::updateGroupHeaderHeight()
groupHeaderHeight += 2 * m_styleOption.horizontalMargin;
groupHeaderMargin = m_styleOption.horizontalMargin;
} else if (m_itemSize.isEmpty()){
- groupHeaderHeight += 2 * m_styleOption.padding;
+ groupHeaderHeight += 4 * m_styleOption.padding;
groupHeaderMargin = m_styleOption.iconSize / 2;
} else {
groupHeaderHeight += 2 * m_styleOption.padding + m_styleOption.verticalMargin;
diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h
index a84794335..5453d851f 100644
--- a/src/kitemviews/kitemlistview.h
+++ b/src/kitemviews/kitemlistview.h
@@ -307,6 +307,12 @@ Q_SIGNALS:
void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
void roleEditingFinished(int index, const QByteArray& role, const QVariant& value);
+ /**
+ * Emitted once scrolling has finished, or immediately if no scrolling was necessary
+ * to get item in view in scrollToItem.
+ */
+ void scrollingStopped();
+
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
void setItemSize(const QSizeF& size);
diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp
index 73744b385..e58340fb8 100644
--- a/src/kitemviews/kstandarditemlistwidget.cpp
+++ b/src/kitemviews/kstandarditemlistwidget.cpp
@@ -764,6 +764,7 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const
m_roleEditor = new KItemListRoleEditor(parent);
m_roleEditor->setRole(current);
+ m_roleEditor->setAllowUpDownKeyChainEdit(m_layout != IconsLayout);
m_roleEditor->setFont(styleOption().font);
const QString text = data().value(current).toString();
diff --git a/src/kitemviews/private/kfileitemmodeldirlister.cpp b/src/kitemviews/private/kfileitemmodeldirlister.cpp
index 90c970874..eb860a2b9 100644
--- a/src/kitemviews/private/kfileitemmodeldirlister.cpp
+++ b/src/kitemviews/private/kfileitemmodeldirlister.cpp
@@ -8,11 +8,16 @@
#include <KLocalizedString>
#include <KIO/Job>
+#include <kio_version.h>
KFileItemModelDirLister::KFileItemModelDirLister(QObject* parent) :
KDirLister(parent)
{
+#if KIO_VERSION < QT_VERSION_CHECK(5, 82, 0)
setAutoErrorHandlingEnabled(false, nullptr);
+#else
+ setAutoErrorHandlingEnabled(false);
+#endif
}
KFileItemModelDirLister::~KFileItemModelDirLister()
diff --git a/src/kitemviews/private/kitemlistroleeditor.cpp b/src/kitemviews/private/kitemlistroleeditor.cpp
index df142a456..cc10bd58a 100644
--- a/src/kitemviews/private/kitemlistroleeditor.cpp
+++ b/src/kitemviews/private/kitemlistroleeditor.cpp
@@ -40,6 +40,11 @@ QByteArray KItemListRoleEditor::role() const
return m_role;
}
+void KItemListRoleEditor::setAllowUpDownKeyChainEdit(bool allowChainEdit)
+{
+ m_allowUpDownKeyChainEdit = allowChainEdit;
+}
+
bool KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event)
{
if (watched == parentWidget() && event->type() == QEvent::Resize) {
@@ -78,6 +83,20 @@ void KItemListRoleEditor::keyPressEvent(QKeyEvent* event)
emitRoleEditingFinished();
event->accept();
return;
+ case Qt::Key_Tab:
+ case Qt::Key_Down:
+ if (m_allowUpDownKeyChainEdit || event->key() == Qt::Key_Tab) {
+ emitRoleEditingFinished(EditNext);
+ event->accept();
+ return;
+ }
+ case Qt::Key_Backtab:
+ case Qt::Key_Up:
+ if (m_allowUpDownKeyChainEdit || event->key() == Qt::Key_Backtab) {
+ emitRoleEditingFinished(EditPrevious);
+ event->accept();
+ return;
+ }
case Qt::Key_Left:
case Qt::Key_Right: {
QTextCursor cursor = textCursor();
@@ -143,10 +162,13 @@ void KItemListRoleEditor::autoAdjustSize()
}
}
-void KItemListRoleEditor::emitRoleEditingFinished()
+void KItemListRoleEditor::emitRoleEditingFinished(EditResultDirection direction)
{
+ QVariant ret;
+ ret.setValue(EditResult {KIO::encodeFileName(toPlainText()), direction});
+
if (!m_blockFinishedSignal) {
- Q_EMIT roleEditingFinished(m_role, KIO::encodeFileName(toPlainText()));
+ Q_EMIT roleEditingFinished(m_role, ret);
}
}
diff --git a/src/kitemviews/private/kitemlistroleeditor.h b/src/kitemviews/private/kitemlistroleeditor.h
index 070cf5ce9..a0f55df51 100644
--- a/src/kitemviews/private/kitemlistroleeditor.h
+++ b/src/kitemviews/private/kitemlistroleeditor.h
@@ -11,12 +11,26 @@
#include <KTextEdit>
+enum EditResultDirection{
+ EditDone,
+ EditNext,
+ EditPrevious,
+};
+Q_DECLARE_METATYPE(EditResultDirection)
+
+struct EditResult
+{
+ QString newName;
+ EditResultDirection direction;
+};
+Q_DECLARE_METATYPE(EditResult)
+
/**
* @brief Editor for renaming roles of a KItemListWidget.
*
* Provides signals when the editing got cancelled (e.g. by
* pressing Escape or when losing the focus) or when the editing
- * got finished (e.g. by pressing Enter or Return).
+ * got finished (e.g. by pressing Enter, Tab or Return).
*
* The size automatically gets increased if the text does not fit.
*/
@@ -31,6 +45,7 @@ public:
void setRole(const QByteArray& role);
QByteArray role() const;
+ void setAllowUpDownKeyChainEdit(bool allowChainEdit);
bool eventFilter(QObject* watched, QEvent* event) override;
Q_SIGNALS:
@@ -53,11 +68,12 @@ private:
* Emits the signal roleEditingFinished if m_blockFinishedSignal
* is false.
*/
- void emitRoleEditingFinished();
+ void emitRoleEditingFinished(EditResultDirection direction = EditDone);
private:
QByteArray m_role;
bool m_blockFinishedSignal;
+ bool m_allowUpDownKeyChainEdit;
};
#endif
diff --git a/src/kitemviews/private/kitemlistsmoothscroller.cpp b/src/kitemviews/private/kitemlistsmoothscroller.cpp
index 1465361ed..f77d3df58 100644
--- a/src/kitemviews/private/kitemlistsmoothscroller.cpp
+++ b/src/kitemviews/private/kitemlistsmoothscroller.cpp
@@ -175,6 +175,9 @@ void KItemListSmoothScroller::slotAnimationStateChanged(QAbstractAnimation::Stat
if (newState == QAbstractAnimation::Stopped && m_smoothScrolling && !m_scrollBarPressed) {
m_smoothScrolling = false;
}
+ if (newState == QAbstractAnimation::Stopped) {
+ Q_EMIT scrollingStopped();
+ }
}
void KItemListSmoothScroller::handleWheelEvent(QWheelEvent* event)
diff --git a/src/kitemviews/private/kitemlistsmoothscroller.h b/src/kitemviews/private/kitemlistsmoothscroller.h
index 55548219e..7b2839884 100644
--- a/src/kitemviews/private/kitemlistsmoothscroller.h
+++ b/src/kitemviews/private/kitemlistsmoothscroller.h
@@ -69,6 +69,11 @@ public:
*/
void handleWheelEvent(QWheelEvent* event);
+Q_SIGNALS:
+ /**
+ * Emitted when the scrolling animation has finished
+ */
+ void scrollingStopped();
protected:
bool eventFilter(QObject* obj, QEvent* event) override;