configurable start drag distance
This commit is contained in:
parent
1471d27cfa
commit
a299c18ddc
@ -45,6 +45,7 @@ DeclarativeDragArea::DeclarativeDragArea(QDeclarativeItem *parent)
|
|||||||
m_defaultAction(Qt::MoveAction),
|
m_defaultAction(Qt::MoveAction),
|
||||||
m_data(new DeclarativeMimeData()) // m_data is owned by us, and we shouldn't pass it to Qt directly as it will automatically delete it after the drag and drop.
|
m_data(new DeclarativeMimeData()) // m_data is owned by us, and we shouldn't pass it to Qt directly as it will automatically delete it after the drag and drop.
|
||||||
{
|
{
|
||||||
|
m_startDragDistance = QApplication::startDragDistance();
|
||||||
setAcceptedMouseButtons(Qt::LeftButton);
|
setAcceptedMouseButtons(Qt::LeftButton);
|
||||||
setFiltersChildEvents(true);
|
setFiltersChildEvents(true);
|
||||||
}
|
}
|
||||||
@ -109,6 +110,22 @@ DeclarativeMimeData* DeclarativeDragArea::mimeData() const
|
|||||||
return m_data;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// startDragDistance
|
||||||
|
int DeclarativeDragArea::startDragDistance() const
|
||||||
|
{
|
||||||
|
return m_startDragDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeDragArea::setStartDragDistance(int distance)
|
||||||
|
{
|
||||||
|
if (distance == m_startDragDistance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_startDragDistance = distance;
|
||||||
|
emit startDragDistanceChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// enabled
|
// enabled
|
||||||
bool DeclarativeDragArea::isEnabled() const
|
bool DeclarativeDragArea::isEnabled() const
|
||||||
{
|
{
|
||||||
@ -152,7 +169,7 @@ void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
{
|
{
|
||||||
if ( !m_enabled
|
if ( !m_enabled
|
||||||
|| QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length()
|
|| QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length()
|
||||||
< QApplication::startDragDistance()) {
|
< m_startDragDistance) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +192,8 @@ void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
QPainter painter(&pixmap);
|
QPainter painter(&pixmap);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
scene.render(&painter);
|
scene.render(&painter);
|
||||||
|
painter.end();
|
||||||
|
delete item;
|
||||||
|
|
||||||
drag->setPixmap(pixmap);
|
drag->setPixmap(pixmap);
|
||||||
drag->setHotSpot(QPoint(0, 0)); // TODO: Make a property for that
|
drag->setHotSpot(QPoint(0, 0)); // TODO: Make a property for that
|
||||||
@ -186,7 +205,6 @@ void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
emit drop(action);
|
emit drop(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool DeclarativeDragArea::sceneEventFilter(QGraphicsItem *item, QEvent *event)
|
bool DeclarativeDragArea::sceneEventFilter(QGraphicsItem *item, QEvent *event)
|
||||||
{
|
{
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
|
@ -75,6 +75,10 @@ class DeclarativeDragArea : public QDeclarativeItem
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(Qt::DropAction defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaultActionChanged)
|
Q_PROPERTY(Qt::DropAction defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaultActionChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* distance in pixel after which a drag event will get started
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance NOTIFY startDragDistanceChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DeclarativeDragArea(QDeclarativeItem *parent=0);
|
DeclarativeDragArea(QDeclarativeItem *parent=0);
|
||||||
@ -92,6 +96,9 @@ public:
|
|||||||
bool isEnabled() const;
|
bool isEnabled() const;
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
|
int startDragDistance() const;
|
||||||
|
void setStartDragDistance(int distance);
|
||||||
|
|
||||||
//supported actions
|
//supported actions
|
||||||
Qt::DropActions supportedActions() const;
|
Qt::DropActions supportedActions() const;
|
||||||
void setSupportedActions(Qt::DropActions actions);
|
void setSupportedActions(Qt::DropActions actions);
|
||||||
@ -111,6 +118,7 @@ signals:
|
|||||||
void drop(int action);
|
void drop(int action);
|
||||||
void supportedActionsChanged();
|
void supportedActionsChanged();
|
||||||
void defaultActionChanged();
|
void defaultActionChanged();
|
||||||
|
void startDragDistanceChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
@ -126,6 +134,7 @@ private:
|
|||||||
Qt::DropActions m_supportedActions;
|
Qt::DropActions m_supportedActions;
|
||||||
Qt::DropAction m_defaultAction;
|
Qt::DropAction m_defaultAction;
|
||||||
DeclarativeMimeData* const m_data;
|
DeclarativeMimeData* const m_data;
|
||||||
|
int m_startDragDistance;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DECLARATIVEDRAGAREA_H
|
#endif // DECLARATIVEDRAGAREA_H
|
||||||
|
Loading…
Reference in New Issue
Block a user