As the Qt-issue 160611 is solved in Qt4.4 and Fredrik has improved KFileItemDelegate, it is not necessary anymore drawing a custom drag & drop indication.

svn path=/trunk/KDE/kdebase/apps/; revision=784851
This commit is contained in:
Peter Penz 2008-03-12 16:49:55 +00:00
parent 9cd5e1f965
commit 38fa728aa6
10 changed files with 7 additions and 128 deletions

View file

@ -60,7 +60,6 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
m_dolphinModel(0),
m_proxyModel(0),
m_iconManager(0),
m_dragging(false),
m_dropRect()
{
setMouseTracking(true);
@ -251,16 +250,11 @@ void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event)
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
m_dragging = true;
}
void DolphinColumnWidget::dragLeaveEvent(QDragLeaveEvent* event)
{
QListView::dragLeaveEvent(event);
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
m_dragging = false;
setDirtyRegion(m_dropRect);
}
@ -301,7 +295,6 @@ void DolphinColumnWidget::dropEvent(QDropEvent* event)
event->acceptProposedAction();
}
QListView::dropEvent(event);
m_dragging = false;
}
void DolphinColumnWidget::paintEvent(QPaintEvent* event)
@ -326,12 +319,6 @@ void DolphinColumnWidget::paintEvent(QPaintEvent* event)
}
QListView::paintEvent(event);
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
if (m_dragging) {
const QBrush& brush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight);
DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush);
}
}
void DolphinColumnWidget::mousePressEvent(QMouseEvent* event)

View file

@ -139,8 +139,7 @@ private:
IconManager* m_iconManager;
bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
QRect m_dropRect;
};
inline bool DolphinColumnWidget::isActive() const

View file

@ -49,7 +49,6 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
m_controller(controller),
m_font(),
m_decorationSize(),
m_dragging(false),
m_showElasticBand(false),
m_elasticBandOrigin(),
m_elasticBandDestination()
@ -261,15 +260,11 @@ void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
updateElasticBand();
m_showElasticBand = false;
}
m_dragging = true;
}
void DolphinDetailsView::dragLeaveEvent(QDragLeaveEvent* event)
{
QTreeView::dragLeaveEvent(event);
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
m_dragging = false;
setDirtyRegion(m_dropRect);
}
@ -280,10 +275,7 @@ void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
setDirtyRegion(m_dropRect);
const QModelIndex index = indexAt(event->pos());
if (!index.isValid() || (index.column() != DolphinModel::Name)) {
m_dragging = false;
} else {
m_dragging = true;
if (index.isValid() && (index.column() == DolphinModel::Name)) {
const KFileItem item = m_controller->itemForIndex(index);
if (!item.isNull() && item.isDir()) {
m_dropRect = visualRect(index);
@ -314,7 +306,6 @@ void DolphinDetailsView::dropEvent(QDropEvent* event)
item);
}
QTreeView::dropEvent(event);
m_dragging = false;
}
void DolphinDetailsView::paintEvent(QPaintEvent* event)
@ -335,12 +326,6 @@ void DolphinDetailsView::paintEvent(QPaintEvent* event)
style()->drawControl(QStyle::CE_RubberBand, &opt, &painter);
painter.restore();
}
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
if (m_dragging) {
const QBrush& brush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight);
DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush);
}
}
void DolphinDetailsView::keyPressEvent(QKeyEvent* event)

View file

@ -161,8 +161,7 @@ private:
QFont m_font;
QSize m_decorationSize;
bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
QRect m_dropRect;
bool m_showElasticBand;
QPoint m_elasticBandOrigin;

View file

@ -46,7 +46,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
m_decorationPosition(QStyleOptionViewItem::Top),
m_displayAlignment(Qt::AlignHCenter),
m_itemSize(),
m_dragging(false),
m_dropRect()
{
Q_ASSERT(controller != 0);
@ -57,9 +56,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
setDragEnabled(true);
viewport()->setAcceptDrops(true);
setMouseTracking(true);
viewport()->setAttribute(Qt::WA_Hover);
// 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' and to handle the
@ -221,15 +217,11 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
m_dragging = true;
}
void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event)
{
KCategorizedView::dragLeaveEvent(event);
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
m_dragging = false;
setDirtyRegion(m_dropRect);
}
@ -273,19 +265,6 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
}
KCategorizedView::dropEvent(event);
m_dragging = false;
}
void DolphinIconsView::paintEvent(QPaintEvent* event)
{
KCategorizedView::paintEvent(event);
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
if (m_dragging) {
const QBrush& brush = viewOptions().palette.brush(QPalette::Normal, QPalette::Highlight);
DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush);
}
}
void DolphinIconsView::keyPressEvent(QKeyEvent* event)

