m_dolphinModel(0),
m_proxyModel(0),
m_iconManager(0),
- m_dragging(false),
m_dropRect()
{
setMouseTracking(true);
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);
}
event->acceptProposedAction();
}
QListView::dropEvent(event);
- m_dragging = false;
}
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)
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
m_controller(controller),
m_font(),
m_decorationSize(),
- m_dragging(false),
m_showElasticBand(false),
m_elasticBandOrigin(),
m_elasticBandDestination()
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);
}
// 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);
item);
}
QTreeView::dropEvent(event);
- m_dragging = false;
}
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)
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;
m_decorationPosition(QStyleOptionViewItem::Top),
m_displayAlignment(Qt::AlignHCenter),
m_itemSize(),
- m_dragging(false),
m_dropRect()
{
Q_ASSERT(controller != 0);
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
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);
}
}
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)
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);
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
#include <QAbstractItemView>
#include <QAbstractProxyModel>
-#include <QBrush>
#include <QDrag>
-#include <QPainter>
-#include <QRect>
-#include <QWidget>
void DragAndDropHelper::startDrag(QAbstractItemView* itemView, Qt::DropActions supportedActions)
{
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();
-}
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
* 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
#include <QScrollBar>
SidebarTreeView::SidebarTreeView(QWidget* parent) :
- QTreeView(parent),
- m_dragging(false)
+ QTreeView(parent)
{
setAcceptDrops(true);
setUniformRowHeights(true);
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);
}
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"
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