2011-07-05 21:13:22 +02:00
|
|
|
/*
|
2012-05-04 14:01:29 +02:00
|
|
|
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
|
|
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
2011-07-05 21:13:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DECLARATIVEDRAGAREA_H
|
|
|
|
#define DECLARATIVEDRAGAREA_H
|
|
|
|
|
|
|
|
#include <QDeclarativeItem>
|
|
|
|
|
|
|
|
class QDeclarativeComponent;
|
|
|
|
class DeclarativeMimeData;
|
|
|
|
|
|
|
|
class DeclarativeDragArea : public QDeclarativeItem
|
|
|
|
{
|
2012-01-10 13:32:41 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The delegate is the item that will be displayed next to the mouse cursor during the drag and drop operation.
|
|
|
|
* It usually consists of a large, semi-transparent icon representing the data being dragged.
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(QDeclarativeComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged RESET resetDelegate)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The QML element that is the source of the resulting drag and drop operation. This can be defined to any item, and will
|
|
|
|
* be available to the DropArea as event.data.source
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(QDeclarativeItem* source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource)
|
|
|
|
|
|
|
|
//TODO: to be implemented
|
|
|
|
Q_PROPERTY(QDeclarativeItem* target READ source NOTIFY targetChanged)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the mime data of the drag operation
|
|
|
|
* @see DeclarativeMimeData
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(DeclarativeMimeData* mimeData READ mimeData CONSTANT)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If false no drag operation will be generate
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) //TODO: Should call setAcceptDrops()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Supported operations, a combination of
|
|
|
|
* Qt.CopyAction
|
|
|
|
* Qt.MoveAction
|
|
|
|
* Qt.LinkAction
|
|
|
|
* Qt.ActionMask
|
|
|
|
* Qt.IgnoreAction
|
|
|
|
* Qt.TargetMoveAction
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default action will be performed during a drag when no modificators are pressed.
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(Qt::DropAction defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaultActionChanged)
|
2011-07-05 21:13:22 +02:00
|
|
|
|
2012-03-02 14:14:21 +01:00
|
|
|
/**
|
|
|
|
* distance in pixel after which a drag event will get started
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance NOTIFY startDragDistanceChanged)
|
2011-07-05 21:13:22 +02:00
|
|
|
|
2012-03-02 15:07:29 +01:00
|
|
|
/**
|
|
|
|
* an image to be used as delegate. if present overrides the delegate property. in can be either a QImage or a QIcon
|
|
|
|
*/
|
|
|
|
Q_PROPERTY(QVariant delegateImage READ delegateImage WRITE setDelegateImage NOTIFY delegateImageChanged)
|
|
|
|
|
2011-07-05 21:13:22 +02:00
|
|
|
public:
|
2012-05-04 14:01:29 +02:00
|
|
|
DeclarativeDragArea(QDeclarativeItem *parent=0);
|
|
|
|
~DeclarativeDragArea();
|
2011-07-05 21:13:22 +02:00
|
|
|
|
2012-05-04 14:01:29 +02:00
|
|
|
QDeclarativeComponent *delegate() const;
|
|
|
|
void setDelegate(QDeclarativeComponent* delegate);
|
|
|
|
void resetDelegate();
|
2011-07-05 21:13:22 +02:00
|
|
|
|
2012-03-02 15:07:29 +01:00
|
|
|
QVariant delegateImage() const;
|
|
|
|
void setDelegateImage(const QVariant &image);
|
2012-05-04 14:01:29 +02:00
|
|
|
QDeclarativeItem* target() const;
|
|
|
|
QDeclarativeItem* source() const;
|
|
|
|
void setSource(QDeclarativeItem* source);
|
|
|
|
void resetSource();
|
2011-07-05 21:13:22 +02:00
|
|
|
|
2012-05-04 14:01:29 +02:00
|
|
|
bool isEnabled() const;
|
|
|
|
void setEnabled(bool enabled);
|
2011-07-05 21:13:22 +02:00
|
|
|
|
2012-03-02 14:14:21 +01:00
|
|
|
int startDragDistance() const;
|
|
|
|
void setStartDragDistance(int distance);
|
|
|
|
|
2012-05-04 14:01:29 +02:00
|
|
|
//supported actions
|
|
|
|
Qt::DropActions supportedActions() const;
|
|
|
|
void setSupportedActions(Qt::DropActions actions);
|
2011-07-05 21:13:22 +02:00
|
|
|
|
2012-05-04 14:01:29 +02:00
|
|
|
//default action
|
|
|
|
Qt::DropAction defaultAction() const;
|
|
|
|
void setDefaultAction(Qt::DropAction action);
|
2011-07-05 21:13:22 +02:00
|
|
|
|
2012-05-04 14:01:29 +02:00
|
|
|
DeclarativeMimeData* mimeData() const;
|
2011-07-05 21:13:22 +02:00
|
|
|
|
|
|
|
signals:
|
2012-05-04 14:01:29 +02:00
|
|
|
void delegateChanged();
|
|
|
|
void sourceChanged();
|
|
|
|
void targetChanged();
|
|
|
|
void dataChanged();
|
|
|
|
void enabledChanged();
|
|
|
|
void drop(int action);
|
|
|
|
void supportedActionsChanged();
|
|
|
|
void defaultActionChanged();
|
2012-03-02 14:14:21 +01:00
|
|
|
void startDragDistanceChanged();
|
2012-03-02 15:07:29 +01:00
|
|
|
void delegateImageChanged();
|
2011-07-05 21:13:22 +02:00
|
|
|
|
|
|
|
protected:
|
2012-05-04 14:01:29 +02:00
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *) {}
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) {}
|
|
|
|
bool sceneEventFilter(QGraphicsItem *item, QEvent *event);
|
2011-07-05 21:13:22 +02:00
|
|
|
|
|
|
|
private:
|
2012-05-04 14:01:29 +02:00
|
|
|
QDeclarativeComponent* m_delegate;
|
|
|
|
QDeclarativeItem* m_source;
|
|
|
|
QDeclarativeItem* m_target;
|
|
|
|
bool m_enabled;
|
|
|
|
Qt::DropActions m_supportedActions;
|
|
|
|
Qt::DropAction m_defaultAction;
|
|
|
|
DeclarativeMimeData* const m_data;
|
2012-03-02 15:07:29 +01:00
|
|
|
QImage m_delegateImage;
|
2012-03-02 14:14:21 +01:00
|
|
|
int m_startDragDistance;
|
2011-07-05 21:13:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DECLARATIVEDRAGAREA_H
|