]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
[KStandardItemListWidget] Update icon when palette changes
[dolphin.git] / src / views / dolphinview.cpp
index 32e182ce7c15bf1518b7e928cfff99188e7605af..30298d2e1efe356d50f62a09d8f2db8e063920ea 100644 (file)
@@ -29,6 +29,7 @@
 #include <QGraphicsSceneDragDropEvent>
 #include <QTimer>
 #include <QScrollBar>
+#include <QPixmapCache>
 #include <QPointer>
 #include <QMenu>
 #include <QVBoxLayout>
 #include <KIO/CopyJob>
 #include <KIO/DeleteJob>
 #include <KIO/JobUiDelegate>
-#include <KIO/NetAccess>
 #include <KIO/PreviewJob>
 #include <KIO/DropJob>
 #include <KIO/PasteJob>
 #include <KIO/Paste>
 #include <KJob>
-#include <QMenu>
 #include <KMessageBox>
 #include <KJobWidgets>
 #include <QUrl>
 #endif
 #include <KFormat>
 
-namespace {
-    const int MaxModeEnum = DolphinView::CompactView;
-};
-
 DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
     QWidget(parent),
     m_active(true),
@@ -179,8 +174,8 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
             this, &DolphinView::slotVisibleRolesChangedByHeader);
     connect(m_view, &DolphinItemListView::roleEditingCanceled,
             this, &DolphinView::slotRoleEditingCanceled);
