diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h --- a/src/dolphincontextmenu.h +++ b/src/dolphincontextmenu.h @@ -51,7 +51,7 @@ Q_OBJECT public: - enum Command + enum class Command { None, OpenParentFolder, @@ -145,11 +145,11 @@ QString comment; }; - enum ContextType + enum class ContextType { NoContext = 0, - ItemContext = 1, - TrashContext = 2 + Item = 1, + Trash = 2 }; QPoint m_pos; diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -69,10 +69,10 @@ m_baseFileItem(nullptr), m_selectedItems(), m_selectedItemsProperties(nullptr), - m_context(NoContext), + m_context(static_cast(ContextType::NoContext)), m_copyToMenu(parent), m_customActions(), - m_command(None), + m_command(Command::None), m_removeAction(nullptr) { // The context menu either accesses the URLs of the selected items @@ -96,25 +96,25 @@ { // get the context information if (m_baseUrl.scheme() == QLatin1String("trash")) { - m_context |= TrashContext; + m_context |= static_cast(ContextType::Trash); } if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) { - m_context |= ItemContext; + m_context |= static_cast(ContextType::Item); // TODO: handle other use cases like devices + desktop files } // open the corresponding popup for the context - if (m_context & TrashContext) { - if (m_context & ItemContext) { + if (m_context & static_cast(ContextType::Trash)) { + if (m_context & static_cast(ContextType::Item)) { openTrashItemContextMenu(); } else { openTrashContextMenu(); } - } else if (m_context & ItemContext) { + } else if (m_context & static_cast(ContextType::Item)) { openItemContextMenu(); } else { - Q_ASSERT(m_context == NoContext); + Q_ASSERT(ContextType(m_context) == ContextType::NoContext); openViewportContextMenu(); } @@ -139,7 +139,7 @@ void DolphinContextMenu::openTrashContextMenu() { - Q_ASSERT(m_context & TrashContext); + Q_ASSERT(m_context & static_cast(ContextType::Trash)); QAction* emptyTrashAction = new QAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"), this); KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); @@ -166,8 +166,8 @@ void DolphinContextMenu::openTrashItemContextMenu() { - Q_ASSERT(m_context & TrashContext); - Q_ASSERT(m_context & ItemContext); + Q_ASSERT(m_context & static_cast(ContextType::Trash)); + Q_ASSERT(m_context & static_cast(ContextType::Item)); QAction* restoreAction = new QAction(i18nc("@action:inmenu", "Restore"), m_mainWindow); addAction(restoreAction); @@ -309,11 +309,11 @@ model.createPlacesItem(text, selectedUrl, KIO::iconNameForUrl(selectedUrl)); } } else if (activatedAction == openParentAction) { - m_command = OpenParentFolder; + m_command = Command::OpenParentFolder; } else if (activatedAction == openParentInNewWindowAction) { - m_command = OpenParentFolderInNewWindow; + m_command = Command::OpenParentFolderInNewWindow; } else if (activatedAction == openParentInNewTabAction) { - m_command = OpenParentFolderInNewTab; + m_command = Command::OpenParentFolderInNewTab; } } } diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -798,19 +798,19 @@ const DolphinContextMenu::Command command = contextMenu.data()->open(); switch (command) { - case DolphinContextMenu::OpenParentFolder: + case DolphinContextMenu::Command::OpenParentFolder: changeUrl(KIO::upUrl(item.url())); break; - case DolphinContextMenu::OpenParentFolderInNewWindow: + case DolphinContextMenu::Command::OpenParentFolderInNewWindow: Dolphin::openNewWindow({KIO::upUrl(item.url())}, this); break; - case DolphinContextMenu::OpenParentFolderInNewTab: + case DolphinContextMenu::Command::OpenParentFolderInNewTab: openNewTab(KIO::upUrl(item.url())); break; - case DolphinContextMenu::None: + case DolphinContextMenu::Command::None: default: break; } diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp --- a/src/kitemviews/kfileitemlistview.cpp +++ b/src/kitemviews/kfileitemlistview.cpp @@ -414,7 +414,7 @@ { const KItemListStyleOption& option = styleOption(); const int iconSize = option.iconSize; - if (itemLayout() == IconsLayout) { + if (itemLayout() == ItemLayout::Icons) { const int maxIconWidth = itemSize().width() - 2 * option.padding; return QSize(maxIconWidth, iconSize); } diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -280,16 +280,15 @@ void dispatchPendingItemsToInsert(); private: - enum RoleType { + enum class RoleType { // User visible roles: - NoRole, NameRole, SizeRole, ModificationTimeRole, CreationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole, - GroupRole, TypeRole, DestinationRole, PathRole, DeletionTimeRole, + NoRole, Name, Size, ModificationTime, CreationTime, AccessTime, Permissions, Owner, + Group, Type, Destination, Path, DeletionTime, // User visible roles available with Baloo: - CommentRole, TagsRole, RatingRole, ImageSizeRole, ImageDateTimeRole, OrientationRole, - WordCountRole, TitleRole, LineCountRole, ArtistRole, GenreRole, AlbumRole, DurationRole, TrackRole, ReleaseYearRole, - BitrateRole, OriginUrlRole, + Comment, Tags, Rating, ImageSize, ImageDateTime, Orientation, WordCount, Title, + LineCount, Artist, Genre, Album, Duration, Track, ReleaseYear, Bitrate, OriginUrl, // Non-visible roles: - IsDirRole, IsLinkRole, IsHiddenRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole, + IsDir, IsLink, IsHidden, IsExpanded, IsExpandable, ExpandedParentsCount, // Mandatory last entry: RolesCount }; @@ -301,7 +300,7 @@ ItemData* parent; }; - enum RemoveItemsBehavior { + enum class RemoveItemsBehavior { KeepItemData, DeleteItemData }; @@ -482,7 +481,7 @@ KFileItemModelFilter m_filter; QHash m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter() - bool m_requestRole[RolesCount]; + bool m_requestRole[static_cast(RoleType::RolesCount)]; QTimer* m_maximumUpdateIntervalTimer; QTimer* m_resortAllItemsTimer; diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -45,7 +45,7 @@ KItemModelBase("text", parent), m_dirLister(nullptr), m_sortDirsFirst(true), - m_sortRole(NameRole), + m_sortRole(RoleType::Name), m_sortingProgressPercent(-1), m_roles(), m_itemData(), @@ -87,9 +87,9 @@ // Apply default roles that should be determined resetRoles(); - m_requestRole[NameRole] = true; - m_requestRole[IsDirRole] = true; - m_requestRole[IsLinkRole] = true; + m_requestRole[static_cast(RoleType::Name)] = true; + m_requestRole[static_cast(RoleType::IsDir)] = true; + m_requestRole[static_cast(RoleType::IsLink)] = true; m_roles.insert("text"); m_roles.insert("isDir"); m_roles.insert("isLink"); @@ -328,30 +328,30 @@ timer.start(); #endif switch (typeForRole(sortRole())) { - case NameRole: m_groups = nameRoleGroups(); break; - case SizeRole: m_groups = sizeRoleGroups(); break; - case ModificationTimeRole: + case RoleType::Name: m_groups = nameRoleGroups(); break; + case RoleType::Size: m_groups = sizeRoleGroups(); break; + case RoleType::ModificationTime: m_groups = timeRoleGroups([](const ItemData *item) { return item->item.time(KFileItem::ModificationTime); }); break; - case CreationTimeRole: + case RoleType::CreationTime: m_groups = timeRoleGroups([](const ItemData *item) { return item->item.time(KFileItem::CreationTime); }); break; - case AccessTimeRole: + case RoleType::AccessTime: m_groups = timeRoleGroups([](const ItemData *item) { return item->item.time(KFileItem::AccessTime); }); break; - case DeletionTimeRole: + case RoleType::DeletionTime: m_groups = timeRoleGroups([](const ItemData *item) { return item->values.value("deletiontime").toDateTime(); }); break; - case PermissionsRole: m_groups = permissionRoleGroups(); break; - case RatingRole: m_groups = ratingRoleGroups(); break; + case RoleType::Permissions: m_groups = permissionRoleGroups(); break; + case RoleType::Rating: m_groups = ratingRoleGroups(); break; default: m_groups = genericStringRoleGroups(sortRole()); break; } @@ -476,7 +476,7 @@ m_roles = roles; if (count() > 0) { - const bool supportedExpanding = m_requestRole[ExpandedParentsCountRole]; + const bool supportedExpanding = m_requestRole[static_cast(RoleType::ExpandedParentsCount)]; const bool willSupportExpanding = roles.contains("expandedParentsCount"); if (supportedExpanding && !willSupportExpanding) { // No expanding is supported anymore. Take care to delete all items that have an expansion level @@ -491,7 +491,7 @@ QSetIterator it(roles); while (it.hasNext()) { const QByteArray& role = it.next(); - m_requestRole[typeForRole(role)] = true; + m_requestRole[static_cast(typeForRole(role))] = true; } if (count() > 0) { @@ -579,7 +579,7 @@ const int childrenCount = childIndex - firstChildIndex; removeFilteredChildren(KItemRangeList() << KItemRange(index, 1 + childrenCount)); - removeItems(KItemRangeList() << KItemRange(firstChildIndex, childrenCount), DeleteItemData); + removeItems(KItemRangeList() << KItemRange(firstChildIndex, childrenCount), RemoveItemsBehavior::DeleteItemData); m_itemData.at(index)->values.insert("previouslyExpandedChildren", expandedChildren); } @@ -715,7 +715,7 @@ } const KItemRangeList removedRanges = KItemRangeList::fromSortedContainer(newFilteredIndexes); - removeItems(removedRanges, KeepItemData); + removeItems(removedRanges, RemoveItemsBehavior::KeepItemData); // Check which hidden items from m_filteredItems should // get visible again and hence removed from m_filteredItems. @@ -736,7 +736,7 @@ void KFileItemModel::removeFilteredChildren(const KItemRangeList& itemRanges) { - if (m_filteredItems.isEmpty() || !m_requestRole[ExpandedParentsCountRole]) { + if (m_filteredItems.isEmpty() || !m_requestRole[static_cast(RoleType::ExpandedParentsCount)]) { // There are either no filtered items, or it is not possible to expand // folders -> there cannot be any filtered children. return; @@ -767,7 +767,7 @@ int count = 0; const RoleInfoMap* map = rolesInfoMap(count); for (int i = 0; i < count; ++i) { - if (map[i].roleType != NoRole) { + if (map[i].roleType != RoleType::NoRole) { RoleInfo info; info.role = map[i].role; info.translation = i18nc(map[i].roleTranslationContext, map[i].roleTranslation); @@ -800,7 +800,7 @@ Q_UNUSED(previous); m_sortRole = typeForRole(current); - if (!m_requestRole[m_sortRole]) { + if (!m_requestRole[static_cast(m_sortRole)]) { QSet newRoles = m_roles; newRoles << current; setRoles(newRoles); @@ -964,7 +964,7 @@ parentUrl = directoryUrl.adjusted(QUrl::StripTrailingSlash); } - if (m_requestRole[ExpandedParentsCountRole]) { + if (m_requestRole[static_cast(RoleType::ExpandedParentsCount)]) { // If the expanding of items is enabled, the call // dirLister->openUrl(url, KDirLister::Keep) in KFileItemModel::setExpanded() // might result in emitting the same items twice due to the Keep-parameter. @@ -1038,7 +1038,7 @@ std::sort(indexesToRemove.begin(), indexesToRemove.end()); - if (m_requestRole[ExpandedParentsCountRole] && !m_expandedDirs.isEmpty()) { + if (m_requestRole[static_cast(RoleType::ExpandedParentsCount)] && !m_expandedDirs.isEmpty()) { // Assure that removing a parent item also results in removing all children QVector indexesToRemoveWithChildren; indexesToRemoveWithChildren.reserve(m_itemData.count()); @@ -1060,7 +1060,7 @@ const KItemRangeList itemRanges = KItemRangeList::fromSortedContainer(indexesToRemove); removeFilteredChildren(itemRanges); - removeItems(itemRanges, DeleteItemData); + removeItems(itemRanges, RemoveItemsBehavior::DeleteItemData); } void KFileItemModel::slotRefreshItems(const QList >& items) @@ -1187,7 +1187,7 @@ m_groups.clear(); prepareItemsForSorting(newItems); - if (m_sortRole == NameRole && m_naturalSorting) { + if (m_sortRole == RoleType::Name && m_naturalSorting) { // Natural sorting of items can be very slow. However, it becomes much // faster if the input sequence is already mostly sorted. Therefore, we // first sort 'newItems' according to the QStrings returned by @@ -1280,7 +1280,7 @@ removedItemsCount += range.count; for (int index = range.index; index < range.index + range.count; ++index) { - if (behavior == DeleteItemData) { + if (behavior == RemoveItemsBehavior::DeleteItemData) { delete m_itemData.at(index); } @@ -1317,7 +1317,7 @@ QList KFileItemModel::createItemDataList(const QUrl& parentUrl, const KFileItemList& items) const { - if (m_sortRole == TypeRole) { + if (m_sortRole == RoleType::Type) { // Try to resolve the MIME-types synchronously to prevent a reordering of // the items when sorting by type (per default MIME-types are resolved // asynchronously by KFileItemModelRolesUpdater). @@ -1343,12 +1343,12 @@ void KFileItemModel::prepareItemsForSorting(QList& itemDataList) { switch (m_sortRole) { - case PermissionsRole: - case OwnerRole: - case GroupRole: - case DestinationRole: - case PathRole: - case DeletionTimeRole: + case RoleType::Permissions: + case RoleType::Owner: + case RoleType::Group: + case RoleType::Destination: + case RoleType::Path: + case RoleType::DeletionTime: // These roles can be determined with retrieveData, and they have to be stored // in the QHash "values" for the sorting. foreach (ItemData* itemData, itemDataList) { @@ -1358,7 +1358,7 @@ } break; - case TypeRole: + case RoleType::Type: // At least store the data including the file type for items with known MIME type. foreach (ItemData* itemData, itemDataList) { if (itemData->values.isEmpty()) { @@ -1409,7 +1409,7 @@ } } - removeItems(KItemRangeList::fromSortedContainer(indexesToRemove), DeleteItemData); + removeItems(KItemRangeList::fromSortedContainer(indexesToRemove), RemoveItemsBehavior::DeleteItemData); m_expandedDirs.clear(); // Also remove all filtered items which have a parent. @@ -1432,7 +1432,7 @@ // 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))) { + if (changedRoles.contains(sortRole()) || changedRoles.contains(roleForType(RoleType::Name))) { foreach (const KItemRange& range, itemRanges) { bool needsResorting = false; @@ -1480,7 +1480,7 @@ void KFileItemModel::resetRoles() { - for (int i = 0; i < RolesCount; ++i) { + for (int i = 0; i < static_cast(RoleType::RolesCount); ++i) { m_requestRole[i] = false; } } @@ -1499,44 +1499,44 @@ // Insert internal roles (take care to synchronize the implementation // with KFileItemModel::roleForType() in case if a change is done). - roles.insert("isDir", IsDirRole); - roles.insert("isLink", IsLinkRole); - roles.insert("isHidden", IsHiddenRole); - roles.insert("isExpanded", IsExpandedRole); - roles.insert("isExpandable", IsExpandableRole); - roles.insert("expandedParentsCount", ExpandedParentsCountRole); + roles.insert("isDir", RoleType::IsDir); + roles.insert("isLink", RoleType::IsLink); + roles.insert("isHidden", RoleType::IsHidden); + roles.insert("isExpanded", RoleType::IsExpanded); + roles.insert("isExpandable", RoleType::IsExpandable); + roles.insert("expandedParentsCount", RoleType::ExpandedParentsCount); - Q_ASSERT(roles.count() == RolesCount); + Q_ASSERT(roles.count() == static_cast(RoleType::RolesCount)); } - return roles.value(role, NoRole); + return roles.value(role, RoleType::NoRole); } QByteArray KFileItemModel::roleForType(RoleType roleType) const { - static QHash roles; + static QHash roles; if (roles.isEmpty()) { // Insert user visible roles that can be accessed with // KFileItemModel::roleInformation() int count = 0; const RoleInfoMap* map = rolesInfoMap(count); for (int i = 0; i < count; ++i) { - roles.insert(map[i].roleType, map[i].role); + roles.insert(static_cast(map[i].roleType), map[i].role); } // Insert internal roles (take care to synchronize the implementation // with KFileItemModel::typeForRole() in case if a change is done). - roles.insert(IsDirRole, "isDir"); - roles.insert(IsLinkRole, "isLink"); - roles.insert(IsHiddenRole, "isHidden"); - roles.insert(IsExpandedRole, "isExpanded"); - roles.insert(IsExpandableRole, "isExpandable"); - roles.insert(ExpandedParentsCountRole, "expandedParentsCount"); - - Q_ASSERT(roles.count() == RolesCount); + roles.insert(static_cast(RoleType::IsDir), "isDir"); + roles.insert(static_cast(RoleType::IsLink), "isLink"); + roles.insert(static_cast(RoleType::IsHidden), "isHidden"); + roles.insert(static_cast(RoleType::IsExpanded), "isExpanded"); + roles.insert(static_cast(RoleType::IsExpandable), "isExpandable"); + roles.insert(static_cast(RoleType::ExpandedParentsCount), "expandedParentsCount"); + + Q_ASSERT(roles.count() == static_cast(RoleType::RolesCount)); }; - return roles.value(roleType); + return roles.value(static_cast(roleType)); } QHash KFileItemModel::retrieveData(const KFileItem& item, const ItemData* parent) const @@ -1548,71 +1548,71 @@ data.insert(sharedValue("url"), item.url()); const bool isDir = item.isDir(); - if (m_requestRole[IsDirRole] && isDir) { + if (m_requestRole[static_cast(RoleType::IsDir)] && isDir) { data.insert(sharedValue("isDir"), true); } - if (m_requestRole[IsLinkRole] && item.isLink()) { + if (m_requestRole[static_cast(RoleType::IsLink)] && item.isLink()) { data.insert(sharedValue("isLink"), true); } - if (m_requestRole[IsHiddenRole] && item.isHidden()) { + if (m_requestRole[static_cast(RoleType::IsHidden)] && item.isHidden()) { data.insert(sharedValue("isHidden"), true); } - if (m_requestRole[NameRole]) { + if (m_requestRole[static_cast(RoleType::Name)]) { data.insert(sharedValue("text"), item.text()); } - if (m_requestRole[SizeRole] && !isDir) { + if (m_requestRole[static_cast(RoleType::Size)] && !isDir) { data.insert(sharedValue("size"), item.size()); } - if (m_requestRole[ModificationTimeRole]) { + if (m_requestRole[static_cast(RoleType::ModificationTime)]) { // Don't use KFileItem::timeString() as this is too expensive when // having several thousands of items. Instead the formatting of the // date-time will be done on-demand by the view when the date will be shown. const QDateTime dateTime = item.time(KFileItem::ModificationTime); data.insert(sharedValue("modificationtime"), dateTime); } - if (m_requestRole[CreationTimeRole]) { + if (m_requestRole[static_cast(RoleType::CreationTime)]) { // Don't use KFileItem::timeString() as this is too expensive when // having several thousands of items. Instead the formatting of the // date-time will be done on-demand by the view when the date will be shown. const QDateTime dateTime = item.time(KFileItem::CreationTime); data.insert(sharedValue("creationtime"), dateTime); } - if (m_requestRole[AccessTimeRole]) { + if (m_requestRole[static_cast(RoleType::AccessTime)]) { // Don't use KFileItem::timeString() as this is too expensive when // having several thousands of items. Instead the formatting of the // date-time will be done on-demand by the view when the date will be shown. const QDateTime dateTime = item.time(KFileItem::AccessTime); data.insert(sharedValue("accesstime"), dateTime); } - if (m_requestRole[PermissionsRole]) { + if (m_requestRole[static_cast(RoleType::Permissions)]) { data.insert(sharedValue("permissions"), item.permissionsString()); } - if (m_requestRole[OwnerRole]) { + if (m_requestRole[static_cast(RoleType::Owner)]) { data.insert(sharedValue("owner"), item.user()); } - if (m_requestRole[GroupRole]) { + if (m_requestRole[static_cast(RoleType::Group)]) { data.insert(sharedValue("group"), item.group()); } - if (m_requestRole[DestinationRole]) { + if (m_requestRole[static_cast(RoleType::Destination)]) { QString destination = item.linkDest(); if (destination.isEmpty()) { destination = QStringLiteral("-"); } data.insert(sharedValue("destination"), destination); } - if (m_requestRole[PathRole]) { + if (m_requestRole[static_cast(RoleType::Path)]) { QString path; if (item.url().scheme() == QLatin1String("trash")) { path = item.entry().stringValue(KIO::UDSEntry::UDS_EXTRA); @@ -1635,19 +1635,19 @@ data.insert(sharedValue("path"), path); } - if (m_requestRole[DeletionTimeRole]) { + if (m_requestRole[static_cast(RoleType::DeletionTime)]) { QDateTime deletionTime; if (item.url().scheme() == QLatin1String("trash")) { deletionTime = QDateTime::fromString(item.entry().stringValue(KIO::UDSEntry::UDS_EXTRA + 1), Qt::ISODate); } data.insert(sharedValue("deletiontime"), deletionTime); } - if (m_requestRole[IsExpandableRole] && isDir) { + if (m_requestRole[static_cast(RoleType::IsExpandable)] && isDir) { data.insert(sharedValue("isExpandable"), true); } - if (m_requestRole[ExpandedParentsCountRole]) { + if (m_requestRole[static_cast(RoleType::ExpandedParentsCount)]) { if (parent) { const int level = expandedParentsCount(parent) + 1; data.insert(sharedValue("expandedParentsCount"), level); @@ -1657,10 +1657,10 @@ if (item.isMimeTypeKnown()) { data.insert(sharedValue("iconName"), item.iconName()); - if (m_requestRole[TypeRole]) { + if (m_requestRole[static_cast(RoleType::Type)]) { data.insert(sharedValue("type"), item.mimeComment()); } - } else if (m_requestRole[TypeRole] && isDir) { + } else if (m_requestRole[static_cast(RoleType::Type)] && isDir) { static const QString folderMimeType = item.mimeComment(); data.insert(sharedValue("type"), folderMimeType); } @@ -1703,7 +1703,7 @@ } } - if (m_sortDirsFirst || m_sortRole == SizeRole) { + if (m_sortDirsFirst || m_sortRole == RoleType::Size) { const bool isDirA = a->item.isDir(); const bool isDirB = b->item.isDir(); if (isDirA && !isDirB) { @@ -1765,7 +1765,7 @@ { KFileItemModelLessThan lessThan(this, m_collator); - if (m_sortRole == NameRole) { + if (m_sortRole == RoleType::Name) { // Sorting by name can be expensive, in particular if natural sorting is // enabled. Use all CPU cores to speed up the sorting process. static const int numberOfThreads = QThread::idealThreadCount(); @@ -1786,11 +1786,11 @@ int result = 0; switch (m_sortRole) { - case NameRole: + case RoleType::Name: // The name role is handled as default fallback after the switch break; - case SizeRole: { + case RoleType::Size: { if (itemA.isDir()) { // See "if (m_sortFoldersFirst || m_sortRole == SizeRole)" in KFileItemModel::lessThan(): Q_ASSERT(itemB.isDir()); @@ -1822,7 +1822,7 @@ break; } - case ModificationTimeRole: { + case RoleType::ModificationTime: { const QDateTime dateTimeA = itemA.time(KFileItem::ModificationTime); const QDateTime dateTimeB = itemB.time(KFileItem::ModificationTime); if (dateTimeA < dateTimeB) { @@ -1833,7 +1833,7 @@ break; } - case CreationTimeRole: { + case RoleType::CreationTime: { const QDateTime dateTimeA = itemA.time(KFileItem::CreationTime); const QDateTime dateTimeB = itemB.time(KFileItem::CreationTime); if (dateTimeA < dateTimeB) { @@ -1844,7 +1844,7 @@ break; } - case DeletionTimeRole: { + case RoleType::DeletionTime: { const QDateTime dateTimeA = a->values.value("deletiontime").toDateTime(); const QDateTime dateTimeB = b->values.value("deletiontime").toDateTime(); if (dateTimeA < dateTimeB) { @@ -1855,12 +1855,12 @@ break; } - case RatingRole: { + case RoleType::Rating: { result = a->values.value("rating").toInt() - b->values.value("rating").toInt(); break; } - case ImageSizeRole: { + case RoleType::ImageSize: { // Alway use a natural comparing to interpret the numbers of a string like // "1600 x 1200" for having a correct sorting. result = collator.compare(a->values.value("imageSize").toString(), @@ -2299,37 +2299,37 @@ const KFileItemModel::RoleInfoMap* KFileItemModel::rolesInfoMap(int& count) { static const RoleInfoMap rolesInfoMap[] = { - // | role | roleType | role translation | group translation | requires Baloo | requires indexer - { nullptr, NoRole, nullptr, nullptr, nullptr, nullptr, false, false }, - { "text", NameRole, I18N_NOOP2_NOSTRIP("@label", "Name"), nullptr, nullptr, false, false }, - { "size", SizeRole, I18N_NOOP2_NOSTRIP("@label", "Size"), nullptr, nullptr, false, false }, - { "modificationtime", ModificationTimeRole, I18N_NOOP2_NOSTRIP("@label", "Modified"), nullptr, nullptr, false, false }, - { "creationtime", CreationTimeRole, I18N_NOOP2_NOSTRIP("@label", "Created"), nullptr, nullptr, false, false }, - { "accesstime", AccessTimeRole, I18N_NOOP2_NOSTRIP("@label", "Accessed"), nullptr, nullptr, false, false }, - { "type", TypeRole, I18N_NOOP2_NOSTRIP("@label", "Type"), nullptr, nullptr, false, false }, - { "rating", RatingRole, I18N_NOOP2_NOSTRIP("@label", "Rating"), nullptr, nullptr, true, false }, - { "tags", TagsRole, I18N_NOOP2_NOSTRIP("@label", "Tags"), nullptr, nullptr, true, false }, - { "comment", CommentRole, I18N_NOOP2_NOSTRIP("@label", "Comment"), nullptr, nullptr, true, false }, - { "title", TitleRole, I18N_NOOP2_NOSTRIP("@label", "Title"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, - { "wordCount", WordCountRole, I18N_NOOP2_NOSTRIP("@label", "Word Count"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, - { "lineCount", LineCountRole, I18N_NOOP2_NOSTRIP("@label", "Line Count"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, - { "imageDateTime", ImageDateTimeRole, I18N_NOOP2_NOSTRIP("@label", "Date Photographed"), I18N_NOOP2_NOSTRIP("@label", "Image"), true, true }, - { "imageSize", ImageSizeRole, I18N_NOOP2_NOSTRIP("@label", "Image Size"), I18N_NOOP2_NOSTRIP("@label", "Image"), true, true }, - { "orientation", OrientationRole, I18N_NOOP2_NOSTRIP("@label", "Orientation"), I18N_NOOP2_NOSTRIP("@label", "Image"), true, true }, - { "artist", ArtistRole, I18N_NOOP2_NOSTRIP("@label", "Artist"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, - { "genre", GenreRole, I18N_NOOP2_NOSTRIP("@label", "Genre"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, - { "album", AlbumRole, I18N_NOOP2_NOSTRIP("@label", "Album"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, - { "duration", DurationRole, I18N_NOOP2_NOSTRIP("@label", "Duration"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, - { "bitrate", BitrateRole, I18N_NOOP2_NOSTRIP("@label", "Bitrate"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, - { "track", TrackRole, I18N_NOOP2_NOSTRIP("@label", "Track"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, - { "releaseYear", ReleaseYearRole, I18N_NOOP2_NOSTRIP("@label", "Release Year"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, - { "path", PathRole, I18N_NOOP2_NOSTRIP("@label", "Path"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, - { "deletiontime",DeletionTimeRole,I18N_NOOP2_NOSTRIP("@label", "Deletion Time"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, - { "destination", DestinationRole, I18N_NOOP2_NOSTRIP("@label", "Link Destination"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, - { "originUrl", OriginUrlRole, I18N_NOOP2_NOSTRIP("@label", "Downloaded From"), I18N_NOOP2_NOSTRIP("@label", "Other"), true, false }, - { "permissions", PermissionsRole, I18N_NOOP2_NOSTRIP("@label", "Permissions"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, - { "owner", OwnerRole, I18N_NOOP2_NOSTRIP("@label", "Owner"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, - { "group", GroupRole, I18N_NOOP2_NOSTRIP("@label", "User Group"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, + // | role | roleType | role translation | group translation | requires Baloo | requires indexer + { nullptr, RoleType::NoRole, nullptr, nullptr, nullptr, nullptr, false, false }, + { "text", RoleType::Name, I18N_NOOP2_NOSTRIP("@label", "Name"), nullptr, nullptr, false, false }, + { "size", RoleType::Size, I18N_NOOP2_NOSTRIP("@label", "Size"), nullptr, nullptr, false, false }, + { "modificationtime", RoleType::ModificationTime, I18N_NOOP2_NOSTRIP("@label", "Modified"), nullptr, nullptr, false, false }, + { "creationtime", RoleType::CreationTime, I18N_NOOP2_NOSTRIP("@label", "Created"), nullptr, nullptr, false, false }, + { "accesstime", RoleType::AccessTime, I18N_NOOP2_NOSTRIP("@label", "Accessed"), nullptr, nullptr, false, false }, + { "type", RoleType::Type, I18N_NOOP2_NOSTRIP("@label", "Type"), nullptr, nullptr, false, false }, + { "rating", RoleType::Rating, I18N_NOOP2_NOSTRIP("@label", "Rating"), nullptr, nullptr, true, false }, + { "tags", RoleType::Tags, I18N_NOOP2_NOSTRIP("@label", "Tags"), nullptr, nullptr, true, false }, + { "comment", RoleType::Comment, I18N_NOOP2_NOSTRIP("@label", "Comment"), nullptr, nullptr, true, false }, + { "title", RoleType::Title, I18N_NOOP2_NOSTRIP("@label", "Title"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, + { "wordCount", RoleType::WordCount, I18N_NOOP2_NOSTRIP("@label", "Word Count"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, + { "lineCount", RoleType::LineCount, I18N_NOOP2_NOSTRIP("@label", "Line Count"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, + { "imageDateTime", RoleType::ImageDateTime, I18N_NOOP2_NOSTRIP("@label", "Date Photographed"), I18N_NOOP2_NOSTRIP("@label", "Image"), true, true }, + { "imageSize", RoleType::ImageSize, I18N_NOOP2_NOSTRIP("@label", "Image Size"), I18N_NOOP2_NOSTRIP("@label", "Image"), true, true }, + { "orientation", RoleType::Orientation, I18N_NOOP2_NOSTRIP("@label", "Orientation"), I18N_NOOP2_NOSTRIP("@label", "Image"), true, true }, + { "artist", RoleType::Artist, I18N_NOOP2_NOSTRIP("@label", "Artist"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, + { "genre", RoleType::Genre, I18N_NOOP2_NOSTRIP("@label", "Genre"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, + { "album", RoleType::Album, I18N_NOOP2_NOSTRIP("@label", "Album"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, + { "duration", RoleType::Duration, I18N_NOOP2_NOSTRIP("@label", "Duration"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, + { "bitrate", RoleType::Bitrate, I18N_NOOP2_NOSTRIP("@label", "Bitrate"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, + { "track", RoleType::Track, I18N_NOOP2_NOSTRIP("@label", "Track"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, + { "releaseYear", RoleType::ReleaseYear, I18N_NOOP2_NOSTRIP("@label", "Release Year"), I18N_NOOP2_NOSTRIP("@label", "Audio"), true, true }, + { "path", RoleType::Path, I18N_NOOP2_NOSTRIP("@label", "Path"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, + { "deletiontime", RoleType::DeletionTime, I18N_NOOP2_NOSTRIP("@label", "Deletion Time"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, + { "destination", RoleType::Destination, I18N_NOOP2_NOSTRIP("@label", "Link Destination"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, + { "originUrl", RoleType::OriginUrl, I18N_NOOP2_NOSTRIP("@label", "Downloaded From"), I18N_NOOP2_NOSTRIP("@label", "Other"), true, false }, + { "permissions", RoleType::Permissions, I18N_NOOP2_NOSTRIP("@label", "Permissions"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, + { "owner", RoleType::Owner, I18N_NOOP2_NOSTRIP("@label", "Owner"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, + { "group", RoleType::Group, I18N_NOOP2_NOSTRIP("@label", "User Group"), I18N_NOOP2_NOSTRIP("@label", "Other"), false, false }, }; count = sizeof(rolesInfoMap) / sizeof(RoleInfoMap); diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h --- a/src/kitemviews/kfileitemmodelrolesupdater.h +++ b/src/kitemviews/kfileitemmodelrolesupdater.h @@ -252,7 +252,7 @@ void applySortProgressToModel(); - enum ResolveHint { + enum class ResolveHint { ResolveFast, ResolveAll }; @@ -275,7 +275,7 @@ QList indexesToResolve() const; private: - enum State { + enum class State { Idle, Paused, ResolvingSortRole, diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -68,7 +68,7 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QObject* parent) : QObject(parent), - m_state(Idle), + m_state(State::Idle), m_previewChangedDuringPausing(false), m_iconSizeChangedDuringPausing(false), m_rolesChangedDuringPausing(false), @@ -152,7 +152,7 @@ { if (size != m_iconSize) { m_iconSize = size; - if (m_state == Paused) { + if (m_state == State::Paused) { m_iconSizeChangedDuringPausing = true; } else if (m_previewShown) { // An icon size change requires the regenerating of @@ -239,12 +239,12 @@ void KFileItemModelRolesUpdater::setPaused(bool paused) { - if (paused == (m_state == Paused)) { + if (paused == (m_state == State::Paused)) { return; } if (paused) { - m_state = Paused; + m_state = State::Paused; killPreviewJob(); } else { const bool updatePreviews = (m_iconSizeChangedDuringPausing && m_previewShown) || @@ -259,10 +259,10 @@ m_rolesChangedDuringPausing = false; if (!m_pendingSortRoleItems.isEmpty()) { - m_state = ResolvingSortRole; + m_state = State::ResolvingSortRole; resolveNextSortRole(); } else { - m_state = Idle; + m_state = State::Idle; } startUpdating(); @@ -300,7 +300,7 @@ } #endif - if (m_state == Paused) { + if (m_state == State::Paused) { m_rolesChangedDuringPausing = true; } else { startUpdating(); @@ -315,7 +315,7 @@ bool KFileItemModelRolesUpdater::isPaused() const { - return m_state == Paused; + return m_state == State::Paused; } QStringList KFileItemModelRolesUpdater::enabledPlugins() const @@ -348,9 +348,9 @@ // If there are still items whose sort role is unknown, check if the // asynchronous determination of the sort role is already in progress, // and start it if that is not the case. - if (!m_pendingSortRoleItems.isEmpty() && m_state != ResolvingSortRole) { + if (!m_pendingSortRoleItems.isEmpty() && m_state != State::ResolvingSortRole) { killPreviewJob(); - m_state = ResolvingSortRole; + m_state = State::ResolvingSortRole; resolveNextSortRole(); } } @@ -382,7 +382,7 @@ #endif if (allItemsRemoved) { - m_state = Idle; + m_state = State::Idle; m_finishedItems.clear(); m_pendingSortRoleItems.clear(); @@ -475,19 +475,19 @@ if (!m_pendingSortRoleItems.isEmpty()) { // Trigger the asynchronous determination of the sort role. killPreviewJob(); - m_state = ResolvingSortRole; + m_state = State::ResolvingSortRole; resolveNextSortRole(); } } else { - m_state = Idle; + m_state = State::Idle; m_pendingSortRoleItems.clear(); applySortProgressToModel(); } } void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPixmap& pixmap) { - if (m_state != PreviewJobRunning) { + if (m_state != State::PreviewJobRunning) { return; } @@ -570,7 +570,7 @@ void KFileItemModelRolesUpdater::slotPreviewFailed(const KFileItem& item) { - if (m_state != PreviewJobRunning) { + if (m_state != State::PreviewJobRunning) { return; } @@ -587,20 +587,20 @@ connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); - applyResolvedRoles(index, ResolveAll); + applyResolvedRoles(index, ResolveHint::ResolveAll); m_finishedItems.insert(item); } } void KFileItemModelRolesUpdater::slotPreviewJobFinished() { m_previewJob = nullptr; - if (m_state != PreviewJobRunning) { + if (m_state != State::PreviewJobRunning) { return; } - m_state = Idle; + m_state = State::Idle; if (!m_pendingPreviewItems.isEmpty()) { startPreviewJob(); @@ -613,7 +613,7 @@ void KFileItemModelRolesUpdater::resolveNextSortRole() { - if (m_state != ResolvingSortRole) { + if (m_state != State::ResolvingSortRole) { return; } @@ -638,7 +638,7 @@ applySortProgressToModel(); QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextSortRole); } else { - m_state = Idle; + m_state = State::Idle; // Prevent that we try to update the items twice. disconnect(m_model, &KFileItemModel::itemsMoved, @@ -652,7 +652,7 @@ void KFileItemModelRolesUpdater::resolveNextPendingRoles() { - if (m_state != ResolvingAllRoles) { + if (m_state != State::ResolvingAllRoles) { return; } @@ -664,16 +664,16 @@ continue; } - applyResolvedRoles(index, ResolveAll); + applyResolvedRoles(index, ResolveHint::ResolveAll); m_finishedItems.insert(item); m_changedItems.remove(item); break; } if (!m_pendingIndexes.isEmpty()) { QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles); } else { - m_state = Idle; + m_state = State::Idle; if (m_clearPreviews) { // Only go through the list if there are items which might still have previews. @@ -785,13 +785,13 @@ void KFileItemModelRolesUpdater::startUpdating() { - if (m_state == Paused) { + if (m_state == State::Paused) { return; } if (m_finishedItems.count() == m_model->count()) { // All roles have been resolved already. - m_state = Idle; + m_state = State::Idle; return; } @@ -807,7 +807,7 @@ // A detailed update of the items in and near the visible area // only makes sense if sorting is finished. - if (m_state == ResolvingSortRole) { + if (m_state == State::ResolvingSortRole) { return; } @@ -829,7 +829,7 @@ } else { m_pendingIndexes = indexes; // Trigger the asynchronous resolving of all roles. - m_state = ResolvingAllRoles; + m_state = State::ResolvingAllRoles; QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles); } } @@ -852,7 +852,7 @@ // Try to determine the final icons for all visible items. int index; for (index = m_firstVisibleIndex; index <= lastVisibleIndex && timer.elapsed() < MaxBlockTimeout; ++index) { - applyResolvedRoles(index, ResolveFast); + applyResolvedRoles(index, ResolveHint::ResolveFast); } // KFileItemListView::initializeItemListWidget(KItemListWidget*) will load @@ -862,7 +862,7 @@ void KFileItemModelRolesUpdater::startPreviewJob() { - m_state = PreviewJobRunning; + m_state = State::PreviewJobRunning; if (m_pendingPreviewItems.isEmpty()) { QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::slotPreviewJobFinished); @@ -924,7 +924,7 @@ void KFileItemModelRolesUpdater::updateChangedItems() { - if (m_state == Paused) { + if (m_state == State::Paused) { return; } @@ -937,11 +937,11 @@ if (m_resolvableRoles.contains(m_model->sortRole())) { m_pendingSortRoleItems += m_changedItems; - if (m_state != ResolvingSortRole) { + if (m_state != State::ResolvingSortRole) { // Stop the preview job if necessary, and trigger the // asynchronous determination of the sort role. killPreviewJob(); - m_state = ResolvingSortRole; + m_state = State::ResolvingSortRole; QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextSortRole); } @@ -985,7 +985,7 @@ m_pendingIndexes = visibleChangedIndexes + m_pendingIndexes + invisibleChangedIndexes; if (!resolvingInProgress) { // Trigger the asynchronous resolving of the changed roles. - m_state = ResolvingAllRoles; + m_state = State::ResolvingAllRoles; QTimer::singleShot(0, this, &KFileItemModelRolesUpdater::resolveNextPendingRoles); } } @@ -1028,7 +1028,7 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint) { const KFileItem item = m_model->fileItem(index); - const bool resolveAll = (hint == ResolveAll); + const bool resolveAll = (hint == ResolveHint::ResolveAll); bool iconChanged = false; if (!item.isMimeTypeKnown() || !item.isFinalIconKnown()) { @@ -1120,7 +1120,7 @@ void KFileItemModelRolesUpdater::updateAllPreviews() { - if (m_state == Paused) { + if (m_state == State::Paused) { m_previewChangedDuringPausing = true; } else { m_finishedItems.clear(); diff --git a/src/kitemviews/kitemlistcontroller.h b/src/kitemviews/kitemlistcontroller.h --- a/src/kitemviews/kitemlistcontroller.h +++ b/src/kitemviews/kitemlistcontroller.h @@ -66,19 +66,19 @@ Q_PROPERTY(MouseDoubleClickAction mouseDoubleClickAction READ mouseDoubleClickAction WRITE setMouseDoubleClickAction) public: - enum SelectionBehavior { + enum class SelectionBehavior { NoSelection, SingleSelection, MultiSelection }; Q_ENUM(SelectionBehavior) - enum AutoActivationBehavior { + enum class AutoActivationBehavior { ActivationAndExpansion, ExpansionOnly }; - enum MouseDoubleClickAction { + enum class MouseDoubleClickAction { ActivateAndExpandItem, ActivateItemOnly }; diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -46,9 +46,9 @@ m_singleClickActivationEnforced(false), m_selectionTogglePressed(false), m_clearSelectionIfItemsAreNotDragged(false), - m_selectionBehavior(NoSelection), - m_autoActivationBehavior(ActivationAndExpansion), - m_mouseDoubleClickAction(ActivateItemOnly), + m_selectionBehavior(SelectionBehavior::NoSelection), + m_autoActivationBehavior(AutoActivationBehavior::ActivationAndExpansion), + m_mouseDoubleClickAction(MouseDoubleClickAction::ActivateItemOnly), m_model(nullptr), m_view(nullptr), m_selectionManager(new KItemListSelectionManager(this)), @@ -261,7 +261,7 @@ } } - const bool selectSingleItem = m_selectionBehavior != NoSelection && + const bool selectSingleItem = m_selectionBehavior != SelectionBehavior::NoSelection && itemCount == 1 && (key == Qt::Key_Home || key == Qt::Key_End || key == Qt::Key_Up || key == Qt::Key_Down || @@ -412,19 +412,19 @@ } case Qt::Key_Escape: - if (m_selectionBehavior != SingleSelection) { + if (m_selectionBehavior != SelectionBehavior::SingleSelection) { m_selectionManager->clearSelection(); } m_keyboardManager->cancelSearch(); emit escapePressed(); break; case Qt::Key_Space: - if (m_selectionBehavior == MultiSelection) { + if (m_selectionBehavior == SelectionBehavior::MultiSelection) { if (controlPressed) { // Toggle the selection state of the current item. m_selectionManager->endAnchoredSelection(); - m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle); + m_selectionManager->setSelected(index, 1, KItemListSelectionManager::SelectionMode::Toggle); m_selectionManager->beginAnchoredSelection(index); break; } else { @@ -447,17 +447,17 @@ if (m_selectionManager->currentItem() != index) { switch (m_selectionBehavior) { - case NoSelection: + case SelectionBehavior::NoSelection: m_selectionManager->setCurrentItem(index); break; - case SingleSelection: + case SelectionBehavior::SingleSelection: m_selectionManager->setCurrentItem(index); m_selectionManager->clearSelection(); m_selectionManager->setSelected(index, 1); break; - case MultiSelection: + case SelectionBehavior::MultiSelection: if (controlPressed) { m_selectionManager->endAnchoredSelection(); } @@ -495,7 +495,7 @@ if (index >= 0) { m_selectionManager->setCurrentItem(index); - if (m_selectionBehavior != NoSelection) { + if (m_selectionBehavior != SelectionBehavior::NoSelection) { m_selectionManager->clearSelection(); m_selectionManager->setSelected(index, 1); m_selectionManager->beginAnchoredSelection(index); @@ -529,7 +529,7 @@ if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) { const bool expanded = m_model->isExpanded(index); m_model->setExpanded(index, !expanded); - } else if (m_autoActivationBehavior != ExpansionOnly) { + } else if (m_autoActivationBehavior != AutoActivationBehavior::ExpansionOnly) { emit itemActivated(index); } } @@ -566,7 +566,7 @@ m_selectionTogglePressed = m_view->isAboveSelectionToggle(m_pressedIndex, m_pressedMousePos); if (m_selectionTogglePressed) { - m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); + m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Toggle); // The previous anchored selection has been finished already in // KItemListSelectionManager::setSelected(). We can safely change // the current item and start a new anchored selection now. @@ -587,7 +587,7 @@ // - open the context menu and perform an action for all selected items. const bool shiftOrControlPressed = shiftPressed || controlPressed; const bool pressedItemAlreadySelected = m_pressedIndex >= 0 && m_selectionManager->isSelected(m_pressedIndex); - const bool clearSelection = m_selectionBehavior == SingleSelection || + const bool clearSelection = m_selectionBehavior == SelectionBehavior::SingleSelection || (!shiftOrControlPressed && !pressedItemAlreadySelected); if (clearSelection) { m_selectionManager->clearSelection(); @@ -613,20 +613,20 @@ m_selectionManager->setCurrentItem(m_pressedIndex); switch (m_selectionBehavior) { - case NoSelection: + case SelectionBehavior::NoSelection: break; - case SingleSelection: + case SelectionBehavior::SingleSelection: m_selectionManager->setSelected(m_pressedIndex); break; - case MultiSelection: + case SelectionBehavior::MultiSelection: if (controlPressed && !shiftPressed) { - m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); + m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Toggle); m_selectionManager->beginAnchoredSelection(m_pressedIndex); } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) { // Select the pressed item and start a new anchored selection - m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select); + m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Select); m_selectionManager->beginAnchoredSelection(m_pressedIndex); } break; @@ -653,7 +653,7 @@ return true; } - if (m_selectionBehavior == MultiSelection) { + if (m_selectionBehavior == SelectionBehavior::MultiSelection) { QPointF startPos = m_pressedMousePos; if (m_view->scrollOrientation() == Qt::Vertical) { startPos.ry() += m_view->scrollOffset(); @@ -693,7 +693,7 @@ // Always assure that the dragged item gets selected. Usually this is already // done on the mouse-press event, but when using the selection-toggle on a // selected item the dragged item is not selected yet. - m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); + m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Toggle); } else { // A selected item has been clicked to drag all selected items // -> the selection should not be cleared when the mouse button is released. @@ -749,7 +749,7 @@ } if (!isAboveSelectionToggle && m_selectionTogglePressed) { - m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); + m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Toggle); m_selectionTogglePressed = false; return true; } @@ -775,7 +775,7 @@ // A selected item has been clicked, but no drag operation has been started // -> clear the rest of the selection. m_selectionManager->clearSelection(); - m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Select); + m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::SelectionMode::Select); m_selectionManager->beginAnchoredSelection(m_pressedIndex); } @@ -813,7 +813,7 @@ const int index = m_view->itemAt(pos); // Expand item if desired - See Bug 295573 - if (m_mouseDoubleClickAction != ActivateItemOnly) { + if (m_mouseDoubleClickAction != MouseDoubleClickAction::ActivateItemOnly) { if (m_view && m_model && m_view->supportsItemExpanding() && m_model->isExpandable(index)) { const bool expanded = m_model->isExpanded(index); m_model->setExpanded(index, !expanded); @@ -1347,7 +1347,7 @@ void KItemListController::updateExtendedSelectionRegion() { if (m_view) { - const bool extend = (m_selectionBehavior != MultiSelection); + const bool extend = (m_selectionBehavior != SelectionBehavior::MultiSelection); KItemListStyleOption option = m_view->styleOption(); if (option.extendedSelectionRegion != extend) { option.extendedSelectionRegion = extend; diff --git a/src/kitemviews/kitemlistheader.cpp b/src/kitemviews/kitemlistheader.cpp --- a/src/kitemviews/kitemlistheader.cpp +++ b/src/kitemviews/kitemlistheader.cpp @@ -32,7 +32,7 @@ m_headerWidget->setAutomaticColumnResizing(automatic); if (automatic) { m_view->applyAutomaticColumnWidths(); - m_view->doLayout(KItemListView::NoAnimation); + m_view->doLayout(KItemListView::LayoutAnimationHint::NoAnimation); } } } @@ -47,7 +47,7 @@ if (!m_headerWidget->automaticColumnResizing()) { m_headerWidget->setColumnWidth(role, width); m_view->applyColumnWidthsFromHeader(); - m_view->doLayout(KItemListView::NoAnimation); + m_view->doLayout(KItemListView::LayoutAnimationHint::NoAnimation); } } @@ -65,7 +65,7 @@ } m_view->applyColumnWidthsFromHeader(); - m_view->doLayout(KItemListView::NoAnimation); + m_view->doLayout(KItemListView::LayoutAnimationHint::NoAnimation); } } diff --git a/src/kitemviews/kitemlistselectionmanager.h b/src/kitemviews/kitemlistselectionmanager.h --- a/src/kitemviews/kitemlistselectionmanager.h +++ b/src/kitemviews/kitemlistselectionmanager.h @@ -39,13 +39,13 @@ { Q_OBJECT - enum RangesRemovingBehaviour { + enum class RangesRemovingBehaviour { DiscardRemovedIndex, AdjustRemovedIndex }; public: - enum SelectionMode { + enum class SelectionMode { Select, Deselect, Toggle @@ -62,7 +62,7 @@ bool isSelected(int index) const; bool hasSelection() const; - void setSelected(int index, int count = 1, SelectionMode mode = Select); + void setSelected(int index, int count = 1, SelectionMode mode = SelectionMode::Select); void clearSelection(); void beginAnchoredSelection(int anchor); diff --git a/src/kitemviews/kitemlistselectionmanager.cpp b/src/kitemviews/kitemlistselectionmanager.cpp --- a/src/kitemviews/kitemlistselectionmanager.cpp +++ b/src/kitemviews/kitemlistselectionmanager.cpp @@ -132,19 +132,19 @@ const int endIndex = index + count -1; switch (mode) { - case Select: + case SelectionMode::Select: for (int i = index; i <= endIndex; ++i) { m_selectedItems.insert(i); } break; - case Deselect: + case SelectionMode::Deselect: for (int i = index; i <= endIndex; ++i) { m_selectedItems.remove(i); } break; - case Toggle: + case SelectionMode::Toggle: for (int i = index; i <= endIndex; ++i) { if (m_selectedItems.contains(i)) { m_selectedItems.remove(i); @@ -284,20 +284,20 @@ const int previousCurrent = m_currentItem; // Update the current item - m_currentItem = indexAfterRangesRemoving(m_currentItem, itemRanges, DiscardRemovedIndex); + m_currentItem = indexAfterRangesRemoving(m_currentItem, itemRanges, RangesRemovingBehaviour::DiscardRemovedIndex); if (m_currentItem != previousCurrent) { emit currentChanged(m_currentItem, previousCurrent); if (m_currentItem < 0) { // Calling setCurrentItem() would trigger the selectionChanged signal, but we want to // emit it only once in this function -> change the current item manually and emit currentChanged - m_currentItem = indexAfterRangesRemoving(previousCurrent, itemRanges, AdjustRemovedIndex); + m_currentItem = indexAfterRangesRemoving(previousCurrent, itemRanges, RangesRemovingBehaviour::AdjustRemovedIndex); emit currentChanged(m_currentItem, -1); } } // Update the anchor item if (m_anchorItem >= 0) { - m_anchorItem = indexAfterRangesRemoving(m_anchorItem, itemRanges, DiscardRemovedIndex); + m_anchorItem = indexAfterRangesRemoving(m_anchorItem, itemRanges, RangesRemovingBehaviour::DiscardRemovedIndex); if (m_anchorItem < 0) { m_isAnchoredSelectionActive = false; } @@ -309,7 +309,7 @@ m_selectedItems.clear(); for (int oldIndex : previous) { - const int index = indexAfterRangesRemoving(oldIndex, itemRanges, DiscardRemovedIndex); + const int index = indexAfterRangesRemoving(oldIndex, itemRanges, RangesRemovingBehaviour::DiscardRemovedIndex); if (index >= 0) { m_selectedItems.insert(index); } @@ -384,7 +384,7 @@ const int firstIndexAfterRange = itemRange.index + itemRange.count; if (index < firstIndexAfterRange) { // The index is part of the removed range - if (behaviour == DiscardRemovedIndex) { + if (behaviour == RangesRemovingBehaviour::DiscardRemovedIndex) { return -1; } else { // Use the first item after the range as new index diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h --- a/src/kitemviews/kitemlistview.h +++ b/src/kitemviews/kitemlistview.h @@ -454,13 +454,13 @@ void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value); private: - enum LayoutAnimationHint + enum class LayoutAnimationHint { NoAnimation, Animation }; - enum SizeType + enum class SizeType { LayouterSize, ItemSize diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -78,7 +78,7 @@ m_supportsItemExpanding(false), m_editingRole(false), m_activeTransactions(0), - m_endTransactionAnimationHint(Animation), + m_endTransactionAnimationHint(LayoutAnimationHint::Animation), m_itemSize(), m_controller(nullptr), m_model(nullptr), @@ -167,7 +167,7 @@ // Don't check whether the m_layoutTimer is active: Changing the // scroll offset must always trigger a synchronous layout, otherwise // the smooth-scrolling might get jerky. - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); onScrollOffsetChanged(offset, previousOffset); } @@ -195,7 +195,7 @@ // Don't check whether the m_layoutTimer is active: Changing the // item offset must always trigger a synchronous layout, otherwise // the smooth-scrolling might get jerky. - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } qreal KItemListView::itemOffset() const @@ -253,7 +253,7 @@ } } - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } QList KItemListView::visibleRoles() const @@ -373,7 +373,7 @@ // Triggering a synchronous layout is fine from a performance point of view, // as with dynamic item sizes no moving animation must be done. m_layouter->setSize(newSize); - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } else { const bool animate = !changesItemGridLayout(newSize, m_layouter->itemSize(), @@ -389,7 +389,7 @@ } } else { m_layoutTimer->stop(); - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } } } @@ -563,7 +563,7 @@ if (m_activeTransactions == 0) { onTransactionEnd(); doLayout(m_endTransactionAnimationHint); - m_endTransactionAnimationHint = Animation; + m_endTransactionAnimationHint = LayoutAnimationHint::Animation; } } @@ -751,7 +751,7 @@ } m_sizeHintResolver->clearCache(); - doLayout(animate ? Animation : NoAnimation); + doLayout(animate ? LayoutAnimationHint::Animation : LayoutAnimationHint::NoAnimation); onItemSizeChanged(size, previousSize); } @@ -791,7 +791,7 @@ m_sizeHintResolver->clearCache(); m_layouter->markAsDirty(); - doLayout(animate ? Animation : NoAnimation); + doLayout(animate ? LayoutAnimationHint::Animation : LayoutAnimationHint::NoAnimation); if (m_itemSize.isEmpty()) { updatePreferredColumnWidths(); @@ -821,7 +821,7 @@ } - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); onScrollOrientationChanged(orientation, previousOrientation); emit scrollOrientationChanged(orientation, previousOrientation); @@ -1081,7 +1081,7 @@ } if (!hasMultipleRanges) { - doLayout(animateChangedItemCount(count) ? Animation : NoAnimation, index, count); + doLayout(animateChangedItemCount(count) ? LayoutAnimationHint::Animation : LayoutAnimationHint::NoAnimation, index, count); updateSiblingsInformation(); } } @@ -1091,7 +1091,7 @@ } if (hasMultipleRanges) { - m_endTransactionAnimationHint = NoAnimation; + m_endTransactionAnimationHint = LayoutAnimationHint::NoAnimation; endTransaction(); updateSiblingsInformation(); @@ -1170,7 +1170,7 @@ // be recycled (deleted) in KItemListView::slotAnimationFinished(). m_visibleItems.remove(i); widget->setIndex(-1); - m_animation->start(widget, KItemListViewAnimation::DeleteAnimation); + m_animation->start(widget, KItemListViewAnimation::AnimationType::Delete); } } @@ -1197,7 +1197,7 @@ // geometry update if necessary. const int activeTransactions = m_activeTransactions; m_activeTransactions = 0; - doLayout(animateChangedItemCount(count) ? Animation : NoAnimation, index, -count); + doLayout(animateChangedItemCount(count) ? LayoutAnimationHint::Animation : LayoutAnimationHint::NoAnimation, index, -count); m_activeTransactions = activeTransactions; updateSiblingsInformation(); } @@ -1208,7 +1208,7 @@ } if (hasMultipleRanges) { - m_endTransactionAnimationHint = NoAnimation; + m_endTransactionAnimationHint = LayoutAnimationHint::NoAnimation; endTransaction(); updateSiblingsInformation(); } @@ -1244,7 +1244,7 @@ } } - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); updateSiblingsInformation(); } @@ -1282,7 +1282,7 @@ // The sort-role has been changed which might result // in modified group headers updateVisibleGroupHeaders(); - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } QAccessibleTableModelChangeEvent ev(this, QAccessibleTableModelChangeEvent::DataChanged); @@ -1295,7 +1295,7 @@ void KItemListView::slotGroupsChanged() { updateVisibleGroupHeaders(); - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); updateSiblingsInformation(); } @@ -1325,16 +1325,16 @@ updateAlternateBackgrounds(); } updateSiblingsInformation(); - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) { Q_UNUSED(current); Q_UNUSED(previous); if (m_grouped) { updateVisibleGroupHeaders(); - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } } @@ -1344,7 +1344,7 @@ Q_UNUSED(previous); if (m_grouped) { updateVisibleGroupHeaders(); - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } } @@ -1354,7 +1354,7 @@ // 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) { + if (m_controller->selectionBehavior() != KItemListController::SelectionBehavior::SingleSelection) { KItemListWidget* previousWidget = m_visibleItems.value(previous, 0); if (previousWidget) { previousWidget->setCurrent(false); @@ -1391,7 +1391,7 @@ Q_ASSERT(itemListWidget); switch (type) { - case KItemListViewAnimation::DeleteAnimation: { + case KItemListViewAnimation::AnimationType::Delete: { // As we recycle the widget in this case it is important to assure that no // other animation has been started. This is a convention in KItemListView and // not a requirement defined by KItemListViewAnimation. @@ -1405,9 +1405,9 @@ break; } - case KItemListViewAnimation::CreateAnimation: - case KItemListViewAnimation::MovingAnimation: - case KItemListViewAnimation::ResizeAnimation: { + case KItemListViewAnimation::AnimationType::Create: + case KItemListViewAnimation::AnimationType::Moving: + case KItemListViewAnimation::AnimationType::Resize: { const int index = itemListWidget->index(); const bool invisible = (index < m_layouter->firstVisibleIndex()) || (index > m_layouter->lastVisibleIndex()); @@ -1424,7 +1424,7 @@ void KItemListView::slotLayoutTimerFinished() { m_layouter->setSize(geometry().size()); - doLayout(Animation); + doLayout(LayoutAnimationHint::Animation); } void KItemListView::slotRubberBandPosChanged() @@ -1457,7 +1457,7 @@ m_headerWidget->setAutomaticColumnResizing(false); applyColumnWidthsFromHeader(); - doLayout(NoAnimation); + doLayout(LayoutAnimationHint::NoAnimation); } void KItemListView::slotHeaderColumnMoved(const QByteArray& role, @@ -1655,10 +1655,10 @@ } if (m_activeTransactions > 0) { - if (hint == NoAnimation) { + if (hint == LayoutAnimationHint::NoAnimation) { // As soon as at least one property change should be done without animation, // the whole transaction will be marked as not animated. - m_endTransactionAnimationHint = NoAnimation; + m_endTransactionAnimationHint = LayoutAnimationHint::NoAnimation; } return; } @@ -1694,7 +1694,7 @@ // Assure that for each visible item a KItemListWidget is available. KItemListWidget // instances from invisible items are reused. If no reusable items are // found then new KItemListWidget instances get created. - const bool animate = (hint == Animation); + const bool animate = (hint == LayoutAnimationHint::Animation); for (int i = firstVisibleIndex; i <= lastVisibleIndex; ++i) { bool applyNewPos = true; bool wasHidden = false; @@ -1745,8 +1745,8 @@ } if (animate) { - if (m_animation->isStarted(widget, KItemListViewAnimation::MovingAnimation)) { - m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos); + if (m_animation->isStarted(widget, KItemListViewAnimation::AnimationType::Moving)) { + m_animation->start(widget, KItemListViewAnimation::AnimationType::Moving, newPos); applyNewPos = false; } @@ -1762,9 +1762,9 @@ // For performance reasons no animation is done when changedCount is equal // to all available items. if (changedCount < m_model->count()) { - m_animation->start(widget, KItemListViewAnimation::CreateAnimation); + m_animation->start(widget, KItemListViewAnimation::AnimationType::Create); } - } else if (!m_animation->isStarted(widget, KItemListViewAnimation::CreateAnimation)) { + } else if (!m_animation->isStarted(widget, KItemListViewAnimation::AnimationType::Create)) { // The item was already there before, so animate the moving of the position. // No moving animation is done if the item is animated by a create animation: This // prevents a "move animation mess" when inserting several ranges in parallel. @@ -1797,7 +1797,7 @@ // The height is dynamic, apply the new height without animation. widget->resize(widget->size().width(), itemBounds.height()); } - m_animation->start(widget, KItemListViewAnimation::ResizeAnimation, itemBounds.size()); + m_animation->start(widget, KItemListViewAnimation::AnimationType::Resize, itemBounds.size()); } else { widget->resize(itemBounds.size()); } @@ -1853,7 +1853,7 @@ if (invisible) { if (m_animation->isStarted(widget)) { - if (hint == NoAnimation) { + if (hint == LayoutAnimationHint::NoAnimation) { // Stopping the animation will call KItemListView::slotAnimationFinished() // and the widget will be recycled if necessary there. m_animation->stop(widget); @@ -1900,12 +1900,12 @@ } if (startMovingAnim) { - m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos); + m_animation->start(widget, KItemListViewAnimation::AnimationType::Moving, newPos); return true; } m_animation->stop(widget); - m_animation->start(widget, KItemListViewAnimation::CreateAnimation); + m_animation->start(widget, KItemListViewAnimation::AnimationType::Create); return false; } @@ -1992,8 +1992,8 @@ void KItemListView::setLayouterSize(const QSizeF& size, SizeType sizeType) { switch (sizeType) { - case LayouterSize: m_layouter->setSize(size); break; - case ItemSize: m_layouter->setItemSize(size); break; + case SizeType::LayouterSize: m_layouter->setSize(size); break; + case SizeType::ItemSize: m_layouter->setItemSize(size); break; default: break; } } @@ -2008,7 +2008,7 @@ // 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) { + if (m_controller->selectionBehavior() != KItemListController::SelectionBehavior::SingleSelection) { widget->setCurrent(index == selectionManager->currentItem()); } widget->setSelected(selectionManager->isSelected(index)); diff --git a/src/kitemviews/kitemlistviewaccessible.cpp b/src/kitemviews/kitemlistviewaccessible.cpp --- a/src/kitemviews/kitemlistviewaccessible.cpp +++ b/src/kitemviews/kitemlistviewaccessible.cpp @@ -344,7 +344,7 @@ state.focused = true; } - if (m_view->controller()->selectionBehavior() == KItemListController::MultiSelection) { + if (m_view->controller()->selectionBehavior() == KItemListController::SelectionBehavior::MultiSelection) { state.multiSelectable = true; } diff --git a/src/kitemviews/kstandarditemlistview.h b/src/kitemviews/kstandarditemlistview.h --- a/src/kitemviews/kstandarditemlistview.h +++ b/src/kitemviews/kstandarditemlistview.h @@ -45,11 +45,11 @@ Q_OBJECT public: - enum ItemLayout + enum class ItemLayout { - IconsLayout, - CompactLayout, - DetailsLayout + Icons, + Compact, + Details }; explicit KStandardItemListView(QGraphicsWidget* parent = nullptr); diff --git a/src/kitemviews/kstandarditemlistview.cpp b/src/kitemviews/kstandarditemlistview.cpp --- a/src/kitemviews/kstandarditemlistview.cpp +++ b/src/kitemviews/kstandarditemlistview.cpp @@ -25,7 +25,7 @@ KStandardItemListView::KStandardItemListView(QGraphicsWidget* parent) : KItemListView(parent), - m_itemLayout(DetailsLayout) + m_itemLayout(ItemLayout::Details) { setAcceptDrops(true); setScrollOrientation(Qt::Vertical); @@ -48,7 +48,7 @@ m_itemLayout = layout; setSupportsItemExpanding(itemLayoutSupportsItemExpanding(layout)); - setScrollOrientation(layout == CompactLayout ? Qt::Horizontal : Qt::Vertical); + setScrollOrientation(layout == ItemLayout::Compact ? Qt::Horizontal : Qt::Vertical); onItemLayoutChanged(layout, previous); @@ -76,9 +76,9 @@ 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; + case ItemLayout::Icons: standardItemListWidget->setLayout(KStandardItemListWidget::Layout::Icons); break; + case ItemLayout::Compact: standardItemListWidget->setLayout(KStandardItemListWidget::Layout::Compact); break; + case ItemLayout::Details: standardItemListWidget->setLayout(KStandardItemListWidget::Layout::Details); break; default: Q_ASSERT(false); break; } @@ -103,7 +103,7 @@ bool KStandardItemListView::itemLayoutSupportsItemExpanding(ItemLayout layout) const { - return layout == DetailsLayout; + return layout == ItemLayout::Details; } void KStandardItemListView::onItemLayoutChanged(ItemLayout current, ItemLayout previous) @@ -130,9 +130,9 @@ 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; + case ItemLayout::Icons: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_LargeIconSize), 2, 4, 8); break; + case ItemLayout::Compact: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_SmallIconSize), 2, 8, 0); break; + case ItemLayout::Details: applyDefaultStyleOption(style()->pixelMetric(QStyle::PM_SmallIconSize), 2, 0, 0); break; default: Q_ASSERT(false); break; } diff --git a/src/kitemviews/kstandarditemlistwidget.h b/src/kitemviews/kstandarditemlistwidget.h --- a/src/kitemviews/kstandarditemlistwidget.h +++ b/src/kitemviews/kstandarditemlistwidget.h @@ -88,11 +88,11 @@ Q_OBJECT public: - enum Layout + enum class Layout { - IconsLayout, - CompactLayout, - DetailsLayout + Icons, + Compact, + Details }; KStandardItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent); diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -56,15 +56,15 @@ void KStandardItemListWidgetInformant::calculateItemSizeHints(QVector& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const { switch (static_cast(view)->itemLayout()) { - case KStandardItemListWidget::IconsLayout: + case KStandardItemListView::ItemLayout::Icons: calculateIconsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); break; - case KStandardItemListWidget::CompactLayout: + case KStandardItemListView::ItemLayout::Compact: calculateCompactLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); break; - case KStandardItemListWidget::DetailsLayout: + case KStandardItemListView::ItemLayout::Details: calculateDetailsLayoutItemSizeHints(logicalHeightHints, logicalWidthHint, view); break; @@ -259,7 +259,7 @@ m_dirtyLayout(true), m_dirtyContent(true), m_dirtyContentRoles(), - m_layout(IconsLayout), + m_layout(Layout::Icons), m_pixmapPos(), m_pixmap(), m_scaledPixmapSize(), @@ -465,16 +465,16 @@ const_cast(this)->triggerCacheRefreshing(); switch (m_layout) { - case CompactLayout: { + case Layout::Compact: { QRectF rect = m_textRect; 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; } - case DetailsLayout: { + case Layout::Details: { QRectF rect = m_textRect; const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles.first()); rect.setTop(textInfo->pos.y()); @@ -501,11 +501,11 @@ const_cast(this)->triggerCacheRefreshing(); switch (m_layout) { - case IconsLayout: + case Layout::Icons: return m_textRect; - case CompactLayout: - case DetailsLayout: { + case Layout::Compact: + case Layout::Details: { const int padding = styleOption().padding; QRectF adjustedIconRect = iconRect().adjusted(-padding, -padding, padding, padding); return adjustedIconRect | m_textRect; @@ -566,7 +566,7 @@ QWidget* widget) { QPixmap pixmap = KItemListWidget::createDragPixmap(option, widget); - if (m_layout != DetailsLayout) { + if (m_layout != Layout::Details) { return pixmap; } @@ -943,7 +943,7 @@ // the remaining height when the alignment is vertical. const QSizeF widgetSize = size(); - const bool iconOnTop = (m_layout == IconsLayout); + const bool iconOnTop = (m_layout == Layout::Icons); const KItemListStyleOption& option = styleOption(); const qreal padding = option.padding; @@ -988,7 +988,7 @@ KIconEffect::semiTransparent(m_pixmap); } - if (m_layout == IconsLayout && isSelected()) { + if (m_layout == Layout::Icons && isSelected()) { const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color(); QImage image = m_pixmap.toImage(); KIconEffect::colorize(image, color, 0.8f); @@ -1006,7 +1006,7 @@ const TextInfo* textInfo = m_textInfo.value("text"); scaledIconSize = static_cast(textInfo->pos.y() - 2 * padding); } else { - const int textRowsCount = (m_layout == CompactLayout) ? visibleRoles().count() : 1; + const int textRowsCount = (m_layout == Layout::Compact) ? visibleRoles().count() : 1; const qreal requiredTextHeight = textRowsCount * m_customizedFontMetrics.height(); scaledIconSize = (requiredTextHeight < maxIconHeight) ? widgetSize.height() - 2 * padding : maxIconHeight; @@ -1053,12 +1053,12 @@ { QTextOption textOption; switch (m_layout) { - case IconsLayout: + case Layout::Icons: textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); textOption.setAlignment(Qt::AlignHCenter); break; - case CompactLayout: - case DetailsLayout: + case Layout::Compact: + case Layout::Details: textOption.setAlignment(Qt::AlignLeft); textOption.setWrapMode(QTextOption::NoWrap); break; @@ -1078,9 +1078,9 @@ } switch (m_layout) { - case IconsLayout: updateIconsLayoutTextCache(); break; - case CompactLayout: updateCompactLayoutTextCache(); break; - case DetailsLayout: updateDetailsLayoutTextCache(); break; + case Layout::Icons: updateIconsLayoutTextCache(); break; + case Layout::Compact: updateCompactLayoutTextCache(); break; + case Layout::Details: updateDetailsLayoutTextCache(); break; default: Q_ASSERT(false); break; } @@ -1091,7 +1091,7 @@ const KItemListStyleOption& option = styleOption(); QSizeF ratingSize = preferredRatingSize(option); - const qreal availableWidth = (m_layout == DetailsLayout) + const qreal availableWidth = (m_layout == Layout::Details) ? columnWidth("rating") - columnPadding(option) : size().width(); if (ratingSize.width() > availableWidth) { @@ -1355,7 +1355,7 @@ QColor c1; if (m_customTextColor.isValid()) { c1 = m_customTextColor; - } else if (isSelected() && m_layout != DetailsLayout) { + } else if (isSelected() && m_layout != Layout::Details) { c1 = styleOption().palette.highlightedText().color(); } else { c1 = styleOption().palette.text().color(); @@ -1429,7 +1429,7 @@ } QRectF rect(textInfo->pos, textInfo->staticText.size()); - if (m_layout == DetailsLayout) { + if (m_layout == Layout::Details) { rect.setWidth(columnWidth(role) - rect.x()); } diff --git a/src/kitemviews/private/kdirectorycontentscounter.cpp b/src/kitemviews/private/kdirectorycontentscounter.cpp --- a/src/kitemviews/private/kdirectorycontentscounter.cpp +++ b/src/kitemviews/private/kdirectorycontentscounter.cpp @@ -94,11 +94,11 @@ KDirectoryContentsCounterWorker::Options options; if (m_model->showHiddenFiles()) { - options |= KDirectoryContentsCounterWorker::CountHiddenFiles; + options |= KDirectoryContentsCounterWorker::Option::CountHiddenFiles; } if (m_model->showDirectoriesOnly()) { - options |= KDirectoryContentsCounterWorker::CountDirectoriesOnly; + options |= KDirectoryContentsCounterWorker::Option::CountDirectoriesOnly; } return KDirectoryContentsCounterWorker::subItemsCount(path, options); @@ -168,11 +168,11 @@ KDirectoryContentsCounterWorker::Options options; if (m_model->showHiddenFiles()) { - options |= KDirectoryContentsCounterWorker::CountHiddenFiles; + options |= KDirectoryContentsCounterWorker::Option::CountHiddenFiles; } if (m_model->showDirectoriesOnly()) { - options |= KDirectoryContentsCounterWorker::CountDirectoriesOnly; + options |= KDirectoryContentsCounterWorker::Option::CountDirectoriesOnly; } emit requestDirectoryContentsCount(path, options); diff --git a/src/kitemviews/private/kdirectorycontentscounterworker.h b/src/kitemviews/private/kdirectorycontentscounterworker.h --- a/src/kitemviews/private/kdirectorycontentscounterworker.h +++ b/src/kitemviews/private/kdirectorycontentscounterworker.h @@ -30,7 +30,7 @@ Q_OBJECT public: - enum Option { + enum class Option { NoOptions = 0x0, CountHiddenFiles = 0x1, CountDirectoriesOnly = 0x2 diff --git a/src/kitemviews/private/kdirectorycontentscounterworker.cpp b/src/kitemviews/private/kdirectorycontentscounterworker.cpp --- a/src/kitemviews/private/kdirectorycontentscounterworker.cpp +++ b/src/kitemviews/private/kdirectorycontentscounterworker.cpp @@ -36,8 +36,8 @@ int KDirectoryContentsCounterWorker::subItemsCount(const QString& path, Options options) { - const bool countHiddenFiles = options & CountHiddenFiles; - const bool countDirectoriesOnly = options & CountDirectoriesOnly; + const bool countHiddenFiles = options & Option::CountHiddenFiles; + const bool countDirectoriesOnly = options & Option::CountDirectoriesOnly; #ifdef Q_OS_WIN QDir dir(path); diff --git a/src/kitemviews/private/kitemlistheaderwidget.h b/src/kitemviews/private/kitemlistheaderwidget.h --- a/src/kitemviews/private/kitemlistheaderwidget.h +++ b/src/kitemviews/private/kitemlistheaderwidget.h @@ -146,11 +146,11 @@ qreal roleXPosition(const QByteArray& role) const; private: - enum RoleOperation + enum class RoleOperation { NoRoleOperation, - ResizeRoleOperation, - MoveRoleOperation + Resize, + Move }; bool m_automaticColumnResizing; diff --git a/src/kitemviews/private/kitemlistheaderwidget.cpp b/src/kitemviews/private/kitemlistheaderwidget.cpp --- a/src/kitemviews/private/kitemlistheaderwidget.cpp +++ b/src/kitemviews/private/kitemlistheaderwidget.cpp @@ -37,7 +37,7 @@ m_preferredColumnWidths(), m_hoveredRoleIndex(-1), m_pressedRoleIndex(-1), - m_roleOperation(NoRoleOperation), + m_roleOperation(RoleOperation::NoRoleOperation), m_pressedMousePos(), m_movingRole() { @@ -179,7 +179,7 @@ } if (!m_movingRole.pixmap.isNull()) { - Q_ASSERT(m_roleOperation == MoveRoleOperation); + Q_ASSERT(m_roleOperation == RoleOperation::Move); painter->drawPixmap(m_movingRole.x, 0, m_movingRole.pixmap); } } @@ -190,7 +190,7 @@ updatePressedRoleIndex(event->pos()); m_pressedMousePos = event->pos(); m_roleOperation = isAboveRoleGrip(m_pressedMousePos, m_pressedRoleIndex) ? - ResizeRoleOperation : NoRoleOperation; + RoleOperation::Resize : RoleOperation::NoRoleOperation; event->accept(); } else { event->ignore(); @@ -206,7 +206,7 @@ } switch (m_roleOperation) { - case NoRoleOperation: { + case RoleOperation::NoRoleOperation: { // Only a click has been done and no moving or resizing has been started const QByteArray sortRole = m_model->sortRole(); const int sortRoleIndex = m_columns.indexOf(sortRole); @@ -232,14 +232,14 @@ break; } - case ResizeRoleOperation: { + case RoleOperation::Resize: { const QByteArray pressedRole = m_columns[m_pressedRoleIndex]; const qreal currentWidth = m_columnWidths.value(pressedRole); emit columnWidthChangeFinished(pressedRole, currentWidth); break; } - case MoveRoleOperation: + case RoleOperation::Move: m_movingRole.pixmap = QPixmap(); m_movingRole.x = 0; m_movingRole.xDec = 0; @@ -251,7 +251,7 @@ } m_pressedRoleIndex = -1; - m_roleOperation = NoRoleOperation; + m_roleOperation = RoleOperation::NoRoleOperation; update(); QApplication::restoreOverrideCursor(); @@ -262,11 +262,11 @@ QGraphicsWidget::mouseMoveEvent(event); switch (m_roleOperation) { - case NoRoleOperation: + case RoleOperation::NoRoleOperation: if ((event->pos() - m_pressedMousePos).manhattanLength() >= QApplication::startDragDistance()) { // A role gets dragged by the user. Create a pixmap of the role that will get // synchronized on each furter mouse-move-event with the mouse-position. - m_roleOperation = MoveRoleOperation; + m_roleOperation = RoleOperation::Move; const int roleIndex = roleIndexAt(m_pressedMousePos); m_movingRole.index = roleIndex; if (roleIndex == 0) { @@ -290,7 +290,7 @@ } break; - case ResizeRoleOperation: { + case RoleOperation::Resize: { const QByteArray pressedRole = m_columns[m_pressedRoleIndex]; qreal previousWidth = m_columnWidths.value(pressedRole); @@ -305,7 +305,7 @@ break; } - case MoveRoleOperation: { + case RoleOperation::Move: { // TODO: It should be configurable whether moving the first role is allowed. // In the context of Dolphin this is not required, however this should be // changed if KItemViews are used in a more generic way. diff --git a/src/kitemviews/private/kitemlistviewanimation.h b/src/kitemviews/private/kitemlistviewanimation.h --- a/src/kitemviews/private/kitemlistviewanimation.h +++ b/src/kitemviews/private/kitemlistviewanimation.h @@ -41,11 +41,11 @@ Q_OBJECT public: - enum AnimationType { - MovingAnimation, - CreateAnimation, - DeleteAnimation, - ResizeAnimation + enum class AnimationType { + Moving, + Create, + Delete, + Resize }; explicit KItemListViewAnimation(QObject* parent = nullptr); diff --git a/src/kitemviews/private/kitemlistviewanimation.cpp b/src/kitemviews/private/kitemlistviewanimation.cpp --- a/src/kitemviews/private/kitemlistviewanimation.cpp +++ b/src/kitemviews/private/kitemlistviewanimation.cpp @@ -59,8 +59,8 @@ // animated QGraphicsWidgets get adjusted. An exception is made // for the delete animation that should just fade away on the // existing position. - for (int type = 0; type < AnimationTypeCount; ++type) { - if (type == DeleteAnimation) { + for (int type = static_cast(AnimationType::Moving); type <= static_cast(AnimationType::Resize); ++type) { + if (AnimationType(type) == AnimationType::Delete) { continue; } @@ -78,7 +78,7 @@ currentPos.rx() += diff; } - if (type == MovingAnimation) { + if (AnimationType(type) == AnimationType::Moving) { // Stop the animation, calculate the moved start- and end-value // and restart the animation for the remaining duration. const int remainingDuration = propertyAnim->duration() @@ -120,7 +120,7 @@ const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animate) ? 200 : 1; switch (type) { - case MovingAnimation: { + case AnimationType::Moving: { const QPointF newPos = endValue.toPointF(); if (newPos == widget->pos()) { return; @@ -132,25 +132,25 @@ break; } - case CreateAnimation: { + case AnimationType::Create: { propertyAnim = new QPropertyAnimation(widget, "opacity"); propertyAnim->setEasingCurve(QEasingCurve::InQuart); propertyAnim->setDuration(animationDuration); propertyAnim->setStartValue(0.0); propertyAnim->setEndValue(1.0); break; } - case DeleteAnimation: { + case AnimationType::Delete: { propertyAnim = new QPropertyAnimation(widget, "opacity"); propertyAnim->setEasingCurve(QEasingCurve::OutQuart); propertyAnim->setDuration(animationDuration); propertyAnim->setStartValue(1.0); propertyAnim->setEndValue(0.0); break; } - case ResizeAnimation: { + case AnimationType::Resize: { const QSizeF newSize = endValue.toSizeF(); if (newSize == widget->size()) { return; @@ -168,26 +168,26 @@ Q_ASSERT(propertyAnim); connect(propertyAnim, &QPropertyAnimation::finished, this, &KItemListViewAnimation::slotFinished); - m_animation[type].insert(widget, propertyAnim); + m_animation[static_cast(type)].insert(widget, propertyAnim); propertyAnim->start(); } void KItemListViewAnimation::stop(QGraphicsWidget* widget, AnimationType type) { - QPropertyAnimation* propertyAnim = m_animation[type].value(widget); + QPropertyAnimation* propertyAnim = m_animation[static_cast(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; + case AnimationType::Moving: break; + case AnimationType::Create: widget->setOpacity(1.0); break; + case AnimationType::Delete: widget->setOpacity(0.0); break; + case AnimationType::Resize: break; default: break; } - m_animation[type].remove(widget); + m_animation[static_cast(type)].remove(widget); delete propertyAnim; emit finished(widget, type); @@ -203,7 +203,7 @@ bool KItemListViewAnimation::isStarted(QGraphicsWidget *widget, AnimationType type) const { - return m_animation[type].value(widget); + return m_animation[static_cast(type)].value(widget); } bool KItemListViewAnimation::isStarted(QGraphicsWidget* widget) const diff --git a/src/kitemviews/private/kpixmapmodifier.cpp b/src/kitemviews/private/kpixmapmodifier.cpp --- a/src/kitemviews/private/kpixmapmodifier.cpp +++ b/src/kitemviews/private/kpixmapmodifier.cpp @@ -264,7 +264,7 @@ public: enum { LeftMargin = 3, TopMargin = 2, RightMargin = 3, BottomMargin = 4 }; - enum Tile { TopLeftCorner = 0, TopSide, TopRightCorner, LeftSide, + enum class Tile { TopLeftCorner = 0, TopSide, TopRightCorner, LeftSide, RightSide, BottomLeftCorner, BottomSide, BottomRightCorner, NumTiles }; @@ -281,39 +281,39 @@ shadowBlur(image, 3, Qt::black); 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); + m_tiles[static_cast(Tile::TopLeftCorner)] = pixmap.copy(0, 0, 8, 8); + m_tiles[static_cast(Tile::TopSide)] = pixmap.copy(8, 0, 8, 8); + m_tiles[static_cast(Tile::TopRightCorner)] = pixmap.copy(16, 0, 8, 8); + m_tiles[static_cast(Tile::LeftSide)] = pixmap.copy(0, 8, 8, 8); + m_tiles[static_cast(Tile::RightSide)] = pixmap.copy(16, 8, 8, 8); + m_tiles[static_cast(Tile::BottomLeftCorner)] = pixmap.copy(0, 16, 8, 8); + m_tiles[static_cast(Tile::BottomSide)] = pixmap.copy(8, 16, 8, 8); + m_tiles[static_cast(Tile::BottomRightCorner)] = pixmap.copy(16, 16, 8, 8); } void paint(QPainter* p, const QRect& r) { - p->drawPixmap(r.topLeft(), m_tiles[TopLeftCorner]); + p->drawPixmap(r.topLeft(), m_tiles[static_cast(Tile::TopLeftCorner)]); if (r.width() - 16 > 0) { - p->drawTiledPixmap(r.x() + 8, r.y(), r.width() - 16, 8, m_tiles[TopSide]); + p->drawTiledPixmap(r.x() + 8, r.y(), r.width() - 16, 8, m_tiles[static_cast(Tile::TopSide)]); } - p->drawPixmap(r.right() - 8 + 1, r.y(), m_tiles[TopRightCorner]); + p->drawPixmap(r.right() - 8 + 1, r.y(), m_tiles[static_cast(Tile::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->drawTiledPixmap(r.x(), r.y() + 8, 8, r.height() - 16, m_tiles[static_cast(Tile::LeftSide)]); + p->drawTiledPixmap(r.right() - 8 + 1, r.y() + 8, 8, r.height() - 16, m_tiles[static_cast(Tile::RightSide)]); } - p->drawPixmap(r.x(), r.bottom() - 8 + 1, m_tiles[BottomLeftCorner]); + p->drawPixmap(r.x(), r.bottom() - 8 + 1, m_tiles[static_cast(Tile::BottomLeftCorner)]); if (r.width() - 16 > 0) { - p->drawTiledPixmap(r.x() + 8, r.bottom() - 8 + 1, r.width() - 16, 8, m_tiles[BottomSide]); + p->drawTiledPixmap(r.x() + 8, r.bottom() - 8 + 1, r.width() - 16, 8, m_tiles[static_cast(Tile::BottomSide)]); } - p->drawPixmap(r.right() - 8 + 1, r.bottom() - 8 + 1, m_tiles[BottomRightCorner]); + p->drawPixmap(r.right() - 8 + 1, r.bottom() - 8 + 1, m_tiles[static_cast(Tile::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[static_cast(Tile::NumTiles)]; }; } diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h --- a/src/panels/folders/folderspanel.h +++ b/src/panels/folders/folderspanel.h @@ -88,7 +88,7 @@ /** * Indicate if it is allowed to leave current location. */ - enum NavigationBehaviour { + enum class NavigationBehaviour { StayWhereYouAre, ///< Don't leave current location. AllowJumpHome ///< Go Home only when context menu option got checked. }; @@ -98,7 +98,7 @@ * @param url URL of the leaf directory that should get expanded. * @param navigationBehaviour Navigation behaviour \see NavigationBehaviour */ - void loadTree(const QUrl& url, NavigationBehaviour navigationBehaviour = StayWhereYouAre); + void loadTree(const QUrl& url, NavigationBehaviour navigationBehaviour = NavigationBehaviour::StayWhereYouAre); void reloadTree(); diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -137,7 +137,7 @@ void FoldersPanel::reloadTree() { if (m_controller) { - loadTree(url(), AllowJumpHome); + loadTree(url(), NavigationBehaviour::AllowJumpHome); } } @@ -172,9 +172,11 @@ connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &FoldersPanel::slotLoadingCompleted, Qt::QueuedConnection); m_controller = new KItemListController(m_model, view, this); - m_controller->setSelectionBehavior(KItemListController::SingleSelection); - m_controller->setAutoActivationBehavior(KItemListController::ExpansionOnly); - m_controller->setMouseDoubleClickAction(KItemListController::ActivateAndExpandItem); + m_controller->setSelectionBehavior(KItemListController::SelectionBehavior::SingleSelection + + ); + m_controller->setAutoActivationBehavior(KItemListController::AutoActivationBehavior::ExpansionOnly); + m_controller->setMouseDoubleClickAction(KItemListController::MouseDoubleClickAction::ActivateAndExpandItem); m_controller->setAutoActivationDelay(750); m_controller->setSingleClickActivationEnforced(true); @@ -335,7 +337,7 @@ // Use the root directory as base for local URLs (#150941) baseUrl = QUrl::fromLocalFile(QDir::rootPath()); } - } else if (FoldersPanelSettings::limitFoldersPanelToHome() && navigationBehaviour == AllowJumpHome) { + } else if (FoldersPanelSettings::limitFoldersPanelToHome() && navigationBehaviour == NavigationBehaviour::AllowJumpHome) { baseUrl = Dolphin::homeUrl(); jumpHome = true; } else { diff --git a/src/panels/information/pixmapviewer.h b/src/panels/information/pixmapviewer.h --- a/src/panels/information/pixmapviewer.h +++ b/src/panels/information/pixmapviewer.h @@ -38,29 +38,29 @@ Q_OBJECT public: - enum Transition + enum class Transition { /** No transition is done when the pixmap is changed. */ NoTransition, /** * The old pixmap is replaced by the new pixmap and the size is * adjusted smoothly to the size of the new pixmap. */ - DefaultTransition, + Default, /** * If the old pixmap and the new pixmap have the same content, but * a different size it is recommended to use Transition::SizeTransition * instead of Transition::DefaultTransition. In this case it is assured * that the larger pixmap is used for downscaling, which leads * to an improved scaling output. */ - SizeTransition + Size }; explicit PixmapViewer(QWidget* parent, - Transition transition = DefaultTransition); + Transition transition = Transition::Default); ~PixmapViewer() override; void setPixmap(const QPixmap& pixmap); diff --git a/src/panels/information/pixmapviewer.cpp b/src/panels/information/pixmapviewer.cpp --- a/src/panels/information/pixmapviewer.cpp +++ b/src/panels/information/pixmapviewer.cpp @@ -37,7 +37,7 @@ m_animation.setDuration(150); m_animation.setCurveShape(QTimeLine::LinearCurve); - if (m_transition != NoTransition) { + if (m_transition != Transition::NoTransition) { connect(&m_animation, &QTimeLine::valueChanged, this, static_cast(&PixmapViewer::update)); connect(&m_animation, &QTimeLine::finished, this, &PixmapViewer::checkPendingPixmaps); } @@ -53,7 +53,7 @@ return; } - if ((m_transition != NoTransition) && (m_animation.state() == QTimeLine::Running)) { + if ((m_transition != Transition::NoTransition) && (m_animation.state() == QTimeLine::Running)) { m_pendingPixmaps.enqueue(pixmap); if (m_pendingPixmaps.count() > 5) { // don't queue more than 5 pixmaps @@ -66,7 +66,7 @@ m_pixmap = pixmap; update(); - const bool animate = (m_transition != NoTransition) && + const bool animate = (m_transition != Transition::NoTransition) && (m_pixmap.size() != m_oldPixmap.size()); if (animate) { m_animation.start(); @@ -90,12 +90,12 @@ QPainter painter(this); - if (m_transition != NoTransition) { + if (m_transition != Transition::NoTransition) { const float value = m_animation.currentValue(); const int scaledWidth = static_cast((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value)); const int scaledHeight = static_cast((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value)); - const bool useOldPixmap = (m_transition == SizeTransition) && + const bool useOldPixmap = (m_transition == Transition::Size) && (m_oldPixmap.width() > m_pixmap.width()); const QPixmap& largePixmap = useOldPixmap ? m_oldPixmap : m_pixmap; if (!largePixmap.isNull()) { diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -463,23 +463,23 @@ if (!props.exist()) { const QString path = itemUrl.path(); if (path == QLatin1String("/documents")) { - props.setViewMode(DolphinView::DetailsView); + props.setViewMode(DolphinView::Mode::DetailsView); props.setPreviewsShown(false); props.setVisibleRoles({"text", "path"}); } else if (path == QLatin1String("/images")) { - props.setViewMode(DolphinView::IconsView); + props.setViewMode(DolphinView::Mode::IconsView); props.setPreviewsShown(true); props.setVisibleRoles({"text", "imageSize"}); } else if (path == QLatin1String("/audio")) { - props.setViewMode(DolphinView::DetailsView); + props.setViewMode(DolphinView::Mode::DetailsView); props.setPreviewsShown(false); props.setVisibleRoles({"text", "artist", "album"}); } else if (path == QLatin1String("/videos")) { - props.setViewMode(DolphinView::IconsView); + props.setViewMode(DolphinView::Mode::IconsView); props.setPreviewsShown(true); props.setVisibleRoles({"text"}); } else if (itemUrl.scheme() == QLatin1String("timeline")) { - props.setViewMode(DolphinView::DetailsView); + props.setViewMode(DolphinView::Mode::DetailsView); props.setVisibleRoles({"text", "modificationtime"}); } props.save(); diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -127,7 +127,7 @@ m_view->setGroupHeaderCreator(new KItemListGroupHeaderCreator()); m_controller = new KItemListController(m_model, m_view, this); - m_controller->setSelectionBehavior(KItemListController::SingleSelection); + m_controller->setSelectionBehavior(KItemListController::SelectionBehavior::SingleSelection); m_controller->setSingleClickActivationEnforced(true); readSettings(); diff --git a/src/settings/general/previewssettingspage.cpp b/src/settings/general/previewssettingspage.cpp --- a/src/settings/general/previewssettingspage.cpp +++ b/src/settings/general/previewssettingspage.cpp @@ -144,7 +144,7 @@ { const QAbstractItemModel* model = index.model(); const QString pluginName = model->data(index).toString(); - const QString desktopEntryName = model->data(index, ServiceModel::DesktopEntryNameRole).toString(); + const QString desktopEntryName = model->data(index, static_cast(ServiceModel::Role::DesktopEntryName)).toString(); ConfigurePreviewPluginDialog* dialog = new ConfigurePreviewPluginDialog(pluginName, desktopEntryName, this); dialog->setAttribute(Qt::WA_DeleteOnClose); @@ -163,9 +163,9 @@ model->insertRow(0); const QModelIndex index = model->index(0, 0); model->setData(index, show, Qt::CheckStateRole); - model->setData(index, configurable, ServiceModel::ConfigurableRole); + model->setData(index, configurable, static_cast(ServiceModel::Role::Configurable)); model->setData(index, service->name(), Qt::DisplayRole); - model->setData(index, service->desktopEntryName(), ServiceModel::DesktopEntryNameRole); + model->setData(index, service->desktopEntryName(), static_cast(ServiceModel::Role::DesktopEntryName)); } model->sort(Qt::DisplayRole); diff --git a/src/settings/kcm/kcmdolphinviewmodes.cpp b/src/settings/kcm/kcmdolphinviewmodes.cpp --- a/src/settings/kcm/kcmdolphinviewmodes.cpp +++ b/src/settings/kcm/kcmdolphinviewmodes.cpp @@ -48,17 +48,17 @@ QTabWidget* tabWidget = new QTabWidget(this); // Initialize 'Icons' tab - ViewSettingsTab* iconsTab = new ViewSettingsTab(ViewSettingsTab::IconsMode, tabWidget); + ViewSettingsTab* iconsTab = new ViewSettingsTab(ViewSettingsTab::Mode::Icons, tabWidget); tabWidget->addTab(iconsTab, QIcon::fromTheme(QStringLiteral("view-list-icons")), i18nc("@title:tab", "Icons")); connect(iconsTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged); // Initialize 'Compact' tab - ViewSettingsTab* compactTab = new ViewSettingsTab(ViewSettingsTab::CompactMode, tabWidget); + ViewSettingsTab* compactTab = new ViewSettingsTab(ViewSettingsTab::Mode::Compact, tabWidget); tabWidget->addTab(compactTab, QIcon::fromTheme(QStringLiteral("view-list-details")), i18nc("@title:tab", "Compact")); connect(compactTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged); // Initialize 'Details' tab - ViewSettingsTab* detailsTab = new ViewSettingsTab(ViewSettingsTab::DetailsMode, tabWidget); + ViewSettingsTab* detailsTab = new ViewSettingsTab(ViewSettingsTab::Mode::Details, tabWidget); tabWidget->addTab(detailsTab, QIcon::fromTheme(QStringLiteral("view-list-tree")), i18nc("@title:tab", "Details")); connect(detailsTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged); diff --git a/src/settings/serviceitemdelegate.cpp b/src/settings/serviceitemdelegate.cpp --- a/src/settings/serviceitemdelegate.cpp +++ b/src/settings/serviceitemdelegate.cpp @@ -98,7 +98,7 @@ } checkBox->setChecked(model->data(index, Qt::CheckStateRole).toBool()); - const bool configurable = model->data(index, ServiceModel::ConfigurableRole).toBool(); + const bool configurable = model->data(index, static_cast(ServiceModel::Role::Configurable)).toBool(); int checkBoxWidth = option.rect.width(); if (configurable) { diff --git a/src/settings/servicemodel.h b/src/settings/servicemodel.h --- a/src/settings/servicemodel.h +++ b/src/settings/servicemodel.h @@ -38,10 +38,10 @@ Q_OBJECT public: - enum Role + enum class Role { - DesktopEntryNameRole = Qt::UserRole, - ConfigurableRole + DesktopEntryName = Qt::UserRole, + Configurable }; explicit ServiceModel(QObject* parent = nullptr); diff --git a/src/settings/servicemodel.cpp b/src/settings/servicemodel.cpp --- a/src/settings/servicemodel.cpp +++ b/src/settings/servicemodel.cpp @@ -62,16 +62,16 @@ case Qt::CheckStateRole: m_items[row].checked = value.toBool(); break; - case ConfigurableRole: + case static_cast(Role::Configurable): m_items[row].configurable = value.toBool(); break; case Qt::DecorationRole: m_items[row].icon = value.toString(); break; case Qt::DisplayRole: m_items[row].text = value.toString(); break; - case DesktopEntryNameRole: + case static_cast(Role::DesktopEntryName): m_items[row].desktopEntryName = value.toString(); break; default: @@ -87,11 +87,11 @@ const int row = index.row(); if (row < rowCount()) { switch (role) { - case ConfigurableRole: return m_items[row].configurable; - case Qt::CheckStateRole: return m_items[row].checked; - case Qt::DecorationRole: return m_items[row].icon; - case Qt::DisplayRole: return m_items[row].text; - case DesktopEntryNameRole: return m_items[row].desktopEntryName; + case static_cast(Role::Configurable): return m_items[row].configurable; + case Qt::CheckStateRole: return m_items[row].checked; + case Qt::DecorationRole: return m_items[row].icon; + case Qt::DisplayRole: return m_items[row].text; + case static_cast(Role::DesktopEntryName): return m_items[row].desktopEntryName; default: break; } } diff --git a/src/settings/services/servicessettingspage.cpp b/src/settings/services/servicessettingspage.cpp --- a/src/settings/services/servicessettingspage.cpp +++ b/src/settings/services/servicessettingspage.cpp @@ -112,7 +112,7 @@ const QAbstractItemModel* model = m_listView->model(); for (int i = 0; i < model->rowCount(); ++i) { const QModelIndex index = model->index(i, 0); - const QString service = model->data(index, ServiceModel::DesktopEntryNameRole).toString(); + const QString service = model->data(index, static_cast(ServiceModel::Role::DesktopEntryName)).toString(); const bool checked = model->data(index, Qt::CheckStateRole).toBool(); if (service.startsWith(VersionControlServicePrefix)) { @@ -151,7 +151,7 @@ QAbstractItemModel* model = m_listView->model(); for (int i = 0; i < model->rowCount(); ++i) { const QModelIndex index = model->index(i, 0); - const QString service = model->data(index, ServiceModel::DesktopEntryNameRole).toString(); + const QString service = model->data(index, static_cast(ServiceModel::Role::DesktopEntryName)).toString(); const bool checked = !service.startsWith(VersionControlServicePrefix) && service != QLatin1String(DeleteService) @@ -266,7 +266,7 @@ { for (int i = 0; i < m_serviceModel->rowCount(); ++i) { const QModelIndex index = m_serviceModel->index(i, 0); - if (m_serviceModel->data(index, ServiceModel::DesktopEntryNameRole).toString() == service) { + if (m_serviceModel->data(index, static_cast(ServiceModel::Role::DesktopEntryName)).toString() == service) { return true; } } @@ -283,7 +283,7 @@ const QModelIndex index = m_serviceModel->index(0, 0); m_serviceModel->setData(index, icon, Qt::DecorationRole); m_serviceModel->setData(index, text, Qt::DisplayRole); - m_serviceModel->setData(index, value, ServiceModel::DesktopEntryNameRole); + m_serviceModel->setData(index, value, static_cast(ServiceModel::Role::DesktopEntryName)); m_serviceModel->setData(index, checked, Qt::CheckStateRole); } diff --git a/src/settings/viewmodes/dolphinfontrequester.h b/src/settings/viewmodes/dolphinfontrequester.h --- a/src/settings/viewmodes/dolphinfontrequester.h +++ b/src/settings/viewmodes/dolphinfontrequester.h @@ -34,7 +34,7 @@ Q_OBJECT public: - enum Mode + enum class Mode { SystemFont = 0, CustomFont = 1 diff --git a/src/settings/viewmodes/dolphinfontrequester.cpp b/src/settings/viewmodes/dolphinfontrequester.cpp --- a/src/settings/viewmodes/dolphinfontrequester.cpp +++ b/src/settings/viewmodes/dolphinfontrequester.cpp @@ -31,7 +31,7 @@ QWidget(parent), m_modeCombo(nullptr), m_chooseFontButton(nullptr), - m_mode(SystemFont), + m_mode(Mode::SystemFont), m_customFont() { QHBoxLayout* topLayout = new QHBoxLayout(this); @@ -60,8 +60,8 @@ void DolphinFontRequester::setMode(Mode mode) { m_mode = mode; - m_modeCombo->setCurrentIndex(m_mode); - m_chooseFontButton->setEnabled(m_mode == CustomFont); + m_modeCombo->setCurrentIndex(static_cast(m_mode)); + m_chooseFontButton->setEnabled(m_mode == Mode::CustomFont); } DolphinFontRequester::Mode DolphinFontRequester::mode() const @@ -71,7 +71,7 @@ QFont DolphinFontRequester::currentFont() const { - return (m_mode == CustomFont) ? m_customFont : QFontDatabase::systemFont(QFontDatabase::GeneralFont); + return (m_mode == Mode::CustomFont) ? m_customFont : QFontDatabase::systemFont(QFontDatabase::GeneralFont); } void DolphinFontRequester::setCustomFont(const QFont& font) @@ -97,7 +97,7 @@ void DolphinFontRequester::changeMode(int index) { - setMode((index == CustomFont) ? CustomFont : SystemFont); + setMode((Mode(index) == Mode::CustomFont) ? Mode::CustomFont : Mode::SystemFont); emit changed(); } diff --git a/src/settings/viewmodes/viewmodesettings.h b/src/settings/viewmodes/viewmodesettings.h --- a/src/settings/viewmodes/viewmodesettings.h +++ b/src/settings/viewmodes/viewmodesettings.h @@ -29,11 +29,11 @@ class ViewModeSettings { public: - enum ViewMode + enum class ViewMode { - IconsMode, - CompactMode, - DetailsMode + Icons, + Compact, + Details }; explicit ViewModeSettings(ViewMode mode); diff --git a/src/settings/viewmodes/viewmodesettings.cpp b/src/settings/viewmodes/viewmodesettings.cpp --- a/src/settings/viewmodes/viewmodesettings.cpp +++ b/src/settings/viewmodes/viewmodesettings.cpp @@ -25,18 +25,18 @@ #define VIEWMODESETTINGS_SET_VALUE(mode, setValue, value) \ switch (mode) { \ - case ViewModeSettings::IconsMode: IconsModeSettings::setValue(value); break; \ - case ViewModeSettings::CompactMode: CompactModeSettings::setValue(value); break; \ - case ViewModeSettings::DetailsMode: DetailsModeSettings::setValue(value); break; \ + case ViewModeSettings::ViewMode::Icons: IconsModeSettings::setValue(value); break; \ + case ViewModeSettings::ViewMode::Compact: CompactModeSettings::setValue(value); break; \ + case ViewModeSettings::ViewMode::Details: DetailsModeSettings::setValue(value); break; \ default: Q_ASSERT(false); break; \ } #define VIEWMODESETTINGS_RETURN_VALUE(mode, getValue, type) \ type value; \ switch (m_mode) { \ - case IconsMode: value = IconsModeSettings::getValue(); break; \ - case CompactMode: value = CompactModeSettings::getValue(); break; \ - case DetailsMode: value = DetailsModeSettings::getValue(); break; \ + case ViewMode::Icons: value = IconsModeSettings::getValue(); break; \ + case ViewMode::Compact: value = CompactModeSettings::getValue(); break; \ + case ViewMode::Details: value = DetailsModeSettings::getValue(); break; \ default: value = IconsModeSettings::getValue(); \ Q_ASSERT(false); \ break; \ @@ -125,19 +125,19 @@ void ViewModeSettings::readConfig() { switch (m_mode) { - case ViewModeSettings::IconsMode: IconsModeSettings::self()->load(); break; - case ViewModeSettings::CompactMode: CompactModeSettings::self()->load(); break; - case ViewModeSettings::DetailsMode: DetailsModeSettings::self()->load(); break; + case ViewModeSettings::ViewMode::Icons: IconsModeSettings::self()->load(); break; + case ViewModeSettings::ViewMode::Compact: CompactModeSettings::self()->load(); break; + case ViewModeSettings::ViewMode::Details: DetailsModeSettings::self()->load(); break; default: Q_ASSERT(false); break; } } void ViewModeSettings::save() { switch (m_mode) { - case ViewModeSettings::IconsMode: IconsModeSettings::self()->save(); break; - case ViewModeSettings::CompactMode: CompactModeSettings::self()->save(); break; - case ViewModeSettings::DetailsMode: DetailsModeSettings::self()->save(); break; + case ViewModeSettings::ViewMode::Icons: IconsModeSettings::self()->save(); break; + case ViewModeSettings::ViewMode::Compact: CompactModeSettings::self()->save(); break; + case ViewModeSettings::ViewMode::Details: DetailsModeSettings::self()->save(); break; default: Q_ASSERT(false); break; } } diff --git a/src/settings/viewmodes/viewsettingspage.cpp b/src/settings/viewmodes/viewsettingspage.cpp --- a/src/settings/viewmodes/viewsettingspage.cpp +++ b/src/settings/viewmodes/viewsettingspage.cpp @@ -38,17 +38,17 @@ QTabWidget* tabWidget = new QTabWidget(this); // Initialize 'Icons' tab - ViewSettingsTab* iconsTab = new ViewSettingsTab(ViewSettingsTab::IconsMode, tabWidget); + ViewSettingsTab* iconsTab = new ViewSettingsTab(ViewSettingsTab::Mode::Icons, tabWidget); tabWidget->addTab(iconsTab, QIcon::fromTheme(QStringLiteral("view-list-icons")), i18nc("@title:tab", "Icons")); connect(iconsTab, &ViewSettingsTab::changed, this, &ViewSettingsPage::changed); // Initialize 'Compact' tab - ViewSettingsTab* compactTab = new ViewSettingsTab(ViewSettingsTab::CompactMode, tabWidget); + ViewSettingsTab* compactTab = new ViewSettingsTab(ViewSettingsTab::Mode::Compact, tabWidget); tabWidget->addTab(compactTab, QIcon::fromTheme(QStringLiteral("view-list-details")), i18nc("@title:tab", "Compact")); connect(compactTab, &ViewSettingsTab::changed, this, &ViewSettingsPage::changed); // Initialize 'Details' tab - ViewSettingsTab* detailsTab = new ViewSettingsTab(ViewSettingsTab::DetailsMode, tabWidget); + ViewSettingsTab* detailsTab = new ViewSettingsTab(ViewSettingsTab::Mode::Details, tabWidget); tabWidget->addTab(detailsTab, QIcon::fromTheme(QStringLiteral("view-list-tree")), i18nc("@title:tab", "Details")); connect(detailsTab, &ViewSettingsTab::changed, this, &ViewSettingsPage::changed); diff --git a/src/settings/viewmodes/viewsettingstab.h b/src/settings/viewmodes/viewsettingstab.h --- a/src/settings/viewmodes/viewsettingstab.h +++ b/src/settings/viewmodes/viewsettingstab.h @@ -36,11 +36,11 @@ Q_OBJECT public: - enum Mode + enum class Mode { - IconsMode, - CompactMode, - DetailsMode + Icons, + Compact, + Details }; explicit ViewSettingsTab(Mode mode, QWidget* parent = nullptr); diff --git a/src/settings/viewmodes/viewsettingstab.cpp b/src/settings/viewmodes/viewsettingstab.cpp --- a/src/settings/viewmodes/viewsettingstab.cpp +++ b/src/settings/viewmodes/viewsettingstab.cpp @@ -89,7 +89,7 @@ textGroupLayout->addWidget(m_fontRequester, 0, 1); switch (m_mode) { - case IconsMode: { + case Mode::Icons: { QLabel* widthLabel = new QLabel(i18nc("@label:listbox", "Width:"), textGroup); m_widthBox = new KComboBox(textGroup); m_widthBox->addItem(i18nc("@item:inlistbox Text width", "Small")); @@ -112,7 +112,7 @@ textGroupLayout->addWidget(m_maxLinesBox, 3, 1); break; } - case CompactMode: { + case Mode::Compact: { QLabel* maxWidthLabel = new QLabel(i18nc("@label:listbox", "Maximum width:"), textGroup); m_widthBox = new KComboBox(textGroup); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Unlimited")); @@ -124,7 +124,7 @@ textGroupLayout->addWidget(m_widthBox, 2, 1); break; } - case DetailsMode: + case Mode::Details: m_expandableFolders = new QCheckBox(i18nc("@option:check", "Expandable folders"), this); break; default: @@ -145,14 +145,14 @@ connect(m_fontRequester, &DolphinFontRequester::changed, this, &ViewSettingsTab::changed); switch (m_mode) { - case IconsMode: + case Mode::Icons: connect(m_widthBox, static_cast(&KComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); connect(m_maxLinesBox, static_cast(&KComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); break; - case CompactMode: + case Mode::Compact: connect(m_widthBox, static_cast(&KComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); break; - case DetailsMode: + case Mode::Details: connect(m_expandableFolders, &QCheckBox::toggled, this, &ViewSettingsTab::changed); break; default: @@ -167,17 +167,17 @@ void ViewSettingsTab::applySettings() { const QFont font = m_fontRequester->currentFont(); - const bool useSystemFont = (m_fontRequester->mode() == DolphinFontRequester::SystemFont); + const bool useSystemFont = (m_fontRequester->mode() == DolphinFontRequester::Mode::SystemFont); switch (m_mode) { - case IconsMode: + case Mode::Icons: IconsModeSettings::setTextWidthIndex(m_widthBox->currentIndex()); IconsModeSettings::setMaximumTextLines(m_maxLinesBox->currentIndex()); break; - case CompactMode: + case Mode::Compact: CompactModeSettings::setMaximumTextWidthIndex(m_widthBox->currentIndex()); break; - case DetailsMode: + case Mode::Details: DetailsModeSettings::setExpandableFolders(m_expandableFolders->isChecked()); break; default: @@ -204,9 +204,9 @@ { KConfigSkeleton* settings = nullptr; switch (m_mode) { - case IconsMode: settings = IconsModeSettings::self(); break; - case CompactMode: settings = CompactModeSettings::self(); break; - case DetailsMode: settings = DetailsModeSettings::self(); break; + case Mode::Icons: settings = IconsModeSettings::self(); break; + case Mode::Compact: settings = CompactModeSettings::self(); break; + case Mode::Details: settings = DetailsModeSettings::self(); break; default: Q_ASSERT(false); break; } @@ -218,14 +218,14 @@ void ViewSettingsTab::loadSettings() { switch (m_mode) { - case IconsMode: + case Mode::Icons: m_widthBox->setCurrentIndex(IconsModeSettings::textWidthIndex()); m_maxLinesBox->setCurrentIndex(IconsModeSettings::maximumTextLines()); break; - case CompactMode: + case Mode::Compact: m_widthBox->setCurrentIndex(CompactModeSettings::maximumTextWidthIndex()); break; - case DetailsMode: + case Mode::Details: m_expandableFolders->setChecked(DetailsModeSettings::expandableFolders()); break; default: @@ -241,8 +241,8 @@ m_previewSizeSlider->setValue(ZoomLevelInfo::zoomLevelForIconSize(previewSize)); m_fontRequester->setMode(settings.useSystemFont() - ? DolphinFontRequester::SystemFont - : DolphinFontRequester::CustomFont); + ? DolphinFontRequester::Mode::SystemFont + : DolphinFontRequester::Mode::CustomFont); QFont font(settings.fontFamily(), qRound(settings.fontSize())); font.setItalic(settings.italicFont()); @@ -256,12 +256,12 @@ ViewModeSettings::ViewMode mode; switch (m_mode) { - case ViewSettingsTab::IconsMode: mode = ViewModeSettings::IconsMode; break; - case ViewSettingsTab::CompactMode: mode = ViewModeSettings::CompactMode; break; - case ViewSettingsTab::DetailsMode: mode = ViewModeSettings::DetailsMode; break; - default: mode = ViewModeSettings::IconsMode; - Q_ASSERT(false); - break; + case ViewSettingsTab::Mode::Icons: mode = ViewModeSettings::ViewMode::Icons; break; + case ViewSettingsTab::Mode::Compact: mode = ViewModeSettings::ViewMode::Compact; break; + case ViewSettingsTab::Mode::Details: mode = ViewModeSettings::ViewMode::Details; break; + default: mode = ViewModeSettings::ViewMode::Icons; + Q_ASSERT(false); + break; } return mode; diff --git a/src/settings/viewpropertiesdialog.cpp b/src/settings/viewpropertiesdialog.cpp --- a/src/settings/viewpropertiesdialog.cpp +++ b/src/settings/viewpropertiesdialog.cpp @@ -91,9 +91,9 @@ QLabel* viewModeLabel = new QLabel(i18nc("@label:listbox", "View mode:"), propsGrid); m_viewMode = new KComboBox(propsGrid); - m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-icons")), i18nc("@item:inlistbox", "Icons"), DolphinView::IconsView); - m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-details")), i18nc("@item:inlistbox", "Compact"), DolphinView::CompactView); - m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-tree")), i18nc("@item:inlistbox", "Details"), DolphinView::DetailsView); + m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-icons")), i18nc("@item:inlistbox", "Icons"), static_cast(DolphinView::Mode::IconsView)); + m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-details")), i18nc("@item:inlistbox", "Compact"), static_cast(DolphinView::Mode::CompactView)); + m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-tree")), i18nc("@item:inlistbox", "Details"), static_cast(DolphinView::Mode::DetailsView)); QLabel* sortingLabel = new QLabel(i18nc("@label:listbox", "Sorting:"), propsGrid); QWidget* sortingBox = new QWidget(propsGrid); @@ -295,7 +295,7 @@ void ViewPropertiesDialog::configureAdditionalInfo() { QList visibleRoles = m_viewProps->visibleRoles(); - const bool useDefaultRoles = (m_viewProps->viewMode() == DolphinView::DetailsView) && visibleRoles.isEmpty(); + const bool useDefaultRoles = (m_viewProps->viewMode() == DolphinView::Mode::DetailsView) && visibleRoles.isEmpty(); if (useDefaultRoles) { // Using the details view without any additional information (-> additional column) // makes no sense and leads to a usability problem as no viewport area is available @@ -386,9 +386,9 @@ { // Load view mode switch (m_viewProps->viewMode()) { - case DolphinView::IconsView: m_viewMode->setCurrentIndex(0); break; - case DolphinView::CompactView: m_viewMode->setCurrentIndex(1); break; - case DolphinView::DetailsView: m_viewMode->setCurrentIndex(2); break; + case DolphinView::Mode::IconsView: m_viewMode->setCurrentIndex(0); break; + case DolphinView::Mode::CompactView: m_viewMode->setCurrentIndex(1); break; + case DolphinView::Mode::DetailsView: m_viewMode->setCurrentIndex(2); break; default: break; } diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp --- a/src/tests/kitemlistcontrollertest.cpp +++ b/src/tests/kitemlistcontrollertest.cpp @@ -124,7 +124,7 @@ m_controller = new KItemListController(m_model, m_view, this); m_container = new KItemListContainer(m_controller); m_controller = m_container->controller(); - m_controller->setSelectionBehavior(KItemListController::MultiSelection); + m_controller->setSelectionBehavior(KItemListController::SelectionBehavior::MultiSelection); m_selectionManager = m_controller->selectionManager(); m_testStyle = new KItemListControllerTestStyle(m_view->style()); m_view->setStyle(m_testStyle); @@ -230,22 +230,22 @@ QTest::addColumn > >("testList"); QList layoutList; - QHash layoutNames; - layoutList.append(KFileItemListView::IconsLayout); - layoutNames[KFileItemListView::IconsLayout] = "Icons"; - layoutList.append(KFileItemListView::CompactLayout); - layoutNames[KFileItemListView::CompactLayout] = "Compact"; - layoutList.append(KFileItemListView::DetailsLayout); - layoutNames[KFileItemListView::DetailsLayout] = "Details"; + QHash layoutNames; + layoutList.append(KFileItemListView::ItemLayout::Icons); + layoutNames[static_cast(KFileItemListView::ItemLayout::Icons)] = "Icons"; + layoutList.append(KFileItemListView::ItemLayout::Compact); + layoutNames[static_cast(KFileItemListView::ItemLayout::Compact)] = "Compact"; + layoutList.append(KFileItemListView::ItemLayout::Details); + layoutNames[static_cast(KFileItemListView::ItemLayout::Details)] = "Details"; QList selectionBehaviorList; - QHash selectionBehaviorNames; - selectionBehaviorList.append(KItemListController::NoSelection); - selectionBehaviorNames[KItemListController::NoSelection] = "NoSelection"; - selectionBehaviorList.append(KItemListController::SingleSelection); - selectionBehaviorNames[KItemListController::SingleSelection] = "SingleSelection"; - selectionBehaviorList.append(KItemListController::MultiSelection); - selectionBehaviorNames[KItemListController::MultiSelection] = "MultiSelection"; + QHash selectionBehaviorNames; + selectionBehaviorList.append(KItemListController::SelectionBehavior::NoSelection); + selectionBehaviorNames[static_cast(KItemListController::SelectionBehavior::NoSelection)] = "NoSelection"; + selectionBehaviorList.append(KItemListController::SelectionBehavior::SingleSelection); + selectionBehaviorNames[static_cast(KItemListController::SelectionBehavior::SingleSelection)] = "SingleSelection"; + selectionBehaviorList.append(KItemListController::SelectionBehavior::MultiSelection); + selectionBehaviorNames[static_cast(KItemListController::SelectionBehavior::MultiSelection)] = "MultiSelection"; QList groupingEnabledList; QHash groupingEnabledNames; @@ -266,23 +266,23 @@ Qt::Key previousRowKey; switch (layout) { - case KFileItemListView::IconsLayout: + case KFileItemListView::ItemLayout::Icons: scrollOrientation = Qt::Vertical; columnCountList << 1 << 3 << 5; nextItemKey = Qt::Key_Right; previousItemKey = Qt::Key_Left; nextRowKey = Qt::Key_Down; previousRowKey = Qt::Key_Up; break; - case KFileItemListView::CompactLayout: + case KFileItemListView::ItemLayout::Compact: scrollOrientation = Qt::Horizontal; columnCountList << 1 << 3 << 5; nextItemKey = Qt::Key_Down; previousItemKey = Qt::Key_Up; nextRowKey = Qt::Key_Right; previousRowKey = Qt::Key_Left; break; - case KFileItemListView::DetailsLayout: + case KFileItemListView::ItemLayout::Details: scrollOrientation = Qt::Vertical; columnCountList << 1; nextItemKey = Qt::Key_Down; @@ -456,9 +456,9 @@ } const QString testName = - layoutNames[layout] + ", " + + layoutNames[static_cast(layout)] + ", " + QString("%1 columns, ").arg(columnCount) + - selectionBehaviorNames[selectionBehavior] + ", " + + selectionBehaviorNames[static_cast(selectionBehavior)] + ", " + groupingEnabledNames[groupingEnabled]; const QByteArray testNameAscii = testName.toLatin1(); @@ -522,14 +522,14 @@ QCOMPARE(m_selectionManager->currentItem(), current); switch (selectionBehavior) { - case KItemListController::NoSelection: QVERIFY(m_selectionManager->selectedItems().isEmpty()); break; - case KItemListController::SingleSelection: QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << current); break; - case KItemListController::MultiSelection: QCOMPARE(m_selectionManager->selectedItems(), selection); break; + case KItemListController::SelectionBehavior::NoSelection: QVERIFY(m_selectionManager->selectedItems().isEmpty()); break; + case KItemListController::SelectionBehavior::SingleSelection: QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << current); break; + case KItemListController::SelectionBehavior::MultiSelection: QCOMPARE(m_selectionManager->selectedItems(), selection); break; } if (activated) { switch (selectionBehavior) { - case KItemListController::MultiSelection: + case KItemListController::SelectionBehavior::MultiSelection: if (!selection.isEmpty()) { // The selected items should be activated. if (selection.count() == 1) { @@ -545,8 +545,8 @@ } // No items are selected. Therefore, the current item should be activated. // This is handled by falling through to the NoSelection/SingleSelection case. - case KItemListController::NoSelection: - case KItemListController::SingleSelection: + case KItemListController::SelectionBehavior::NoSelection: + case KItemListController::SelectionBehavior::SingleSelection: // In NoSelection and SingleSelection mode, the current item should be activated. QVERIFY(!spySingleItemActivated.isEmpty()); QCOMPARE(qvariant_cast(spySingleItemActivated.takeFirst().at(0)), current); @@ -559,7 +559,7 @@ void KItemListControllerTest::testMouseClickActivation() { - m_view->setItemLayout(KFileItemListView::IconsLayout); + m_view->setItemLayout(KFileItemListView::ItemLayout::Icons); // Make sure that we have a large window, such that // the items are visible and clickable. diff --git a/src/tests/kitemlistselectionmanagertest.cpp b/src/tests/kitemlistselectionmanagertest.cpp --- a/src/tests/kitemlistselectionmanagertest.cpp +++ b/src/tests/kitemlistselectionmanagertest.cpp @@ -313,7 +313,7 @@ } namespace { - enum ChangeType { + enum class ChangeType { NoChange, InsertItems, RemoveItems, @@ -369,57 +369,57 @@ << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) - << NoChange + << ChangeType::NoChange << QList{} << (KItemSet() << 2 << 3 << 5 << 6); QTest::newRow("Insert Items") << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) - << InsertItems + << ChangeType::InsertItems << QList{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2) << KItemRange(10, 5))} << (KItemSet() << 3 << 4 << 8 << 9); QTest::newRow("Remove Items") << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) - << RemoveItems + << ChangeType::RemoveItems << QList{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(3, 1) << KItemRange(10, 5))} << (KItemSet() << 1 << 2 << 3 << 4); QTest::newRow("Empty Anchored Selection") << KItemSet() << 2 << 2 << KItemSet() - << EndAnchoredSelection + << ChangeType::EndAnchoredSelection << QList{} << KItemSet(); QTest::newRow("Toggle selection") << (KItemSet() << 1 << 3 << 4) << 6 << 8 << (KItemSet() << 1 << 3 << 4 << 6 << 7 << 8) - << SetSelected - << QList{0, 10, QVariant::fromValue(KItemListSelectionManager::Toggle)} + << ChangeType::SetSelected + << QList{0, 10, QVariant::fromValue(KItemListSelectionManager::SelectionMode::Toggle)} << (KItemSet() << 0 << 2 << 5 << 9); // Swap items 2, 3 and 4, 5 QTest::newRow("Move items") << (KItemSet() << 0 << 1 << 2 << 3) << -1 << -1 << (KItemSet() << 0 << 1 << 2 << 3) - << MoveItems + << ChangeType::MoveItems << QList{QVariant::fromValue(KItemRange(2, 4)), QVariant::fromValue(QList{4, 5, 2, 3})} << (KItemSet() << 0 << 1 << 4 << 5); QTest::newRow("Move items with active anchored selection") << KItemSet() << 0 << 3 << (KItemSet() << 0 << 1 << 2 << 3) - << MoveItems + << ChangeType::MoveItems << QList{QVariant::fromValue(KItemRange(2, 4)), QVariant::fromValue(QList{4, 5, 2, 3})} << (KItemSet() << 0 << 1 << 4 << 5); @@ -429,7 +429,7 @@ << (KItemSet() << 0 << 1) << 3 << 4 << (KItemSet() << 0 << 1 << 3 << 4) - << MoveItems + << ChangeType::MoveItems << QList{QVariant::fromValue(KItemRange(0, 10)), QVariant::fromValue(QList{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})} << (KItemSet() << 5 << 6 << 8 << 9); @@ -469,26 +469,26 @@ // Change the model by inserting or removing items. switch (changeType) { - case InsertItems: + case ChangeType::InsertItems: m_selectionManager->itemsInserted(data.at(0).value()); break; - case RemoveItems: + case ChangeType::RemoveItems: m_selectionManager->itemsRemoved(data.at(0).value()); break; - case MoveItems: + case ChangeType::MoveItems: m_selectionManager->itemsMoved(data.at(0).value(), data.at(1).value>()); break; - case EndAnchoredSelection: + case ChangeType::EndAnchoredSelection: m_selectionManager->endAnchoredSelection(); QVERIFY(!m_selectionManager->isAnchoredSelectionActive()); break; - case SetSelected: + case ChangeType::SetSelected: m_selectionManager->setSelected(data.at(0).value(), // index data.at(1).value(), // count data.at(2).value()); break; - case NoChange: + case ChangeType::NoChange: break; } diff --git a/src/tests/placesitemmodeltest.cpp b/src/tests/placesitemmodeltest.cpp --- a/src/tests/placesitemmodeltest.cpp +++ b/src/tests/placesitemmodeltest.cpp @@ -417,19 +417,19 @@ QTest::addColumn >("expectedVisibleRole"); // places - QTest::newRow("Places - Home") << QUrl::fromLocalFile(QDir::homePath()) << DolphinView::IconsView << true << QList({"text"}); + QTest::newRow("Places - Home") << QUrl::fromLocalFile(QDir::homePath()) << DolphinView::Mode::IconsView << true << QList({"text"}); // baloo -search - QTest::newRow("Baloo - Documents") << QUrl("search:/documents") << DolphinView::DetailsView << false << QList({"text", "path"}); + QTest::newRow("Baloo - Documents") << QUrl("search:/documents") << DolphinView::Mode::DetailsView << false << QList({"text", "path"}); // audio files - QTest::newRow("Places - Audio") << QUrl("search:/audio") << DolphinView::DetailsView << false << QList({"text", "artist", "album"}); + QTest::newRow("Places - Audio") << QUrl("search:/audio") << DolphinView::Mode::DetailsView << false << QList({"text", "artist", "album"}); // baloo - timeline - QTest::newRow("Baloo - Last Month") << QUrl("timeline:/lastmonth") << DolphinView::DetailsView << true << QList({"text", "modificationtime"}); + QTest::newRow("Baloo - Last Month") << QUrl("timeline:/lastmonth") << DolphinView::Mode::DetailsView << true << QList({"text", "modificationtime"}); // devices - QTest::newRow("Devices - Floppy") << QUrl("file:///media/floppy0") << DolphinView::IconsView << true << QList({"text"}); + QTest::newRow("Devices - Floppy") << QUrl("file:///media/floppy0") << DolphinView::Mode::IconsView << true << QList({"text"}); } diff --git a/src/views/dolphinfileitemlistwidget.cpp b/src/views/dolphinfileitemlistwidget.cpp --- a/src/views/dolphinfileitemlistwidget.cpp +++ b/src/views/dolphinfileitemlistwidget.cpp @@ -50,16 +50,16 @@ // as tint colors and are mixed with the current set text color. The tint colors // have been optimized for the base colors of the corresponding Oxygen emblems. switch (version) { - case KVersionControlPlugin::UpdateRequiredVersion: tintColor = Qt::yellow; break; - case KVersionControlPlugin::LocallyModifiedUnstagedVersion: tintColor = Qt::green; break; - case KVersionControlPlugin::LocallyModifiedVersion: tintColor = Qt::green; break; - case KVersionControlPlugin::AddedVersion: tintColor = Qt::green; break; - case KVersionControlPlugin::RemovedVersion: tintColor = Qt::darkRed; break; - case KVersionControlPlugin::ConflictingVersion: tintColor = Qt::red; break; - case KVersionControlPlugin::IgnoredVersion: tintColor = Qt::white; break; - case KVersionControlPlugin::MissingVersion: tintColor = Qt::red; break; - case KVersionControlPlugin::NormalVersion: - case KVersionControlPlugin::UnversionedVersion: + case KVersionControlPlugin::ItemVersion::UpdateRequired: tintColor = Qt::yellow; break; + case KVersionControlPlugin::ItemVersion::LocallyModifiedUnstaged: tintColor = Qt::green; break; + case KVersionControlPlugin::ItemVersion::LocallyModified: tintColor = Qt::green; break; + case KVersionControlPlugin::ItemVersion::Added: tintColor = Qt::green; break; + case KVersionControlPlugin::ItemVersion::Removed: tintColor = Qt::darkRed; break; + case KVersionControlPlugin::ItemVersion::Conflicting: tintColor = Qt::red; break; + case KVersionControlPlugin::ItemVersion::Ignored: tintColor = Qt::white; break; + case KVersionControlPlugin::ItemVersion::Missing: tintColor = Qt::red; break; + case KVersionControlPlugin::ItemVersion::Normal: + case KVersionControlPlugin::ItemVersion::Unversioned: default: break; } @@ -92,30 +92,30 @@ QString iconName; switch (version) { - case KVersionControlPlugin::NormalVersion: + case KVersionControlPlugin::ItemVersion::Normal: iconName = QStringLiteral("vcs-normal"); break; - case KVersionControlPlugin::UpdateRequiredVersion: + case KVersionControlPlugin::ItemVersion::UpdateRequired: iconName = QStringLiteral("vcs-update-required"); break; - case KVersionControlPlugin::LocallyModifiedVersion: + case KVersionControlPlugin::ItemVersion::LocallyModified: iconName = QStringLiteral("vcs-locally-modified"); break; - case KVersionControlPlugin::LocallyModifiedUnstagedVersion: + case KVersionControlPlugin::ItemVersion::LocallyModifiedUnstaged: iconName = QStringLiteral("vcs-locally-modified-unstaged"); break; - case KVersionControlPlugin::AddedVersion: + case KVersionControlPlugin::ItemVersion::Added: iconName = QStringLiteral("vcs-added"); break; - case KVersionControlPlugin::RemovedVersion: + case KVersionControlPlugin::ItemVersion::Removed: iconName = QStringLiteral("vcs-removed"); break; - case KVersionControlPlugin::ConflictingVersion: + case KVersionControlPlugin::ItemVersion::Conflicting: iconName = QStringLiteral("vcs-conflicting"); break; - case KVersionControlPlugin::UnversionedVersion: - case KVersionControlPlugin::IgnoredVersion: - case KVersionControlPlugin::MissingVersion: + case KVersionControlPlugin::ItemVersion::Unversioned: + case KVersionControlPlugin::ItemVersion::Ignored: + case KVersionControlPlugin::ItemVersion::Missing: break; default: Q_ASSERT(false); diff --git a/src/views/dolphinitemlistview.cpp b/src/views/dolphinitemlistview.cpp --- a/src/views/dolphinitemlistview.cpp +++ b/src/views/dolphinitemlistview.cpp @@ -114,12 +114,12 @@ bool DolphinItemListView::itemLayoutSupportsItemExpanding(ItemLayout layout) const { - return layout == DetailsLayout && DetailsModeSettings::expandableFolders(); + return layout == ItemLayout::Details && DetailsModeSettings::expandableFolders(); } void DolphinItemListView::onItemLayoutChanged(ItemLayout current, ItemLayout previous) { - setHeaderVisible(current == DetailsLayout); + setHeaderVisible(current == ItemLayout::Details); updateFont(); updateGridSize(); @@ -180,7 +180,7 @@ int maxTextWidth = 0; switch (itemLayout()) { - case KFileItemListView::IconsLayout: { + case KFileItemListView::ItemLayout::Icons: { const int minItemWidth = 48; itemWidth = minItemWidth + IconsModeSettings::textWidthIndex() * 64; @@ -203,7 +203,7 @@ maxTextLines = IconsModeSettings::maximumTextLines(); break; } - case KFileItemListView::CompactLayout: { + case KFileItemListView::ItemLayout::Compact: { itemWidth = padding * 4 + iconSize + option.fontMetrics.height() * 5; const int textLinesCount = visibleRoles().count(); itemHeight = padding * 2 + qMax(iconSize, textLinesCount * option.fontMetrics.lineSpacing()); @@ -217,7 +217,7 @@ horizontalMargin = 8; break; } - case KFileItemListView::DetailsLayout: { + case KFileItemListView::ItemLayout::Details: { itemWidth = -1; itemHeight = padding * 2 + qMax(iconSize, option.fontMetrics.lineSpacing()); break; @@ -247,12 +247,12 @@ ViewModeSettings::ViewMode mode; switch (itemLayout()) { - case KFileItemListView::IconsLayout: mode = ViewModeSettings::IconsMode; break; - case KFileItemListView::CompactLayout: mode = ViewModeSettings::CompactMode; break; - case KFileItemListView::DetailsLayout: mode = ViewModeSettings::DetailsMode; break; - default: mode = ViewModeSettings::IconsMode; - Q_ASSERT(false); - break; + case KFileItemListView::ItemLayout::Icons: mode = ViewModeSettings::ViewMode::Icons; break; + case KFileItemListView::ItemLayout::Compact: mode = ViewModeSettings::ViewMode::Compact; break; + case KFileItemListView::ItemLayout::Details: mode = ViewModeSettings::ViewMode::Details; break; + default: mode = ViewModeSettings::ViewMode::Icons; + Q_ASSERT(false); + break; } return mode; diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -67,7 +67,7 @@ * view mode is automatically updated if the directory itself * defines a view mode (see class ViewProperties for details). */ - enum Mode + enum class Mode { /** * The items are shown as icons with a name-label below. diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -85,7 +85,7 @@ m_dragging(false), m_url(url), m_viewPropertiesContext(), - m_mode(DolphinView::IconsView), + m_mode(DolphinView::Mode::IconsView), m_visibleRoles(), m_topLayout(nullptr), m_model(nullptr), @@ -138,7 +138,7 @@ connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip); connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip); - controller->setSelectionBehavior(KItemListController::MultiSelection); + controller->setSelectionBehavior(KItemListController::SelectionBehavior::MultiSelection); connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated); connect(controller, &KItemListController::itemsActivated, this, &DolphinView::slotItemsActivated); connect(controller, &KItemListController::itemMiddleClicked, this, &DolphinView::slotItemMiddleClicked); @@ -369,8 +369,8 @@ void DolphinView::selectItems(const QRegExp& pattern, bool enabled) { const KItemListSelectionManager::SelectionMode mode = enabled - ? KItemListSelectionManager::Select - : KItemListSelectionManager::Deselect; + ? KItemListSelectionManager::SelectionMode::Select + : KItemListSelectionManager::SelectionMode::Deselect; KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); for (int index = 0; index < m_model->count(); index++) { @@ -615,7 +615,7 @@ void DolphinView::invertSelection() { KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - selectionManager->setSelected(0, m_model->count(), KItemListSelectionManager::Toggle); + selectionManager->setSelected(0, m_model->count(), KItemListSelectionManager::SelectionMode::Toggle); } void DolphinView::clearSelection() @@ -1224,7 +1224,7 @@ bool DolphinView::itemsExpandable() const { - return m_mode == DetailsView; + return m_mode == Mode::DetailsView; } void DolphinView::restoreState(QDataStream& stream) @@ -1727,9 +1727,9 @@ void DolphinView::applyModeToView() { switch (m_mode) { - case IconsView: m_view->setItemLayout(KFileItemListView::IconsLayout); break; - case CompactView: m_view->setItemLayout(KFileItemListView::CompactLayout); break; - case DetailsView: m_view->setItemLayout(KFileItemListView::DetailsLayout); break; + case Mode::IconsView: m_view->setItemLayout(KFileItemListView::ItemLayout::Icons); break; + case Mode::CompactView: m_view->setItemLayout(KFileItemListView::ItemLayout::Compact); break; + case Mode::DetailsView: m_view->setItemLayout(KFileItemListView::ItemLayout::Details); break; default: Q_ASSERT(false); break; } } diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -338,11 +338,11 @@ QString DolphinViewActionHandler::currentViewModeActionName() const { switch (m_currentView->mode()) { - case DolphinView::IconsView: + case DolphinView::Mode::IconsView: return QStringLiteral("icons"); - case DolphinView::DetailsView: + case DolphinView::Mode::DetailsView: return QStringLiteral("details"); - case DolphinView::CompactView: + case DolphinView::Mode::CompactView: return QStringLiteral("compact"); default: Q_ASSERT(false); @@ -501,7 +501,7 @@ iconsView->setToolTip(i18nc("@info", "Icons view mode")); m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL | Qt::Key_1); iconsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); - iconsView->setData(QVariant::fromValue(DolphinView::IconsView)); + iconsView->setData(QVariant::fromValue(DolphinView::Mode::IconsView)); return iconsView; } @@ -512,7 +512,7 @@ iconsView->setToolTip(i18nc("@info", "Compact view mode")); m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL | Qt::Key_2); iconsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name - iconsView->setData(QVariant::fromValue(DolphinView::CompactView)); + iconsView->setData(QVariant::fromValue(DolphinView::Mode::CompactView)); return iconsView; } @@ -523,7 +523,7 @@ detailsView->setToolTip(i18nc("@info", "Details view mode")); m_actionCollection->setDefaultShortcut(detailsView, Qt::CTRL | Qt::Key_3); detailsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); - detailsView->setData(QVariant::fromValue(DolphinView::DetailsView)); + detailsView->setData(QVariant::fromValue(DolphinView::Mode::DetailsView)); return detailsView; } diff --git a/src/views/versioncontrol/kversioncontrolplugin.h b/src/views/versioncontrol/kversioncontrolplugin.h --- a/src/views/versioncontrol/kversioncontrolplugin.h +++ b/src/views/versioncontrol/kversioncontrolplugin.h @@ -86,62 +86,62 @@ Q_OBJECT public: - enum ItemVersion + enum class ItemVersion { /** The file is not under version control. */ - UnversionedVersion, + Unversioned, /** * The file is under version control and represents * the latest version. */ - NormalVersion, + Normal, /** * The file is under version control and a newer * version exists on the main branch. */ - UpdateRequiredVersion, + UpdateRequired, /** * The file is under version control and has been * modified locally. All modifications will be part * of the next commit. */ - LocallyModifiedVersion, + LocallyModified, /** * The file has not been under version control but * has been marked to get added with the next commit. */ - AddedVersion, + Added, /** * The file is under version control but has been marked * for getting removed with the next commit. */ - RemovedVersion, + Removed, /** * The file is under version control and has been locally * modified. A modification has also been done on the main * branch. */ - ConflictingVersion, + Conflicting, /** * The file is under version control and has local * modifications, which will not be part of the next * commit (or are "unstaged" in git jargon). * @since 4.6 */ - LocallyModifiedUnstagedVersion, + LocallyModifiedUnstaged, /** * The file is not under version control and is listed * in the ignore list of the version control system. * @since 4.8 */ - IgnoredVersion, + Ignored, /** * The file is is tracked by the version control system, but * is missing in the directory (e.g. by deleted without using * a version control command). * @since 4.8 */ - MissingVersion + Missing }; KVersionControlPlugin(QObject* parent = nullptr); diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp --- a/src/views/versioncontrol/versioncontrolobserver.cpp +++ b/src/views/versioncontrol/versioncontrolobserver.cpp @@ -178,7 +178,7 @@ const KFileItem& fileItem = item.first; const KVersionControlPlugin::ItemVersion version = item.second; QHash values; - values.insert("version", QVariant(version)); + values.insert("version", QVariant(static_cast(version))); m_model->setData(m_model->index(fileItem), values); } } @@ -239,7 +239,7 @@ if (expansionLevel == currentExpansionLevel) { ItemState itemState; itemState.first = m_model->fileItem(index); - itemState.second = KVersionControlPlugin::UnversionedVersion; + itemState.second = KVersionControlPlugin::ItemVersion::Unversioned; items.append(itemState); } else if (expansionLevel > currentExpansionLevel) { diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -96,7 +96,7 @@ (m_node->timestamp() < settings->viewPropsTimestamp())); if (useDefaultProps) { if (useDetailsViewWithPath) { - setViewMode(DolphinView::DetailsView); + setViewMode(DolphinView::Mode::DetailsView); setVisibleRoles({"path"}); } else { // The global view-properties act as default for directories without @@ -145,8 +145,8 @@ void ViewProperties::setViewMode(DolphinView::Mode mode) { - if (m_node->viewMode() != mode) { - m_node->setViewMode(mode); + if (DolphinView::Mode(m_node->viewMode()) != mode) { + m_node->setViewMode(static_cast(mode)); update(); } } @@ -261,7 +261,7 @@ } if (oldVisibleRoles != newVisibleRoles) { - const bool markCustomizedDetails = (m_node->viewMode() == DolphinView::DetailsView) + const bool markCustomizedDetails = (DolphinView::Mode(m_node->viewMode()) == DolphinView::Mode::DetailsView) && !newVisibleRoles.contains(CustomizedDetailsString); if (markCustomizedDetails) { // The additional information of the details-view has been modified. Set a marker, @@ -311,7 +311,7 @@ // For the details view the size and date should be shown per default // until the additional information has been explicitly changed by the user const bool useDefaultValues = roles.count() == 1 // "text" - && (m_node->viewMode() == DolphinView::DetailsView) + && (DolphinView::Mode(m_node->viewMode()) == DolphinView::Mode::DetailsView) && !visibleRoles.contains(CustomizedDetailsString); if (useDefaultValues) { roles.append("size"); @@ -391,10 +391,10 @@ { QString prefix; - switch (m_node->viewMode()) { - case DolphinView::IconsView: prefix = QStringLiteral("Icons_"); break; - case DolphinView::CompactView: prefix = QStringLiteral("Compact_"); break; - case DolphinView::DetailsView: prefix = QStringLiteral("Details_"); break; + switch (DolphinView::Mode(m_node->viewMode())) { + case DolphinView::Mode::IconsView: prefix = QStringLiteral("Icons_"); break; + case DolphinView::Mode::CompactView: prefix = QStringLiteral("Compact_"); break; + case DolphinView::Mode::DetailsView: prefix = QStringLiteral("Details_"); break; default: qCWarning(DolphinDebug) << "Unknown view-mode of the view properties"; }