]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/folders/folderspanel.cpp
DolphinView: Remove -1 interval, add setAutoActivationEnabled
[dolphin.git] / src / panels / folders / folderspanel.cpp
index d3d8b81f14d6ed34c8cb1e0fcd457b5cc0bbc10d..e375f2ce51fc84603020becc0e78b2fcff02b213 100644 (file)
 #include "treeviewcontextmenu.h"
 #include "views/draganddrophelper.h"
 
-#include <KJobWidgets>
-#include <KJobUiDelegate>
 #include <KIO/CopyJob>
 #include <KIO/DropJob>
 #include <KIO/FileUndoManager>
 #include <KIO/RenameFileDialog>
+#include <KJobUiDelegate>
+#include <KJobWidgets>
 
 #include <QApplication>
 #include <QBoxLayout>
 #include <QPropertyAnimation>
 #include <QTimer>
 
-FoldersPanel::FoldersPanel(QWidget* parent) :
-    Panel(parent),
-    m_updateCurrentItem(false),
-    m_controller(nullptr),
-    m_model(nullptr)
+FoldersPanel::FoldersPanel(QWidget *parent)
+    : Panel(parent)
+    , m_updateCurrentItem(false)
+    , m_controller(nullptr)
+    m_model(nullptr)
 {
     setLayoutDirection(Qt::LeftToRight);
 }
@@ -47,7 +47,7 @@ FoldersPanel::~FoldersPanel()
     FoldersPanelSettings::self()->save();
 
     if (m_controller) {
-        KItemListViewview = m_controller->view();
+        KItemListView *view = m_controller->view();
         m_controller->setView(nullptr);
         delete view;
     }
@@ -86,13 +86,13 @@ bool FoldersPanel::autoScrolling() const
     return FoldersPanelSettings::autoScrolling();
 }
 
-void FoldersPanel::rename(const KFileItemitem)
+void FoldersPanel::rename(const KFileItem &item)
 {
     if (GeneralSettings::renameInline()) {
         const int index = m_model->index(item);
         m_controller->view()->editRole(index, "text");
     } else {
-        KIO::RenameFileDialogdialog = new KIO::RenameFileDialog(KFileItemList({item}), this);
+        KIO::RenameFileDialog *dialog = new KIO::RenameFileDialog(KFileItemList({item}), this);
         dialog->open();
     }
 }
@@ -119,8 +119,7 @@ void FoldersPanel::reloadTree()
     }
 }
 
-
-void FoldersPanel::showEvent(QShowEvent* event)
+void FoldersPanel::showEvent(QShowEvent *event)
 {
     if (event->spontaneous()) {
         Panel::showEvent(event);
@@ -131,8 +130,7 @@ void FoldersPanel::showEvent(QShowEvent* event)
         // Postpone the creating of the controller to the first show event.
         // This assures that no performance and memory overhead is given when the folders panel is not
         // used at all and stays invisible.
-        KFileItemListView* view  = new KFileItemListView();
-        view->setScanDirectories(false);
+        KFileItemListView *view = new KFileItemListView();
         view->setWidgetCreator(new KItemListWidgetCreator<FoldersItemListWidget>());
         view->setSupportsItemExpanding(true);
         // Set the opacity to 0 initially. The opacity will be increased after the loading of the initial tree
@@ -140,8 +138,7 @@ void FoldersPanel::showEvent(QShowEvent* event)
         // opening the folders panel.
         view->setOpacity(0);
 
-        connect(view, &KFileItemListView::roleEditingFinished,
-                this, &FoldersPanel::slotRoleEditingFinished);
+        connect(view, &KFileItemListView::roleEditingFinished, this, &FoldersPanel::slotRoleEditingFinished);
 
         m_model = new KFileItemModel(this);
         m_model->setShowDirectoriesOnly(true);
@@ -154,7 +151,6 @@ void FoldersPanel::showEvent(QShowEvent* event)
         m_controller->setSelectionBehavior(KItemListController::SingleSelection);
         m_controller->setAutoActivationBehavior(KItemListController::ExpansionOnly);
         m_controller->setMouseDoubleClickAction(KItemListController::ActivateAndExpandItem);
-        m_controller->setAutoActivationDelay(750);
         m_controller->setSingleClickActivationEnforced(true);
 
         connect(m_controller, &KItemListController::itemActivated, this, &FoldersPanel::slotItemActivated);
@@ -163,10 +159,13 @@ void FoldersPanel::showEvent(QShowEvent* event)
         connect(m_controller, &KItemListController::viewContextMenuRequested, this, &FoldersPanel::slotViewContextMenuRequested);
         connect(m_controller, &KItemListController::itemDropEvent, this, &FoldersPanel::slotItemDropEvent);
 
-        KItemListContainer* container = new KItemListContainer(m_controller, this);
+        KItemListContainer *container = new KItemListContainer(m_controller, this);
+#ifndef QT_NO_ACCESSIBILITY
+        view->setAccessibleParentsObject(container);
+#endif
         container->setEnabledFrame(false);
 
-        QVBoxLayoutlayout = new QVBoxLayout(this);
+        QVBoxLayout *layout = new QVBoxLayout(this);
         layout->setContentsMargins(0, 0, 0, 0);
         layout->addWidget(container);
     }
@@ -175,7 +174,7 @@ void FoldersPanel::showEvent(QShowEvent* event)
     Panel::showEvent(event);
 }
 
