#include "dolphincontroller.h"
#include "dolphinsettings.h"
#include "dolphin_iconsmodesettings.h"
+#include "draganddrophelper.h"
#include <kcategorizedsortfilterproxymodel.h>
#include <kdialog.h>
setViewMode(QListView::IconMode);
setResizeMode(QListView::Adjust);
setSpacing(KDialog::spacingHint());
- setMovement(QListView::Snap);
+ setMovement(QListView::Static);
+ setDragEnabled(true);
+ viewport()->setAcceptDrops(true);
+
setMouseTracking(true);
viewport()->setAttribute(Qt::WA_Hover);
KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model());
if (leftToRightFlow && !proxyModel->isCategorizedModel()) {
- // TODO: This workaround bypasses a layout issue in QListView::visualRect(), where
- // the horizontal position of items might get calculated in a wrong manner when the item
- // name is too long. I'll try create a patch for Qt but as Dolphin must also work with
- // Qt 4.3.0 this workaround must get applied at least for KDE 4.0.
+ // TODO: QListView::visualRect() calculates a wrong position of the items under
+ // certain circumstances (e. g. if the text is too long). This issue is bypassed
+ // by the following code (I'll try create a patch for Qt but as Dolphin must also work with
+ // Qt 4.3.0 this workaround must get applied at least for KDE 4.0).
const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
const int margin = settings->gridSpacing();
const int gridWidth = gridSize().width();
KCategorizedView::mousePressEvent(event);
}
+void DolphinIconsView::startDrag(Qt::DropActions supportedActions)
+{
+ // TODO: invoking KCategorizedView::startDrag() should not be necessary, we'll
+ // fix this in KDE 4.1
+ KCategorizedView::startDrag(supportedActions);
+ DragAndDropHelper::startDrag(this, supportedActions);
+}
+
void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls()) {
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
const QModelIndex index = indexAt(event->pos());
setDirtyRegion(m_dropRect);
- if (itemForIndex(index).isDir()) {
- m_dropRect = visualRect(index);
- } else {
- m_dropRect.setSize(QSize()); // set as invalid
+
+ m_dropRect.setSize(QSize()); // set as invalid
+ if (index.isValid()) {
+ const KFileItem item = itemForIndex(index);
+ if (!item.isNull() && item.isDir()) {
+ m_dropRect = visualRect(index);
+ }
}
setDirtyRegion(m_dropRect);
}
}
KCategorizedView::dropEvent(event);
+
m_dragging = false;
}
// 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);
}
}
void DolphinIconsView::slotShowPreviewChanged()
{
const DolphinView* view = m_controller->dolphinView();
- const int infoCount = view->additionalInfo().count();
- updateGridSize(view->showPreview(), infoCount);
+ updateGridSize(view->showPreview(), additionalInfoCount());
}
void DolphinIconsView::slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info)
{
+ const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+ if (!settings->showAdditionalInfo()) {
+ return;
+ }
+
const bool showPreview = m_controller->dolphinView()->showPreview();
updateGridSize(showPreview, info.count());
}
settings->setItemWidth(settings->itemWidth() + diff);
settings->setItemHeight(settings->itemHeight() + diff);
- const int infoCount = m_controller->dolphinView()->additionalInfo().count();
- updateGridSize(showPreview, infoCount);
+ updateGridSize(showPreview, additionalInfoCount());
}
}
settings->setItemWidth(settings->itemWidth() - diff);
settings->setItemHeight(settings->itemHeight() - diff);
- const int infoCount = m_controller->dolphinView()->additionalInfo().count();
- updateGridSize(showPreview, infoCount);
+ updateGridSize(showPreview, additionalInfoCount());
}
}
return dirModel->itemForIndex(dirIndex);
}
+int DolphinIconsView::additionalInfoCount() const
+{
+ const DolphinView* view = m_controller->dolphinView();
+ const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+ return settings->showAdditionalInfo() ? view->additionalInfo().count() : 0;
+}
#include "dolphiniconsview.moc"