-    connect(m_view->header(), &KItemListHeader::columnWidthChanged,
-            this, &DolphinView::slotHeaderColumnWidthChanged);
+    connect(m_view->header(), &KItemListHeader::columnWidthChangeFinished,
+            this, &DolphinView::slotHeaderColumnWidthChangeFinished);
 
     KItemListSelectionManager* selectionManager = controller->selectionManager();
     connect(selectionManager, &KItemListSelectionManager::selectionChanged,
@@ -217,19 +212,7 @@ void DolphinView::setActive(bool active)
 
     m_active = active;
 
-    QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
-    if (!active) {
-        color.setAlpha(150);
-    }
-
-    QWidget* viewport = m_container->viewport();
-    if (viewport) {
-        QPalette palette;
-        palette.setColor(viewport->backgroundRole(), color);
-        viewport->setPalette(palette);
-    }
-
-    update();
+    updatePalette();
 
     if (active) {
         m_container->setFocus();
@@ -351,7 +334,9 @@ KFileItemList DolphinView::selectedItems() const
     const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
 
     KFileItemList selectedItems;
-    foreach (int index, selectionManager->selectedItems()) {
+    const auto items = selectionManager->selectedItems();
+    selectedItems.reserve(items.count());
+    for (int index : items) {
         selectedItems.append(m_model->fileItem(index));
     }
     return selectedItems;
@@ -673,7 +658,7 @@ void DolphinView::trashSelectedItems()
     uiDelegate.setWindow(window());
     if (uiDelegate.askDeleteConfirmation(list, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) {
         KIO::Job* job = KIO::trash(list);
-        KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl("trash:/"), job);
+        KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, list, QUrl(QStringLiteral("trash:/")), job);
         KJobWidgets::setWindow(job, this);
         connect(job, &KIO::Job::result,
                 this, &DolphinView::slotTrashFileFinished);
@@ -725,9 +710,40 @@ void DolphinView::stopLoading()
     m_model->cancelDirectoryLoading();
 }
 
+void DolphinView::updatePalette()
+{
+    QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
+    if (!m_active) {
+        color.setAlpha(150);
+    }
+
+    QWidget* viewport = m_container->viewport();
+    if (viewport) {
+        QPalette palette;
+        palette.setColor(viewport->backgroundRole(), color);
+        viewport->setPalette(palette);
+    }
+
+    update();
+}
+
 bool DolphinView::eventFilter(QObject* watched, QEvent* event)
 {
     switch (event->type()) {
+    case QEvent::PaletteChange:
+        updatePalette();
+        QPixmapCache::clear();
+        break;
+
+    case QEvent::KeyPress:
+        if (GeneralSettings::useTabForSwitchingSplitView()) {
+            QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
+            if (keyEvent->key() == Qt::Key_Tab && keyEvent->modifiers() == Qt::NoModifier) {
+                toggleActiveViewRequested();
+                return true;
+            }
+        }
+        break;
     case QEvent::FocusIn:
         if (watched == m_container) {
             setActive(true);
@@ -818,7 +834,7 @@ void DolphinView::slotItemsActivated(const KItemSet& indexes)
     KFileItemList items;
     items.reserve(indexes.count());
 
-    foreach (int index, indexes) {
+    for (int index : indexes) {
         KFileItem item = m_model->fileItem(index);
         const QUrl& url = openItemAsFolderUrl(item);
 
@@ -941,6 +957,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
             // Apply the current column-widths as custom column-widths and turn
             // off the automatic resizing of the columns
             QList<int> columnWidths;
+            columnWidths.reserve(view->visibleRoles().count());
             foreach (const QByteArray& role, view->visibleRoles()) {
                 columnWidths.append(header->columnWidth(role));
             }
@@ -962,6 +979,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
 
             QList<int> columnWidths;
             if (!header->automaticColumnResizing()) {
+                columnWidths.reserve(view->visibleRoles().count());
                 foreach (const QByteArray& role, view->visibleRoles()) {
                     columnWidths.append(header->columnWidth(role));
                 }
@@ -973,10 +991,8 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
     delete menu;
 }
 
-void DolphinView::slotHeaderColumnWidthChanged(const QByteArray& role, qreal current, qreal previous)
+void DolphinView::slotHeaderColumnWidthChangeFinished(const QByteArray& role, qreal current)
 {
-    Q_UNUSED(previous);
-
     const QList<QByteArray> visibleRoles = m_view->visibleRoles();
 
     ViewProperties props(viewPropertiesUrl());
@@ -1031,7 +1047,7 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
         destUrl = url();
     } else {
         // The item represents a directory or desktop-file
-        destUrl = destItem.url();
+        destUrl = destItem.mostLocalUrl();
     }
 
     QDropEvent dropEvent(event->pos().toPoint(),
@@ -1048,12 +1064,15 @@ void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent)
 {
     KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, this);
 
-    if (job && destUrl == url()) {
-        // Mark the dropped urls as selected.
-        m_clearSelectionBeforeSelectingNewItems = true;
-        m_markFirstNewlySelectedItemAsCurrent = true;
-        connect(job, &KIO::DropJob::itemCreated, this, &DolphinView::slotItemCreated);
+    if (job) {
         connect(job, &KIO::DropJob::result, this, &DolphinView::slotPasteJobResult);
+
+        if (destUrl == url()) {
+            // Mark the dropped urls as selected.
+            m_clearSelectionBeforeSelectingNewItems = true;
+            m_markFirstNewlySelectedItemAsCurrent = true;
+            connect(job, &KIO::DropJob::itemCreated, this, &DolphinView::slotItemCreated);
+        }
     }
 }
 
@@ -1275,7 +1294,7 @@ QUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseTh
             if (desktopFile.hasLinkType()) {
                 const QString linkUrl = desktopFile.readUrl();
                 if (!linkUrl.startsWith(QLatin1String("http"))) {
-                    return linkUrl;
+                    return QUrl::fromUserInput(linkUrl);
                 }
             }
         }
@@ -1405,7 +1424,7 @@ void DolphinView::slotRenamingResult(KJob* job)
         const int index = m_model->index(newUrl);
         if (index >= 0) {
             QHash<QByteArray, QVariant> data;
-            const QUrl oldUrl = copyJob->srcUrls().first();
+            const QUrl oldUrl = copyJob->srcUrls().at(0);
             data.insert("text", oldUrl.fileName());
             m_model->setData(index, data);
         }
@@ -1428,7 +1447,7 @@ void DolphinView::slotDirectoryLoadingCompleted()
 {
     // Update the view-state. This has to be done asynchronously
     // because the view might not be in its final state yet.
-    QTimer::singleShot(0, this, SLOT(updateViewState()));
+    QTimer::singleShot(0, this, &DolphinView::updateViewState);
 
     emit directoryLoadingCompleted();
 
@@ -1672,6 +1691,7 @@ QList<QUrl> DolphinView::simplifiedSelectedUrls() const
     QList<QUrl> urls;
 
     const KFileItemList items = selectedItems();
+    urls.reserve(items.count());
     foreach (const KFileItem& item, items) {
         urls.append(item.url());
     }