-void FoldersPanel::keyPressEvent(QKeyEventevent)
+void FoldersPanel::keyPressEvent(QKeyEvent *event)
 {
     const int key = event->key();
     if ((key == Qt::Key_Enter) || (key == Qt::Key_Return)) {
@@ -219,7 +218,7 @@ void FoldersPanel::slotItemMiddleClicked(int index)
     }
 }
 
-void FoldersPanel::slotItemContextMenuRequested(int index, const QPointFpos)
+void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF &pos)
 {
     const KFileItem fileItem = m_model->fileItem(index);
 
@@ -230,7 +229,7 @@ void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos)
     }
 }
 
-void FoldersPanel::slotViewContextMenuRequested(const QPointFpos)
+void FoldersPanel::slotViewContextMenuRequested(const QPointF &pos)
 {
     QPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, KFileItem());
     contextMenu.data()->open(pos.toPoint());
@@ -239,7 +238,7 @@ void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos)
     }
 }
 
-void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEventevent)
+void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent *event)
 {
     if (index >= 0) {
         KFileItem destItem = m_model->fileItem(index);
@@ -247,20 +246,20 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve
             return;
         }
 
-        QDropEvent dropEvent(event->pos().toPoint(),
-                             event->possibleActions(),
-                             event->mimeData(),
-                             event->buttons(),
-                             event->modifiers());
+        QDropEvent dropEvent(event->pos().toPoint(), event->possibleActions(), event->mimeData(), event->buttons(), event->modifiers());
 
         KIO::DropJob *job = DragAndDropHelper::dropUrls(destItem.mostLocalUrl(), &dropEvent, this);
         if (job) {
-            connect(job, &KIO::DropJob::result, this, [this](KJob *job) { if (job->error()) Q_EMIT errorMessage(job->errorString()); });
+            connect(job, &KIO::DropJob::result, this, [this](KJob *job) {
+                if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
+                    Q_EMIT errorMessage(job->errorString());
+                }
+            });
         }
     }
 }
 
-void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
+void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray &role, const QVariant &value)
 {
     if (role == "text") {
         const KFileItem item = m_model->fileItem(index);
@@ -271,7 +270,7 @@ void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, co
             QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename);
             newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));
 
-            KIO::Jobjob = KIO::moveAs(oldUrl, newUrl);
+            KIO::Job *job = KIO::moveAs(oldUrl, newUrl);
             KJobWidgets::setWindow(job, this);
             KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job);
             job->uiDelegate()->setAutoErrorHandlingEnabled(true);
@@ -302,7 +301,7 @@ void FoldersPanel::slotLoadingCompleted()
 
 void FoldersPanel::startFadeInAnimation()
 {
-    QPropertyAnimationanim = new QPropertyAnimation(m_controller->view(), "opacity", this);
+    QPropertyAnimation *anim = new QPropertyAnimation(m_controller->view(), "opacity", this);
     anim->setStartValue(0);
     anim->setEndValue(1);
     anim->setEasingCurve(QEasingCurve::InOutQuad);
@@ -310,7 +309,7 @@ void FoldersPanel::startFadeInAnimation()
     anim->setDuration(200);
 }
 
-void FoldersPanel::loadTree(const QUrlurl, FoldersPanel::NavigationBehaviour navigationBehaviour)
+void FoldersPanel::loadTree(const QUrl &url, FoldersPanel::NavigationBehaviour navigationBehaviour)
 {
     Q_ASSERT(m_controller);
 
@@ -323,7 +322,7 @@ void FoldersPanel::loadTree(const QUrl& url, FoldersPanel::NavigationBehaviour n
         baseUrl = url;
         baseUrl.setPath(QStringLiteral("/"));
     } else if (Dolphin::homeUrl().isParentOf(url) || (Dolphin::homeUrl() == url)) {
-        if (FoldersPanelSettings::limitFoldersPanelToHome() ) {
+        if (FoldersPanelSettings::limitFoldersPanelToHome()) {
             baseUrl = Dolphin::homeUrl();
         } else {
             // Use the root directory as base for local URLs (#150941)
@@ -344,7 +343,7 @@ void FoldersPanel::loadTree(const QUrl& url, FoldersPanel::NavigationBehaviour n
 
     const int index = m_model->index(url);
     if (jumpHome) {
-      Q_EMIT folderActivated(baseUrl);
+        Q_EMIT folderActivated(baseUrl);
     } else if (index >= 0) {
         updateCurrentItem(index);
     } else if (url == baseUrl) {
@@ -361,7 +360,7 @@ void FoldersPanel::loadTree(const QUrl& url, FoldersPanel::NavigationBehaviour n
 
 void FoldersPanel::updateCurrentItem(int index)
 {
-    KItemListSelectionManagerselectionManager = m_controller->selectionManager();
+    KItemListSelectionManager *selectionManager = m_controller->selectionManager();
     selectionManager->setCurrentItem(index);
     selectionManager->clearSelection();
     selectionManager->setSelected(index);
@@ -369,3 +368,4 @@ void FoldersPanel::updateCurrentItem(int index)
     m_controller->view()->scrollToItem(index);
 }
 
+#include "moc_folderspanel.cpp"