View file

@ -60,7 +60,6 @@ protected:
virtual void dragLeaveEvent(QDragLeaveEvent* event);
virtual void dragMoveEvent(QDragMoveEvent* event);
virtual void dropEvent(QDropEvent* event);
virtual void paintEvent(QPaintEvent* event);
virtual void keyPressEvent(QKeyEvent* event);
virtual void wheelEvent(QWheelEvent* event);
@ -104,9 +103,7 @@ private:
Qt::Alignment m_displayAlignment;
QSize m_itemSize;
bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
QRect m_dropRect;
};
#endif

View file

@ -25,11 +25,7 @@
#include <QAbstractItemView>
#include <QAbstractProxyModel>
#include <QBrush>
#include <QDrag>
#include <QPainter>
#include <QRect>
#include <QWidget>
void DragAndDropHelper::startDrag(QAbstractItemView* itemView, Qt::DropActions supportedActions)
{
@ -57,40 +53,3 @@ void DragAndDropHelper::startDrag(QAbstractItemView* itemView, Qt::DropActions s
drag->exec(supportedActions, Qt::IgnoreAction);
}
}
void DragAndDropHelper::drawHoverIndication(QAbstractItemView* itemView,
const QRect& bounds,
const QBrush& brush)
{
if (bounds.isEmpty()) {
return;
}
QWidget* widget = itemView->viewport();
QPainter painter(widget);
painter.save();
QBrush blendedBrush(brush);
QColor color = blendedBrush.color();
color.setAlpha(64);
blendedBrush.setColor(color);
if (dynamic_cast<DolphinIconsView*>(itemView)) {
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);
} else {
painter.fillRect(bounds, blendedBrush);
}
painter.restore();
}

View file

@ -28,7 +28,7 @@ class QRect;
class QWidget;
/**
* @brief Helper class to bypass some drag & drop limitations in Qt.
* @brief Helper class for having a common drag and drop behavior.
*
* The class is used by DolphinIconsView, DolphinDetailsView,
* DolphinColumnView and SidebarTreeView to have a consistent
@ -42,11 +42,6 @@ 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(QAbstractItemView* itemView,
const QRect& bounds,
const QBrush& brush);
};
#endif

View file

@ -30,8 +30,7 @@
#include <QScrollBar>
SidebarTreeView::SidebarTreeView(QWidget* parent) :
QTreeView(parent),
m_dragging(false)
QTreeView(parent)
{
setAcceptDrops(true);
setUniformRowHeights(true);
@ -95,20 +94,14 @@ void SidebarTreeView::startDrag(Qt::DropActions supportedActions)
void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
{
QTreeView::dragEnterEvent(event);
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
m_dragging = true;
}
void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event)
{
QTreeView::dragLeaveEvent(event);
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
m_dragging = false;
setDirtyRegion(m_dropRect);
}
@ -140,18 +133,6 @@ void SidebarTreeView::dropEvent(QDropEvent* event)
emit urlsDropped(urls, index);
}
}
m_dragging = false;
}
void SidebarTreeView::paintEvent(QPaintEvent* event)
{
QTreeView::paintEvent(event);
// 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);
DragAndDropHelper::drawHoverIndication(this, m_dropRect, brush);
}
}
#include "sidebartreeview.moc"

View file

@ -51,11 +51,9 @@ protected:
virtual void dragLeaveEvent(QDragLeaveEvent* event);
virtual void dragMoveEvent(QDragMoveEvent* event);
virtual void dropEvent(QDropEvent* event);
virtual void paintEvent(QPaintEvent* event);
private:
bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
QRect m_dropRect;
};
#endif