diff options
Diffstat (limited to 'src/kitemviews')
70 files changed, 2485 insertions, 2840 deletions
diff --git a/src/kitemviews/kfileitemlisttostring.cpp b/src/kitemviews/kfileitemlisttostring.cpp index 0004c7e7f..d10680adc 100644 --- a/src/kitemviews/kfileitemlisttostring.cpp +++ b/src/kitemviews/kfileitemlisttostring.cpp @@ -19,27 +19,35 @@ QString fileItemListToString(KFileItemList items, int maximumTextWidth, const QF QString text; switch (items.count()) { case 1: - text = i18nc("Textual representation of a file. %1 is the name of the file/folder.", - "\"%1\"", items.first().name()); + text = i18nc("Textual representation of a file. %1 is the name of the file/folder.", "\"%1\"", items.first().name()); break; case 2: - text = i18nc("Textual representation of two files. %1 and %2 are names of files/folders.", - "\"%1\" and \"%2\"", items.first().name(), items.last().name()); + text = + i18nc("Textual representation of two files. %1 and %2 are names of files/folders.", "\"%1\" and \"%2\"", items.first().name(), items.last().name()); break; case 3: text = i18nc("Textual representation of three files. %1, %2 and %3 are names of files/folders.", - "\"%1\", \"%2\" and \"%3\"", - items.first().name(), items.at(1).name(), items.last().name()); + "\"%1\", \"%2\" and \"%3\"", + items.first().name(), + items.at(1).name(), + items.last().name()); break; case 4: text = i18nc("Textual representation of four files. %1, %2, %3 and %4 are names of files/folders.", - "\"%1\", \"%2\", \"%3\" and \"%4\"", - items.first().name(), items.at(1).name(), items.at(2).name(), items.last().name()); + "\"%1\", \"%2\", \"%3\" and \"%4\"", + items.first().name(), + items.at(1).name(), + items.at(2).name(), + items.last().name()); break; case 5: text = i18nc("Textual representation of five files. %1, %2, %3, %4 and %5 are names of files/folders.", - "\"%1\", \"%2\", \"%3\", \"%4\" and \"%5\"", - items.first().name(), items.at(1).name(), items.at(2).name(), items.at(3).name(), items.last().name()); + "\"%1\", \"%2\", \"%3\", \"%4\" and \"%5\"", + items.first().name(), + items.at(1).name(), + items.at(2).name(), + items.at(3).name(), + items.last().name()); break; default: text = QString(); @@ -54,14 +62,15 @@ QString fileItemListToString(KFileItemList items, int maximumTextWidth, const QF const KFileItemListProperties properties(items); if (itemsState == Selected) { if (properties.isFile()) { - text = i18ncp("Textual representation of selected files. %1 is the number of files.", - "One Selected File", "%1 Selected Files", items.count()); + text = i18ncp("Textual representation of selected files. %1 is the number of files.", "One Selected File", "%1 Selected Files", items.count()); } else if (properties.isDirectory()) { - text = i18ncp("Textual representation of selected folders. %1 is the number of folders.", - "One Selected Folder", "%1 Selected Folders", items.count()); + text = + i18ncp("Textual representation of selected folders. %1 is the number of folders.", "One Selected Folder", "%1 Selected Folders", items.count()); } else { text = i18ncp("Textual representation of selected fileitems. %1 is the number of files/folders.", - "One Selected Item", "%1 Selected Items", items.count()); + "One Selected Item", + "%1 Selected Items", + items.count()); } if (fontMetrics.horizontalAdvance(text) <= maximumTextWidth) { @@ -70,13 +79,10 @@ QString fileItemListToString(KFileItemList items, int maximumTextWidth, const QF } if (properties.isFile()) { - return i18ncp("Textual representation of files. %1 is the number of files.", - "One File", "%1 Files", items.count()); + return i18ncp("Textual representation of files. %1 is the number of files.", "One File", "%1 Files", items.count()); } else if (properties.isDirectory()) { - return i18ncp("Textual representation of folders. %1 is the number of folders.", - "One Folder", "%1 Folders", items.count()); + return i18ncp("Textual representation of folders. %1 is the number of folders.", "One Folder", "%1 Folders", items.count()); } else { - return i18ncp("Textual representation of fileitems. %1 is the number of files/folders.", - "One Item", "%1 Items", items.count()); + return i18ncp("Textual representation of fileitems. %1 is the number of files/folders.", "One Item", "%1 Items", items.count()); } } diff --git a/src/kitemviews/kfileitemlisttostring.h b/src/kitemviews/kfileitemlisttostring.h index ad8c82b21..f1c2902b8 100644 --- a/src/kitemviews/kfileitemlisttostring.h +++ b/src/kitemviews/kfileitemlisttostring.h @@ -12,10 +12,7 @@ class KFileItemList; class QFontMetrics; class QString; -enum ItemsState { - None, - Selected -}; +enum ItemsState { None, Selected }; /** * @brief Generates a textual representation of the given list of KFileItems. diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp index 26bc01465..e2a27a5ea 100644 --- a/src/kitemviews/kfileitemlistview.cpp +++ b/src/kitemviews/kfileitemlistview.cpp @@ -15,32 +15,33 @@ #include <QGraphicsScene> #include <QGraphicsView> -#include <QPainter> -#include <QTimer> #include <QIcon> #include <QMimeDatabase> +#include <QPainter> +#include <QTimer> // #define KFILEITEMLISTVIEW_DEBUG -namespace { - // If the visible index range changes, KFileItemModelRolesUpdater is not - // informed immediately, but with a short delay. This ensures that scrolling - // always feels smooth and is not interrupted by icon loading (which can be - // quite expensive if a disk access is required to determine the final icon). - const int ShortInterval = 50; +namespace +{ +// If the visible index range changes, KFileItemModelRolesUpdater is not +// informed immediately, but with a short delay. This ensures that scrolling +// always feels smooth and is not interrupted by icon loading (which can be +// quite expensive if a disk access is required to determine the final icon). +const int ShortInterval = 50; - // If the icon size changes, a longer delay is used. This prevents that - // the expensive re-generation of all previews is triggered repeatedly when - // changing the zoom level. - const int LongInterval = 300; +// If the icon size changes, a longer delay is used. This prevents that +// the expensive re-generation of all previews is triggered repeatedly when +// changing the zoom level. +const int LongInterval = 300; } -KFileItemListView::KFileItemListView(QGraphicsWidget* parent) : - KStandardItemListView(parent), - m_modelRolesUpdater(nullptr), - m_updateVisibleIndexRangeTimer(nullptr), - m_updateIconSizeTimer(nullptr), - m_scanDirectories(true) +KFileItemListView::KFileItemListView(QGraphicsWidget *parent) + : KStandardItemListView(parent) + , m_modelRolesUpdater(nullptr) + , m_updateVisibleIndexRangeTimer(nullptr) + , m_updateIconSizeTimer(nullptr) + , m_scanDirectories(true) { setAcceptDrops(true); @@ -94,7 +95,7 @@ bool KFileItemListView::enlargeSmallPreviews() const return m_modelRolesUpdater ? m_modelRolesUpdater->enlargeSmallPreviews() : false; } -void KFileItemListView::setEnabledPlugins(const QStringList& list) +void KFileItemListView::setEnabledPlugins(const QStringList &list) { if (m_modelRolesUpdater) { m_modelRolesUpdater->setEnabledPlugins(list); @@ -131,7 +132,7 @@ bool KFileItemListView::scanDirectories() return m_scanDirectories; } -QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const +QPixmap KFileItemListView::createDragPixmap(const KItemSet &indexes) const { if (!model()) { return QPixmap(); @@ -213,27 +214,27 @@ QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const return dragPixmap; } -void KFileItemListView::setHoverSequenceState(const QUrl& itemUrl, int seqIdx) +void KFileItemListView::setHoverSequenceState(const QUrl &itemUrl, int seqIdx) { if (m_modelRolesUpdater) { m_modelRolesUpdater->setHoverSequenceState(itemUrl, seqIdx); } } -KItemListWidgetCreatorBase* KFileItemListView::defaultWidgetCreator() const +KItemListWidgetCreatorBase *KFileItemListView::defaultWidgetCreator() const { return new KItemListWidgetCreator<KFileItemListWidget>(); } -void KFileItemListView::initializeItemListWidget(KItemListWidget* item) +void KFileItemListView::initializeItemListWidget(KItemListWidget *item) { KStandardItemListView::initializeItemListWidget(item); // Make sure that the item has an icon. QHash<QByteArray, QVariant> data = item->data(); if (!data.contains("iconName") && data["iconPixmap"].value<QPixmap>().isNull()) { - Q_ASSERT(qobject_cast<KFileItemModel*>(model())); - KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(model()); + Q_ASSERT(qobject_cast<KFileItemModel *>(model())); + KFileItemModel *fileItemModel = static_cast<KFileItemModel *>(model()); const KFileItem fileItem = fileItemModel->fileItem(item->index()); QString iconName = fileItem.iconName(); @@ -257,16 +258,16 @@ void KFileItemListView::onItemLayoutChanged(ItemLayout current, ItemLayout previ triggerVisibleIndexRangeUpdate(); } -void KFileItemListView::onModelChanged(KItemModelBase* current, KItemModelBase* previous) +void KFileItemListView::onModelChanged(KItemModelBase *current, KItemModelBase *previous) { - Q_ASSERT(qobject_cast<KFileItemModel*>(current)); + Q_ASSERT(qobject_cast<KFileItemModel *>(current)); KStandardItemListView::onModelChanged(current, previous); delete m_modelRolesUpdater; m_modelRolesUpdater = nullptr; if (current) { - m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast<KFileItemModel*>(current), this); + m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast<KFileItemModel *>(current), this); m_modelRolesUpdater->setIconSize(availableIconSize()); m_modelRolesUpdater->setScanDirectories(scanDirectories()); @@ -280,7 +281,7 @@ void KFileItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt:: triggerVisibleIndexRangeUpdate(); } -void KFileItemListView::onItemSizeChanged(const QSizeF& current, const QSizeF& previous) +void KFileItemListView::onItemSizeChanged(const QSizeF ¤t, const QSizeF &previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -293,13 +294,13 @@ void KFileItemListView::onScrollOffsetChanged(qreal current, qreal previous) triggerVisibleIndexRangeUpdate(); } -void KFileItemListView::onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous) +void KFileItemListView::onVisibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous) { KStandardItemListView::onVisibleRolesChanged(current, previous); applyRolesToModel(); } -void KFileItemListView::onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) +void KFileItemListView::onStyleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous) { KStandardItemListView::onStyleOptionChanged(current, previous); triggerIconSizeUpdate(); @@ -328,25 +329,24 @@ void KFileItemListView::onTransactionEnd() // Only unpause the model-roles-updater if no timer is active. If one // timer is still active the model-roles-updater will be unpaused later as // soon as the timer has been exceeded. - const bool timerActive = m_updateVisibleIndexRangeTimer->isActive() || - m_updateIconSizeTimer->isActive(); + const bool timerActive = m_updateVisibleIndexRangeTimer->isActive() || m_updateIconSizeTimer->isActive(); if (!timerActive) { m_modelRolesUpdater->setPaused(false); } } -void KFileItemListView::resizeEvent(QGraphicsSceneResizeEvent* event) +void KFileItemListView::resizeEvent(QGraphicsSceneResizeEvent *event) { KStandardItemListView::resizeEvent(event); triggerVisibleIndexRangeUpdate(); } -void KFileItemListView::slotItemsRemoved(const KItemRangeList& itemRanges) +void KFileItemListView::slotItemsRemoved(const KItemRangeList &itemRanges) { KStandardItemListView::slotItemsRemoved(itemRanges); } -void KFileItemListView::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) +void KFileItemListView::slotSortRoleChanged(const QByteArray ¤t, const QByteArray &previous) { const QByteArray sortRole = model()->sortRole(); if (!visibleRoles().contains(sortRole)) { @@ -420,8 +420,8 @@ void KFileItemListView::applyRolesToModel() return; } - Q_ASSERT(qobject_cast<KFileItemModel*>(model())); - KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(model()); + Q_ASSERT(qobject_cast<KFileItemModel *>(model())); + KFileItemModel *fileItemModel = static_cast<KFileItemModel *>(model()); // KFileItemModel does not distinct between "visible" and "invisible" roles. // Add all roles that are mandatory for having a working KFileItemListView: @@ -448,7 +448,7 @@ void KFileItemListView::applyRolesToModel() QSize KFileItemListView::availableIconSize() const { - const KItemListStyleOption& option = styleOption(); + const KItemListStyleOption &option = styleOption(); const int iconSize = option.iconSize; if (itemLayout() == IconsLayout) { const int maxIconWidth = itemSize().width() - 2 * option.padding; @@ -457,4 +457,3 @@ QSize KFileItemListView::availableIconSize() const return QSize(iconSize, iconSize); } - diff --git a/src/kitemviews/kfileitemlistview.h b/src/kitemviews/kfileitemlistview.h index 9c7b4fc6f..63bcf9e75 100644 --- a/src/kitemviews/kfileitemlistview.h +++ b/src/kitemviews/kfileitemlistview.h @@ -29,7 +29,7 @@ class DOLPHIN_EXPORT KFileItemListView : public KStandardItemListView Q_OBJECT public: - explicit KFileItemListView(QGraphicsWidget* parent = nullptr); + explicit KFileItemListView(QGraphicsWidget *parent = nullptr); ~KFileItemListView() override; void setPreviewsShown(bool show); @@ -52,7 +52,7 @@ public: * * @see enabledPlugins */ - void setEnabledPlugins(const QStringList& list); + void setEnabledPlugins(const QStringList &list); /** * Returns the list of enabled thumbnail plugins. @@ -78,7 +78,7 @@ public: void setScanDirectories(bool enabled); bool scanDirectories(); - QPixmap createDragPixmap(const KItemSet& indexes) const override; + QPixmap createDragPixmap(const KItemSet &indexes) const override; /** * Notifies the view of a change in the hover state on an item. @@ -88,27 +88,27 @@ public: * this method will be called repeatedly with increasing values * for this parameter. */ - void setHoverSequenceState(const QUrl& itemUrl, int seqIdx); + void setHoverSequenceState(const QUrl &itemUrl, int seqIdx); protected: - KItemListWidgetCreatorBase* defaultWidgetCreator() const override; - void initializeItemListWidget(KItemListWidget* item) override; + KItemListWidgetCreatorBase *defaultWidgetCreator() const override; + void initializeItemListWidget(KItemListWidget *item) override; virtual void onPreviewsShownChanged(bool shown); void onItemLayoutChanged(ItemLayout current, ItemLayout previous) override; - void onModelChanged(KItemModelBase* current, KItemModelBase* previous) override; + void onModelChanged(KItemModelBase *current, KItemModelBase *previous) override; void onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) override; - void onItemSizeChanged(const QSizeF& current, const QSizeF& previous) override; + void onItemSizeChanged(const QSizeF ¤t, const QSizeF &previous) override; void onScrollOffsetChanged(qreal current, qreal previous) override; - void onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous) override; - void onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) override; + void onVisibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous) override; + void onStyleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous) override; void onSupportsItemExpandingChanged(bool supportsExpanding) override; void onTransactionBegin() override; void onTransactionEnd() override; - void resizeEvent(QGraphicsSceneResizeEvent* event) override; + void resizeEvent(QGraphicsSceneResizeEvent *event) override; protected Q_SLOTS: - void slotItemsRemoved(const KItemRangeList& itemRanges) override; - void slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) override; + void slotItemsRemoved(const KItemRangeList &itemRanges) override; + void slotSortRoleChanged(const QByteArray ¤t, const QByteArray &previous) override; private Q_SLOTS: void triggerVisibleIndexRangeUpdate(); @@ -134,14 +134,12 @@ private: QSize availableIconSize() const; private: - KFileItemModelRolesUpdater* m_modelRolesUpdater; - QTimer* m_updateVisibleIndexRangeTimer; - QTimer* m_updateIconSizeTimer; + KFileItemModelRolesUpdater *m_modelRolesUpdater; + QTimer *m_updateVisibleIndexRangeTimer; + QTimer *m_updateIconSizeTimer; bool m_scanDirectories; friend class KFileItemListViewTest; // For unit testing }; #endif - - diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp index a62b75824..8002af597 100644 --- a/src/kitemviews/kfileitemlistwidget.cpp +++ b/src/kitemviews/kfileitemlistwidget.cpp @@ -18,8 +18,8 @@ #include <QGraphicsView> #include <QMimeDatabase> -KFileItemListWidgetInformant::KFileItemListWidgetInformant() : - KStandardItemListWidgetInformant() +KFileItemListWidgetInformant::KFileItemListWidgetInformant() + : KStandardItemListWidgetInformant() { } @@ -27,26 +27,25 @@ KFileItemListWidgetInformant::~KFileItemListWidgetInformant() { } -QString KFileItemListWidgetInformant::itemText(int index, const KItemListView* view) const +QString KFileItemListWidgetInformant::itemText(int index, const KItemListView *view) const { - Q_ASSERT(qobject_cast<KFileItemModel*>(view->model())); - KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(view->model()); + Q_ASSERT(qobject_cast<KFileItemModel *>(view->model())); + KFileItemModel *fileItemModel = static_cast<KFileItemModel *>(view->model()); const KFileItem item = fileItemModel->fileItem(index); return item.text(); } -bool KFileItemListWidgetInformant::itemIsLink(int index, const KItemListView* view) const +bool KFileItemListWidgetInformant::itemIsLink(int index, const KItemListView *view) const { - Q_ASSERT(qobject_cast<KFileItemModel*>(view->model())); - KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(view->model()); + Q_ASSERT(qobject_cast<KFileItemModel *>(view->model())); + KFileItemModel *fileItemModel = static_cast<KFileItemModel *>(view->model()); const KFileItem item = fileItemModel->fileItem(index); return item.isLink(); } -QString KFileItemListWidgetInformant::roleText(const QByteArray& role, - const QHash<QByteArray, QVariant>& values) const +QString KFileItemListWidgetInformant::roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values) const { QString text; const QVariant roleValue = values.value(role); @@ -56,7 +55,7 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role, // Implementation note: In case if more roles require a custom handling // use a hash + switch for a linear runtime. - auto formatDate = [formatter, local](const QDateTime& time) { + auto formatDate = [formatter, local](const QDateTime &time) { if (DetailsModeSettings::useShortRelativeDates()) { return formatter.formatRelativeDateTime(time, QLocale::ShortFormat); } else { @@ -83,12 +82,12 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role, text = formatter.formatByteSize(size); } } else if (role == "modificationtime" || role == "creationtime" || role == "accesstime") { - bool ok; - const long long time = roleValue.toLongLong(&ok); - if (ok && time != -1) { - const QDateTime dateTime = QDateTime::fromSecsSinceEpoch(time); - text = formatDate(dateTime); - } + bool ok; + const long long time = roleValue.toLongLong(&ok); + if (ok && time != -1) { + const QDateTime dateTime = QDateTime::fromSecsSinceEpoch(time); + text = formatDate(dateTime); + } } else if (role == "deletiontime" || role == "imageDateTime") { const QDateTime dateTime = roleValue.toDateTime(); if (dateTime.isValid()) { @@ -106,7 +105,7 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role, return text; } -QFont KFileItemListWidgetInformant::customizedFontForLinks(const QFont& baseFont) const +QFont KFileItemListWidgetInformant::customizedFontForLinks(const QFont &baseFont) const { // The customized font should be italic if the file is a symbolic link. QFont font(baseFont); @@ -114,8 +113,8 @@ QFont KFileItemListWidgetInformant::customizedFontForLinks(const QFont& baseFont return font; } -KFileItemListWidget::KFileItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) : - KStandardItemListWidget(informant, parent) +KFileItemListWidget::KFileItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent) + : KStandardItemListWidget(informant, parent) { } @@ -123,12 +122,12 @@ KFileItemListWidget::~KFileItemListWidget() { } -KItemListWidgetInformant* KFileItemListWidget::createInformant() +KItemListWidgetInformant *KFileItemListWidget::createInformant() { return new KFileItemListWidgetInformant(); } -bool KFileItemListWidget::isRoleRightAligned(const QByteArray& role) const +bool KFileItemListWidget::isRoleRightAligned(const QByteArray &role) const { return role == "size"; } @@ -138,7 +137,7 @@ bool KFileItemListWidget::isHidden() const return data().value("isHidden").toBool(); } -QFont KFileItemListWidget::customizedFont(const QFont& baseFont) const +QFont KFileItemListWidget::customizedFont(const QFont &baseFont) const { // The customized font should be italic if the file is a symbolic link. QFont font(baseFont); @@ -146,14 +145,14 @@ QFont KFileItemListWidget::customizedFont(const QFont& baseFont) const return font; } -int KFileItemListWidget::selectionLength(const QString& text) const +int KFileItemListWidget::selectionLength(const QString &text) const { // Select the text without MIME-type extension int selectionLength = text.length(); // If item is a directory, use the whole text length for // selection (ignore all points) - if(data().value("isDir").toBool()) { + if (data().value("isDir").toBool()) { return selectionLength; } @@ -179,7 +178,7 @@ int KFileItemListWidget::selectionLength(const QString& text) const void KFileItemListWidget::hoverSequenceStarted() { - KFileItemListView* view = listView(); + KFileItemListView *view = listView(); if (!view) { return; @@ -192,7 +191,7 @@ void KFileItemListWidget::hoverSequenceStarted() void KFileItemListWidget::hoverSequenceIndexChanged(int sequenceIndex) { - KFileItemListView* view = listView(); + KFileItemListView *view = listView(); if (!view) { return; @@ -209,7 +208,7 @@ void KFileItemListWidget::hoverSequenceIndexChanged(int sequenceIndex) void KFileItemListWidget::hoverSequenceEnded() { - KFileItemListView* view = listView(); + KFileItemListView *view = listView(); if (!view) { return; @@ -218,8 +217,7 @@ void KFileItemListWidget::hoverSequenceEnded() view->setHoverSequenceState(QUrl(), 0); } -KFileItemListView* KFileItemListWidget::listView() +KFileItemListView *KFileItemListWidget::listView() { - return dynamic_cast<KFileItemListView*>(parentItem()); + return dynamic_cast<KFileItemListView *>(parentItem()); } - diff --git a/src/kitemviews/kfileitemlistwidget.h b/src/kitemviews/kfileitemlistwidget.h index 094f6105f..27fcf7f29 100644 --- a/src/kitemviews/kfileitemlistwidget.h +++ b/src/kitemviews/kfileitemlistwidget.h @@ -12,7 +12,6 @@ class KFileItemListView; - class DOLPHIN_EXPORT KFileItemListWidgetInformant : public KStandardItemListWidgetInformant { public: @@ -20,10 +19,10 @@ public: ~KFileItemListWidgetInformant() override; protected: - QString itemText(int index, const KItemListView* view) const override; - bool itemIsLink(int index, const KItemListView* view) const override; - QString roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values) const override; - QFont customizedFontForLinks(const QFont& baseFont) const override; + QString itemText(int index, const KItemListView *view) const override; + bool itemIsLink(int index, const KItemListView *view) const override; + QString roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values) const override; + QFont customizedFontForLinks(const QFont &baseFont) const override; }; class DOLPHIN_EXPORT KFileItemListWidget : public KStandardItemListWidget @@ -31,29 +30,27 @@ class DOLPHIN_EXPORT KFileItemListWidget : public KStandardItemListWidget Q_OBJECT public: - KFileItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent); + KFileItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent); ~KFileItemListWidget() override; - static KItemListWidgetInformant* createInformant(); + static KItemListWidgetInformant *createInformant(); protected: virtual void hoverSequenceStarted() override; virtual void hoverSequenceIndexChanged(int sequenceIndex) override; virtual void hoverSequenceEnded() override; - bool isRoleRightAligned(const QByteArray& role) const override; + bool isRoleRightAligned(const QByteArray &role) const override; bool isHidden() const override; - QFont customizedFont(const QFont& baseFont) const override; + QFont customizedFont(const QFont &baseFont) const override; /** * @return Selection length without MIME-type extension */ - int selectionLength(const QString& text) const override; + int selectionLength(const QString &text) const override; private: - KFileItemListView* listView(); + KFileItemListView *listView(); }; #endif - - diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 5e6f9af01..14de9697b 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -8,24 +8,24 @@ #include "kfileitemmodel.h" -#include "dolphin_generalsettings.h" #include "dolphin_detailsmodesettings.h" +#include "dolphin_generalsettings.h" #include "dolphindebug.h" #include "private/kfileitemmodelsortalgorithm.h" #include <KDirLister> #include <KIO/Job> -#include <kio_version.h> #include <KLocalizedString> #include <KUrlMimeData> +#include <kio_version.h> #include <QElapsedTimer> +#include <QIcon> #include <QMimeData> #include <QMimeDatabase> +#include <QRecursiveMutex> #include <QTimer> #include <QWidget> -#include <QRecursiveMutex> -#include <QIcon> #include <algorithm> #include <klazylocalizedstring.h> @@ -33,25 +33,25 @@ Q_GLOBAL_STATIC(QRecursiveMutex, s_collatorMutex) // #define KFILEITEMMODEL_DEBUG -KFileItemModel::KFileItemModel(QObject* parent) : - KItemModelBase("text", parent), - m_dirLister(nullptr), - m_sortDirsFirst(true), - m_sortHiddenLast(false), - m_sortRole(NameRole), - m_sortingProgressPercent(-1), - m_roles(), - m_itemData(), - m_items(), - m_filter(), - m_filteredItems(), - m_requestRole(), - m_maximumUpdateIntervalTimer(nullptr), - m_resortAllItemsTimer(nullptr), - m_pendingItemsToInsert(), - m_groups(), - m_expandedDirs(), - m_urlsToExpand() +KFileItemModel::KFileItemModel(QObject *parent) + : KItemModelBase("text", parent) + , m_dirLister(nullptr) + , m_sortDirsFirst(true) + , m_sortHiddenLast(false) + , m_sortRole(NameRole) + , m_sortingProgressPercent(-1) + , m_roles() + , m_itemData() + , m_items() + , m_filter() + , m_filteredItems() + , m_requestRole() + , m_maximumUpdateIntervalTimer(nullptr) + , m_resortAllItemsTimer(nullptr) + , m_pendingItemsToInsert() + , m_groups() + , m_expandedDirs() + , m_urlsToExpand() { m_collator.setNumericMode(true); @@ -61,7 +61,7 @@ KFileItemModel::KFileItemModel(QObject* parent) : m_dirLister->setAutoErrorHandlingEnabled(false); m_dirLister->setDelayedMimeTypes(true); - const QWidget* parentWidget = qobject_cast<QWidget*>(parent); + const QWidget *parentWidget = qobject_cast<QWidget *>(parent); if (parentWidget) { m_dirLister->setMainWindow(parentWidget->window()); } @@ -149,7 +149,7 @@ int KFileItemModel::count() const QHash<QByteArray, QVariant> KFileItemModel::data(int index) const { if (index >= 0 && index < count()) { - ItemData* data = m_itemData.at(index); + ItemData *data = m_itemData.at(index); if (data->values.isEmpty()) { data->values = retrieveData(data->item, data->parent); } else if (data->values.count() <= 2 && data->values.value("isExpanded").toBool()) { @@ -171,7 +171,7 @@ QHash<QByteArray, QVariant> KFileItemModel::data(int index) const return QHash<QByteArray, QVariant>(); } -bool KFileItemModel::setData(int index, const QHash<QByteArray, QVariant>& values) +bool KFileItemModel::setData(int index, const QHash<QByteArray, QVariant> &values) { if (index < 0 || index >= count()) { return false; @@ -268,20 +268,20 @@ bool KFileItemModel::showDirectoriesOnly() const return m_dirLister->dirOnlyMode(); } -QMimeData* KFileItemModel::createMimeData(const KItemSet& indexes) const +QMimeData *KFileItemModel::createMimeData(const KItemSet &indexes) const { - QMimeData* data = new QMimeData(); + QMimeData *data = new QMimeData(); // The following code has been taken from KDirModel::mimeData() // (kdelibs/kio/kio/kdirmodel.cpp) // SPDX-FileCopyrightText: 2006 David Faure <[email protected]> QList<QUrl> urls; QList<QUrl> mostLocalUrls; - const ItemData* lastAddedItem = nullptr; + const ItemData *lastAddedItem = nullptr; for (int index : indexes) { - const ItemData* itemData = m_itemData.at(index); - const ItemData* parent = itemData->parent; + const ItemData *itemData = m_itemData.at(index); + const ItemData *parent = itemData->parent; while (parent && parent != lastAddedItem) { parent = parent->parent; @@ -293,7 +293,7 @@ QMimeData* KFileItemModel::createMimeData(const KItemSet& indexes) const } lastAddedItem = itemData; - const KFileItem& item = itemData->item; + const KFileItem &item = itemData->item; if (!item.isNull()) { urls << item.url(); @@ -306,7 +306,7 @@ QMimeData* KFileItemModel::createMimeData(const KItemSet& indexes) const return data; } -int KFileItemModel::indexForKeyboardSearch(const QString& text, int startFromIndex) const +int KFileItemModel::indexForKeyboardSearch(const QString &text, int startFromIndex) const { startFromIndex = qMax(0, startFromIndex); for (int i = startFromIndex; i < count(); ++i) { @@ -328,12 +328,12 @@ bool KFileItemModel::supportsDropping(int index) const return !item.isNull() && (item.isDir() || item.isDesktopFile()); } -QString KFileItemModel::roleDescription(const QByteArray& role) const +QString KFileItemModel::roleDescription(const QByteArray &role) const { static QHash<QByteArray, QString> description; if (description.isEmpty()) { int count = 0; - const RoleInfoMap* map = rolesInfoMap(count); + const RoleInfoMap *map = rolesInfoMap(count); for (int i = 0; i < count; ++i) { if (map[i].roleTranslation.isEmpty()) { continue; @@ -345,7 +345,7 @@ QString KFileItemModel::roleDescription(const QByteArray& role) const return description.value(role); } -QList<QPair<int, QVariant> > KFileItemModel::groups() const +QList<QPair<int, QVariant>> KFileItemModel::groups() const { if (!m_itemData.isEmpty() && m_groups.isEmpty()) { #ifdef KFILEITEMMODEL_DEBUG @@ -353,8 +353,12 @@ QList<QPair<int, QVariant> > KFileItemModel::groups() const timer.start(); #endif switch (typeForRole(sortRole())) { - case NameRole: m_groups = nameRoleGroups(); break; - case SizeRole: m_groups = sizeRoleGroups(); break; + case NameRole: + m_groups = nameRoleGroups(); + break; + case SizeRole: + m_groups = sizeRoleGroups(); + break; case ModificationTimeRole: m_groups = timeRoleGroups([](const ItemData *item) { return item->item.time(KFileItem::ModificationTime); @@ -375,9 +379,15 @@ QList<QPair<int, QVariant> > KFileItemModel::groups() const return item->values.value("deletiontime").toDateTime(); }); break; - case PermissionsRole: m_groups = permissionRoleGroups(); break; - case RatingRole: m_groups = ratingRoleGroups(); break; - default: m_groups = genericStringRoleGroups(sortRole()); break; + case PermissionsRole: + m_groups = permissionRoleGroups(); + break; + case RatingRole: + m_groups = ratingRoleGroups(); + break; + default: + m_groups = genericStringRoleGroups(sortRole()); + break; } #ifdef KFILEITEMMODEL_DEBUG @@ -406,12 +416,12 @@ KFileItem KFileItemModel::fileItem(const QUrl &url) const return KFileItem(); } -int KFileItemModel::index(const KFileItem& item) const +int KFileItemModel::index(const KFileItem &item) const { return index(item.url()); } -int KFileItemModel::index(const QUrl& url) const +int KFileItemModel::index(const QUrl &url) const { const QUrl urlToFind = url.adjusted(QUrl::StripTrailingSlash); @@ -461,13 +471,13 @@ int KFileItemModel::index(const QUrl& url) const } const auto uniqueKeys = indexesForUrl.uniqueKeys(); - for (const QUrl& url : uniqueKeys) { + for (const QUrl &url : uniqueKeys) { if (indexesForUrl.count(url) > 1) { qCWarning(DolphinDebug) << "Multiple items found with the URL" << url; auto it = indexesForUrl.find(url); while (it != indexesForUrl.end() && it.key() == url) { - const ItemData* data = m_itemData.at(it.value()); + const ItemData *data = m_itemData.at(it.value()); qCWarning(DolphinDebug) << "index" << it.value() << ":" << data->item; if (data->parent) { qCWarning(DolphinDebug) << "parent" << data->parent->item; @@ -492,7 +502,7 @@ void KFileItemModel::clear() slotClear(); } -void KFileItemModel::setRoles(const QSet<QByteArray>& roles) +void KFileItemModel::setRoles(const QSet<QByteArray> &roles) { if (m_roles == roles) { return; @@ -516,7 +526,7 @@ void KFileItemModel::setRoles(const QSet<QByteArray>& roles) QSetIterator<QByteArray> it(roles); while (it.hasNext()) { - const QByteArray& role = it.next(); + const QByteArray &role = it.next(); m_requestRole[typeForRole(role)] = true; } @@ -532,8 +542,8 @@ void KFileItemModel::setRoles(const QSet<QByteArray>& roles) // Clear the 'values' of all filtered items. They will be re-populated with the // correct roles the next time 'values' will be accessed via data(int). - QHash<KFileItem, ItemData*>::iterator filteredIt = m_filteredItems.begin(); - const QHash<KFileItem, ItemData*>::iterator filteredEnd = m_filteredItems.end(); + QHash<KFileItem, ItemData *>::iterator filteredIt = m_filteredItems.begin(); + const QHash<KFileItem, ItemData *>::iterator filteredEnd = m_filteredItems.end(); while (filteredIt != filteredEnd) { (*filteredIt)->values.clear(); ++filteredIt; @@ -565,7 +575,7 @@ bool KFileItemModel::setExpanded(int index, bool expanded) m_dirLister->openUrl(url, KDirLister::Keep); const QVariantList previouslyExpandedChildren = m_itemData.at(index)->values.value("previouslyExpandedChildren").value<QVariantList>(); - for (const QVariant& var : previouslyExpandedChildren) { + for (const QVariant &var : previouslyExpandedChildren) { m_urlsToExpand.insert(var.toUrl()); } } else { @@ -595,12 +605,12 @@ bool KFileItemModel::setExpanded(int index, bool expanded) int childIndex = firstChildIndex; while (childIndex < itemCount && expandedParentsCount(childIndex) > parentLevel) { - ItemData* itemData = m_itemData.at(childIndex); + ItemData *itemData = m_itemData.at(childIndex); if (itemData->values.value("isExpanded").toBool()) { const QUrl targetUrl = itemData->item.targetUrl(); const QUrl url = itemData->item.url(); m_expandedDirs.remove(targetUrl); - m_dirLister->stop(url); // TODO: try to unit-test this, see https://bugs.kde.org/show_bug.cgi?id=332102#c11 + m_dirLister->stop(url); // TODO: try to unit-test this, see https://bugs.kde.org/show_bug.cgi?id=332102#c11 #if KIO_VERSION >= QT_VERSION_CHECK(5, 92, 0) m_dirLister->forgetDirs(url); #endif @@ -662,7 +672,6 @@ void KFileItemModel::restoreExpandedDirectories(const QSet<QUrl> &urls) void KFileItemModel::expandParentDirectories(const QUrl &url) { - // Assure that each sub-path of the URL that should be // expanded is added to m_urlsToExpand. KDirLister // does not care whether the parent-URL has already been @@ -696,7 +705,7 @@ void KFileItemModel::expandParentDirectories(const QUrl &url) } } -void KFileItemModel::setNameFilter(const QString& nameFilter) +void KFileItemModel::setNameFilter(const QString &nameFilter) { if (m_filter.pattern() != nameFilter) { dispatchPendingItemsToInsert(); @@ -710,7 +719,7 @@ QString KFileItemModel::nameFilter() const return m_filter.pattern(); } -void KFileItemModel::setMimeTypeFilters(const QStringList& filters) +void KFileItemModel::setMimeTypeFilters(const QStringList &filters) { if (m_filter.mimeTypes() != filters) { dispatchPendingItemsToInsert(); @@ -740,8 +749,7 @@ void KFileItemModel::applyFilters() for (int index = m_itemData.count() - 1; index >= 0; --index) { ItemData *itemData = m_itemData.at(index); - if (m_filter.matches(itemData->item) - || (itemShownBelow && itemShownBelow->parent == itemData)) { + if (m_filter.matches(itemData->item) || (itemShownBelow && itemShownBelow->parent == itemData)) { // We could've entered here for two reasons: // 1. This item passes the filter itself // 2. This is an expanded folder that doesn't pass the filter but sees a filter-passing child just below @@ -808,7 +816,7 @@ void KFileItemModel::applyFilters() insertItems(newVisibleItems); } -void KFileItemModel::removeFilteredChildren(const KItemRangeList& itemRanges) +void KFileItemModel::removeFilteredChildren(const KItemRangeList &itemRanges) { if (m_filteredItems.isEmpty() || !m_requestRole[ExpandedParentsCountRole]) { // There are either no filtered items, or it is not possible to expand @@ -816,14 +824,14 @@ void KFileItemModel::removeFilteredChildren(const KItemRangeList& itemRanges) return; } - QSet<ItemData*> parents; - for (const KItemRange& range : itemRanges) { + QSet<ItemData *> parents; + for (const KItemRange &range : itemRanges) { for (int index = range.index; index < range.index + range.count; ++index) { parents.insert(m_itemData.at(index)); } } - QHash<KFileItem, ItemData*>::iterator it = m_filteredItems.begin(); + QHash<KFileItem, ItemData *>::iterator it = m_filteredItems.begin(); while (it != m_filteredItems.end()) { if (parents.contains(it.value()->parent)) { delete it.value(); @@ -839,7 +847,7 @@ QList<KFileItemModel::RoleInfo> KFileItemModel::rolesInformation() static QList<RoleInfo> rolesInfo; if (rolesInfo.isEmpty()) { int count = 0; - const RoleInfoMap* map = rolesInfoMap(count); + const RoleInfoMap *map = rolesInfoMap(count); for (int i = 0; i < count; ++i) { if (map[i].roleType != NoRole) { RoleInfo info; @@ -869,7 +877,7 @@ void KFileItemModel::onGroupedSortingChanged(bool current) m_groups.clear(); } -void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems) +void KFileItemModel::onSortRoleChanged(const QByteArray ¤t, const QByteArray &previous, bool resortItems) { Q_UNUSED(previous) m_sortRole = typeForRole(current); @@ -937,7 +945,7 @@ void KFileItemModel::resortAllItems() // been moved because of the resorting. QList<QUrl> oldUrls; oldUrls.reserve(itemCount); - for (const ItemData* itemData : qAsConst(m_itemData)) { + for (const ItemData *itemData : qAsConst(m_itemData)) { oldUrls.append(itemData->item.url()); } @@ -952,8 +960,7 @@ void KFileItemModel::resortAllItems() // Determine the first index that has been moved. int firstMovedIndex = 0; - while (firstMovedIndex < itemCount - && firstMovedIndex == m_items.value(oldUrls.at(firstMovedIndex))) { + while (firstMovedIndex < itemCount && firstMovedIndex == m_items.value(oldUrls.at(firstMovedIndex))) { ++firstMovedIndex; } @@ -962,8 +969,7 @@ void KFileItemModel::resortAllItems() m_groups.clear(); int lastMovedIndex = itemCount - 1; - while (lastMovedIndex > firstMovedIndex - && lastMovedIndex == m_items.value(oldUrls.at(lastMovedIndex))) { + while (lastMovedIndex > firstMovedIndex && lastMovedIndex == m_items.value(oldUrls.at(lastMovedIndex))) { --lastMovedIndex; } @@ -983,7 +989,7 @@ void KFileItemModel::resortAllItems() Q_EMIT itemsMoved(KItemRange(firstMovedIndex, movedItemsCount), movedToIndexes); } else if (groupedSorting()) { // The groups might have changed even if the order of the items has not. - const QList<QPair<int, QVariant> > oldGroups = m_groups; + const QList<QPair<int, QVariant>> oldGroups = m_groups; m_groups.clear(); if (groups() != oldGroups) { Q_EMIT groupsChanged(); @@ -1007,7 +1013,7 @@ void KFileItemModel::slotCompleted() // -> we expand the first visible URL we find in m_restoredExpandedUrls. // Iterate over a const copy because items are deleted and inserted within the loop const auto urlsToExpand = m_urlsToExpand; - for(const QUrl &url : urlsToExpand) { + for (const QUrl &url : urlsToExpand) { const int indexForUrl = index(url); if (indexForUrl >= 0) { m_urlsToExpand.remove(url); @@ -1035,7 +1041,7 @@ void KFileItemModel::slotCanceled() Q_EMIT directoryLoadingCanceled(); } -void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemList& items) +void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemList &items) { Q_ASSERT(!items.isEmpty()); @@ -1068,7 +1074,7 @@ void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemLis } } - const QList<ItemData*> itemDataList = createItemDataList(parentUrl, items); + const QList<ItemData *> itemDataList = createItemDataList(parentUrl, items); if (!m_filter.hasSetFilters()) { m_pendingItemsToInsert.append(itemDataList); @@ -1078,7 +1084,7 @@ void KFileItemModel::slotItemsAdded(const QUrl &directoryUrl, const KFileItemLis // The name or type filter is active. Hide filtered items // before inserting them into the model and remember // the filtered items in m_filteredItems. - for (ItemData* itemData : itemDataList) { + for (ItemData *itemData : itemDataList) { if (m_filter.matches(itemData->item)) { m_pendingItemsToInsert.append(itemData); if (itemData->parent) { @@ -1142,7 +1148,7 @@ int KFileItemModel::filterChildlessParents(KItemRangeList &removedItemRanges, co return filteredParentsCount; } -void KFileItemModel::slotItemsDeleted(const KFileItemList& items) +void KFileItemModel::slotItemsDeleted(const KFileItemList &items) { dispatchPendingItemsToInsert(); @@ -1152,7 +1158,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items) const auto currentDir = directory(); - for (const KFileItem& item : items) { + for (const KFileItem &item : items) { if (item.url() == currentDir) { Q_EMIT currentDirectoryRemoved(); return; @@ -1163,7 +1169,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items) indexesToRemove.append(indexForItem); } else { // Probably the item has been filtered. - QHash<KFileItem, ItemData*>::iterator it = m_filteredItems.find(item); + QHash<KFileItem, ItemData *>::iterator it = m_filteredItems.find(item); if (it != m_filteredItems.end()) { delete it.value(); m_filteredItems.erase(it); @@ -1213,7 +1219,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList& items) Q_EMIT fileItemsChanged(dirsChanged); } -void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& items) +void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem>> &items) { Q_ASSERT(!items.isEmpty()); #ifdef KFILEITEMMODEL_DEBUG @@ -1233,14 +1239,14 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& // Contains currently hidden items that should // get visible and hence removed from m_filteredItems - QList<ItemData*> newVisibleItems; + QList<ItemData *> newVisibleItems; - QListIterator<QPair<KFileItem, KFileItem> > it(items); + QListIterator<QPair<KFileItem, KFileItem>> it(items); while (it.hasNext()) { - const QPair<KFileItem, KFileItem>& itemPair = it.next(); - const KFileItem& oldItem = itemPair.first; - const KFileItem& newItem = itemPair.second; + const QPair<KFileItem, KFileItem> &itemPair = it.next(); + const KFileItem &oldItem = itemPair.first; + const KFileItem &newItem = itemPair.second; const int indexForItem = index(oldItem); const bool newItemMatchesFilter = m_filter.matches(newItem); if (indexForItem >= 0) { @@ -1248,11 +1254,11 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& // Keep old values as long as possible if they could not retrieved synchronously yet. // The update of the values will be done asynchronously by KFileItemModelRolesUpdater. - ItemData * const itemData = m_itemData.at(indexForItem); + ItemData *const itemData = m_itemData.at(indexForItem); QHashIterator<QByteArray, QVariant> it(retrieveData(newItem, itemData->parent)); while (it.hasNext()) { it.next(); - const QByteArray& role = it.key(); + const QByteArray &role = it.key(); if (itemData->values.value(role) != it.value()) { itemData->values.insert(role, it.value()); changedRoles.insert(role); @@ -1276,7 +1282,7 @@ void KFileItemModel::slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& } } else { // Check if 'oldItem' is one of the filtered items. - QHash<KFileItem, ItemData*>::iterator it = m_filteredItems.find(oldItem); + QHash<KFileItem, ItemData *>::iterator it = m_filteredItems.find(oldItem); if (it != m_filteredItems.end()) { ItemData *const itemData = it.value(); itemData->item = newItem; @@ -1413,7 +1419,7 @@ void KFileItemModel::dispatchPendingItemsToInsert() } } -void KFileItemModel::insertItems(QList<ItemData*>& newItems) +void KFileItemModel::insertItems(QList<ItemData *> &newItems) { if (newItems.isEmpty()) { return; @@ -1436,8 +1442,7 @@ void KFileItemModel::insertItems(QList<ItemData*>& newItems) if (m_sortRole == NameRole) { parallelMergeSort(newItems.begin(), newItems.end(), nameLessThan, QThread::idealThreadCount()); } else if (isRoleValueNatural(m_sortRole)) { - auto lambdaLessThan = [&] (const KFileItemModel::ItemData* a, const KFileItemModel::ItemData* b) - { + auto lambdaLessThan = [&](const KFileItemModel::ItemData *a, const KFileItemModel::ItemData *b) { const QByteArray role = roleForType(m_sortRole); return a->values.value(role).toString() < b->values.value(role).toString(); }; @@ -1476,7 +1481,7 @@ void KFileItemModel::insertItems(QList<ItemData*>& newItems) int rangeCount = 0; while (sourceIndexNewItems >= 0) { - ItemData* newItem = newItems.at(sourceIndexNewItems); + ItemData *newItem = newItems.at(sourceIndexNewItems); if (sourceIndexExistingItems >= 0 && lessThan(newItem, m_itemData.at(sourceIndexExistingItems), m_collator)) { // Move an existing item to its new position. If any new items // are behind it, push the item range to itemRanges. @@ -1516,7 +1521,7 @@ void KFileItemModel::insertItems(QList<ItemData*>& newItems) #endif } -void KFileItemModel::removeItems(const KItemRangeList& itemRanges, RemoveItemsBehavior behavior) +void KFileItemModel::removeItems(const KItemRangeList &itemRanges, RemoveItemsBehavior behavior) { if (itemRanges.isEmpty()) { return; @@ -1526,7 +1531,7 @@ void KFileItemModel::removeItems(const KItemRangeList& itemRanges, RemoveItemsBe // Step 1: Remove the items from m_itemData, and free the ItemData. int removedItemsCount = 0; - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { removedItemsCount += range.count; for (int index = range.index; index < range.index + range.count; ++index) { @@ -1565,7 +1570,7 @@ void KFileItemModel::removeItems(const KItemRangeList& itemRanges, RemoveItemsBe Q_EMIT itemsRemoved(itemRanges); } -QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const QUrl& parentUrl, const KFileItemList& items) const +QList<KFileItemModel::ItemData *> KFileItemModel::createItemDataList(const QUrl &parentUrl, const KFileItemList &items) const { if (m_sortRole == TypeRole) { // Try to resolve the MIME-types synchronously to prevent a reordering of @@ -1578,11 +1583,11 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const QUrl& const int parentIndex = index(parentUrl); ItemData *parentItem = parentIndex < 0 ? m_filteredItems.value(KFileItem(parentUrl), nullptr) : m_itemData.at(parentIndex); - QList<ItemData*> itemDataList; + QList<ItemData *> itemDataList; itemDataList.reserve(items.count()); - for (const KFileItem& item : items) { - ItemData* itemData = new ItemData(); + for (const KFileItem &item : items) { + ItemData *itemData = new ItemData(); itemData->item = item; itemData->parent = parentItem; itemDataList.append(itemData); @@ -1591,7 +1596,7 @@ QList<KFileItemModel::ItemData*> KFileItemModel::createItemDataList(const QUrl& return itemDataList; } -void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList) +void KFileItemModel::prepareItemsForSorting(QList<ItemData *> &itemDataList) { switch (m_sortRole) { case ExtensionRole: @@ -1603,7 +1608,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList) case DeletionTimeRole: // These roles can be determined with retrieveData, and they have to be stored // in the QHash "values" for the sorting. - for (ItemData* itemData : qAsConst(itemDataList)) { + for (ItemData *itemData : qAsConst(itemDataList)) { if (itemData->values.isEmpty()) { itemData->values = retrieveData(itemData->item, itemData->parent); } @@ -1612,7 +1617,7 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList) case TypeRole: // At least store the data including the file type for items with known MIME type. - for (ItemData* itemData : qAsConst(itemDataList)) { + for (ItemData *itemData : qAsConst(itemDataList)) { if (itemData->values.isEmpty()) { const KFileItem item = itemData->item; if (item.isDir() || item.isMimeTypeKnown()) { @@ -1632,11 +1637,11 @@ void KFileItemModel::prepareItemsForSorting(QList<ItemData*>& itemDataList) } } -int KFileItemModel::expandedParentsCount(const ItemData* data) +int KFileItemModel::expandedParentsCount(const ItemData *data) { // The hash 'values' is only guaranteed to contain the key "expandedParentsCount" // if the corresponding item is expanded, and it is not a top-level item. - const ItemData* parent = data->parent; + const ItemData *parent = data->parent; if (parent) { if (parent->parent) { Q_ASSERT(parent->values.contains("expandedParentsCount")); @@ -1655,7 +1660,7 @@ void KFileItemModel::removeExpandedItems() const int maxIndex = m_itemData.count() - 1; for (int i = 0; i <= maxIndex; ++i) { - const ItemData* itemData = m_itemData.at(i); + const ItemData *itemData = m_itemData.at(i); if (itemData->parent) { indexesToRemove.append(i); } @@ -1665,8 +1670,8 @@ void KFileItemModel::removeExpandedItems() m_expandedDirs.clear(); // Also remove all filtered items which have a parent. - QHash<KFileItem, ItemData*>::iterator it = m_filteredItems.begin(); - const QHash<KFileItem, ItemData*>::iterator end = m_filteredItems.end(); + QHash<KFileItem, ItemData *>::iterator it = m_filteredItems.begin(); + const QHash<KFileItem, ItemData *>::iterator end = m_filteredItems.end(); while (it != end) { if (it.value()->parent) { @@ -1678,14 +1683,14 @@ void KFileItemModel::removeExpandedItems() } } -void KFileItemModel::emitItemsChangedAndTriggerResorting(const KItemRangeList& itemRanges, const QSet<QByteArray>& changedRoles) +void KFileItemModel::emitItemsChangedAndTriggerResorting(const KItemRangeList &itemRanges, const QSet<QByteArray> &changedRoles) { Q_EMIT itemsChanged(itemRanges, changedRoles); // Trigger a resorting if necessary. Note that this can happen even if the sort // role has not changed at all because the file name can be used as a fallback. if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(NameRole))) { - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { bool needsResorting = false; const int first = range.index; @@ -1695,11 +1700,9 @@ void KFileItemModel::emitItemsChangedAndTriggerResorting(const KItemRangeList& i // (a) The first item in the range is "lessThan" its predecessor, // (b) the successor of the last item is "lessThan" the last item, or // (c) the internal order of the items in the range is incorrect. - if (first > 0 - && lessThan(m_itemData.at(first), m_itemData.at(first - 1), m_collator)) { + if (first > 0 && lessThan(m_itemData.at(first), m_itemData.at(first - 1), m_collator)) { needsResorting = true; - } else if (last < count() - 1 - && lessThan(m_itemData.at(last + 1), m_itemData.at(last), m_collator)) { + } else if (last < count() - 1 && lessThan(m_itemData.at(last + 1), m_itemData.at(last), m_collator)) { needsResorting = true; } else { for (int index = first; index < last; ++index) { @@ -1737,14 +1740,14 @@ void KFileItemModel::resetRoles() } } -KFileItemModel::RoleType KFileItemModel::typeForRole(const QByteArray& role) const +KFileItemModel::RoleType KFileItemModel::typeForRole(const QByteArray &role) const { static QHash<QByteArray, RoleType> roles; if (roles.isEmpty()) { // Insert user visible roles that can be accessed with // KFileItemModel::roleInformation() int count = 0; - const RoleInfoMap* map = rolesInfoMap(count); + const RoleInfoMap *map = rolesInfoMap(count); for (int i = 0; i < count; ++i) { roles.insert(map[i].role, map[i].roleType); } @@ -1771,7 +1774,7 @@ QByteArray KFileItemModel::roleForType(RoleType roleType) const // Insert user visible roles that can be accessed with // KFileItemModel::roleInformation() int count = 0; - const RoleInfoMap* map = rolesInfoMap(count); + const RoleInfoMap *map = rolesInfoMap(count); for (int i = 0; i < count; ++i) { roles.insert(map[i].roleType, map[i].role); } @@ -1791,7 +1794,7 @@ QByteArray KFileItemModel::roleForType(RoleType roleType) const return roles.value(roleType); } -QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item, const ItemData* parent) const +QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem &item, const ItemData *parent) const { // It is important to insert only roles that are fast to retrieve. E.g. // KFileItem::iconName() can be very expensive if the MIME-type is unknown @@ -1930,7 +1933,7 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item, return data; } -bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QCollator& collator) const +bool KFileItemModel::lessThan(const ItemData *a, const ItemData *b, const QCollator &collator) const { int result = 0; @@ -1991,11 +1994,9 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0; } -void KFileItemModel::sort(const QList<KFileItemModel::ItemData*>::iterator &begin, - const QList<KFileItemModel::ItemData*>::iterator &end) const +void KFileItemModel::sort(const QList<KFileItemModel::ItemData *>::iterator &begin, const QList<KFileItemModel::ItemData *>::iterator &end) const { - auto lambdaLessThan = [&] (const KFileItemModel::ItemData* a, const KFileItemModel::ItemData* b) - { + auto lambdaLessThan = [&](const KFileItemModel::ItemData *a, const KFileItemModel::ItemData *b) { return lessThan(a, b, m_collator); }; @@ -2012,15 +2013,15 @@ void KFileItemModel::sort(const QList<KFileItemModel::ItemData*>::iterator &begi } } -int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const QCollator& collator) const +int KFileItemModel::sortRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const { // This function must never return 0, because that would break stable // sorting, which leads to all kinds of bugs. // See: https://bugs.kde.org/show_bug.cgi?id=433247 // If two items have equal sort values, let the fallbacks at the bottom of // the function handle it. - const KFileItem& itemA = a->item; - const KFileItem& itemB = b->item; + const KFileItem &itemA = a->item; + const KFileItem &itemB = b->item; int result = 0; @@ -2128,7 +2129,7 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const break; } - case DimensionsRole: { + case DimensionsRole: { const QByteArray role = roleForType(m_sortRole); const QSize dimensionsA = a->values.value(role).toSize(); const QSize dimensionsB = b->values.value(role).toSize(); @@ -2156,7 +2157,6 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const } break; } - } if (result != 0) { @@ -2182,7 +2182,7 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const return QString::compare(itemA.url().url(), itemB.url().url(), Qt::CaseSensitive); } -int KFileItemModel::stringCompare(const QString& a, const QString& b, const QCollator& collator) const +int KFileItemModel::stringCompare(const QString &a, const QString &b, const QCollator &collator) const { QMutexLocker collatorLock(s_collatorMutex()); @@ -2201,12 +2201,12 @@ int KFileItemModel::stringCompare(const QString& a, const QString& b, const QCol return QString::compare(a, b, Qt::CaseSensitive); } -QList<QPair<int, QVariant> > KFileItemModel::nameRoleGroups() const +QList<QPair<int, QVariant>> KFileItemModel::nameRoleGroups() const { Q_ASSERT(!m_itemData.isEmpty()); const int maxIndex = count() - 1; - QList<QPair<int, QVariant> > groups; + QList<QPair<int, QVariant>> groups; QString groupValue; QChar firstChar; @@ -2226,7 +2226,6 @@ QList<QPair<int, QVariant> > KFileItemModel::nameRoleGroups() const if (firstChar != newFirstChar) { QString newGroupValue; if (newFirstChar.isLetter()) { - if (m_collator.compare(newFirstChar, QChar(QLatin1Char('A'))) >= 0 && m_collator.compare(newFirstChar, QChar(QLatin1Char('Z'))) <= 0) { // WARNING! Symbols based on latin 'Z' like 'Z' with acute are treated wrong as non Latin and put in a new group. @@ -2275,12 +2274,12 @@ QList<QPair<int, QVariant> > KFileItemModel::nameRoleGroups() const return groups; } -QList<QPair<int, QVariant> > KFileItemModel::sizeRoleGroups() const +QList<QPair<int, QVariant>> KFileItemModel::sizeRoleGroups() const { Q_ASSERT(!m_itemData.isEmpty()); const int maxIndex = count() - 1; - QList<QPair<int, QVariant> > groups; + QList<QPair<int, QVariant>> groups; QString groupValue; for (int i = 0; i <= maxIndex; ++i) { @@ -2288,7 +2287,7 @@ QList<QPair<int, QVariant> > KFileItemModel::sizeRoleGroups() const continue; } - const KFileItem& item = m_itemData.at(i)->item; + const KFileItem &item = m_itemData.at(i)->item; KIO::filesize_t fileSize = !item.isNull() ? item.size() : ~0U; QString newGroupValue; if (!item.isNull() && item.isDir()) { @@ -2318,12 +2317,12 @@ QList<QPair<int, QVariant> > KFileItemModel::sizeRoleGroups() const return groups; } -QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const +QList<QPair<int, QVariant>> KFileItemModel::timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const { Q_ASSERT(!m_itemData.isEmpty()); const int maxIndex = count() - 1; - QList<QPair<int, QVariant> > groups; + QList<QPair<int, QVariant>> groups; const QDate currentDate = QDate::currentDate(); @@ -2345,19 +2344,23 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function< const int daysDistance = fileDate.daysTo(currentDate); QString newGroupValue; - if (currentDate.year() == fileDate.year() && - currentDate.month() == fileDate.month()) { - + if (currentDate.year() == fileDate.year() && currentDate.month() == fileDate.month()) { switch (daysDistance / 7) { case 0: switch (daysDistance) { - case 0: newGroupValue = i18nc("@title:group Date", "Today"); break; - case 1: newGroupValue = i18nc("@title:group Date", "Yesterday"); break; + case 0: + newGroupValue = i18nc("@title:group Date", "Today"); + break; + case 1: + newGroupValue = i18nc("@title:group Date", "Yesterday"); + break; default: - newGroupValue = fileTime.toString( - i18nc("@title:group Date: The week day name: dddd", "dddd")); - newGroupValue = i18nc("Can be used to script translation of \"dddd\"" - "with context @title:group Date", "%1", newGroupValue); + newGroupValue = fileTime.toString(i18nc("@title:group Date: The week day name: dddd", "dddd")); + newGroupValue = i18nc( + "Can be used to script translation of \"dddd\"" + "with context @title:group Date", + "%1", + newGroupValue); } break; case 1: @@ -2378,100 +2381,135 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function< } } else { const QDate lastMonthDate = currentDate.addMonths(-1); - if (lastMonthDate.year() == fileDate.year() && - lastMonthDate.month() == fileDate.month()) { - + if (lastMonthDate.year() == fileDate.year() && lastMonthDate.month() == fileDate.month()) { if (daysDistance == 1) { - const KLocalizedString format = ki18nc("@title:group Date: " - "MMMM is full month name in current locale, and yyyy is " - "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 KLocalizedString format = ki18nc( + "@title:group Date: " + "MMMM is full month name in current locale, and yyyy is " + "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); - newGroupValue = i18nc("Can be used to script translation of " + newGroupValue = i18nc( + "Can be used to script translation of " "\"'Yesterday' (MMMM, yyyy)\" with context @title:group Date", - "%1", newGroupValue); + "%1", + newGroupValue); } else { - qCWarning(DolphinDebug).nospace() << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; - const QString untranslatedFormat = format.toString({ QLatin1String("en_US") }); + qCWarning(DolphinDebug).nospace() + << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; + const QString untranslatedFormat = format.toString({QLatin1String("en_US")}); newGroupValue = fileTime.toString(untranslatedFormat); } } 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.", - "dddd (MMMM, yyyy)")); - newGroupValue = i18nc("Can be used to script translation of " + 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.", + "dddd (MMMM, yyyy)")); + newGroupValue = i18nc( + "Can be used to script translation of " "\"dddd (MMMM, yyyy)\" with context @title:group Date", - "%1", newGroupValue); + "%1", + newGroupValue); } 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. 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 KLocalizedString format = ki18nc( + "@title:group Date: " + "MMMM is full month name in current locale, and yyyy is " + "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); - newGroupValue = i18nc("Can be used to script translation of " + newGroupValue = i18nc( + "Can be used to script translation of " "\"'One Week Ago' (MMMM, yyyy)\" with context @title:group Date", - "%1", newGroupValue); + "%1", + newGroupValue); } else { - qCWarning(DolphinDebug).nospace() << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; - const QString untranslatedFormat = format.toString({ QLatin1String("en_US") }); + qCWarning(DolphinDebug).nospace() + << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; + const QString untranslatedFormat = format.toString({QLatin1String("en_US")}); newGroupValue = fileTime.toString(untranslatedFormat); } } 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. 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 KLocalizedString format = ki18nc( + "@title:group Date: " + "MMMM is full month name in current locale, and yyyy is " + "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); - newGroupValue = i18nc("Can be used to script translation of " + newGroupValue = i18nc( + "Can be used to script translation of " "\"'Two Weeks Ago' (MMMM, yyyy)\" with context @title:group Date", - "%1", newGroupValue); + "%1", + newGroupValue); } else { - qCWarning(DolphinDebug).nospace() << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; - const QString untranslatedFormat = format.toString({ QLatin1String("en_US") }); + qCWarning(DolphinDebug).nospace() + << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; + const QString untranslatedFormat = format.toString({QLatin1String("en_US")}); newGroupValue = fileTime.toString(untranslatedFormat); } } 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. 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 KLocalizedString format = ki18nc( + "@title:group Date: " + "MMMM is full month name in current locale, and yyyy is " + "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); - newGroupValue = i18nc("Can be used to script translation of " + newGroupValue = i18nc( + "Can be used to script translation of " "\"'Three Weeks Ago' (MMMM, yyyy)\" with context @title:group Date", - "%1", newGroupValue); + "%1", + newGroupValue); } else { - qCWarning(DolphinDebug).nospace() << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; - const QString untranslatedFormat = format.toString({ QLatin1String("en_US") }); + qCWarning(DolphinDebug).nospace() + << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; + const QString untranslatedFormat = format.toString({QLatin1String("en_US")}); newGroupValue = fileTime.toString(untranslatedFormat); } } else { - const KLocalizedString format = ki18nc("@title:group Date: " - "MMMM is full month name in current locale, and yyyy is " - "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 KLocalizedString format = ki18nc( + "@title:group Date: " + "MMMM is full month name in current locale, and yyyy is " + "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); - newGroupValue = i18nc("Can be used to script translation of " + newGroupValue = i18nc( + "Can be used to script translation of " "\"'Earlier on' MMMM, yyyy\" with context @title:group Date", - "%1", newGroupValue); + "%1", + newGroupValue); } else { - qCWarning(DolphinDebug).nospace() << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; - const QString untranslatedFormat = format.toString({ QLatin1String("en_US") }); + qCWarning(DolphinDebug).nospace() + << "A wrong translation was found: " << translatedFormat << ". Please file a bug report at bugs.kde.org"; + const QString untranslatedFormat = format.toString({QLatin1String("en_US")}); newGroupValue = fileTime.toString(untranslatedFormat); } } } else { - newGroupValue = fileTime.toString(i18nc("@title:group " - "The month and year: MMMM is full month name in current locale, " - "and yyyy is full year number", "MMMM, yyyy")); - newGroupValue = i18nc("Can be used to script translation of " + newGroupValue = + fileTime.toString(i18nc("@title:group " + "The month and year: MMMM is full month name in current locale, " + "and yyyy is full year number", + "MMMM, yyyy")); + newGroupValue = i18nc( + "Can be used to script translation of " "\"MMMM, yyyy\" with context @title:group Date", - "%1", newGroupValue); + "%1", + newGroupValue); } } @@ -2484,12 +2522,12 @@ QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function< return groups; } -QList<QPair<int, QVariant> > KFileItemModel::permissionRoleGroups() const +QList<QPair<int, QVariant>> KFileItemModel::permissionRoleGroups() const { Q_ASSERT(!m_itemData.isEmpty()); const int maxIndex = count() - 1; - QList<QPair<int, QVariant> > groups; + QList<QPair<int, QVariant>> groups; QString permissionsString; QString groupValue; @@ -2498,7 +2536,7 @@ QList<QPair<int, QVariant> > KFileItemModel::permissionRoleGroups() const continue; } - const ItemData* itemData = m_itemData.at(i); + const ItemData *itemData = m_itemData.at(i); const QString newPermissionsString = itemData->values.value("permissions").toString(); if (newPermissionsString == permissionsString) { continue; @@ -2556,12 +2594,12 @@ QList<QPair<int, QVariant> > KFileItemModel::permissionRoleGroups() const return groups; } -QList<QPair<int, QVariant> > KFileItemModel::ratingRoleGroups() const +QList<QPair<int, QVariant>> KFileItemModel::ratingRoleGroups() const { Q_ASSERT(!m_itemData.isEmpty()); const int maxIndex = count() - 1; - QList<QPair<int, QVariant> > groups; + QList<QPair<int, QVariant>> groups; int groupValue = -1; for (int i = 0; i <= maxIndex; ++i) { @@ -2578,12 +2616,12 @@ QList<QPair<int, QVariant> > KFileItemModel::ratingRoleGroups() const return groups; } -QList<QPair<int, QVariant> > KFileItemModel::genericStringRoleGroups(const QByteArray& role) const +QList<QPair<int, QVariant>> KFileItemModel::genericStringRoleGroups(const QByteArray &role) const { Q_ASSERT(!m_itemData.isEmpty()); const int maxIndex = count() - 1; - QList<QPair<int, QVariant> > groups; + QList<QPair<int, QVariant>> groups; bool isFirstGroupValue = true; QString groupValue; @@ -2630,7 +2668,7 @@ void KFileItemModel::emitSortProgress(int resolvedCount) } } -const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count) +const KFileItemModel::RoleInfoMap *KFileItemModel::rolesInfoMap(int &count) { static const RoleInfoMap rolesInfoMap[] = { // | role | roleType | role translation | group translation | requires Baloo | requires indexer @@ -2678,11 +2716,11 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count) return rolesInfoMap; } -void KFileItemModel::determineMimeTypes(const KFileItemList& items, int timeout) +void KFileItemModel::determineMimeTypes(const KFileItemList &items, int timeout) { QElapsedTimer timer; timer.start(); - for (const KFileItem& item : items) { + for (const KFileItem &item : items) { // Only determine mime types for files here. For directories, // KFileItem::determineMimeType() reads the .directory file inside to // load the icon, but this is not necessary at all if we just need the @@ -2700,7 +2738,7 @@ void KFileItemModel::determineMimeTypes(const KFileItemList& items, int timeout) } } -QByteArray KFileItemModel::sharedValue(const QByteArray& value) +QByteArray KFileItemModel::sharedValue(const QByteArray &value) { static QSet<QByteArray> pool; const QSet<QByteArray>::const_iterator it = pool.constFind(value); @@ -2737,14 +2775,13 @@ bool KFileItemModel::isConsistent() const // Check if the items are sorted correctly. if (i > 0 && !lessThan(m_itemData.at(i - 1), m_itemData.at(i), m_collator)) { - qCWarning(DolphinDebug) << "The order of items" << i - 1 << "and" << i << "is wrong:" - << fileItem(i - 1) << fileItem(i); + qCWarning(DolphinDebug) << "The order of items" << i - 1 << "and" << i << "is wrong:" << fileItem(i - 1) << fileItem(i); return false; } // Check if all parent-child relationships are consistent. - const ItemData* data = m_itemData.at(i); - const ItemData* parent = data->parent; + const ItemData *data = m_itemData.at(i); + const ItemData *parent = data->parent; if (parent) { if (expandedParentsCount(data) != expandedParentsCount(parent) + 1) { qCWarning(DolphinDebug) << "expandedParentsCount is inconsistent for parent" << parent->item << "and child" << data->item; @@ -2753,7 +2790,8 @@ bool KFileItemModel::isConsistent() const const int parentIndex = index(parent->item); if (parentIndex >= i) { - qCWarning(DolphinDebug) << "Index" << parentIndex << "of parent" << parent->item << "is not smaller than index" << i << "of child" << data->item; + qCWarning(DolphinDebug) << "Index" << parentIndex << "of parent" << parent->item << "is not smaller than index" << i << "of child" + << data->item; return false; } } diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index 368ab76d8..7c4b8ec8f 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -25,8 +25,9 @@ class KDirLister; class QTimer; -namespace KIO { - class Job; +namespace KIO +{ +class Job; } /** @@ -44,7 +45,7 @@ class DOLPHIN_EXPORT KFileItemModel : public KItemModelBase Q_OBJECT public: - explicit KFileItemModel(QObject* parent = nullptr); + explicit KFileItemModel(QObject *parent = nullptr); ~KFileItemModel() override; /** @@ -53,13 +54,13 @@ public: * indicate the current state of the loading process. The items * of the directory are added after the loading has been completed. */ - void loadDirectory(const QUrl& url); + void loadDirectory(const QUrl &url); /** * Throws away all currently loaded items and refreshes the directory * by reloading all items again. */ - void refreshDirectory(const QUrl& url); + void refreshDirectory(const QUrl &url); /** * @return Parent directory of the items that are shown. In case @@ -77,7 +78,7 @@ public: int count() const override; QHash<QByteArray, QVariant> data(int index) const override; - bool setData(int index, const QHash<QByteArray, QVariant>& values) override; + bool setData(int index, const QHash<QByteArray, QVariant> &values) override; /** * Sets a separate sorting with directories first (true) or a mixed @@ -102,15 +103,15 @@ public: void setShowDirectoriesOnly(bool enabled); bool showDirectoriesOnly() const; - QMimeData* createMimeData(const KItemSet& indexes) const override; + QMimeData *createMimeData(const KItemSet &indexes) const override; - int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const override; + int indexForKeyboardSearch(const QString &text, int startFromIndex = 0) const override; bool supportsDropping(int index) const override; - QString roleDescription(const QByteArray& role) const override; + QString roleDescription(const QByteArray &role) const override; - QList<QPair<int, QVariant> > groups() const override; + QList<QPair<int, QVariant>> groups() const override; /** * @return The file-item for the index \a index. If the index is in a valid @@ -124,14 +125,14 @@ public: * URL is found KFileItem::isNull() will be true for the returned * file-item. The runtime complexity of this call is O(1). */ - KFileItem fileItem(const QUrl& url) const; + KFileItem fileItem(const QUrl &url) const; /** * @return The index for the file-item \a item. -1 is returned if no file-item * is found or if the file-item is null. The amortized runtime * complexity of this call is O(1). */ - int index(const KFileItem& item) const; + int index(const KFileItem &item) const; /** * @return The index for the URL \a url. -1 is returned if no file-item @@ -153,7 +154,7 @@ public: /** * Sets the roles that should be shown for each item. */ - void setRoles(const QSet<QByteArray>& roles); + void setRoles(const QSet<QByteArray> &roles); QSet<QByteArray> roles() const; bool setExpanded(int index, bool expanded) override; @@ -168,21 +169,21 @@ public: * After calling loadDirectory() or refreshDirectory() the marked sub-directories * will be expanded step-by-step. */ - void restoreExpandedDirectories(const QSet<QUrl>& urls); + void restoreExpandedDirectories(const QSet<QUrl> &urls); /** * Expands all parent-directories of the item \a url. */ - void expandParentDirectories(const QUrl& url); + void expandParentDirectories(const QUrl &url); - void setNameFilter(const QString& nameFilter); + void setNameFilter(const QString &nameFilter); QString nameFilter() const; - void setMimeTypeFilters(const QStringList& filters); + void setMimeTypeFilters(const QStringList &filters); QStringList mimeTypeFilters() const; - struct RoleInfo - { QByteArray role; + struct RoleInfo { + QByteArray role; QString translation; QString group; bool requiresBaloo; @@ -237,25 +238,25 @@ Q_SIGNALS: * Is emitted if an information message (e.g. "Connecting to host...") * should be shown. */ - void infoMessage(const QString& message); + void infoMessage(const QString &message); /** * Is emitted if an error message (e.g. "Unknown location") * should be shown. */ - void errorMessage(const QString& message); + void errorMessage(const QString &message); /** * Is emitted if a redirection from the current URL \a oldUrl * to the new URL \a newUrl has been done. */ - void directoryRedirection(const QUrl& oldUrl, const QUrl& newUrl); + void directoryRedirection(const QUrl &oldUrl, const QUrl &newUrl); /** * Is emitted when the URL passed by KFileItemModel::setUrl() represents a file. * In this case no signal errorMessage() will be emitted. */ - void urlIsFileError(const QUrl& url); + void urlIsFileError(const QUrl &url); /** * It is emitted for files when they change and @@ -270,7 +271,7 @@ Q_SIGNALS: protected: void onGroupedSortingChanged(bool current) override; - void onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems = true) override; + void onSortRoleChanged(const QByteArray ¤t, const QByteArray &previous, bool resortItems = true) override; void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) override; private Q_SLOTS: @@ -282,9 +283,9 @@ private Q_SLOTS: void slotCompleted(); void slotCanceled(); - void slotItemsAdded(const QUrl& directoryUrl, const KFileItemList& items); - void slotItemsDeleted(const KFileItemList& items); - void slotRefreshItems(const QList<QPair<KFileItem, KFileItem> >& items); + void slotItemsAdded(const QUrl &directoryUrl, const KFileItemList &items); + void slotItemsDeleted(const KFileItemList &items); + void slotRefreshItems(const QList<QPair<KFileItem, KFileItem>> &items); void slotClear(); void slotSortingChoiceChanged(); void slotListerError(KIO::Job *job); @@ -294,33 +295,66 @@ private Q_SLOTS: private: enum RoleType { // User visible roles: - NoRole, NameRole, SizeRole, ModificationTimeRole, CreationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole, - GroupRole, TypeRole, ExtensionRole, DestinationRole, PathRole, DeletionTimeRole, + NoRole, + NameRole, + SizeRole, + ModificationTimeRole, + CreationTimeRole, + AccessTimeRole, + PermissionsRole, + OwnerRole, + GroupRole, + TypeRole, + ExtensionRole, + DestinationRole, + PathRole, + DeletionTimeRole, // User visible roles available with Baloo: - CommentRole, TagsRole, RatingRole, DimensionsRole, WidthRole, HeightRole, ImageDateTimeRole, OrientationRole, - PublisherRole, PageCountRole, WordCountRole, TitleRole, AuthorRole, LineCountRole, ArtistRole, GenreRole, AlbumRole, DurationRole, TrackRole, ReleaseYearRole, - BitrateRole, OriginUrlRole, AspectRatioRole, FrameRateRole, + CommentRole, + TagsRole, + RatingRole, + DimensionsRole, + WidthRole, + HeightRole, + ImageDateTimeRole, + OrientationRole, + PublisherRole, + PageCountRole, + WordCountRole, + TitleRole, + AuthorRole, + LineCountRole, + ArtistRole, + GenreRole, + AlbumRole, + DurationRole, + TrackRole, + ReleaseYearRole, + BitrateRole, + OriginUrlRole, + AspectRatioRole, + FrameRateRole, // Non-visible roles: - IsDirRole, IsLinkRole, IsHiddenRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole, + IsDirRole, + IsLinkRole, + IsHiddenRole, + IsExpandedRole, + IsExpandableRole, + ExpandedParentsCountRole, // Mandatory last entry: RolesCount }; - struct ItemData - { + struct ItemData { KFileItem item; QHash<QByteArray, QVariant> values; - ItemData* parent; + ItemData *parent; }; - enum RemoveItemsBehavior { - KeepItemData, - DeleteItemData, - DeleteItemDataIfUnfiltered - }; + enum RemoveItemsBehavior { KeepItemData, DeleteItemData, DeleteItemDataIfUnfiltered }; - void insertItems(QList<ItemData*>& items); - void removeItems(const KItemRangeList& itemRanges, RemoveItemsBehavior behavior); + void insertItems(QList<ItemData *> &items); + void removeItems(const KItemRangeList &itemRanges, RemoveItemsBehavior behavior); /** * Helper method for insertItems() and removeItems(): Creates @@ -328,16 +362,16 @@ private: * Note that the ItemData instances are created dynamically and * must be deleted by the caller. */ - QList<ItemData*> createItemDataList(const QUrl& parentUrl, const KFileItemList& items) const; + QList<ItemData *> createItemDataList(const QUrl &parentUrl, const KFileItemList &items) const; /** * Prepares the items for sorting. Normally, the hash 'values' in ItemData is filled * lazily to save time and memory, but for some sort roles, it is expected that the * sort role data is stored in 'values'. */ - void prepareItemsForSorting(QList<ItemData*>& itemDataList); + void prepareItemsForSorting(QList<ItemData *> &itemDataList); - static int expandedParentsCount(const ItemData* data); + static int expandedParentsCount(const ItemData *data); void removeExpandedItems(); @@ -346,7 +380,7 @@ private: * the itemsChanged() signal, checks if the sort order is still correct, * and starts m_resortAllItemsTimer if that is not the case. */ - void emitItemsChangedAndTriggerResorting(const KItemRangeList& itemRanges, const QSet<QByteArray>& changedRoles); + void emitItemsChangedAndTriggerResorting(const KItemRangeList &itemRanges, const QSet<QByteArray> &changedRoles); /** * Resets all values from m_requestRole to false. @@ -357,7 +391,7 @@ private: * @return Role-type for the given role. * Runtime complexity is O(1). */ - RoleType typeForRole(const QByteArray& role) const; + RoleType typeForRole(const QByteArray &role) const; /** * @return Role-byte-array for the given role-type. @@ -365,7 +399,7 @@ private: */ QByteArray roleForType(RoleType roleType) const; - QHash<QByteArray, QVariant> retrieveData(const KFileItem& item, const ItemData* parent) const; + QHash<QByteArray, QVariant> retrieveData(const KFileItem &item, const ItemData *parent) const; /** * @return True if role values benefit from natural or case insensitive sorting. @@ -376,35 +410,35 @@ private: * @return True if \a a has a KFileItem whose text is 'less than' the one * of \a b according to QString::operator<(const QString&). */ - static bool nameLessThan(const ItemData* a, const ItemData* b); + static bool nameLessThan(const ItemData *a, const ItemData *b); /** * @return True if the item-data \a a should be ordered before the item-data * \b. The item-data may have different parent-items. */ - bool lessThan(const ItemData* a, const ItemData* b, const QCollator& collator) const; + bool lessThan(const ItemData *a, const ItemData *b, const QCollator &collator) const; /** * Sorts the items between \a begin and \a end using the comparison * function lessThan(). */ - void sort(const QList<ItemData*>::iterator &begin, const QList<ItemData*>::iterator &end) const; + void sort(const QList<ItemData *>::iterator &begin, const QList<ItemData *>::iterator &end) const; /** * Helper method for lessThan() and expandedParentsCountCompare(): Compares * the passed item-data using m_sortRole as criteria. Both items must * have the same parent item, otherwise the comparison will be wrong. */ - int sortRoleCompare(const ItemData* a, const ItemData* b, const QCollator& collator) const; + int sortRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const; - int stringCompare(const QString& a, const QString& b, const QCollator& collator) const; + int stringCompare(const QString &a, const QString &b, const QCollator &collator) const; - QList<QPair<int, QVariant> > nameRoleGroups() const; - QList<QPair<int, QVariant> > sizeRoleGroups() const; - QList<QPair<int, QVariant> > timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const; - QList<QPair<int, QVariant> > permissionRoleGroups() const; - QList<QPair<int, QVariant> > ratingRoleGroups() const; - QList<QPair<int, QVariant> > genericStringRoleGroups(const QByteArray& typeForRole) const; + QList<QPair<int, QVariant>> nameRoleGroups() const; + QList<QPair<int, QVariant>> sizeRoleGroups() const; + QList<QPair<int, QVariant>> timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const; + QList<QPair<int, QVariant>> permissionRoleGroups() const; + QList<QPair<int, QVariant>> ratingRoleGroups() const; + QList<QPair<int, QVariant>> genericStringRoleGroups(const QByteArray &typeForRole) const; /** * Helper method for all xxxRoleGroups() methods to check whether the @@ -431,7 +465,7 @@ private: * Removes filtered items whose expanded parents have been deleted * or collapsed via setExpanded(parentIndex, false). */ - void removeFilteredChildren(const KItemRangeList& parents); + void removeFilteredChildren(const KItemRangeList &parents); /** * Loads the selected choice of sorting method from Dolphin General Settings @@ -442,9 +476,8 @@ private: * Maps the QByteArray-roles to RoleTypes and provides translation- and * group-contexts. */ - struct RoleInfoMap - { - const char* const role; + struct RoleInfoMap { + const char *const role; const RoleType roleType; const KLazyLocalizedString roleTranslation; const KLazyLocalizedString groupTranslation; @@ -455,19 +488,19 @@ private: /** * @return Map of user visible roles that are accessible by KFileItemModel::rolesInformation(). */ - static const RoleInfoMap* rolesInfoMap(int& count); + static const RoleInfoMap *rolesInfoMap(int &count); /** * Determines the MIME-types of all items that can be done within * the given timeout. */ - static void determineMimeTypes(const KFileItemList& items, int timeout); + static void determineMimeTypes(const KFileItemList &items, int timeout); /** * @return Returns a copy of \a value that is implicitly shared * with other users to save memory. */ - static QByteArray sharedValue(const QByteArray& value); + static QByteArray sharedValue(const QByteArray &value); /** * Checks if the model's internal data structures are consistent. @@ -495,7 +528,7 @@ private: int m_sortingProgressPercent; // Value of directorySortingProgress() signal QSet<QByteArray> m_roles; - QList<ItemData*> m_itemData; + QList<ItemData *> m_itemData; // m_items is a cache for the method index(const QUrl&). If it contains N // entries, it is guaranteed that these correspond to the first N items in @@ -504,16 +537,16 @@ private: mutable QHash<QUrl, int> m_items; KFileItemModelFilter m_filter; - QHash<KFileItem, ItemData*> m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter() + QHash<KFileItem, ItemData *> m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter() bool m_requestRole[RolesCount]; - QTimer* m_maximumUpdateIntervalTimer; - QTimer* m_resortAllItemsTimer; - QList<ItemData*> m_pendingItemsToInsert; + QTimer *m_maximumUpdateIntervalTimer; + QTimer *m_resortAllItemsTimer; + QList<ItemData *> m_pendingItemsToInsert; // Cache for KFileItemModel::groups() - mutable QList<QPair<int, QVariant> > m_groups; + mutable QList<QPair<int, QVariant>> m_groups; // Stores the URLs (key: target url, value: url) of the expanded directories. QHash<QUrl, QUrl> m_expandedDirs; @@ -522,31 +555,21 @@ private: // and done step after step in slotCompleted(). QSet<QUrl> m_urlsToExpand; - friend class KFileItemModelRolesUpdater; // Accesses emitSortProgress() method - friend class KFileItemModelTest; // For unit testing - friend class KFileItemModelBenchmark; // For unit testing - friend class KFileItemListViewTest; // For unit testing - friend class DolphinPart; // Accesses m_dirLister + friend class KFileItemModelRolesUpdater; // Accesses emitSortProgress() method + friend class KFileItemModelTest; // For unit testing + friend class KFileItemModelBenchmark; // For unit testing + friend class KFileItemListViewTest; // For unit testing + friend class DolphinPart; // Accesses m_dirLister }; inline bool KFileItemModel::isRoleValueNatural(RoleType roleType) { - return (roleType == TypeRole || - roleType == ExtensionRole || - roleType == TagsRole || - roleType == CommentRole || - roleType == TitleRole || - roleType == ArtistRole || - roleType == GenreRole || - roleType == AlbumRole || - roleType == PathRole || - roleType == DestinationRole || - roleType == OriginUrlRole || - roleType == OwnerRole || - roleType == GroupRole); + return (roleType == TypeRole || roleType == ExtensionRole || roleType == TagsRole || roleType == CommentRole || roleType == TitleRole + || roleType == ArtistRole || roleType == GenreRole || roleType == AlbumRole || roleType == PathRole || roleType == DestinationRole + || roleType == OriginUrlRole || roleType == OwnerRole || roleType == GroupRole); } -inline bool KFileItemModel::nameLessThan(const ItemData* a, const ItemData* b) +inline bool KFileItemModel::nameLessThan(const ItemData *a, const ItemData *b) { return a->item.text() < b->item.text(); } @@ -561,5 +584,3 @@ inline bool KFileItemModel::isChildItem(int index) const } #endif - - diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 568f43a4b..cf660cb9f 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -38,55 +38,56 @@ using namespace std::chrono_literals; // #define KFILEITEMMODELROLESUPDATER_DEBUG -namespace { - // Maximum time in ms that the KFileItemModelRolesUpdater - // may perform a blocking operation - const int MaxBlockTimeout = 200; +namespace +{ +// Maximum time in ms that the KFileItemModelRolesUpdater +// may perform a blocking operation +const int MaxBlockTimeout = 200; - // If the number of items is smaller than ResolveAllItemsLimit, - // the roles of all items will be resolved. - const int ResolveAllItemsLimit = 500; +// If the number of items is smaller than ResolveAllItemsLimit, +// the roles of all items will be resolved. +const int ResolveAllItemsLimit = 500; - // Not only the visible area, but up to ReadAheadPages before and after - // this area will be resolved. - const int ReadAheadPages = 5; +// Not only the visible area, but up to ReadAheadPages before and after +// this area will be resolved. +const int ReadAheadPages = 5; } -KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QObject* parent) : - QObject(parent), - m_state(Idle), - m_previewChangedDuringPausing(false), - m_iconSizeChangedDuringPausing(false), - m_rolesChangedDuringPausing(false), - m_previewShown(false), - m_enlargeSmallPreviews(true), - m_clearPreviews(false), - m_finishedItems(), - m_model(model), - m_iconSize(), - m_firstVisibleIndex(0), - m_lastVisibleIndex(-1), - m_maximumVisibleItems(50), - m_roles(), - m_resolvableRoles(), - m_enabledPlugins(), - m_localFileSizePreviewLimit(0), - m_scanDirectories(true), - m_pendingSortRoleItems(), - m_pendingIndexes(), - m_pendingPreviewItems(), - m_previewJob(), - m_hoverSequenceItem(), - m_hoverSequenceIndex(0), - m_hoverSequencePreviewJob(nullptr), - m_hoverSequenceNumSuccessiveFailures(0), - m_recentlyChangedItemsTimer(nullptr), - m_recentlyChangedItems(), - m_changedItems(), - m_directoryContentsCounter(nullptr) - #if HAVE_BALOO - , m_balooFileMonitor(nullptr) - #endif +KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel *model, QObject *parent) + : QObject(parent) + , m_state(Idle) + , m_previewChangedDuringPausing(false) + , m_iconSizeChangedDuringPausing(false) + , m_rolesChangedDuringPausing(false) + , m_previewShown(false) + , m_enlargeSmallPreviews(true) + , m_clearPreviews(false) + , m_finishedItems() + , m_model(model) + , m_iconSize() + , m_firstVisibleIndex(0) + , m_lastVisibleIndex(-1) + , m_maximumVisibleItems(50) + , m_roles() + , m_resolvableRoles() + , m_enabledPlugins() + , m_localFileSizePreviewLimit(0) + , m_scanDirectories(true) + , m_pendingSortRoleItems() + , m_pendingIndexes() + , m_pendingPreviewItems() + , m_previewJob() + , m_hoverSequenceItem() + , m_hoverSequenceIndex(0) + , m_hoverSequencePreviewJob(nullptr) + , m_hoverSequenceNumSuccessiveFailures(0) + , m_recentlyChangedItemsTimer(nullptr) + , m_recentlyChangedItems() + , m_changedItems() + , m_directoryContentsCounter(nullptr) +#if HAVE_BALOO + , m_balooFileMonitor(nullptr) +#endif { Q_ASSERT(model); @@ -94,16 +95,11 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO m_enabledPlugins = globalConfig.readEntry("Plugins", KIO::PreviewJob::defaultPlugins()); m_localFileSizePreviewLimit = static_cast<qulonglong>(globalConfig.readEntry("MaximumSize", 0)); - connect(m_model, &KFileItemModel::itemsInserted, - this, &KFileItemModelRolesUpdater::slotItemsInserted); - connect(m_model, &KFileItemModel::itemsRemoved, - this, &KFileItemModelRolesUpdater::slotItemsRemoved); - connect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); - connect(m_model, &KFileItemModel::itemsMoved, - this, &KFileItemModelRolesUpdater::slotItemsMoved); - connect(m_model, &KFileItemModel::sortRoleChanged, - this, &KFileItemModelRolesUpdater::slotSortRoleChanged); + connect(m_model, &KFileItemModel::itemsInserted, this, &KFileItemModelRolesUpdater::slotItemsInserted); + connect(m_model, &KFileItemModel::itemsRemoved, this, &KFileItemModelRolesUpdater::slotItemsRemoved); + connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); + connect(m_model, &KFileItemModel::itemsMoved, this, &KFileItemModelRolesUpdater::slotItemsMoved); + connect(m_model, &KFileItemModel::sortRoleChanged, this, &KFileItemModelRolesUpdater::slotSortRoleChanged); // Use a timer to prevent that each call of slotItemsChanged() results in a synchronous // resolving of the roles. Postpone the resolving until no update has been done for 100 ms. @@ -120,8 +116,7 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO #endif m_directoryContentsCounter = new KDirectoryContentsCounter(m_model, this); - connect(m_directoryContentsCounter, &KDirectoryContentsCounter::result, - this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived); + connect(m_directoryContentsCounter, &KDirectoryContentsCounter::result, this, &KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived); const auto plugins = KPluginMetaData::findPlugins(QStringLiteral("kf" QT_STRINGIFY(QT_VERSION_MAJOR)) + QStringLiteral("/overlayicon")); for (const KPluginMetaData &data : plugins) { @@ -142,7 +137,7 @@ KFileItemModelRolesUpdater::~KFileItemModelRolesUpdater() killPreviewJob(); } -void KFileItemModelRolesUpdater::setIconSize(const QSize& size) +void KFileItemModelRolesUpdater::setIconSize(const QSize &size) { if (size != m_iconSize) { m_iconSize = size; @@ -221,7 +216,7 @@ bool KFileItemModelRolesUpdater::enlargeSmallPreviews() const return m_enlargeSmallPreviews; } -void KFileItemModelRolesUpdater::setEnabledPlugins(const QStringList& list) +void KFileItemModelRolesUpdater::setEnabledPlugins(const QStringList &list) { if (m_enabledPlugins != list) { m_enabledPlugins = list; @@ -241,8 +236,7 @@ void KFileItemModelRolesUpdater::setPaused(bool paused) m_state = Paused; killPreviewJob(); } else { - const bool updatePreviews = (m_iconSizeChangedDuringPausing && m_previewShown) || - m_previewChangedDuringPausing; + const bool updatePreviews = (m_iconSizeChangedDuringPausing && m_previewShown) || m_previewChangedDuringPausing; const bool resolveAll = updatePreviews || m_rolesChangedDuringPausing; if (resolveAll) { m_finishedItems.clear(); @@ -263,7 +257,7 @@ void KFileItemModelRolesUpdater::setPaused(bool paused) } } -void KFileItemModelRolesUpdater::setRoles(const QSet<QByteArray>& roles) +void KFileItemModelRolesUpdater::setRoles(const QSet<QByteArray> &roles) { if (m_roles != roles) { m_roles = roles; @@ -273,11 +267,11 @@ void KFileItemModelRolesUpdater::setRoles(const QSet<QByteArray>& roles) // with the help of Baloo. If this is the case, a (quite expensive) // resolving will be done in KFileItemModelRolesUpdater::rolesData() and // the role gets watched for changes. - const KBalooRolesProvider& rolesProvider = KBalooRolesProvider::instance(); + const KBalooRolesProvider &rolesProvider = KBalooRolesProvider::instance(); bool hasBalooRole = false; QSetIterator<QByteArray> it(roles); while (it.hasNext()) { - const QByteArray& role = it.next(); + const QByteArray &role = it.next(); if (rolesProvider.roles().contains(role)) { hasBalooRole = true; break; @@ -286,8 +280,7 @@ void KFileItemModelRolesUpdater::setRoles(const QSet<QByteArray>& roles) if (hasBalooRole && m_balooConfig.fileIndexingEnabled() && !m_balooFileMonitor) { m_balooFileMonitor = new Baloo::FileMonitor(this); - connect(m_balooFileMonitor, &Baloo::FileMonitor::fileMetaDataChanged, - this, &KFileItemModelRolesUpdater::applyChangedBalooRoles); + connect(m_balooFileMonitor, &Baloo::FileMonitor::fileMetaDataChanged, this, &KFileItemModelRolesUpdater::applyChangedBalooRoles); } else if (!hasBalooRole && m_balooFileMonitor) { delete m_balooFileMonitor; m_balooFileMonitor = nullptr; @@ -337,7 +330,7 @@ bool KFileItemModelRolesUpdater::scanDirectories() const return m_scanDirectories; } -void KFileItemModelRolesUpdater::setHoverSequenceState(const QUrl& itemUrl, int seqIdx) +void KFileItemModelRolesUpdater::setHoverSequenceState(const QUrl &itemUrl, int seqIdx) { const KFileItem item = m_model->fileItem(itemUrl); @@ -357,7 +350,7 @@ void KFileItemModelRolesUpdater::setHoverSequenceState(const QUrl& itemUrl, int loadNextHoverSequencePreview(); } -void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRanges) +void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList &itemRanges) { QElapsedTimer timer; timer.start(); @@ -365,7 +358,7 @@ void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRan // Determine the sort role synchronously for as many items as possible. if (m_resolvableRoles.contains(m_model->sortRole())) { int insertedCount = 0; - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { const int lastIndex = insertedCount + range.index + range.count - 1; for (int i = insertedCount + range.index; i <= lastIndex; ++i) { if (timer.elapsed() < MaxBlockTimeout) { @@ -392,7 +385,7 @@ void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRan startUpdating(); } -void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRanges) +void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList &itemRanges) { Q_UNUSED(itemRanges) @@ -406,7 +399,7 @@ void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRang } else { QStringList newFileList; const QStringList oldFileList = m_balooFileMonitor->files(); - for (const QString& file : oldFileList) { + for (const QString &file : oldFileList) { if (m_model->index(QUrl::fromLocalFile(file)) >= 0) { newFileList.append(file); } @@ -442,7 +435,7 @@ void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRang } // Removed items won't have hover previews loaded anymore. - for (const KItemRange& itemRange : itemRanges) { + for (const KItemRange &itemRange : itemRanges) { int index = itemRange.index; for (int count = itemRange.count; count > 0; --count) { const KFileItem item = m_model->fileItem(index); @@ -465,8 +458,7 @@ void KFileItemModelRolesUpdater::slotItemsMoved(KItemRange itemRange, const QLis startUpdating(); } -void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList& itemRanges, - const QSet<QByteArray>& roles) +void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList &itemRanges, const QSet<QByteArray> &roles) { Q_UNUSED(roles) @@ -475,9 +467,9 @@ void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList& itemRang // to prevent expensive repeated updates if files are updated frequently. const bool itemsChangedRecently = m_recentlyChangedItemsTimer->isActive(); - QSet<KFileItem>& targetSet = itemsChangedRecently ? m_recentlyChangedItems : m_changedItems; + QSet<KFileItem> &targetSet = itemsChangedRecently ? m_recentlyChangedItems : m_changedItems; - for (const KItemRange& itemRange : itemRanges) { + for (const KItemRange &itemRange : itemRanges) { int index = itemRange.index; for (int count = itemRange.count; count > 0; --count) { const KFileItem item = m_model->fileItem(index); @@ -493,8 +485,7 @@ void KFileItemModelRolesUpdater::slotItemsChanged(const KItemRangeList& itemRang } } -void KFileItemModelRolesUpdater::slotSortRoleChanged(const QByteArray& current, - const QByteArray& previous) +void KFileItemModelRolesUpdater::slotSortRoleChanged(const QByteArray ¤t, const QByteArray &previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -531,7 +522,7 @@ void KFileItemModelRolesUpdater::slotSortRoleChanged(const QByteArray& current, } } -void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPixmap& pixmap) +void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem &item, const QPixmap &pixmap) { if (m_state != PreviewJobRunning) { return; @@ -555,7 +546,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi // assumes that an overlay will be drawn and has some additional // setup time. if (!scaledPixmap.isNull()) { - for (const QString& overlay : overlays) { + for (const QString &overlay : overlays) { if (!overlay.isEmpty()) { // There is at least one overlay, draw all overlays above m_pixmap // and cancel the check @@ -567,16 +558,14 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi data.insert("iconPixmap", scaledPixmap); - disconnect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); m_model->setData(index, data); - connect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); m_finishedItems.insert(item); } -void KFileItemModelRolesUpdater::slotPreviewFailed(const KFileItem& item) +void KFileItemModelRolesUpdater::slotPreviewFailed(const KFileItem &item) { if (m_state != PreviewJobRunning) { return; @@ -589,11 +578,9 @@ void KFileItemModelRolesUpdater::slotPreviewFailed(const KFileItem& item) QHash<QByteArray, QVariant> data; data.insert("iconPixmap", QPixmap()); - disconnect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); m_model->setData(index, data); - connect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); applyResolvedRoles(index, ResolveAll); m_finishedItems.insert(item); @@ -619,7 +606,7 @@ void KFileItemModelRolesUpdater::slotPreviewJobFinished() } } -void KFileItemModelRolesUpdater::slotHoverSequenceGotPreview(const KFileItem& item, const QPixmap& pixmap) +void KFileItemModelRolesUpdater::slotHoverSequenceGotPreview(const KFileItem &item, const QPixmap &pixmap) { const int index = m_model->index(item); if (index < 0) { @@ -653,8 +640,7 @@ void KFileItemModelRolesUpdater::slotHoverSequenceGotPreview(const KFileItem& it m_model->setData(index, data); - const auto loadedIt = std::find(m_hoverSequenceLoadedItems.begin(), - m_hoverSequenceLoadedItems.end(), item); + const auto loadedIt = std::find(m_hoverSequenceLoadedItems.begin(), m_hoverSequenceLoadedItems.end(), item); if (loadedIt == m_hoverSequenceLoadedItems.end()) { m_hoverSequenceLoadedItems.push_back(item); trimHoverSequenceLoadedItems(); @@ -664,7 +650,7 @@ void KFileItemModelRolesUpdater::slotHoverSequenceGotPreview(const KFileItem& it m_hoverSequenceNumSuccessiveFailures = 0; } -void KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed(const KFileItem& item) +void KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed(const KFileItem &item) { const int index = m_model->index(item); if (index < 0) { @@ -676,11 +662,8 @@ void KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed(const KFileItem& QHash<QByteArray, QVariant> data = m_model->data(index); QVector<QPixmap> pixmaps = data["hoverSequencePixmaps"].value<QVector<QPixmap>>(); - qCDebug(DolphinDebug).nospace() - << "Failed to generate hover sequence preview #" << pixmaps.size() - << " for file " << item.url().toString() - << " (attempt " << (m_hoverSequenceNumSuccessiveFailures+1) - << "/" << (numRetries+1) << ")"; + qCDebug(DolphinDebug).nospace() << "Failed to generate hover sequence preview #" << pixmaps.size() << " for file " << item.url().toString() << " (attempt " + << (m_hoverSequenceNumSuccessiveFailures + 1) << "/" << (numRetries + 1) << ")"; if (m_hoverSequenceNumSuccessiveFailures >= numRetries) { // Give up and simply duplicate the previous sequence image (if any) @@ -755,11 +738,9 @@ void KFileItemModelRolesUpdater::resolveNextSortRole() m_state = Idle; // Prevent that we try to update the items twice. - disconnect(m_model, &KFileItemModel::itemsMoved, - this, &KFileItemModelRolesUpdater::slotItemsMoved); + disconnect(m_model, &KFileItemModel::itemsMoved, this, &KFileItemModelRolesUpdater::slotItemsMoved); applySortProgressToModel(); - connect(m_model, &KFileItemModel::itemsMoved, - this, &KFileItemModelRolesUpdater::slotItemsMoved); + connect(m_model, &KFileItemModel::itemsMoved, this, &KFileItemModelRolesUpdater::slotItemsMoved); startUpdating(); } } @@ -796,18 +777,13 @@ void KFileItemModelRolesUpdater::resolveNextPendingRoles() data.insert("iconPixmap", QPixmap()); data.insert("hoverSequencePixmaps", QVariant::fromValue(QVector<QPixmap>())); - disconnect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); for (int index = 0; index <= m_model->count(); ++index) { - if (m_model->data(index).contains("iconPixmap") || - m_model->data(index).contains("hoverSequencePixmaps")) - { + if (m_model->data(index).contains("iconPixmap") || m_model->data(index).contains("hoverSequencePixmaps")) { m_model->setData(index, data); } } - connect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); - + connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); } m_clearPreviews = false; } @@ -825,7 +801,7 @@ void KFileItemModelRolesUpdater::resolveRecentlyChangedItems() updateChangedItems(); } -void KFileItemModelRolesUpdater::applyChangedBalooRoles(const QString& file) +void KFileItemModelRolesUpdater::applyChangedBalooRoles(const QString &file) { #if HAVE_BALOO const KFileItem item = m_model->fileItem(QUrl::fromLocalFile(file)); @@ -847,11 +823,11 @@ void KFileItemModelRolesUpdater::applyChangedBalooRolesForItem(const KFileItem & Baloo::File file(item.localPath()); file.load(); - const KBalooRolesProvider& rolesProvider = KBalooRolesProvider::instance(); + const KBalooRolesProvider &rolesProvider = KBalooRolesProvider::instance(); QHash<QByteArray, QVariant> data; const auto roles = rolesProvider.roles(); - for (const QByteArray& role : roles) { + for (const QByteArray &role : roles) { // Overwrite all the role values with an empty QVariant, because the roles // provider doesn't overwrite it when the property value list is empty. // See bug 322348 @@ -864,12 +840,10 @@ void KFileItemModelRolesUpdater::applyChangedBalooRolesForItem(const KFileItem & data.insert(it.key(), it.value()); } - disconnect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); const int index = m_model->index(item); m_model->setData(index, data); - connect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); #else #ifndef Q_CC_MSVC Q_UNUSED(item) @@ -877,7 +851,7 @@ void KFileItemModelRolesUpdater::applyChangedBalooRolesForItem(const KFileItem & #endif } -void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QString& path, int count, long size) +void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QString &path, int count, long size) { const bool getSizeRole = m_roles.contains("size"); const bool getIsExpandableRole = m_roles.contains("isExpandable"); @@ -895,11 +869,9 @@ void KFileItemModelRolesUpdater::slotDirectoryContentsCountReceived(const QStrin data.insert("isExpandable", count > 0); } - disconnect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); m_model->setData(index, data); - connect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); } } } @@ -995,8 +967,7 @@ void KFileItemModelRolesUpdater::startPreviewJob() // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must // do a downscaling anyhow because of the frame, so in this case only the provided // cache sizes are requested. - const QSize cacheSize = (m_iconSize.width() > 128) || (m_iconSize.height() > 128) - ? QSize(256, 256) : QSize(128, 128); + const QSize cacheSize = (m_iconSize.width() > 128) || (m_iconSize.height() > 128) ? QSize(256, 256) : QSize(128, 128); // KIO::filePreview() will request the MIME-type of all passed items, which (in the // worst case) might block the application for several seconds. To prevent such @@ -1026,38 +997,32 @@ void KFileItemModelRolesUpdater::startPreviewJob() } while (!m_pendingPreviewItems.isEmpty() && timer.elapsed() < MaxBlockTimeout); } - KIO::PreviewJob* job = new KIO::PreviewJob(itemSubSet, cacheSize, &m_enabledPlugins); + KIO::PreviewJob *job = new KIO::PreviewJob(itemSubSet, cacheSize, &m_enabledPlugins); job->setIgnoreMaximumSize(itemSubSet.first().isLocalFile() && !itemSubSet.first().isSlow() && m_localFileSizePreviewLimit <= 0); if (job->uiDelegate()) { KJobWidgets::setWindow(job, qApp->activeWindow()); } - connect(job, &KIO::PreviewJob::gotPreview, - this, &KFileItemModelRolesUpdater::slotGotPreview); - connect(job, &KIO::PreviewJob::failed, - this, &KFileItemModelRolesUpdater::slotPreviewFailed); - connect(job, &KIO::PreviewJob::finished, - this, &KFileItemModelRolesUpdater::slotPreviewJobFinished); + connect(job, &KIO::PreviewJob::gotPreview, this, &KFileItemModelRolesUpdater::slotGotPreview); + connect(job, &KIO::PreviewJob::failed, this, &KFileItemModelRolesUpdater::slotPreviewFailed); + connect(job, &KIO::PreviewJob::finished, this, &KFileItemModelRolesUpdater::slotPreviewJobFinished); m_previewJob = job; } -QPixmap KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap& pixmap) +QPixmap KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap &pixmap) { QPixmap scaledPixmap = pixmap; - if (!pixmap.hasAlpha() && !pixmap.isNull() - && m_iconSize.width() > KIconLoader::SizeSmallMedium - && m_iconSize.height() > KIconLoader::SizeSmallMedium) { + if (!pixmap.hasAlpha() && !pixmap.isNull() && m_iconSize.width() > KIconLoader::SizeSmallMedium && m_iconSize.height() > KIconLoader::SizeSmallMedium) { if (m_enlargeSmallPreviews) { KPixmapModifier::applyFrame(scaledPixmap, m_iconSize); } else { // Assure that small previews don't get enlarged. Instead they // should be shown centered within the frame. const QSize contentSize = KPixmapModifier::sizeInsideFrame(m_iconSize); - const bool enlargingRequired = scaledPixmap.width() < contentSize.width() && - scaledPixmap.height() < contentSize.height(); + const bool enlargingRequired = scaledPixmap.width() < contentSize.width() && scaledPixmap.height() < contentSize.height(); if (enlargingRequired) { QSize frameSize = scaledPixmap.size() / scaledPixmap.devicePixelRatio(); frameSize.scale(m_iconSize, Qt::KeepAspectRatio); @@ -1068,7 +1033,7 @@ QPixmap KFileItemModelRolesUpdater::transformPreviewPixmap(const QPixmap& pixmap KPixmapModifier::applyFrame(largeFrame, frameSize); QPainter painter(&largeFrame); - painter.drawPixmap((largeFrame.width() - scaledPixmap.width() / scaledPixmap.devicePixelRatio()) / 2, + painter.drawPixmap((largeFrame.width() - scaledPixmap.width() / scaledPixmap.devicePixelRatio()) / 2, (largeFrame.height() - scaledPixmap.height() / scaledPixmap.devicePixelRatio()) / 2, scaledPixmap); scaledPixmap = largeFrame; @@ -1098,7 +1063,7 @@ void KFileItemModelRolesUpdater::loadNextHoverSequencePreview() } // We generate the next few sequence indices in advance (buffering) - const int maxSeqIdx = m_hoverSequenceIndex+5; + const int maxSeqIdx = m_hoverSequenceIndex + 5; QHash<QByteArray, QVariant> data = m_model->data(index); @@ -1131,10 +1096,9 @@ void KFileItemModelRolesUpdater::loadNextHoverSequencePreview() // by PreviewJob if a smaller size is requested. For images KFileItemModelRolesUpdater must // do a downscaling anyhow because of the frame, so in this case only the provided // cache sizes are requested. - const QSize cacheSize = (m_iconSize.width() > 128) || (m_iconSize.height() > 128) - ? QSize(256, 256) : QSize(128, 128); + const QSize cacheSize = (m_iconSize.width() > 128) || (m_iconSize.height() > 128) ? QSize(256, 256) : QSize(128, 128); - KIO::PreviewJob* job = new KIO::PreviewJob({m_hoverSequenceItem}, cacheSize, &m_enabledPlugins); + KIO::PreviewJob *job = new KIO::PreviewJob({m_hoverSequenceItem}, cacheSize, &m_enabledPlugins); job->setSequenceIndex(loadSeqIdx); job->setIgnoreMaximumSize(m_hoverSequenceItem.isLocalFile() && !m_hoverSequenceItem.isSlow() && m_localFileSizePreviewLimit <= 0); @@ -1142,12 +1106,9 @@ void KFileItemModelRolesUpdater::loadNextHoverSequencePreview() KJobWidgets::setWindow(job, qApp->activeWindow()); } - connect(job, &KIO::PreviewJob::gotPreview, - this, &KFileItemModelRolesUpdater::slotHoverSequenceGotPreview); - connect(job, &KIO::PreviewJob::failed, - this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed); - connect(job, &KIO::PreviewJob::finished, - this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished); + connect(job, &KIO::PreviewJob::gotPreview, this, &KFileItemModelRolesUpdater::slotHoverSequenceGotPreview); + connect(job, &KIO::PreviewJob::failed, this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed); + connect(job, &KIO::PreviewJob::finished, this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished); m_hoverSequencePreviewJob = job; } @@ -1155,12 +1116,9 @@ void KFileItemModelRolesUpdater::loadNextHoverSequencePreview() void KFileItemModelRolesUpdater::killHoverSequencePreviewJob() { if (m_hoverSequencePreviewJob) { - disconnect(m_hoverSequencePreviewJob, &KIO::PreviewJob::gotPreview, - this, &KFileItemModelRolesUpdater::slotHoverSequenceGotPreview); - disconnect(m_hoverSequencePreviewJob, &KIO::PreviewJob::failed, - this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed); - disconnect(m_hoverSequencePreviewJob, &KIO::PreviewJob::finished, - this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished); + disconnect(m_hoverSequencePreviewJob, &KIO::PreviewJob::gotPreview, this, &KFileItemModelRolesUpdater::slotHoverSequenceGotPreview); + disconnect(m_hoverSequencePreviewJob, &KIO::PreviewJob::failed, this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewFailed); + disconnect(m_hoverSequencePreviewJob, &KIO::PreviewJob::finished, this, &KFileItemModelRolesUpdater::slotHoverSequencePreviewJobFinished); m_hoverSequencePreviewJob->kill(); m_hoverSequencePreviewJob = nullptr; } @@ -1199,7 +1157,7 @@ void KFileItemModelRolesUpdater::updateChangedItems() auto changedItemsIt = m_changedItems.begin(); while (changedItemsIt != m_changedItems.end()) { - const auto& item = *changedItemsIt; + const auto &item = *changedItemsIt; const int index = m_model->index(item); if (index < 0) { @@ -1261,11 +1219,9 @@ void KFileItemModelRolesUpdater::applySortRole(int index) data = rolesData(item); } - disconnect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); m_model->setData(index, data); - connect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); } void KFileItemModelRolesUpdater::applySortProgressToModel() @@ -1308,18 +1264,16 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint) data.insert("hoverSequencePixmaps", QVariant::fromValue(QVector<QPixmap>())); } - disconnect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); m_model->setData(index, data); - connect(m_model, &KFileItemModel::itemsChanged, - this, &KFileItemModelRolesUpdater::slotItemsChanged); + connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); return true; } return false; } -QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileItem& item) +QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileItem &item) { QHash<QByteArray, QVariant> data; @@ -1364,14 +1318,14 @@ QHash<QByteArray, QVariant> KFileItemModelRolesUpdater::rolesData(const KFileIte return data; } -void KFileItemModelRolesUpdater::slotOverlaysChanged(const QUrl& url, const QStringList &) +void KFileItemModelRolesUpdater::slotOverlaysChanged(const QUrl &url, const QStringList &) { const KFileItem item = m_model->fileItem(url); if (item.isNull()) { return; } const int index = m_model->index(item); - QHash<QByteArray, QVariant> data = m_model->data(index); + QHash<QByteArray, QVariant> data = m_model->data(index); QStringList overlays = item.overlays(); for (KOverlayIconPlugin *it : qAsConst(m_overlayIconsPlugin)) { overlays.append(it->getOverlays(url)); @@ -1393,12 +1347,9 @@ void KFileItemModelRolesUpdater::updateAllPreviews() void KFileItemModelRolesUpdater::killPreviewJob() { if (m_previewJob) { - disconnect(m_previewJob, &KIO::PreviewJob::gotPreview, - this, &KFileItemModelRolesUpdater::slotGotPreview); - disconnect(m_previewJob, &KIO::PreviewJob::failed, - this, &KFileItemModelRolesUpdater::slotPreviewFailed); - disconnect(m_previewJob, &KIO::PreviewJob::finished, - this, &KFileItemModelRolesUpdater::slotPreviewJobFinished); + disconnect(m_previewJob, &KIO::PreviewJob::gotPreview, this, &KFileItemModelRolesUpdater::slotGotPreview); + disconnect(m_previewJob, &KIO::PreviewJob::failed, this, &KFileItemModelRolesUpdater::slotPreviewFailed); + disconnect(m_previewJob, &KIO::PreviewJob::finished, this, &KFileItemModelRolesUpdater::slotPreviewJobFinished); m_previewJob->kill(); m_previewJob = nullptr; m_pendingPreviewItems.clear(); @@ -1410,9 +1361,7 @@ QList<int> KFileItemModelRolesUpdater::indexesToResolve() const const int count = m_model->count(); QList<int> result; - result.reserve(qMin(count, (m_lastVisibleIndex - m_firstVisibleIndex + 1) + - ResolveAllItemsLimit + - (2 * m_maximumVisibleItems))); + result.reserve(qMin(count, (m_lastVisibleIndex - m_firstVisibleIndex + 1) + ResolveAllItemsLimit + (2 * m_maximumVisibleItems))); // Add visible items. // Resolve files first, their previews are quicker. @@ -1492,4 +1441,3 @@ void KFileItemModelRolesUpdater::trimHoverSequenceLoadedItems() } } } - diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h index b0177b9f8..90f29c5c0 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.h +++ b/src/kitemviews/kfileitemmodelrolesupdater.h @@ -12,8 +12,8 @@ #include <list> -#include <KFileItem> #include "config-dolphin.h" +#include <KFileItem> #include <QObject> #include <QSet> @@ -26,16 +26,17 @@ class QPixmap; class QTimer; class KOverlayIconPlugin; -namespace KIO { - class PreviewJob; +namespace KIO +{ +class PreviewJob; } #if HAVE_BALOO - namespace Baloo - { - class FileMonitor; - } - #include <Baloo/IndexerConfig> +namespace Baloo +{ +class FileMonitor; +} +#include <Baloo/IndexerConfig> #endif /** @@ -82,10 +83,10 @@ class DOLPHIN_EXPORT KFileItemModelRolesUpdater : public QObject Q_OBJECT public: - explicit KFileItemModelRolesUpdater(KFileItemModel* model, QObject* parent = nullptr); + explicit KFileItemModelRolesUpdater(KFileItemModel *model, QObject *parent = nullptr); ~KFileItemModelRolesUpdater() override; - void setIconSize(const QSize& size); + void setIconSize(const QSize &size); QSize iconSize() const; /** @@ -123,7 +124,7 @@ public: /** * Sets the roles that should be resolved asynchronously. */ - void setRoles(const QSet<QByteArray>& roles); + void setRoles(const QSet<QByteArray> &roles); QSet<QByteArray> roles() const; /** @@ -135,7 +136,7 @@ public: * * @see enabledPlugins */ - void setEnabledPlugins(const QStringList& list); + void setEnabledPlugins(const QStringList &list); /** * Returns the list of enabled thumbnail plugins. @@ -172,16 +173,14 @@ public: * this method will be called repeatedly with increasing values * for this parameter. */ - void setHoverSequenceState(const QUrl& itemUrl, int seqIdx); + void setHoverSequenceState(const QUrl &itemUrl, int seqIdx); private Q_SLOTS: - void slotItemsInserted(const KItemRangeList& itemRanges); - void slotItemsRemoved(const KItemRangeList& itemRanges); + void slotItemsInserted(const KItemRangeList &itemRanges); + void slotItemsRemoved(const KItemRangeList &itemRanges); void slotItemsMoved(KItemRange itemRange, const QList<int> &movedToIndexes); - void slotItemsChanged(const KItemRangeList& itemRanges, - const QSet<QByteArray>& roles); - void slotSortRoleChanged(const QByteArray& current, - const QByteArray& previous); + void slotItemsChanged(const KItemRangeList &itemRanges, const QSet<QByteArray> &roles); + void slotSortRoleChanged(const QByteArray ¤t, const QByteArray &previous); /** * Is invoked after a preview has been received successfully. @@ -190,7 +189,7 @@ private Q_SLOTS: * * @see startPreviewJob() */ - void slotGotPreview(const KFileItem& item, const QPixmap& pixmap); + void slotGotPreview(const KFileItem &item, const QPixmap &pixmap); /** * Is invoked after generating a preview has failed. @@ -199,7 +198,7 @@ private Q_SLOTS: * * @see startPreviewJob() */ - void slotPreviewFailed(const KFileItem& item); + void slotPreviewFailed(const KFileItem &item); /** * Is invoked when the preview job has been finished. Starts a new preview @@ -215,12 +214,12 @@ private Q_SLOTS: /** * Is invoked after a hover sequence preview has been received successfully. */ - void slotHoverSequenceGotPreview(const KFileItem& item, const QPixmap& pixmap); + void slotHoverSequenceGotPreview(const KFileItem &item, const QPixmap &pixmap); /** * Is invoked after generating a hover sequence preview has failed. */ - void slotHoverSequencePreviewFailed(const KFileItem& item); + void slotHoverSequencePreviewFailed(const KFileItem &item); /** * Is invoked when a hover sequence preview job is finished. May start another @@ -235,7 +234,7 @@ private Q_SLOTS: /** * Is invoked when one of the KOverlayIconPlugin emit the signal that an overlay has changed */ - void slotOverlaysChanged(const QUrl& url, const QStringList&); + void slotOverlaysChanged(const QUrl &url, const QStringList &); /** * Resolves the sort role of the next item in m_pendingSortRole, applies it @@ -258,10 +257,10 @@ private Q_SLOTS: */ void resolveRecentlyChangedItems(); - void applyChangedBalooRoles(const QString& file); - void applyChangedBalooRolesForItem(const KFileItem& file); + void applyChangedBalooRoles(const QString &file); + void applyChangedBalooRolesForItem(const KFileItem &file); - void slotDirectoryContentsCountReceived(const QString& path, int count, long size); + void slotDirectoryContentsCountReceived(const QString &path, int count, long size); private: /** @@ -293,7 +292,7 @@ private: * @param pixmap A raw preview image from a PreviewJob. * @return The scaled and decorated preview image. */ - QPixmap transformPreviewPixmap(const QPixmap& pixmap); + QPixmap transformPreviewPixmap(const QPixmap &pixmap); /** * Starts a PreviewJob for loading the next hover sequence image. @@ -318,12 +317,9 @@ private: void applySortProgressToModel(); - enum ResolveHint { - ResolveFast, - ResolveAll - }; + enum ResolveHint { ResolveFast, ResolveAll }; bool applyResolvedRoles(int index, ResolveHint hint); - QHash<QByteArray, QVariant> rolesData(const KFileItem& item); + QHash<QByteArray, QVariant> rolesData(const KFileItem &item); /** * Must be invoked if a property has been changed that affects @@ -338,13 +334,7 @@ private: void trimHoverSequenceLoadedItems(); private: - enum State { - Idle, - Paused, - ResolvingSortRole, - ResolvingAllRoles, - PreviewJobRunning - }; + enum State { Idle, Paused, ResolvingSortRole, ResolvingAllRoles, PreviewJobRunning }; State m_state; @@ -369,7 +359,7 @@ private: // previews and other expensive roles are determined again. QSet<KFileItem> m_finishedItems; - KFileItemModel* m_model; + KFileItemModel *m_model; QSize m_iconSize; int m_firstVisibleIndex; int m_lastVisibleIndex; @@ -391,13 +381,13 @@ private: // A new preview job will be started from them once the first one finishes. KFileItemList m_pendingPreviewItems; - KIO::PreviewJob* m_previewJob; + KIO::PreviewJob *m_previewJob; // Info about the item that the user currently hovers, and the current sequence // index for thumb generation. KFileItem m_hoverSequenceItem; int m_hoverSequenceIndex; - KIO::PreviewJob* m_hoverSequencePreviewJob; + KIO::PreviewJob *m_hoverSequencePreviewJob; int m_hoverSequenceNumSuccessiveFailures; std::list<KFileItem> m_hoverSequenceLoadedItems; @@ -406,18 +396,18 @@ private: // a high CPU-load by generating e.g. previews for each notification, the update // will be postponed until no file change has been done within a longer period // of time. - QTimer* m_recentlyChangedItemsTimer; + QTimer *m_recentlyChangedItemsTimer; QSet<KFileItem> m_recentlyChangedItems; // Items which have not been changed repeatedly recently. QSet<KFileItem> m_changedItems; - KDirectoryContentsCounter* m_directoryContentsCounter; + KDirectoryContentsCounter *m_directoryContentsCounter; - QList<KOverlayIconPlugin*> m_overlayIconsPlugin; + QList<KOverlayIconPlugin *> m_overlayIconsPlugin; #if HAVE_BALOO - Baloo::FileMonitor* m_balooFileMonitor; + Baloo::FileMonitor *m_balooFileMonitor; Baloo::IndexerConfig m_balooConfig; #endif }; diff --git a/src/kitemviews/kitemlistcontainer.cpp b/src/kitemviews/kitemlistcontainer.cpp index 10b9f1415..1d62c9620 100644 --- a/src/kitemviews/kitemlistcontainer.cpp +++ b/src/kitemviews/kitemlistcontainer.cpp @@ -30,13 +30,14 @@ class KItemListContainerViewport : public QGraphicsView Q_OBJECT public: - KItemListContainerViewport(QGraphicsScene* scene, QWidget* parent); + KItemListContainerViewport(QGraphicsScene *scene, QWidget *parent); + protected: - void wheelEvent(QWheelEvent* event) override; + void wheelEvent(QWheelEvent *event) override; }; -KItemListContainerViewport::KItemListContainerViewport(QGraphicsScene* scene, QWidget* parent) : - QGraphicsView(scene, parent) +KItemListContainerViewport::KItemListContainerViewport(QGraphicsScene *scene, QWidget *parent) + : QGraphicsView(scene, parent) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -44,24 +45,24 @@ KItemListContainerViewport::KItemListContainerViewport(QGraphicsScene* scene, QW setFrameShape(QFrame::NoFrame); } -void KItemListContainerViewport::wheelEvent(QWheelEvent* event) +void KItemListContainerViewport::wheelEvent(QWheelEvent *event) { // Assure that the wheel-event gets forwarded to the parent // and not handled at all by QGraphicsView. event->ignore(); } -KItemListContainer::KItemListContainer(KItemListController* controller, QWidget* parent) : - QAbstractScrollArea(parent), - m_controller(controller), - m_horizontalSmoothScroller(nullptr), - m_verticalSmoothScroller(nullptr), - m_scroller(nullptr) +KItemListContainer::KItemListContainer(KItemListController *controller, QWidget *parent) + : QAbstractScrollArea(parent) + , m_controller(controller) + , m_horizontalSmoothScroller(nullptr) + , m_verticalSmoothScroller(nullptr) + , m_scroller(nullptr) { Q_ASSERT(controller); controller->setParent(this); - QGraphicsView* graphicsView = new KItemListContainerViewport(new QGraphicsScene(this), this); + QGraphicsView *graphicsView = new KItemListContainerViewport(new QGraphicsScene(this), this); setViewport(graphicsView); m_horizontalSmoothScroller = new KItemListSmoothScroller(horizontalScrollBar(), this); @@ -74,17 +75,13 @@ KItemListContainer::KItemListContainer(KItemListController* controller, QWidget* slotViewChanged(controller->view(), nullptr); } - connect(controller, &KItemListController::modelChanged, - this, &KItemListContainer::slotModelChanged); - connect(controller, &KItemListController::viewChanged, - this, &KItemListContainer::slotViewChanged); + connect(controller, &KItemListController::modelChanged, this, &KItemListContainer::slotModelChanged); + connect(controller, &KItemListController::viewChanged, this, &KItemListContainer::slotViewChanged); m_scroller = QScroller::scroller(viewport()); m_scroller->grabGesture(viewport()); - connect(controller, &KItemListController::scrollerStop, - this, &KItemListContainer::stopScroller); - connect(m_scroller, &QScroller::stateChanged, - controller, &KItemListController::slotStateChanged); + connect(controller, &KItemListController::scrollerStop, this, &KItemListContainer::stopScroller); + connect(m_scroller, &QScroller::stateChanged, controller, &KItemListController::slotStateChanged); } KItemListContainer::~KItemListContainer() @@ -95,14 +92,14 @@ KItemListContainer::~KItemListContainer() m_controller = nullptr; } -KItemListController* KItemListContainer::controller() const +KItemListController *KItemListContainer::controller() const { return m_controller; } void KItemListContainer::setEnabledFrame(bool enable) { - QGraphicsView* graphicsView = qobject_cast<QGraphicsView*>(viewport()); + QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(viewport()); if (enable) { setFrameShape(QFrame::StyledPanel); graphicsView->setPalette(palette()); @@ -113,7 +110,7 @@ void KItemListContainer::setEnabledFrame(bool enable) // to the text color, so that enough contrast is given for all color // schemes QPalette p = graphicsView->palette(); - p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText)); + p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText)); p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText)); p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText)); graphicsView->setPalette(p); @@ -123,11 +120,11 @@ void KItemListContainer::setEnabledFrame(bool enable) bool KItemListContainer::enabledFrame() const { - const QGraphicsView* graphicsView = qobject_cast<QGraphicsView*>(viewport()); + const QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(viewport()); return graphicsView->autoFillBackground(); } -void KItemListContainer::keyPressEvent(QKeyEvent* event) +void KItemListContainer::keyPressEvent(QKeyEvent *event) { // TODO: We should find a better way to handle the key press events in the view. // The reasons why we need this hack are: @@ -135,19 +132,19 @@ void KItemListContainer::keyPressEvent(QKeyEvent* event) // 2. By default, the KItemListView does not have the keyboard focus in the QGraphicsScene, so // simply sending the event to the QGraphicsView which is the KItemListContainer's viewport // does not work. - KItemListView* view = m_controller->view(); + KItemListView *view = m_controller->view(); if (view) { QApplication::sendEvent(view, event); } } -void KItemListContainer::showEvent(QShowEvent* event) +void KItemListContainer::showEvent(QShowEvent *event) { QAbstractScrollArea::showEvent(event); updateGeometries(); } -void KItemListContainer::resizeEvent(QResizeEvent* event) +void KItemListContainer::resizeEvent(QResizeEvent *event) { QAbstractScrollArea::resizeEvent(event); updateGeometries(); @@ -159,23 +156,21 @@ void KItemListContainer::scrollContentsBy(int dx, int dy) m_verticalSmoothScroller->scrollContentsBy(dy); } -void KItemListContainer::wheelEvent(QWheelEvent* event) +void KItemListContainer::wheelEvent(QWheelEvent *event) { if (event->modifiers().testFlag(Qt::ControlModifier)) { event->ignore(); return; } - KItemListView* view = m_controller->view(); + KItemListView *view = m_controller->view(); if (!view) { event->ignore(); return; } - const bool scrollHorizontally = (qAbs(event->angleDelta().y()) < qAbs(event->angleDelta().x())) || - (!verticalScrollBar()->isVisible()); - KItemListSmoothScroller* smoothScroller = scrollHorizontally ? - m_horizontalSmoothScroller : m_verticalSmoothScroller; + const bool scrollHorizontally = (qAbs(event->angleDelta().y()) < qAbs(event->angleDelta().x())) || (!verticalScrollBar()->isVisible()); + KItemListSmoothScroller *smoothScroller = scrollHorizontally ? m_horizontalSmoothScroller : m_verticalSmoothScroller; smoothScroller->handleWheelEvent(event); } @@ -186,27 +181,22 @@ void KItemListContainer::slotScrollOrientationChanged(Qt::Orientation current, Q updateSmoothScrollers(current); } -void KItemListContainer::slotModelChanged(KItemModelBase* current, KItemModelBase* previous) +void KItemListContainer::slotModelChanged(KItemModelBase *current, KItemModelBase *previous) { Q_UNUSED(current) Q_UNUSED(previous) } -void KItemListContainer::slotViewChanged(KItemListView* current, KItemListView* previous) +void KItemListContainer::slotViewChanged(KItemListView *current, KItemListView *previous) { - QGraphicsScene* scene = static_cast<QGraphicsView*>(viewport())->scene(); + QGraphicsScene *scene = static_cast<QGraphicsView *>(viewport())->scene(); if (previous) { scene->removeItem(previous); - disconnect(previous, &KItemListView::scrollOrientationChanged, - this, &KItemListContainer::slotScrollOrientationChanged); - disconnect(previous, &KItemListView::scrollOffsetChanged, - this, &KItemListContainer::updateScrollOffsetScrollBar); - disconnect(previous, &KItemListView::maximumScrollOffsetChanged, - this, &KItemListContainer::updateScrollOffsetScrollBar); - disconnect(previous, &KItemListView::itemOffsetChanged, - this, &KItemListContainer::updateItemOffsetScrollBar); - disconnect(previous, &KItemListView::maximumItemOffsetChanged, - this, &KItemListContainer::updateItemOffsetScrollBar); + disconnect(previous, &KItemListView::scrollOrientationChanged, this, &KItemListContainer::slotScrollOrientationChanged); + disconnect(previous, &KItemListView::scrollOffsetChanged, this, &KItemListContainer::updateScrollOffsetScrollBar); + disconnect(previous, &KItemListView::maximumScrollOffsetChanged, this, &KItemListContainer::updateScrollOffsetScrollBar); + disconnect(previous, &KItemListView::itemOffsetChanged, this, &KItemListContainer::updateItemOffsetScrollBar); + 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); @@ -215,16 +205,11 @@ void KItemListContainer::slotViewChanged(KItemListView* current, KItemListView* } if (current) { scene->addItem(current); - connect(current, &KItemListView::scrollOrientationChanged, - this, &KItemListContainer::slotScrollOrientationChanged); - connect(current, &KItemListView::scrollOffsetChanged, - this, &KItemListContainer::updateScrollOffsetScrollBar); - connect(current, &KItemListView::maximumScrollOffsetChanged, - this, &KItemListContainer::updateScrollOffsetScrollBar); - connect(current, &KItemListView::itemOffsetChanged, - this, &KItemListContainer::updateItemOffsetScrollBar); - connect(current, &KItemListView::maximumItemOffsetChanged, - this, &KItemListContainer::updateItemOffsetScrollBar); + connect(current, &KItemListView::scrollOrientationChanged, this, &KItemListContainer::slotScrollOrientationChanged); + connect(current, &KItemListView::scrollOffsetChanged, this, &KItemListContainer::updateScrollOffsetScrollBar); + connect(current, &KItemListView::maximumScrollOffsetChanged, this, &KItemListContainer::updateScrollOffsetScrollBar); + connect(current, &KItemListView::itemOffsetChanged, this, &KItemListContainer::updateItemOffsetScrollBar); + 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); @@ -237,7 +222,7 @@ void KItemListContainer::slotViewChanged(KItemListView* current, KItemListView* void KItemListContainer::scrollTo(qreal offset) { - const KItemListView* view = m_controller->view(); + const KItemListView *view = m_controller->view(); if (view) { if (view->scrollOrientation() == Qt::Vertical) { m_verticalSmoothScroller->scrollTo(offset); @@ -249,13 +234,13 @@ void KItemListContainer::scrollTo(qreal offset) void KItemListContainer::updateScrollOffsetScrollBar() { - const KItemListView* view = m_controller->view(); + const KItemListView *view = m_controller->view(); if (!view) { return; } - KItemListSmoothScroller* smoothScroller = nullptr; - QScrollBar* scrollOffsetScrollBar = nullptr; + KItemListSmoothScroller *smoothScroller = nullptr; + QScrollBar *scrollOffsetScrollBar = nullptr; int singleStep = 0; int pageStep = 0; int maximum = 0; @@ -289,8 +274,7 @@ void KItemListContainer::updateScrollOffsetScrollBar() const int value = view->scrollOffset(); if (smoothScroller->requestScrollBarUpdate(maximum)) { - const bool updatePolicy = (scrollOffsetScrollBar->maximum() > 0 && maximum == 0) - || horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOn; + const bool updatePolicy = (scrollOffsetScrollBar->maximum() > 0 && maximum == 0) || horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOn; scrollOffsetScrollBar->setSingleStep(singleStep); scrollOffsetScrollBar->setPageStep(pageStep); @@ -307,13 +291,13 @@ void KItemListContainer::updateScrollOffsetScrollBar() void KItemListContainer::updateItemOffsetScrollBar() { - const KItemListView* view = m_controller->view(); + const KItemListView *view = m_controller->view(); if (!view) { return; } - KItemListSmoothScroller* smoothScroller = nullptr; - QScrollBar* itemOffsetScrollBar = nullptr; + KItemListSmoothScroller *smoothScroller = nullptr; + QScrollBar *itemOffsetScrollBar = nullptr; int singleStep = 0; int pageStep = 0; if (view->scrollOrientation() == Qt::Vertical) { @@ -356,23 +340,19 @@ void KItemListContainer::updateGeometries() scrollbarSpacing = style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, &option, this); } - const int widthDec = verticalScrollBar()->isVisible() - ? extra + scrollbarSpacing + style()->pixelMetric(QStyle::PM_ScrollBarExtent, &option, this) - : extra; + const int widthDec = verticalScrollBar()->isVisible() ? extra + scrollbarSpacing + style()->pixelMetric(QStyle::PM_ScrollBarExtent, &option, this) : extra; - const int heightDec = horizontalScrollBar()->isVisible() - ? extra + scrollbarSpacing + style()->pixelMetric(QStyle::PM_ScrollBarExtent, &option, this) - : extra; + const int heightDec = + horizontalScrollBar()->isVisible() ? extra + scrollbarSpacing + style()->pixelMetric(QStyle::PM_ScrollBarExtent, &option, this) : extra; - const QRectF newGeometry(0, 0, rect.width() - widthDec, - rect.height() - heightDec); + const QRectF newGeometry(0, 0, rect.width() - widthDec, rect.height() - heightDec); if (m_controller->view()->geometry() != newGeometry) { m_controller->view()->setGeometry(newGeometry); // Get the real geometry of the view again since the scrollbars // visibilities and the view geometry may have changed in re-layout. - static_cast<KItemListContainerViewport*>(viewport())->scene()->setSceneRect(m_controller->view()->geometry()); - static_cast<KItemListContainerViewport*>(viewport())->viewport()->setGeometry(m_controller->view()->geometry().toRect()); + static_cast<KItemListContainerViewport *>(viewport())->scene()->setSceneRect(m_controller->view()->geometry()); + static_cast<KItemListContainerViewport *>(viewport())->viewport()->setGeometry(m_controller->view()->geometry().toRect()); updateScrollOffsetScrollBar(); updateItemOffsetScrollBar(); @@ -392,7 +372,7 @@ void KItemListContainer::updateSmoothScrollers(Qt::Orientation orientation) void KItemListContainer::updateScrollOffsetScrollBarPolicy() { - const KItemListView* view = m_controller->view(); + const KItemListView *view = m_controller->view(); Q_ASSERT(view); const bool vertical = (view->scrollOrientation() == Qt::Vertical); @@ -407,8 +387,7 @@ void KItemListContainer::updateScrollOffsetScrollBarPolicy() newViewSize.rheight() += scrollBarInc; } - const Qt::ScrollBarPolicy policy = view->scrollBarRequired(newViewSize) - ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAsNeeded; + const Qt::ScrollBarPolicy policy = view->scrollBarRequired(newViewSize) ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAsNeeded; if (vertical) { setVerticalScrollBarPolicy(policy); } else { diff --git a/src/kitemviews/kitemlistcontainer.h b/src/kitemviews/kitemlistcontainer.h index 9d96d2ce0..6bb28469e 100644 --- a/src/kitemviews/kitemlistcontainer.h +++ b/src/kitemviews/kitemlistcontainer.h @@ -37,24 +37,24 @@ public: * (the parent will be set to the KItemListContainer). * @param parent Optional parent widget. */ - explicit KItemListContainer(KItemListController* controller, QWidget* parent = nullptr); + explicit KItemListContainer(KItemListController *controller, QWidget *parent = nullptr); ~KItemListContainer() override; - KItemListController* controller() const; + KItemListController *controller() const; void setEnabledFrame(bool enable); bool enabledFrame() const; protected: - void keyPressEvent(QKeyEvent* event) override; - void showEvent(QShowEvent* event) override; - void resizeEvent(QResizeEvent* event) override; + void keyPressEvent(QKeyEvent *event) override; + void showEvent(QShowEvent *event) override; + void resizeEvent(QResizeEvent *event) override; void scrollContentsBy(int dx, int dy) override; - void wheelEvent(QWheelEvent* event) override; + void wheelEvent(QWheelEvent *event) override; private Q_SLOTS: void slotScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous); - void slotModelChanged(KItemModelBase* current, KItemModelBase* previous); - void slotViewChanged(KItemListView* current, KItemListView* previous); + void slotModelChanged(KItemModelBase *current, KItemModelBase *previous); + void slotViewChanged(KItemListView *current, KItemListView *previous); void scrollTo(qreal offset); void updateScrollOffsetScrollBar(); void updateItemOffsetScrollBar(); @@ -72,13 +72,11 @@ private: void updateScrollOffsetScrollBarPolicy(); private: - KItemListController* m_controller; + KItemListController *m_controller; - KItemListSmoothScroller* m_horizontalSmoothScroller; - KItemListSmoothScroller* m_verticalSmoothScroller; - QScroller* m_scroller; + KItemListSmoothScroller *m_horizontalSmoothScroller; + KItemListSmoothScroller *m_verticalSmoothScroller; + QScroller *m_scroller; }; #endif - - diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index 29a5bd87a..54a856fb8 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -30,40 +30,37 @@ #include <QTimer> #include <QTouchEvent> -KItemListController::KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent) : - QObject(parent), - m_singleClickActivationEnforced(false), - m_selectionMode(false), - m_selectionTogglePressed(false), - m_clearSelectionIfItemsAreNotDragged(false), - m_isSwipeGesture(false), - m_dragActionOrRightClick(false), - m_scrollerIsScrolling(false), - m_pinchGestureInProgress(false), - m_mousePress(false), - m_isTouchEvent(false), - m_selectionBehavior(NoSelection), - m_autoActivationBehavior(ActivationAndExpansion), - m_mouseDoubleClickAction(ActivateItemOnly), - m_model(nullptr), - m_view(nullptr), - m_selectionManager(new KItemListSelectionManager(this)), - m_keyboardManager(new KItemListKeyboardSearchManager(this)), - m_pressedIndex(std::nullopt), - m_pressedMousePos(), - m_autoActivationTimer(nullptr), - m_swipeGesture(Qt::CustomGesture), - m_twoFingerTapGesture(Qt::CustomGesture), - m_oldSelection(), - m_keyboardAnchorIndex(-1), - m_keyboardAnchorPos(0) +KItemListController::KItemListController(KItemModelBase *model, KItemListView *view, QObject *parent) + : QObject(parent) + , m_singleClickActivationEnforced(false) + , m_selectionMode(false) + , m_selectionTogglePressed(false) + , m_clearSelectionIfItemsAreNotDragged(false) + , m_isSwipeGesture(false) + , m_dragActionOrRightClick(false) + , m_scrollerIsScrolling(false) + , m_pinchGestureInProgress(false) + , m_mousePress(false) + , m_isTouchEvent(false) + , m_selectionBehavior(NoSelection) + , m_autoActivationBehavior(ActivationAndExpansion) + , m_mouseDoubleClickAction(ActivateItemOnly) + , m_model(nullptr) + , m_view(nullptr) + , m_selectionManager(new KItemListSelectionManager(this)) + , m_keyboardManager(new KItemListKeyboardSearchManager(this)) + , m_pressedIndex(std::nullopt) + , m_pressedMousePos() + , m_autoActivationTimer(nullptr) + , m_swipeGesture(Qt::CustomGesture) + , m_twoFingerTapGesture(Qt::CustomGesture) + , m_oldSelection() + , m_keyboardAnchorIndex(-1) + , m_keyboardAnchorPos(0) { - connect(m_keyboardManager, &KItemListKeyboardSearchManager::changeCurrentItem, - this, &KItemListController::slotChangeCurrentItem); - connect(m_selectionManager, &KItemListSelectionManager::currentChanged, - m_keyboardManager, &KItemListKeyboardSearchManager::slotCurrentChanged); - connect(m_selectionManager, &KItemListSelectionManager::selectionChanged, - m_keyboardManager, &KItemListKeyboardSearchManager::slotSelectionChanged); + connect(m_keyboardManager, &KItemListKeyboardSearchManager::changeCurrentItem, this, &KItemListController::slotChangeCurrentItem); + connect(m_selectionManager, &KItemListSelectionManager::currentChanged, m_keyboardManager, &KItemListKeyboardSearchManager::slotCurrentChanged); + connect(m_selectionManager, &KItemListSelectionManager::selectionChanged, m_keyboardManager, &KItemListKeyboardSearchManager::slotSelectionChanged); m_autoActivationTimer = new QTimer(this); m_autoActivationTimer->setSingleShot(true); @@ -91,13 +88,13 @@ KItemListController::~KItemListController() Q_ASSERT(!m_model); } -void KItemListController::setModel(KItemModelBase* model) +void KItemListController::setModel(KItemModelBase *model) { if (m_model == model) { return; } - KItemModelBase* oldModel = m_model; + KItemModelBase *oldModel = m_model; if (oldModel) { oldModel->deleteLater(); } @@ -116,23 +113,23 @@ void KItemListController::setModel(KItemModelBase* model) Q_EMIT modelChanged(m_model, oldModel); } -KItemModelBase* KItemListController::model() const +KItemModelBase *KItemListController::model() const { return m_model; } -KItemListSelectionManager* KItemListController::selectionManager() const +KItemListSelectionManager *KItemListController::selectionManager() const { return m_selectionManager; } -void KItemListController::setView(KItemListView* view) +void KItemListController::setView(KItemListView *view) { if (m_view == view) { return; } - KItemListView* oldView = m_view; + KItemListView *oldView = m_view; if (oldView) { disconnect(oldView, &KItemListView::scrollOffsetChanged, this, &KItemListController::slotViewScrollOffsetChanged); oldView->deleteLater(); @@ -151,7 +148,7 @@ void KItemListController::setView(KItemListView* view) Q_EMIT viewChanged(m_view, oldView); } -KItemListView* KItemListController::view() const +KItemListView *KItemListController::view() const { return m_view; } @@ -189,7 +186,7 @@ KItemListController::MouseDoubleClickAction KItemListController::mouseDoubleClic int KItemListController::indexCloseToMousePressedPosition() const { - QHashIterator<KItemListWidget*, KItemListGroupHeader*> it(m_view->m_visibleGroups); + QHashIterator<KItemListWidget *, KItemListGroupHeader *> it(m_view->m_visibleGroups); while (it.hasNext()) { it.next(); KItemListGroupHeader *groupHeader = it.value(); @@ -231,7 +228,7 @@ bool KItemListController::selectionMode() const return m_selectionMode; } -bool KItemListController::keyPressEvent(QKeyEvent* event) +bool KItemListController::keyPressEvent(QKeyEvent *event) { int index = m_selectionManager->currentItem(); int key = event->key(); @@ -252,10 +249,8 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) const bool shiftPressed = event->modifiers() & Qt::ShiftModifier; const bool controlPressed = event->modifiers() & Qt::ControlModifier; const bool shiftOrControlPressed = shiftPressed || controlPressed; - const bool navigationPressed = key == Qt::Key_Home || key == Qt::Key_End || - key == Qt::Key_PageUp || key == Qt::Key_PageDown || - key == Qt::Key_Up || key == Qt::Key_Down || - key == Qt::Key_Left || key == Qt::Key_Right; + const bool navigationPressed = key == Qt::Key_Home || key == Qt::Key_End || key == Qt::Key_PageUp || key == Qt::Key_PageDown || key == Qt::Key_Up + || key == Qt::Key_Down || key == Qt::Key_Left || key == Qt::Key_Right; const int itemCount = m_model->count(); @@ -263,11 +258,20 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) // the arrow keys to simplify the event handling. if (m_view->scrollOrientation() == Qt::Horizontal) { switch (key) { - case Qt::Key_Up: key = Qt::Key_Left; break; - case Qt::Key_Down: key = Qt::Key_Right; break; - case Qt::Key_Left: key = Qt::Key_Up; break; - case Qt::Key_Right: key = Qt::Key_Down; break; - default: break; + case Qt::Key_Up: + key = Qt::Key_Left; + break; + case Qt::Key_Down: + key = Qt::Key_Right; + break; + case Qt::Key_Left: + key = Qt::Key_Up; + break; + case Qt::Key_Right: + key = Qt::Key_Down; + break; + default: + break; } } @@ -402,8 +406,7 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) int index = -1; if (selectedItems.count() >= 2) { const int currentItemIndex = m_selectionManager->currentItem(); - index = selectedItems.contains(currentItemIndex) - ? currentItemIndex : selectedItems.first(); + index = selectedItems.contains(currentItemIndex) ? currentItemIndex : selectedItems.first(); } else if (selectedItems.count() == 1) { index = selectedItems.first(); } @@ -437,12 +440,12 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) m_selectionManager->beginAnchoredSelection(index); break; } else if (m_keyboardManager->addKeyBeginsNewSearch()) { // File names shouldn't start with a space, - // so we can use this press as a keyboard shortcut instead. + // so we can use this press as a keyboard shortcut instead. Q_EMIT selectionModeChangeRequested(!m_selectionMode); break; } } - Q_FALLTHROUGH(); // fall through to the default case and add the Space to the current search string. + Q_FALLTHROUGH(); // fall through to the default case and add the Space to the current search string. default: m_keyboardManager->addKeys(event->text()); // Make sure unconsumed events get propagated up the chain. #302329 @@ -487,7 +490,7 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) return true; } -void KItemListController::slotChangeCurrentItem(const QString& text, bool searchFromNextItem) +void KItemListController::slotChangeCurrentItem(const QString &text, bool searchFromNextItem) { if (!m_model || m_model->count() == 0) { return; @@ -541,13 +544,13 @@ void KItemListController::slotAutoActivationTimeout() } } -bool KItemListController::inputMethodEvent(QInputMethodEvent* event) +bool KItemListController::inputMethodEvent(QInputMethodEvent *event) { Q_UNUSED(event) return false; } -bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) +bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent *event, const QTransform &transform) { m_mousePress = true; @@ -572,7 +575,7 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const return true; } -bool KItemListController::mouseMoveEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) +bool KItemListController::mouseMoveEvent(QGraphicsSceneMouseEvent *event, const QTransform &transform) { if (!m_view) { return false; @@ -607,7 +610,7 @@ bool KItemListController::mouseMoveEvent(QGraphicsSceneMouseEvent* event, const } } } else { - KItemListRubberBand* rubberBand = m_view->rubberBand(); + KItemListRubberBand *rubberBand = m_view->rubberBand(); if (rubberBand->isActive()) { QPointF endPos = transform.map(event->pos()); @@ -637,7 +640,7 @@ bool KItemListController::mouseMoveEvent(QGraphicsSceneMouseEvent* event, const return false; } -bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) +bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, const QTransform &transform) { m_mousePress = false; m_isTouchEvent = false; @@ -650,7 +653,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con m_view->m_tapAndHoldIndicator->setActive(false); } - KItemListRubberBand* rubberBand = m_view->rubberBand(); + KItemListRubberBand *rubberBand = m_view->rubberBand(); if (event->source() == Qt::MouseEventSynthesizedByQt && !rubberBand->isActive() && m_isTouchEvent) { return false; } @@ -660,7 +663,7 @@ bool KItemListController::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, con return onRelease(transform.map(event->pos()), event->modifiers(), event->button(), false); } -bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform) +bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event, const QTransform &transform) { const QPointF pos = transform.map(event->pos()); const std::optional<int> index = m_view->itemAt(pos); @@ -689,16 +692,15 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, return true; } - bool emitItemActivated = !(m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) && - (event->button() & Qt::LeftButton) && - index.has_value() && index.value() < m_model->count(); + bool emitItemActivated = !(m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) + && (event->button() & Qt::LeftButton) && index.has_value() && index.value() < m_model->count(); if (emitItemActivated) { Q_EMIT itemActivated(index.value()); } return false; } -bool KItemListController::dragEnterEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform) +bool KItemListController::dragEnterEvent(QGraphicsSceneDragDropEvent *event, const QTransform &transform) { Q_UNUSED(event) Q_UNUSED(transform) @@ -708,7 +710,7 @@ bool KItemListController::dragEnterEvent(QGraphicsSceneDragDropEvent* event, con return false; } -bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform) +bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent *event, const QTransform &transform) { Q_UNUSED(event) Q_UNUSED(transform) @@ -717,7 +719,7 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con m_view->setAutoScroll(false); m_view->hideDropIndicator(); - KItemListWidget* widget = hoveredWidget(); + KItemListWidget *widget = hoveredWidget(); if (widget) { widget->setHovered(false); Q_EMIT itemUnhovered(widget->index()); @@ -725,18 +727,17 @@ bool KItemListController::dragLeaveEvent(QGraphicsSceneDragDropEvent* event, con return false; } -bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform) +bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, const QTransform &transform) { if (!m_model || !m_view) { return false; } - QUrl hoveredDir = m_model->directory(); - KItemListWidget* oldHoveredWidget = hoveredWidget(); + KItemListWidget *oldHoveredWidget = hoveredWidget(); const QPointF pos = transform.map(event->pos()); - KItemListWidget* newHoveredWidget = widgetForDropPos(pos); + KItemListWidget *newHoveredWidget = widgetForDropPos(pos); if (oldHoveredWidget != newHoveredWidget) { m_autoActivationTimer->stop(); @@ -795,7 +796,7 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons return false; } -bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform) +bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent *event, const QTransform &transform) { if (!m_view) { return false; @@ -832,14 +833,14 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT return true; } -bool KItemListController::hoverEnterEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform) +bool KItemListController::hoverEnterEvent(QGraphicsSceneHoverEvent *event, const QTransform &transform) { Q_UNUSED(event) Q_UNUSED(transform) return false; } -bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform) +bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent *event, const QTransform &transform) { Q_UNUSED(transform) if (!m_model || !m_view) { @@ -853,8 +854,8 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const const auto oldHoveredExpansionWidgetIterator = std::find_if(visibleItemListWidgets.begin(), visibleItemListWidgets.end(), [](auto &widget) { return widget->expansionAreaHovered(); }); - const auto oldHoveredExpansionWidget = oldHoveredExpansionWidgetIterator == visibleItemListWidgets.end() ? - std::nullopt : std::make_optional(*oldHoveredExpansionWidgetIterator); + const auto oldHoveredExpansionWidget = + oldHoveredExpansionWidgetIterator == visibleItemListWidgets.end() ? std::nullopt : std::make_optional(*oldHoveredExpansionWidgetIterator); const auto unhoverOldHoveredWidget = [&]() { if (auto oldHoveredWidget = hoveredWidget(); oldHoveredWidget) { @@ -885,7 +886,6 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const // we also unhover any old icon+text hovers, in case the mouse movement from icon+text to expansion toggle is too fast (i.e. newHoveredWidget is never null between the transition) unhoverOldHoveredWidget(); - newHoveredWidget->setExpansionAreaHovered(true); } else { // make sure we unhover the old one first if old!=new @@ -922,7 +922,7 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const return false; } -bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform) +bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent *event, const QTransform &transform) { Q_UNUSED(event) Q_UNUSED(transform) @@ -935,7 +935,7 @@ bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const } const auto widgets = m_view->visibleItemListWidgets(); - for (KItemListWidget* widget : widgets) { + for (KItemListWidget *widget : widgets) { if (widget->isHovered()) { widget->setHovered(false); Q_EMIT itemUnhovered(widget->index()); @@ -944,21 +944,21 @@ bool KItemListController::hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const return false; } -bool KItemListController::wheelEvent(QGraphicsSceneWheelEvent* event, const QTransform& transform) +bool KItemListController::wheelEvent(QGraphicsSceneWheelEvent *event, const QTransform &transform) { Q_UNUSED(event) Q_UNUSED(transform) return false; } -bool KItemListController::resizeEvent(QGraphicsSceneResizeEvent* event, const QTransform& transform) +bool KItemListController::resizeEvent(QGraphicsSceneResizeEvent *event, const QTransform &transform) { Q_UNUSED(event) Q_UNUSED(transform) return false; } -bool KItemListController::gestureEvent(QGestureEvent* event, const QTransform& transform) +bool KItemListController::gestureEvent(QGestureEvent *event, const QTransform &transform) { if (!m_view) { return false; @@ -968,8 +968,8 @@ bool KItemListController::gestureEvent(QGestureEvent* event, const QTransform& t //we use this to get the right QWidget //the only exception is a tap gesture with state GestureStarted, we need to reset some variable if (!m_mousePress) { - if (QGesture* tap = event->gesture(Qt::TapGesture)) { - QTapGesture* tapGesture = static_cast<QTapGesture*>(tap); + if (QGesture *tap = event->gesture(Qt::TapGesture)) { + QTapGesture *tapGesture = static_cast<QTapGesture *>(tap); if (tapGesture->state() == Qt::GestureStarted) { tapTriggered(tapGesture, transform); } @@ -979,8 +979,8 @@ bool KItemListController::gestureEvent(QGestureEvent* event, const QTransform& t bool accepted = false; - if (QGesture* tap = event->gesture(Qt::TapGesture)) { - tapTriggered(static_cast<QTapGesture*>(tap), transform); + if (QGesture *tap = event->gesture(Qt::TapGesture)) { + tapTriggered(static_cast<QTapGesture *>(tap), transform); accepted = true; } if (event->gesture(Qt::TapAndHoldGesture)) { @@ -1002,7 +1002,7 @@ bool KItemListController::gestureEvent(QGestureEvent* event, const QTransform& t return accepted; } -bool KItemListController::touchBeginEvent(QTouchEvent* event, const QTransform& transform) +bool KItemListController::touchBeginEvent(QTouchEvent *event, const QTransform &transform) { Q_UNUSED(event) Q_UNUSED(transform) @@ -1011,7 +1011,7 @@ bool KItemListController::touchBeginEvent(QTouchEvent* event, const QTransform& return false; } -void KItemListController::tapTriggered(QTapGesture* tap, const QTransform& transform) +void KItemListController::tapTriggered(QTapGesture *tap, const QTransform &transform) { static bool scrollerWasActive = false; @@ -1040,8 +1040,7 @@ void KItemListController::tapTriggered(QTapGesture* tap, const QTransform& trans if (m_dragActionOrRightClick) { m_dragActionOrRightClick = false; - } - else { + } else { onPress(tap->hotSpot().toPoint(), tap->position().toPoint(), Qt::NoModifier, Qt::LeftButton); onRelease(transform.map(tap->position()), Qt::NoModifier, Qt::LeftButton, true); } @@ -1049,15 +1048,14 @@ void KItemListController::tapTriggered(QTapGesture* tap, const QTransform& trans } } -void KItemListController::tapAndHoldTriggered(QGestureEvent* event, const QTransform& transform) +void KItemListController::tapAndHoldTriggered(QGestureEvent *event, const QTransform &transform) { - //the Qt TabAndHold gesture is triggerable with a mouse click, we don't want this if (!m_isTouchEvent) { return; } - const QTapAndHoldGesture* tap = static_cast<QTapAndHoldGesture*>(event->gesture(Qt::TapAndHoldGesture)); + const QTapAndHoldGesture *tap = static_cast<QTapAndHoldGesture *>(event->gesture(Qt::TapAndHoldGesture)); if (tap->state() == Qt::GestureFinished) { //if a pinch gesture is in progress we don't want a TabAndHold gesture if (m_pinchGestureInProgress) { @@ -1086,11 +1084,11 @@ void KItemListController::tapAndHoldTriggered(QGestureEvent* event, const QTrans } } -void KItemListController::pinchTriggered(QGestureEvent* event, const QTransform& transform) +void KItemListController::pinchTriggered(QGestureEvent *event, const QTransform &transform) { Q_UNUSED(transform) - const QPinchGesture* pinch = static_cast<QPinchGesture*>(event->gesture(Qt::PinchGesture)); + const QPinchGesture *pinch = static_cast<QPinchGesture *>(event->gesture(Qt::PinchGesture)); const qreal sensitivityModifier = 0.2; static qreal counter = 0; @@ -1114,11 +1112,11 @@ void KItemListController::pinchTriggered(QGestureEvent* event, const QTransform& } } -void KItemListController::swipeTriggered(QGestureEvent* event, const QTransform& transform) +void KItemListController::swipeTriggered(QGestureEvent *event, const QTransform &transform) { Q_UNUSED(transform) - const KTwoFingerSwipe* swipe = static_cast<KTwoFingerSwipe*>(event->gesture(m_swipeGesture)); + const KTwoFingerSwipe *swipe = static_cast<KTwoFingerSwipe *>(event->gesture(m_swipeGesture)); if (!swipe) { return; @@ -1145,9 +1143,9 @@ void KItemListController::swipeTriggered(QGestureEvent* event, const QTransform& } } -void KItemListController::twoFingerTapTriggered(QGestureEvent* event, const QTransform& transform) +void KItemListController::twoFingerTapTriggered(QGestureEvent *event, const QTransform &transform) { - const KTwoFingerTap* twoTap = static_cast<KTwoFingerTap*>(event->gesture(m_twoFingerTapGesture)); + const KTwoFingerTap *twoTap = static_cast<KTwoFingerTap *>(event->gesture(m_twoFingerTapGesture)); if (!twoTap) { return; @@ -1160,11 +1158,10 @@ void KItemListController::twoFingerTapTriggered(QGestureEvent* event, const QTra onPress(twoTap->screenPos().toPoint(), twoTap->pos().toPoint(), Qt::ControlModifier, Qt::LeftButton); onRelease(transform.map(twoTap->pos()), Qt::ControlModifier, Qt::LeftButton, false); } - } } -bool KItemListController::processEvent(QEvent* event, const QTransform& transform) +bool KItemListController::processEvent(QEvent *event, const QTransform &transform) { if (!event) { return false; @@ -1172,39 +1169,39 @@ bool KItemListController::processEvent(QEvent* event, const QTransform& transfor switch (event->type()) { case QEvent::KeyPress: - return keyPressEvent(static_cast<QKeyEvent*>(event)); + return keyPressEvent(static_cast<QKeyEvent *>(event)); case QEvent::InputMethod: - return inputMethodEvent(static_cast<QInputMethodEvent*>(event)); + return inputMethodEvent(static_cast<QInputMethodEvent *>(event)); case QEvent::GraphicsSceneMousePress: - return mousePressEvent(static_cast<QGraphicsSceneMouseEvent*>(event), QTransform()); + return mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event), QTransform()); case QEvent::GraphicsSceneMouseMove: - return mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent*>(event), QTransform()); + return mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event), QTransform()); case QEvent::GraphicsSceneMouseRelease: - return mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(event), QTransform()); + return mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event), QTransform()); case QEvent::GraphicsSceneMouseDoubleClick: - return mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent*>(event), QTransform()); + return mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event), QTransform()); case QEvent::GraphicsSceneWheel: - return wheelEvent(static_cast<QGraphicsSceneWheelEvent*>(event), QTransform()); + return wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event), QTransform()); case QEvent::GraphicsSceneDragEnter: - return dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent*>(event), QTransform()); + return dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event), QTransform()); case QEvent::GraphicsSceneDragLeave: - return dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent*>(event), QTransform()); + return dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event), QTransform()); case QEvent::GraphicsSceneDragMove: - return dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent*>(event), QTransform()); + return dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event), QTransform()); case QEvent::GraphicsSceneDrop: - return dropEvent(static_cast<QGraphicsSceneDragDropEvent*>(event), QTransform()); + return dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event), QTransform()); case QEvent::GraphicsSceneHoverEnter: - return hoverEnterEvent(static_cast<QGraphicsSceneHoverEvent*>(event), QTransform()); + return hoverEnterEvent(static_cast<QGraphicsSceneHoverEvent *>(event), QTransform()); case QEvent::GraphicsSceneHoverMove: - return hoverMoveEvent(static_cast<QGraphicsSceneHoverEvent*>(event), QTransform()); + return hoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event), QTransform()); case QEvent::GraphicsSceneHoverLeave: - return hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent*>(event), QTransform()); + return hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event), QTransform()); case QEvent::GraphicsSceneResize: - return resizeEvent(static_cast<QGraphicsSceneResizeEvent*>(event), transform); + return resizeEvent(static_cast<QGraphicsSceneResizeEvent *>(event), transform); case QEvent::Gesture: - return gestureEvent(static_cast<QGestureEvent*>(event), transform); + return gestureEvent(static_cast<QGestureEvent *>(event), transform); case QEvent::TouchBegin: - return touchBeginEvent(static_cast<QTouchEvent*>(event), transform); + return touchBeginEvent(static_cast<QTouchEvent *>(event), transform); default: break; } @@ -1218,7 +1215,7 @@ void KItemListController::slotViewScrollOffsetChanged(qreal current, qreal previ return; } - KItemListRubberBand* rubberBand = m_view->rubberBand(); + KItemListRubberBand *rubberBand = m_view->rubberBand(); if (rubberBand->isActive()) { const qreal diff = current - previous; // TODO: Ideally just QCursor::pos() should be used as @@ -1242,7 +1239,7 @@ void KItemListController::slotRubberBandChanged() return; } - const KItemListRubberBand* rubberBand = m_view->rubberBand(); + const KItemListRubberBand *rubberBand = m_view->rubberBand(); const QPointF startPos = rubberBand->startPosition(); const QPointF endPos = rubberBand->endPosition(); QRectF rubberBandRect = QRectF(startPos, endPos).normalized(); @@ -1257,8 +1254,7 @@ void KItemListController::slotRubberBandChanged() if (!m_oldSelection.isEmpty()) { // Clear the old selection that was available before the rubberband has // been activated in case if no Shift- or Control-key are pressed - const bool shiftOrControlPressed = QApplication::keyboardModifiers() & Qt::ShiftModifier || - QApplication::keyboardModifiers() & Qt::ControlModifier; + const bool shiftOrControlPressed = QApplication::keyboardModifiers() & Qt::ShiftModifier || QApplication::keyboardModifiers() & Qt::ControlModifier; if (!shiftOrControlPressed && !m_selectionMode) { m_oldSelection.clear(); } @@ -1268,7 +1264,7 @@ void KItemListController::slotRubberBandChanged() // Select all visible items that intersect with the rubberband const auto widgets = m_view->visibleItemListWidgets(); - for (const KItemListWidget* widget : widgets) { + for (const KItemListWidget *widget : widgets) { const int index = widget->index(); const QRectF widgetRect = m_view->itemRect(index); @@ -1284,8 +1280,7 @@ void KItemListController::slotRubberBandChanged() // Select all invisible items that intersect with the rubberband. Instead of // iterating all items only the area which might be touched by the rubberband // will be checked. - const bool increaseIndex = scrollVertical ? - startPos.y() > endPos.y(): startPos.x() > endPos.x(); + const bool increaseIndex = scrollVertical ? startPos.y() > endPos.y() : startPos.x() > endPos.x(); int index = increaseIndex ? m_view->lastVisibleIndex() + 1 : m_view->firstVisibleIndex() - 1; bool selectionFinished = false; @@ -1297,14 +1292,12 @@ void KItemListController::slotRubberBandChanged() if (increaseIndex) { ++index; - selectionFinished = (index >= m_model->count()) || - ( scrollVertical && widgetRect.top() > rubberBandRect.bottom()) || - (!scrollVertical && widgetRect.left() > rubberBandRect.right()); + selectionFinished = (index >= m_model->count()) || (scrollVertical && widgetRect.top() > rubberBandRect.bottom()) + || (!scrollVertical && widgetRect.left() > rubberBandRect.right()); } else { --index; - selectionFinished = (index < 0) || - ( scrollVertical && widgetRect.bottom() < rubberBandRect.top()) || - (!scrollVertical && widgetRect.right() < rubberBandRect.left()); + selectionFinished = (index < 0) || (scrollVertical && widgetRect.bottom() < rubberBandRect.top()) + || (!scrollVertical && widgetRect.right() < rubberBandRect.left()); } } while (!selectionFinished); @@ -1314,8 +1307,7 @@ void KItemListController::slotRubberBandChanged() // 1. All previously selected items which are not inside the rubberband, and // 2. all items inside the rubberband which have not been selected previously. m_selectionManager->setSelectedItems(m_oldSelection ^ selectedItems); - } - else { + } else { m_selectionManager->setSelectedItems(selectedItems + m_oldSelection); } } @@ -1339,7 +1331,7 @@ void KItemListController::startDragging() // The created drag object will be owned and deleted // by QApplication::activeWindow(). - QDrag* drag = new QDrag(QApplication::activeWindow()); + QDrag *drag = new QDrag(QApplication::activeWindow()); drag->setMimeData(data); const QPixmap pixmap = m_view->createDragPixmap(selectedItems); @@ -1354,12 +1346,12 @@ void KItemListController::startDragging() QAccessible::updateAccessibility(&accessibilityEvent); } -KItemListWidget* KItemListController::hoveredWidget() const +KItemListWidget *KItemListController::hoveredWidget() const { Q_ASSERT(m_view); const auto widgets = m_view->visibleItemListWidgets(); - for (KItemListWidget* widget : widgets) { + for (KItemListWidget *widget : widgets) { if (widget->isHovered()) { return widget; } @@ -1368,12 +1360,12 @@ KItemListWidget* KItemListController::hoveredWidget() const return nullptr; } -KItemListWidget* KItemListController::widgetForPos(const QPointF& pos) const +KItemListWidget *KItemListController::widgetForPos(const QPointF &pos) const { Q_ASSERT(m_view); const auto widgets = m_view->visibleItemListWidgets(); - for (KItemListWidget* widget : widgets) { + for (KItemListWidget *widget : widgets) { const QPointF mappedPos = widget->mapFromItem(m_view, pos); if (widget->contains(mappedPos) || widget->selectionRect().contains(mappedPos)) { return widget; @@ -1383,12 +1375,12 @@ KItemListWidget* KItemListController::widgetForPos(const QPointF& pos) const return nullptr; } -KItemListWidget* KItemListController::widgetForDropPos(const QPointF& pos) const +KItemListWidget *KItemListController::widgetForDropPos(const QPointF &pos) const { Q_ASSERT(m_view); const auto widgets = m_view->visibleItemListWidgets(); - for (KItemListWidget* widget : widgets) { + for (KItemListWidget *widget : widgets) { const QPointF mappedPos = widget->mapFromItem(m_view, pos); if (widget->contains(mappedPos)) { return widget; @@ -1400,9 +1392,8 @@ KItemListWidget* KItemListController::widgetForDropPos(const QPointF& pos) const void KItemListController::updateKeyboardAnchor() { - const bool validAnchor = m_keyboardAnchorIndex >= 0 && - m_keyboardAnchorIndex < m_model->count() && - keyboardAnchorPos(m_keyboardAnchorIndex) == m_keyboardAnchorPos; + const bool validAnchor = + m_keyboardAnchorIndex >= 0 && m_keyboardAnchorIndex < m_model->count() && keyboardAnchorPos(m_keyboardAnchorIndex) == m_keyboardAnchorPos; if (!validAnchor) { const int index = m_selectionManager->currentItem(); m_keyboardAnchorIndex = index; @@ -1501,7 +1492,7 @@ void KItemListController::updateExtendedSelectionRegion() } } -bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons) +bool KItemListController::onPress(const QPoint &screenPos, const QPointF &pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons) { Q_EMIT mouseButtonPressed(m_pressedIndex.value_or(-1), buttons); @@ -1544,16 +1535,14 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c // - open the context menu and perform an action for all selected items. const bool shiftOrControlPressed = shiftPressed || controlPressed; const bool pressedItemAlreadySelected = m_pressedIndex.has_value() && m_selectionManager->isSelected(m_pressedIndex.value()); - const bool clearSelection = m_selectionBehavior == SingleSelection || - (!shiftOrControlPressed && !pressedItemAlreadySelected); - + const bool clearSelection = m_selectionBehavior == SingleSelection || (!shiftOrControlPressed && !pressedItemAlreadySelected); // When this method returns false, a rubberBand selection is created using KItemListController::startRubberBand via the caller. if (clearSelection) { const int selectedItemsCount = m_selectionManager->selectedItems().count(); m_selectionManager->clearSelection(); // clear and bail when we got an existing multi-selection - if (selectedItemsCount > 1 && m_pressedIndex.has_value()) { + if (selectedItemsCount > 1 && m_pressedIndex.has_value()) { const auto row = m_view->m_visibleItems.value(m_pressedIndex.value()); const auto mappedPos = row->mapFromItem(m_view, pos); if (pressedItemAlreadySelected || row->iconRect().contains(mappedPos) || row->textRect().contains(mappedPos)) { @@ -1597,7 +1586,6 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c } if (rightClick) { - // Do header hit check and short circuit before commencing any state changing effects if (m_view->headerBoundaries().contains(pos)) { Q_EMIT headerContextMenuRequested(screenPos); @@ -1605,7 +1593,7 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c } // Stop rubber band from persisting after right-clicks - KItemListRubberBand* rubberBand = m_view->rubberBand(); + KItemListRubberBand *rubberBand = m_view->rubberBand(); if (rubberBand->isActive()) { disconnect(rubberBand, &KItemListRubberBand::endPositionChanged, this, &KItemListController::slotRubberBandChanged); rubberBand->setActive(false); @@ -1687,7 +1675,7 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c return false; } -bool KItemListController::onRelease(const QPointF& pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons, bool touch) +bool KItemListController::onRelease(const QPointF &pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons, bool touch) { const bool isAboveSelectionToggle = m_view->isAboveSelectionToggle(m_pressedIndex.value_or(-1), m_pressedMousePos); if (isAboveSelectionToggle) { @@ -1702,12 +1690,11 @@ bool KItemListController::onRelease(const QPointF& pos, const Qt::KeyboardModifi } const bool controlPressed = modifiers & Qt::ControlModifier; - const bool shiftOrControlPressed = modifiers & Qt::ShiftModifier || - controlPressed; + const bool shiftOrControlPressed = modifiers & Qt::ShiftModifier || controlPressed; const std::optional<int> index = m_view->itemAt(pos); - KItemListRubberBand* rubberBand = m_view->rubberBand(); + KItemListRubberBand *rubberBand = m_view->rubberBand(); bool rubberBandRelease = false; if (rubberBand->isActive()) { disconnect(rubberBand, &KItemListRubberBand::endPositionChanged, this, &KItemListController::slotRubberBandChanged); @@ -1796,7 +1783,7 @@ void KItemListController::startRubberBand() } m_oldSelection = m_selectionManager->selectedItems(); - KItemListRubberBand* rubberBand = m_view->rubberBand(); + KItemListRubberBand *rubberBand = m_view->rubberBand(); rubberBand->setStartPosition(startPos); rubberBand->setEndPosition(startPos); rubberBand->setActive(true); diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h index b6a2f05fe..d75a8a22d 100644 --- a/src/kitemviews/kitemlistcontroller.h +++ b/src/kitemviews/kitemlistcontroller.h @@ -49,45 +49,35 @@ class QTouchEvent; class DOLPHIN_EXPORT KItemListController : public QObject { Q_OBJECT - Q_PROPERTY(KItemModelBase* model READ model WRITE setModel) + Q_PROPERTY(KItemModelBase *model READ model WRITE setModel) Q_PROPERTY(KItemListView *view READ view WRITE setView) Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior) Q_PROPERTY(AutoActivationBehavior autoActivationBehavior READ autoActivationBehavior WRITE setAutoActivationBehavior) Q_PROPERTY(MouseDoubleClickAction mouseDoubleClickAction READ mouseDoubleClickAction WRITE setMouseDoubleClickAction) public: - enum SelectionBehavior { - NoSelection, - SingleSelection, - MultiSelection - }; + enum SelectionBehavior { NoSelection, SingleSelection, MultiSelection }; Q_ENUM(SelectionBehavior) - enum AutoActivationBehavior { - ActivationAndExpansion, - ExpansionOnly - }; + enum AutoActivationBehavior { ActivationAndExpansion, ExpansionOnly }; - enum MouseDoubleClickAction { - ActivateAndExpandItem, - ActivateItemOnly - }; + enum MouseDoubleClickAction { ActivateAndExpandItem, ActivateItemOnly }; /** * @param model Model of the controller. The ownership is passed to the controller. * @param view View of the controller. The ownership is passed to the controller. * @param parent Optional parent object. */ - KItemListController(KItemModelBase* model, KItemListView* view, QObject* parent = nullptr); + KItemListController(KItemModelBase *model, KItemListView *view, QObject *parent = nullptr); ~KItemListController() override; - void setModel(KItemModelBase* model); - KItemModelBase* model() const; + void setModel(KItemModelBase *model); + KItemModelBase *model() const; - void setView(KItemListView* view); - KItemListView* view() const; + void setView(KItemListView *view); + KItemListView *view() const; - KItemListSelectionManager* selectionManager() const; + KItemListSelectionManager *selectionManager() const; void setSelectionBehavior(SelectionBehavior behavior); SelectionBehavior selectionBehavior() const; @@ -133,7 +123,7 @@ public: void setSelectionModeEnabled(bool enabled); bool selectionMode() const; - bool processEvent(QEvent* event, const QTransform& transform); + bool processEvent(QEvent *event, const QTransform &transform); Q_SIGNALS: /** @@ -154,17 +144,17 @@ Q_SIGNALS: * Emitted if a context-menu is requested for the item with * the index \a index. It is assured that the index is valid. */ - void itemContextMenuRequested(int index, const QPointF& pos); + void itemContextMenuRequested(int index, const QPointF &pos); /** * Emitted if a context-menu is requested for the KItemListView. */ - void viewContextMenuRequested(const QPointF& pos); + void viewContextMenuRequested(const QPointF &pos); /** * Emitted if a context-menu is requested for the header of the KItemListView. */ - void headerContextMenuRequested(const QPointF& pos); + void headerContextMenuRequested(const QPointF &pos); /** * Is emitted if the item with the index \p index gets hovered. @@ -203,13 +193,13 @@ Q_SIGNALS: * which is emitted if the drop event occurs on an empty area in * the view, and make sure that index is always >= 0 in itemDropEvent(). */ - void itemDropEvent(int index, QGraphicsSceneDragDropEvent* event); + void itemDropEvent(int index, QGraphicsSceneDragDropEvent *event); /** * Is emitted if a drop event is done between the item with the index * \a index and the previous item. */ - void aboveItemDropEvent(int index, QGraphicsSceneDragDropEvent* event); + void aboveItemDropEvent(int index, QGraphicsSceneDragDropEvent *event); /** * Is emitted if the Escape key is pressed. @@ -227,8 +217,8 @@ Q_SIGNALS: */ void selectionModeChangeRequested(bool enabled); - void modelChanged(KItemModelBase* current, KItemModelBase* previous); - void viewChanged(KItemListView* current, KItemListView* previous); + void modelChanged(KItemModelBase *current, KItemModelBase *previous); + void viewChanged(KItemListView *current, KItemListView *previous); void selectedItemTextPressed(int index); @@ -249,7 +239,7 @@ private Q_SLOTS: */ void slotRubberBandChanged(); - void slotChangeCurrentItem(const QString& text, bool searchFromNextItem); + void slotChangeCurrentItem(const QString &text, bool searchFromNextItem); void slotAutoActivationTimeout(); @@ -263,13 +253,13 @@ private: * @return Widget that is currently in the hovered state. 0 is returned * if no widget is marked as hovered. */ - KItemListWidget* hoveredWidget() const; + KItemListWidget *hoveredWidget() const; /** * @return Widget that is below the position \a pos. 0 is returned * if no widget is below the position. */ - KItemListWidget* widgetForPos(const QPointF& pos) const; + KItemListWidget *widgetForPos(const QPointF &pos) const; /** * @return Widget that should receive a drop event if an item is dropped at \a pos. 0 is returned @@ -278,7 +268,7 @@ private: * While widgetForPos() returns a widget if \a pos is anywhere inside the hover highlight area of the widget, * widgetForDropPos() only returns a widget if \a pos is directly above the widget (widget->contains(pos) == true). */ - KItemListWidget* widgetForDropPos(const QPointF& pos) const; + KItemListWidget *widgetForDropPos(const QPointF &pos) const; /** * Updates m_keyboardAnchorIndex and m_keyboardAnchorPos. If no anchor is @@ -315,30 +305,30 @@ private: */ void updateExtendedSelectionRegion(); - bool keyPressEvent(QKeyEvent* event); - bool inputMethodEvent(QInputMethodEvent* event); - bool mousePressEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform); - bool mouseMoveEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform); - bool mouseReleaseEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform); - bool mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform); - bool dragEnterEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform); - bool dragLeaveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform); - bool dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform); - bool dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform); - bool hoverEnterEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform); - bool hoverMoveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform); - bool hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform); - bool wheelEvent(QGraphicsSceneWheelEvent* event, const QTransform& transform); - bool resizeEvent(QGraphicsSceneResizeEvent* event, const QTransform& transform); - bool gestureEvent(QGestureEvent* event, const QTransform& transform); - bool touchBeginEvent(QTouchEvent* event, const QTransform& transform); - void tapTriggered(QTapGesture* tap, const QTransform& transform); - void tapAndHoldTriggered(QGestureEvent* event, const QTransform& transform); - void pinchTriggered(QGestureEvent* event, const QTransform& transform); - void swipeTriggered(QGestureEvent* event, const QTransform& transform); - void twoFingerTapTriggered(QGestureEvent* event, const QTransform& transform); - bool onPress(const QPoint& screenPos, const QPointF& pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons); - bool onRelease(const QPointF& pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons, bool touch); + bool keyPressEvent(QKeyEvent *event); + bool inputMethodEvent(QInputMethodEvent *event); + bool mousePressEvent(QGraphicsSceneMouseEvent *event, const QTransform &transform); + bool mouseMoveEvent(QGraphicsSceneMouseEvent *event, const QTransform &transform); + bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event, const QTransform &transform); + bool mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event, const QTransform &transform); + bool dragEnterEvent(QGraphicsSceneDragDropEvent *event, const QTransform &transform); + bool dragLeaveEvent(QGraphicsSceneDragDropEvent *event, const QTransform &transform); + bool dragMoveEvent(QGraphicsSceneDragDropEvent *event, const QTransform &transform); + bool dropEvent(QGraphicsSceneDragDropEvent *event, const QTransform &transform); + bool hoverEnterEvent(QGraphicsSceneHoverEvent *event, const QTransform &transform); + bool hoverMoveEvent(QGraphicsSceneHoverEvent *event, const QTransform &transform); + bool hoverLeaveEvent(QGraphicsSceneHoverEvent *event, const QTransform &transform); + bool wheelEvent(QGraphicsSceneWheelEvent *event, const QTransform &transform); + bool resizeEvent(QGraphicsSceneResizeEvent *event, const QTransform &transform); + bool gestureEvent(QGestureEvent *event, const QTransform &transform); + bool touchBeginEvent(QTouchEvent *event, const QTransform &transform); + void tapTriggered(QTapGesture *tap, const QTransform &transform); + void tapAndHoldTriggered(QGestureEvent *event, const QTransform &transform); + void pinchTriggered(QGestureEvent *event, const QTransform &transform); + void swipeTriggered(QGestureEvent *event, const QTransform &transform); + void twoFingerTapTriggered(QGestureEvent *event, const QTransform &transform); + bool onPress(const QPoint &screenPos, const QPointF &pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons); + bool onRelease(const QPointF &pos, const Qt::KeyboardModifiers modifiers, const Qt::MouseButtons buttons, bool touch); void startRubberBand(); private: @@ -355,14 +345,14 @@ private: SelectionBehavior m_selectionBehavior; AutoActivationBehavior m_autoActivationBehavior; MouseDoubleClickAction m_mouseDoubleClickAction; - KItemModelBase* m_model; - KItemListView* m_view; - KItemListSelectionManager* m_selectionManager; - KItemListKeyboardSearchManager* m_keyboardManager; + KItemModelBase *m_model; + KItemListView *m_view; + KItemListSelectionManager *m_selectionManager; + KItemListKeyboardSearchManager *m_keyboardManager; std::optional<int> m_pressedIndex; QPointF m_pressedMousePos; - QTimer* m_autoActivationTimer; + QTimer *m_autoActivationTimer; Qt::GestureType m_swipeGesture; Qt::GestureType m_twoFingerTapGesture; @@ -394,5 +384,3 @@ private: }; #endif - - diff --git a/src/kitemviews/kitemlistgroupheader.cpp b/src/kitemviews/kitemlistgroupheader.cpp index f0ff52503..66cd74eb4 100644 --- a/src/kitemviews/kitemlistgroupheader.cpp +++ b/src/kitemviews/kitemlistgroupheader.cpp @@ -14,17 +14,17 @@ #include <QPainter> #include <QStyleOptionGraphicsItem> -KItemListGroupHeader::KItemListGroupHeader(QGraphicsWidget* parent) : - QGraphicsWidget(parent), - m_dirtyCache(true), - m_role(), - m_data(), - m_styleOption(), - m_scrollOrientation(Qt::Vertical), - m_itemIndex(-1), - m_separatorColor(), - m_roleColor(), - m_roleBounds() +KItemListGroupHeader::KItemListGroupHeader(QGraphicsWidget *parent) + : QGraphicsWidget(parent) + , m_dirtyCache(true) + , m_role() + , m_data() + , m_styleOption() + , m_scrollOrientation(Qt::Vertical) + , m_itemIndex(-1) + , m_separatorColor() + , m_roleColor() + , m_roleBounds() { } @@ -32,7 +32,7 @@ KItemListGroupHeader::~KItemListGroupHeader() { } -void KItemListGroupHeader::setRole(const QByteArray& role) +void KItemListGroupHeader::setRole(const QByteArray &role) { if (m_role != role) { const QByteArray previous = m_role; @@ -47,7 +47,7 @@ QByteArray KItemListGroupHeader::role() const return m_role; } -void KItemListGroupHeader::setData(const QVariant& data) +void KItemListGroupHeader::setData(const QVariant &data) { if (m_data != data) { const QVariant previous = m_data; @@ -62,7 +62,7 @@ QVariant KItemListGroupHeader::data() const return m_data; } -void KItemListGroupHeader::setStyleOption(const KItemListStyleOption& option) +void KItemListGroupHeader::setStyleOption(const KItemListStyleOption &option) { if (m_styleOption == option) { return; @@ -74,7 +74,7 @@ void KItemListGroupHeader::setStyleOption(const KItemListStyleOption& option) styleOptionChanged(option, previous); } -const KItemListStyleOption& KItemListGroupHeader::styleOption() const +const KItemListStyleOption &KItemListGroupHeader::styleOption() const { return m_styleOption; } @@ -111,7 +111,7 @@ Qt::Orientation KItemListGroupHeader::scrollOrientation() const return m_scrollOrientation; } -void KItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void KItemListGroupHeader::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(painter) Q_UNUSED(option) @@ -125,19 +125,19 @@ void KItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsIt paintRole(painter, m_roleBounds, m_roleColor); } -void KItemListGroupHeader::roleChanged(const QByteArray& current, const QByteArray& previous) +void KItemListGroupHeader::roleChanged(const QByteArray ¤t, const QByteArray &previous) { Q_UNUSED(current) Q_UNUSED(previous) } -void KItemListGroupHeader::dataChanged(const QVariant& current, const QVariant& previous) +void KItemListGroupHeader::dataChanged(const QVariant ¤t, const QVariant &previous) { Q_UNUSED(current) Q_UNUSED(previous) } -void KItemListGroupHeader::styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) +void KItemListGroupHeader::styleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -155,7 +155,7 @@ void KItemListGroupHeader::itemIndexChanged(int current, int previous) Q_UNUSED(previous) } -void KItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent* event) +void KItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent *event) { QGraphicsWidget::resizeEvent(event); if (event->oldSize().height() != event->newSize().height()) { @@ -190,22 +190,19 @@ void KItemListGroupHeader::updateSize() const int y = (m_scrollOrientation == Qt::Vertical) ? padding : horizontalMargin; - m_roleBounds = QRectF(horizontalMargin + padding, - y, - size().width() - 2 * padding - horizontalMargin, - roleHeight); + m_roleBounds = QRectF(horizontalMargin + padding, y, size().width() - 2 * padding - horizontalMargin, roleHeight); update(); } -QColor KItemListGroupHeader::mixedColor(const QColor& c1, const QColor& c2, int c1Percent) +QColor KItemListGroupHeader::mixedColor(const QColor &c1, const QColor &c2, int c1Percent) { Q_ASSERT(c1Percent >= 0 && c1Percent <= 100); const int c2Percent = 100 - c1Percent; - return QColor((c1.red() * c1Percent + c2.red() * c2Percent) / 100, + return QColor((c1.red() * c1Percent + c2.red() * c2Percent) / 100, (c1.green() * c1Percent + c2.green() * c2Percent) / 100, - (c1.blue() * c1Percent + c2.blue() * c2Percent) / 100); + (c1.blue() * c1Percent + c2.blue() * c2Percent) / 100); } QPalette::ColorRole KItemListGroupHeader::normalTextColorRole() const @@ -229,4 +226,3 @@ QColor KItemListGroupHeader::baseColor() const const QPalette::ColorGroup group = isActiveWindow() ? QPalette::Active : QPalette::Inactive; return styleOption().palette.color(group, normalBaseColorRole()); } - diff --git a/src/kitemviews/kitemlistgroupheader.h b/src/kitemviews/kitemlistgroupheader.h index 48af1e9e0..1522af0ce 100644 --- a/src/kitemviews/kitemlistgroupheader.h +++ b/src/kitemviews/kitemlistgroupheader.h @@ -28,17 +28,17 @@ class DOLPHIN_EXPORT KItemListGroupHeader : public QGraphicsWidget Q_OBJECT public: - explicit KItemListGroupHeader(QGraphicsWidget* parent = nullptr); + explicit KItemListGroupHeader(QGraphicsWidget *parent = nullptr); ~KItemListGroupHeader() override; - void setRole(const QByteArray& role); + void setRole(const QByteArray &role); QByteArray role() const; - void setData(const QVariant& data); + void setData(const QVariant &data); QVariant data() const; - void setStyleOption(const KItemListStyleOption& option); - const KItemListStyleOption& styleOption() const; + void setStyleOption(const KItemListStyleOption &option); + const KItemListStyleOption &styleOption() const; /** * Sets the scroll orientation that is used by the KItemListView. @@ -51,29 +51,29 @@ public: void setItemIndex(int index); int itemIndex() const; - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; protected: - virtual void paintRole(QPainter* painter, const QRectF& roleBounds, const QColor& color) = 0; - virtual void paintSeparator(QPainter* painter, const QColor& color) = 0; + virtual void paintRole(QPainter *painter, const QRectF &roleBounds, const QColor &color) = 0; + virtual void paintSeparator(QPainter *painter, const QColor &color) = 0; /** * Is called after the role has been changed and allows the derived class * to react on this change. */ - virtual void roleChanged(const QByteArray& current, const QByteArray& previous); + virtual void roleChanged(const QByteArray ¤t, const QByteArray &previous); /** * Is called after the role has been changed and allows the derived class * to react on this change. */ - virtual void dataChanged(const QVariant& current, const QVariant& previous); + virtual void dataChanged(const QVariant ¤t, const QVariant &previous); /** * Is called after the style option has been changed and allows the derived class * to react on this change. */ - virtual void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous); + virtual void styleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous); /** * Is called after the scroll orientation has been changed and allows the derived class @@ -87,7 +87,7 @@ protected: */ virtual void itemIndexChanged(int current, int previous); - void resizeEvent(QGraphicsSceneResizeEvent* event) override; + void resizeEvent(QGraphicsSceneResizeEvent *event) override; virtual QPalette::ColorRole normalTextColorRole() const; virtual QPalette::ColorRole normalBaseColorRole() const; @@ -96,7 +96,7 @@ private: void updateCache(); void updateSize(); - static QColor mixedColor(const QColor& c1, const QColor& c2, int c1Percent = 50); + static QColor mixedColor(const QColor &c1, const QColor &c2, int c1Percent = 50); QColor textColor() const; QColor baseColor() const; @@ -114,5 +114,3 @@ private: QRectF m_roleBounds; }; #endif - - diff --git a/src/kitemviews/kitemlistheader.cpp b/src/kitemviews/kitemlistheader.cpp index 64d6a2559..dfbe7ab2c 100644 --- a/src/kitemviews/kitemlistheader.cpp +++ b/src/kitemviews/kitemlistheader.cpp @@ -28,7 +28,7 @@ bool KItemListHeader::automaticColumnResizing() const return m_headerWidget->automaticColumnResizing(); } -void KItemListHeader::setColumnWidth(const QByteArray& role, qreal width) +void KItemListHeader::setColumnWidth(const QByteArray &role, qreal width) { if (!m_headerWidget->automaticColumnResizing()) { m_headerWidget->setColumnWidth(role, width); @@ -37,16 +37,16 @@ void KItemListHeader::setColumnWidth(const QByteArray& role, qreal width) } } -qreal KItemListHeader::columnWidth(const QByteArray& role) const +qreal KItemListHeader::columnWidth(const QByteArray &role) const { return m_headerWidget->columnWidth(role); } -void KItemListHeader::setColumnWidths(const QHash<QByteArray, qreal>& columnWidths) +void KItemListHeader::setColumnWidths(const QHash<QByteArray, qreal> &columnWidths) { if (!m_headerWidget->automaticColumnResizing()) { const auto visibleRoles = m_view->visibleRoles(); - for (const QByteArray& role : visibleRoles) { + for (const QByteArray &role : visibleRoles) { const qreal width = columnWidths.value(role); m_headerWidget->setColumnWidth(role, width); } @@ -56,12 +56,13 @@ void KItemListHeader::setColumnWidths(const QHash<QByteArray, qreal>& columnWidt } } -qreal KItemListHeader::preferredColumnWidth(const QByteArray& role) const +qreal KItemListHeader::preferredColumnWidth(const QByteArray &role) const { return m_headerWidget->preferredColumnWidth(role); } -void KItemListHeader::setSidePadding(qreal width){ +void KItemListHeader::setSidePadding(qreal width) +{ if (m_headerWidget->sidePadding() != width) { m_headerWidget->setSidePadding(width); if (m_headerWidget->automaticColumnResizing()) { @@ -71,22 +72,19 @@ void KItemListHeader::setSidePadding(qreal width){ } } -qreal KItemListHeader::sidePadding() const{ +qreal KItemListHeader::sidePadding() const +{ return m_headerWidget->sidePadding(); } -KItemListHeader::KItemListHeader(KItemListView* listView) : - QObject(listView), - m_view(listView) +KItemListHeader::KItemListHeader(KItemListView *listView) + : QObject(listView) + , m_view(listView) { m_headerWidget = m_view->m_headerWidget; Q_ASSERT(m_headerWidget); - connect(m_headerWidget, &KItemListHeaderWidget::columnWidthChanged, - this, &KItemListHeader::columnWidthChanged); - connect(m_headerWidget, &KItemListHeaderWidget::columnWidthChangeFinished, - this, &KItemListHeader::columnWidthChangeFinished); - connect(m_headerWidget, &KItemListHeaderWidget::sidePaddingChanged, - this, &KItemListHeader::sidePaddingChanged); + connect(m_headerWidget, &KItemListHeaderWidget::columnWidthChanged, this, &KItemListHeader::columnWidthChanged); + connect(m_headerWidget, &KItemListHeaderWidget::columnWidthChangeFinished, this, &KItemListHeader::columnWidthChangeFinished); + connect(m_headerWidget, &KItemListHeaderWidget::sidePaddingChanged, this, &KItemListHeader::sidePaddingChanged); } - diff --git a/src/kitemviews/kitemlistheader.h b/src/kitemviews/kitemlistheader.h index 66223f0c7..04519f12c 100644 --- a/src/kitemviews/kitemlistheader.h +++ b/src/kitemviews/kitemlistheader.h @@ -41,8 +41,8 @@ public: * the width only gets applied if KItemListHeader::automaticColumnResizing() * has been turned off. */ - void setColumnWidth(const QByteArray& role, qreal width); - qreal columnWidth(const QByteArray& role) const; + void setColumnWidth(const QByteArray &role, qreal width); + qreal columnWidth(const QByteArray &role) const; /** * Sets the widths of the columns for all roles. From a performance point of @@ -51,12 +51,12 @@ public: * Note that the widths only get applied if KItemListHeader::automaticColumnResizing() * has been turned off. */ - void setColumnWidths(const QHash<QByteArray, qreal>& columnWidths); + void setColumnWidths(const QHash<QByteArray, qreal> &columnWidths); /** * @return The column width that is required to show the role unclipped. */ - qreal preferredColumnWidth(const QByteArray& role) const; + qreal preferredColumnWidth(const QByteArray &role) const; /** * Sets the width of the column *before* the first column. @@ -72,27 +72,22 @@ Q_SIGNALS: * Is emitted if the width of a column has been adjusted by the user with the mouse * (no signal is emitted if KItemListHeader::setColumnWidth() is invoked). */ - void columnWidthChanged(const QByteArray& role, - qreal currentWidth, - qreal previousWidth); + void columnWidthChanged(const QByteArray &role, qreal currentWidth, qreal previousWidth); /** * Is emitted if the user has released the mouse button after adjusting the * width of a visible role. */ - void columnWidthChangeFinished(const QByteArray& role, - qreal currentWidth); + void columnWidthChangeFinished(const QByteArray &role, qreal currentWidth); private: - explicit KItemListHeader(KItemListView* listView); + explicit KItemListHeader(KItemListView *listView); private: - KItemListView* m_view; - KItemListHeaderWidget* m_headerWidget; + KItemListView *m_view; + KItemListHeaderWidget *m_headerWidget; friend class KItemListView; // Constructs the KItemListHeader instance }; #endif - - diff --git a/src/kitemviews/kitemlistselectionmanager.cpp b/src/kitemviews/kitemlistselectionmanager.cpp index ce0dc06de..2a2fbac81 100644 --- a/src/kitemviews/kitemlistselectionmanager.cpp +++ b/src/kitemviews/kitemlistselectionmanager.cpp @@ -9,13 +9,13 @@ #include "kitemlistselectionmanager.h" -KItemListSelectionManager::KItemListSelectionManager(QObject* parent) : - QObject(parent), - m_currentItem(-1), - m_anchorItem(-1), - m_selectedItems(), - m_isAnchoredSelectionActive(false), - m_model(nullptr) +KItemListSelectionManager::KItemListSelectionManager(QObject *parent) + : QObject(parent) + , m_currentItem(-1) + , m_anchorItem(-1) + , m_selectedItems() + , m_isAnchoredSelectionActive(false) + , m_model(nullptr) { } @@ -51,7 +51,7 @@ int KItemListSelectionManager::currentItem() const return m_currentItem; } -void KItemListSelectionManager::setSelectedItems(const KItemSet& items) +void KItemListSelectionManager::setSelectedItems(const KItemSet &items) { if (m_selectedItems != items) { const KItemSet previous = m_selectedItems; @@ -114,7 +114,7 @@ void KItemListSelectionManager::setSelected(int index, int count, SelectionMode count = qMin(count, m_model->count() - index); - const int endIndex = index + count -1; + const int endIndex = index + count - 1; switch (mode) { case Select: for (int i = index; i <= endIndex; ++i) { @@ -198,12 +198,12 @@ bool KItemListSelectionManager::isAnchoredSelectionActive() const return m_isAnchoredSelectionActive; } -KItemModelBase* KItemListSelectionManager::model() const +KItemModelBase *KItemListSelectionManager::model() const { return m_model; } -void KItemListSelectionManager::setModel(KItemModelBase* model) +void KItemListSelectionManager::setModel(KItemModelBase *model) { m_model = model; if (model && model->count() > 0) { @@ -211,7 +211,7 @@ void KItemListSelectionManager::setModel(KItemModelBase* model) } } -void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges) +void KItemListSelectionManager::itemsInserted(const KItemRangeList &itemRanges) { // Store the current selection (needed in the selectionChanged() signal) const KItemSet previousSelection = selectedItems(); @@ -222,7 +222,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges) } else { const int previousCurrent = m_currentItem; int inc = 0; - for (const KItemRange& itemRange : itemRanges) { + for (const KItemRange &itemRange : itemRanges) { if (m_currentItem < itemRange.index) { break; } @@ -242,7 +242,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges) m_anchorItem = 0; } else { int inc = 0; - for (const KItemRange& itemRange : itemRanges) { + for (const KItemRange &itemRange : itemRanges) { if (m_anchorItem < itemRange.index) { break; } @@ -256,9 +256,9 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges) const KItemSet previous = m_selectedItems; m_selectedItems.clear(); - for (int index: previous) { + for (int index : previous) { int inc = 0; - for (const KItemRange& itemRange : itemRanges) { + for (const KItemRange &itemRange : itemRanges) { if (index < itemRange.index) { break; } @@ -274,7 +274,7 @@ void KItemListSelectionManager::itemsInserted(const KItemRangeList& itemRanges) } } -void KItemListSelectionManager::itemsRemoved(const KItemRangeList& itemRanges) +void KItemListSelectionManager::itemsRemoved(const KItemRangeList &itemRanges) { // Store the current selection (needed in the selectionChanged() signal) const KItemSet previousSelection = selectedItems(); @@ -307,7 +307,7 @@ void KItemListSelectionManager::itemsRemoved(const KItemRangeList& itemRanges) for (int oldIndex : previous) { const int index = indexAfterRangesRemoving(oldIndex, itemRanges, DiscardRemovedIndex); - if (index >= 0) { + if (index >= 0) { m_selectedItems.insert(index); } } @@ -322,7 +322,7 @@ void KItemListSelectionManager::itemsRemoved(const KItemRangeList& itemRanges) Q_ASSERT(m_anchorItem < m_model->count()); } -void KItemListSelectionManager::itemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes) +void KItemListSelectionManager::itemsMoved(const KItemRange &itemRange, const QList<int> &movedToIndexes) { // Store the current selection (needed in the selectionChanged() signal) const KItemSet previousSelection = selectedItems(); @@ -359,8 +359,7 @@ void KItemListSelectionManager::itemsMoved(const KItemRange& itemRange, const QL for (int index : previous) { if (index >= itemRange.index && index < itemRange.index + itemRange.count) { m_selectedItems.insert(movedToIndexes.at(index - itemRange.index)); - } - else { + } else { m_selectedItems.insert(index); } } @@ -372,11 +371,10 @@ void KItemListSelectionManager::itemsMoved(const KItemRange& itemRange, const QL } } -int KItemListSelectionManager::indexAfterRangesRemoving(int index, const KItemRangeList& itemRanges, - const RangesRemovingBehaviour behaviour) const +int KItemListSelectionManager::indexAfterRangesRemoving(int index, const KItemRangeList &itemRanges, const RangesRemovingBehaviour behaviour) const { int dec = 0; - for (const KItemRange& itemRange : itemRanges) { + for (const KItemRange &itemRange : itemRanges) { if (index < itemRange.index) { break; } @@ -397,4 +395,3 @@ int KItemListSelectionManager::indexAfterRangesRemoving(int index, const KItemRa } return qBound(-1, index - dec, m_model->count() - 1); } - diff --git a/src/kitemviews/kitemlistselectionmanager.h b/src/kitemviews/kitemlistselectionmanager.h index 2fc5061fe..ba9dd538a 100644 --- a/src/kitemviews/kitemlistselectionmanager.h +++ b/src/kitemviews/kitemlistselectionmanager.h @@ -24,25 +24,18 @@ class DOLPHIN_EXPORT KItemListSelectionManager : public QObject { Q_OBJECT - enum RangesRemovingBehaviour { - DiscardRemovedIndex, - AdjustRemovedIndex - }; + enum RangesRemovingBehaviour { DiscardRemovedIndex, AdjustRemovedIndex }; public: - enum SelectionMode { - Select, - Deselect, - Toggle - }; + enum SelectionMode { Select, Deselect, Toggle }; - explicit KItemListSelectionManager(QObject* parent = nullptr); + explicit KItemListSelectionManager(QObject *parent = nullptr); ~KItemListSelectionManager() override; void setCurrentItem(int current); int currentItem() const; - void setSelectedItems(const KItemSet& items); + void setSelectedItems(const KItemSet &items); KItemSet selectedItems() const; bool isSelected(int index) const; bool hasSelection() const; @@ -61,24 +54,23 @@ public: void endAnchoredSelection(); bool isAnchoredSelectionActive() const; - KItemModelBase* model() const; + KItemModelBase *model() const; Q_SIGNALS: void currentChanged(int current, int previous); - void selectionChanged(const KItemSet& current, const KItemSet& previous); + void selectionChanged(const KItemSet ¤t, const KItemSet &previous); private: - void setModel(KItemModelBase* model); - void itemsInserted(const KItemRangeList& itemRanges); - void itemsRemoved(const KItemRangeList& itemRanges); - void itemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes); - + void setModel(KItemModelBase *model); + void itemsInserted(const KItemRangeList &itemRanges); + void itemsRemoved(const KItemRangeList &itemRanges); + void itemsMoved(const KItemRange &itemRange, const QList<int> &movedToIndexes); /** * Helper method for itemsRemoved. Returns the changed index after removing * the given range. If the index is part of the range, -1 will be returned. */ - int indexAfterRangesRemoving(int index, const KItemRangeList& itemRanges, const RangesRemovingBehaviour behaviour) const; + int indexAfterRangesRemoving(int index, const KItemRangeList &itemRanges, const RangesRemovingBehaviour behaviour) const; private: int m_currentItem; @@ -86,10 +78,10 @@ private: KItemSet m_selectedItems; bool m_isAnchoredSelectionActive; - KItemModelBase* m_model; + KItemModelBase *m_model; friend class KItemListController; // Calls setModel() - friend class KItemListView; // Calls itemsInserted(), itemsRemoved() and itemsMoved() + friend class KItemListView; // Calls itemsInserted(), itemsRemoved() and itemsMoved() friend class KItemListSelectionManagerTest; }; diff --git a/src/kitemviews/kitemliststyleoption.cpp b/src/kitemviews/kitemliststyleoption.cpp index 6e4aaa96e..7ca6bd1d5 100644 --- a/src/kitemviews/kitemliststyleoption.cpp +++ b/src/kitemviews/kitemliststyleoption.cpp @@ -6,19 +6,18 @@ #include "kitemliststyleoption.h" - -KItemListStyleOption::KItemListStyleOption() : - rect(), - font(), - fontMetrics(QFont()), - palette(), - padding(-1), - horizontalMargin(-1), - verticalMargin(-1), - iconSize(-1), - extendedSelectionRegion(false), - maxTextLines(0), - maxTextWidth(0) +KItemListStyleOption::KItemListStyleOption() + : rect() + , font() + , fontMetrics(QFont()) + , palette() + , padding(-1) + , horizontalMargin(-1) + , verticalMargin(-1) + , iconSize(-1) + , extendedSelectionRegion(false) + , maxTextLines(0) + , maxTextWidth(0) { } @@ -26,22 +25,14 @@ KItemListStyleOption::~KItemListStyleOption() { } -bool KItemListStyleOption::operator==(const KItemListStyleOption& other) const +bool KItemListStyleOption::operator==(const KItemListStyleOption &other) const { - return rect == other.rect - && font == other.font - && fontMetrics == other.fontMetrics - && palette == other.palette - && padding == other.padding - && horizontalMargin == other.horizontalMargin - && verticalMargin == other.verticalMargin - && iconSize == other.iconSize - && extendedSelectionRegion == other.extendedSelectionRegion - && maxTextLines == other.maxTextLines - && maxTextWidth == other.maxTextWidth; + return rect == other.rect && font == other.font && fontMetrics == other.fontMetrics && palette == other.palette && padding == other.padding + && horizontalMargin == other.horizontalMargin && verticalMargin == other.verticalMargin && iconSize == other.iconSize + && extendedSelectionRegion == other.extendedSelectionRegion && maxTextLines == other.maxTextLines && maxTextWidth == other.maxTextWidth; } -bool KItemListStyleOption::operator!=(const KItemListStyleOption& other) const +bool KItemListStyleOption::operator!=(const KItemListStyleOption &other) const { return !(*this == other); } diff --git a/src/kitemviews/kitemliststyleoption.h b/src/kitemviews/kitemliststyleoption.h index 62e462a5d..49dcc53c5 100644 --- a/src/kitemviews/kitemliststyleoption.h +++ b/src/kitemviews/kitemliststyleoption.h @@ -32,9 +32,7 @@ public: int maxTextLines; int maxTextWidth; - bool operator==(const KItemListStyleOption& other) const; - bool operator!=(const KItemListStyleOption& other) const; + bool operator==(const KItemListStyleOption &other) const; + bool operator!=(const KItemListStyleOption &other) const; }; #endif - - diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 543be6518..d9455ce9e 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -29,29 +29,29 @@ #include <QTimer> #include <QVariantAnimation> +namespace +{ +// Time in ms until reaching the autoscroll margin triggers +// an initial autoscrolling +const int InitialAutoScrollDelay = 700; -namespace { - // Time in ms until reaching the autoscroll margin triggers - // an initial autoscrolling - const int InitialAutoScrollDelay = 700; - - // Delay in ms for triggering the next autoscroll - const int RepeatingAutoScrollDelay = 1000 / 60; +// Delay in ms for triggering the next autoscroll +const int RepeatingAutoScrollDelay = 1000 / 60; - // Copied from the Kirigami.Units.shortDuration - const int RubberFadeSpeed = 150; +// Copied from the Kirigami.Units.shortDuration +const int RubberFadeSpeed = 150; - const char* RubberPropertyName = "_kitemviews_rubberBandPosition"; +const char *RubberPropertyName = "_kitemviews_rubberBandPosition"; } #ifndef QT_NO_ACCESSIBILITY -QAccessibleInterface* accessibleInterfaceFactory(const QString& key, QObject* object) +QAccessibleInterface *accessibleInterfaceFactory(const QString &key, QObject *object) { Q_UNUSED(key) - if (KItemListContainer* container = qobject_cast<KItemListContainer*>(object)) { + if (KItemListContainer *container = qobject_cast<KItemListContainer *>(object)) { return new KItemListContainerAccessible(container); - } else if (KItemListView* view = qobject_cast<KItemListView*>(object)) { + } else if (KItemListView *view = qobject_cast<KItemListView *>(object)) { return new KItemListViewAccessible(view); } @@ -59,44 +59,44 @@ QAccessibleInterface* accessibleInterfaceFactory(const QString& key, QObject* ob } #endif -KItemListView::KItemListView(QGraphicsWidget* parent) : - QGraphicsWidget(parent), - m_enabledSelectionToggles(false), - m_grouped(false), - m_highlightEntireRow(false), - m_alternateBackgrounds(false), - m_supportsItemExpanding(false), - m_editingRole(false), - m_activeTransactions(0), - m_endTransactionAnimationHint(Animation), - m_itemSize(), - m_controller(nullptr), - m_model(nullptr), - m_visibleRoles(), - m_widgetCreator(nullptr), - m_groupHeaderCreator(nullptr), - m_styleOption(), - m_visibleItems(), - m_visibleGroups(), - m_visibleCells(), - m_scrollBarExtent(0), - m_layouter(nullptr), - m_animation(nullptr), - m_oldScrollOffset(0), - m_oldMaximumScrollOffset(0), - m_oldItemOffset(0), - m_oldMaximumItemOffset(0), - m_skipAutoScrollForRubberBand(false), - m_rubberBand(nullptr), - m_tapAndHoldIndicator(nullptr), - m_mousePos(), - m_autoScrollIncrement(0), - m_autoScrollTimer(nullptr), - m_header(nullptr), - m_headerWidget(nullptr), - m_indicatorAnimation(nullptr), - m_dropIndicator(), - m_sizeHintResolver(nullptr) +KItemListView::KItemListView(QGraphicsWidget *parent) + : QGraphicsWidget(parent) + , m_enabledSelectionToggles(false) + , m_grouped(false) + , m_highlightEntireRow(false) + , m_alternateBackgrounds(false) + , m_supportsItemExpanding(false) + , m_editingRole(false) + , m_activeTransactions(0) + , m_endTransactionAnimationHint(Animation) + , m_itemSize() + , m_controller(nullptr) + , m_model(nullptr) + , m_visibleRoles() + , m_widgetCreator(nullptr) + , m_groupHeaderCreator(nullptr) + , m_styleOption() + , m_visibleItems() + , m_visibleGroups() + , m_visibleCells() + , m_scrollBarExtent(0) + , m_layouter(nullptr) + , m_animation(nullptr) + , m_oldScrollOffset(0) + , m_oldMaximumScrollOffset(0) + , m_oldItemOffset(0) + , m_oldMaximumItemOffset(0) + , m_skipAutoScrollForRubberBand(false) + , m_rubberBand(nullptr) + , m_tapAndHoldIndicator(nullptr) + , m_mousePos() + , m_autoScrollIncrement(0) + , m_autoScrollTimer(nullptr) + , m_header(nullptr) + , m_headerWidget(nullptr) + , m_indicatorAnimation(nullptr) + , m_dropIndicator() + , m_sizeHintResolver(nullptr) { setAcceptHoverEvents(true); setAcceptTouchEvents(true); @@ -106,8 +106,7 @@ KItemListView::KItemListView(QGraphicsWidget* parent) : m_layouter = new KItemListViewLayouter(m_sizeHintResolver, this); m_animation = new KItemListViewAnimation(this); - connect(m_animation, &KItemListViewAnimation::finished, - this, &KItemListView::slotAnimationFinished); + connect(m_animation, &KItemListViewAnimation::finished, this, &KItemListView::slotAnimationFinished); m_rubberBand = new KItemListRubberBand(this); connect(m_rubberBand, &KItemListRubberBand::activationChanged, this, &KItemListView::slotRubberBandActivationChanged); @@ -137,7 +136,6 @@ KItemListView::KItemListView(QGraphicsWidget* parent) : #ifndef QT_NO_ACCESSIBILITY QAccessible::installFactory(accessibleInterfaceFactory); #endif - } KItemListView::~KItemListView() @@ -218,7 +216,7 @@ int KItemListView::maximumVisibleItems() const return m_layouter->maximumVisibleItems(); } -void KItemListView::setVisibleRoles(const QList<QByteArray>& roles) +void KItemListView::setVisibleRoles(const QList<QByteArray> &roles) { const QList<QByteArray> previousRoles = m_visibleRoles; m_visibleRoles = roles; @@ -233,7 +231,7 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles) if (!m_headerWidget->automaticColumnResizing()) { // The column-width of new roles are still 0. Apply the preferred // column-width as default with. - for (const QByteArray& role : qAsConst(m_visibleRoles)) { + for (const QByteArray &role : qAsConst(m_visibleRoles)) { if (m_headerWidget->columnWidth(role) == 0) { const qreal width = m_headerWidget->preferredColumnWidth(role); m_headerWidget->setColumnWidth(role, width); @@ -244,14 +242,13 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles) } } - const bool alternateBackgroundsChanged = m_itemSize.isEmpty() && - ((roles.count() > 1 && previousRoles.count() <= 1) || - (roles.count() <= 1 && previousRoles.count() > 1)); + const bool alternateBackgroundsChanged = + m_itemSize.isEmpty() && ((roles.count() > 1 && previousRoles.count() <= 1) || (roles.count() <= 1 && previousRoles.count() > 1)); - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); - KItemListWidget* widget = it.value(); + KItemListWidget *widget = it.value(); widget->setVisibleRoles(roles); if (alternateBackgroundsChanged) { updateAlternateBackgroundForWidget(widget); @@ -289,7 +286,7 @@ void KItemListView::setEnabledSelectionToggles(bool enabled) if (m_enabledSelectionToggles != enabled) { m_enabledSelectionToggles = enabled; - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); it.value()->setEnabledSelectionToggle(enabled); @@ -302,23 +299,23 @@ bool KItemListView::enabledSelectionToggles() const return m_enabledSelectionToggles; } -KItemListController* KItemListView::controller() const +KItemListController *KItemListView::controller() const { return m_controller; } -KItemModelBase* KItemListView::model() const +KItemModelBase *KItemListView::model() const { return m_model; } -void KItemListView::setWidgetCreator(KItemListWidgetCreatorBase* widgetCreator) +void KItemListView::setWidgetCreator(KItemListWidgetCreatorBase *widgetCreator) { delete m_widgetCreator; m_widgetCreator = widgetCreator; } -KItemListWidgetCreatorBase* KItemListView::widgetCreator() const +KItemListWidgetCreatorBase *KItemListView::widgetCreator() const { if (!m_widgetCreator) { m_widgetCreator = defaultWidgetCreator(); @@ -326,13 +323,13 @@ KItemListWidgetCreatorBase* KItemListView::widgetCreator() const return m_widgetCreator; } -void KItemListView::setGroupHeaderCreator(KItemListGroupHeaderCreatorBase* groupHeaderCreator) +void KItemListView::setGroupHeaderCreator(KItemListGroupHeaderCreatorBase *groupHeaderCreator) { delete m_groupHeaderCreator; m_groupHeaderCreator = groupHeaderCreator; } -KItemListGroupHeaderCreatorBase* KItemListView::groupHeaderCreator() const +KItemListGroupHeaderCreatorBase *KItemListView::groupHeaderCreator() const { if (!m_groupHeaderCreator) { m_groupHeaderCreator = defaultGroupHeaderCreator(); @@ -345,12 +342,12 @@ QSizeF KItemListView::itemSize() const return m_itemSize; } -const KItemListStyleOption& KItemListView::styleOption() const +const KItemListStyleOption &KItemListView::styleOption() const { return m_styleOption; } -void KItemListView::setGeometry(const QRectF& rect) +void KItemListView::setGeometry(const QRectF &rect) { QGraphicsWidget::setGeometry(rect); @@ -365,8 +362,7 @@ void KItemListView::setGeometry(const QRectF& rect) applyAutomaticColumnWidths(); } else { const qreal requiredWidth = columnWidthsSum(); - const QSizeF dynamicItemSize(qMax(newSize.width(), requiredWidth), - m_itemSize.height()); + const QSizeF dynamicItemSize(qMax(newSize.width(), requiredWidth), m_itemSize.height()); m_layouter->setItemSize(dynamicItemSize); } } @@ -386,13 +382,13 @@ qreal KItemListView::verticalPageStep() const return size().height() - headerHeight; } -std::optional<int> KItemListView::itemAt(const QPointF& pos) const +std::optional<int> KItemListView::itemAt(const QPointF &pos) const { - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); - const KItemListWidget* widget = it.value(); + const KItemListWidget *widget = it.value(); const QPointF mappedPos = widget->mapFromItem(this, pos); if (widget->contains(mappedPos) || widget->selectionRect().contains(mappedPos)) { return it.key(); @@ -402,13 +398,13 @@ std::optional<int> KItemListView::itemAt(const QPointF& pos) const return std::nullopt; } -bool KItemListView::isAboveSelectionToggle(int index, const QPointF& pos) const +bool KItemListView::isAboveSelectionToggle(int index, const QPointF &pos) const { if (!m_enabledSelectionToggles) { return false; } - const KItemListWidget* widget = m_visibleItems.value(index); + const KItemListWidget *widget = m_visibleItems.value(index); if (widget) { const QRectF selectionToggleRect = widget->selectionToggleRect(); if (!selectionToggleRect.isEmpty()) { @@ -419,9 +415,9 @@ bool KItemListView::isAboveSelectionToggle(int index, const QPointF& pos) const return false; } -bool KItemListView::isAboveExpansionToggle(int index, const QPointF& pos) const +bool KItemListView::isAboveExpansionToggle(int index, const QPointF &pos) const { - const KItemListWidget* widget = m_visibleItems.value(index); + const KItemListWidget *widget = m_visibleItems.value(index); if (widget) { const QRectF expansionToggleRect = widget->expansionToggleRect(); if (!expansionToggleRect.isEmpty()) { @@ -434,7 +430,7 @@ bool KItemListView::isAboveExpansionToggle(int index, const QPointF& pos) const bool KItemListView::isAboveText(int index, const QPointF &pos) const { - const KItemListWidget* widget = m_visibleItems.value(index); + const KItemListWidget *widget = m_visibleItems.value(index); if (widget) { const QRectF &textRect = widget->textRect(); if (!textRect.isEmpty()) { @@ -455,7 +451,7 @@ int KItemListView::lastVisibleIndex() const return m_layouter->lastVisibleIndex(); } -void KItemListView::calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint) const +void KItemListView::calculateItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, qreal &logicalWidthHint) const { widgetCreator()->calculateItemSizeHints(logicalHeightHints, logicalWidthHint, this); } @@ -509,7 +505,7 @@ QRectF KItemListView::itemContextRect(int index) const { QRectF contextRect; - const KItemListWidget* widget = m_visibleItems.value(index); + const KItemListWidget *widget = m_visibleItems.value(index); if (widget) { contextRect = widget->iconRect() | widget->textRect(); contextRect.translate(itemRect(index).topLeft()); @@ -533,8 +529,7 @@ void KItemListView::scrollToItem(int index) QRectF currentRect = itemRect(index); // Fix for Bug 311099 - View the underscore when using Ctrl + PagDown - currentRect.adjust(-m_styleOption.horizontalMargin, -m_styleOption.verticalMargin, - m_styleOption.horizontalMargin, m_styleOption.verticalMargin); + currentRect.adjust(-m_styleOption.horizontalMargin, -m_styleOption.verticalMargin, m_styleOption.horizontalMargin, m_styleOption.verticalMargin); if (!viewGeometry.contains(currentRect)) { qreal newOffset = scrollOffset(); @@ -593,8 +588,7 @@ void KItemListView::setHeaderVisible(bool visible) { if (visible && !m_headerWidget->isVisible()) { QStyleOptionHeader option; - const QSize headerSize = style()->sizeFromContents(QStyle::CT_HeaderSection, - &option, QSize()); + const QSize headerSize = style()->sizeFromContents(QStyle::CT_HeaderSection, &option, QSize()); m_headerWidget->setPos(0, 0); m_headerWidget->resize(size().width(), headerSize.height()); @@ -602,30 +596,20 @@ void KItemListView::setHeaderVisible(bool visible) m_headerWidget->setColumns(m_visibleRoles); m_headerWidget->setZValue(1); - connect(m_headerWidget, &KItemListHeaderWidget::columnWidthChanged, - this, &KItemListView::slotHeaderColumnWidthChanged); - connect(m_headerWidget, &KItemListHeaderWidget::sidePaddingChanged, - this, &KItemListView::slotSidePaddingChanged); - connect(m_headerWidget, &KItemListHeaderWidget::columnMoved, - this, &KItemListView::slotHeaderColumnMoved); - connect(m_headerWidget, &KItemListHeaderWidget::sortOrderChanged, - this, &KItemListView::sortOrderChanged); - connect(m_headerWidget, &KItemListHeaderWidget::sortRoleChanged, - this, &KItemListView::sortRoleChanged); + connect(m_headerWidget, &KItemListHeaderWidget::columnWidthChanged, this, &KItemListView::slotHeaderColumnWidthChanged); + connect(m_headerWidget, &KItemListHeaderWidget::sidePaddingChanged, this, &KItemListView::slotSidePaddingChanged); + connect(m_headerWidget, &KItemListHeaderWidget::columnMoved, this, &KItemListView::slotHeaderColumnMoved); + connect(m_headerWidget, &KItemListHeaderWidget::sortOrderChanged, this, &KItemListView::sortOrderChanged); + connect(m_headerWidget, &KItemListHeaderWidget::sortRoleChanged, this, &KItemListView::sortRoleChanged); m_layouter->setHeaderHeight(headerSize.height()); m_headerWidget->setVisible(true); } else if (!visible && m_headerWidget->isVisible()) { - disconnect(m_headerWidget, &KItemListHeaderWidget::columnWidthChanged, - this, &KItemListView::slotHeaderColumnWidthChanged); - disconnect(m_headerWidget, &KItemListHeaderWidget::sidePaddingChanged, - this, &KItemListView::slotSidePaddingChanged); - disconnect(m_headerWidget, &KItemListHeaderWidget::columnMoved, - this, &KItemListView::slotHeaderColumnMoved); - disconnect(m_headerWidget, &KItemListHeaderWidget::sortOrderChanged, - this, &KItemListView::sortOrderChanged); - disconnect(m_headerWidget, &KItemListHeaderWidget::sortRoleChanged, - this, &KItemListView::sortRoleChanged); + disconnect(m_headerWidget, &KItemListHeaderWidget::columnWidthChanged, this, &KItemListView::slotHeaderColumnWidthChanged); + disconnect(m_headerWidget, &KItemListHeaderWidget::sidePaddingChanged, this, &KItemListView::slotSidePaddingChanged); + disconnect(m_headerWidget, &KItemListHeaderWidget::columnMoved, this, &KItemListView::slotHeaderColumnMoved); + disconnect(m_headerWidget, &KItemListHeaderWidget::sortOrderChanged, this, &KItemListView::sortOrderChanged); + disconnect(m_headerWidget, &KItemListHeaderWidget::sortRoleChanged, this, &KItemListView::sortRoleChanged); m_layouter->setHeaderHeight(0); m_headerWidget->setVisible(false); @@ -637,18 +621,18 @@ bool KItemListView::isHeaderVisible() const return m_headerWidget->isVisible(); } -KItemListHeader* KItemListView::header() const +KItemListHeader *KItemListView::header() const { return m_header; } -QPixmap KItemListView::createDragPixmap(const KItemSet& indexes) const +QPixmap KItemListView::createDragPixmap(const KItemSet &indexes) const { QPixmap pixmap; if (indexes.count() == 1) { - KItemListWidget* item = m_visibleItems.value(indexes.first()); - QGraphicsView* graphicsView = scene()->views()[0]; + KItemListWidget *item = m_visibleItems.value(indexes.first()); + QGraphicsView *graphicsView = scene()->views()[0]; if (item && graphicsView) { pixmap = item->createDragPixmap(nullptr, graphicsView); } @@ -661,9 +645,9 @@ QPixmap KItemListView::createDragPixmap(const KItemSet& indexes) const return pixmap; } -void KItemListView::editRole(int index, const QByteArray& role) +void KItemListView::editRole(int index, const QByteArray &role) { - KStandardItemListWidget* widget = qobject_cast<KStandardItemListWidget *>(m_visibleItems.value(index)); + KStandardItemListWidget *widget = qobject_cast<KStandardItemListWidget *>(m_visibleItems.value(index)); if (!widget || m_editingRole) { return; } @@ -671,16 +655,13 @@ void KItemListView::editRole(int index, const QByteArray& role) m_editingRole = true; widget->setEditedRole(role); - connect(widget, &KItemListWidget::roleEditingCanceled, - this, &KItemListView::slotRoleEditingCanceled); - connect(widget, &KItemListWidget::roleEditingFinished, - this, &KItemListView::slotRoleEditingFinished); + connect(widget, &KItemListWidget::roleEditingCanceled, this, &KItemListView::slotRoleEditingCanceled); + connect(widget, &KItemListWidget::roleEditingFinished, this, &KItemListView::slotRoleEditingFinished); - connect(this, &KItemListView::scrollOffsetChanged, - widget, &KStandardItemListWidget::finishRoleEditing); + connect(this, &KItemListView::scrollOffsetChanged, widget, &KStandardItemListWidget::finishRoleEditing); } -void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void KItemListView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QGraphicsWidget::paint(painter, option, widget); @@ -709,8 +690,7 @@ void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt } if (m_rubberBand->isActive()) { - QRectF rubberBandRect = QRectF(m_rubberBand->startPosition(), - m_rubberBand->endPosition()).normalized(); + QRectF rubberBandRect = QRectF(m_rubberBand->startPosition(), m_rubberBand->endPosition()).normalized(); const QPointF topLeft = rubberBandRect.topLeft(); if (scrollOrientation() == Qt::Vertical) { @@ -729,8 +709,8 @@ void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt if (m_tapAndHoldIndicator->isActive()) { const QPointF indicatorSize = m_tapAndHoldIndicator->endPosition(); - const QRectF rubberBandRect = QRectF(m_tapAndHoldIndicator->startPosition() - indicatorSize, - (m_tapAndHoldIndicator->startPosition()) + indicatorSize).normalized(); + const QRectF rubberBandRect = + QRectF(m_tapAndHoldIndicator->startPosition() - indicatorSize, (m_tapAndHoldIndicator->startPosition()) + indicatorSize).normalized(); QStyleOptionRubberBand opt; initStyleOption(&opt); opt.shape = QRubberBand::Rectangle; @@ -766,7 +746,7 @@ QVariant KItemListView::itemChange(GraphicsItemChange change, const QVariant &va return QGraphicsItem::itemChange(change, value); } -void KItemListView::setItemSize(const QSizeF& size) +void KItemListView::setItemSize(const QSizeF &size) { const QSizeF previousSize = m_itemSize; if (size == previousSize) { @@ -776,13 +756,9 @@ void KItemListView::setItemSize(const QSizeF& size) // Skip animations when the number of rows or columns // are changed in the grid layout. Although the animation // engine can handle this usecase, it looks obtrusive. - const bool animate = !changesItemGridLayout(m_layouter->size(), - size, - m_layouter->itemMargin()); + const bool animate = !changesItemGridLayout(m_layouter->size(), size, m_layouter->itemMargin()); - const bool alternateBackgroundsChanged = m_alternateBackgrounds && - (( m_itemSize.isEmpty() && !size.isEmpty()) || - (!m_itemSize.isEmpty() && size.isEmpty())); + const bool alternateBackgroundsChanged = m_alternateBackgrounds && ((m_itemSize.isEmpty() && !size.isEmpty()) || (!m_itemSize.isEmpty() && size.isEmpty())); m_itemSize = size; @@ -812,7 +788,7 @@ void KItemListView::setItemSize(const QSizeF& size) onItemSizeChanged(size, previousSize); } -void KItemListView::setStyleOption(const KItemListStyleOption& option) +void KItemListView::setStyleOption(const KItemListStyleOption &option) { if (m_styleOption == option) { return; @@ -827,9 +803,7 @@ void KItemListView::setStyleOption(const KItemListStyleOption& option) // Skip animations when the number of rows or columns // are changed in the grid layout. Although the animation // engine can handle this usecase, it looks obtrusive. - animate = !changesItemGridLayout(m_layouter->size(), - m_layouter->itemSize(), - margin); + animate = !changesItemGridLayout(m_layouter->size(), m_layouter->itemSize(), margin); m_layouter->setItemMargin(margin); } @@ -837,14 +811,13 @@ void KItemListView::setStyleOption(const KItemListStyleOption& option) updateGroupHeaderHeight(); } - if (animate && - (previousOption.maxTextLines != option.maxTextLines || previousOption.maxTextWidth != option.maxTextWidth)) { + if (animate && (previousOption.maxTextLines != option.maxTextLines || previousOption.maxTextWidth != option.maxTextWidth)) { // Animating a change of the maximum text size just results in expensive // temporary eliding and clipping operations and does not look good visually. animate = false; } - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); it.value()->setStyleOption(option); @@ -873,13 +846,12 @@ void KItemListView::setScrollOrientation(Qt::Orientation orientation) m_sizeHintResolver->clearCache(); if (m_grouped) { - QMutableHashIterator<KItemListWidget*, KItemListGroupHeader*> it (m_visibleGroups); + QMutableHashIterator<KItemListWidget *, KItemListGroupHeader *> it(m_visibleGroups); while (it.hasNext()) { it.next(); it.value()->setScrollOrientation(orientation); } updateGroupHeaderHeight(); - } doLayout(NoAnimation); @@ -893,34 +865,34 @@ Qt::Orientation KItemListView::scrollOrientation() const return m_layouter->scrollOrientation(); } -KItemListWidgetCreatorBase* KItemListView::defaultWidgetCreator() const +KItemListWidgetCreatorBase *KItemListView::defaultWidgetCreator() const { return nullptr; } -KItemListGroupHeaderCreatorBase* KItemListView::defaultGroupHeaderCreator() const +KItemListGroupHeaderCreatorBase *KItemListView::defaultGroupHeaderCreator() const { return nullptr; } -void KItemListView::initializeItemListWidget(KItemListWidget* item) +void KItemListView::initializeItemListWidget(KItemListWidget *item) { Q_UNUSED(item) } -bool KItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const +bool KItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray> &changedRoles) const { Q_UNUSED(changedRoles) return true; } -void KItemListView::onControllerChanged(KItemListController* current, KItemListController* previous) +void KItemListView::onControllerChanged(KItemListController *current, KItemListController *previous) { Q_UNUSED(current) Q_UNUSED(previous) } -void KItemListView::onModelChanged(KItemModelBase* current, KItemModelBase* previous) +void KItemListView::onModelChanged(KItemModelBase *current, KItemModelBase *previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -932,7 +904,7 @@ void KItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orie Q_UNUSED(previous) } -void KItemListView::onItemSizeChanged(const QSizeF& current, const QSizeF& previous) +void KItemListView::onItemSizeChanged(const QSizeF ¤t, const QSizeF &previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -944,13 +916,13 @@ void KItemListView::onScrollOffsetChanged(qreal current, qreal previous) Q_UNUSED(previous) } -void KItemListView::onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous) +void KItemListView::onVisibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous) { Q_UNUSED(current) Q_UNUSED(previous) } -void KItemListView::onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) +void KItemListView::onStyleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -974,7 +946,7 @@ void KItemListView::onTransactionEnd() { } -bool KItemListView::event(QEvent* event) +bool KItemListView::event(QEvent *event) { switch (event->type()) { case QEvent::PaletteChange: @@ -996,13 +968,13 @@ bool KItemListView::event(QEvent* event) return QGraphicsWidget::event(event); } -void KItemListView::mousePressEvent(QGraphicsSceneMouseEvent* event) +void KItemListView::mousePressEvent(QGraphicsSceneMouseEvent *event) { m_mousePos = transform().map(event->pos()); event->accept(); } -void KItemListView::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +void KItemListView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { QGraphicsWidget::mouseMoveEvent(event); @@ -1012,13 +984,13 @@ void KItemListView::mouseMoveEvent(QGraphicsSceneMouseEvent* event) } } -void KItemListView::dragEnterEvent(QGraphicsSceneDragDropEvent* event) +void KItemListView::dragEnterEvent(QGraphicsSceneDragDropEvent *event) { event->setAccepted(true); setAutoScroll(true); } -void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent* event) +void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent *event) { QGraphicsWidget::dragMoveEvent(event); @@ -1028,19 +1000,19 @@ void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent* event) } } -void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEvent* event) +void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) { QGraphicsWidget::dragLeaveEvent(event); setAutoScroll(false); } -void KItemListView::dropEvent(QGraphicsSceneDragDropEvent* event) +void KItemListView::dropEvent(QGraphicsSceneDragDropEvent *event) { QGraphicsWidget::dropEvent(event); setAutoScroll(false); } -QList<KItemListWidget*> KItemListView::visibleItemListWidgets() const +QList<KItemListWidget *> KItemListView::visibleItemListWidgets() const { return m_visibleItems.values(); } @@ -1066,7 +1038,7 @@ void KItemListView::updatePalette() } } -void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) +void KItemListView::slotItemsInserted(const KItemRangeList &itemRanges) { if (m_itemSize.isEmpty()) { updatePreferredColumnWidths(itemRanges); @@ -1082,7 +1054,7 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) m_sizeHintResolver->itemsInserted(itemRanges); int previouslyInsertedCount = 0; - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { // range.index is related to the model before anything has been inserted. // As in each loop the current item-range gets inserted the index must // be increased by the already previously inserted items. @@ -1096,7 +1068,7 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) // Determine which visible items must be moved QList<int> itemsToMove; - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); const int visibleItemIndex = it.key(); @@ -1110,7 +1082,7 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) // from the highest index to the lowest index to prevent overlaps when setting the new index. std::sort(itemsToMove.begin(), itemsToMove.end()); for (int i = itemsToMove.count() - 1; i >= 0; --i) { - KItemListWidget* widget = m_visibleItems.value(itemsToMove[i]); + KItemListWidget *widget = m_visibleItems.value(itemsToMove[i]); Q_ASSERT(widget); const int newIndex = widget->index() + count; if (hasMultipleRanges) { @@ -1126,8 +1098,8 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) // the size of the layouter will be decreased before calling doLayout(): This prevents // an unnecessary temporary animation due to the geometry change of the inserted scrollbar. const bool verticalScrollOrientation = (scrollOrientation() == Qt::Vertical); - const bool decreaseLayouterSize = ( verticalScrollOrientation && maximumScrollOffset() > size().height()) || - (!verticalScrollOrientation && maximumScrollOffset() > size().width()); + const bool decreaseLayouterSize = (verticalScrollOrientation && maximumScrollOffset() > size().height()) + || (!verticalScrollOrientation && maximumScrollOffset() > size().width()); if (decreaseLayouterSize) { const int scrollBarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent); @@ -1175,7 +1147,7 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges) } } -void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges) +void KItemListView::slotItemsRemoved(const KItemRangeList &itemRanges) { if (m_itemSize.isEmpty()) { // Don't pass the item-range: The preferred column-widths of @@ -1193,7 +1165,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges) m_sizeHintResolver->itemsRemoved(itemRanges); for (int i = itemRanges.count() - 1; i >= 0; --i) { - const KItemRange& range = itemRanges[i]; + const KItemRange &range = itemRanges[i]; const int index = range.index; const int count = range.count; if (index < 0 || count <= 0) { @@ -1211,7 +1183,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges) // Iterate over a const copy because the container is mutated within the loop // directly and in `recycleWidget()` (https://bugs.kde.org/show_bug.cgi?id=428374) const auto visibleItems = m_visibleItems; - for (KItemListWidget* widget : visibleItems) { + for (KItemListWidget *widget : visibleItems) { const int i = widget->index(); if (i < firstRemovedIndex) { continue; @@ -1248,7 +1220,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges) // order to prevent overlaps when setting the new index. std::sort(itemsToMove.begin(), itemsToMove.end()); for (int i : qAsConst(itemsToMove)) { - KItemListWidget* widget = m_visibleItems.value(i); + KItemListWidget *widget = m_visibleItems.value(i); Q_ASSERT(widget); const int newIndex = i - count; if (hasMultipleRanges) { @@ -1293,7 +1265,7 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges) } } -void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes) +void KItemListView::slotItemsMoved(const KItemRange &itemRange, const QList<int> &movedToIndexes) { m_sizeHintResolver->itemsMoved(itemRange, movedToIndexes); m_layouter->markAsDirty(); @@ -1306,7 +1278,7 @@ void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int> const int lastVisibleMovedIndex = qMin(lastVisibleIndex(), itemRange.index + itemRange.count - 1); for (int index = firstVisibleMovedIndex; index <= lastVisibleMovedIndex; ++index) { - KItemListWidget* widget = m_visibleItems.value(index); + KItemListWidget *widget = m_visibleItems.value(index); if (widget) { updateWidgetProperties(widget, index); initializeItemListWidget(widget); @@ -1317,15 +1289,14 @@ void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int> updateSiblingsInformation(); } -void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges, - const QSet<QByteArray>& roles) +void KItemListView::slotItemsChanged(const KItemRangeList &itemRanges, const QSet<QByteArray> &roles) { const bool updateSizeHints = itemSizeHintUpdateRequired(roles); if (updateSizeHints && m_itemSize.isEmpty()) { updatePreferredColumnWidths(itemRanges); } - for (const KItemRange& itemRange : itemRanges) { + for (const KItemRange &itemRange : itemRanges) { const int index = itemRange.index; const int count = itemRange.count; @@ -1337,7 +1308,7 @@ void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges, // Apply the changed roles to the visible item-widgets const int lastIndex = index + count - 1; for (int i = index; i <= lastIndex; ++i) { - KItemListWidget* widget = m_visibleItems.value(i); + KItemListWidget *widget = m_visibleItems.value(i); if (widget) { widget->setData(m_model->data(i), roles); } @@ -1377,7 +1348,7 @@ void KItemListView::slotGroupedSortingChanged(bool current) // Clear all visible headers. Note that the QHashIterator takes a copy of // m_visibleGroups. Therefore, it remains valid even if items are removed // from m_visibleGroups in recycleGroupHeaderForWidget(). - QHashIterator<KItemListWidget*, KItemListGroupHeader*> it(m_visibleGroups); + QHashIterator<KItemListWidget *, KItemListGroupHeader *> it(m_visibleGroups); while (it.hasNext()) { it.next(); recycleGroupHeaderForWidget(it.key()); @@ -1405,7 +1376,7 @@ void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder pr } } -void KItemListView::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) +void KItemListView::slotSortRoleChanged(const QByteArray ¤t, const QByteArray &previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -1422,12 +1393,12 @@ void KItemListView::slotCurrentChanged(int current, int previous) // In SingleSelection mode (e.g., in the Places Panel), the current item is // always the selected item. It is not necessary to highlight the current item then. if (m_controller->selectionBehavior() != KItemListController::SingleSelection) { - KItemListWidget* previousWidget = m_visibleItems.value(previous, nullptr); + KItemListWidget *previousWidget = m_visibleItems.value(previous, nullptr); if (previousWidget) { previousWidget->setCurrent(false); } - KItemListWidget* currentWidget = m_visibleItems.value(current, nullptr); + KItemListWidget *currentWidget = m_visibleItems.value(current, nullptr); if (currentWidget) { currentWidget->setCurrent(true); } @@ -1438,23 +1409,22 @@ void KItemListView::slotCurrentChanged(int current, int previous) QAccessible::updateAccessibility(&ev); } -void KItemListView::slotSelectionChanged(const KItemSet& current, const KItemSet& previous) +void KItemListView::slotSelectionChanged(const KItemSet ¤t, const KItemSet &previous) { Q_UNUSED(previous) - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); const int index = it.key(); - KItemListWidget* widget = it.value(); + KItemListWidget *widget = it.value(); widget->setSelected(current.contains(index)); } } -void KItemListView::slotAnimationFinished(QGraphicsWidget* widget, - KItemListViewAnimation::AnimationType type) +void KItemListView::slotAnimationFinished(QGraphicsWidget *widget, KItemListViewAnimation::AnimationType type) { - KItemListWidget* itemListWidget = qobject_cast<KItemListWidget*>(widget); + KItemListWidget *itemListWidget = qobject_cast<KItemListWidget *>(widget); Q_ASSERT(itemListWidget); if (type == KItemListViewAnimation::DeleteAnimation) { @@ -1470,8 +1440,7 @@ void KItemListView::slotAnimationFinished(QGraphicsWidget* widget, widgetCreator()->recycle(itemListWidget); } else { const int index = itemListWidget->index(); - const bool invisible = (index < m_layouter->firstVisibleIndex()) || - (index > m_layouter->lastVisibleIndex()); + const bool invisible = (index < m_layouter->firstVisibleIndex()) || (index > m_layouter->lastVisibleIndex()); if (invisible && !m_animation->isStarted(itemListWidget)) { recycleWidget(itemListWidget); } @@ -1490,8 +1459,7 @@ void KItemListView::slotRubberBandActivationChanged(bool active) connect(m_rubberBand, &KItemListRubberBand::endPositionChanged, this, &KItemListView::slotRubberBandPosChanged); m_skipAutoScrollForRubberBand = true; } else { - QRectF rubberBandRect = QRectF(m_rubberBand->startPosition(), - m_rubberBand->endPosition()).normalized(); + QRectF rubberBandRect = QRectF(m_rubberBand->startPosition(), m_rubberBand->endPosition()).normalized(); auto animation = new QVariantAnimation(this); animation->setStartValue(1.0); @@ -1504,7 +1472,7 @@ void KItemListView::slotRubberBandActivationChanged(bool active) curve.addCubicBezierSegment(QPointF(0.4, 0.0), QPointF(1.0, 1.0), QPointF(1.0, 1.0)); animation->setEasingCurve(curve); - connect(animation, &QVariantAnimation::valueChanged, this, [=](const QVariant&) { + connect(animation, &QVariantAnimation::valueChanged, this, [=](const QVariant &) { update(); }); connect(animation, &QVariantAnimation::finished, this, [=]() { @@ -1522,9 +1490,7 @@ void KItemListView::slotRubberBandActivationChanged(bool active) update(); } -void KItemListView::slotHeaderColumnWidthChanged(const QByteArray& role, - qreal currentWidth, - qreal previousWidth) +void KItemListView::slotHeaderColumnWidthChanged(const QByteArray &role, qreal currentWidth, qreal previousWidth) { Q_UNUSED(role) Q_UNUSED(currentWidth) @@ -1545,9 +1511,7 @@ void KItemListView::slotSidePaddingChanged(qreal width) doLayout(NoAnimation); } -void KItemListView::slotHeaderColumnMoved(const QByteArray& role, - int currentIndex, - int previousIndex) +void KItemListView::slotHeaderColumnMoved(const QByteArray &role, int currentIndex, int previousIndex) { Q_ASSERT(m_visibleRoles[previousIndex] == role); @@ -1597,9 +1561,8 @@ void KItemListView::triggerAutoScrolling() // an autoscrolling. const qreal minDiff = 4; // Ignore any autoscrolling if the rubberband is very small - const qreal diff = (scrollOrientation() == Qt::Vertical) - ? m_rubberBand->endPosition().y() - m_rubberBand->startPosition().y() - : m_rubberBand->endPosition().x() - m_rubberBand->startPosition().x(); + const qreal diff = (scrollOrientation() == Qt::Vertical) ? m_rubberBand->endPosition().y() - m_rubberBand->startPosition().y() + : m_rubberBand->endPosition().x() - m_rubberBand->startPosition().x(); if (qAbs(diff) < minDiff || (m_autoScrollIncrement < 0 && diff > 0) || (m_autoScrollIncrement > 0 && diff < 0)) { // The rubberband direction is different from the scroll direction (e.g. the rubberband has // been moved up although the autoscroll direction might be down) @@ -1623,14 +1586,14 @@ void KItemListView::triggerAutoScrolling() void KItemListView::slotGeometryOfGroupHeaderParentChanged() { - KItemListWidget* widget = qobject_cast<KItemListWidget*>(sender()); + KItemListWidget *widget = qobject_cast<KItemListWidget *>(sender()); Q_ASSERT(widget); - KItemListGroupHeader* groupHeader = m_visibleGroups.value(widget); + KItemListGroupHeader *groupHeader = m_visibleGroups.value(widget); Q_ASSERT(groupHeader); updateGroupHeaderLayout(widget); } -void KItemListView::slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value) +void KItemListView::slotRoleEditingCanceled(int index, const QByteArray &role, const QVariant &value) { disconnectRoleEditingSignals(index); @@ -1638,7 +1601,7 @@ void KItemListView::slotRoleEditingCanceled(int index, const QByteArray& role, c Q_EMIT roleEditingCanceled(index, role, value); } -void KItemListView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value) +void KItemListView::slotRoleEditingFinished(int index, const QByteArray &role, const QVariant &value) { disconnectRoleEditingSignals(index); @@ -1646,12 +1609,12 @@ void KItemListView::slotRoleEditingFinished(int index, const QByteArray& role, c Q_EMIT roleEditingFinished(index, role, value); } -void KItemListView::setController(KItemListController* controller) +void KItemListView::setController(KItemListController *controller) { if (m_controller != controller) { - KItemListController* previous = m_controller; + KItemListController *previous = m_controller; if (previous) { - KItemListSelectionManager* selectionManager = previous->selectionManager(); + KItemListSelectionManager *selectionManager = previous->selectionManager(); disconnect(selectionManager, &KItemListSelectionManager::currentChanged, this, &KItemListView::slotCurrentChanged); disconnect(selectionManager, &KItemListSelectionManager::selectionChanged, this, &KItemListView::slotSelectionChanged); } @@ -1659,7 +1622,7 @@ void KItemListView::setController(KItemListController* controller) m_controller = controller; if (controller) { - KItemListSelectionManager* selectionManager = controller->selectionManager(); + KItemListSelectionManager *selectionManager = controller->selectionManager(); connect(selectionManager, &KItemListSelectionManager::currentChanged, this, &KItemListView::slotCurrentChanged); connect(selectionManager, &KItemListSelectionManager::selectionChanged, this, &KItemListView::slotSelectionChanged); } @@ -1668,31 +1631,23 @@ void KItemListView::setController(KItemListController* controller) } } -void KItemListView::setModel(KItemModelBase* model) +void KItemListView::setModel(KItemModelBase *model) { if (m_model == model) { return; } - KItemModelBase* previous = m_model; + KItemModelBase *previous = m_model; if (m_model) { - disconnect(m_model, &KItemModelBase::itemsChanged, - this, &KItemListView::slotItemsChanged); - disconnect(m_model, &KItemModelBase::itemsInserted, - this, &KItemListView::slotItemsInserted); - disconnect(m_model, &KItemModelBase::itemsRemoved, - this, &KItemListView::slotItemsRemoved); - disconnect(m_model, &KItemModelBase::itemsMoved, - this, &KItemListView::slotItemsMoved); - disconnect(m_model, &KItemModelBase::groupsChanged, - this, &KItemListView::slotGroupsChanged); - disconnect(m_model, &KItemModelBase::groupedSortingChanged, - this, &KItemListView::slotGroupedSortingChanged); - disconnect(m_model, &KItemModelBase::sortOrderChanged, - this, &KItemListView::slotSortOrderChanged); - disconnect(m_model, &KItemModelBase::sortRoleChanged, - this, &KItemListView::slotSortRoleChanged); + disconnect(m_model, &KItemModelBase::itemsChanged, this, &KItemListView::slotItemsChanged); + disconnect(m_model, &KItemModelBase::itemsInserted, this, &KItemListView::slotItemsInserted); + disconnect(m_model, &KItemModelBase::itemsRemoved, this, &KItemListView::slotItemsRemoved); + disconnect(m_model, &KItemModelBase::itemsMoved, this, &KItemListView::slotItemsMoved); + disconnect(m_model, &KItemModelBase::groupsChanged, this, &KItemListView::slotGroupsChanged); + disconnect(m_model, &KItemModelBase::groupedSortingChanged, this, &KItemListView::slotGroupedSortingChanged); + disconnect(m_model, &KItemModelBase::sortOrderChanged, this, &KItemListView::slotSortOrderChanged); + disconnect(m_model, &KItemModelBase::sortRoleChanged, this, &KItemListView::slotSortRoleChanged); m_sizeHintResolver->itemsRemoved(KItemRangeList() << KItemRange(0, m_model->count())); } @@ -1702,22 +1657,14 @@ void KItemListView::setModel(KItemModelBase* model) m_grouped = model->groupedSorting(); if (m_model) { - connect(m_model, &KItemModelBase::itemsChanged, - this, &KItemListView::slotItemsChanged); - connect(m_model, &KItemModelBase::itemsInserted, - this, &KItemListView::slotItemsInserted); - connect(m_model, &KItemModelBase::itemsRemoved, - this, &KItemListView::slotItemsRemoved); - connect(m_model, &KItemModelBase::itemsMoved, - this, &KItemListView::slotItemsMoved); - connect(m_model, &KItemModelBase::groupsChanged, - this, &KItemListView::slotGroupsChanged); - connect(m_model, &KItemModelBase::groupedSortingChanged, - this, &KItemListView::slotGroupedSortingChanged); - connect(m_model, &KItemModelBase::sortOrderChanged, - this, &KItemListView::slotSortOrderChanged); - connect(m_model, &KItemModelBase::sortRoleChanged, - this, &KItemListView::slotSortRoleChanged); + connect(m_model, &KItemModelBase::itemsChanged, this, &KItemListView::slotItemsChanged); + connect(m_model, &KItemModelBase::itemsInserted, this, &KItemListView::slotItemsInserted); + connect(m_model, &KItemModelBase::itemsRemoved, this, &KItemListView::slotItemsRemoved); + connect(m_model, &KItemModelBase::itemsMoved, this, &KItemListView::slotItemsMoved); + connect(m_model, &KItemModelBase::groupsChanged, this, &KItemListView::slotGroupsChanged); + connect(m_model, &KItemModelBase::groupedSortingChanged, this, &KItemListView::slotGroupedSortingChanged); + connect(m_model, &KItemModelBase::sortOrderChanged, this, &KItemListView::slotSortOrderChanged); + connect(m_model, &KItemModelBase::sortRoleChanged, this, &KItemListView::slotSortRoleChanged); const int itemCount = m_model->count(); if (itemCount > 0) { @@ -1728,7 +1675,7 @@ void KItemListView::setModel(KItemModelBase* model) onModelChanged(model, previous); } -KItemListRubberBand* KItemListView::rubberBand() const +KItemListRubberBand *KItemListView::rubberBand() const { return m_rubberBand; } @@ -1781,7 +1728,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha const QRectF itemBounds = m_layouter->itemRect(i); const QPointF newPos = itemBounds.topLeft(); - KItemListWidget* widget = m_visibleItems.value(i); + KItemListWidget *widget = m_visibleItems.value(i); if (!widget) { if (!reusableItems.isEmpty()) { // Reuse a KItemListWidget instance from an invisible item @@ -1805,8 +1752,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha const int previousIndex = i - changedCount; const QRectF itemRect = m_layouter->itemRect(previousIndex); if (itemRect.isEmpty()) { - const QPointF invisibleOldPos = (scrollOrientation() == Qt::Vertical) - ? QPointF(0, size().height()) : QPointF(size().width(), 0); + const QPointF invisibleOldPos = (scrollOrientation() == Qt::Vertical) ? QPointF(0, size().height()) : QPointF(size().width(), 0); widget->setPos(invisibleOldPos); } else { widget->setPos(itemRect.topLeft()); @@ -1825,7 +1771,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha if (animate) { if (m_animation->isStarted(widget, KItemListViewAnimation::MovingAnimation)) { - m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos); + m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos); applyNewPos = false; } @@ -1910,7 +1856,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha if (m_grouped) { // Update the layout of all visible group headers - QHashIterator<KItemListWidget*, KItemListGroupHeader*> it(m_visibleGroups); + QHashIterator<KItemListWidget *, KItemListGroupHeader *> it(m_visibleGroups); while (it.hasNext()) { it.next(); updateGroupHeaderLayout(it.key()); @@ -1920,9 +1866,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha emitOffsetChanges(); } -QList<int> KItemListView::recycleInvisibleItems(int firstVisibleIndex, - int lastVisibleIndex, - LayoutAnimationHint hint) +QList<int> KItemListView::recycleInvisibleItems(int firstVisibleIndex, int lastVisibleIndex, LayoutAnimationHint hint) { // Determine all items that are completely invisible and might be // reused for items that just got (at least partly) visible. If the @@ -1932,11 +1876,11 @@ QList<int> KItemListView::recycleInvisibleItems(int firstVisibleIndex, QList<int> items; - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); - KItemListWidget* widget = it.value(); + KItemListWidget *widget = it.value(); const int index = widget->index(); const bool invisible = (index < firstVisibleIndex) || (index > lastVisibleIndex); @@ -1961,7 +1905,7 @@ QList<int> KItemListView::recycleInvisibleItems(int firstVisibleIndex, return items; } -bool KItemListView::moveWidget(KItemListWidget* widget,const QPointF& newPos) +bool KItemListView::moveWidget(KItemListWidget *widget, const QPointF &newPos) { if (widget->pos() == newPos) { return false; @@ -2025,9 +1969,9 @@ void KItemListView::emitOffsetChanges() } } -KItemListWidget* KItemListView::createWidget(int index) +KItemListWidget *KItemListView::createWidget(int index) { - KItemListWidget* widget = widgetCreator()->create(this); + KItemListWidget *widget = widgetCreator()->create(this); widget->setFlag(QGraphicsItem::ItemStacksBehindParent); m_visibleItems.insert(index, widget); @@ -2037,7 +1981,7 @@ KItemListWidget* KItemListView::createWidget(int index) return widget; } -void KItemListView::recycleWidget(KItemListWidget* widget) +void KItemListView::recycleWidget(KItemListWidget *widget) { if (m_grouped) { recycleGroupHeaderForWidget(widget); @@ -2050,7 +1994,7 @@ void KItemListView::recycleWidget(KItemListWidget* widget) widgetCreator()->recycle(widget); } -void KItemListView::setWidgetIndex(KItemListWidget* widget, int index) +void KItemListView::setWidgetIndex(KItemListWidget *widget, int index) { const int oldIndex = widget->index(); m_visibleItems.remove(oldIndex); @@ -2062,7 +2006,7 @@ void KItemListView::setWidgetIndex(KItemListWidget* widget, int index) widget->setIndex(index); } -void KItemListView::moveWidgetToIndex(KItemListWidget* widget, int index) +void KItemListView::moveWidgetToIndex(KItemListWidget *widget, int index) { const int oldIndex = widget->index(); const Cell oldCell = m_visibleCells.value(oldIndex); @@ -2071,29 +2015,33 @@ void KItemListView::moveWidgetToIndex(KItemListWidget* widget, int index) const Cell newCell(m_layouter->itemColumn(index), m_layouter->itemRow(index)); const bool vertical = (scrollOrientation() == Qt::Vertical); - const bool updateCell = (vertical && oldCell.row == newCell.row) || - (!vertical && oldCell.column == newCell.column); + const bool updateCell = (vertical && oldCell.row == newCell.row) || (!vertical && oldCell.column == newCell.column); if (updateCell) { m_visibleCells.insert(index, newCell); } } -void KItemListView::setLayouterSize(const QSizeF& size, SizeType sizeType) +void KItemListView::setLayouterSize(const QSizeF &size, SizeType sizeType) { switch (sizeType) { - case LayouterSize: m_layouter->setSize(size); break; - case ItemSize: m_layouter->setItemSize(size); break; - default: break; + case LayouterSize: + m_layouter->setSize(size); + break; + case ItemSize: + m_layouter->setItemSize(size); + break; + default: + break; } } -void KItemListView::updateWidgetProperties(KItemListWidget* widget, int index) +void KItemListView::updateWidgetProperties(KItemListWidget *widget, int index) { widget->setVisibleRoles(m_visibleRoles); updateWidgetColumnWidths(widget); widget->setStyleOption(m_styleOption); - const KItemListSelectionManager* selectionManager = m_controller->selectionManager(); + const KItemListSelectionManager *selectionManager = m_controller->selectionManager(); // In SingleSelection mode (e.g., in the Places Panel), the current item is // always the selected item. It is not necessary to highlight the current item then. @@ -2113,7 +2061,7 @@ void KItemListView::updateWidgetProperties(KItemListWidget* widget, int index) } } -void KItemListView::updateGroupHeaderForWidget(KItemListWidget* widget) +void KItemListView::updateGroupHeaderForWidget(KItemListWidget *widget) { Q_ASSERT(m_grouped); @@ -2125,12 +2073,12 @@ void KItemListView::updateGroupHeaderForWidget(KItemListWidget* widget) return; } - const QList<QPair<int, QVariant> > groups = model()->groups(); + const QList<QPair<int, QVariant>> groups = model()->groups(); if (groups.isEmpty() || !groupHeaderCreator()) { return; } - KItemListGroupHeader* groupHeader = m_visibleGroups.value(widget); + KItemListGroupHeader *groupHeader = m_visibleGroups.value(widget); if (!groupHeader) { groupHeader = groupHeaderCreator()->create(this); groupHeader->setParentItem(widget); @@ -2150,9 +2098,9 @@ void KItemListView::updateGroupHeaderForWidget(KItemListWidget* widget) groupHeader->show(); } -void KItemListView::updateGroupHeaderLayout(KItemListWidget* widget) +void KItemListView::updateGroupHeaderLayout(KItemListWidget *widget) { - KItemListGroupHeader* groupHeader = m_visibleGroups.value(widget); + KItemListGroupHeader *groupHeader = m_visibleGroups.value(widget); Q_ASSERT(groupHeader); const int index = widget->index(); @@ -2175,9 +2123,9 @@ void KItemListView::updateGroupHeaderLayout(KItemListWidget* widget) } } -void KItemListView::recycleGroupHeaderForWidget(KItemListWidget* widget) +void KItemListView::recycleGroupHeaderForWidget(KItemListWidget *widget) { - KItemListGroupHeader* header = m_visibleGroups.value(widget); + KItemListGroupHeader *header = m_visibleGroups.value(widget); if (header) { header->setParentItem(nullptr); groupHeaderCreator()->recycle(header); @@ -2191,7 +2139,7 @@ void KItemListView::updateVisibleGroupHeaders() Q_ASSERT(m_grouped); m_layouter->markAsDirty(); - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); updateGroupHeaderForWidget(it.value()); @@ -2202,7 +2150,7 @@ int KItemListView::groupIndexForItem(int index) const { Q_ASSERT(m_grouped); - const QList<QPair<int, QVariant> > groups = model()->groups(); + const QList<QPair<int, QVariant>> groups = model()->groups(); if (groups.isEmpty()) { return -1; } @@ -2230,14 +2178,14 @@ int KItemListView::groupIndexForItem(int index) const void KItemListView::updateAlternateBackgrounds() { - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); updateAlternateBackgroundForWidget(it.value()); } } -void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget* widget) +void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget *widget) { bool enabled = useAlternateBackgrounds(); if (enabled) { @@ -2246,7 +2194,7 @@ void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget* widget) if (m_grouped) { const int groupIndex = groupIndexForItem(index); if (groupIndex >= 0) { - const QList<QPair<int, QVariant> > groups = model()->groups(); + const QList<QPair<int, QVariant>> groups = model()->groups(); const int indexOfFirstGroupItem = groups[groupIndex].first; const int relativeIndex = index - indexOfFirstGroupItem; enabled = (relativeIndex & 0x1) > 0; @@ -2261,7 +2209,7 @@ bool KItemListView::useAlternateBackgrounds() const return m_alternateBackgrounds && m_itemSize.isEmpty(); } -QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeList& itemRanges) const +QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeList &itemRanges) const { QElapsedTimer timer; timer.start(); @@ -2271,9 +2219,9 @@ QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeLi // Calculate the minimum width for each column that is required // to show the headline unclipped. const QFontMetricsF fontMetrics(m_headerWidget->font()); - const int gripMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderGripMargin); + const int gripMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderGripMargin); const int headerMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderMargin); - for (const QByteArray& visibleRole : qAsConst(m_visibleRoles)) { + for (const QByteArray &visibleRole : qAsConst(m_visibleRoles)) { const QString headerText = m_model->roleDescription(visibleRole); const qreal headerWidth = fontMetrics.horizontalAdvance(headerText) + gripMargin + headerMargin * 2; widths.insert(visibleRole, headerWidth); @@ -2281,15 +2229,15 @@ QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeLi // Calculate the preferred column widths for each item and ignore values // smaller than the width for showing the headline unclipped. - const KItemListWidgetCreatorBase* creator = widgetCreator(); + const KItemListWidgetCreatorBase *creator = widgetCreator(); int calculatedItemCount = 0; bool maxTimeExceeded = false; - for (const KItemRange& itemRange : itemRanges) { + for (const KItemRange &itemRange : itemRanges) { const int startIndex = itemRange.index; const int endIndex = startIndex + itemRange.count - 1; for (int i = startIndex; i <= endIndex; ++i) { - for (const QByteArray& visibleRole : qAsConst(m_visibleRoles)) { + for (const QByteArray &visibleRole : qAsConst(m_visibleRoles)) { qreal maxWidth = widths.value(visibleRole, 0); const qreal width = creator->preferredRoleColumnWidth(visibleRole, i, this); maxWidth = qMax(width, maxWidth); @@ -2317,38 +2265,37 @@ void KItemListView::applyColumnWidthsFromHeader() { // Apply the new size to the layouter const qreal requiredWidth = columnWidthsSum() + m_headerWidget->sidePadding(); - const QSizeF dynamicItemSize(qMax(size().width(), requiredWidth), - m_itemSize.height()); + const QSizeF dynamicItemSize(qMax(size().width(), requiredWidth), m_itemSize.height()); m_layouter->setItemSize(dynamicItemSize); // Update the role sizes for all visible widgets - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); updateWidgetColumnWidths(it.value()); } } -void KItemListView::updateWidgetColumnWidths(KItemListWidget* widget) +void KItemListView::updateWidgetColumnWidths(KItemListWidget *widget) { - for (const QByteArray& role : qAsConst(m_visibleRoles)) { + for (const QByteArray &role : qAsConst(m_visibleRoles)) { widget->setColumnWidth(role, m_headerWidget->columnWidth(role)); } widget->setSidePadding(m_headerWidget->sidePadding()); } -void KItemListView::updatePreferredColumnWidths(const KItemRangeList& itemRanges) +void KItemListView::updatePreferredColumnWidths(const KItemRangeList &itemRanges) { Q_ASSERT(m_itemSize.isEmpty()); const int itemCount = m_model->count(); int rangesItemCount = 0; - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { rangesItemCount += range.count; } if (itemCount == rangesItemCount) { const QHash<QByteArray, qreal> preferredWidths = preferredColumnWidths(itemRanges); - for (const QByteArray& role : qAsConst(m_visibleRoles)) { + for (const QByteArray &role : qAsConst(m_visibleRoles)) { m_headerWidget->setPreferredColumnWidth(role, preferredWidths.value(role)); } } else { @@ -2362,7 +2309,7 @@ void KItemListView::updatePreferredColumnWidths(const KItemRangeList& itemRanges QHashIterator<QByteArray, qreal> it(updatedWidths); while (it.hasNext()) { it.next(); - const QByteArray& role = it.key(); + const QByteArray &role = it.key(); const qreal updatedWidth = it.value(); const qreal currentWidth = m_headerWidget->preferredColumnWidth(role); if (updatedWidth > currentWidth) { @@ -2403,7 +2350,7 @@ void KItemListView::applyAutomaticColumnWidths() // size does not use the available view-size the size of the // first role will get stretched. - for (const QByteArray& role : qAsConst(m_visibleRoles)) { + for (const QByteArray &role : qAsConst(m_visibleRoles)) { const qreal preferredWidth = m_headerWidget->preferredColumnWidth(role); m_headerWidget->setColumnWidth(role, preferredWidth); } @@ -2414,7 +2361,7 @@ void KItemListView::applyAutomaticColumnWidths() qreal requiredWidth = columnWidthsSum() + m_headerWidget->sidePadding() + m_headerWidget->sidePadding(); // Adding the padding a second time so we have the same padding symmetrically on both sides of the view. - // This improves UX, looks better and increases the chances of users figuring out that the padding area can be used for deselecting and dropping files. + // This improves UX, looks better and increases the chances of users figuring out that the padding area can be used for deselecting and dropping files. const qreal availableWidth = size().width(); if (requiredWidth < availableWidth) { // Stretch the first column to use the whole remaining width @@ -2442,7 +2389,7 @@ void KItemListView::applyAutomaticColumnWidths() m_layouter->setItemSize(dynamicItemSize); // Update the role sizes for all visible widgets - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); updateWidgetColumnWidths(it.value()); @@ -2452,7 +2399,7 @@ void KItemListView::applyAutomaticColumnWidths() qreal KItemListView::columnWidthsSum() const { qreal widthsSum = 0; - for (const QByteArray& role : qAsConst(m_visibleRoles)) { + for (const QByteArray &role : qAsConst(m_visibleRoles)) { widthsSum += m_headerWidget->columnWidth(role); } return widthsSum; @@ -2463,9 +2410,7 @@ QRectF KItemListView::headerBoundaries() const return m_headerWidget->isVisible() ? m_headerWidget->geometry() : QRectF(); } -bool KItemListView::changesItemGridLayout(const QSizeF& newGridSize, - const QSizeF& newItemSize, - const QSizeF& newItemMargin) const +bool KItemListView::changesItemGridLayout(const QSizeF &newGridSize, const QSizeF &newItemSize, const QSizeF &newItemMargin) const { if (newItemSize.isEmpty() || newGridSize.isEmpty()) { return false; @@ -2474,26 +2419,18 @@ bool KItemListView::changesItemGridLayout(const QSizeF& newGridSize, if (m_layouter->scrollOrientation() == Qt::Vertical) { const qreal itemWidth = m_layouter->itemSize().width(); if (itemWidth > 0) { - const int newColumnCount = itemsPerSize(newGridSize.width(), - newItemSize.width(), - newItemMargin.width()); + const int newColumnCount = itemsPerSize(newGridSize.width(), newItemSize.width(), newItemMargin.width()); if (m_model->count() > newColumnCount) { - const int oldColumnCount = itemsPerSize(m_layouter->size().width(), - itemWidth, - m_layouter->itemMargin().width()); + const int oldColumnCount = itemsPerSize(m_layouter->size().width(), itemWidth, m_layouter->itemMargin().width()); return oldColumnCount != newColumnCount; } } } else { const qreal itemHeight = m_layouter->itemSize().height(); if (itemHeight > 0) { - const int newRowCount = itemsPerSize(newGridSize.height(), - newItemSize.height(), - newItemMargin.height()); + const int newRowCount = itemsPerSize(newGridSize.height(), newItemSize.height(), newItemMargin.height()); if (m_model->count() > newRowCount) { - const int oldRowCount = itemsPerSize(m_layouter->size().height(), - itemHeight, - m_layouter->itemMargin().height()); + const int oldRowCount = itemsPerSize(m_layouter->size().height(), itemHeight, m_layouter->itemMargin().height()); return oldRowCount != newRowCount; } } @@ -2514,15 +2451,13 @@ bool KItemListView::animateChangedItemCount(int changedItemCount) const return false; } - const int maximum = (scrollOrientation() == Qt::Vertical) - ? m_layouter->size().width() / m_layouter->itemSize().width() - : m_layouter->size().height() / m_layouter->itemSize().height(); + const int maximum = (scrollOrientation() == Qt::Vertical) ? m_layouter->size().width() / m_layouter->itemSize().width() + : m_layouter->size().height() / m_layouter->itemSize().height(); // Only animate if up to 2/3 of a row or column are inserted or removed return changedItemCount <= maximum * 2 / 3; } - -bool KItemListView::scrollBarRequired(const QSizeF& size) const +bool KItemListView::scrollBarRequired(const QSizeF &size) const { const QSizeF oldSize = m_layouter->size(); @@ -2530,16 +2465,15 @@ bool KItemListView::scrollBarRequired(const QSizeF& size) const const qreal maxOffset = m_layouter->maximumScrollOffset(); m_layouter->setSize(oldSize); - return m_layouter->scrollOrientation() == Qt::Vertical ? maxOffset > size.height() - : maxOffset > size.width(); + return m_layouter->scrollOrientation() == Qt::Vertical ? maxOffset > size.height() : maxOffset > size.width(); } -int KItemListView::showDropIndicator(const QPointF& pos) +int KItemListView::showDropIndicator(const QPointF &pos) { - QHashIterator<int, KItemListWidget*> it(m_visibleItems); + QHashIterator<int, KItemListWidget *> it(m_visibleItems); while (it.hasNext()) { it.next(); - const KItemListWidget* widget = it.value(); + const KItemListWidget *widget = it.value(); const QPointF mappedPos = widget->mapFromItem(this, pos); const QRectF rect = itemRect(widget->index()); @@ -2552,7 +2486,7 @@ int KItemListView::showDropIndicator(const QPointF& pos) } } - const bool isAboveItem = (mappedPos.y () < rect.height() / 2); + const bool isAboveItem = (mappedPos.y() < rect.height() / 2); const qreal y = isAboveItem ? rect.top() : rect.bottom(); const QRectF draggingInsertIndicator(rect.left(), y, rect.width(), 1); @@ -2592,7 +2526,7 @@ void KItemListView::updateGroupHeaderHeight() // from m_styleOption. groupHeaderHeight += 2 * m_styleOption.horizontalMargin; groupHeaderMargin = m_styleOption.horizontalMargin; - } else if (m_itemSize.isEmpty()){ + } else if (m_itemSize.isEmpty()) { groupHeaderHeight += 4 * m_styleOption.padding; groupHeaderMargin = m_styleOption.iconSize / 2; } else { @@ -2613,10 +2547,9 @@ void KItemListView::updateSiblingsInformation(int firstIndex, int lastIndex) if (firstIndex < 0 || lastIndex < 0) { firstIndex = m_layouter->firstVisibleIndex(); - lastIndex = m_layouter->lastVisibleIndex(); + lastIndex = m_layouter->lastVisibleIndex(); } else { - const bool isRangeVisible = (firstIndex <= m_layouter->lastVisibleIndex() && - lastIndex >= m_layouter->firstVisibleIndex()); + const bool isRangeVisible = (firstIndex <= m_layouter->lastVisibleIndex() && lastIndex >= m_layouter->firstVisibleIndex()); if (!isRangeVisible) { return; } @@ -2632,7 +2565,7 @@ void KItemListView::updateSiblingsInformation(int firstIndex, int lastIndex) // contain a siblings information which can be used as base. int rootIndex = firstIndex; - KItemListWidget* widget = m_visibleItems.value(firstIndex - 1); + KItemListWidget *widget = m_visibleItems.value(firstIndex - 1); if (!widget) { // There is no visible widget before the range, check whether there // is one after the range: @@ -2685,7 +2618,7 @@ void KItemListView::updateSiblingsInformation(int firstIndex, int lastIndex) if (i >= firstIndex) { // The index represents a visible item. Apply the parent-siblings // and update the sibling of the current item. - KItemListWidget* widget = m_visibleItems.value(i); + KItemListWidget *widget = m_visibleItems.value(i); if (!widget) { continue; } @@ -2734,7 +2667,7 @@ bool KItemListView::hasSiblingSuccessor(int index) const void KItemListView::disconnectRoleEditingSignals(int index) { - KStandardItemListWidget* widget = qobject_cast<KStandardItemListWidget *>(m_visibleItems.value(index)); + KStandardItemListWidget *widget = qobject_cast<KStandardItemListWidget *>(m_visibleItems.value(index)); if (!widget) { return; } @@ -2777,20 +2710,18 @@ int KItemListView::itemsPerSize(qreal size, qreal itemSize, qreal itemMargin) return count; } - - KItemListCreatorBase::~KItemListCreatorBase() { qDeleteAll(m_recycleableWidgets); qDeleteAll(m_createdWidgets); } -void KItemListCreatorBase::addCreatedWidget(QGraphicsWidget* widget) +void KItemListCreatorBase::addCreatedWidget(QGraphicsWidget *widget) { m_createdWidgets.insert(widget); } -void KItemListCreatorBase::pushRecycleableWidget(QGraphicsWidget* widget) +void KItemListCreatorBase::pushRecycleableWidget(QGraphicsWidget *widget) { Q_ASSERT(m_createdWidgets.contains(widget)); m_createdWidgets.remove(widget); @@ -2803,13 +2734,13 @@ void KItemListCreatorBase::pushRecycleableWidget(QGraphicsWidget* widget) } } -QGraphicsWidget* KItemListCreatorBase::popRecycleableWidget() +QGraphicsWidget *KItemListCreatorBase::popRecycleableWidget() { if (m_recycleableWidgets.isEmpty()) { return nullptr; } - QGraphicsWidget* widget = m_recycleableWidgets.takeLast(); + QGraphicsWidget *widget = m_recycleableWidgets.takeLast(); m_createdWidgets.insert(widget); return widget; } @@ -2818,7 +2749,7 @@ KItemListWidgetCreatorBase::~KItemListWidgetCreatorBase() { } -void KItemListWidgetCreatorBase::recycle(KItemListWidget* widget) +void KItemListWidgetCreatorBase::recycle(KItemListWidget *widget) { widget->setParentItem(nullptr); widget->setOpacity(1.0); @@ -2829,9 +2760,8 @@ KItemListGroupHeaderCreatorBase::~KItemListGroupHeaderCreatorBase() { } -void KItemListGroupHeaderCreatorBase::recycle(KItemListGroupHeader* header) +void KItemListGroupHeaderCreatorBase::recycle(KItemListGroupHeader *header) { header->setOpacity(1.0); pushRecycleableWidget(header); } - diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h index 27bddd0d9..e9b4a62dd 100644 --- a/src/kitemviews/kitemlistview.h +++ b/src/kitemviews/kitemlistview.h @@ -57,7 +57,7 @@ class DOLPHIN_EXPORT KItemListView : public QGraphicsWidget Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset) public: - explicit KItemListView(QGraphicsWidget* parent = nullptr); + explicit KItemListView(QGraphicsWidget *parent = nullptr); ~KItemListView() override; /** @@ -83,7 +83,7 @@ public: int maximumVisibleItems() const; - void setVisibleRoles(const QList<QByteArray>& roles); + void setVisibleRoles(const QList<QByteArray> &roles); QList<QByteArray> visibleRoles() const; /** @@ -106,14 +106,14 @@ public: * initialized by KItemListController::setView() and will * result in calling KItemListController::onControllerChanged(). */ - KItemListController* controller() const; + KItemListController *controller() const; /** * @return Model of the item-list. The model gets * initialized by KItemListController::setModel() and will * result in calling KItemListController::onModelChanged(). */ - KItemModelBase* model() const; + KItemModelBase *model() const; /** * Sets the creator that creates a widget showing the @@ -126,8 +126,8 @@ public: * The ownership of the widget creator is transferred to * the item-list view. **/ - void setWidgetCreator(KItemListWidgetCreatorBase* widgetCreator); - KItemListWidgetCreatorBase* widgetCreator() const; + void setWidgetCreator(KItemListWidgetCreatorBase *widgetCreator); + KItemListWidgetCreatorBase *widgetCreator() const; /** * Sets the creator that creates a group header. Usually it is sufficient @@ -139,8 +139,8 @@ public: * The ownership of the gropup header creator is transferred to * the item-list view. **/ - void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase* groupHeaderCreator); - KItemListGroupHeaderCreatorBase* groupHeaderCreator() const; + void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase *groupHeaderCreator); + KItemListGroupHeaderCreatorBase *groupHeaderCreator() const; /** * @return The basic size of all items. The size of an item may be larger than @@ -148,9 +148,9 @@ public: */ QSizeF itemSize() const; - const KItemListStyleOption& styleOption() const; + const KItemListStyleOption &styleOption() const; - void setGeometry(const QRectF& rect) override; + void setGeometry(const QRectF &rect) override; /** * @return The page step which should be used by the vertical scroll bar. @@ -165,10 +165,10 @@ public: * items are considered. std::nullopt is returned if * no item is below the position. */ - std::optional<int> itemAt(const QPointF& pos) const; - bool isAboveSelectionToggle(int index, const QPointF& pos) const; - bool isAboveExpansionToggle(int index, const QPointF& pos) const; - bool isAboveText(int index, const QPointF& pos) const; + std::optional<int> itemAt(const QPointF &pos) const; + bool isAboveSelectionToggle(int index, const QPointF &pos) const; + bool isAboveExpansionToggle(int index, const QPointF &pos) const; + bool isAboveText(int index, const QPointF &pos) const; /** * @return Index of the first item that is at least partly visible. @@ -191,7 +191,7 @@ public: * @note the logical height (width) is actually the * width (height) if the scroll orientation is Qt::Vertical! */ - void calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint) const; + void calculateItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, qreal &logicalWidthHint) const; /** * If set to true, items having child-items can be expanded to show the child-items as @@ -269,20 +269,20 @@ public: * @return Header of the list. The header is also available if it is not shown * (see KItemListView::setHeaderShown()). */ - KItemListHeader* header() const; + KItemListHeader *header() const; /** * @return Pixmap that is used for a drag operation based on the * items given by \a indexes. */ - virtual QPixmap createDragPixmap(const KItemSet& indexes) const; + virtual QPixmap createDragPixmap(const KItemSet &indexes) const; /** * Lets the user edit the role \a role for item with the index \a index. */ - void editRole(int index, const QByteArray& role); + void editRole(int index, const QByteArray &role); - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; Q_SIGNALS: void scrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous); @@ -308,7 +308,7 @@ Q_SIGNALS: * the current sort role. Note that no signal will be emitted if the * sort role of the model has been changed without user interaction. */ - void sortRoleChanged(const QByteArray& current, const QByteArray& previous); + void sortRoleChanged(const QByteArray ¤t, const QByteArray &previous); /** * Is emitted if the user has changed the visible roles by moving a header @@ -316,10 +316,10 @@ Q_SIGNALS: * emitted if the roles have been changed without user interaction by * KItemListView::setVisibleRoles(). */ - void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous); + void visibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous); - void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value); - void roleEditingFinished(int index, const QByteArray& role, const QVariant& value); + 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 @@ -329,8 +329,8 @@ Q_SIGNALS: protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; - void setItemSize(const QSizeF& size); - void setStyleOption(const KItemListStyleOption& option); + void setItemSize(const QSizeF &size); + void setStyleOption(const KItemListStyleOption &option); /** * If the scroll-orientation is vertical, the items are ordered @@ -346,7 +346,7 @@ protected: * @return New instance of the widget-creator that should be used per * default. */ - virtual KItemListWidgetCreatorBase* defaultWidgetCreator() const; + virtual KItemListWidgetCreatorBase *defaultWidgetCreator() const; /** * Factory method for creating a default group-header-creator. The method will be used @@ -354,13 +354,13 @@ protected: * @return New instance of the group-header-creator that should be used per * default. */ - virtual KItemListGroupHeaderCreatorBase* defaultGroupHeaderCreator() const; + virtual KItemListGroupHeaderCreatorBase *defaultGroupHeaderCreator() const; /** * Is called when creating a new KItemListWidget instance and allows derived * classes to do a custom initialization. */ - virtual void initializeItemListWidget(KItemListWidget* item); + virtual void initializeItemListWidget(KItemListWidget *item); /** * @return True if at least one of the changed roles \p changedRoles might result @@ -370,52 +370,50 @@ protected: * to return false in case if a role-change will not result in a changed * item-size hint. */ - virtual bool itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const; + virtual bool itemSizeHintUpdateRequired(const QSet<QByteArray> &changedRoles) const; - virtual void onControllerChanged(KItemListController* current, KItemListController* previous); - virtual void onModelChanged(KItemModelBase* current, KItemModelBase* previous); + virtual void onControllerChanged(KItemListController *current, KItemListController *previous); + virtual void onModelChanged(KItemModelBase *current, KItemModelBase *previous); virtual void onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous); - virtual void onItemSizeChanged(const QSizeF& current, const QSizeF& previous); + virtual void onItemSizeChanged(const QSizeF ¤t, const QSizeF &previous); virtual void onScrollOffsetChanged(qreal current, qreal previous); - virtual void onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous); - virtual void onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous); + virtual void onVisibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous); + virtual void onStyleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous); virtual void onHighlightEntireRowChanged(bool highlightEntireRow); virtual void onSupportsItemExpandingChanged(bool supportsExpanding); virtual void onTransactionBegin(); virtual void onTransactionEnd(); - bool event(QEvent* event) override; - void mousePressEvent(QGraphicsSceneMouseEvent* event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; - void dragEnterEvent(QGraphicsSceneDragDropEvent* event) override; - void dragMoveEvent(QGraphicsSceneDragDropEvent* event) override; - void dragLeaveEvent(QGraphicsSceneDragDropEvent* event) override; - void dropEvent(QGraphicsSceneDragDropEvent* event) override; + bool event(QEvent *event) override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override; + void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override; + void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override; + void dropEvent(QGraphicsSceneDragDropEvent *event) override; - QList<KItemListWidget*> visibleItemListWidgets() const; + QList<KItemListWidget *> visibleItemListWidgets() const; virtual void updateFont(); virtual void updatePalette(); protected Q_SLOTS: - virtual void slotItemsInserted(const KItemRangeList& itemRanges); - virtual void slotItemsRemoved(const KItemRangeList& itemRanges); - virtual void slotItemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes); - virtual void slotItemsChanged(const KItemRangeList& itemRanges, - const QSet<QByteArray>& roles); + virtual void slotItemsInserted(const KItemRangeList &itemRanges); + virtual void slotItemsRemoved(const KItemRangeList &itemRanges); + virtual void slotItemsMoved(const KItemRange &itemRange, const QList<int> &movedToIndexes); + virtual void slotItemsChanged(const KItemRangeList &itemRanges, const QSet<QByteArray> &roles); virtual void slotGroupsChanged(); virtual void slotGroupedSortingChanged(bool current); virtual void slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); - virtual void slotSortRoleChanged(const QByteArray& current, const QByteArray& previous); + virtual void slotSortRoleChanged(const QByteArray ¤t, const QByteArray &previous); virtual void slotCurrentChanged(int current, int previous); - virtual void slotSelectionChanged(const KItemSet& current, const KItemSet& previous); + virtual void slotSelectionChanged(const KItemSet ¤t, const KItemSet &previous); private Q_SLOTS: - void slotAnimationFinished(QGraphicsWidget* widget, - KItemListViewAnimation::AnimationType type); + void slotAnimationFinished(QGraphicsWidget *widget, KItemListViewAnimation::AnimationType type); void slotRubberBandPosChanged(); void slotRubberBandActivationChanged(bool active); @@ -426,9 +424,7 @@ private Q_SLOTS: * will be turned off as soon as this method has been called at * least once. */ - void slotHeaderColumnWidthChanged(const QByteArray& role, - qreal currentWidth, - qreal previousWidth); + void slotHeaderColumnWidthChanged(const QByteArray &role, qreal currentWidth, qreal previousWidth); void slotSidePaddingChanged(qreal width); @@ -436,9 +432,7 @@ private Q_SLOTS: * Is invoked if a column has been moved by the user. Applies * the moved role to the view. */ - void slotHeaderColumnMoved(const QByteArray& role, - int currentIndex, - int previousIndex); + void slotHeaderColumnMoved(const QByteArray &role, int currentIndex, int previousIndex); /** * Triggers the autoscrolling if autoScroll() is enabled by checking the @@ -455,26 +449,18 @@ private Q_SLOTS: */ void slotGeometryOfGroupHeaderParentChanged(); - void slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value); - void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value); + void slotRoleEditingCanceled(int index, const QByteArray &role, const QVariant &value); + void slotRoleEditingFinished(int index, const QByteArray &role, const QVariant &value); private: - enum LayoutAnimationHint - { - NoAnimation, - Animation - }; + enum LayoutAnimationHint { NoAnimation, Animation }; - enum SizeType - { - LayouterSize, - ItemSize - }; + enum SizeType { LayouterSize, ItemSize }; - void setController(KItemListController* controller); - void setModel(KItemModelBase* model); + void setController(KItemListController *controller); + void setModel(KItemModelBase *model); - KItemListRubberBand* rubberBand() const; + KItemListRubberBand *rubberBand() const; void doLayout(LayoutAnimationHint hint, int changedIndex = 0, int changedCount = 0); @@ -485,9 +471,7 @@ private: * won't be reused. Reusing items is faster in comparison to deleting invisible * items and creating a new instance for visible items. */ - QList<int> recycleInvisibleItems(int firstVisibleIndex, - int lastVisibleIndex, - LayoutAnimationHint hint); + QList<int> recycleInvisibleItems(int firstVisibleIndex, int lastVisibleIndex, LayoutAnimationHint hint); /** * Helper method for doLayout: Starts a moving-animation for the widget to the given @@ -495,19 +479,19 @@ private: * the same row or column, otherwise the create-animation is used instead. * @return True if the moving-animation has been applied. */ - bool moveWidget(KItemListWidget* widget, const QPointF& newPos); + bool moveWidget(KItemListWidget *widget, const QPointF &newPos); void emitOffsetChanges(); - KItemListWidget* createWidget(int index); - void recycleWidget(KItemListWidget* widget); + KItemListWidget *createWidget(int index); + void recycleWidget(KItemListWidget *widget); /** * Changes the index of the widget to \a index and assures a consistent * update for m_visibleItems and m_visibleCells. The cell-information * for the new index will not be updated and be initialized as empty cell. */ - void setWidgetIndex(KItemListWidget* widget, int index); + void setWidgetIndex(KItemListWidget *widget, int index); /** * Changes the index of the widget to \a index. In opposite to @@ -515,36 +499,36 @@ private: * This update gives doLayout() the chance to animate the moving * of the item visually (see moveWidget()). */ - void moveWidgetToIndex(KItemListWidget* widget, int index); + void moveWidgetToIndex(KItemListWidget *widget, int index); /** * Helper method for prepareLayoutForIncreasedItemCount(). */ - void setLayouterSize(const QSizeF& size, SizeType sizeType); + void setLayouterSize(const QSizeF &size, SizeType sizeType); /** * Helper method for createWidget() and setWidgetIndex() to update the properties * of the itemlist widget. */ - void updateWidgetProperties(KItemListWidget* widget, int index); + void updateWidgetProperties(KItemListWidget *widget, int index); /** * Helper method for updateWidgetPropertes() to create or update * the itemlist group-header. */ - void updateGroupHeaderForWidget(KItemListWidget* widget); + void updateGroupHeaderForWidget(KItemListWidget *widget); /** * Updates the position and size of the group-header that belongs * to the itemlist widget \a widget. The given widget must represent * the first item of a group. */ - void updateGroupHeaderLayout(KItemListWidget* widget); + void updateGroupHeaderLayout(KItemListWidget *widget); /** * Recycles the group-header for the widget. */ - void recycleGroupHeaderForWidget(KItemListWidget* widget); + void recycleGroupHeaderForWidget(KItemListWidget *widget); /** * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged() @@ -570,7 +554,7 @@ private: * Updates the alternateBackground-property of the widget dependent * on the state of useAlternateBackgrounds() and the grouping state. */ - void updateAlternateBackgroundForWidget(KItemListWidget* widget); + void updateAlternateBackgroundForWidget(KItemListWidget *widget); /** * @return True if alternate backgrounds should be used for the items. @@ -586,7 +570,7 @@ private: * KItemListView::setItemSize()). Per default an empty hash * is returned. */ - QHash<QByteArray, qreal> preferredColumnWidths(const KItemRangeList& itemRanges) const; + QHash<QByteArray, qreal> preferredColumnWidths(const KItemRangeList &itemRanges) const; /** * Applies the column-widths from m_headerWidget to the layout @@ -597,13 +581,13 @@ private: /** * Applies the column-widths from m_headerWidget to \a widget. */ - void updateWidgetColumnWidths(KItemListWidget* widget); + void updateWidgetColumnWidths(KItemListWidget *widget); /** * Updates the preferred column-widths of m_groupHeaderWidget by * invoking KItemListView::columnWidths(). */ - void updatePreferredColumnWidths(const KItemRangeList& itemRanges); + void updatePreferredColumnWidths(const KItemRangeList &itemRanges); /** * Convenience method for @@ -633,9 +617,7 @@ private: * the new grid- and item-size. Used to determine whether an animation * should be done when applying the new layout. */ - bool changesItemGridLayout(const QSizeF& newGridSize, - const QSizeF& newItemSize, - const QSizeF& newItemMargin) const; + bool changesItemGridLayout(const QSizeF &newGridSize, const QSizeF &newItemSize, const QSizeF &newItemMargin) const; /** * @param changedItemCount Number of inserted or removed items. @@ -650,7 +632,7 @@ private: * when using a size of \p size for the view. Calling the method is rather * expansive as a temporary relayout needs to be done. */ - bool scrollBarRequired(const QSizeF& size) const; + bool scrollBarRequired(const QSizeF &size) const; /** * Shows a drop-indicator between items dependent on the given @@ -659,7 +641,7 @@ private: * @return Index of the item where the dropping is done. An index of -1 * indicates that the item has been dropped after the last item. */ - int showDropIndicator(const QPointF& pos); + int showDropIndicator(const QPointF &pos); void hideDropIndicator(); /** @@ -721,28 +703,35 @@ private: LayoutAnimationHint m_endTransactionAnimationHint; QSizeF m_itemSize; - KItemListController* m_controller; - KItemModelBase* m_model; + KItemListController *m_controller; + KItemModelBase *m_model; QList<QByteArray> m_visibleRoles; - mutable KItemListWidgetCreatorBase* m_widgetCreator; - mutable KItemListGroupHeaderCreatorBase* m_groupHeaderCreator; + mutable KItemListWidgetCreatorBase *m_widgetCreator; + mutable KItemListGroupHeaderCreatorBase *m_groupHeaderCreator; KItemListStyleOption m_styleOption; - QHash<int, KItemListWidget*> m_visibleItems; - QHash<KItemListWidget*, KItemListGroupHeader*> m_visibleGroups; + QHash<int, KItemListWidget *> m_visibleItems; + QHash<KItemListWidget *, KItemListGroupHeader *> m_visibleGroups; - struct Cell - { - Cell() : column(-1), row(-1) {} - Cell(int c, int r) : column(c), row(r) {} + struct Cell { + Cell() + : column(-1) + , row(-1) + { + } + Cell(int c, int r) + : column(c) + , row(r) + { + } int column; int row; }; QHash<int, Cell> m_visibleCells; int m_scrollBarExtent; - KItemListViewLayouter* m_layouter; - KItemListViewAnimation* m_animation; + KItemListViewLayouter *m_layouter; + KItemListViewAnimation *m_animation; qreal m_oldScrollOffset; qreal m_oldMaximumScrollOffset; @@ -750,17 +739,17 @@ private: qreal m_oldMaximumItemOffset; bool m_skipAutoScrollForRubberBand; - KItemListRubberBand* m_rubberBand; - KItemListRubberBand* m_tapAndHoldIndicator; + KItemListRubberBand *m_rubberBand; + KItemListRubberBand *m_tapAndHoldIndicator; QPointF m_mousePos; int m_autoScrollIncrement; - QTimer* m_autoScrollTimer; + QTimer *m_autoScrollTimer; - KItemListHeader* m_header; - KItemListHeaderWidget* m_headerWidget; + KItemListHeader *m_header; + KItemListHeaderWidget *m_headerWidget; - QPropertyAnimation* m_indicatorAnimation; + QPropertyAnimation *m_indicatorAnimation; // When dragging items into the view where the sort-role of the model // is empty, a visual indicator should be shown during dragging where @@ -770,12 +759,12 @@ private: // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator(). QRectF m_dropIndicator; - QList<QVariantAnimation*> m_rubberBandAnimations; + QList<QVariantAnimation *> m_rubberBandAnimations; - KItemListSizeHintResolver* m_sizeHintResolver; + KItemListSizeHintResolver *m_sizeHintResolver; friend class KItemListContainer; // Accesses scrollBarRequired() - friend class KItemListHeader; // Accesses m_headerWidget + friend class KItemListHeader; // Accesses m_headerWidget friend class KItemListController; friend class KItemListControllerTest; friend class KItemListViewAccessible; @@ -794,13 +783,13 @@ public: virtual ~KItemListCreatorBase(); protected: - void addCreatedWidget(QGraphicsWidget* widget); - void pushRecycleableWidget(QGraphicsWidget* widget); - QGraphicsWidget* popRecycleableWidget(); + void addCreatedWidget(QGraphicsWidget *widget); + void pushRecycleableWidget(QGraphicsWidget *widget); + QGraphicsWidget *popRecycleableWidget(); private: - QSet<QGraphicsWidget*> m_createdWidgets; - QList<QGraphicsWidget*> m_recycleableWidgets; + QSet<QGraphicsWidget *> m_createdWidgets; + QList<QGraphicsWidget *> m_recycleableWidgets; }; /** @@ -817,54 +806,51 @@ class DOLPHIN_EXPORT KItemListWidgetCreatorBase : public KItemListCreatorBase public: ~KItemListWidgetCreatorBase() override; - virtual KItemListWidget* create(KItemListView* view) = 0; + virtual KItemListWidget *create(KItemListView *view) = 0; - virtual void recycle(KItemListWidget* widget); + virtual void recycle(KItemListWidget *widget); - virtual void calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const = 0; + virtual void calculateItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, qreal &logicalWidthHint, const KItemListView *view) const = 0; - virtual qreal preferredRoleColumnWidth(const QByteArray& role, - int index, - const KItemListView* view) const = 0; + virtual qreal preferredRoleColumnWidth(const QByteArray &role, int index, const KItemListView *view) const = 0; }; /** * @brief Template class for creating KItemListWidgets. */ -template <class T> +template<class T> class KItemListWidgetCreator : public KItemListWidgetCreatorBase { public: KItemListWidgetCreator(); ~KItemListWidgetCreator() override; - KItemListWidget* create(KItemListView* view) override; + KItemListWidget *create(KItemListView *view) override; - void calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override; + void calculateItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, qreal &logicalWidthHint, const KItemListView *view) const override; + + qreal preferredRoleColumnWidth(const QByteArray &role, int index, const KItemListView *view) const override; - qreal preferredRoleColumnWidth(const QByteArray& role, - int index, - const KItemListView* view) const override; private: - KItemListWidgetInformant* m_informant; + KItemListWidgetInformant *m_informant; }; -template <class T> -KItemListWidgetCreator<T>::KItemListWidgetCreator() : - m_informant(T::createInformant()) +template<class T> +KItemListWidgetCreator<T>::KItemListWidgetCreator() + : m_informant(T::createInformant()) { } -template <class T> +template<class T> KItemListWidgetCreator<T>::~KItemListWidgetCreator() { delete m_informant; } -template <class T> -KItemListWidget* KItemListWidgetCreator<T>::create(KItemListView* view) +template<class T> +KItemListWidget *KItemListWidgetCreator<T>::create(KItemListView *view) { - KItemListWidget* widget = static_cast<KItemListWidget*>(popRecycleableWidget()); + KItemListWidget *widget = static_cast<KItemListWidget *>(popRecycleableWidget()); if (!widget) { widget = new T(m_informant, view); addCreatedWidget(widget); @@ -874,15 +860,15 @@ KItemListWidget* KItemListWidgetCreator<T>::create(KItemListView* view) } template<class T> -void KItemListWidgetCreator<T>::calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const +void KItemListWidgetCreator<T>::calculateItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, + qreal &logicalWidthHint, + const KItemListView *view) const { return m_informant->calculateItemSizeHints(logicalHeightHints, logicalWidthHint, view); } template<class T> -qreal KItemListWidgetCreator<T>::preferredRoleColumnWidth(const QByteArray& role, - int index, - const KItemListView* view) const +qreal KItemListWidgetCreator<T>::preferredRoleColumnWidth(const QByteArray &role, int index, const KItemListView *view) const { return m_informant->preferredRoleColumnWidth(role, index, view); } @@ -899,27 +885,27 @@ class DOLPHIN_EXPORT KItemListGroupHeaderCreatorBase : public KItemListCreatorBa { public: ~KItemListGroupHeaderCreatorBase() override; - virtual KItemListGroupHeader* create(KItemListView* view) = 0; - virtual void recycle(KItemListGroupHeader* header); + virtual KItemListGroupHeader *create(KItemListView *view) = 0; + virtual void recycle(KItemListGroupHeader *header); }; -template <class T> +template<class T> class KItemListGroupHeaderCreator : public KItemListGroupHeaderCreatorBase { public: ~KItemListGroupHeaderCreator() override; - KItemListGroupHeader* create(KItemListView* view) override; + KItemListGroupHeader *create(KItemListView *view) override; }; -template <class T> +template<class T> KItemListGroupHeaderCreator<T>::~KItemListGroupHeaderCreator() { } -template <class T> -KItemListGroupHeader* KItemListGroupHeaderCreator<T>::create(KItemListView* view) +template<class T> +KItemListGroupHeader *KItemListGroupHeaderCreator<T>::create(KItemListView *view) { - KItemListGroupHeader* widget = static_cast<KItemListGroupHeader*>(popRecycleableWidget()); + KItemListGroupHeader *widget = static_cast<KItemListGroupHeader *>(popRecycleableWidget()); if (!widget) { widget = new T(view); addCreatedWidget(widget); diff --git a/src/kitemviews/kitemlistviewaccessible.cpp b/src/kitemviews/kitemlistviewaccessible.cpp index a1afadff4..a75df8b76 100644 --- a/src/kitemviews/kitemlistviewaccessible.cpp +++ b/src/kitemviews/kitemlistviewaccessible.cpp @@ -16,13 +16,13 @@ #include <QGraphicsScene> #include <QGraphicsView> -KItemListView* KItemListViewAccessible::view() const +KItemListView *KItemListViewAccessible::view() const { - return qobject_cast<KItemListView*>(object()); + return qobject_cast<KItemListView *>(object()); } -KItemListViewAccessible::KItemListViewAccessible(KItemListView* view_) : - QAccessibleObject(view_) +KItemListViewAccessible::KItemListViewAccessible(KItemListView *view_) + : QAccessibleObject(view_) { Q_ASSERT(view()); m_cells.resize(childCount()); @@ -37,10 +37,10 @@ KItemListViewAccessible::~KItemListViewAccessible() } } -void* KItemListViewAccessible::interface_cast(QAccessible::InterfaceType type) +void *KItemListViewAccessible::interface_cast(QAccessible::InterfaceType type) { if (type == QAccessible::TableInterface) { - return static_cast<QAccessibleTableInterface*>(this); + return static_cast<QAccessibleTableInterface *>(this); } return nullptr; } @@ -49,7 +49,7 @@ void KItemListViewAccessible::modelReset() { } -QAccessibleInterface* KItemListViewAccessible::cell(int index) const +QAccessibleInterface *KItemListViewAccessible::cell(int index) const { if (index < 0 || index >= view()->model()->count()) { return nullptr; @@ -69,12 +69,12 @@ QAccessibleInterface* KItemListViewAccessible::cell(int index) const return QAccessible::accessibleInterface(idWrapper.id); } -QAccessibleInterface* KItemListViewAccessible::cellAt(int row, int column) const +QAccessibleInterface *KItemListViewAccessible::cellAt(int row, int column) const { return cell(columnCount() * row + column); } -QAccessibleInterface* KItemListViewAccessible::caption() const +QAccessibleInterface *KItemListViewAccessible::caption() const { return nullptr; } @@ -128,9 +128,9 @@ QString KItemListViewAccessible::rowDescription(int) const return QString(); } -QList<QAccessibleInterface*> KItemListViewAccessible::selectedCells() const +QList<QAccessibleInterface *> KItemListViewAccessible::selectedCells() const { - QList<QAccessibleInterface*> cells; + QList<QAccessibleInterface *> cells; const auto items = view()->controller()->selectionManager()->selectedItems(); cells.reserve(items.count()); for (int index : items) { @@ -149,7 +149,7 @@ QList<int> KItemListViewAccessible::selectedRows() const return QList<int>(); } -QAccessibleInterface* KItemListViewAccessible::summary() const +QAccessibleInterface *KItemListViewAccessible::summary() const { return nullptr; } @@ -184,8 +184,9 @@ bool KItemListViewAccessible::unselectColumn(int) return true; } -void KItemListViewAccessible::modelChange(QAccessibleTableModelChangeEvent* /*event*/) -{} +void KItemListViewAccessible::modelChange(QAccessibleTableModelChangeEvent * /*event*/) +{ +} QAccessible::Role KItemListViewAccessible::role() const { @@ -198,14 +199,14 @@ QAccessible::State KItemListViewAccessible::state() const return s; } -QAccessibleInterface* KItemListViewAccessible::childAt(int x, int y) const +QAccessibleInterface *KItemListViewAccessible::childAt(int x, int y) const { const QPointF point = QPointF(x, y); const std::optional<int> itemIndex = view()->itemAt(view()->mapFromScene(point)); return child(itemIndex.value_or(-1)); } -QAccessibleInterface* KItemListViewAccessible::parent() const +QAccessibleInterface *KItemListViewAccessible::parent() const { // FIXME: return KItemListContainerAccessible here return nullptr; @@ -216,9 +217,9 @@ int KItemListViewAccessible::childCount() const return view()->model()->count(); } -int KItemListViewAccessible::indexOfChild(const QAccessibleInterface* interface) const +int KItemListViewAccessible::indexOfChild(const QAccessibleInterface *interface) const { - const KItemListAccessibleCell* widget = static_cast<const KItemListAccessibleCell*>(interface); + const KItemListAccessibleCell *widget = static_cast<const KItemListAccessibleCell *>(interface); return widget->index(); } @@ -233,7 +234,7 @@ QRect KItemListViewAccessible::rect() const return QRect(); } - const QGraphicsScene* scene = view()->scene(); + const QGraphicsScene *scene = view()->scene(); if (scene) { const QPoint origin = scene->views().at(0)->mapToGlobal(QPoint(0, 0)); const QRect viewRect = view()->geometry().toRect(); @@ -243,7 +244,7 @@ QRect KItemListViewAccessible::rect() const } } -QAccessibleInterface* KItemListViewAccessible::child(int index) const +QAccessibleInterface *KItemListViewAccessible::child(int index) const { if (index >= 0 && index < childCount()) { return cell(index); @@ -251,25 +252,25 @@ QAccessibleInterface* KItemListViewAccessible::child(int index) const return nullptr; } -KItemListViewAccessible::AccessibleIdWrapper::AccessibleIdWrapper() : - isValid(false), - id(0) +KItemListViewAccessible::AccessibleIdWrapper::AccessibleIdWrapper() + : isValid(false) + , id(0) { } // Table Cell -KItemListAccessibleCell::KItemListAccessibleCell(KItemListView* view, int index) : - m_view(view), - m_index(index) +KItemListAccessibleCell::KItemListAccessibleCell(KItemListView *view, int index) + : m_view(view) + , m_index(index) { Q_ASSERT(index >= 0 && index < view->model()->count()); } -void* KItemListAccessibleCell::interface_cast(QAccessible::InterfaceType type) +void *KItemListAccessibleCell::interface_cast(QAccessible::InterfaceType type) { if (type == QAccessible::TableCellInterface) { - return static_cast<QAccessibleTableCellInterface*>(this); + return static_cast<QAccessibleTableCellInterface *>(this); } return nullptr; } @@ -284,14 +285,14 @@ int KItemListAccessibleCell::rowExtent() const return 1; } -QList<QAccessibleInterface*> KItemListAccessibleCell::rowHeaderCells() const +QList<QAccessibleInterface *> KItemListAccessibleCell::rowHeaderCells() const { - return QList<QAccessibleInterface*>(); + return QList<QAccessibleInterface *>(); } -QList<QAccessibleInterface*> KItemListAccessibleCell::columnHeaderCells() const +QList<QAccessibleInterface *> KItemListAccessibleCell::columnHeaderCells() const { - return QList<QAccessibleInterface*>(); + return QList<QAccessibleInterface *>(); } int KItemListAccessibleCell::columnIndex() const @@ -309,7 +310,7 @@ bool KItemListAccessibleCell::isSelected() const return m_view->controller()->selectionManager()->isSelected(m_index); } -QAccessibleInterface* KItemListAccessibleCell::table() const +QAccessibleInterface *KItemListAccessibleCell::table() const { return QAccessible::queryAccessibleInterface(m_view); } @@ -381,11 +382,11 @@ QString KItemListAccessibleCell::text(QAccessible::Text t) const return QString(); } -void KItemListAccessibleCell::setText(QAccessible::Text, const QString&) +void KItemListAccessibleCell::setText(QAccessible::Text, const QString &) { } -QAccessibleInterface* KItemListAccessibleCell::child(int) const +QAccessibleInterface *KItemListAccessibleCell::child(int) const { return nullptr; } @@ -395,7 +396,7 @@ bool KItemListAccessibleCell::isValid() const return m_view && (m_index >= 0) && (m_index < m_view->model()->count()); } -QAccessibleInterface* KItemListAccessibleCell::childAt(int, int) const +QAccessibleInterface *KItemListAccessibleCell::childAt(int, int) const { return nullptr; } @@ -405,13 +406,13 @@ int KItemListAccessibleCell::childCount() const return 0; } -int KItemListAccessibleCell::indexOfChild(const QAccessibleInterface* child) const +int KItemListAccessibleCell::indexOfChild(const QAccessibleInterface *child) const { Q_UNUSED(child) return -1; } -QAccessibleInterface* KItemListAccessibleCell::parent() const +QAccessibleInterface *KItemListAccessibleCell::parent() const { return QAccessible::queryAccessibleInterface(m_view); } @@ -421,14 +422,14 @@ int KItemListAccessibleCell::index() const return m_index; } -QObject* KItemListAccessibleCell::object() const +QObject *KItemListAccessibleCell::object() const { return nullptr; } // Container Interface -KItemListContainerAccessible::KItemListContainerAccessible(KItemListContainer* container) : - QAccessibleWidget(container) +KItemListContainerAccessible::KItemListContainerAccessible(KItemListContainer *container) + : QAccessibleWidget(container) { } @@ -441,7 +442,7 @@ int KItemListContainerAccessible::childCount() const return 1; } -int KItemListContainerAccessible::indexOfChild(const QAccessibleInterface* child) const +int KItemListContainerAccessible::indexOfChild(const QAccessibleInterface *child) const { if (child->object() == container()->controller()->view()) { return 0; @@ -449,7 +450,7 @@ int KItemListContainerAccessible::indexOfChild(const QAccessibleInterface* child return -1; } -QAccessibleInterface* KItemListContainerAccessible::child(int index) const +QAccessibleInterface *KItemListContainerAccessible::child(int index) const { if (index == 0) { return QAccessible::queryAccessibleInterface(container()->controller()->view()); @@ -457,9 +458,9 @@ QAccessibleInterface* KItemListContainerAccessible::child(int index) const return nullptr; } -const KItemListContainer* KItemListContainerAccessible::container() const +const KItemListContainer *KItemListContainerAccessible::container() const { - return qobject_cast<KItemListContainer*>(object()); + return qobject_cast<KItemListContainer *>(object()); } #endif // QT_NO_ACCESSIBILITY diff --git a/src/kitemviews/kitemlistviewaccessible.h b/src/kitemviews/kitemlistviewaccessible.h index cdef2ccca..628c32fc2 100644 --- a/src/kitemviews/kitemlistviewaccessible.h +++ b/src/kitemviews/kitemlistviewaccessible.h @@ -19,29 +19,29 @@ class KItemListView; class KItemListContainer; -class DOLPHIN_EXPORT KItemListViewAccessible: public QAccessibleObject, public QAccessibleTableInterface +class DOLPHIN_EXPORT KItemListViewAccessible : public QAccessibleObject, public QAccessibleTableInterface { public: - explicit KItemListViewAccessible(KItemListView* view); + explicit KItemListViewAccessible(KItemListView *view); ~KItemListViewAccessible() override; - void* interface_cast(QAccessible::InterfaceType type) override; + void *interface_cast(QAccessible::InterfaceType type) override; QAccessible::Role role() const override; QAccessible::State state() const override; QString text(QAccessible::Text t) const override; QRect rect() const override; - QAccessibleInterface* child(int index) const override; + QAccessibleInterface *child(int index) const override; int childCount() const override; - int indexOfChild(const QAccessibleInterface*) const override; - QAccessibleInterface* childAt(int x, int y) const override; - QAccessibleInterface* parent() const override; + int indexOfChild(const QAccessibleInterface *) const override; + QAccessibleInterface *childAt(int x, int y) const override; + QAccessibleInterface *parent() const override; // Table interface - QAccessibleInterface* cellAt(int row, int column) const override; - QAccessibleInterface* caption() const override; - QAccessibleInterface* summary() const override; + QAccessibleInterface *cellAt(int row, int column) const override; + QAccessibleInterface *caption() const override; + QAccessibleInterface *summary() const override; QString columnDescription(int column) const override; QString rowDescription(int row) const override; int columnCount() const override; @@ -51,7 +51,7 @@ public: int selectedCellCount() const override; int selectedColumnCount() const override; int selectedRowCount() const override; - QList<QAccessibleInterface*> selectedCells() const override; + QList<QAccessibleInterface *> selectedCells() const override; QList<int> selectedColumns() const override; QList<int> selectedRows() const override; bool isColumnSelected(int column) const override; @@ -60,9 +60,9 @@ public: bool selectColumn(int column) override; bool unselectRow(int row) override; bool unselectColumn(int column) override; - void modelChange(QAccessibleTableModelChangeEvent*) override; + void modelChange(QAccessibleTableModelChangeEvent *) override; - KItemListView* view() const; + KItemListView *view() const; protected: virtual void modelReset(); @@ -70,10 +70,11 @@ protected: * Create an QAccessibleTableCellInterface representing the table * cell at the @index. Index is 0-based. */ - inline QAccessibleInterface* cell(int index) const; + inline QAccessibleInterface *cell(int index) const; private: - class AccessibleIdWrapper { + class AccessibleIdWrapper + { public: AccessibleIdWrapper(); bool isValid; @@ -82,37 +83,37 @@ private: mutable QVector<AccessibleIdWrapper> m_cells; }; -class DOLPHIN_EXPORT KItemListAccessibleCell: public QAccessibleInterface, public QAccessibleTableCellInterface +class DOLPHIN_EXPORT KItemListAccessibleCell : public QAccessibleInterface, public QAccessibleTableCellInterface { public: - KItemListAccessibleCell(KItemListView* view, int m_index); + KItemListAccessibleCell(KItemListView *view, int m_index); - void* interface_cast(QAccessible::InterfaceType type) override; - QObject* object() const override; + void *interface_cast(QAccessible::InterfaceType type) override; + QObject *object() const override; bool isValid() const override; QAccessible::Role role() const override; QAccessible::State state() const override; QRect rect() const override; QString text(QAccessible::Text t) const override; - void setText(QAccessible::Text t, const QString& text) override; + void setText(QAccessible::Text t, const QString &text) override; - QAccessibleInterface* child(int index) const override; + QAccessibleInterface *child(int index) const override; int childCount() const override; - QAccessibleInterface* childAt(int x, int y) const override; - int indexOfChild(const QAccessibleInterface*) const override; + QAccessibleInterface *childAt(int x, int y) const override; + int indexOfChild(const QAccessibleInterface *) const override; - QAccessibleInterface* parent() const override; + QAccessibleInterface *parent() const override; bool isExpandable() const; // Cell Interface int columnExtent() const override; - QList<QAccessibleInterface*> columnHeaderCells() const override; + QList<QAccessibleInterface *> columnHeaderCells() const override; int columnIndex() const override; int rowExtent() const override; - QList<QAccessibleInterface*> rowHeaderCells() const override; + QList<QAccessibleInterface *> rowHeaderCells() const override; int rowIndex() const override; bool isSelected() const override; - QAccessibleInterface* table() const override; + QAccessibleInterface *table() const override; inline int index() const; @@ -124,15 +125,15 @@ private: class DOLPHIN_EXPORT KItemListContainerAccessible : public QAccessibleWidget { public: - explicit KItemListContainerAccessible(KItemListContainer* container); + explicit KItemListContainerAccessible(KItemListContainer *container); ~KItemListContainerAccessible() override; - QAccessibleInterface* child(int index) const override; + QAccessibleInterface *child(int index) const override; int childCount() const override; - int indexOfChild(const QAccessibleInterface* child) const override; + int indexOfChild(const QAccessibleInterface *child) const override; private: - const KItemListContainer* container() const; + const KItemListContainer *container() const; }; #endif // QT_NO_ACCESSIBILITY diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index ae721c7e4..25a347517 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -27,28 +27,28 @@ KItemListWidgetInformant::~KItemListWidgetInformant() { } -KItemListWidget::KItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) : - QGraphicsWidget(parent), - m_informant(informant), - m_index(-1), - m_selected(false), - m_current(false), - m_hovered(false), - m_expansionAreaHovered(false), - m_alternateBackground(false), - m_enabledSelectionToggle(false), - m_data(), - m_visibleRoles(), - m_columnWidths(), - m_styleOption(), - m_siblingsInfo(), - m_hoverOpacity(0), - m_hoverCache(nullptr), - m_hoverAnimation(nullptr), - m_hoverSequenceIndex(0), - m_selectionToggle(nullptr), - m_editedRole(), - m_iconSize(-1) +KItemListWidget::KItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent) + : QGraphicsWidget(parent) + , m_informant(informant) + , m_index(-1) + , m_selected(false) + , m_current(false) + , m_hovered(false) + , m_expansionAreaHovered(false) + , m_alternateBackground(false) + , m_enabledSelectionToggle(false) + , m_data() + , m_visibleRoles() + , m_columnWidths() + , m_styleOption() + , m_siblingsInfo() + , m_hoverOpacity(0) + , m_hoverCache(nullptr) + , m_hoverAnimation(nullptr) + , m_hoverSequenceIndex(0) + , m_selectionToggle(nullptr) + , m_editedRole() + , m_iconSize(-1) { connect(&m_hoverSequenceTimer, &QTimer::timeout, this, &KItemListWidget::slotHoverSequenceTimerTimeout); } @@ -79,15 +79,14 @@ int KItemListWidget::index() const return m_index; } -void KItemListWidget::setData(const QHash<QByteArray, QVariant>& data, - const QSet<QByteArray>& roles) +void KItemListWidget::setData(const QHash<QByteArray, QVariant> &data, const QSet<QByteArray> &roles) { clearHoverCache(); if (roles.isEmpty()) { m_data = data; dataChanged(m_data); } else { - for (const QByteArray& role : roles) { + for (const QByteArray &role : roles) { m_data[role] = data[role]; } dataChanged(m_data, roles); @@ -100,7 +99,7 @@ QHash<QByteArray, QVariant> KItemListWidget::data() const return m_data; } -void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void KItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) @@ -112,10 +111,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o if (m_selected && m_editedRole.isEmpty()) { const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0); - drawItemStyleOption(painter, widget, activeState | - QStyle::State_Enabled | - QStyle::State_Selected | - QStyle::State_Item); + drawItemStyleOption(painter, widget, activeState | QStyle::State_Enabled | QStyle::State_Selected | QStyle::State_Item); } if (m_current && m_editedRole.isEmpty()) { @@ -139,10 +135,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o QPainter pixmapPainter(m_hoverCache); const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0); - drawItemStyleOption(&pixmapPainter, widget, activeState | - QStyle::State_Enabled | - QStyle::State_MouseOver | - QStyle::State_Item); + drawItemStyleOption(&pixmapPainter, widget, activeState | QStyle::State_Enabled | QStyle::State_MouseOver | QStyle::State_Item); } const qreal opacity = painter->opacity(); @@ -152,7 +145,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o } } -void KItemListWidget::setVisibleRoles(const QList<QByteArray>& roles) +void KItemListWidget::setVisibleRoles(const QList<QByteArray> &roles) { const QList<QByteArray> previousRoles = m_visibleRoles; m_visibleRoles = roles; @@ -166,8 +159,7 @@ QList<QByteArray> KItemListWidget::visibleRoles() const return m_visibleRoles; } - -void KItemListWidget::setColumnWidth(const QByteArray& role, qreal width) +void KItemListWidget::setColumnWidth(const QByteArray &role, qreal width) { const qreal previousWidth = m_columnWidths.value(role); if (previousWidth != width) { @@ -177,24 +169,26 @@ void KItemListWidget::setColumnWidth(const QByteArray& role, qreal width) } } -qreal KItemListWidget::columnWidth(const QByteArray& role) const +qreal KItemListWidget::columnWidth(const QByteArray &role) const { return m_columnWidths.value(role); } -qreal KItemListWidget::sidePadding() const { +qreal KItemListWidget::sidePadding() const +{ return m_sidePadding; } -void KItemListWidget::setSidePadding(qreal width) { - if (m_sidePadding != width){ +void KItemListWidget::setSidePadding(qreal width) +{ + if (m_sidePadding != width) { m_sidePadding = width; sidePaddingChanged(width); update(); } } -void KItemListWidget::setStyleOption(const KItemListStyleOption& option) +void KItemListWidget::setStyleOption(const KItemListStyleOption &option) { if (m_styleOption == option) { return; @@ -207,7 +201,7 @@ void KItemListWidget::setStyleOption(const KItemListStyleOption& option) update(); } -const KItemListStyleOption& KItemListWidget::styleOption() const +const KItemListStyleOption &KItemListWidget::styleOption() const { return m_styleOption; } @@ -308,7 +302,7 @@ bool KItemListWidget::expansionAreaHovered() const return m_expansionAreaHovered; } -void KItemListWidget::setHoverPosition(const QPointF& pos) +void KItemListWidget::setHoverPosition(const QPointF &pos) { if (m_selectionToggle) { m_selectionToggle->setHovered(selectionToggleRect().contains(pos)); @@ -353,7 +347,7 @@ bool KItemListWidget::enabledSelectionToggle() const return m_enabledSelectionToggle; } -void KItemListWidget::setSiblingsInformation(const QBitArray& siblings) +void KItemListWidget::setSiblingsInformation(const QBitArray &siblings) { const QBitArray previous = m_siblingsInfo; m_siblingsInfo = siblings; @@ -366,7 +360,7 @@ QBitArray KItemListWidget::siblingsInformation() const return m_siblingsInfo; } -void KItemListWidget::setEditedRole(const QByteArray& role) +void KItemListWidget::setEditedRole(const QByteArray &role) { if (m_editedRole != role) { const QByteArray previous = m_editedRole; @@ -394,16 +388,13 @@ int KItemListWidget::iconSize() const return m_iconSize; } -bool KItemListWidget::contains(const QPointF& point) const +bool KItemListWidget::contains(const QPointF &point) const { if (!QGraphicsWidget::contains(point)) { return false; } - return iconRect().contains(point) || - textRect().contains(point) || - expansionToggleRect().contains(point) || - selectionToggleRect().contains(point); + return iconRect().contains(point) || textRect().contains(point) || expansionToggleRect().contains(point) || selectionToggleRect().contains(point); } QRectF KItemListWidget::textFocusRect() const @@ -421,8 +412,7 @@ QRectF KItemListWidget::expansionToggleRect() const return QRectF(); } -QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option, - QWidget* widget) +QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget) { QPixmap pixmap(size().toSize() * widget->devicePixelRatio()); pixmap.setDevicePixelRatio(widget->devicePixelRatio()); @@ -446,23 +436,19 @@ QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option return pixmap; } -void KItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current, - const QSet<QByteArray>& roles) +void KItemListWidget::dataChanged(const QHash<QByteArray, QVariant> ¤t, const QSet<QByteArray> &roles) { Q_UNUSED(current) Q_UNUSED(roles) } -void KItemListWidget::visibleRolesChanged(const QList<QByteArray>& current, - const QList<QByteArray>& previous) +void KItemListWidget::visibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous) { Q_UNUSED(current) Q_UNUSED(previous) } -void KItemListWidget::columnWidthChanged(const QByteArray& role, - qreal current, - qreal previous) +void KItemListWidget::columnWidthChanged(const QByteArray &role, qreal current, qreal previous) { Q_UNUSED(role) Q_UNUSED(current) @@ -474,8 +460,7 @@ void KItemListWidget::sidePaddingChanged(qreal width) Q_UNUSED(width) } -void KItemListWidget::styleOptionChanged(const KItemListStyleOption& current, - const KItemListStyleOption& previous) +void KItemListWidget::styleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous) { Q_UNUSED(previous) @@ -505,13 +490,13 @@ void KItemListWidget::alternateBackgroundChanged(bool enabled) Q_UNUSED(enabled) } -void KItemListWidget::siblingsInformationChanged(const QBitArray& current, const QBitArray& previous) +void KItemListWidget::siblingsInformationChanged(const QBitArray ¤t, const QBitArray &previous) { Q_UNUSED(current) Q_UNUSED(previous) } -void KItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous) +void KItemListWidget::editedRoleChanged(const QByteArray ¤t, const QByteArray &previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -523,13 +508,13 @@ void KItemListWidget::iconSizeChanged(int current, int previous) Q_UNUSED(previous) } -void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) +void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent *event) { QGraphicsWidget::resizeEvent(event); clearHoverCache(); if (m_selectionToggle) { - const QRectF& toggleRect = selectionToggleRect(); + const QRectF &toggleRect = selectionToggleRect(); m_selectionToggle->setPos(toggleRect.topLeft()); m_selectionToggle->resize(toggleRect.size()); } @@ -608,7 +593,7 @@ void KItemListWidget::clearHoverCache() m_hoverCache = nullptr; } -void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QStyle::State styleState) +void KItemListWidget::drawItemStyleOption(QPainter *painter, QWidget *widget, QStyle::State styleState) { QStyleOptionViewItem viewItemOption; initStyleOption(&viewItemOption); @@ -618,4 +603,3 @@ void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QS viewItemOption.rect = selectionRect().toRect(); style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); } - diff --git a/src/kitemviews/kitemlistwidget.h b/src/kitemviews/kitemlistwidget.h index eeaed09c0..4634ecc0d 100644 --- a/src/kitemviews/kitemlistwidget.h +++ b/src/kitemviews/kitemlistwidget.h @@ -35,11 +35,9 @@ public: KItemListWidgetInformant(); virtual ~KItemListWidgetInformant(); - virtual void calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const = 0; + virtual void calculateItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, qreal &logicalWidthHint, const KItemListView *view) const = 0; - virtual qreal preferredRoleColumnWidth(const QByteArray& role, - int index, - const KItemListView* view) const = 0; + virtual qreal preferredRoleColumnWidth(const QByteArray &role, int index, const KItemListView *view) const = 0; }; /** @@ -56,13 +54,13 @@ class DOLPHIN_EXPORT KItemListWidget : public QGraphicsWidget Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize) public: - KItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent); + KItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent); ~KItemListWidget() override; void setIndex(int index); int index() const; - void setData(const QHash<QByteArray, QVariant>& data, const QSet<QByteArray>& roles = QSet<QByteArray>()); + void setData(const QHash<QByteArray, QVariant> &data, const QSet<QByteArray> &roles = QSet<QByteArray>()); QHash<QByteArray, QVariant> data() const; /** @@ -70,23 +68,23 @@ public: * to show the data of the custom model provided by KItemListWidget::data(). * @reimp */ - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - void setVisibleRoles(const QList<QByteArray>& roles); + void setVisibleRoles(const QList<QByteArray> &roles); QList<QByteArray> visibleRoles() const; /** * Sets the width of a role that should be used if the alignment of the content * should be done in columns. */ - void setColumnWidth(const QByteArray& role, qreal width); - qreal columnWidth(const QByteArray& role) const; + void setColumnWidth(const QByteArray &role, qreal width); + qreal columnWidth(const QByteArray &role) const; void setSidePadding(qreal width); qreal sidePadding() const; - void setStyleOption(const KItemListStyleOption& option); - const KItemListStyleOption& styleOption() const; + void setStyleOption(const KItemListStyleOption &option); + const KItemListStyleOption &styleOption() const; // TODO: Hides QGraphicsItem::setSelected()/isSelected(). Replace // this by using the default mechanism. @@ -102,7 +100,7 @@ public: void setExpansionAreaHovered(bool hover); bool expansionAreaHovered() const; - void setHoverPosition(const QPointF& pos); + void setHoverPosition(const QPointF &pos); void setAlternateBackground(bool enable); bool alternateBackground() const; @@ -117,7 +115,7 @@ public: * The sibling information is useful for drawing the branches in * tree views. */ - void setSiblingsInformation(const QBitArray& siblings); + void setSiblingsInformation(const QBitArray &siblings); QBitArray siblingsInformation() const; /** @@ -127,7 +125,7 @@ public: * the role is empty. Derived classes must implement * editedRoleChanged(). */ - void setEditedRole(const QByteArray& role); + void setEditedRole(const QByteArray &role); QByteArray editedRole() const; /** @@ -143,7 +141,7 @@ public: * or KItemListWidget::expansionToggleRect(). * @reimp */ - bool contains(const QPointF& point) const override; + bool contains(const QPointF &point) const override; /** * @return Rectangle for the area that shows the icon. @@ -187,26 +185,26 @@ public: * @return Pixmap that is used when dragging an item. Per default the current state of the * widget is returned as pixmap. */ - virtual QPixmap createDragPixmap(const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr); + virtual QPixmap createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr); Q_SIGNALS: - void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value); - void roleEditingFinished(int index, const QByteArray& role, const QVariant& value); + void roleEditingCanceled(int index, const QByteArray &role, const QVariant &value); + void roleEditingFinished(int index, const QByteArray &role, const QVariant &value); protected: - virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>()); - virtual void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous); - virtual void columnWidthChanged(const QByteArray& role, qreal current, qreal previous); + virtual void dataChanged(const QHash<QByteArray, QVariant> ¤t, const QSet<QByteArray> &roles = QSet<QByteArray>()); + virtual void visibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous); + virtual void columnWidthChanged(const QByteArray &role, qreal current, qreal previous); virtual void sidePaddingChanged(qreal width); - virtual void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous); + virtual void styleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous); virtual void currentChanged(bool current); virtual void selectedChanged(bool selected); virtual void hoveredChanged(bool hovered); virtual void alternateBackgroundChanged(bool enabled); - virtual void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous); - virtual void editedRoleChanged(const QByteArray& current, const QByteArray& previous); + virtual void siblingsInformationChanged(const QBitArray ¤t, const QBitArray &previous); + virtual void editedRoleChanged(const QByteArray ¤t, const QByteArray &previous); virtual void iconSizeChanged(int current, int previous); - void resizeEvent(QGraphicsSceneResizeEvent* event) override; + void resizeEvent(QGraphicsSceneResizeEvent *event) override; void clearHoverCache(); /** @@ -234,7 +232,7 @@ protected: int hoverSequenceIndex() const; - const KItemListWidgetInformant* informant() const; + const KItemListWidgetInformant *informant() const; private Q_SLOTS: void slotHoverAnimationFinished(); @@ -243,12 +241,12 @@ private Q_SLOTS: private: void initializeSelectionToggle(); void setHoverOpacity(qreal opacity); - void drawItemStyleOption(QPainter* painter, QWidget* widget, QStyle::State styleState); + void drawItemStyleOption(QPainter *painter, QWidget *widget, QStyle::State styleState); private: Q_PROPERTY(qreal hoverOpacity READ hoverOpacity WRITE setHoverOpacity) - KItemListWidgetInformant* m_informant; + KItemListWidgetInformant *m_informant; int m_index; bool m_selected; bool m_current; @@ -264,23 +262,21 @@ private: QBitArray m_siblingsInfo; qreal m_hoverOpacity; - mutable QPixmap* m_hoverCache; - QPropertyAnimation* m_hoverAnimation; + mutable QPixmap *m_hoverCache; + QPropertyAnimation *m_hoverAnimation; int m_hoverSequenceIndex; QTimer m_hoverSequenceTimer; - KItemListSelectionToggle* m_selectionToggle; + KItemListSelectionToggle *m_selectionToggle; QByteArray m_editedRole; int m_iconSize; }; -inline const KItemListWidgetInformant* KItemListWidget::informant() const +inline const KItemListWidgetInformant *KItemListWidget::informant() const { return m_informant; } #endif - - diff --git a/src/kitemviews/kitemmodelbase.cpp b/src/kitemviews/kitemmodelbase.cpp index 5c6141ce2..e302d6093 100644 --- a/src/kitemviews/kitemmodelbase.cpp +++ b/src/kitemviews/kitemmodelbase.cpp @@ -8,19 +8,19 @@ #include "kitemmodelbase.h" -KItemModelBase::KItemModelBase(QObject* parent) : - QObject(parent), - m_groupedSorting(false), - m_sortRole(), - m_sortOrder(Qt::AscendingOrder) +KItemModelBase::KItemModelBase(QObject *parent) + : QObject(parent) + , m_groupedSorting(false) + , m_sortRole() + , m_sortOrder(Qt::AscendingOrder) { } -KItemModelBase::KItemModelBase(const QByteArray& sortRole, QObject* parent) : - QObject(parent), - m_groupedSorting(false), - m_sortRole(sortRole), - m_sortOrder(Qt::AscendingOrder) +KItemModelBase::KItemModelBase(const QByteArray &sortRole, QObject *parent) + : QObject(parent) + , m_groupedSorting(false) + , m_sortRole(sortRole) + , m_sortOrder(Qt::AscendingOrder) { } @@ -49,7 +49,7 @@ bool KItemModelBase::groupedSorting() const return m_groupedSorting; } -void KItemModelBase::setSortRole(const QByteArray& role, bool resortItems) +void KItemModelBase::setSortRole(const QByteArray &role, bool resortItems) { if (role != m_sortRole) { const QByteArray previous = m_sortRole; @@ -74,14 +74,14 @@ void KItemModelBase::setSortOrder(Qt::SortOrder order) } } -QString KItemModelBase::roleDescription(const QByteArray& role) const +QString KItemModelBase::roleDescription(const QByteArray &role) const { return role; } -QList<QPair<int, QVariant> > KItemModelBase::groups() const +QList<QPair<int, QVariant>> KItemModelBase::groups() const { - return QList<QPair<int, QVariant> >(); + return QList<QPair<int, QVariant>>(); } bool KItemModelBase::setExpanded(int index, bool expanded) @@ -109,13 +109,13 @@ int KItemModelBase::expandedParentsCount(int index) const return 0; } -QMimeData* KItemModelBase::createMimeData(const KItemSet& indexes) const +QMimeData *KItemModelBase::createMimeData(const KItemSet &indexes) const { Q_UNUSED(indexes) return nullptr; } -int KItemModelBase::indexForKeyboardSearch(const QString& text, int startFromIndex) const +int KItemModelBase::indexForKeyboardSearch(const QString &text, int startFromIndex) const { Q_UNUSED(text) Q_UNUSED(startFromIndex) @@ -138,7 +138,7 @@ void KItemModelBase::onGroupedSortingChanged(bool current) Q_UNUSED(current) } -void KItemModelBase::onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems) +void KItemModelBase::onSortRoleChanged(const QByteArray ¤t, const QByteArray &previous, bool resortItems) { Q_UNUSED(current) Q_UNUSED(previous) diff --git a/src/kitemviews/kitemmodelbase.h b/src/kitemviews/kitemmodelbase.h index 2ce4c9fd3..4e1fd8a8f 100644 --- a/src/kitemviews/kitemmodelbase.h +++ b/src/kitemviews/kitemmodelbase.h @@ -40,8 +40,8 @@ class DOLPHIN_EXPORT KItemModelBase : public QObject Q_OBJECT public: - explicit KItemModelBase(QObject* parent = nullptr); - explicit KItemModelBase(const QByteArray& sortRole, QObject* parent = nullptr); + explicit KItemModelBase(QObject *parent = nullptr); + explicit KItemModelBase(const QByteArray &sortRole, QObject *parent = nullptr); ~KItemModelBase() override; /** @return The number of items. */ @@ -56,7 +56,7 @@ public: * The default implementation does not set the data, and will always return * false. */ - virtual bool setData(int index, const QHash<QByteArray, QVariant>& values); + virtual bool setData(int index, const QHash<QByteArray, QVariant> &values); /** * Enables/disables the grouped sorting. The method KItemModelBase::onGroupedSortingChanged() will be @@ -73,7 +73,7 @@ public: * signal sortRoleChanged() will be emitted. * The implementation should resort only if \a resortItems is true. */ - void setSortRole(const QByteArray& role, bool resortItems = true); + void setSortRole(const QByteArray &role, bool resortItems = true); QByteArray sortRole() const; /** @@ -88,7 +88,7 @@ public: * @return Translated description for the \p role. The description is e.g. used * for the header in KItemListView. */ - virtual QString roleDescription(const QByteArray& role) const; + virtual QString roleDescription(const QByteArray &role) const; /** * @return List of group headers. Each list-item consists of the index of the item @@ -96,7 +96,7 @@ public: * as QVariant. The value is shown by an instance of KItemListGroupHeader. * Per default an empty list is returned. */ - virtual QList<QPair<int, QVariant> > groups() const; + virtual QList<QPair<int, QVariant>> groups() const; /** * Expands the item with the index \a index if \a expanded is true. @@ -136,7 +136,7 @@ public: * caller of this method. The method must be implemented if dragging of * items should be possible. */ - virtual QMimeData* createMimeData(const KItemSet& indexes) const; + virtual QMimeData *createMimeData(const KItemSet &indexes) const; /** * @return Reimplement this to return the index for the first item @@ -144,7 +144,7 @@ public: * @param text the text which has been typed in through the keyboard * @param startFromIndex the index from which to start searching from */ - virtual int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const; + virtual int indexForKeyboardSearch(const QString &text, int startFromIndex = 0) const; /** * @return True, if the item with the index \a index basically supports dropping. @@ -196,7 +196,7 @@ Q_SIGNALS: * - They don't overlap * - The index of item-range n is smaller than the index of item-range n + 1. */ - void itemsInserted(const KItemRangeList& itemRanges); + void itemsInserted(const KItemRangeList &itemRanges); /** * Is emitted if one or more items have been removed. Each item-range consists @@ -210,7 +210,7 @@ Q_SIGNALS: * - They don't overlap * - The index of item-range n is smaller than the index of item-range n + 1. */ - void itemsRemoved(const KItemRangeList& itemRanges); + void itemsRemoved(const KItemRangeList &itemRanges); /** * Is emitted if one ore more items get moved. @@ -225,9 +225,9 @@ Q_SIGNALS: * This signal implies that the groups might have changed. Therefore, * gropusChanged() is not emitted if this signal is emitted. */ - void itemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes); + void itemsMoved(const KItemRange &itemRange, const QList<int> &movedToIndexes); - void itemsChanged(const KItemRangeList& itemRanges, const QSet<QByteArray>& roles); + void itemsChanged(const KItemRangeList &itemRanges, const QSet<QByteArray> &roles); /** * Is emitted if the groups have changed, even though the order of the @@ -236,7 +236,7 @@ Q_SIGNALS: void groupsChanged(); void groupedSortingChanged(bool current); - void sortRoleChanged(const QByteArray& current, const QByteArray& previous); + void sortRoleChanged(const QByteArray ¤t, const QByteArray &previous); void sortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); protected: @@ -255,7 +255,7 @@ protected: * itemsInserted() signal afterwards. * The implementation should resort only if \a resortItems is true. */ - virtual void onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems = true); + virtual void onSortRoleChanged(const QByteArray ¤t, const QByteArray &previous, bool resortItems = true); /** * Is invoked if the sort order has been changed by KItemModelBase::setSortOrder(). Allows @@ -279,5 +279,3 @@ inline Qt::SortOrder KItemModelBase::sortOrder() const } #endif - - diff --git a/src/kitemviews/kitemrange.h b/src/kitemviews/kitemrange.h index 0ea068062..81d457aaa 100644 --- a/src/kitemviews/kitemrange.h +++ b/src/kitemviews/kitemrange.h @@ -12,37 +12,41 @@ #include <QList> -struct KItemRange -{ +struct KItemRange { KItemRange(int index = 0, int count = 0); int index; int count; - bool operator == (const KItemRange& other) const; + bool operator==(const KItemRange &other) const; }; -inline KItemRange::KItemRange(int index, int count) : - index(index), - count(count) +inline KItemRange::KItemRange(int index, int count) + : index(index) + , count(count) { } -inline bool KItemRange::operator == (const KItemRange& other) const +inline bool KItemRange::operator==(const KItemRange &other) const { return index == other.index && count == other.count; } - class KItemRangeList : public QList<KItemRange> { public: - KItemRangeList() : QList<KItemRange>() {} - explicit KItemRangeList(const QList<KItemRange>& list) : QList<KItemRange>(list) {} + KItemRangeList() + : QList<KItemRange>() + { + } + explicit KItemRangeList(const QList<KItemRange> &list) + : QList<KItemRange>(list) + { + } template<class Container> - static KItemRangeList fromSortedContainer(const Container& container); + static KItemRangeList fromSortedContainer(const Container &container); - KItemRangeList& operator<<(const KItemRange& range) + KItemRangeList &operator<<(const KItemRange &range) { append(range); return *this; @@ -50,7 +54,7 @@ public: }; template<class Container> -KItemRangeList KItemRangeList::fromSortedContainer(const Container& container) +KItemRangeList KItemRangeList::fromSortedContainer(const Container &container) { typename Container::const_iterator it = container.constBegin(); const typename Container::const_iterator end = container.constEnd(); diff --git a/src/kitemviews/kitemset.cpp b/src/kitemviews/kitemset.cpp index 1200bc7a9..b3a9909af 100644 --- a/src/kitemviews/kitemset.cpp +++ b/src/kitemviews/kitemset.cpp @@ -6,7 +6,6 @@ #include "kitemset.h" - KItemSet::iterator KItemSet::insert(int i) { if (m_itemRanges.empty()) { @@ -128,7 +127,7 @@ KItemSet::iterator KItemSet::erase(iterator it) } } -KItemSet KItemSet::operator+(const KItemSet& other) const +KItemSet KItemSet::operator+(const KItemSet &other) const { KItemSet sum; @@ -170,8 +169,7 @@ KItemSet KItemSet::operator+(const KItemSet& other) const count = qMax(count, it2->index + it2->count - index); ++it2; } - } while ((it1 != end1 && it1->index <= index + count) - || (it2 != end2 && it2->index <= index + count)); + } while ((it1 != end1 && it1->index <= index + count) || (it2 != end2 && it2->index <= index + count)); sum.m_itemRanges.append(KItemRange(index, count)); } @@ -180,7 +178,7 @@ KItemSet KItemSet::operator+(const KItemSet& other) const return sum; } -KItemSet KItemSet::operator^(const KItemSet& other) const +KItemSet KItemSet::operator^(const KItemSet &other) const { // We are looking for all ints which are either in *this or in other, // but not in both. @@ -197,14 +195,14 @@ KItemSet KItemSet::operator^(const KItemSet& other) const const QVector<int>::iterator end = rangeBoundaries.end(); QVector<int>::iterator it = begin; - for (const KItemRange& range : qAsConst(m_itemRanges)) { + for (const KItemRange &range : qAsConst(m_itemRanges)) { *it++ = range.index; *it++ = range.index + range.count; } const QVector<int>::iterator middle = it; - for (const KItemRange& range : qAsConst(other.m_itemRanges)) { + for (const KItemRange &range : qAsConst(other.m_itemRanges)) { *it++ = range.index; *it++ = range.index + range.count; } diff --git a/src/kitemviews/kitemset.h b/src/kitemviews/kitemset.h index 2d0137e0f..fd73c0e02 100644 --- a/src/kitemviews/kitemset.h +++ b/src/kitemviews/kitemset.h @@ -4,7 +4,6 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ - #ifndef KITEMSET_H #define KITEMSET_H @@ -33,9 +32,9 @@ class DOLPHIN_EXPORT KItemSet { public: KItemSet(); - KItemSet(const KItemSet& other); + KItemSet(const KItemSet &other); ~KItemSet(); - KItemSet& operator=(const KItemSet& other); + KItemSet &operator=(const KItemSet &other); /** * Returns the number of items in the set. @@ -46,25 +45,25 @@ public: bool isEmpty() const; void clear(); - bool operator==(const KItemSet& other) const; - bool operator!=(const KItemSet& other) const; + bool operator==(const KItemSet &other) const; + bool operator!=(const KItemSet &other) const; class iterator { - iterator(const KItemRangeList::iterator& rangeIt, int offset) : - m_rangeIt(rangeIt), - m_offset(offset) + iterator(const KItemRangeList::iterator &rangeIt, int offset) + : m_rangeIt(rangeIt) + , m_offset(offset) { } public: - iterator(const iterator& other) : - m_rangeIt(other.m_rangeIt), - m_offset(other.m_offset) + iterator(const iterator &other) + : m_rangeIt(other.m_rangeIt) + , m_offset(other.m_offset) { } - iterator& operator=(const iterator& other) + iterator &operator=(const iterator &other) { m_rangeIt = other.m_rangeIt; m_offset = other.m_offset; @@ -78,17 +77,17 @@ public: return m_rangeIt->index + m_offset; } - inline bool operator==(const iterator& other) const + inline bool operator==(const iterator &other) const { return m_rangeIt == other.m_rangeIt && m_offset == other.m_offset; } - inline bool operator!=(const iterator& other) const + inline bool operator!=(const iterator &other) const { return !(*this == other); } - inline iterator& operator++() + inline iterator &operator++() { ++m_offset; @@ -107,7 +106,7 @@ public: return r; } - inline iterator& operator--() + inline iterator &operator--() { if (m_offset == 0) { --m_rangeIt; @@ -134,29 +133,28 @@ public: friend class KItemSet; }; - class const_iterator { - const_iterator(KItemRangeList::const_iterator rangeIt, int offset) : - m_rangeIt(rangeIt), - m_offset(offset) + const_iterator(KItemRangeList::const_iterator rangeIt, int offset) + : m_rangeIt(rangeIt) + , m_offset(offset) { } public: - const_iterator(const const_iterator& other) : - m_rangeIt(other.m_rangeIt), - m_offset(other.m_offset) + const_iterator(const const_iterator &other) + : m_rangeIt(other.m_rangeIt) + , m_offset(other.m_offset) { } - explicit const_iterator(const iterator& other) : - m_rangeIt(other.m_rangeIt), - m_offset(other.m_offset) + explicit const_iterator(const iterator &other) + : m_rangeIt(other.m_rangeIt) + , m_offset(other.m_offset) { } - const_iterator& operator=(const const_iterator& other) + const_iterator &operator=(const const_iterator &other) { m_rangeIt = other.m_rangeIt; m_offset = other.m_offset; @@ -170,17 +168,17 @@ public: return m_rangeIt->index + m_offset; } - inline bool operator==(const const_iterator& other) const + inline bool operator==(const const_iterator &other) const { return m_rangeIt == other.m_rangeIt && m_offset == other.m_offset; } - inline bool operator!=(const const_iterator& other) const + inline bool operator!=(const const_iterator &other) const { return !(*this == other); } - inline const_iterator& operator++() + inline const_iterator &operator++() { ++m_offset; @@ -199,7 +197,7 @@ public: return r; } - inline const_iterator& operator--() + inline const_iterator &operator--() { if (m_offset == 0) { --m_rangeIt; @@ -246,16 +244,16 @@ public: * Returns a new set which contains all items that are contained in this * KItemSet, in \a other, or in both. */ - KItemSet operator+(const KItemSet& other) const; + KItemSet operator+(const KItemSet &other) const; /** * Returns a new set which contains all items that are contained either in * this KItemSet, or in \a other, but not in both (the symmetric difference * of both KItemSets). */ - KItemSet operator^(const KItemSet& other) const; + KItemSet operator^(const KItemSet &other) const; - KItemSet& operator<<(int i); + KItemSet &operator<<(int i); private: /** @@ -282,28 +280,28 @@ private: friend class KItemSetTest; }; -inline KItemSet::KItemSet() : - m_itemRanges() +inline KItemSet::KItemSet() + : m_itemRanges() { } -inline KItemSet::KItemSet(const KItemSet& other) : - m_itemRanges(other.m_itemRanges) +inline KItemSet::KItemSet(const KItemSet &other) + : m_itemRanges(other.m_itemRanges) { } inline KItemSet::~KItemSet() = default; -inline KItemSet& KItemSet::operator=(const KItemSet& other) +inline KItemSet &KItemSet::operator=(const KItemSet &other) { - m_itemRanges=other.m_itemRanges; + m_itemRanges = other.m_itemRanges; return *this; } inline int KItemSet::count() const { int result = 0; - for (const KItemRange& range : qAsConst(m_itemRanges)) { + for (const KItemRange &range : qAsConst(m_itemRanges)) { result += range.count; } return result; @@ -319,12 +317,12 @@ inline void KItemSet::clear() m_itemRanges.clear(); } -inline bool KItemSet::operator==(const KItemSet& other) const +inline bool KItemSet::operator==(const KItemSet &other) const { return m_itemRanges == other.m_itemRanges; } -inline bool KItemSet::operator!=(const KItemSet& other) const +inline bool KItemSet::operator!=(const KItemSet &other) const { return m_itemRanges != other.m_itemRanges; } @@ -403,11 +401,11 @@ inline int KItemSet::first() const inline int KItemSet::last() const { - const KItemRange& lastRange = m_itemRanges.last(); + const KItemRange &lastRange = m_itemRanges.last(); return lastRange.index + lastRange.count - 1; } -inline KItemSet& KItemSet::operator<<(int i) +inline KItemSet &KItemSet::operator<<(int i) { insert(i); return *this; diff --git a/src/kitemviews/kstandarditemlistgroupheader.cpp b/src/kitemviews/kstandarditemlistgroupheader.cpp index 28497ddfc..e8468dacc 100644 --- a/src/kitemviews/kstandarditemlistgroupheader.cpp +++ b/src/kitemviews/kstandarditemlistgroupheader.cpp @@ -11,20 +11,19 @@ #include <KRatingPainter> #include <QPainter> -KStandardItemListGroupHeader::KStandardItemListGroupHeader(QGraphicsWidget* parent) : - KItemListGroupHeader(parent), - m_dirtyCache(true), - m_text(), - m_pixmap() +KStandardItemListGroupHeader::KStandardItemListGroupHeader(QGraphicsWidget *parent) + : KItemListGroupHeader(parent) + , m_dirtyCache(true) + , m_text() + , m_pixmap() { - } KStandardItemListGroupHeader::~KStandardItemListGroupHeader() { } -void KStandardItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void KStandardItemListGroupHeader::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { if (m_dirtyCache) { updateCache(); @@ -32,7 +31,7 @@ void KStandardItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGr KItemListGroupHeader::paint(painter, option, widget); } -void KStandardItemListGroupHeader::paintRole(QPainter* painter, const QRectF& roleBounds, const QColor& color) +void KStandardItemListGroupHeader::paintRole(QPainter *painter, const QRectF &roleBounds, const QColor &color) { if (m_pixmap.isNull()) { painter->setPen(color); @@ -42,7 +41,7 @@ void KStandardItemListGroupHeader::paintRole(QPainter* painter, const QRectF& ro } } -void KStandardItemListGroupHeader::paintSeparator(QPainter* painter, const QColor& color) +void KStandardItemListGroupHeader::paintSeparator(QPainter *painter, const QColor &color) { if (itemIndex() == 0) { // No top- or left-line should be drawn for the first group-header @@ -69,14 +68,14 @@ void KStandardItemListGroupHeader::roleChanged(const QByteArray ¤t, const m_dirtyCache = true; } -void KStandardItemListGroupHeader::dataChanged(const QVariant& current, const QVariant& previous) +void KStandardItemListGroupHeader::dataChanged(const QVariant ¤t, const QVariant &previous) { Q_UNUSED(current) Q_UNUSED(previous) m_dirtyCache = true; } -void KStandardItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent* event) +void KStandardItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent *event) { KItemListGroupHeader::resizeEvent(event); m_dirtyCache = true; @@ -110,4 +109,3 @@ void KStandardItemListGroupHeader::updateCache() m_text = text; } } - diff --git a/src/kitemviews/kstandarditemlistgroupheader.h b/src/kitemviews/kstandarditemlistgroupheader.h index adba00998..ee1df76fb 100644 --- a/src/kitemviews/kstandarditemlistgroupheader.h +++ b/src/kitemviews/kstandarditemlistgroupheader.h @@ -17,17 +17,17 @@ class DOLPHIN_EXPORT KStandardItemListGroupHeader : public KItemListGroupHeader Q_OBJECT public: - explicit KStandardItemListGroupHeader(QGraphicsWidget* parent = nullptr); + explicit KStandardItemListGroupHeader(QGraphicsWidget *parent = nullptr); ~KStandardItemListGroupHeader() override; - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; protected: - void paintRole(QPainter* painter, const QRectF& roleBounds, const QColor& color) override; - void paintSeparator(QPainter* painter, const QColor& color) override; + void paintRole(QPainter *painter, const QRectF &roleBounds, const QColor &color) override; + void paintSeparator(QPainter *painter, const QColor &color) override; void roleChanged(const QByteArray ¤t, const QByteArray &previous) override; - void dataChanged(const QVariant& current, const QVariant& previous) override; - void resizeEvent(QGraphicsSceneResizeEvent* event) override; + void dataChanged(const QVariant ¤t, const QVariant &previous) override; + void resizeEvent(QGraphicsSceneResizeEvent *event) override; private: void updateCache(); @@ -38,5 +38,3 @@ private: QPixmap m_pixmap; }; #endif - - diff --git a/src/kitemviews/kstandarditemlistview.cpp b/src/kitemviews/kstandarditemlistview.cpp index 0ba23e654..f94aed0b5 100644 --- a/src/kitemviews/kstandarditemlistview.cpp +++ b/src/kitemviews/kstandarditemlistview.cpp @@ -10,9 +10,9 @@ #include <KIconLoader> -KStandardItemListView::KStandardItemListView(QGraphicsWidget* parent) : - KItemListView(parent), - m_itemLayout(DetailsLayout) +KStandardItemListView::KStandardItemListView(QGraphicsWidget *parent) + : KItemListView(parent) + , m_itemLayout(DetailsLayout) { setAcceptDrops(true); setScrollOrientation(Qt::Vertical); @@ -50,34 +50,41 @@ KStandardItemListView::ItemLayout KStandardItemListView::itemLayout() const return m_itemLayout; } -KItemListWidgetCreatorBase* KStandardItemListView::defaultWidgetCreator() const +KItemListWidgetCreatorBase *KStandardItemListView::defaultWidgetCreator() const { return new KItemListWidgetCreator<KStandardItemListWidget>(); } -KItemListGroupHeaderCreatorBase* KStandardItemListView::defaultGroupHeaderCreator() const +KItemListGroupHeaderCreatorBase *KStandardItemListView::defaultGroupHeaderCreator() const { return new KItemListGroupHeaderCreator<KStandardItemListGroupHeader>(); } -void KStandardItemListView::initializeItemListWidget(KItemListWidget* item) +void KStandardItemListView::initializeItemListWidget(KItemListWidget *item) { - KStandardItemListWidget* standardItemListWidget = qobject_cast<KStandardItemListWidget*>(item); + KStandardItemListWidget *standardItemListWidget = qobject_cast<KStandardItemListWidget *>(item); Q_ASSERT(standardItemListWidget); switch (itemLayout()) { - case IconsLayout: standardItemListWidget->setLayout(KStandardItemListWidget::IconsLayout); break; - case CompactLayout: standardItemListWidget->setLayout(KStandardItemListWidget::CompactLayout); break; - case DetailsLayout: standardItemListWidget->setLayout(KStandardItemListWidget::DetailsLayout); break; - default: Q_ASSERT(false); break; + case IconsLayout: + standardItemListWidget->setLayout(KStandardItemListWidget::IconsLayout); + break; + case CompactLayout: + standardItemListWidget->setLayout(KStandardItemListWidget::CompactLayout); + break; + case DetailsLayout: + standardItemListWidget->setLayout(KStandardItemListWidget::DetailsLayout); + break; + default: + Q_ASSERT(false); + break; } standardItemListWidget->setHighlightEntireRow(highlightEntireRow()); standardItemListWidget->setSupportsItemExpanding(supportsItemExpanding()); } - -bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const +bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray> &changedRoles) const { // The only thing that can modify the item's size hint is the amount of space // needed to display the text for the visible roles. @@ -85,7 +92,7 @@ bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& c // the area defined by KItemStyleOption.iconSize and hence result in no // change of the item-size. const auto roles = visibleRoles(); - for (const QByteArray& role : roles) { + for (const QByteArray &role : roles) { if (changedRoles.contains(role)) { return true; } @@ -123,23 +130,27 @@ void KStandardItemListView::onSupportsItemExpandingChanged(bool supportsExpandin updateLayoutOfVisibleItems(); } - void KStandardItemListView::polishEvent() { switch (m_itemLayout) { - case IconsLayout: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_LargeIconSize), 2, 4, 8); break; - case CompactLayout: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_SmallIconSize), 2, 8, 0); break; - case DetailsLayout: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_SmallIconSize), 2, 0, 0); break; - default: Q_ASSERT(false); break; + case IconsLayout: + applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_LargeIconSize), 2, 4, 8); + break; + case CompactLayout: + applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_SmallIconSize), 2, 8, 0); + break; + case DetailsLayout: + applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_SmallIconSize), 2, 0, 0); + break; + default: + Q_ASSERT(false); + break; } QGraphicsWidget::polishEvent(); } -void KStandardItemListView::applyDefaultStyleOption(int iconSize, - int padding, - int horizontalMargin, - int verticalMargin) +void KStandardItemListView::applyDefaultStyleOption(int iconSize, int padding, int horizontalMargin, int verticalMargin) { KItemListStyleOption option = styleOption(); @@ -163,9 +174,8 @@ void KStandardItemListView::updateLayoutOfVisibleItems() { if (model()) { const auto widgets = visibleItemListWidgets(); - for (KItemListWidget* widget : widgets) { + for (KItemListWidget *widget : widgets) { initializeItemListWidget(widget); } } } - diff --git a/src/kitemviews/kstandarditemlistview.h b/src/kitemviews/kstandarditemlistview.h index 527d14b9d..396383718 100644 --- a/src/kitemviews/kstandarditemlistview.h +++ b/src/kitemviews/kstandarditemlistview.h @@ -31,24 +31,19 @@ class DOLPHIN_EXPORT KStandardItemListView : public KItemListView Q_OBJECT public: - enum ItemLayout - { - IconsLayout, - CompactLayout, - DetailsLayout - }; + enum ItemLayout { IconsLayout, CompactLayout, DetailsLayout }; - explicit KStandardItemListView(QGraphicsWidget* parent = nullptr); + explicit KStandardItemListView(QGraphicsWidget *parent = nullptr); ~KStandardItemListView() override; void setItemLayout(ItemLayout layout); ItemLayout itemLayout() const; protected: - KItemListWidgetCreatorBase* defaultWidgetCreator() const override; - KItemListGroupHeaderCreatorBase* defaultGroupHeaderCreator() const override; - void initializeItemListWidget(KItemListWidget* item) override; - bool itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const override; + KItemListWidgetCreatorBase *defaultWidgetCreator() const override; + KItemListGroupHeaderCreatorBase *defaultGroupHeaderCreator() const override; + void initializeItemListWidget(KItemListWidget *item) override; + bool itemSizeHintUpdateRequired(const QSet<QByteArray> &changedRoles) const override; virtual bool itemLayoutSupportsItemExpanding(ItemLayout layout) const; /** To be overriden by sub-classes to specify when full row highlighting should be enabled. */ virtual bool itemLayoutHighlightEntireRow(ItemLayout layout) const; @@ -66,5 +61,3 @@ private: }; #endif - - diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index ddc7c2988..afe614363 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -26,8 +26,8 @@ // #define KSTANDARDITEMLISTWIDGET_DEBUG -KStandardItemListWidgetInformant::KStandardItemListWidgetInformant() : - KItemListWidgetInformant() +KStandardItemListWidgetInformant::KStandardItemListWidgetInformant() + : KItemListWidgetInformant() { } @@ -35,9 +35,11 @@ KStandardItemListWidgetInformant::~KStandardItemListWidgetInformant() { } -void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const +void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, + qreal &logicalWidthHint, + const KItemListView *view) const { - switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) { + switch (static_cast<const KStandardItemListView *>(view)->itemLayout()) { case KStandardItemListView::IconsLayout: calculateIconsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); break; @@ -56,24 +58,22 @@ void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector<std::pair< } } -qreal KStandardItemListWidgetInformant::preferredRoleColumnWidth(const QByteArray& role, - int index, - const KItemListView* view) const +qreal KStandardItemListWidgetInformant::preferredRoleColumnWidth(const QByteArray &role, int index, const KItemListView *view) const { const QHash<QByteArray, QVariant> values = view->model()->data(index); - const KItemListStyleOption& option = view->styleOption(); + const KItemListStyleOption &option = view->styleOption(); const QString text = roleText(role, values); qreal width = KStandardItemListWidget::columnPadding(option); - const QFontMetrics& normalFontMetrics = option.fontMetrics; + const QFontMetrics &normalFontMetrics = option.fontMetrics; const QFontMetrics linkFontMetrics(customizedFontForLinks(option.font)); if (role == "rating") { width += KStandardItemListWidget::preferredRatingSize(option).width(); } else { // If current item is a link, we use the customized link font metrics instead of the normal font metrics. - const QFontMetrics& fontMetrics = itemIsLink(index, view) ? linkFontMetrics : normalFontMetrics; + const QFontMetrics &fontMetrics = itemIsLink(index, view) ? linkFontMetrics : normalFontMetrics; width += fontMetrics.horizontalAdvance(text); @@ -93,20 +93,19 @@ qreal KStandardItemListWidgetInformant::preferredRoleColumnWidth(const QByteArra return width; } -QString KStandardItemListWidgetInformant::itemText(int index, const KItemListView* view) const +QString KStandardItemListWidgetInformant::itemText(int index, const KItemListView *view) const { return view->model()->data(index).value("text").toString(); } -bool KStandardItemListWidgetInformant::itemIsLink(int index, const KItemListView* view) const +bool KStandardItemListWidgetInformant::itemIsLink(int index, const KItemListView *view) const { Q_UNUSED(index) Q_UNUSED(view) return false; } -QString KStandardItemListWidgetInformant::roleText(const QByteArray& role, - const QHash<QByteArray, QVariant>& values) const +QString KStandardItemListWidgetInformant::roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values) const { if (role == "rating") { // Always use an empty text, as the rating is shown by the image m_rating. @@ -115,15 +114,17 @@ QString KStandardItemListWidgetInformant::roleText(const QByteArray& role, return values.value(role).toString(); } -QFont KStandardItemListWidgetInformant::customizedFontForLinks(const QFont& baseFont) const +QFont KStandardItemListWidgetInformant::customizedFontForLinks(const QFont &baseFont) const { return baseFont; } -void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const +void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, + qreal &logicalWidthHint, + const KItemListView *view) const { - const KItemListStyleOption& option = view->styleOption(); - const QFont& normalFont = option.font; + const KItemListStyleOption &option = view->styleOption(); + const QFont &normalFont = option.font; const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0); const qreal itemWidth = view->itemSize().width(); @@ -142,10 +143,10 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector } // If the current item is a link, we use the customized link font instead of the normal font. - const QFont& font = itemIsLink(index, view) ? linkFont : normalFont; + const QFont &font = itemIsLink(index, view) ? linkFont : normalFont; + + const QString &text = KStringHandler::preProcessWrap(itemText(index, view)); - const QString& text = KStringHandler::preProcessWrap(itemText(index, view)); - // Calculate the number of lines required for wrapping the name qreal textHeight = 0; QTextLayout layout(text, font); @@ -177,13 +178,15 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector logicalWidthHint = itemWidth; } -void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const +void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, + qreal &logicalWidthHint, + const KItemListView *view) const { - const KItemListStyleOption& option = view->styleOption(); - const QFontMetrics& normalFontMetrics = option.fontMetrics; + const KItemListStyleOption &option = view->styleOption(); + const QFontMetrics &normalFontMetrics = option.fontMetrics; const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0); - const QList<QByteArray>& visibleRoles = view->visibleRoles(); + const QList<QByteArray> &visibleRoles = view->visibleRoles(); const bool showOnlyTextRole = (visibleRoles.count() == 1) && (visibleRoles.first() == "text"); const qreal maxWidth = option.maxTextWidth; const qreal paddingAndIconWidth = option.padding * 4 + option.iconSize; @@ -197,7 +200,7 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect } // If the current item is a link, we use the customized link font metrics instead of the normal font metrics. - const QFontMetrics& fontMetrics = itemIsLink(index, view) ? linkFontMetrics : normalFontMetrics; + const QFontMetrics &fontMetrics = itemIsLink(index, view) ? linkFontMetrics : normalFontMetrics; // For each row exactly one role is shown. Calculate the maximum required width that is necessary // to show all roles without horizontal clipping. @@ -206,9 +209,9 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect if (showOnlyTextRole) { maximumRequiredWidth = fontMetrics.horizontalAdvance(itemText(index, view)); } else { - const QHash<QByteArray, QVariant>& values = view->model()->data(index); - for (const QByteArray& role : visibleRoles) { - const QString& text = roleText(role, values); + const QHash<QByteArray, QVariant> &values = view->model()->data(index); + for (const QByteArray &role : visibleRoles) { + const QString &text = roleText(role, values); const qreal requiredWidth = fontMetrics.horizontalAdvance(text); maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth); } @@ -225,43 +228,45 @@ void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVect logicalWidthHint = height; } -void KStandardItemListWidgetInformant::calculateDetailsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const +void KStandardItemListWidgetInformant::calculateDetailsLayoutItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, + qreal &logicalWidthHint, + const KItemListView *view) const { - const KItemListStyleOption& option = view->styleOption(); + const KItemListStyleOption &option = view->styleOption(); const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height()); logicalHeightHints.fill(std::make_pair(height, false)); logicalWidthHint = -1.0; } -KStandardItemListWidget::KStandardItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) : - KItemListWidget(informant, parent), - m_textInfo(), - m_isCut(false), - m_isHidden(false), - m_customizedFont(), - m_customizedFontMetrics(m_customizedFont), - m_isExpandable(false), - m_highlightEntireRow(false), - m_supportsItemExpanding(false), - m_dirtyLayout(true), - m_dirtyContent(true), - m_dirtyContentRoles(), - m_layout(IconsLayout), - m_pixmapPos(), - m_pixmap(), - m_scaledPixmapSize(), - m_columnWidthSum(), - m_iconRect(), - m_hoverPixmap(), - m_textRect(), - m_sortedVisibleRoles(), - m_expansionArea(), - m_customTextColor(), - m_additionalInfoTextColor(), - m_overlay(), - m_rating(), - m_roleEditor(nullptr), - m_oldRoleEditor(nullptr) +KStandardItemListWidget::KStandardItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent) + : KItemListWidget(informant, parent) + , m_textInfo() + , m_isCut(false) + , m_isHidden(false) + , m_customizedFont() + , m_customizedFontMetrics(m_customizedFont) + , m_isExpandable(false) + , m_highlightEntireRow(false) + , m_supportsItemExpanding(false) + , m_dirtyLayout(true) + , m_dirtyContent(true) + , m_dirtyContentRoles() + , m_layout(IconsLayout) + , m_pixmapPos() + , m_pixmap() + , m_scaledPixmapSize() + , m_columnWidthSum() + , m_iconRect() + , m_hoverPixmap() + , m_textRect() + , m_sortedVisibleRoles() + , m_expansionArea() + , m_customTextColor() + , m_additionalInfoTextColor() + , m_overlay() + , m_rating() + , m_roleEditor(nullptr) + , m_oldRoleEditor(nullptr) { } @@ -294,7 +299,8 @@ KStandardItemListWidget::Layout KStandardItemListWidget::layout() const return m_layout; } -void KStandardItemListWidget::setHighlightEntireRow(bool highlightEntireRow) { +void KStandardItemListWidget::setHighlightEntireRow(bool highlightEntireRow) +{ if (m_highlightEntireRow != highlightEntireRow) { m_highlightEntireRow = highlightEntireRow; m_dirtyLayout = true; @@ -302,7 +308,8 @@ void KStandardItemListWidget::setHighlightEntireRow(bool highlightEntireRow) { } } -bool KStandardItemListWidget::highlightEntireRow() const { +bool KStandardItemListWidget::highlightEntireRow() const +{ return m_highlightEntireRow; } @@ -320,9 +327,9 @@ bool KStandardItemListWidget::supportsItemExpanding() const return m_supportsItemExpanding; } -void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void KStandardItemListWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); + const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing(); KItemListWidget::paint(painter, option, widget); @@ -330,7 +337,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic drawSiblingsInformation(painter); } - const KItemListStyleOption& itemListStyleOption = styleOption(); + const KItemListStyleOption &itemListStyleOption = styleOption(); if (isHovered() && !m_pixmap.isNull()) { if (hoverOpacity() < 1.0) { /* @@ -380,7 +387,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic painter->setFont(m_customizedFont); painter->setPen(textColor()); - const TextInfo* textInfo = m_textInfo.value("text"); + const TextInfo *textInfo = m_textInfo.value("text"); if (!textInfo) { // It seems that we can end up here even if m_textInfo does not contain @@ -410,12 +417,12 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic painter->setFont(m_customizedFont); for (int i = 1; i < m_sortedVisibleRoles.count(); ++i) { - const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles[i]); + const TextInfo *textInfo = m_textInfo.value(m_sortedVisibleRoles[i]); painter->drawStaticText(textInfo->pos, textInfo->staticText); } if (!m_rating.isNull()) { - const TextInfo* ratingTextInfo = m_textInfo.value("rating"); + const TextInfo *ratingTextInfo = m_textInfo.value("rating"); QPointF pos = ratingTextInfo->pos; const Qt::Alignment align = ratingTextInfo->staticText.textOption().alignment(); if (align & Qt::AlignHCenter) { @@ -444,13 +451,13 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic QRectF KStandardItemListWidget::iconRect() const { - const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); + const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing(); return m_iconRect; } QRectF KStandardItemListWidget::textRect() const { - const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); + const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing(); return m_textRect; } @@ -461,13 +468,13 @@ QRectF KStandardItemListWidget::textFocusRect() const // when having a quite large icon size but only one line of text. Still the // focus rectangle should be shown as narrow as possible around the text. - const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); + const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing(); switch (m_layout) { case CompactLayout: { QRectF rect = m_textRect; - const TextInfo* topText = m_textInfo.value(m_sortedVisibleRoles.first()); - const TextInfo* bottomText = m_textInfo.value(m_sortedVisibleRoles.last()); + const TextInfo *topText = m_textInfo.value(m_sortedVisibleRoles.first()); + const TextInfo *bottomText = m_textInfo.value(m_sortedVisibleRoles.last()); rect.setTop(topText->pos.y()); rect.setBottom(bottomText->pos.y() + bottomText->staticText.size().height()); return rect; @@ -475,11 +482,11 @@ QRectF KStandardItemListWidget::textFocusRect() const case DetailsLayout: { QRectF rect = m_textRect; - const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles.first()); + const TextInfo *textInfo = m_textInfo.value(m_sortedVisibleRoles.first()); rect.setTop(textInfo->pos.y()); rect.setBottom(textInfo->pos.y() + textInfo->staticText.size().height()); - const KItemListStyleOption& option = styleOption(); + const KItemListStyleOption &option = styleOption(); if (option.extendedSelectionRegion) { const QString text = textInfo->staticText.text(); rect.setWidth(m_customizedFontMetrics.horizontalAdvance(text) + 2 * option.padding); @@ -497,7 +504,7 @@ QRectF KStandardItemListWidget::textFocusRect() const QRectF KStandardItemListWidget::selectionRect() const { - const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); + const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing(); switch (m_layout) { case IconsLayout: @@ -524,13 +531,13 @@ QRectF KStandardItemListWidget::selectionRect() const QRectF KStandardItemListWidget::expansionToggleRect() const { - const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); + const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing(); return m_isExpandable ? m_expansionArea : QRectF(); } QRectF KStandardItemListWidget::selectionToggleRect() const { - const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing(); + const_cast<KStandardItemListWidget *>(this)->triggerCacheRefreshing(); const int widgetIconSize = iconSize(); int toggleSize = KIconLoader::SizeSmall; @@ -564,8 +571,7 @@ QRectF KStandardItemListWidget::selectionToggleRect() const return QRectF(pos, QSizeF(toggleSize, toggleSize)); } -QPixmap KStandardItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option, - QWidget* widget) +QPixmap KStandardItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget) { QPixmap pixmap = KItemListWidget::createDragPixmap(option, widget); if (m_layout != DetailsLayout) { @@ -575,10 +581,8 @@ QPixmap KStandardItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem // Only return the content of the text-column as pixmap const int leftClip = m_pixmapPos.x(); - const TextInfo* textInfo = m_textInfo.value("text"); - const int rightClip = textInfo->pos.x() + - textInfo->staticText.size().width() + - 2 * styleOption().padding; + const TextInfo *textInfo = m_textInfo.value("text"); + const int rightClip = textInfo->pos.x() + textInfo->staticText.size().width() + 2 * styleOption().padding; QPixmap clippedPixmap(rightClip - leftClip + 1, pixmap.height()); clippedPixmap.fill(Qt::transparent); @@ -589,8 +593,7 @@ QPixmap KStandardItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem return clippedPixmap; } - -KItemListWidgetInformant* KStandardItemListWidget::createInformant() +KItemListWidgetInformant *KStandardItemListWidget::createInformant() { return new KStandardItemListWidgetInformant(); } @@ -612,7 +615,7 @@ void KStandardItemListWidget::refreshCache() { } -bool KStandardItemListWidget::isRoleRightAligned(const QByteArray& role) const +bool KStandardItemListWidget::isRoleRightAligned(const QByteArray &role) const { Q_UNUSED(role) return false; @@ -623,7 +626,7 @@ bool KStandardItemListWidget::isHidden() const return false; } -QFont KStandardItemListWidget::customizedFont(const QFont& baseFont) const +QFont KStandardItemListWidget::customizedFont(const QFont &baseFont) const { return baseFont; } @@ -633,7 +636,7 @@ QPalette::ColorRole KStandardItemListWidget::normalTextColorRole() const return QPalette::Text; } -void KStandardItemListWidget::setTextColor(const QColor& color) +void KStandardItemListWidget::setTextColor(const QColor &color) { if (color != m_customTextColor) { m_customTextColor = color; @@ -657,7 +660,7 @@ QColor KStandardItemListWidget::textColor() const return styleOption().palette.color(group, role); } -void KStandardItemListWidget::setOverlay(const QPixmap& overlay) +void KStandardItemListWidget::setOverlay(const QPixmap &overlay) { m_overlay = overlay; m_dirtyContent = true; @@ -669,15 +672,12 @@ QPixmap KStandardItemListWidget::overlay() const return m_overlay; } - -QString KStandardItemListWidget::roleText(const QByteArray& role, - const QHash<QByteArray, QVariant>& values) const +QString KStandardItemListWidget::roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values) const { - return static_cast<const KStandardItemListWidgetInformant*>(informant())->roleText(role, values); + return static_cast<const KStandardItemListWidgetInformant *>(informant())->roleText(role, values); } -void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current, - const QSet<QByteArray>& roles) +void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant> ¤t, const QSet<QByteArray> &roles) { Q_UNUSED(current) @@ -693,7 +693,7 @@ void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& cur // The URL might have changed (i.e., if the sort order of the items has // been changed). Therefore, the "is cut" state must be updated. - KFileItemClipboard* clipboard = KFileItemClipboard::instance(); + KFileItemClipboard *clipboard = KFileItemClipboard::instance(); const QUrl itemUrl = data().value("url").toUrl(); m_isCut = clipboard->isCut(itemUrl); @@ -704,22 +704,19 @@ void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& cur QSetIterator<QByteArray> it(dirtyRoles); while (it.hasNext()) { - const QByteArray& role = it.next(); + const QByteArray &role = it.next(); m_dirtyContentRoles.insert(role); } } -void KStandardItemListWidget::visibleRolesChanged(const QList<QByteArray>& current, - const QList<QByteArray>& previous) +void KStandardItemListWidget::visibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous) { Q_UNUSED(previous) m_sortedVisibleRoles = current; m_dirtyLayout = true; } -void KStandardItemListWidget::columnWidthChanged(const QByteArray& role, - qreal current, - qreal previous) +void KStandardItemListWidget::columnWidthChanged(const QByteArray &role, qreal current, qreal previous) { Q_UNUSED(role) Q_UNUSED(current) @@ -727,13 +724,13 @@ void KStandardItemListWidget::columnWidthChanged(const QByteArray& role, m_dirtyLayout = true; } -void KStandardItemListWidget::sidePaddingChanged(qreal padding) { +void KStandardItemListWidget::sidePaddingChanged(qreal padding) +{ Q_UNUSED(padding) m_dirtyLayout = true; } -void KStandardItemListWidget::styleOptionChanged(const KItemListStyleOption& current, - const KItemListStyleOption& previous) +void KStandardItemListWidget::styleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous) { KItemListWidget::styleOptionChanged(current, previous); @@ -754,31 +751,29 @@ void KStandardItemListWidget::selectedChanged(bool selected) m_dirtyContent = true; } -void KStandardItemListWidget::siblingsInformationChanged(const QBitArray& current, const QBitArray& previous) +void KStandardItemListWidget::siblingsInformationChanged(const QBitArray ¤t, const QBitArray &previous) { Q_UNUSED(current) Q_UNUSED(previous) m_dirtyLayout = true; } -int KStandardItemListWidget::selectionLength(const QString& text) const +int KStandardItemListWidget::selectionLength(const QString &text) const { return text.length(); } -void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous) +void KStandardItemListWidget::editedRoleChanged(const QByteArray ¤t, const QByteArray &previous) { Q_UNUSED(previous) - QGraphicsView* parent = scene()->views()[0]; + QGraphicsView *parent = scene()->views()[0]; if (current.isEmpty() || !parent || current != "text") { if (m_roleEditor) { Q_EMIT roleEditingCanceled(index(), current, data().value(current)); - disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingCanceled, - this, &KStandardItemListWidget::slotRoleEditingCanceled); - disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingFinished, - this, &KStandardItemListWidget::slotRoleEditingFinished); + disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingCanceled, this, &KStandardItemListWidget::slotRoleEditingCanceled); + disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingFinished, this, &KStandardItemListWidget::slotRoleEditingFinished); if (m_oldRoleEditor) { m_oldRoleEditor->deleteLater(); @@ -792,7 +787,7 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const Q_ASSERT(!m_roleEditor); - const TextInfo* textInfo = m_textInfo.value("text"); + const TextInfo *textInfo = m_textInfo.value("text"); m_roleEditor = new KItemListRoleEditor(parent); m_roleEditor->setRole(current); @@ -814,10 +809,8 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const m_roleEditor->setTextCursor(cursor); } - connect(m_roleEditor, &KItemListRoleEditor::roleEditingCanceled, - this, &KStandardItemListWidget::slotRoleEditingCanceled); - connect(m_roleEditor, &KItemListRoleEditor::roleEditingFinished, - this, &KStandardItemListWidget::slotRoleEditingFinished); + connect(m_roleEditor, &KItemListRoleEditor::roleEditingCanceled, this, &KStandardItemListWidget::slotRoleEditingCanceled); + connect(m_roleEditor, &KItemListRoleEditor::roleEditingFinished, this, &KStandardItemListWidget::slotRoleEditingFinished); // Adjust the geometry of the editor QRectF rect = roleEditingRect(current); @@ -841,7 +834,7 @@ void KStandardItemListWidget::iconSizeChanged(int current, int previous) update(); } -void KStandardItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) +void KStandardItemListWidget::resizeEvent(QGraphicsSceneResizeEvent *event) { if (m_roleEditor) { setEditedRole(QByteArray()); @@ -853,32 +846,29 @@ void KStandardItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) m_dirtyLayout = true; } -void KStandardItemListWidget::showEvent(QShowEvent* event) +void KStandardItemListWidget::showEvent(QShowEvent *event) { KItemListWidget::showEvent(event); // Listen to changes of the clipboard to mark the item as cut/uncut - KFileItemClipboard* clipboard = KFileItemClipboard::instance(); + KFileItemClipboard *clipboard = KFileItemClipboard::instance(); const QUrl itemUrl = data().value("url").toUrl(); m_isCut = clipboard->isCut(itemUrl); - connect(clipboard, &KFileItemClipboard::cutItemsChanged, - this, &KStandardItemListWidget::slotCutItemsChanged); + connect(clipboard, &KFileItemClipboard::cutItemsChanged, this, &KStandardItemListWidget::slotCutItemsChanged); } -void KStandardItemListWidget::hideEvent(QHideEvent* event) +void KStandardItemListWidget::hideEvent(QHideEvent *event) { - disconnect(KFileItemClipboard::instance(), &KFileItemClipboard::cutItemsChanged, - this, &KStandardItemListWidget::slotCutItemsChanged); + disconnect(KFileItemClipboard::instance(), &KFileItemClipboard::cutItemsChanged, this, &KStandardItemListWidget::slotCutItemsChanged); KItemListWidget::hideEvent(event); } bool KStandardItemListWidget::event(QEvent *event) { - if (event->type() == QEvent::WindowDeactivate || event->type() == QEvent::WindowActivate - || event->type() == QEvent::PaletteChange) { + if (event->type() == QEvent::WindowDeactivate || event->type() == QEvent::WindowActivate || event->type() == QEvent::PaletteChange) { m_dirtyContent = true; } @@ -904,16 +894,14 @@ void KStandardItemListWidget::slotCutItemsChanged() } } -void KStandardItemListWidget::slotRoleEditingCanceled(const QByteArray& role, - const QVariant& value) +void KStandardItemListWidget::slotRoleEditingCanceled(const QByteArray &role, const QVariant &value) { closeRoleEditor(); Q_EMIT roleEditingCanceled(index(), role, value); setEditedRole(QByteArray()); } -void KStandardItemListWidget::slotRoleEditingFinished(const QByteArray& role, - const QVariant& value) +void KStandardItemListWidget::slotRoleEditingFinished(const QByteArray &role, const QVariant &value) { closeRoleEditor(); Q_EMIT roleEditingFinished(index(), role, value); @@ -933,8 +921,9 @@ void KStandardItemListWidget::triggerCacheRefreshing() m_isHidden = isHidden(); m_customizedFont = customizedFont(styleOption().font); m_customizedFontMetrics = QFontMetrics(m_customizedFont); - m_columnWidthSum = std::accumulate(m_sortedVisibleRoles.begin(), m_sortedVisibleRoles.end(), - qreal(), [this](qreal sum, const auto &role){ return sum + columnWidth(role); }); + m_columnWidthSum = std::accumulate(m_sortedVisibleRoles.begin(), m_sortedVisibleRoles.end(), qreal(), [this](qreal sum, const auto &role) { + return sum + columnWidth(role); + }); updateExpansionArea(); updateTextsCache(); @@ -973,7 +962,7 @@ void KStandardItemListWidget::updatePixmapCache() const QSizeF widgetSize = size(); const bool iconOnTop = (m_layout == IconsLayout); - const KItemListStyleOption& option = styleOption(); + const KItemListStyleOption &option = styleOption(); const qreal padding = option.padding; const int widgetIconSize = iconSize(); @@ -984,10 +973,8 @@ void KStandardItemListWidget::updatePixmapCache() bool updatePixmap = (m_pixmap.width() != maxIconWidth || m_pixmap.height() != maxIconHeight); if (!updatePixmap && m_dirtyContent) { - updatePixmap = m_dirtyContentRoles.isEmpty() - || m_dirtyContentRoles.contains("iconPixmap") - || m_dirtyContentRoles.contains("iconName") - || m_dirtyContentRoles.contains("iconOverlays"); + updatePixmap = m_dirtyContentRoles.isEmpty() || m_dirtyContentRoles.contains("iconPixmap") || m_dirtyContentRoles.contains("iconName") + || m_dirtyContentRoles.contains("iconOverlays"); } if (updatePixmap) { @@ -1008,7 +995,7 @@ void KStandardItemListWidget::updatePixmapCache() } } - const int loadedIndex = qMax(qMin(sequenceIndex, pixmaps.size()-1), 0); + const int loadedIndex = qMax(qMin(sequenceIndex, pixmaps.size() - 1), 0); if (loadedIndex != 0) { m_pixmap = pixmaps[loadedIndex]; @@ -1028,7 +1015,8 @@ void KStandardItemListWidget::updatePixmapCache() iconName = QStringLiteral("unknown"); } const QStringList overlays = values["iconOverlays"].toStringList(); - m_pixmap = pixmapForIcon(iconName, overlays, maxIconHeight, m_layout != IconsLayout && isActiveWindow() && isSelected() ? QIcon::Selected : QIcon::Normal); + m_pixmap = + pixmapForIcon(iconName, overlays, maxIconHeight, m_layout != IconsLayout && isActiveWindow() && isSelected() ? QIcon::Selected : QIcon::Normal); } else if (m_pixmap.width() / m_pixmap.devicePixelRatio() != maxIconWidth || m_pixmap.height() / m_pixmap.devicePixelRatio() != maxIconHeight) { // A custom pixmap has been applied. Assure that the pixmap @@ -1042,7 +1030,7 @@ void KStandardItemListWidget::updatePixmapCache() } if (m_isCut) { - KIconEffect* effect = KIconLoader::global()->iconEffect(); + KIconEffect *effect = KIconLoader::global()->iconEffect(); m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState); } @@ -1069,13 +1057,12 @@ void KStandardItemListWidget::updatePixmapCache() int scaledIconSize = 0; if (iconOnTop) { - const TextInfo* textInfo = m_textInfo.value("text"); + const TextInfo *textInfo = m_textInfo.value("text"); scaledIconSize = static_cast<int>(textInfo->pos.y() - 2 * padding); } else { const int textRowsCount = (m_layout == CompactLayout) ? visibleRoles().count() : 1; const qreal requiredTextHeight = textRowsCount * m_customizedFontMetrics.height(); - scaledIconSize = (requiredTextHeight < maxIconHeight) ? - widgetSize.height() - 2 * padding : maxIconHeight; + scaledIconSize = (requiredTextHeight < maxIconHeight) ? widgetSize.height() - 2 * padding : maxIconHeight; } const int maxScaledIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : scaledIconSize; @@ -1091,17 +1078,13 @@ void KStandardItemListWidget::updatePixmapCache() m_pixmapPos.setY(padding + scaledIconSize - m_scaledPixmapSize.height()); } else { // Center horizontally and vertically within the icon-area - const TextInfo* textInfo = m_textInfo.value("text"); - m_pixmapPos.setX(textInfo->pos.x() - 2.0 * padding - - (scaledIconSize + m_scaledPixmapSize.width()) / 2.0); + const TextInfo *textInfo = m_textInfo.value("text"); + m_pixmapPos.setX(textInfo->pos.x() - 2.0 * padding - (scaledIconSize + m_scaledPixmapSize.width()) / 2.0); // Derive icon's vertical center from the center of the text frame, including // any necessary adjustment if the font's midline is offset from the frame center - const qreal midlineShift = m_customizedFontMetrics.height() / 2.0 - - m_customizedFontMetrics.descent() - - m_customizedFontMetrics.capHeight() / 2.0; + const qreal midlineShift = m_customizedFontMetrics.height() / 2.0 - m_customizedFontMetrics.descent() - m_customizedFontMetrics.capHeight() / 2.0; m_pixmapPos.setY(m_textRect.center().y() + midlineShift - m_scaledPixmapSize.height() / 2.0); - } if (m_layout == IconsLayout) { @@ -1109,8 +1092,7 @@ void KStandardItemListWidget::updatePixmapCache() } else { const qreal widthOffset = widgetIconSize - m_scaledPixmapSize.width(); const qreal heightOffset = widgetIconSize - m_scaledPixmapSize.height(); - const QPointF squareIconPos(m_pixmapPos.x() - 0.5 * widthOffset, - m_pixmapPos.y() - 0.5 * heightOffset); + const QPointF squareIconPos(m_pixmapPos.x() - 0.5 * widthOffset, m_pixmapPos.y() - 0.5 * heightOffset); const QSizeF squareIconSize(widgetIconSize, widgetIconSize); m_iconRect = QRectF(squareIconPos, squareIconSize); } @@ -1118,7 +1100,7 @@ void KStandardItemListWidget::updatePixmapCache() // Prepare the pixmap that is used when the item gets hovered if (isHovered()) { m_hoverPixmap = m_pixmap; - KIconEffect* effect = KIconLoader::global()->iconEffect(); + KIconEffect *effect = KIconLoader::global()->iconEffect(); // In the KIconLoader terminology, active = hover. if (effect->hasEffect(KIconLoader::Desktop, KIconLoader::ActiveState)) { m_hoverPixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::ActiveState); @@ -1152,7 +1134,7 @@ void KStandardItemListWidget::updateTextsCache() qDeleteAll(m_textInfo); m_textInfo.clear(); for (int i = 0; i < m_sortedVisibleRoles.count(); ++i) { - TextInfo* textInfo = new TextInfo(); + TextInfo *textInfo = new TextInfo(); textInfo->staticText.setTextFormat(Qt::PlainText); textInfo->staticText.setPerformanceHint(QStaticText::AggressiveCaching); textInfo->staticText.setTextOption(textOption); @@ -1160,22 +1142,28 @@ void KStandardItemListWidget::updateTextsCache() } switch (m_layout) { - case IconsLayout: updateIconsLayoutTextCache(); break; - case CompactLayout: updateCompactLayoutTextCache(); break; - case DetailsLayout: updateDetailsLayoutTextCache(); break; - default: Q_ASSERT(false); break; + case IconsLayout: + updateIconsLayoutTextCache(); + break; + case CompactLayout: + updateCompactLayoutTextCache(); + break; + case DetailsLayout: + updateDetailsLayoutTextCache(); + break; + default: + Q_ASSERT(false); + break; } - const TextInfo* ratingTextInfo = m_textInfo.value("rating"); + const TextInfo *ratingTextInfo = m_textInfo.value("rating"); if (ratingTextInfo) { // The text of the rating-role has been set to empty to get // replaced by a rating-image showing the rating as stars. - const KItemListStyleOption& option = styleOption(); + const KItemListStyleOption &option = styleOption(); QSizeF ratingSize = preferredRatingSize(option); - const qreal availableWidth = (m_layout == DetailsLayout) - ? columnWidth("rating") - columnPadding(option) - : size().width(); + const qreal availableWidth = (m_layout == DetailsLayout) ? columnWidth("rating") - columnPadding(option) : size().width(); if (ratingSize.width() > availableWidth) { ratingSize.rwidth() = availableWidth; } @@ -1202,9 +1190,7 @@ QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, in const auto extensionWidth = m_customizedFontMetrics.horizontalAdvance(text.right(extensionLength)); if (elidingWidth > extensionWidth && extensionLength < 6 && (float(extensionWidth) / float(elidingWidth)) < 0.3) { // if we have room to display the file extension and the extension is not too long - QString ret = m_customizedFontMetrics.elidedText(text.chopped(extensionLength), - Qt::ElideRight, - elidingWidth - extensionWidth); + QString ret = m_customizedFontMetrics.elidedText(text.chopped(extensionLength), Qt::ElideRight, elidingWidth - extensionWidth); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) ret.append(text.rightRef(extensionLength)); #else @@ -1213,8 +1199,7 @@ QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, in return ret; } } - return m_customizedFontMetrics.elidedText(text,Qt::ElideRight, - elidingWidth); + return m_customizedFontMetrics.elidedText(text, Qt::ElideRight, elidingWidth); } void KStandardItemListWidget::updateIconsLayoutTextCache() @@ -1231,14 +1216,14 @@ void KStandardItemListWidget::updateIconsLayoutTextCache() const QHash<QByteArray, QVariant> values = data(); - const KItemListStyleOption& option = styleOption(); + const KItemListStyleOption &option = styleOption(); const qreal padding = option.padding; const qreal maxWidth = size().width() - 2 * padding; const qreal lineSpacing = m_customizedFontMetrics.lineSpacing(); // Initialize properties for the "text" role. It will be used as anchor // for initializing the position of the other roles. - TextInfo* nameTextInfo = m_textInfo.value("text"); + TextInfo *nameTextInfo = m_textInfo.value("text"); const QString nameText = KStringHandler::preProcessWrap(values["text"].toString()); nameTextInfo->staticText.setText(nameText); @@ -1289,20 +1274,17 @@ void KStandardItemListWidget::updateIconsLayoutTextCache() // Use one line for each additional information nameTextInfo->staticText.setTextWidth(maxWidth); nameTextInfo->pos = QPointF(padding, iconSize() + 2 * padding); - m_textRect = QRectF(padding + (maxWidth - nameWidth) / 2, - nameTextInfo->pos.y(), - nameWidth, - nameHeight); + m_textRect = QRectF(padding + (maxWidth - nameWidth) / 2, nameTextInfo->pos.y(), nameWidth, nameHeight); // Calculate the position for each additional information qreal y = nameTextInfo->pos.y() + nameHeight; - for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) { + for (const QByteArray &role : qAsConst(m_sortedVisibleRoles)) { if (role == "text") { continue; } const QString text = roleText(role, values); - TextInfo* textInfo = m_textInfo.value(role); + TextInfo *textInfo = m_textInfo.value(role); textInfo->staticText.setText(text); qreal requiredWidth = 0; @@ -1353,7 +1335,7 @@ void KStandardItemListWidget::updateCompactLayoutTextCache() const QHash<QByteArray, QVariant> values = data(); - const KItemListStyleOption& option = styleOption(); + const KItemListStyleOption &option = styleOption(); const qreal widgetHeight = size().height(); const qreal lineSpacing = m_customizedFontMetrics.lineSpacing(); const qreal textLinesHeight = qMax(visibleRoles().count(), 1) * lineSpacing; @@ -1362,9 +1344,9 @@ void KStandardItemListWidget::updateCompactLayoutTextCache() const qreal x = option.padding * 3 + iconSize(); qreal y = qRound((widgetHeight - textLinesHeight) / 2); const qreal maxWidth = size().width() - x - option.padding; - for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) { + for (const QByteArray &role : qAsConst(m_sortedVisibleRoles)) { const QString text = roleText(role, values); - TextInfo* textInfo = m_textInfo.value(role); + TextInfo *textInfo = m_textInfo.value(role); textInfo->staticText.setText(text); qreal requiredWidth = m_customizedFontMetrics.horizontalAdvance(text); @@ -1395,7 +1377,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache() // +------+ m_textRect = QRectF(); - const KItemListStyleOption& option = styleOption(); + const KItemListStyleOption &option = styleOption(); const QHash<QByteArray, QVariant> values = data(); const qreal widgetHeight = size().height(); @@ -1412,7 +1394,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache() qreal x = firstColumnInc; const qreal y = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2); - for (const QByteArray& role : qAsConst(m_sortedVisibleRoles)) { + for (const QByteArray &role : qAsConst(m_sortedVisibleRoles)) { QString text = roleText(role, values); // Elide the text in case it does not fit into the available column-width @@ -1430,17 +1412,14 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache() requiredWidth = m_customizedFontMetrics.horizontalAdvance(text); } - TextInfo* textInfo = m_textInfo.value(role); + TextInfo *textInfo = m_textInfo.value(role); textInfo->staticText.setText(text); textInfo->pos = QPointF(x + columnWidthInc / 2, y); x += roleWidth; if (isTextRole) { - const qreal textWidth = option.extendedSelectionRegion - ? size().width() - textInfo->pos.x() - : requiredWidth + 2 * option.padding; - m_textRect = QRectF(textInfo->pos.x() - option.padding, 0, - textWidth, size().height()); + const qreal textWidth = option.extendedSelectionRegion ? size().width() - textInfo->pos.x() : requiredWidth + 2 * option.padding; + m_textRect = QRectF(textInfo->pos.x() - option.padding, 0, textWidth, size().height()); // The column after the name should always be aligned on the same x-position independent // from the expansion-level shown in the name column @@ -1471,12 +1450,11 @@ void KStandardItemListWidget::updateAdditionalInfoTextColor() const QColor c2 = styleOption().palette.base().color(); const int p1 = 70; const int p2 = 100 - p1; - m_additionalInfoTextColor = QColor((c1.red() * p1 + c2.red() * p2) / 100, - (c1.green() * p1 + c2.green() * p2) / 100, - (c1.blue() * p1 + c2.blue() * p2) / 100); + m_additionalInfoTextColor = + QColor((c1.red() * p1 + c2.red() * p2) / 100, (c1.green() * p1 + c2.green() * p2) / 100, (c1.blue() * p1 + c2.blue() * p2) / 100); } -void KStandardItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap) +void KStandardItemListWidget::drawPixmap(QPainter *painter, const QPixmap &pixmap) { if (m_scaledPixmapSize != pixmap.size() / pixmap.devicePixelRatio()) { QPixmap scaledPixmap = pixmap; @@ -1493,7 +1471,7 @@ void KStandardItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixma } } -void KStandardItemListWidget::drawSiblingsInformation(QPainter* painter) +void KStandardItemListWidget::drawSiblingsInformation(QPainter *painter) { const int siblingSize = size().height(); const int x = (m_expansionArea.left() + m_expansionArea.right() - siblingSize) / 2; @@ -1528,9 +1506,9 @@ void KStandardItemListWidget::drawSiblingsInformation(QPainter* painter) } } -QRectF KStandardItemListWidget::roleEditingRect(const QByteArray& role) const +QRectF KStandardItemListWidget::roleEditingRect(const QByteArray &role) const { - const TextInfo* textInfo = m_textInfo.value(role); + const TextInfo *textInfo = m_textInfo.value(role); if (!textInfo) { return QRectF(); } @@ -1545,10 +1523,8 @@ QRectF KStandardItemListWidget::roleEditingRect(const QByteArray& role) const void KStandardItemListWidget::closeRoleEditor() { - disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingCanceled, - this, &KStandardItemListWidget::slotRoleEditingCanceled); - disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingFinished, - this, &KStandardItemListWidget::slotRoleEditingFinished); + disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingCanceled, this, &KStandardItemListWidget::slotRoleEditingCanceled); + disconnect(m_roleEditor, &KItemListRoleEditor::roleEditingFinished, this, &KStandardItemListWidget::slotRoleEditingFinished); if (m_roleEditor->hasFocus()) { // If the editing was not ended by a FocusOut event, we have @@ -1564,7 +1540,7 @@ void KStandardItemListWidget::closeRoleEditor() m_roleEditor = nullptr; } -QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStringList& overlays, int size, QIcon::Mode mode) +QPixmap KStandardItemListWidget::pixmapForIcon(const QString &name, const QStringList &overlays, int size, QIcon::Mode mode) { static const QIcon fallbackIcon = QIcon::fromTheme(QStringLiteral("unknown")); @@ -1578,8 +1554,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin if (icon.isNull()) { icon = QIcon(name); } - if (icon.isNull() - || icon.pixmap(size / qApp->devicePixelRatio(), size / qApp->devicePixelRatio(), mode).isNull()) { + if (icon.isNull() || icon.pixmap(size / qApp->devicePixelRatio(), size / qApp->devicePixelRatio(), mode).isNull()) { icon = fallbackIcon; } @@ -1593,7 +1568,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin // It is more efficient to do it here, as KIconLoader::drawOverlays() // assumes that an overlay will be drawn and has some additional // setup time. - for (const QString& overlay : overlays) { + for (const QString &overlay : overlays) { if (!overlay.isEmpty()) { int state = KIconLoader::DefaultState; @@ -1625,14 +1600,13 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin return pixmap; } -QSizeF KStandardItemListWidget::preferredRatingSize(const KItemListStyleOption& option) +QSizeF KStandardItemListWidget::preferredRatingSize(const KItemListStyleOption &option) { const qreal height = option.fontMetrics.ascent(); return QSizeF(height * 5, height); } -qreal KStandardItemListWidget::columnPadding(const KItemListStyleOption& option) +qreal KStandardItemListWidget::columnPadding(const KItemListStyleOption &option) { return option.padding * 6; } - diff --git a/src/kitemviews/kstandarditemlistwidget.h b/src/kitemviews/kstandarditemlistwidget.h index 35d4886b6..5bfb7df29 100644 --- a/src/kitemviews/kstandarditemlistwidget.h +++ b/src/kitemviews/kstandarditemlistwidget.h @@ -23,12 +23,12 @@ class DOLPHIN_EXPORT KStandardItemListWidgetInformant : public KItemListWidgetIn public: KStandardItemListWidgetInformant(); ~KStandardItemListWidgetInformant() override; - - void calculateItemSizeHints(QVector<std::pair<qreal /* height */, bool /* isElided */>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override; - qreal preferredRoleColumnWidth(const QByteArray& role, - int index, - const KItemListView* view) const override; + void calculateItemSizeHints(QVector<std::pair<qreal /* height */, bool /* isElided */>> &logicalHeightHints, + qreal &logicalWidthHint, + const KItemListView *view) const override; + + qreal preferredRoleColumnWidth(const QByteArray &role, int index, const KItemListView *view) const override; protected: /** @@ -38,31 +38,30 @@ protected: * QHash<QByteArray, QVariant> returned by KItemModelBase::data(int), * it can reimplement this function. */ - virtual QString itemText(int index, const KItemListView* view) const; + virtual QString itemText(int index, const KItemListView *view) const; /** * @return The value of the "isLink" role. The default implementation returns false. * The derived class should reimplement this function, when information about * links is available and in usage. */ - virtual bool itemIsLink(int index, const KItemListView* view) const; + virtual bool itemIsLink(int index, const KItemListView *view) const; /** * @return String representation of the role \a role. The representation of * a role might depend on other roles, so the values of all roles * are passed as parameter. */ - virtual QString roleText(const QByteArray& role, - const QHash<QByteArray, QVariant>& values) const; + virtual QString roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values) const; /** * @return A font based on baseFont which is customized for symlinks. */ - virtual QFont customizedFontForLinks(const QFont& baseFont) const; + virtual QFont customizedFontForLinks(const QFont &baseFont) const; - void calculateIconsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const; - void calculateCompactLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const; - void calculateDetailsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const; + void calculateIconsLayoutItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, qreal &logicalWidthHint, const KItemListView *view) const; + void calculateCompactLayoutItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, qreal &logicalWidthHint, const KItemListView *view) const; + void calculateDetailsLayoutItemSizeHints(QVector<std::pair<qreal, bool>> &logicalHeightHints, qreal &logicalWidthHint, const KItemListView *view) const; friend class KStandardItemListWidget; // Accesses roleText() }; @@ -75,14 +74,9 @@ class DOLPHIN_EXPORT KStandardItemListWidget : public KItemListWidget Q_OBJECT public: - enum Layout - { - IconsLayout, - CompactLayout, - DetailsLayout - }; + enum Layout { IconsLayout, CompactLayout, DetailsLayout }; - KStandardItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent); + KStandardItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent); ~KStandardItemListWidget() override; void setLayout(Layout layout); @@ -94,7 +88,7 @@ public: void setSupportsItemExpanding(bool supportsItemExpanding); bool supportsItemExpanding() const; - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; QRectF iconRect() const override; QRectF textRect() const override; @@ -102,9 +96,9 @@ public: QRectF selectionRect() const override; QRectF expansionToggleRect() const override; QRectF selectionToggleRect() const override; - QPixmap createDragPixmap(const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; + QPixmap createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; - static KItemListWidgetInformant* createInformant(); + static KItemListWidgetInformant *createInformant(); protected: /** @@ -129,7 +123,7 @@ protected: * @return True if the give role should be right aligned when showing it inside a column. * Per default false is returned. */ - virtual bool isRoleRightAligned(const QByteArray& role) const; + virtual bool isRoleRightAligned(const QByteArray &role) const; /** * @return True if the item should be visually marked as hidden item. Per default @@ -140,20 +134,20 @@ protected: /** * @return A font based on baseFont which is customized according to the data shown in the widget. */ - virtual QFont customizedFont(const QFont& baseFont) const; + virtual QFont customizedFont(const QFont &baseFont) const; virtual QPalette::ColorRole normalTextColorRole() const; - void setTextColor(const QColor& color); + void setTextColor(const QColor &color); QColor textColor() const; - void setOverlay(const QPixmap& overlay); + void setOverlay(const QPixmap &overlay); QPixmap overlay() const; /** * @see KStandardItemListWidgetInformant::roleText(). */ - QString roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values) const; + QString roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values) const; /** * Fixes: @@ -166,25 +160,24 @@ protected: * * @return Selection length (with or without MIME-type extension) */ - virtual int selectionLength(const QString& text) const; + virtual int selectionLength(const QString &text) const; - void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>()) override; - void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous) override; - void columnWidthChanged(const QByteArray& role, qreal current, qreal previous) override; + void dataChanged(const QHash<QByteArray, QVariant> ¤t, const QSet<QByteArray> &roles = QSet<QByteArray>()) override; + void visibleRolesChanged(const QList<QByteArray> ¤t, const QList<QByteArray> &previous) override; + void columnWidthChanged(const QByteArray &role, qreal current, qreal previous) override; void sidePaddingChanged(qreal width) override; - void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) override; + void styleOptionChanged(const KItemListStyleOption ¤t, const KItemListStyleOption &previous) override; void hoveredChanged(bool hovered) override; void selectedChanged(bool selected) override; - void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous) override; - void editedRoleChanged(const QByteArray& current, const QByteArray& previous) override; + void siblingsInformationChanged(const QBitArray ¤t, const QBitArray &previous) override; + void editedRoleChanged(const QByteArray ¤t, const QByteArray &previous) override; void iconSizeChanged(int current, int previous) override; - void resizeEvent(QGraphicsSceneResizeEvent* event) override; - void showEvent(QShowEvent* event) override; - void hideEvent(QHideEvent* event) override; + void resizeEvent(QGraphicsSceneResizeEvent *event) override; + void showEvent(QShowEvent *event) override; + void hideEvent(QHideEvent *event) override; bool event(QEvent *event) override; - struct TextInfo - { + struct TextInfo { QPointF pos; QStaticText staticText; }; @@ -194,8 +187,8 @@ public Q_SLOTS: private Q_SLOTS: void slotCutItemsChanged(); - void slotRoleEditingCanceled(const QByteArray& role, const QVariant& value); - void slotRoleEditingFinished(const QByteArray& role, const QVariant& value); + void slotRoleEditingCanceled(const QByteArray &role, const QVariant &value); + void slotRoleEditingFinished(const QByteArray &role, const QVariant &value); private: void triggerCacheRefreshing(); @@ -209,8 +202,8 @@ private: void updateAdditionalInfoTextColor(); - void drawPixmap(QPainter* painter, const QPixmap& pixmap); - void drawSiblingsInformation(QPainter* painter); + void drawPixmap(QPainter *painter, const QPixmap &pixmap); + void drawSiblingsInformation(QPainter *painter); QRectF roleEditingRect(const QByteArray &role) const; @@ -222,23 +215,23 @@ private: */ void closeRoleEditor(); - static QPixmap pixmapForIcon(const QString& name, const QStringList& overlays, int size, QIcon::Mode mode); + static QPixmap pixmapForIcon(const QString &name, const QStringList &overlays, int size, QIcon::Mode mode); /** * @return Preferred size of the rating-image based on the given * style-option. The height of the font is taken as * reference. */ - static QSizeF preferredRatingSize(const KItemListStyleOption& option); + static QSizeF preferredRatingSize(const KItemListStyleOption &option); /** * @return Horizontal padding in pixels that is added to the required width of * a column to display the content. */ - static qreal columnPadding(const KItemListStyleOption& option); + static qreal columnPadding(const KItemListStyleOption &option); protected: - QHash<QByteArray, TextInfo*> m_textInfo; // PlacesItemListWidget needs to access this + QHash<QByteArray, TextInfo *> m_textInfo; // PlacesItemListWidget needs to access this private: bool m_isCut; @@ -259,8 +252,8 @@ private: QSize m_scaledPixmapSize; //Size of the pixmap in device independent pixels qreal m_columnWidthSum; - QRectF m_iconRect; // Cache for KItemListWidget::iconRect() - QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item + QRectF m_iconRect; // Cache for KItemListWidget::iconRect() + QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item QRectF m_textRect; @@ -274,8 +267,8 @@ private: QPixmap m_overlay; QPixmap m_rating; - KItemListRoleEditor* m_roleEditor; - KItemListRoleEditor* m_oldRoleEditor; + KItemListRoleEditor *m_roleEditor; + KItemListRoleEditor *m_oldRoleEditor; friend class KStandardItemListWidgetInformant; // Accesses private static methods to be able to // share a common layout calculation diff --git a/src/kitemviews/private/kbaloorolesprovider.cpp b/src/kitemviews/private/kbaloorolesprovider.cpp index f6d4dddb7..4cf36eb2d 100644 --- a/src/kitemviews/private/kbaloorolesprovider.cpp +++ b/src/kitemviews/private/kbaloorolesprovider.cpp @@ -14,20 +14,23 @@ #include <QCollator> #include <QSize> -namespace { - QString tagsFromValues(const QStringList& values) - { - if (values.size() == 1) { - return values.at(0); - } - - QStringList alphabeticalOrderTags = values; - QCollator coll; - coll.setNumericMode(true); - std::sort(alphabeticalOrderTags.begin(), alphabeticalOrderTags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; }); - return alphabeticalOrderTags.join(QLatin1String(", ")); +namespace +{ +QString tagsFromValues(const QStringList &values) +{ + if (values.size() == 1) { + return values.at(0); } + QStringList alphabeticalOrderTags = values; + QCollator coll; + coll.setNumericMode(true); + std::sort(alphabeticalOrderTags.begin(), alphabeticalOrderTags.end(), [&](const QString &s1, const QString &s2) { + return coll.compare(s1, s2) < 0; + }); + return alphabeticalOrderTags.join(QLatin1String(", ")); +} + using Property = KFileMetaData::Property::Property; // Mapping from the KFM::Property to the KFileItemModel roles. const QHash<Property, QByteArray> propertyRoleMap() { @@ -58,14 +61,12 @@ namespace { } } -struct KBalooRolesProviderSingleton -{ +struct KBalooRolesProviderSingleton { KBalooRolesProvider instance; }; Q_GLOBAL_STATIC(KBalooRolesProviderSingleton, s_balooRolesProvider) - -KBalooRolesProvider& KBalooRolesProvider::instance() +KBalooRolesProvider &KBalooRolesProvider::instance() { return s_balooRolesProvider->instance; } @@ -79,21 +80,21 @@ QSet<QByteArray> KBalooRolesProvider::roles() const return m_roles; } -QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& file, - const QSet<QByteArray>& roles) const +QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File &file, const QSet<QByteArray> &roles) const { QHash<QByteArray, QVariant> values; - using entry = std::pair<const KFileMetaData::Property::Property&, const QVariant&>; + using entry = std::pair<const KFileMetaData::Property::Property &, const QVariant &>; - const auto& propMap = file.properties(); + const auto &propMap = file.properties(); auto rangeBegin = propMap.constKeyValueBegin(); while (rangeBegin != propMap.constKeyValueEnd()) { auto key = (*rangeBegin).first; - auto rangeEnd = std::find_if(rangeBegin, propMap.constKeyValueEnd(), - [key](const entry& e) { return e.first != key; }); + auto rangeEnd = std::find_if(rangeBegin, propMap.constKeyValueEnd(), [key](const entry &e) { + return e.first != key; + }); const QByteArray role = propertyRoleMap().value(key); if (role.isEmpty() || !roles.contains(role)) { @@ -106,7 +107,9 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f if (distance > 1) { QVariantList list; list.reserve(static_cast<int>(distance)); - std::for_each(rangeBegin, rangeEnd, [&list](const entry& s) { list.append(s.second); }); + std::for_each(rangeBegin, rangeEnd, [&list](const entry &s) { + list.append(s.second); + }); values.insert(role, propertyInfo.formatAsDisplayString(list)); } else { if (propertyInfo.valueType() == QVariant::DateTime) { @@ -171,7 +174,7 @@ QHash<QByteArray, QVariant> KBalooRolesProvider::roleValues(const Baloo::File& f KBalooRolesProvider::KBalooRolesProvider() { // Display roles filled from Baloo property cache - for (const auto& role : propertyRoleMap()) { + for (const auto &role : propertyRoleMap()) { m_roles.insert(role); } m_roles.insert("dimensions"); @@ -182,4 +185,3 @@ KBalooRolesProvider::KBalooRolesProvider() m_roles.insert(QByteArrayLiteral("comment")); m_roles.insert(QByteArrayLiteral("originUrl")); } - diff --git a/src/kitemviews/private/kbaloorolesprovider.h b/src/kitemviews/private/kbaloorolesprovider.h index 97ed58f2b..5ff33e1c6 100644 --- a/src/kitemviews/private/kbaloorolesprovider.h +++ b/src/kitemviews/private/kbaloorolesprovider.h @@ -14,8 +14,9 @@ #include <QSet> #include <QVariant> -namespace Baloo { - class File; +namespace Baloo +{ +class File; } /** @@ -27,7 +28,7 @@ namespace Baloo { class DOLPHIN_EXPORT KBalooRolesProvider { public: - static KBalooRolesProvider& instance(); + static KBalooRolesProvider &instance(); virtual ~KBalooRolesProvider(); /** @@ -39,8 +40,7 @@ public: * @return Values for the roles \a roles that can be determined from the file * with the URL \a url. */ - QHash<QByteArray, QVariant> roleValues(const Baloo::File& file, - const QSet<QByteArray>& roles) const; + QHash<QByteArray, QVariant> roleValues(const Baloo::File &file, const QSet<QByteArray> &roles) const; protected: KBalooRolesProvider(); @@ -52,4 +52,3 @@ private: }; #endif - diff --git a/src/kitemviews/private/kdirectorycontentscounter.cpp b/src/kitemviews/private/kdirectorycontentscounter.cpp index a2a27ad28..039b79b6e 100644 --- a/src/kitemviews/private/kdirectorycontentscounter.cpp +++ b/src/kitemviews/private/kdirectorycontentscounter.cpp @@ -10,26 +10,26 @@ #include <KDirWatch> -#include <QFileInfo> #include <QDir> +#include <QFileInfo> #include <QThread> -namespace { - /// cache of directory counting result - static QHash<QString, QPair<int, long>> *s_cache; +namespace +{ +/// cache of directory counting result +static QHash<QString, QPair<int, long>> *s_cache; } -KDirectoryContentsCounter::KDirectoryContentsCounter(KFileItemModel* model, QObject* parent) : - QObject(parent), - m_model(model), - m_queue(), - m_worker(nullptr), - m_workerIsBusy(false), - m_dirWatcher(nullptr), - m_watchedDirs() +KDirectoryContentsCounter::KDirectoryContentsCounter(KFileItemModel *model, QObject *parent) + : QObject(parent) + , m_model(model) + , m_queue() + , m_worker(nullptr) + , m_workerIsBusy(false) + , m_dirWatcher(nullptr) + , m_watchedDirs() { - connect(m_model, &KFileItemModel::itemsRemoved, - this, &KDirectoryContentsCounter::slotItemsRemoved); + connect(m_model, &KFileItemModel::itemsRemoved, this, &KDirectoryContentsCounter::slotItemsRemoved); if (!m_workerThread) { m_workerThread = new QThread(); @@ -43,10 +43,8 @@ KDirectoryContentsCounter::KDirectoryContentsCounter(KFileItemModel* model, QObj m_worker = new KDirectoryContentsCounterWorker(); m_worker->moveToThread(m_workerThread); - connect(this, &KDirectoryContentsCounter::requestDirectoryContentsCount, - m_worker, &KDirectoryContentsCounterWorker::countDirectoryContents); - connect(m_worker, &KDirectoryContentsCounterWorker::result, - this, &KDirectoryContentsCounter::slotResult); + connect(this, &KDirectoryContentsCounter::requestDirectoryContentsCount, m_worker, &KDirectoryContentsCounterWorker::countDirectoryContents); + connect(m_worker, &KDirectoryContentsCounterWorker::result, this, &KDirectoryContentsCounter::slotResult); m_dirWatcher = new KDirWatch(this); connect(m_dirWatcher, &KDirWatch::dirty, this, &KDirectoryContentsCounter::slotDirWatchDirty); @@ -73,12 +71,12 @@ KDirectoryContentsCounter::~KDirectoryContentsCounter() } } -void KDirectoryContentsCounter::scanDirectory(const QString& path) +void KDirectoryContentsCounter::scanDirectory(const QString &path) { startWorker(path); } -void KDirectoryContentsCounter::slotResult(const QString& path, int count, long size) +void KDirectoryContentsCounter::slotResult(const QString &path, int count, long size) { m_workerIsBusy = false; @@ -118,7 +116,7 @@ void KDirectoryContentsCounter::slotResult(const QString& path, int count, long Q_EMIT result(path, count, size); } -void KDirectoryContentsCounter::slotDirWatchDirty(const QString& path) +void KDirectoryContentsCounter::slotDirWatchDirty(const QString &path) { const int index = m_model->index(QUrl::fromLocalFile(path)); if (index >= 0) { @@ -140,7 +138,7 @@ void KDirectoryContentsCounter::slotItemsRemoved() if (!m_watchedDirs.isEmpty()) { // Don't let KDirWatch watch for removed items if (allItemsRemoved) { - for (const QString& path : qAsConst(m_watchedDirs)) { + for (const QString &path : qAsConst(m_watchedDirs)) { m_dirWatcher->removeDir(path); } m_watchedDirs.clear(); @@ -148,7 +146,7 @@ void KDirectoryContentsCounter::slotItemsRemoved() } else { QMutableSetIterator<QString> it(m_watchedDirs); while (it.hasNext()) { - const QString& path = it.next(); + const QString &path = it.next(); if (m_model->index(QUrl::fromLocalFile(path)) < 0) { m_dirWatcher->removeDir(path); it.remove(); @@ -158,7 +156,7 @@ void KDirectoryContentsCounter::slotItemsRemoved() } } -void KDirectoryContentsCounter::startWorker(const QString& path) +void KDirectoryContentsCounter::startWorker(const QString &path) { const QString resolvedPath = QFileInfo(path).canonicalFilePath(); const bool alreadyInCache = s_cache->contains(resolvedPath); @@ -170,8 +168,8 @@ void KDirectoryContentsCounter::startWorker(const QString& path) } if (m_workerIsBusy) { - if (std::find(m_queue.begin(), m_queue.end(), path) == m_queue.end() && - std::find(m_priorityQueue.begin(), m_priorityQueue.end(), path) == m_priorityQueue.end()) { + if (std::find(m_queue.begin(), m_queue.end(), path) == m_queue.end() + && std::find(m_priorityQueue.begin(), m_priorityQueue.end(), path) == m_priorityQueue.end()) { if (alreadyInCache) { m_queue.push_back(path); } else { @@ -195,4 +193,4 @@ void KDirectoryContentsCounter::startWorker(const QString& path) } } -QThread* KDirectoryContentsCounter::m_workerThread = nullptr; +QThread *KDirectoryContentsCounter::m_workerThread = nullptr; diff --git a/src/kitemviews/private/kdirectorycontentscounter.h b/src/kitemviews/private/kdirectorycontentscounter.h index 6d3d1f3c1..f74565b73 100644 --- a/src/kitemviews/private/kdirectorycontentscounter.h +++ b/src/kitemviews/private/kdirectorycontentscounter.h @@ -21,7 +21,7 @@ class KDirectoryContentsCounter : public QObject Q_OBJECT public: - explicit KDirectoryContentsCounter(KFileItemModel* model, QObject* parent = nullptr); + explicit KDirectoryContentsCounter(KFileItemModel *model, QObject *parent = nullptr); ~KDirectoryContentsCounter() override; /** @@ -35,40 +35,40 @@ public: * Uses a cache internally to speed up first result, * but emit again result when the cache was updated */ - void scanDirectory(const QString& path); + void scanDirectory(const QString &path); Q_SIGNALS: /** * Signals that the directory \a path contains \a count items of size \a * Size calculation depends on parameter DetailsModeSettings::recursiveDirectorySizeLimit */ - void result(const QString& path, int count, long size); + void result(const QString &path, int count, long size); - void requestDirectoryContentsCount(const QString& path, KDirectoryContentsCounterWorker::Options options); + void requestDirectoryContentsCount(const QString &path, KDirectoryContentsCounterWorker::Options options); private Q_SLOTS: - void slotResult(const QString& path, int count, long size); - void slotDirWatchDirty(const QString& path); + void slotResult(const QString &path, int count, long size); + void slotDirWatchDirty(const QString &path); void slotItemsRemoved(); private: - void startWorker(const QString& path); + void startWorker(const QString &path); private: - KFileItemModel* m_model; + KFileItemModel *m_model; // Used as FIFO queues. std::list<QString> m_priorityQueue; std::list<QString> m_queue; - static QThread* m_workerThread; + static QThread *m_workerThread; - KDirectoryContentsCounterWorker* m_worker; + KDirectoryContentsCounterWorker *m_worker; bool m_workerIsBusy; - KDirWatch* m_dirWatcher; - QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method - // to get all watched directories. + KDirWatch *m_dirWatcher; + QSet<QString> m_watchedDirs; // Required as sadly KDirWatch does not offer a getter method + // to get all watched directories. }; #endif diff --git a/src/kitemviews/private/kdirectorycontentscounterworker.cpp b/src/kitemviews/private/kdirectorycontentscounterworker.cpp index 2a683cdbc..e227c1bc6 100644 --- a/src/kitemviews/private/kdirectorycontentscounterworker.cpp +++ b/src/kitemviews/private/kdirectorycontentscounterworker.cpp @@ -17,17 +17,15 @@ #include "dolphin_detailsmodesettings.h" -KDirectoryContentsCounterWorker::KDirectoryContentsCounterWorker(QObject* parent) : - QObject(parent) +KDirectoryContentsCounterWorker::KDirectoryContentsCounterWorker(QObject *parent) + : QObject(parent) { qRegisterMetaType<KDirectoryContentsCounterWorker::Options>(); } #ifndef Q_OS_WIN -KDirectoryContentsCounterWorker::CountResult walkDir(const QString &dirPath, - const bool countHiddenFiles, - const bool countDirectoriesOnly, - const uint allowedRecursiveLevel) +KDirectoryContentsCounterWorker::CountResult +walkDir(const QString &dirPath, const bool countHiddenFiles, const bool countDirectoriesOnly, const uint allowedRecursiveLevel) { int count = -1; long size = -1; @@ -53,10 +51,7 @@ KDirectoryContentsCounterWorker::CountResult walkDir(const QString &dirPath, // If only directories are counted, consider an unknown file type and links also // as directory instead of trying to do an expensive stat() // (see bugs 292642 and 299997). - const bool countEntry = !countDirectoriesOnly || - dirEntry->d_type == DT_DIR || - dirEntry->d_type == DT_LNK || - dirEntry->d_type == DT_UNKNOWN; + const bool countEntry = !countDirectoriesOnly || dirEntry->d_type == DT_DIR || dirEntry->d_type == DT_LNK || dirEntry->d_type == DT_UNKNOWN; if (countEntry) { ++count; } @@ -84,7 +79,7 @@ KDirectoryContentsCounterWorker::CountResult walkDir(const QString &dirPath, } #endif -KDirectoryContentsCounterWorker::CountResult KDirectoryContentsCounterWorker::subItemsCount(const QString& path, Options options) +KDirectoryContentsCounterWorker::CountResult KDirectoryContentsCounterWorker::subItemsCount(const QString &path, Options options) { const bool countHiddenFiles = options & CountHiddenFiles; const bool countDirectoriesOnly = options & CountDirectoriesOnly; @@ -111,7 +106,7 @@ KDirectoryContentsCounterWorker::CountResult KDirectoryContentsCounterWorker::su #endif } -void KDirectoryContentsCounterWorker::countDirectoryContents(const QString& path, Options options) +void KDirectoryContentsCounterWorker::countDirectoryContents(const QString &path, Options options) { auto res = subItemsCount(path, options); Q_EMIT result(path, res.count, res.size); diff --git a/src/kitemviews/private/kdirectorycontentscounterworker.h b/src/kitemviews/private/kdirectorycontentscounterworker.h index 48a2d1ff9..6bbe099a5 100644 --- a/src/kitemviews/private/kdirectorycontentscounterworker.h +++ b/src/kitemviews/private/kdirectorycontentscounterworker.h @@ -17,11 +17,7 @@ class KDirectoryContentsCounterWorker : public QObject Q_OBJECT public: - enum Option { - NoOptions = 0x0, - CountHiddenFiles = 0x1, - CountDirectoriesOnly = 0x2 - }; + enum Option { NoOptions = 0x0, CountHiddenFiles = 0x1, CountDirectoriesOnly = 0x2 }; Q_DECLARE_FLAGS(Options, Option) struct CountResult { @@ -32,7 +28,7 @@ public: long size; }; - explicit KDirectoryContentsCounterWorker(QObject* parent = nullptr); + explicit KDirectoryContentsCounterWorker(QObject *parent = nullptr); /** * Counts the items inside the directory \a path using the options @@ -40,13 +36,13 @@ public: * * @return The number of items. */ - static CountResult subItemsCount(const QString& path, Options options); + static CountResult subItemsCount(const QString &path, Options options); Q_SIGNALS: /** * Signals that the directory \a path contains \a count items and optionally the size of its content. */ - void result(const QString& path, int count, long size); + void result(const QString &path, int count, long size); public Q_SLOTS: /** @@ -56,7 +52,7 @@ public Q_SLOTS: // Note that the full type name KDirectoryContentsCounterWorker::Options // is needed here. Just using 'Options' is OK for the compiler, but // confuses moc. - void countDirectoryContents(const QString& path, KDirectoryContentsCounterWorker::Options options); + void countDirectoryContents(const QString &path, KDirectoryContentsCounterWorker::Options options); }; Q_DECLARE_METATYPE(KDirectoryContentsCounterWorker::Options) diff --git a/src/kitemviews/private/kfileitemclipboard.cpp b/src/kitemviews/private/kfileitemclipboard.cpp index ec31068e7..33bf298ed 100644 --- a/src/kitemviews/private/kfileitemclipboard.cpp +++ b/src/kitemviews/private/kfileitemclipboard.cpp @@ -19,14 +19,12 @@ public: }; Q_GLOBAL_STATIC(KFileItemClipboardSingleton, s_KFileItemClipboard) - - -KFileItemClipboard* KFileItemClipboard::instance() +KFileItemClipboard *KFileItemClipboard::instance() { return &s_KFileItemClipboard->instance; } -bool KFileItemClipboard::isCut(const QUrl& url) const +bool KFileItemClipboard::isCut(const QUrl &url) const { return m_cutItems.contains(url); } @@ -42,7 +40,7 @@ KFileItemClipboard::~KFileItemClipboard() void KFileItemClipboard::updateCutItems() { - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); + const QMimeData *mimeData = QApplication::clipboard()->mimeData(); // mimeData can be 0 according to https://bugs.kde.org/show_bug.cgi?id=335053 if (!mimeData) { @@ -62,12 +60,11 @@ void KFileItemClipboard::updateCutItems() Q_EMIT cutItemsChanged(); } -KFileItemClipboard::KFileItemClipboard() : - QObject(nullptr), - m_cutItems() +KFileItemClipboard::KFileItemClipboard() + : QObject(nullptr) + , m_cutItems() { updateCutItems(); - connect(QApplication::clipboard(), &QClipboard::dataChanged, - this, &KFileItemClipboard::updateCutItems); + connect(QApplication::clipboard(), &QClipboard::dataChanged, this, &KFileItemClipboard::updateCutItems); } diff --git a/src/kitemviews/private/kfileitemclipboard.h b/src/kitemviews/private/kfileitemclipboard.h index 818201308..1d3e2dedf 100644 --- a/src/kitemviews/private/kfileitemclipboard.h +++ b/src/kitemviews/private/kfileitemclipboard.h @@ -23,9 +23,9 @@ class DOLPHIN_EXPORT KFileItemClipboard : public QObject Q_OBJECT public: - static KFileItemClipboard* instance(); + static KFileItemClipboard *instance(); - bool isCut(const QUrl& url) const; + bool isCut(const QUrl &url) const; QList<QUrl> cutItems() const; diff --git a/src/kitemviews/private/kfileitemmodelfilter.cpp b/src/kitemviews/private/kfileitemmodelfilter.cpp index 6a2a4177f..f199c314f 100644 --- a/src/kitemviews/private/kfileitemmodelfilter.cpp +++ b/src/kitemviews/private/kfileitemmodelfilter.cpp @@ -10,11 +10,11 @@ #include <KFileItem> -KFileItemModelFilter::KFileItemModelFilter() : - m_useRegExp(false), - m_regExp(nullptr), - m_lowerCasePattern(), - m_pattern() +KFileItemModelFilter::KFileItemModelFilter() + : m_useRegExp(false) + , m_regExp(nullptr) + , m_lowerCasePattern() + , m_pattern() { } @@ -24,7 +24,7 @@ KFileItemModelFilter::~KFileItemModelFilter() m_regExp = nullptr; } -void KFileItemModelFilter::setPattern(const QString& filter) +void KFileItemModelFilter::setPattern(const QString &filter) { m_pattern = filter; m_lowerCasePattern = filter.toLower(); @@ -46,7 +46,7 @@ QString KFileItemModelFilter::pattern() const return m_pattern; } -void KFileItemModelFilter::setMimeTypes(const QStringList& types) +void KFileItemModelFilter::setMimeTypes(const QStringList &types) { m_mimeTypes = types; } @@ -61,8 +61,7 @@ bool KFileItemModelFilter::hasSetFilters() const return (!m_pattern.isEmpty() || !m_mimeTypes.isEmpty()); } - -bool KFileItemModelFilter::matches(const KFileItem& item) const +bool KFileItemModelFilter::matches(const KFileItem &item) const { const bool hasPatternFilter = !m_pattern.isEmpty(); const bool hasMimeTypesFilter = !m_mimeTypes.isEmpty(); @@ -85,7 +84,7 @@ bool KFileItemModelFilter::matches(const KFileItem& item) const return matchesType(item); } -bool KFileItemModelFilter::matchesPattern(const KFileItem& item) const +bool KFileItemModelFilter::matchesPattern(const KFileItem &item) const { if (m_useRegExp) { return m_regExp->match(item.text()).hasMatch(); @@ -94,9 +93,9 @@ bool KFileItemModelFilter::matchesPattern(const KFileItem& item) const } } -bool KFileItemModelFilter::matchesType(const KFileItem& item) const +bool KFileItemModelFilter::matchesType(const KFileItem &item) const { - for (const QString& mimeType : qAsConst(m_mimeTypes)) { + for (const QString &mimeType : qAsConst(m_mimeTypes)) { if (item.mimetype() == mimeType) { return true; } diff --git a/src/kitemviews/private/kfileitemmodelfilter.h b/src/kitemviews/private/kfileitemmodelfilter.h index f55a8097d..959590da8 100644 --- a/src/kitemviews/private/kfileitemmodelfilter.h +++ b/src/kitemviews/private/kfileitemmodelfilter.h @@ -24,7 +24,6 @@ class QRegularExpression; */ class DOLPHIN_EXPORT KFileItemModelFilter { - public: KFileItemModelFilter(); virtual ~KFileItemModelFilter(); @@ -35,14 +34,14 @@ public: * defines a sub-string. As soon as the pattern contains at least * a '*', '?' or '[' the pattern represents a regular expression. */ - void setPattern(const QString& pattern); + void setPattern(const QString &pattern); QString pattern() const; /** * Set the list of mimetypes that are used for comparison with the * item in KFileItemModelFilter::matchesMimeType. */ - void setMimeTypes(const QStringList& types); + void setMimeTypes(const QStringList &types); QStringList mimeTypes() const; /** @@ -54,27 +53,25 @@ public: * @return True if the item matches with the pattern defined by * @ref setPattern() or @ref setMimeTypes */ - bool matches(const KFileItem& item) const; + bool matches(const KFileItem &item) const; private: /** * @return True if item matches pattern set by @ref setPattern. */ - bool matchesPattern(const KFileItem& item) const; + bool matchesPattern(const KFileItem &item) const; /** * @return True if item matches mimetypes set by @ref setMimeTypes. */ - bool matchesType(const KFileItem& item) const; + bool matchesType(const KFileItem &item) const; - bool m_useRegExp; // If true, m_regExp is used for filtering, - // otherwise m_lowerCaseFilter is used. + bool m_useRegExp; // If true, m_regExp is used for filtering, + // otherwise m_lowerCaseFilter is used. QRegularExpression *m_regExp; QString m_lowerCasePattern; // Lowercase version of m_filter for // faster comparison in matches(). - QString m_pattern; // Property set by setPattern(). - QStringList m_mimeTypes; // Property set by setMimeTypes() + QString m_pattern; // Property set by setPattern(). + QStringList m_mimeTypes; // Property set by setMimeTypes() }; #endif - - diff --git a/src/kitemviews/private/kfileitemmodelsortalgorithm.h b/src/kitemviews/private/kfileitemmodelsortalgorithm.h index 4fe6aa66a..29c1fe5ac 100644 --- a/src/kitemviews/private/kfileitemmodelsortalgorithm.h +++ b/src/kitemviews/private/kfileitemmodelsortalgorithm.h @@ -21,10 +21,8 @@ * SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). */ -template <typename RandomAccessIterator, typename LessThan> -static void mergeSort(RandomAccessIterator begin, - RandomAccessIterator end, - const LessThan& lessThan) +template<typename RandomAccessIterator, typename LessThan> +static void mergeSort(RandomAccessIterator begin, RandomAccessIterator end, const LessThan &lessThan) { // The implementation is based on qStableSortHelper() from qalgorithms.h // SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). @@ -49,12 +47,9 @@ static void mergeSort(RandomAccessIterator begin, * The comparison function \a lessThan must be reentrant. */ -template <typename RandomAccessIterator, typename LessThan> -static void parallelMergeSort(RandomAccessIterator begin, - RandomAccessIterator end, - LessThan lessThan, - int numberOfThreads, - int parallelMergeSortingThreshold = 100) +template<typename RandomAccessIterator, typename LessThan> +static void +parallelMergeSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan, int numberOfThreads, int parallelMergeSortingThreshold = 100) { const int span = end - begin; @@ -62,7 +57,8 @@ static void parallelMergeSort(RandomAccessIterator begin, const int newNumberOfThreads = numberOfThreads / 2; const RandomAccessIterator middle = begin + span / 2; - QFuture<void> future = QtConcurrent::run(parallelMergeSort<RandomAccessIterator, LessThan>, begin, middle, lessThan, newNumberOfThreads, parallelMergeSortingThreshold); + QFuture<void> future = + QtConcurrent::run(parallelMergeSort<RandomAccessIterator, LessThan>, begin, middle, lessThan, newNumberOfThreads, parallelMergeSortingThreshold); parallelMergeSort(middle, end, lessThan, newNumberOfThreads, parallelMergeSortingThreshold); future.waitForFinished(); @@ -82,11 +78,8 @@ static void parallelMergeSort(RandomAccessIterator begin, * SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). */ -template <typename RandomAccessIterator, typename LessThan> -static void merge(RandomAccessIterator begin, - RandomAccessIterator pivot, - RandomAccessIterator end, - const LessThan& lessThan) +template<typename RandomAccessIterator, typename LessThan> +static void merge(RandomAccessIterator begin, RandomAccessIterator pivot, RandomAccessIterator end, const LessThan &lessThan) { // The implementation is based on qMerge() from qalgorithms.h // SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). @@ -111,14 +104,12 @@ static void merge(RandomAccessIterator begin, if (len1 > len2) { const int len1Half = len1 / 2; firstCut = begin + len1Half; - secondCut = std::lower_bound<RandomAccessIterator, - decltype(*firstCut), const LessThan&>(pivot, end, *firstCut, lessThan); + secondCut = std::lower_bound<RandomAccessIterator, decltype(*firstCut), const LessThan &>(pivot, end, *firstCut, lessThan); len2Half = secondCut - pivot; } else { len2Half = len2 / 2; secondCut = pivot + len2Half; - firstCut = std::upper_bound<RandomAccessIterator, - decltype(*secondCut), const LessThan&>(begin, pivot, *secondCut, lessThan); + firstCut = std::upper_bound<RandomAccessIterator, decltype(*secondCut), const LessThan &>(begin, pivot, *secondCut, lessThan); } std::rotate(firstCut, pivot, secondCut); @@ -129,4 +120,3 @@ static void merge(RandomAccessIterator begin, } #endif - diff --git a/src/kitemviews/private/kitemlistheaderwidget.cpp b/src/kitemviews/private/kitemlistheaderwidget.cpp index 9f4f868d0..ac25d189c 100644 --- a/src/kitemviews/private/kitemlistheaderwidget.cpp +++ b/src/kitemviews/private/kitemlistheaderwidget.cpp @@ -12,21 +12,20 @@ #include <QPainter> #include <QStyleOptionHeader> - -KItemListHeaderWidget::KItemListHeaderWidget(QGraphicsWidget* parent) : - QGraphicsWidget(parent), - m_automaticColumnResizing(true), - m_model(nullptr), - m_offset(0), - m_sidePadding(0), - m_columns(), - m_columnWidths(), - m_preferredColumnWidths(), - m_hoveredRoleIndex(-1), - m_pressedRoleIndex(-1), - m_roleOperation(NoRoleOperation), - m_pressedMousePos(), - m_movingRole() +KItemListHeaderWidget::KItemListHeaderWidget(QGraphicsWidget *parent) + : QGraphicsWidget(parent) + , m_automaticColumnResizing(true) + , m_model(nullptr) + , m_offset(0) + , m_sidePadding(0) + , m_columns() + , m_columnWidths() + , m_preferredColumnWidths() + , m_hoveredRoleIndex(-1) + , m_pressedRoleIndex(-1) + , m_roleOperation(NoRoleOperation) + , m_pressedMousePos() + , m_movingRole() { m_movingRole.x = 0; m_movingRole.xDec = 0; @@ -41,30 +40,26 @@ KItemListHeaderWidget::~KItemListHeaderWidget() { } -void KItemListHeaderWidget::setModel(KItemModelBase* model) +void KItemListHeaderWidget::setModel(KItemModelBase *model) { if (m_model == model) { return; } if (m_model) { - disconnect(m_model, &KItemModelBase::sortRoleChanged, - this, &KItemListHeaderWidget::slotSortRoleChanged); - disconnect(m_model, &KItemModelBase::sortOrderChanged, - this, &KItemListHeaderWidget::slotSortOrderChanged); + disconnect(m_model, &KItemModelBase::sortRoleChanged, this, &KItemListHeaderWidget::slotSortRoleChanged); + disconnect(m_model, &KItemModelBase::sortOrderChanged, this, &KItemListHeaderWidget::slotSortOrderChanged); } m_model = model; if (m_model) { - connect(m_model, &KItemModelBase::sortRoleChanged, - this, &KItemListHeaderWidget::slotSortRoleChanged); - connect(m_model, &KItemModelBase::sortOrderChanged, - this, &KItemListHeaderWidget::slotSortOrderChanged); + connect(m_model, &KItemModelBase::sortRoleChanged, this, &KItemListHeaderWidget::slotSortRoleChanged); + connect(m_model, &KItemModelBase::sortOrderChanged, this, &KItemListHeaderWidget::slotSortOrderChanged); } } -KItemModelBase* KItemListHeaderWidget::model() const +KItemModelBase *KItemListHeaderWidget::model() const { return m_model; } @@ -79,9 +74,9 @@ bool KItemListHeaderWidget::automaticColumnResizing() const return m_automaticColumnResizing; } -void KItemListHeaderWidget::setColumns(const QList<QByteArray>& roles) +void KItemListHeaderWidget::setColumns(const QList<QByteArray> &roles) { - for (const QByteArray& role : roles) { + for (const QByteArray &role : roles) { if (!m_columnWidths.contains(role)) { m_preferredColumnWidths.remove(role); } @@ -96,7 +91,7 @@ QList<QByteArray> KItemListHeaderWidget::columns() const return m_columns; } -void KItemListHeaderWidget::setColumnWidth(const QByteArray& role, qreal width) +void KItemListHeaderWidget::setColumnWidth(const QByteArray &role, qreal width) { const qreal minWidth = minimumColumnWidth(); if (width < minWidth) { @@ -109,17 +104,17 @@ void KItemListHeaderWidget::setColumnWidth(const QByteArray& role, qreal width) } } -qreal KItemListHeaderWidget::columnWidth(const QByteArray& role) const +qreal KItemListHeaderWidget::columnWidth(const QByteArray &role) const { return m_columnWidths.value(role); } -void KItemListHeaderWidget::setPreferredColumnWidth(const QByteArray& role, qreal width) +void KItemListHeaderWidget::setPreferredColumnWidth(const QByteArray &role, qreal width) { m_preferredColumnWidths.insert(role, width); } -qreal KItemListHeaderWidget::preferredColumnWidth(const QByteArray& role) const +qreal KItemListHeaderWidget::preferredColumnWidth(const QByteArray &role) const { return m_preferredColumnWidths.value(role); } @@ -157,7 +152,7 @@ qreal KItemListHeaderWidget::minimumColumnWidth() const return fontMetrics.height() * 4; } -void KItemListHeaderWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void KItemListHeaderWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) Q_UNUSED(widget) @@ -172,7 +167,7 @@ void KItemListHeaderWidget::paint(QPainter* painter, const QStyleOptionGraphicsI qreal x = -m_offset + m_sidePadding; int orderIndex = 0; - for (const QByteArray& role : qAsConst(m_columns)) { + for (const QByteArray &role : qAsConst(m_columns)) { const qreal roleWidth = m_columnWidths.value(role); const QRectF rect(x, 0, roleWidth, size().height()); paintRole(painter, role, rect, orderIndex, widget); @@ -186,7 +181,7 @@ void KItemListHeaderWidget::paint(QPainter* painter, const QStyleOptionGraphicsI } } -void KItemListHeaderWidget::mousePressEvent(QGraphicsSceneMouseEvent* event) +void KItemListHeaderWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() & Qt::LeftButton) { m_pressedMousePos = event->pos(); @@ -194,8 +189,7 @@ void KItemListHeaderWidget::mousePressEvent(QGraphicsSceneMouseEvent* event) m_roleOperation = ResizePaddingColumnOperation; } else { updatePressedRoleIndex(event->pos()); - m_roleOperation = isAboveRoleGrip(m_pressedMousePos, m_pressedRoleIndex) ? - ResizeRoleOperation : NoRoleOperation; + m_roleOperation = isAboveRoleGrip(m_pressedMousePos, m_pressedRoleIndex) ? ResizeRoleOperation : NoRoleOperation; } event->accept(); } else { @@ -203,7 +197,7 @@ void KItemListHeaderWidget::mousePressEvent(QGraphicsSceneMouseEvent* event) } } -void KItemListHeaderWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +void KItemListHeaderWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { QGraphicsWidget::mouseReleaseEvent(event); @@ -219,8 +213,7 @@ void KItemListHeaderWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) if (m_pressedRoleIndex == sortRoleIndex) { // Toggle the sort order const Qt::SortOrder previous = m_model->sortOrder(); - const Qt::SortOrder current = (m_model->sortOrder() == Qt::AscendingOrder) ? - Qt::DescendingOrder : Qt::AscendingOrder; + const Qt::SortOrder current = (m_model->sortOrder() == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder; m_model->setSortOrder(current); Q_EMIT sortOrderChanged(current, previous); } else { @@ -264,7 +257,7 @@ void KItemListHeaderWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) QApplication::restoreOverrideCursor(); } -void KItemListHeaderWidget::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +void KItemListHeaderWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { QGraphicsWidget::mouseMoveEvent(event); @@ -352,7 +345,7 @@ void KItemListHeaderWidget::mouseMoveEvent(QGraphicsSceneMouseEvent* event) } } -void KItemListHeaderWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) +void KItemListHeaderWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { QGraphicsItem::mouseDoubleClickEvent(event); @@ -369,13 +362,13 @@ void KItemListHeaderWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* even } } -void KItemListHeaderWidget::hoverEnterEvent(QGraphicsSceneHoverEvent* event) +void KItemListHeaderWidget::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { QGraphicsWidget::hoverEnterEvent(event); updateHoveredRoleIndex(event->pos()); } -void KItemListHeaderWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) +void KItemListHeaderWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { QGraphicsWidget::hoverLeaveEvent(event); if (m_hoveredRoleIndex != -1) { @@ -384,22 +377,21 @@ void KItemListHeaderWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) } } -void KItemListHeaderWidget::hoverMoveEvent(QGraphicsSceneHoverEvent* event) +void KItemListHeaderWidget::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { QGraphicsWidget::hoverMoveEvent(event); - const QPointF& pos = event->pos(); + const QPointF &pos = event->pos(); updateHoveredRoleIndex(pos); - if ((m_hoveredRoleIndex >= 0 && isAboveRoleGrip(pos, m_hoveredRoleIndex)) || - isAbovePaddingGrip(pos, PaddingGrip::Leading) || - isAbovePaddingGrip(pos, PaddingGrip::Trailing)) { + if ((m_hoveredRoleIndex >= 0 && isAboveRoleGrip(pos, m_hoveredRoleIndex)) || isAbovePaddingGrip(pos, PaddingGrip::Leading) + || isAbovePaddingGrip(pos, PaddingGrip::Trailing)) { setCursor(Qt::SplitHCursor); } else { unsetCursor(); } } -void KItemListHeaderWidget::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) +void KItemListHeaderWidget::slotSortRoleChanged(const QByteArray ¤t, const QByteArray &previous) { Q_UNUSED(current) Q_UNUSED(previous) @@ -413,11 +405,7 @@ void KItemListHeaderWidget::slotSortOrderChanged(Qt::SortOrder current, Qt::Sort update(); } -void KItemListHeaderWidget::paintRole(QPainter* painter, - const QByteArray& role, - const QRectF& rect, - int orderIndex, - QWidget* widget) const +void KItemListHeaderWidget::paintRole(QPainter *painter, const QByteArray &role, const QRectF &rect, int orderIndex, QWidget *widget) const { const auto direction = widget ? widget->layoutDirection() : qApp->layoutDirection(); @@ -425,10 +413,7 @@ void KItemListHeaderWidget::paintRole(QPainter* painter, // SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). QStyleOptionHeader option; option.direction = direction; - option.textAlignment = - direction == Qt::LeftToRight - ? Qt::AlignLeft - : Qt::AlignRight; + option.textAlignment = direction == Qt::LeftToRight ? Qt::AlignLeft : Qt::AlignRight; option.section = orderIndex; option.state = QStyle::State_None | QStyle::State_Raised | QStyle::State_Horizontal; @@ -445,8 +430,7 @@ void KItemListHeaderWidget::paintRole(QPainter* painter, option.state |= QStyle::State_Sunken; } if (m_model->sortRole() == role) { - option.sortIndicator = (m_model->sortOrder() == Qt::AscendingOrder) ? - QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp; + option.sortIndicator = (m_model->sortOrder() == Qt::AscendingOrder) ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp; } option.rect = rect.toRect(); option.orientation = Qt::Horizontal; @@ -454,7 +438,7 @@ void KItemListHeaderWidget::paintRole(QPainter* painter, option.text = m_model->roleDescription(role); // First we paint any potential empty (padding) space on left and/or right of this role's column. - const auto paintPadding = [&](int section, const QRectF &rect, const QStyleOptionHeader::SectionPosition &pos){ + const auto paintPadding = [&](int section, const QRectF &rect, const QStyleOptionHeader::SectionPosition &pos) { QStyleOptionHeader padding; padding.state = QStyle::State_None | QStyle::State_Raised | QStyle::State_Horizontal; padding.section = section; @@ -473,7 +457,7 @@ void KItemListHeaderWidget::paintRole(QPainter* painter, // Paint the header for the first column; check if there is some empty space to the left which needs to be filled. if (rect.left() > 0) { option.position = QStyleOptionHeader::Middle; - paintPadding(0,QRectF(0.0, 0.0, rect.left(), rect.height()), QStyleOptionHeader::Beginning); + paintPadding(0, QRectF(0.0, 0.0, rect.left(), rect.height()), QStyleOptionHeader::Beginning); } else { option.position = QStyleOptionHeader::Beginning; } @@ -492,7 +476,7 @@ void KItemListHeaderWidget::paintRole(QPainter* painter, style()->drawControl(QStyle::CE_Header, &option, painter, widget); } -void KItemListHeaderWidget::updatePressedRoleIndex(const QPointF& pos) +void KItemListHeaderWidget::updatePressedRoleIndex(const QPointF &pos) { const int pressedIndex = roleIndexAt(pos); if (m_pressedRoleIndex != pressedIndex) { @@ -501,7 +485,7 @@ void KItemListHeaderWidget::updatePressedRoleIndex(const QPointF& pos) } } -void KItemListHeaderWidget::updateHoveredRoleIndex(const QPointF& pos) +void KItemListHeaderWidget::updateHoveredRoleIndex(const QPointF &pos) { const int hoverIndex = roleIndexAt(pos); if (m_hoveredRoleIndex != hoverIndex) { @@ -510,12 +494,12 @@ void KItemListHeaderWidget::updateHoveredRoleIndex(const QPointF& pos) } } -int KItemListHeaderWidget::roleIndexAt(const QPointF& pos) const +int KItemListHeaderWidget::roleIndexAt(const QPointF &pos) const { int index = -1; qreal x = -m_offset + m_sidePadding; - for (const QByteArray& role : qAsConst(m_columns)) { + for (const QByteArray &role : qAsConst(m_columns)) { ++index; x += m_columnWidths.value(role); if (pos.x() <= x) { @@ -526,7 +510,7 @@ int KItemListHeaderWidget::roleIndexAt(const QPointF& pos) const return index; } -bool KItemListHeaderWidget::isAboveRoleGrip(const QPointF& pos, int roleIndex) const +bool KItemListHeaderWidget::isAboveRoleGrip(const QPointF &pos, int roleIndex) const { qreal x = -m_offset + m_sidePadding; for (int i = 0; i <= roleIndex; ++i) { @@ -538,7 +522,7 @@ bool KItemListHeaderWidget::isAboveRoleGrip(const QPointF& pos, int roleIndex) c return pos.x() >= (x - grip) && pos.x() <= x; } -bool KItemListHeaderWidget::isAbovePaddingGrip(const QPointF& pos, PaddingGrip paddingGrip) const +bool KItemListHeaderWidget::isAbovePaddingGrip(const QPointF &pos, PaddingGrip paddingGrip) const { const qreal lx = -m_offset + m_sidePadding; const int grip = style()->pixelMetric(QStyle::PM_HeaderGripMargin); @@ -546,10 +530,9 @@ bool KItemListHeaderWidget::isAbovePaddingGrip(const QPointF& pos, PaddingGrip p switch (paddingGrip) { case Leading: return pos.x() >= (lx - grip) && pos.x() <= lx; - case Trailing: - { + case Trailing: { qreal rx = lx; - for (const QByteArray& role : qAsConst(m_columns)) { + for (const QByteArray &role : qAsConst(m_columns)) { rx += m_columnWidths.value(role); } return pos.x() >= (rx - grip) && pos.x() <= rx; @@ -596,12 +579,8 @@ int KItemListHeaderWidget::targetOfMovingRole() const const qreal targetWidth = m_columnWidths.value(role); const qreal targetRight = targetLeft + targetWidth - 1; - const bool isInTarget = (targetWidth >= movingWidth && - movingLeft >= targetLeft && - movingRight <= targetRight) || - (targetWidth < movingWidth && - movingLeft <= targetLeft && - movingRight >= targetRight); + const bool isInTarget = (targetWidth >= movingWidth && movingLeft >= targetLeft && movingRight <= targetRight) + || (targetWidth < movingWidth && movingLeft <= targetLeft && movingRight >= targetRight); if (isInTarget) { return targetIndex; @@ -614,10 +593,10 @@ int KItemListHeaderWidget::targetOfMovingRole() const return m_movingRole.index; } -qreal KItemListHeaderWidget::roleXPosition(const QByteArray& role) const +qreal KItemListHeaderWidget::roleXPosition(const QByteArray &role) const { qreal x = -m_offset + m_sidePadding; - for (const QByteArray& visibleRole : qAsConst(m_columns)) { + for (const QByteArray &visibleRole : qAsConst(m_columns)) { if (visibleRole == role) { return x; } @@ -627,4 +606,3 @@ qreal KItemListHeaderWidget::roleXPosition(const QByteArray& role) const return -1; } - diff --git a/src/kitemviews/private/kitemlistheaderwidget.h b/src/kitemviews/private/kitemlistheaderwidget.h index f99d64c81..58c27b43a 100644 --- a/src/kitemviews/private/kitemlistheaderwidget.h +++ b/src/kitemviews/private/kitemlistheaderwidget.h @@ -26,26 +26,26 @@ class DOLPHIN_EXPORT KItemListHeaderWidget : public QGraphicsWidget Q_OBJECT public: - explicit KItemListHeaderWidget(QGraphicsWidget* parent = nullptr); + explicit KItemListHeaderWidget(QGraphicsWidget *parent = nullptr); ~KItemListHeaderWidget() override; - void setModel(KItemModelBase* model); - KItemModelBase* model() const; + void setModel(KItemModelBase *model); + KItemModelBase *model() const; void setAutomaticColumnResizing(bool automatic); bool automaticColumnResizing() const; - void setColumns(const QList<QByteArray>& roles); + void setColumns(const QList<QByteArray> &roles); QList<QByteArray> columns() const; - void setColumnWidth(const QByteArray& role, qreal width); - qreal columnWidth(const QByteArray& role) const; + void setColumnWidth(const QByteArray &role, qreal width); + qreal columnWidth(const QByteArray &role) const; /** * Sets the column-width that is required to show the role unclipped. */ - void setPreferredColumnWidth(const QByteArray& role, qreal width); - qreal preferredColumnWidth(const QByteArray& role) const; + void setPreferredColumnWidth(const QByteArray &role, qreal width); + qreal preferredColumnWidth(const QByteArray &role) const; void setOffset(qreal offset); qreal offset() const; @@ -55,16 +55,14 @@ public: qreal minimumColumnWidth() const; - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; Q_SIGNALS: /** * Is emitted if the width of a visible role has been adjusted by the user with the mouse * (no signal is emitted if KItemListHeader::setVisibleRoleWidth() is invoked). */ - void columnWidthChanged(const QByteArray& role, - qreal currentWidth, - qreal previousWidth); + void columnWidthChanged(const QByteArray &role, qreal currentWidth, qreal previousWidth); void sidePaddingChanged(qreal width); @@ -72,13 +70,12 @@ Q_SIGNALS: * Is emitted if the user has released the mouse button after adjusting the * width of a visible role. */ - void columnWidthChangeFinished(const QByteArray& role, - qreal currentWidth); + void columnWidthChangeFinished(const QByteArray &role, qreal currentWidth); /** * Is emitted if the position of the column has been changed. */ - void columnMoved(const QByteArray& role, int currentIndex, int previousIndex); + void columnMoved(const QByteArray &role, int currentIndex, int previousIndex); /** * Is emitted if the user has changed the sort order by clicking on a @@ -94,40 +91,34 @@ Q_SIGNALS: * the current sort role. Note that no signal will be emitted if the * sort role of the model has been changed without user interaction. */ - void sortRoleChanged(const QByteArray& current, const QByteArray& previous); + void sortRoleChanged(const QByteArray ¤t, const QByteArray &previous); protected: - void mousePressEvent(QGraphicsSceneMouseEvent* event) override; - void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override; - void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override; - void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override; - void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override; - void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override; + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; + void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; + void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override; private Q_SLOTS: - void slotSortRoleChanged(const QByteArray& current, const QByteArray& previous); + void slotSortRoleChanged(const QByteArray ¤t, const QByteArray &previous); void slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); private: - - enum PaddingGrip - { + enum PaddingGrip { Leading, Trailing, }; - void paintRole(QPainter* painter, - const QByteArray& role, - const QRectF& rect, - int orderIndex, - QWidget* widget = nullptr) const; + void paintRole(QPainter *painter, const QByteArray &role, const QRectF &rect, int orderIndex, QWidget *widget = nullptr) const; - void updatePressedRoleIndex(const QPointF& pos); - void updateHoveredRoleIndex(const QPointF& pos); - int roleIndexAt(const QPointF& pos) const; - bool isAboveRoleGrip(const QPointF& pos, int roleIndex) const; - bool isAbovePaddingGrip(const QPointF& pos, PaddingGrip paddingGrip) const; + void updatePressedRoleIndex(const QPointF &pos); + void updateHoveredRoleIndex(const QPointF &pos); + int roleIndexAt(const QPointF &pos) const; + bool isAboveRoleGrip(const QPointF &pos, int roleIndex) const; + bool isAbovePaddingGrip(const QPointF &pos, PaddingGrip paddingGrip) const; /** * Creates a pixmap of the role with the index \a roleIndex that is shown @@ -144,19 +135,13 @@ private: /** * @return x-position of the left border of the role \a role. */ - qreal roleXPosition(const QByteArray& role) const; + qreal roleXPosition(const QByteArray &role) const; private: - enum RoleOperation - { - NoRoleOperation, - ResizeRoleOperation, - ResizePaddingColumnOperation, - MoveRoleOperation - }; + enum RoleOperation { NoRoleOperation, ResizeRoleOperation, ResizePaddingColumnOperation, MoveRoleOperation }; bool m_automaticColumnResizing; - KItemModelBase* m_model; + KItemModelBase *m_model; qreal m_offset; qreal m_sidePadding; QList<QByteArray> m_columns; @@ -168,8 +153,7 @@ private: RoleOperation m_roleOperation; QPointF m_pressedMousePos; - struct MovingRole - { + struct MovingRole { QPixmap pixmap; int x; int xDec; @@ -178,5 +162,3 @@ private: }; #endif - - diff --git a/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp b/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp index e646a6249..b7318b344 100644 --- a/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp +++ b/src/kitemviews/private/kitemlistkeyboardsearchmanager.cpp @@ -8,10 +8,10 @@ #include "kitemlistkeyboardsearchmanager.h" -KItemListKeyboardSearchManager::KItemListKeyboardSearchManager(QObject* parent) : - QObject(parent), - m_isSearchRestarted(false), - m_timeout(1000) +KItemListKeyboardSearchManager::KItemListKeyboardSearchManager(QObject *parent) + : QObject(parent) + , m_isSearchRestarted(false) + , m_timeout(1000) { m_keyboardInputTime.invalidate(); } @@ -27,7 +27,7 @@ bool KItemListKeyboardSearchManager::shouldClearSearchIfInputTimeReached() return (keyboardInputTimeElapsed > m_timeout) || !keyboardTimeWasValid; } -void KItemListKeyboardSearchManager::addKeys(const QString& keys) +void KItemListKeyboardSearchManager::addKeys(const QString &keys) { if (shouldClearSearchIfInputTimeReached()) { m_searchedString.clear(); @@ -94,7 +94,7 @@ void KItemListKeyboardSearchManager::slotCurrentChanged(int current, int previou } } -void KItemListKeyboardSearchManager::slotSelectionChanged(const KItemSet& current, const KItemSet& previous) +void KItemListKeyboardSearchManager::slotSelectionChanged(const KItemSet ¤t, const KItemSet &previous) { if (!previous.isEmpty() && current.isEmpty() && previous.count() > 0 && current.count() == 0) { // The selection has been emptied. We should cancel the search. diff --git a/src/kitemviews/private/kitemlistkeyboardsearchmanager.h b/src/kitemviews/private/kitemlistkeyboardsearchmanager.h index 80caea2ed..d370bc9ba 100644 --- a/src/kitemviews/private/kitemlistkeyboardsearchmanager.h +++ b/src/kitemviews/private/kitemlistkeyboardsearchmanager.h @@ -27,14 +27,13 @@ class DOLPHIN_EXPORT KItemListKeyboardSearchManager : public QObject Q_OBJECT public: - - explicit KItemListKeyboardSearchManager(QObject* parent = nullptr); + explicit KItemListKeyboardSearchManager(QObject *parent = nullptr); ~KItemListKeyboardSearchManager() override; /** * Add \a keys to the text buffer used for searching. */ - void addKeys(const QString& keys); + void addKeys(const QString &keys); /** * @returns true if the next call to addKeys() will trigger a new search. * Returns false if the next added key char will be added to the search string that was used previously. @@ -55,7 +54,7 @@ public: public Q_SLOTS: void slotCurrentChanged(int current, int previous); - void slotSelectionChanged(const KItemSet& current, const KItemSet& previous); + void slotSelectionChanged(const KItemSet ¤t, const KItemSet &previous); Q_SIGNALS: /** @@ -67,7 +66,7 @@ Q_SIGNALS: */ // TODO: Think about getting rid of the bool parameter // (see https://doc.qt.io/archives/qq/qq13-apis.html#thebooleanparametertrap) - void changeCurrentItem(const QString& string, bool searchFromNextItem); + void changeCurrentItem(const QString &string, bool searchFromNextItem); private: bool shouldClearSearchIfInputTimeReached(); @@ -82,5 +81,3 @@ private: }; #endif - - diff --git a/src/kitemviews/private/kitemlistroleeditor.cpp b/src/kitemviews/private/kitemlistroleeditor.cpp index 993c6893a..d3389832b 100644 --- a/src/kitemviews/private/kitemlistroleeditor.cpp +++ b/src/kitemviews/private/kitemlistroleeditor.cpp @@ -8,10 +8,10 @@ #include <KIO/Global> -KItemListRoleEditor::KItemListRoleEditor(QWidget *parent) : - KTextEdit(parent), - m_role(), - m_blockFinishedSignal(false) +KItemListRoleEditor::KItemListRoleEditor(QWidget *parent) + : KTextEdit(parent) + , m_role() + , m_blockFinishedSignal(false) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -30,7 +30,7 @@ KItemListRoleEditor::~KItemListRoleEditor() { } -void KItemListRoleEditor::setRole(const QByteArray& role) +void KItemListRoleEditor::setRole(const QByteArray &role) { m_role = role; } @@ -45,7 +45,7 @@ void KItemListRoleEditor::setAllowUpDownKeyChainEdit(bool allowChainEdit) m_allowUpDownKeyChainEdit = allowChainEdit; } -bool KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event) +bool KItemListRoleEditor::eventFilter(QObject *watched, QEvent *event) { if (watched == parentWidget() && event->type() == QEvent::Resize) { emitRoleEditingFinished(); @@ -54,10 +54,10 @@ bool KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event) return KTextEdit::eventFilter(watched, event); } -bool KItemListRoleEditor::event(QEvent* event) +bool KItemListRoleEditor::event(QEvent *event) { if (event->type() == QEvent::FocusOut) { - QFocusEvent* focusEvent = static_cast<QFocusEvent*>(event); + QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event); if (focusEvent->reason() != Qt::PopupFocusReason) { emitRoleEditingFinished(); } @@ -65,7 +65,7 @@ bool KItemListRoleEditor::event(QEvent* event) return KTextEdit::event(event); } -void KItemListRoleEditor::keyPressEvent(QKeyEvent* event) +void KItemListRoleEditor::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case Qt::Key_Escape: @@ -118,12 +118,8 @@ void KItemListRoleEditor::keyPressEvent(QKeyEvent* event) case Qt::Key_Home: case Qt::Key_End: { if (event->modifiers() == Qt::NoModifier || event->modifiers() == Qt::ShiftModifier) { - const QTextCursor::MoveOperation op = event->key() == Qt::Key_Home - ? QTextCursor::Start - : QTextCursor::End; - const QTextCursor::MoveMode mode = event->modifiers() == Qt::NoModifier - ? QTextCursor::MoveAnchor - : QTextCursor::KeepAnchor; + const QTextCursor::MoveOperation op = event->key() == Qt::Key_Home ? QTextCursor::Start : QTextCursor::End; + const QTextCursor::MoveMode mode = event->modifiers() == Qt::NoModifier ? QTextCursor::MoveAnchor : QTextCursor::KeepAnchor; QTextCursor cursor = textCursor(); cursor.movePosition(op, mode); setTextCursor(cursor); @@ -167,10 +163,9 @@ void KItemListRoleEditor::autoAdjustSize() void KItemListRoleEditor::emitRoleEditingFinished(EditResultDirection direction) { QVariant ret; - ret.setValue(EditResult {KIO::encodeFileName(toPlainText()), direction}); + ret.setValue(EditResult{KIO::encodeFileName(toPlainText()), direction}); if (!m_blockFinishedSignal) { Q_EMIT roleEditingFinished(m_role, ret); } } - diff --git a/src/kitemviews/private/kitemlistroleeditor.h b/src/kitemviews/private/kitemlistroleeditor.h index a0f55df51..18304374d 100644 --- a/src/kitemviews/private/kitemlistroleeditor.h +++ b/src/kitemviews/private/kitemlistroleeditor.h @@ -11,15 +11,14 @@ #include <KTextEdit> -enum EditResultDirection{ +enum EditResultDirection { EditDone, EditNext, EditPrevious, }; Q_DECLARE_METATYPE(EditResultDirection) -struct EditResult -{ +struct EditResult { QString newName; EditResultDirection direction; }; @@ -39,22 +38,22 @@ class DOLPHIN_EXPORT KItemListRoleEditor : public KTextEdit Q_OBJECT public: - explicit KItemListRoleEditor(QWidget* parent); + explicit KItemListRoleEditor(QWidget *parent); ~KItemListRoleEditor() override; - void setRole(const QByteArray& role); + void setRole(const QByteArray &role); QByteArray role() const; void setAllowUpDownKeyChainEdit(bool allowChainEdit); - bool eventFilter(QObject* watched, QEvent* event) override; + bool eventFilter(QObject *watched, QEvent *event) override; Q_SIGNALS: - void roleEditingFinished(const QByteArray& role, const QVariant& value); - void roleEditingCanceled(const QByteArray& role, const QVariant& value); + void roleEditingFinished(const QByteArray &role, const QVariant &value); + void roleEditingCanceled(const QByteArray &role, const QVariant &value); protected: - bool event(QEvent* event) override; - void keyPressEvent(QKeyEvent* event) override; + bool event(QEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; private Q_SLOTS: /** diff --git a/src/kitemviews/private/kitemlistrubberband.cpp b/src/kitemviews/private/kitemlistrubberband.cpp index 646139a33..e572780e7 100644 --- a/src/kitemviews/private/kitemlistrubberband.cpp +++ b/src/kitemviews/private/kitemlistrubberband.cpp @@ -6,11 +6,11 @@ #include "kitemlistrubberband.h" -KItemListRubberBand::KItemListRubberBand(QObject* parent) : - QObject(parent), - m_active(false), - m_startPos(), - m_endPos() +KItemListRubberBand::KItemListRubberBand(QObject *parent) + : QObject(parent) + , m_active(false) + , m_startPos() + , m_endPos() { } @@ -18,7 +18,7 @@ KItemListRubberBand::~KItemListRubberBand() { } -void KItemListRubberBand::setStartPosition(const QPointF& pos) +void KItemListRubberBand::setStartPosition(const QPointF &pos) { if (m_startPos != pos) { const QPointF previous = m_startPos; @@ -32,7 +32,7 @@ QPointF KItemListRubberBand::startPosition() const return m_startPos; } -void KItemListRubberBand::setEndPosition(const QPointF& pos) +void KItemListRubberBand::setEndPosition(const QPointF &pos) { if (m_endPos != pos) { const QPointF previous = m_endPos; @@ -74,4 +74,3 @@ bool KItemListRubberBand::isActive() const { return m_active; } - diff --git a/src/kitemviews/private/kitemlistrubberband.h b/src/kitemviews/private/kitemlistrubberband.h index 11febcf7e..fd1416b56 100644 --- a/src/kitemviews/private/kitemlistrubberband.h +++ b/src/kitemviews/private/kitemlistrubberband.h @@ -21,13 +21,13 @@ class DOLPHIN_EXPORT KItemListRubberBand : public QObject Q_PROPERTY(QPointF endPosition MEMBER m_endPos READ endPosition WRITE setEndPosition) public: - explicit KItemListRubberBand(QObject* parent = nullptr); + explicit KItemListRubberBand(QObject *parent = nullptr); ~KItemListRubberBand() override; - void setStartPosition(const QPointF& pos); + void setStartPosition(const QPointF &pos); QPointF startPosition() const; - void setEndPosition(const QPointF& pos); + void setEndPosition(const QPointF &pos); QPointF endPosition() const; void setActive(bool active); @@ -35,8 +35,8 @@ public: Q_SIGNALS: void activationChanged(bool active); - void startPositionChanged(const QPointF& current, const QPointF& previous); - void endPositionChanged(const QPointF& current, const QPointF& previous); + void startPositionChanged(const QPointF ¤t, const QPointF &previous); + void endPositionChanged(const QPointF ¤t, const QPointF &previous); private: bool m_active; @@ -45,5 +45,3 @@ private: }; #endif - - diff --git a/src/kitemviews/private/kitemlistselectiontoggle.cpp b/src/kitemviews/private/kitemlistselectiontoggle.cpp index 2905e2925..bec32b3d3 100644 --- a/src/kitemviews/private/kitemlistselectiontoggle.cpp +++ b/src/kitemviews/private/kitemlistselectiontoggle.cpp @@ -11,10 +11,10 @@ #include <QIcon> #include <QPainter> -KItemListSelectionToggle::KItemListSelectionToggle(QGraphicsItem* parent) : - QGraphicsWidget(parent), - m_checked(false), - m_hovered(false) +KItemListSelectionToggle::KItemListSelectionToggle(QGraphicsItem *parent) + : QGraphicsWidget(parent) + , m_checked(false) + , m_hovered(false) { } @@ -45,7 +45,7 @@ void KItemListSelectionToggle::setHovered(bool hovered) } } -void KItemListSelectionToggle::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +void KItemListSelectionToggle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) Q_UNUSED(widget) @@ -54,12 +54,12 @@ void KItemListSelectionToggle::paint(QPainter* painter, const QStyleOptionGraphi updatePixmap(); } - const qreal x = (size().width() - qreal(m_pixmap.width() / m_pixmap.devicePixelRatioF())) / 2; + const qreal x = (size().width() - qreal(m_pixmap.width() / m_pixmap.devicePixelRatioF())) / 2; const qreal y = (size().height() - qreal(m_pixmap.height() / m_pixmap.devicePixelRatioF())) / 2; painter->drawPixmap(x, y, m_pixmap); } -void KItemListSelectionToggle::resizeEvent(QGraphicsSceneResizeEvent* event) +void KItemListSelectionToggle::resizeEvent(QGraphicsSceneResizeEvent *event) { QGraphicsWidget::resizeEvent(event); @@ -99,4 +99,3 @@ int KItemListSelectionToggle::iconSize() const return iconSize; } - diff --git a/src/kitemviews/private/kitemlistselectiontoggle.h b/src/kitemviews/private/kitemlistselectiontoggle.h index 0a592653e..2f3969c29 100644 --- a/src/kitemviews/private/kitemlistselectiontoggle.h +++ b/src/kitemviews/private/kitemlistselectiontoggle.h @@ -11,7 +11,6 @@ #include <QGraphicsWidget> #include <QPixmap> - /** * @brief Allows to toggle between the selected and unselected state of an item. */ @@ -20,7 +19,7 @@ class DOLPHIN_EXPORT KItemListSelectionToggle : public QGraphicsWidget Q_OBJECT public: - explicit KItemListSelectionToggle(QGraphicsItem* parent); + explicit KItemListSelectionToggle(QGraphicsItem *parent); ~KItemListSelectionToggle() override; void setChecked(bool checked); @@ -28,10 +27,10 @@ public: void setHovered(bool hovered); - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; protected: - void resizeEvent(QGraphicsSceneResizeEvent* event) override; + void resizeEvent(QGraphicsSceneResizeEvent *event) override; private: void updatePixmap(); @@ -44,5 +43,3 @@ private: }; #endif - - diff --git a/src/kitemviews/private/kitemlistsizehintresolver.cpp b/src/kitemviews/private/kitemlistsizehintresolver.cpp index 0c2dd0b80..b7165e8c3 100644 --- a/src/kitemviews/private/kitemlistsizehintresolver.cpp +++ b/src/kitemviews/private/kitemlistsizehintresolver.cpp @@ -7,12 +7,12 @@ #include "kitemlistsizehintresolver.h" #include "kitemviews/kitemlistview.h" -KItemListSizeHintResolver::KItemListSizeHintResolver(const KItemListView* itemListView) : - m_itemListView(itemListView), - m_logicalHeightHintCache(), - m_logicalWidthHint(0.0), - m_minHeightHint(0.0), - m_needsResolving(false) +KItemListSizeHintResolver::KItemListSizeHintResolver(const KItemListView *itemListView) + : m_itemListView(itemListView) + , m_logicalHeightHintCache() + , m_logicalWidthHint(0.0) + , m_minHeightHint(0.0) + , m_needsResolving(false) { } @@ -37,10 +37,10 @@ bool KItemListSizeHintResolver::isElided(int index) return m_logicalHeightHintCache.at(index).second; } -void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges) +void KItemListSizeHintResolver::itemsInserted(const KItemRangeList &itemRanges) { int insertedCount = 0; - for (const KItemRange& range : itemRanges) { + for (const KItemRange &range : itemRanges) { insertedCount += range.count; } @@ -56,7 +56,7 @@ void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges) int itemsToInsertBeforeCurrentRange = insertedCount; for (int rangeIndex = itemRanges.count() - 1; rangeIndex >= 0; --rangeIndex) { - const KItemRange& range = itemRanges.at(rangeIndex); + const KItemRange &range = itemRanges.at(rangeIndex); itemsToInsertBeforeCurrentRange -= range.count; // First: move all existing items that must be put behind 'range'. @@ -78,7 +78,7 @@ void KItemListSizeHintResolver::itemsInserted(const KItemRangeList& itemRanges) Q_ASSERT(m_logicalHeightHintCache.count() == m_itemListView->model()->count()); } -void KItemListSizeHintResolver::itemsRemoved(const KItemRangeList& itemRanges) +void KItemListSizeHintResolver::itemsRemoved(const KItemRangeList &itemRanges) { const QVector<std::pair<qreal, bool>>::iterator begin = m_logicalHeightHintCache.begin(); const QVector<std::pair<qreal, bool>>::iterator end = m_logicalHeightHintCache.end(); @@ -112,7 +112,7 @@ void KItemListSizeHintResolver::itemsRemoved(const KItemRangeList& itemRanges) } } -void KItemListSizeHintResolver::itemsMoved(const KItemRange& range, const QList<int>& movedToIndexes) +void KItemListSizeHintResolver::itemsMoved(const KItemRange &range, const QList<int> &movedToIndexes) { QVector<std::pair<qreal, bool>> newLogicalHeightHintCache(m_logicalHeightHintCache); @@ -125,7 +125,7 @@ void KItemListSizeHintResolver::itemsMoved(const KItemRange& range, const QList< m_logicalHeightHintCache = newLogicalHeightHintCache; } -void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QByteArray>& roles) +void KItemListSizeHintResolver::itemsChanged(int index, int count, const QSet<QByteArray> &roles) { Q_UNUSED(roles) while (count) { diff --git a/src/kitemviews/private/kitemlistsizehintresolver.h b/src/kitemviews/private/kitemlistsizehintresolver.h index a6cc56614..c5a47f130 100644 --- a/src/kitemviews/private/kitemlistsizehintresolver.h +++ b/src/kitemviews/private/kitemlistsizehintresolver.h @@ -21,22 +21,22 @@ class KItemListView; class DOLPHIN_EXPORT KItemListSizeHintResolver { public: - explicit KItemListSizeHintResolver(const KItemListView* itemListView); + explicit KItemListSizeHintResolver(const KItemListView *itemListView); virtual ~KItemListSizeHintResolver(); QSizeF minSizeHint(); QSizeF sizeHint(int index); bool isElided(int index); - void itemsInserted(const KItemRangeList& itemRanges); - void itemsRemoved(const KItemRangeList& itemRanges); - void itemsMoved(const KItemRange& range, const QList<int>& movedToIndexes); - void itemsChanged(int index, int count, const QSet<QByteArray>& roles); + void itemsInserted(const KItemRangeList &itemRanges); + void itemsRemoved(const KItemRangeList &itemRanges); + void itemsMoved(const KItemRange &range, const QList<int> &movedToIndexes); + void itemsChanged(int index, int count, const QSet<QByteArray> &roles); void clearCache(); void updateCache(); private: - const KItemListView* m_itemListView; + const KItemListView *m_itemListView; mutable QVector<std::pair<qreal /* height */, bool /* isElided */>> m_logicalHeightHintCache; mutable qreal m_logicalWidthHint; mutable qreal m_minHeightHint; diff --git a/src/kitemviews/private/kitemlistsmoothscroller.cpp b/src/kitemviews/private/kitemlistsmoothscroller.cpp index 343399179..19d47aac8 100644 --- a/src/kitemviews/private/kitemlistsmoothscroller.cpp +++ b/src/kitemviews/private/kitemlistsmoothscroller.cpp @@ -12,20 +12,18 @@ #include <QStyle> #include <QWheelEvent> -KItemListSmoothScroller::KItemListSmoothScroller(QScrollBar* scrollBar, - QObject* parent) : - QObject(parent), - m_scrollBarPressed(false), - m_smoothScrolling(true), - m_scrollBar(scrollBar), - m_animation(nullptr) +KItemListSmoothScroller::KItemListSmoothScroller(QScrollBar *scrollBar, QObject *parent) + : QObject(parent) + , m_scrollBarPressed(false) + , m_smoothScrolling(true) + , m_scrollBar(scrollBar) + , m_animation(nullptr) { m_animation = new QPropertyAnimation(this); const int animationDuration = m_scrollBar->style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, m_scrollBar); const bool animationEnabled = (animationDuration > 0); m_animation->setDuration(animationEnabled ? animationDuration : 1); - connect(m_animation, &QPropertyAnimation::stateChanged, - this, &KItemListSmoothScroller::slotAnimationStateChanged); + connect(m_animation, &QPropertyAnimation::stateChanged, this, &KItemListSmoothScroller::slotAnimationStateChanged); m_scrollBar->installEventFilter(this); } @@ -39,22 +37,22 @@ void KItemListSmoothScroller::setScrollBar(QScrollBar *scrollBar) m_scrollBar = scrollBar; } -QScrollBar* KItemListSmoothScroller::scrollBar() const +QScrollBar *KItemListSmoothScroller::scrollBar() const { return m_scrollBar; } -void KItemListSmoothScroller::setTargetObject(QObject* target) +void KItemListSmoothScroller::setTargetObject(QObject *target) { m_animation->setTargetObject(target); } -QObject* KItemListSmoothScroller::targetObject() const +QObject *KItemListSmoothScroller::targetObject() const { return m_animation->targetObject(); } -void KItemListSmoothScroller::setPropertyName(const QByteArray& propertyName) +void KItemListSmoothScroller::setPropertyName(const QByteArray &propertyName) { m_animation->setPropertyName(propertyName); } @@ -66,7 +64,7 @@ QByteArray KItemListSmoothScroller::propertyName() const void KItemListSmoothScroller::scrollContentsBy(qreal distance) { - QObject* target = targetObject(); + QObject *target = targetObject(); if (!target) { return; } @@ -143,7 +141,7 @@ bool KItemListSmoothScroller::requestScrollBarUpdate(int newMaximum) return true; } -bool KItemListSmoothScroller::eventFilter(QObject* obj, QEvent* event) +bool KItemListSmoothScroller::eventFilter(QObject *obj, QEvent *event) { Q_ASSERT(obj == m_scrollBar); @@ -168,8 +166,7 @@ bool KItemListSmoothScroller::eventFilter(QObject* obj, QEvent* event) return QObject::eventFilter(obj, event); } -void KItemListSmoothScroller::slotAnimationStateChanged(QAbstractAnimation::State newState, - QAbstractAnimation::State oldState) +void KItemListSmoothScroller::slotAnimationStateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { Q_UNUSED(oldState) if (newState == QAbstractAnimation::Stopped && m_smoothScrolling && !m_scrollBarPressed) { @@ -180,7 +177,7 @@ void KItemListSmoothScroller::slotAnimationStateChanged(QAbstractAnimation::Stat } } -void KItemListSmoothScroller::handleWheelEvent(QWheelEvent* event) +void KItemListSmoothScroller::handleWheelEvent(QWheelEvent *event) { const bool previous = m_smoothScrolling; @@ -198,4 +195,3 @@ void KItemListSmoothScroller::handleWheelEvent(QWheelEvent* event) m_smoothScrolling = previous; } - diff --git a/src/kitemviews/private/kitemlistsmoothscroller.h b/src/kitemviews/private/kitemlistsmoothscroller.h index 7b2839884..d1cfcf9d9 100644 --- a/src/kitemviews/private/kitemlistsmoothscroller.h +++ b/src/kitemviews/private/kitemlistsmoothscroller.h @@ -25,17 +25,16 @@ class DOLPHIN_EXPORT KItemListSmoothScroller : public QObject Q_OBJECT public: - explicit KItemListSmoothScroller(QScrollBar* scrollBar, - QObject* parent = nullptr); + explicit KItemListSmoothScroller(QScrollBar *scrollBar, QObject *parent = nullptr); ~KItemListSmoothScroller() override; - void setScrollBar(QScrollBar* scrollBar); - QScrollBar* scrollBar() const; + void setScrollBar(QScrollBar *scrollBar); + QScrollBar *scrollBar() const; - void setTargetObject(QObject* target); - QObject* targetObject() const; + void setTargetObject(QObject *target); + QObject *targetObject() const; - void setPropertyName(const QByteArray& propertyName); + void setPropertyName(const QByteArray &propertyName); QByteArray propertyName() const; /** @@ -67,27 +66,25 @@ public: /** * Forwards wheel events to the scrollbar, ensuring smooth and proper scrolling */ - void handleWheelEvent(QWheelEvent* event); + void handleWheelEvent(QWheelEvent *event); Q_SIGNALS: /** * Emitted when the scrolling animation has finished */ void scrollingStopped(); + protected: - bool eventFilter(QObject* obj, QEvent* event) override; + bool eventFilter(QObject *obj, QEvent *event) override; private Q_SLOTS: - void slotAnimationStateChanged(QAbstractAnimation::State newState, - QAbstractAnimation::State oldState); + void slotAnimationStateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); private: bool m_scrollBarPressed; bool m_smoothScrolling; - QScrollBar* m_scrollBar; - QPropertyAnimation* m_animation; + QScrollBar *m_scrollBar; + QPropertyAnimation *m_animation; }; #endif - - diff --git a/src/kitemviews/private/kitemlistviewanimation.cpp b/src/kitemviews/private/kitemlistviewanimation.cpp index 0c16c8b0a..83a7a2ec6 100644 --- a/src/kitemviews/private/kitemlistviewanimation.cpp +++ b/src/kitemviews/private/kitemlistviewanimation.cpp @@ -9,11 +9,11 @@ #include <QPropertyAnimation> -KItemListViewAnimation::KItemListViewAnimation(QObject* parent) : - QObject(parent), - m_scrollOrientation(Qt::Vertical), - m_scrollOffset(0), - m_animation() +KItemListViewAnimation::KItemListViewAnimation(QObject *parent) + : QObject(parent) + , m_scrollOrientation(Qt::Vertical) + , m_scrollOffset(0) + , m_animation() { } @@ -48,12 +48,12 @@ void KItemListViewAnimation::setScrollOffset(qreal offset) continue; } - QHashIterator<QGraphicsWidget*, QPropertyAnimation*> it(m_animation[type]); + QHashIterator<QGraphicsWidget *, QPropertyAnimation *> it(m_animation[type]); while (it.hasNext()) { it.next(); - QGraphicsWidget* widget = it.key(); - QPropertyAnimation* propertyAnim = it.value(); + QGraphicsWidget *widget = it.key(); + QPropertyAnimation *propertyAnim = it.value(); QPointF currentPos = widget->pos(); if (m_scrollOrientation == Qt::Vertical) { @@ -65,8 +65,7 @@ void KItemListViewAnimation::setScrollOffset(qreal offset) if (type == MovingAnimation) { // Stop the animation, calculate the moved start- and end-value // and restart the animation for the remaining duration. - const int remainingDuration = propertyAnim->duration() - - propertyAnim->currentTime(); + const int remainingDuration = propertyAnim->duration() - propertyAnim->currentTime(); const bool block = propertyAnim->signalsBlocked(); propertyAnim->blockSignals(true); @@ -96,11 +95,11 @@ qreal KItemListViewAnimation::scrollOffset() const return m_scrollOffset; } -void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue) +void KItemListViewAnimation::start(QGraphicsWidget *widget, AnimationType type, const QVariant &endValue) { stop(widget, type); - QPropertyAnimation* propertyAnim = nullptr; + QPropertyAnimation *propertyAnim = nullptr; const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animate) ? 200 : 1; switch (type) { @@ -165,18 +164,25 @@ void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type, propertyAnim->start(); } -void KItemListViewAnimation::stop(QGraphicsWidget* widget, AnimationType type) +void KItemListViewAnimation::stop(QGraphicsWidget *widget, AnimationType type) { - QPropertyAnimation* propertyAnim = m_animation[type].value(widget); + QPropertyAnimation *propertyAnim = m_animation[type].value(widget); if (propertyAnim) { propertyAnim->stop(); switch (type) { - case MovingAnimation: break; - case CreateAnimation: widget->setOpacity(1.0); break; - case DeleteAnimation: widget->setOpacity(0.0); break; - case ResizeAnimation: break; - default: break; + case MovingAnimation: + break; + case CreateAnimation: + widget->setOpacity(1.0); + break; + case DeleteAnimation: + widget->setOpacity(0.0); + break; + case ResizeAnimation: + break; + default: + break; } m_animation[type].remove(widget); @@ -186,7 +192,7 @@ void KItemListViewAnimation::stop(QGraphicsWidget* widget, AnimationType type) } } -void KItemListViewAnimation::stop(QGraphicsWidget* widget) +void KItemListViewAnimation::stop(QGraphicsWidget *widget) { for (int type = 0; type < AnimationTypeCount; ++type) { stop(widget, static_cast<AnimationType>(type)); @@ -198,7 +204,7 @@ bool KItemListViewAnimation::isStarted(QGraphicsWidget *widget, AnimationType ty return m_animation[type].value(widget); } -bool KItemListViewAnimation::isStarted(QGraphicsWidget* widget) const +bool KItemListViewAnimation::isStarted(QGraphicsWidget *widget) const { for (int type = 0; type < AnimationTypeCount; ++type) { if (isStarted(widget, static_cast<AnimationType>(type))) { @@ -210,14 +216,14 @@ bool KItemListViewAnimation::isStarted(QGraphicsWidget* widget) const void KItemListViewAnimation::slotFinished() { - QPropertyAnimation* finishedAnim = qobject_cast<QPropertyAnimation*>(sender()); + QPropertyAnimation *finishedAnim = qobject_cast<QPropertyAnimation *>(sender()); for (int type = 0; type < AnimationTypeCount; ++type) { - QMutableHashIterator<QGraphicsWidget*, QPropertyAnimation*> it(m_animation[type]); + QMutableHashIterator<QGraphicsWidget *, QPropertyAnimation *> it(m_animation[type]); while (it.hasNext()) { it.next(); - QPropertyAnimation* propertyAnim = it.value(); + QPropertyAnimation *propertyAnim = it.value(); if (propertyAnim == finishedAnim) { - QGraphicsWidget* widget = it.key(); + QGraphicsWidget *widget = it.key(); it.remove(); finishedAnim->deleteLater(); @@ -228,4 +234,3 @@ void KItemListViewAnimation::slotFinished() } Q_ASSERT(false); } - diff --git a/src/kitemviews/private/kitemlistviewanimation.h b/src/kitemviews/private/kitemlistviewanimation.h index 5e0ebf982..c052d5dff 100644 --- a/src/kitemviews/private/kitemlistviewanimation.h +++ b/src/kitemviews/private/kitemlistviewanimation.h @@ -28,16 +28,9 @@ class DOLPHIN_EXPORT KItemListViewAnimation : public QObject Q_OBJECT public: - enum AnimationType { - MovingAnimation, - CreateAnimation, - DeleteAnimation, - ResizeAnimation, - IconResizeAnimation, - AnimationTypeCount - }; + enum AnimationType { MovingAnimation, CreateAnimation, DeleteAnimation, ResizeAnimation, IconResizeAnimation, AnimationTypeCount }; - explicit KItemListViewAnimation(QObject* parent = nullptr); + explicit KItemListViewAnimation(QObject *parent = nullptr); ~KItemListViewAnimation() override; void setScrollOrientation(Qt::Orientation orientation); @@ -51,17 +44,17 @@ public: * of the type is already running, this animation will be stopped before starting * the new animation. */ - void start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue = QVariant()); + void start(QGraphicsWidget *widget, AnimationType type, const QVariant &endValue = QVariant()); /** * Stops the animation of the type \a type for the widget \a widget. */ - void stop(QGraphicsWidget* widget, AnimationType type); + void stop(QGraphicsWidget *widget, AnimationType type); /** * Stops all animations that have been applied to the widget \a widget. */ - void stop(QGraphicsWidget* widget); + void stop(QGraphicsWidget *widget); /** * @return True if the animation of the type \a type has been started @@ -72,10 +65,10 @@ public: /** * @return True if any animation has been started for the widget. */ - bool isStarted(QGraphicsWidget* widget) const; + bool isStarted(QGraphicsWidget *widget) const; Q_SIGNALS: - void finished(QGraphicsWidget* widget, KItemListViewAnimation::AnimationType type); + void finished(QGraphicsWidget *widget, KItemListViewAnimation::AnimationType type); private Q_SLOTS: void slotFinished(); @@ -83,9 +76,7 @@ private Q_SLOTS: private: Qt::Orientation m_scrollOrientation; qreal m_scrollOffset; - QHash<QGraphicsWidget*, QPropertyAnimation*> m_animation[AnimationTypeCount]; + QHash<QGraphicsWidget *, QPropertyAnimation *> m_animation[AnimationTypeCount]; }; #endif - - diff --git a/src/kitemviews/private/kitemlistviewlayouter.cpp b/src/kitemviews/private/kitemlistviewlayouter.cpp index 4c22b4dbc..027943683 100644 --- a/src/kitemviews/private/kitemlistviewlayouter.cpp +++ b/src/kitemviews/private/kitemlistviewlayouter.cpp @@ -14,32 +14,32 @@ // #define KITEMLISTVIEWLAYOUTER_DEBUG -KItemListViewLayouter::KItemListViewLayouter(KItemListSizeHintResolver* sizeHintResolver, QObject* parent) : - QObject(parent), - m_dirty(true), - m_visibleIndexesDirty(true), - m_scrollOrientation(Qt::Vertical), - m_size(), - m_itemSize(128, 128), - m_itemMargin(), - m_headerHeight(0), - m_model(nullptr), - m_sizeHintResolver(sizeHintResolver), - m_scrollOffset(0), - m_maximumScrollOffset(0), - m_itemOffset(0), - m_maximumItemOffset(0), - m_firstVisibleIndex(-1), - m_lastVisibleIndex(-1), - m_columnWidth(0), - m_xPosInc(0), - m_columnCount(0), - m_rowOffsets(), - m_columnOffsets(), - m_groupItemIndexes(), - m_groupHeaderHeight(0), - m_groupHeaderMargin(0), - m_itemInfos() +KItemListViewLayouter::KItemListViewLayouter(KItemListSizeHintResolver *sizeHintResolver, QObject *parent) + : QObject(parent) + , m_dirty(true) + , m_visibleIndexesDirty(true) + , m_scrollOrientation(Qt::Vertical) + , m_size() + , m_itemSize(128, 128) + , m_itemMargin() + , m_headerHeight(0) + , m_model(nullptr) + , m_sizeHintResolver(sizeHintResolver) + , m_scrollOffset(0) + , m_maximumScrollOffset(0) + , m_itemOffset(0) + , m_maximumItemOffset(0) + , m_firstVisibleIndex(-1) + , m_lastVisibleIndex(-1) + , m_columnWidth(0) + , m_xPosInc(0) + , m_columnCount(0) + , m_rowOffsets() + , m_columnOffsets() + , m_groupItemIndexes() + , m_groupHeaderHeight(0) + , m_groupHeaderMargin(0) + , m_itemInfos() { Q_ASSERT(m_sizeHintResolver); } @@ -61,7 +61,7 @@ Qt::Orientation KItemListViewLayouter::scrollOrientation() const return m_scrollOrientation; } -void KItemListViewLayouter::setSize(const QSizeF& size) +void KItemListViewLayouter::setSize(const QSizeF &size) { if (m_size != size) { if (m_scrollOrientation == Qt::Vertical) { @@ -82,7 +82,7 @@ QSizeF KItemListViewLayouter::size() const return m_size; } -void KItemListViewLayouter::setItemSize(const QSizeF& size) +void KItemListViewLayouter::setItemSize(const QSizeF &size) { if (m_itemSize != size) { m_itemSize = size; @@ -95,7 +95,7 @@ QSizeF KItemListViewLayouter::itemSize() const return m_itemSize; } -void KItemListViewLayouter::setItemMargin(const QSizeF& margin) +void KItemListViewLayouter::setItemMargin(const QSizeF &margin) { if (m_itemMargin != margin) { m_itemMargin = margin; @@ -162,7 +162,7 @@ qreal KItemListViewLayouter::scrollOffset() const qreal KItemListViewLayouter::maximumScrollOffset() const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); return m_maximumScrollOffset; } @@ -181,11 +181,11 @@ qreal KItemListViewLayouter::itemOffset() const qreal KItemListViewLayouter::maximumItemOffset() const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); return m_maximumItemOffset; } -void KItemListViewLayouter::setModel(const KItemModelBase* model) +void KItemListViewLayouter::setModel(const KItemModelBase *model) { if (m_model != model) { m_model = model; @@ -193,26 +193,26 @@ void KItemListViewLayouter::setModel(const KItemModelBase* model) } } -const KItemModelBase* KItemListViewLayouter::model() const +const KItemModelBase *KItemListViewLayouter::model() const { return m_model; } int KItemListViewLayouter::firstVisibleIndex() const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); return m_firstVisibleIndex; } int KItemListViewLayouter::lastVisibleIndex() const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); return m_lastVisibleIndex; } QRectF KItemListViewLayouter::itemRect(int index) const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); if (index < 0 || index >= m_itemInfos.count()) { return QRectF(); } @@ -242,7 +242,7 @@ QRectF KItemListViewLayouter::itemRect(int index) const QRectF KItemListViewLayouter::groupHeaderRect(int index) const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); const QRectF firstItemRect = itemRect(index); QPointF pos = firstItemRect.topLeft(); @@ -271,9 +271,8 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const break; } - const qreal itemWidth = (m_scrollOrientation == Qt::Vertical) - ? m_sizeHintResolver->sizeHint(index).width() - : m_sizeHintResolver->sizeHint(index).height(); + const qreal itemWidth = + (m_scrollOrientation == Qt::Vertical) ? m_sizeHintResolver->sizeHint(index).width() : m_sizeHintResolver->sizeHint(index).height(); if (itemWidth > headerWidth) { headerWidth = itemWidth; @@ -289,31 +288,27 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const int KItemListViewLayouter::itemColumn(int index) const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); if (index < 0 || index >= m_itemInfos.count()) { return -1; } - return (m_scrollOrientation == Qt::Vertical) - ? m_itemInfos[index].column - : m_itemInfos[index].row; + return (m_scrollOrientation == Qt::Vertical) ? m_itemInfos[index].column : m_itemInfos[index].row; } int KItemListViewLayouter::itemRow(int index) const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); if (index < 0 || index >= m_itemInfos.count()) { return -1; } - return (m_scrollOrientation == Qt::Vertical) - ? m_itemInfos[index].row - : m_itemInfos[index].column; + return (m_scrollOrientation == Qt::Vertical) ? m_itemInfos[index].row : m_itemInfos[index].column; } int KItemListViewLayouter::maximumVisibleItems() const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); const int height = static_cast<int>(m_size.height()); const int rowHeight = static_cast<int>(m_itemSize.height()); @@ -327,7 +322,7 @@ int KItemListViewLayouter::maximumVisibleItems() const bool KItemListViewLayouter::isFirstGroupItem(int itemIndex) const { - const_cast<KItemListViewLayouter*>(this)->doLayout(); + const_cast<KItemListViewLayouter *>(this)->doLayout(); return m_groupItemIndexes.contains(itemIndex); } @@ -336,18 +331,19 @@ void KItemListViewLayouter::markAsDirty() m_dirty = true; } - #ifndef QT_NO_DEBUG - bool KItemListViewLayouter::isDirty() - { - return m_dirty; - } +bool KItemListViewLayouter::isDirty() +{ + return m_dirty; +} #endif void KItemListViewLayouter::doLayout() { // we always want to update visible indexes after performing a layout - auto qsg = qScopeGuard([this] { updateVisibleIndexes(); }); + auto qsg = qScopeGuard([this] { + updateVisibleIndexes(); + }); if (!m_dirty) { return; @@ -409,14 +405,16 @@ void KItemListViewLayouter::doLayout() currentOffset += m_groupHeaderHeight; } - if (QGuiApplication::isLeftToRight()) for (int column = 0; column < m_columnCount; ++column) { - m_columnOffsets[column] = currentOffset; - currentOffset += m_columnWidth; - } - else for (int column = 0; column < m_columnCount; ++column) { - m_columnOffsets[column] = currentOffset - m_columnWidth; - currentOffset -= m_columnWidth; - } + if (QGuiApplication::isLeftToRight()) + for (int column = 0; column < m_columnCount; ++column) { + m_columnOffsets[column] = currentOffset; + currentOffset += m_columnWidth; + } + else + for (int column = 0; column < m_columnCount; ++column) { + m_columnOffsets[column] = currentOffset - m_columnWidth; + currentOffset -= m_columnWidth; + } // Prepare the QVector which stores the y-coordinate for each new row. int numberOfRows = (itemCount + m_columnCount - 1) / m_columnCount; @@ -467,7 +465,7 @@ void KItemListViewLayouter::doLayout() requiredItemHeight = sizeHintHeight; } - ItemInfo& itemInfo = m_itemInfos[index]; + ItemInfo &itemInfo = m_itemInfos[index]; itemInfo.column = column; itemInfo.row = row; @@ -598,7 +596,7 @@ bool KItemListViewLayouter::createGroupHeaders() m_groupItemIndexes.clear(); - const QList<QPair<int, QVariant> > groups = m_model->groups(); + const QList<QPair<int, QVariant>> groups = m_model->groups(); if (groups.isEmpty()) { return false; } @@ -615,4 +613,3 @@ qreal KItemListViewLayouter::minimumGroupHeaderWidth() const { return 100; } - diff --git a/src/kitemviews/private/kitemlistviewlayouter.h b/src/kitemviews/private/kitemlistviewlayouter.h index d5dc6dae1..77d59c947 100644 --- a/src/kitemviews/private/kitemlistviewlayouter.h +++ b/src/kitemviews/private/kitemlistviewlayouter.h @@ -37,22 +37,22 @@ class DOLPHIN_EXPORT KItemListViewLayouter : public QObject Q_OBJECT public: - explicit KItemListViewLayouter(KItemListSizeHintResolver* sizeHintResolver, QObject* parent = nullptr); + explicit KItemListViewLayouter(KItemListSizeHintResolver *sizeHintResolver, QObject *parent = nullptr); ~KItemListViewLayouter() override; void setScrollOrientation(Qt::Orientation orientation); Qt::Orientation scrollOrientation() const; - void setSize(const QSizeF& size); + void setSize(const QSizeF &size); QSizeF size() const; - void setItemSize(const QSizeF& size); + void setItemSize(const QSizeF &size); QSizeF itemSize() const; /** * Margin between the rows and columns of items. */ - void setItemMargin(const QSizeF& margin); + void setItemMargin(const QSizeF &margin); QSizeF itemMargin() const; /** @@ -87,8 +87,8 @@ public: qreal maximumItemOffset() const; - void setModel(const KItemModelBase* model); - const KItemModelBase* model() const; + void setModel(const KItemModelBase *model); + const KItemModelBase *model() const; /** * @return The first (at least partly) visible index. -1 is returned @@ -188,8 +188,8 @@ private: QSizeF m_itemSize; QSizeF m_itemMargin; qreal m_headerHeight; - const KItemModelBase* m_model; - KItemListSizeHintResolver* m_sizeHintResolver; + const KItemModelBase *m_model; + KItemListSizeHintResolver *m_sizeHintResolver; qreal m_scrollOffset; qreal m_maximumScrollOffset; @@ -223,5 +223,3 @@ private: }; #endif - - diff --git a/src/kitemviews/private/kpixmapmodifier.cpp b/src/kitemviews/private/kpixmapmodifier.cpp index 9f7f2edc8..bf316b880 100644 --- a/src/kitemviews/private/kpixmapmodifier.cpp +++ b/src/kitemviews/private/kpixmapmodifier.cpp @@ -19,52 +19,32 @@ #include <QImage> #include <QPainter> -static const quint32 stackBlur8Mul[255] = -{ - 512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512, - 454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512, - 482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456, - 437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512, - 497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328, - 320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456, - 446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335, - 329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512, - 505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405, - 399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328, - 324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271, - 268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456, - 451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388, - 385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335, - 332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292, - 289,287,285,282,280,278,275,273,271,269,267,265,263,261,259 -}; +static const quint32 stackBlur8Mul[255] = { + 512, 512, 456, 512, 328, 456, 335, 512, 405, 328, 271, 456, 388, 335, 292, 512, 454, 405, 364, 328, 298, 271, 496, 456, 420, 388, 360, 335, 312, + 292, 273, 512, 482, 454, 428, 405, 383, 364, 345, 328, 312, 298, 284, 271, 259, 496, 475, 456, 437, 420, 404, 388, 374, 360, 347, 335, 323, 312, + 302, 292, 282, 273, 265, 512, 497, 482, 468, 454, 441, 428, 417, 405, 394, 383, 373, 364, 354, 345, 337, 328, 320, 312, 305, 298, 291, 284, 278, + 271, 265, 259, 507, 496, 485, 475, 465, 456, 446, 437, 428, 420, 412, 404, 396, 388, 381, 374, 367, 360, 354, 347, 341, 335, 329, 323, 318, 312, + 307, 302, 297, 292, 287, 282, 278, 273, 269, 265, 261, 512, 505, 497, 489, 482, 475, 468, 461, 454, 447, 441, 435, 428, 422, 417, 411, 405, 399, + 394, 389, 383, 378, 373, 368, 364, 359, 354, 350, 345, 341, 337, 332, 328, 324, 320, 316, 312, 309, 305, 301, 298, 294, 291, 287, 284, 281, 278, + 274, 271, 268, 265, 262, 259, 257, 507, 501, 496, 491, 485, 480, 475, 470, 465, 460, 456, 451, 446, 442, 437, 433, 428, 424, 420, 416, 412, 408, + 404, 400, 396, 392, 388, 385, 381, 377, 374, 370, 367, 363, 360, 357, 354, 350, 347, 344, 341, 338, 335, 332, 329, 326, 323, 320, 318, 315, 312, + 310, 307, 304, 302, 299, 297, 294, 292, 289, 287, 285, 282, 280, 278, 275, 273, 271, 269, 267, 265, 263, 261, 259}; -static const quint32 stackBlur8Shr[255] = -{ - 9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, - 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, - 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 -}; +static const quint32 stackBlur8Shr[255] = { + 9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, + 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24}; -static void blurHorizontal(QImage& image, unsigned int* stack, int div, int radius) +static void blurHorizontal(QImage &image, unsigned int *stack, int div, int radius) { int stackindex; int stackstart; - quint32 * const pixels = reinterpret_cast<quint32 *>(image.bits()); + quint32 *const pixels = reinterpret_cast<quint32 *>(image.bits()); quint32 pixel; int w = image.width(); @@ -77,8 +57,8 @@ static void blurHorizontal(QImage& image, unsigned int* stack, int div, int radi unsigned int sum, sumIn, sumOut; for (int y = 0; y < h; y++) { - sum = 0; - sumIn = 0; + sum = 0; + sumIn = 0; sumOut = 0; const int yw = y * w; @@ -93,10 +73,10 @@ static void blurHorizontal(QImage& image, unsigned int* stack, int div, int radi for (int i = 1; i <= radius; i++) { pixel = pixels[yw + qMin(i, wm)]; - unsigned int* stackpix = &stack[i + radius]; + unsigned int *stackpix = &stack[i + radius]; *stackpix = qAlpha(pixel); - sum += *stackpix * (radius + 1 - i); + sum += *stackpix * (radius + 1 - i); sumIn += *stackpix; } @@ -111,7 +91,7 @@ static void blurHorizontal(QImage& image, unsigned int* stack, int div, int radi stackstart -= div; } - unsigned int* stackpix = &stack[stackstart]; + unsigned int *stackpix = &stack[stackstart]; sumOut -= *stackpix; @@ -120,7 +100,7 @@ static void blurHorizontal(QImage& image, unsigned int* stack, int div, int radi *stackpix = qAlpha(pixel); sumIn += *stackpix; - sum += sumIn; + sum += sumIn; if (++stackindex >= div) { stackindex = 0; @@ -129,17 +109,17 @@ static void blurHorizontal(QImage& image, unsigned int* stack, int div, int radi stackpix = &stack[stackindex]; sumOut += *stackpix; - sumIn -= *stackpix; + sumIn -= *stackpix; } } } -static void blurVertical(QImage& image, unsigned int* stack, int div, int radius) +static void blurVertical(QImage &image, unsigned int *stack, int div, int radius) { int stackindex; int stackstart; - quint32 * const pixels = reinterpret_cast<quint32 *>(image.bits()); + quint32 *const pixels = reinterpret_cast<quint32 *>(image.bits()); quint32 pixel; int w = image.width(); @@ -152,8 +132,8 @@ static void blurVertical(QImage& image, unsigned int* stack, int div, int radius unsigned int sum, sumIn, sumOut; for (int x = 0; x < w; x++) { - sum = 0; - sumIn = 0; + sum = 0; + sumIn = 0; sumOut = 0; pixel = pixels[x]; @@ -167,10 +147,10 @@ static void blurVertical(QImage& image, unsigned int* stack, int div, int radius for (int i = 1; i <= radius; i++) { pixel = pixels[qMin(i, hm) * w + x]; - unsigned int* stackpix = &stack[i + radius]; + unsigned int *stackpix = &stack[i + radius]; *stackpix = qAlpha(pixel); - sum += *stackpix * (radius + 1 - i); + sum += *stackpix * (radius + 1 - i); sumIn += *stackpix; } @@ -184,7 +164,7 @@ static void blurVertical(QImage& image, unsigned int* stack, int div, int radius if (stackstart >= div) stackstart -= div; - unsigned int* stackpix = &stack[stackstart]; + unsigned int *stackpix = &stack[stackstart]; sumOut -= *stackpix; @@ -193,7 +173,7 @@ static void blurVertical(QImage& image, unsigned int* stack, int div, int radius *stackpix = qAlpha(pixel); sumIn += *stackpix; - sum += sumIn; + sum += sumIn; if (++stackindex >= div) { stackindex = 0; @@ -202,25 +182,25 @@ static void blurVertical(QImage& image, unsigned int* stack, int div, int radius stackpix = &stack[stackindex]; sumOut += *stackpix; - sumIn -= *stackpix; + sumIn -= *stackpix; } } } -static void stackBlur(QImage& image, float radius) +static void stackBlur(QImage &image, float radius) { radius = qRound(radius); int div = int(radius * 2) + 1; - unsigned int* stack = new unsigned int[div]; + unsigned int *stack = new unsigned int[div]; blurHorizontal(image, stack, div, radius); blurVertical(image, stack, div, radius); - delete [] stack; + delete[] stack; } -static void shadowBlur(QImage& image, float radius, const QColor& color) +static void shadowBlur(QImage &image, float radius, const QColor &color) { if (radius < 0) { return; @@ -236,67 +216,65 @@ static void shadowBlur(QImage& image, float radius, const QColor& color) p.fillRect(image.rect(), color); } -namespace { - /** Helper class for drawing frames for KPixmapModifier::applyFrame(). */ - class TileSet - { - public: - enum { LeftMargin = 3, TopMargin = 2, RightMargin = 3, BottomMargin = 4 }; - - enum Tile { TopLeftCorner = 0, TopSide, TopRightCorner, LeftSide, - RightSide, BottomLeftCorner, BottomSide, BottomRightCorner, - NumTiles }; +namespace +{ +/** Helper class for drawing frames for KPixmapModifier::applyFrame(). */ +class TileSet +{ +public: + enum { LeftMargin = 3, TopMargin = 2, RightMargin = 3, BottomMargin = 4 }; - TileSet() - { - QImage image(8 * 3, 8 * 3, QImage::Format_ARGB32_Premultiplied); + enum Tile { TopLeftCorner = 0, TopSide, TopRightCorner, LeftSide, RightSide, BottomLeftCorner, BottomSide, BottomRightCorner, NumTiles }; - QPainter p(&image); - p.setCompositionMode(QPainter::CompositionMode_Source); - p.fillRect(image.rect(), Qt::transparent); - p.fillRect(image.rect().adjusted(3, 3, -3, -3), Qt::black); - p.end(); + TileSet() + { + QImage image(8 * 3, 8 * 3, QImage::Format_ARGB32_Premultiplied); - shadowBlur(image, 3, Qt::black); + QPainter p(&image); + p.setCompositionMode(QPainter::CompositionMode_Source); + p.fillRect(image.rect(), Qt::transparent); + p.fillRect(image.rect().adjusted(3, 3, -3, -3), Qt::black); + p.end(); - QPixmap pixmap = QPixmap::fromImage(image); - m_tiles[TopLeftCorner] = pixmap.copy(0, 0, 8, 8); - m_tiles[TopSide] = pixmap.copy(8, 0, 8, 8); - m_tiles[TopRightCorner] = pixmap.copy(16, 0, 8, 8); - m_tiles[LeftSide] = pixmap.copy(0, 8, 8, 8); - m_tiles[RightSide] = pixmap.copy(16, 8, 8, 8); - m_tiles[BottomLeftCorner] = pixmap.copy(0, 16, 8, 8); - m_tiles[BottomSide] = pixmap.copy(8, 16, 8, 8); - m_tiles[BottomRightCorner] = pixmap.copy(16, 16, 8, 8); - } + shadowBlur(image, 3, Qt::black); - void paint(QPainter* p, const QRect& r) - { - p->drawPixmap(r.topLeft(), m_tiles[TopLeftCorner]); - if (r.width() - 16 > 0) { - p->drawTiledPixmap(r.x() + 8, r.y(), r.width() - 16, 8, m_tiles[TopSide]); - } - p->drawPixmap(r.right() - 8 + 1, r.y(), m_tiles[TopRightCorner]); - if (r.height() - 16 > 0) { - p->drawTiledPixmap(r.x(), r.y() + 8, 8, r.height() - 16, m_tiles[LeftSide]); - p->drawTiledPixmap(r.right() - 8 + 1, r.y() + 8, 8, r.height() - 16, m_tiles[RightSide]); - } - p->drawPixmap(r.x(), r.bottom() - 8 + 1, m_tiles[BottomLeftCorner]); - if (r.width() - 16 > 0) { - p->drawTiledPixmap(r.x() + 8, r.bottom() - 8 + 1, r.width() - 16, 8, m_tiles[BottomSide]); - } - p->drawPixmap(r.right() - 8 + 1, r.bottom() - 8 + 1, m_tiles[BottomRightCorner]); + QPixmap pixmap = QPixmap::fromImage(image); + m_tiles[TopLeftCorner] = pixmap.copy(0, 0, 8, 8); + m_tiles[TopSide] = pixmap.copy(8, 0, 8, 8); + m_tiles[TopRightCorner] = pixmap.copy(16, 0, 8, 8); + m_tiles[LeftSide] = pixmap.copy(0, 8, 8, 8); + m_tiles[RightSide] = pixmap.copy(16, 8, 8, 8); + m_tiles[BottomLeftCorner] = pixmap.copy(0, 16, 8, 8); + m_tiles[BottomSide] = pixmap.copy(8, 16, 8, 8); + m_tiles[BottomRightCorner] = pixmap.copy(16, 16, 8, 8); + } - const QRect contentRect = r.adjusted(LeftMargin + 1, TopMargin + 1, - -(RightMargin + 1), -(BottomMargin + 1)); - p->fillRect(contentRect, Qt::transparent); + void paint(QPainter *p, const QRect &r) + { + p->drawPixmap(r.topLeft(), m_tiles[TopLeftCorner]); + if (r.width() - 16 > 0) { + p->drawTiledPixmap(r.x() + 8, r.y(), r.width() - 16, 8, m_tiles[TopSide]); + } + p->drawPixmap(r.right() - 8 + 1, r.y(), m_tiles[TopRightCorner]); + if (r.height() - 16 > 0) { + p->drawTiledPixmap(r.x(), r.y() + 8, 8, r.height() - 16, m_tiles[LeftSide]); + p->drawTiledPixmap(r.right() - 8 + 1, r.y() + 8, 8, r.height() - 16, m_tiles[RightSide]); } + p->drawPixmap(r.x(), r.bottom() - 8 + 1, m_tiles[BottomLeftCorner]); + if (r.width() - 16 > 0) { + p->drawTiledPixmap(r.x() + 8, r.bottom() - 8 + 1, r.width() - 16, 8, m_tiles[BottomSide]); + } + p->drawPixmap(r.right() - 8 + 1, r.bottom() - 8 + 1, m_tiles[BottomRightCorner]); + + const QRect contentRect = r.adjusted(LeftMargin + 1, TopMargin + 1, -(RightMargin + 1), -(BottomMargin + 1)); + p->fillRect(contentRect, Qt::transparent); + } - QPixmap m_tiles[NumTiles]; - }; + QPixmap m_tiles[NumTiles]; +}; } -void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize) +void KPixmapModifier::scale(QPixmap &pixmap, const QSize &scaledSize) { if (scaledSize.isEmpty() || pixmap.isNull()) { pixmap = QPixmap(); @@ -307,7 +285,7 @@ void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize) pixmap.setDevicePixelRatio(dpr); } -void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize) +void KPixmapModifier::applyFrame(QPixmap &icon, const QSize &scaledSize) { if (icon.isNull()) { icon = QPixmap(scaledSize); @@ -319,8 +297,7 @@ void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize) qreal dpr = qApp->devicePixelRatio(); // Resize the icon to the maximum size minus the space required for the frame - const QSize size(scaledSize.width() - TileSet::LeftMargin - TileSet::RightMargin, - scaledSize.height() - TileSet::TopMargin - TileSet::BottomMargin); + const QSize size(scaledSize.width() - TileSet::LeftMargin - TileSet::RightMargin, scaledSize.height() - TileSet::TopMargin - TileSet::BottomMargin); scale(icon, size * dpr); icon.setDevicePixelRatio(dpr); @@ -332,16 +309,14 @@ void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize) QPainter painter; painter.begin(&framedIcon); painter.setCompositionMode(QPainter::CompositionMode_Source); - tileSet.paint(&painter, QRect(QPoint(0,0), framedIcon.size() / dpr)); + tileSet.paint(&painter, QRect(QPoint(0, 0), framedIcon.size() / dpr)); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawPixmap(TileSet::LeftMargin, TileSet::TopMargin, icon); icon = framedIcon; } -QSize KPixmapModifier::sizeInsideFrame(const QSize& frameSize) +QSize KPixmapModifier::sizeInsideFrame(const QSize &frameSize) { - return QSize(frameSize.width() - TileSet::LeftMargin - TileSet::RightMargin, - frameSize.height() - TileSet::TopMargin - TileSet::BottomMargin); + return QSize(frameSize.width() - TileSet::LeftMargin - TileSet::RightMargin, frameSize.height() - TileSet::TopMargin - TileSet::BottomMargin); } - diff --git a/src/kitemviews/private/kpixmapmodifier.h b/src/kitemviews/private/kpixmapmodifier.h index d8d7f2394..0d86b0157 100644 --- a/src/kitemviews/private/kpixmapmodifier.h +++ b/src/kitemviews/private/kpixmapmodifier.h @@ -20,14 +20,14 @@ public: * @arg scaledSize is assumed to be the scaled to the same device pixel ratio as the source pixmap * @arg scaledSize is in device pixels */ - static void scale(QPixmap& pixmap, const QSize& scaledSize); + static void scale(QPixmap &pixmap, const QSize &scaledSize); /** * Resize and paint a frame round an icon * @arg scaledSize is in device-independent pixels * The returned image will be scaled by the application devicePixelRatio */ - static void applyFrame(QPixmap& icon, const QSize& scaledSize); + static void applyFrame(QPixmap &icon, const QSize &scaledSize); /** * return and paint a frame round an icon @@ -35,9 +35,7 @@ public: * @return is in device-independent pixels */ - static QSize sizeInsideFrame(const QSize& frameSize); + static QSize sizeInsideFrame(const QSize &frameSize); }; #endif - - |
