]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincolumnwidget.cpp
there's no need having 2-liners inside their own method when this method is only...
[dolphin.git] / src / dolphincolumnwidget.cpp
index 38057362929eba3a8793a7b99b2842177f038d18..1a7f712f38e2a3681f81fd941eab1239c4409973 100644 (file)
@@ -26,8 +26,8 @@
 #include "dolphinmodel.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinsettings.h"
-
 #include "dolphin_columnmodesettings.h"
+#include "draganddrophelper.h"
 
 #include <kcolorutils.h>
 #include <kcolorscheme.h>
@@ -35,6 +35,7 @@
 #include <kfileitem.h>
 #include <kio/previewjob.h>
 #include <kiconeffect.h>
+#include <kmimetyperesolver.h>
 #include <konqmimedata.h>
 
 #include <QAbstractProxyModel>
@@ -69,7 +70,6 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
     setSelectionMode(QAbstractItemView::ExtendedSelection);
     setDragDropMode(QAbstractItemView::DragDrop);
     setDropIndicatorShown(false);
-    setFocusPolicy(Qt::NoFocus);
 
 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
 //       check avoids a division by zero happening on versions before 4.3.1.
@@ -111,7 +111,8 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
     m_dirLister->setAutoUpdate(true);
     m_dirLister->setMainWindow(this);
     m_dirLister->setDelayedMimeTypes(true);
-    m_dirLister->setShowingDotFiles(m_view->m_controller->showHiddenFiles());
+    const bool showHiddenFiles = m_view->m_controller->dolphinView()->showHiddenFiles();
+    m_dirLister->setShowingDotFiles(showHiddenFiles);
     connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)),
             this, SLOT(generatePreviews(const KFileItemList&)));
 
@@ -123,6 +124,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
     m_proxyModel->setSourceModel(m_dolphinModel);
 
     setModel(m_proxyModel);
+    new KMimeTypeResolver(this, m_dolphinModel);
 
     m_dirLister->openUrl(url, KDirLister::NoFlags);
 }
@@ -181,7 +183,7 @@ void DolphinColumnWidget::updateBackground()
 {
     QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
     if (!m_active || !m_view->m_active) {
-        color.setAlpha(0);
+        color.setAlpha(150);
     }
     QPalette palette = viewport()->palette();
     palette.setColor(viewport()->backgroundRole(), color);
@@ -190,6 +192,16 @@ void DolphinColumnWidget::updateBackground()
     update();
 }
 
+void DolphinColumnWidget::setNameFilter(const QString& nameFilter)
+{
+    m_proxyModel->setFilterRegExp(nameFilter);
+}
+
+void DolphinColumnWidget::startDrag(Qt::DropActions supportedActions)
+{
+    DragAndDropHelper::startDrag(this, supportedActions);
+}
+
 void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
 {
     if (event->mimeData()->hasUrls()) {
@@ -215,7 +227,11 @@ void DolphinColumnWidget::dragMoveEvent(QDragMoveEvent* event)
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     const QModelIndex index = indexAt(event->pos());
     setDirtyRegion(m_dropRect);
-    m_dropRect = visualRect(index);
+    if (itemForIndex(index).isDir()) {
+        m_dropRect = visualRect(index);
+    } else {
+        m_dropRect.setSize(QSize()); // set as invalid
+    }
     setDirtyRegion(m_dropRect);
 }
 
@@ -223,11 +239,12 @@ void DolphinColumnWidget::dropEvent(QDropEvent* event)
 {
     const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
     if (!urls.isEmpty()) {
-        event->acceptProposedAction();
+        const QModelIndex index = indexAt(event->pos());
+        const KFileItem item = itemForIndex(index);
         m_view->m_controller->indicateDroppedUrls(urls,
                                                   url(),
-                                                  indexAt(event->pos()),
-                                                  event->source());
+                                                  item);
+        event->acceptProposedAction();
     }
     QListView::dropEvent(event);
     m_dragging = false;
@@ -259,7 +276,7 @@ void DolphinColumnWidget::paintEvent(QPaintEvent* event)
     // TODO: remove this code when the issue #160611 is solved in Qt 4.4
     if (m_dragging) {
         const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
-        DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
+        DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
     }
 }
 
@@ -314,9 +331,10 @@ void DolphinColumnWidget::selectionChanged(const QItemSelection& selected, const
     selModel->select(selected, QItemSelectionModel::Select);
     selModel->select(deselected, QItemSelectionModel::Deselect);
 }
+
 void DolphinColumnWidget::triggerItem(const QModelIndex& index)
 {
-    const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index));
+    const KFileItem item = itemForIndex(index);
     m_view->m_controller->triggerItem(item);
 }
 
@@ -325,7 +343,7 @@ void DolphinColumnWidget::generatePreviews(const KFileItemList& items)
     // TODO: same implementation as in DolphinView; create helper class
     // for generatePreviews(), showPreview() and isCutItem()
 
-    if (m_view->m_controller->showPreview()) {
+    if (m_view->m_controller->dolphinView()->showPreview()) {
         KIO::PreviewJob* job = KIO::filePreview(items, 128);
         connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
                 this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
@@ -366,10 +384,7 @@ void DolphinColumnWidget::slotEntered(const QModelIndex& index)
 
 void DolphinColumnWidget::activate()
 {
-    if (m_view->hasFocus()) {
-        setFocus(Qt::OtherFocusReason);
-    }
-    m_view->setFocusProxy(this);
+    setFocus(Qt::OtherFocusReason);
 
     // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
     // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
@@ -395,6 +410,8 @@ void DolphinColumnWidget::activate()
 
 void DolphinColumnWidget::deactivate()
 {
+    clearFocus();
+
     // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
     // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
     // necessary connecting the signal 'singleClick()' or 'doubleClick'.
@@ -431,4 +448,11 @@ bool DolphinColumnWidget::isCutItem(const KFileItem& item) const
     return false;
 }
 
+KFileItem DolphinColumnWidget::itemForIndex(const QModelIndex& index) const
+{
+    const QModelIndex dirIndex = m_proxyModel->mapToSource(index);
+    return m_dolphinModel->itemForIndex(dirIndex);
+}
+
+
 #include "dolphincolumnwidget.moc"