+ // Add all roles to the menu that can be shown or hidden by the user
+ const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
+ for (const KFileItemModel::RoleInfo& info : rolesInfo) {
+ if (info.role == "text") {
+ // It should not be possible to hide the "text" role
+ continue;
+ }
+
+ const QString text = m_model->roleDescription(info.role);
+ QAction* action = nullptr;
+ if (info.group.isEmpty()) {
+ action = menu->addAction(text);
+ } else {
+ if (!groupMenu || info.group != groupName) {
+ groupName = info.group;
+ groupMenu = menu->addMenu(groupName);
+ }
+
+ action = groupMenu->addAction(text);
+ }
+
+ action->setCheckable(true);
+ action->setChecked(visibleRolesSet.contains(info.role));
+ action->setData(info.role);
+
+ const bool enable = (!info.requiresBaloo && !info.requiresIndexer) ||
+ (info.requiresBaloo) ||
+ (info.requiresIndexer && indexingEnabled);
+ action->setEnabled(enable);
+ }
+
+ menu->addSeparator();
+
+ QActionGroup* widthsGroup = new QActionGroup(menu);
+ const bool autoColumnWidths = props.headerColumnWidths().isEmpty();
+
+ QAction* toggleSidePaddingAction = menu->addAction(i18nc("@action:inmenu", "Side Padding"));
+ toggleSidePaddingAction->setCheckable(true);
+ toggleSidePaddingAction->setChecked(view->header()->sidePadding() > 0);
+
+ QAction* autoAdjustWidthsAction = menu->addAction(i18nc("@action:inmenu", "Automatic Column Widths"));
+ autoAdjustWidthsAction->setCheckable(true);
+ autoAdjustWidthsAction->setChecked(autoColumnWidths);
+ autoAdjustWidthsAction->setActionGroup(widthsGroup);
+
+ QAction* customWidthsAction = menu->addAction(i18nc("@action:inmenu", "Custom Column Widths"));
+ customWidthsAction->setCheckable(true);
+ customWidthsAction->setChecked(!autoColumnWidths);
+ customWidthsAction->setActionGroup(widthsGroup);
+
+ QAction* action = menu->exec(pos.toPoint());
+ if (menu && action) {
+ KItemListHeader* header = view->header();
+
+ if (action == autoAdjustWidthsAction) {
+ // Clear the column-widths from the viewproperties and turn on
+ // the automatic resizing of the columns
+ props.setHeaderColumnWidths(QList<int>());
+ header->setAutomaticColumnResizing(true);
+ } else if (action == customWidthsAction) {
+ // Apply the current column-widths as custom column-widths and turn
+ // off the automatic resizing of the columns
+ QList<int> columnWidths;
+ const auto visibleRoles = view->visibleRoles();
+ columnWidths.reserve(visibleRoles.count());
+ for (const QByteArray& role : visibleRoles) {
+ columnWidths.append(header->columnWidth(role));
+ }
+ props.setHeaderColumnWidths(columnWidths);
+ header->setAutomaticColumnResizing(false);
+ } else if (action == toggleSidePaddingAction) {
+ header->setSidePadding(toggleSidePaddingAction->isChecked() ? 20 : 0);
+ } else {
+ // Show or hide the selected role
+ const QByteArray selectedRole = action->data().toByteArray();
+
+ QList<QByteArray> visibleRoles = view->visibleRoles();
+ if (action->isChecked()) {
+ visibleRoles.append(selectedRole);
+ } else {
+ visibleRoles.removeOne(selectedRole);
+ }
+
+ view->setVisibleRoles(visibleRoles);
+ props.setVisibleRoles(visibleRoles);
+
+ QList<int> columnWidths;
+ if (!header->automaticColumnResizing()) {
+ const auto visibleRoles = view->visibleRoles();
+ columnWidths.reserve(visibleRoles.count());
+ for (const QByteArray& role : visibleRoles) {
+ columnWidths.append(header->columnWidth(role));
+ }
+ }
+ props.setHeaderColumnWidths(columnWidths);
+ }
+ }
+
+ delete menu;
+}
+
+void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray& role, qreal current)
+{
+ const QList<QByteArray> visibleRoles = m_view->visibleRoles();
+
+ ViewProperties props(viewPropertiesUrl());
+ QList<int> columnWidths = props.headerColumnWidths();
+ if (columnWidths.count() != visibleRoles.count()) {
+ columnWidths.clear();
+ columnWidths.reserve(visibleRoles.count());
+ const KItemListHeader* header = m_view->header();
+ for (const QByteArray& role : visibleRoles) {
+ const int width = header->columnWidth(role);
+ columnWidths.append(width);
+ }
+ }
+
+ const int roleIndex = visibleRoles.indexOf(role);
+ Q_ASSERT(roleIndex >= 0 && roleIndex < columnWidths.count());
+ columnWidths[roleIndex] = current;
+
+ props.setHeaderColumnWidths(columnWidths);
+}
+
+void DolphinView::slotSidePaddingWidthChanged(qreal width)
+{
+ ViewProperties props(viewPropertiesUrl());
+ DetailsModeSettings::setSidePadding(int(width));
+ m_view->writeSettings();
+}
+
+void DolphinView::slotItemHovered(int index)
+{
+ const KFileItem item = m_model->fileItem(index);
+
+ if (GeneralSettings::showToolTips() && !m_dragging) {
+ QRectF itemRect = m_container->controller()->view()->itemContextRect(index);
+ const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint());
+ itemRect.moveTo(pos);
+
+#if HAVE_BALOO
+ auto nativeParent = nativeParentWidget();
+ if (nativeParent) {
+ m_toolTipManager->showToolTip(item, itemRect, nativeParent->windowHandle());
+ }
+#endif
+ }
+
+ Q_EMIT requestItemInfo(item);
+}
+
+void DolphinView::slotItemUnhovered(int index)
+{
+ Q_UNUSED(index)
+ hideToolTip();
+ Q_EMIT requestItemInfo(KFileItem());
+}
+
+void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
+{
+ QUrl destUrl;
+ KFileItem destItem = m_model->fileItem(index);
+ if (destItem.isNull() || (!destItem.isDir() && !destItem.isDesktopFile())) {
+ // Use the URL of the view as drop target if the item is no directory
+ // or desktop-file
+ destItem = m_model->rootItem();
+ destUrl = url();
+ } else {
+ // The item represents a directory or desktop-file
+ destUrl = destItem.mostLocalUrl();
+ }
+
+ QDropEvent dropEvent(event->pos().toPoint(),
+ event->possibleActions(),
+ event->mimeData(),
+ event->buttons(),
+ event->modifiers());
+ dropUrls(destUrl, &dropEvent, this);
+
+ setActive(true);
+}
+
+void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent, QWidget *dropWidget)
+{
+ KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, dropWidget);
+
+ if (job) {
+ connect(job, &KIO::DropJob::result, this, &DolphinView::slotJobResult);
+
+ if (destUrl == url()) {
+ // Mark the dropped urls as selected.
+ m_clearSelectionBeforeSelectingNewItems = true;
+ m_markFirstNewlySelectedItemAsCurrent = true;
+ connect(job, &KIO::DropJob::itemCreated, this, &DolphinView::slotItemCreated);
+ }
+ }
+}
+
+void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
+{
+ if (previous != nullptr) {
+ Q_ASSERT(qobject_cast<KFileItemModel*>(previous));
+ KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(previous);
+ disconnect(fileItemModel, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted);
+ m_versionControlObserver->setModel(nullptr);
+ }
+
+ if (current) {
+ Q_ASSERT(qobject_cast<KFileItemModel*>(current));
+ KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(current);
+ connect(fileItemModel, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted);
+ m_versionControlObserver->setModel(fileItemModel);
+ }
+}
+
+void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons)
+{
+ Q_UNUSED(itemIndex)
+
+ hideToolTip();
+
+ if (buttons & Qt::BackButton) {
+ Q_EMIT goBackRequested();
+ } else if (buttons & Qt::ForwardButton) {
+ Q_EMIT goForwardRequested();
+ }
+}
+
+void DolphinView::slotSelectedItemTextPressed(int index)
+{
+ if (GeneralSettings::renameInline() && !m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) {
+ const KFileItem item = m_model->fileItem(index);
+ const KFileItemListProperties capabilities(KFileItemList() << item);
+ if (capabilities.supportsMoving()) {
+ m_twoClicksRenamingItemUrl = item.url();
+ m_twoClicksRenamingTimer->start(QApplication::doubleClickInterval());
+ }
+ }
+}
+
+void DolphinView::slotCopyingDone(KIO::Job *, const QUrl &, const QUrl &to)
+{
+ slotItemCreated(to);
+}
+
+void DolphinView::slotItemCreated(const QUrl& url)
+{
+ if (m_markFirstNewlySelectedItemAsCurrent) {
+ markUrlAsCurrent(url);
+ m_markFirstNewlySelectedItemAsCurrent = false;
+ }
+ m_selectedUrls << url;
+}
+
+void DolphinView::slotJobResult(KJob *job)
+{
+ if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
+ Q_EMIT errorMessage(job->errorString());
+ }
+ if (!m_selectedUrls.isEmpty()) {
+ m_selectedUrls = KDirModel::simplifiedUrlList(m_selectedUrls);
+ }
+}
+
+void DolphinView::slotSelectionChanged(const KItemSet& current, const KItemSet& previous)
+{
+ const int currentCount = current.count();
+ const int previousCount = previous.count();
+ const bool selectionStateChanged = (currentCount == 0 && previousCount > 0) ||
+ (currentCount > 0 && previousCount == 0);