dolphiniconsview.cpp
dolphincolumnview.cpp
dolphincolumnwidget.cpp
+ draganddrophelper.cpp
kcategorizedview.cpp
kcategorydrawer.cpp
dolphinmodel.cpp
dolphindirlister.cpp
dolphincontextmenu.cpp
dolphinsettingsdialog.cpp
+ draganddrophelper.cpp
filterbar.cpp
generalsettingspage.cpp
generalviewsettingspage.cpp
#include "dolphinmodel.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinsettings.h"
-
#include "dolphin_columnmodesettings.h"
+#include "draganddrophelper.h"
#include <kcolorutils.h>
#include <kcolorscheme.h>
m_proxyModel->setFilterRegExp(nameFilter);
}
+void DolphinColumnWidget::startDrag(Qt::DropActions supportedActions)
+{
+ DragAndDropHelper::startDrag(this, supportedActions);
+}
+
void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls()) {
// 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);
}
}
protected:
virtual QStyleOptionViewItem viewOptions() const;
+ virtual void startDrag(Qt::DropActions supportedActions);
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dragLeaveEvent(QDragLeaveEvent* event);
virtual void dragMoveEvent(QDragMoveEvent* event);
#include "dolphincontroller.h"
-#include <QPainter>
-
DolphinController::DolphinController(DolphinView* dolphinView) :
QObject(dolphinView),
m_zoomInPossible(false),
emit zoomOut();
}
-void DolphinController::drawHoverIndication(QWidget* widget,
- const QRect& bounds,
- const QBrush& brush)
-{
- QPainter painter(widget);
- painter.save();
- QBrush blendedBrush(brush);
- QColor color = blendedBrush.color();
- color.setAlpha(64);
- blendedBrush.setColor(color);
-
- const int radius = 10;
- QPainterPath path(QPointF(bounds.left(), bounds.top() + radius));
- path.quadTo(bounds.left(), bounds.top(), bounds.left() + radius, bounds.top());
- path.lineTo(bounds.right() - radius, bounds.top());
- path.quadTo(bounds.right(), bounds.top(), bounds.right(), bounds.top() + radius);
- path.lineTo(bounds.right(), bounds.bottom() - radius);
- path.quadTo(bounds.right(), bounds.bottom(), bounds.right() - radius, bounds.bottom());
- path.lineTo(bounds.left() + radius, bounds.bottom());
- path.quadTo(bounds.left(), bounds.bottom(), bounds.left(), bounds.bottom() - radius);
- path.closeSubpath();
-
- painter.setRenderHint(QPainter::Antialiasing);
- painter.fillPath(path, blendedBrush);
- painter.restore();
-}
-
void DolphinController::triggerItem(const KFileItem& item)
{
emit itemTriggered(item);
void setZoomOutPossible(bool possible);
bool isZoomOutPossible() const;
- // TODO: remove this method when the issue #160611 is solved in Qt 4.4
- static void drawHoverIndication(QWidget* widget,
- const QRect& bounds,
- const QBrush& brush);
-
public slots:
/**
* Emits the signal itemTriggered(). The method should be invoked by the
#include "dolphincontroller.h"
#include "dolphinsettings.h"
#include "dolphinsortfilterproxymodel.h"
+#include "draganddrophelper.h"
#include "viewproperties.h"
#include "dolphin_detailsmodesettings.h"
}
}
+void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
+{
+ DragAndDropHelper::startDrag(this, supportedActions);
+}
+
void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls()) {
// 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);
}
}
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
+ virtual void startDrag(Qt::DropActions supportedActions);
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dragLeaveEvent(QDragLeaveEvent* event);
virtual void dragMoveEvent(QDragMoveEvent* event);
#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);
itemRect.setHeight(maxHeight);
}
- 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.
+ if (leftToRightFlow && bypassVisualRectIssue()) {
+ // TODO: check inline comment inside bypassVisualRectIssue() for details
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)
+{
+ if (bypassVisualRectIssue()) {
+ // TODO: check inline comment inside bypassVisualRectIssue() for details
+ DragAndDropHelper::startDrag(this, supportedActions);
+ } else {
+ KCategorizedView::startDrag(supportedActions);
+ }
+}
+
void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls()) {
void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
{
- KCategorizedView::dragLeaveEvent(event);
+ if (bypassVisualRectIssue()) {
+ // TODO: check inline comment inside bypassVisualRectIssue() for details
+ QAbstractItemView::dragLeaveEvent(event);
+ } else {
+ KCategorizedView::dragLeaveEvent(event);
+ }
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
m_dragging = false;
void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
{
- KCategorizedView::dragMoveEvent(event);
+ if (bypassVisualRectIssue()) {
+ // TODO: check inline comment inside bypassVisualRectIssue() for details
+ QAbstractItemView::dragMoveEvent(event);
+ } else {
+ KCategorizedView::dragMoveEvent(event);
+ }
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
const QModelIndex index = indexAt(event->pos());
}
}
- KCategorizedView::dropEvent(event);
+ if (bypassVisualRectIssue()) {
+ // TODO: check inline comment inside bypassVisualRectIssue() for details
+ QAbstractItemView::dropEvent(event);
+ } else {
+ 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);
}
}
return dirModel->itemForIndex(dirIndex);
}
+bool DolphinIconsView::bypassVisualRectIssue() const
+{
+ // 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
+ // inside DolphinIconsView::visualRect(), but internally QListView does not use
+ // visualRect() but the (non-virtual) QListView::rectForIndex(). This leads
+ // to problems in combination with drag & drop operations: visual fragments get
+ // created. To bypass the drag & drop issue the calls for QListView::dragMoveEvent(),
+ // QListView::dropEvent() are replaced by the QAbstractItemView counterparts and
+ // QAbstractItemView::startDrag() has been reimplemented.
+ //
+ // 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.
+ KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model());
+ return !proxyModel->isCategorizedModel();
+}
#include "dolphiniconsview.moc"
virtual QStyleOptionViewItem viewOptions() const;
virtual void contextMenuEvent(QContextMenuEvent* event);
virtual void mousePressEvent(QMouseEvent* event);
+ virtual void startDrag(Qt::DropActions supportedActions);
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dragLeaveEvent(QDragLeaveEvent* event);
virtual void dragMoveEvent(QDragMoveEvent* event);
KFileItem itemForIndex(const QModelIndex& index) const;
+ /**
+ * Returns true, if the QListView-issue in QListView::visualRect()
+ * must be bypassed. TODO: this method is only temporary to have
+ * a usable drag & drop behavior until the issue in Qt is fixed.
+ */
+ bool bypassVisualRectIssue() const;
+
private:
DolphinController* m_controller;
DolphinCategoryDrawer* m_categoryDrawer;
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "draganddrophelper.h"
+
+#include <kdirmodel.h>
+#include <kicon.h>
+
+#include <QAbstractItemView>
+#include <QAbstractProxyModel>
+#include <QBrush>
+#include <QDrag>
+#include <QPainter>
+#include <QRect>
+#include <QWidget>
+
+void DragAndDropHelper::startDrag(QAbstractItemView* itemView, Qt::DropActions supportedActions)
+{
+ QModelIndexList indexes = itemView->selectionModel()->selectedIndexes();
+ if (indexes.count() > 0) {
+ QMimeData *data = itemView->model()->mimeData(indexes);
+ if (data == 0) {
+ return;
+ }
+
+ QDrag* drag = new QDrag(itemView);
+ QPixmap pixmap;
+ if (indexes.count() == 1) {
+ QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(itemView->model());
+ KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+ const QModelIndex index = proxyModel->mapToSource(indexes.first());
+
+ const KFileItem item = dirModel->itemForIndex(index);
+ pixmap = item.pixmap(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
+ } else {
+ pixmap = KIcon("item-drag-multiple").pixmap(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
+ }
+ drag->setPixmap(pixmap);
+ drag->setMimeData(data);
+ drag->exec(supportedActions);
+ }
+}
+
+void DragAndDropHelper::drawHoverIndication(QWidget* widget,
+ const QRect& bounds,
+ const QBrush& brush)
+{
+ QPainter painter(widget);
+ painter.save();
+ QBrush blendedBrush(brush);
+ QColor color = blendedBrush.color();
+ color.setAlpha(64);
+ blendedBrush.setColor(color);
+
+ const int radius = 10;
+ QPainterPath path(QPointF(bounds.left(), bounds.top() + radius));
+ path.quadTo(bounds.left(), bounds.top(), bounds.left() + radius, bounds.top());
+ path.lineTo(bounds.right() - radius, bounds.top());
+ path.quadTo(bounds.right(), bounds.top(), bounds.right(), bounds.top() + radius);
+ path.lineTo(bounds.right(), bounds.bottom() - radius);
+ path.quadTo(bounds.right(), bounds.bottom(), bounds.right() - radius, bounds.bottom());
+ path.lineTo(bounds.left() + radius, bounds.bottom());
+ path.quadTo(bounds.left(), bounds.bottom(), bounds.left(), bounds.bottom() - radius);
+ path.closeSubpath();
+
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.fillPath(path, blendedBrush);
+ painter.restore();
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef DRAGANDDROPHELPER_H
+#define DRAGANDDROPHELPER_H
+
+#include <Qt>
+
+class QAbstractItemView;
+class QBrush;
+class QRect;
+class QWidget;
+
+/**
+ * @brief Helper class to bypass some drag & drop limitations in Qt.
+ *
+ * The class is used by DolphinIconsView, DolphinDetailsView,
+ * DolphinColumnView and SidebarTreeView to have a consistent
+ * drag and drop behavior between all views.
+ */
+class DragAndDropHelper
+{
+
+public:
+ /**
+ * Creates a drag object for the view \a itemView for all selected items.
+ */
+ static void startDrag(QAbstractItemView* itemView, Qt::DropActions supportedActions);
+
+ // TODO: remove this method when the issue #160611 is solved in Qt 4.4
+ static void drawHoverIndication(QWidget* widget,
+ const QRect& bounds,
+ const QBrush& brush);
+};
+
+#endif
#include "dolphincontroller.h"
#include "dolphinmodel.h"
+#include "draganddrophelper.h"
#include <kfileitemdelegate.h>
#include <QKeyEvent>
return QTreeView::event(event);
}
+void SidebarTreeView::startDrag(Qt::DropActions supportedActions)
+{
+ DragAndDropHelper::startDrag(this, supportedActions);
+}
+
void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls()) {
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
if (m_dragging) {
const QBrush& brush = palette().brush(QPalette::Normal, QPalette::Highlight);
- DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
+ DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
}
}
protected:
virtual bool event(QEvent* event);
+ virtual void startDrag(Qt::DropActions supportedActions);
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dragLeaveEvent(QDragLeaveEvent* event);
virtual void dragMoveEvent(QDragMoveEvent* event);