2015-12-09 19:21:38 +08:00
|
|
|
#ifndef DROP_OVERLAY_H
|
|
|
|
#define DROP_OVERLAY_H
|
|
|
|
|
2016-04-15 14:21:23 +08:00
|
|
|
#include <QPointer>
|
2016-04-15 18:14:50 +08:00
|
|
|
#include <QHash>
|
2016-02-01 17:55:45 +08:00
|
|
|
#include <QRect>
|
2016-02-26 19:43:14 +08:00
|
|
|
#include <QFrame>
|
2016-04-15 18:14:50 +08:00
|
|
|
class QGridLayout;
|
2015-12-09 19:21:38 +08:00
|
|
|
|
2016-02-02 22:01:48 +08:00
|
|
|
#include "ads/API.h"
|
2015-12-09 19:21:38 +08:00
|
|
|
|
|
|
|
ADS_NAMESPACE_BEGIN
|
2016-04-18 13:06:46 +08:00
|
|
|
class DropOverlayCross;
|
2015-12-09 19:21:38 +08:00
|
|
|
|
2016-04-18 13:18:50 +08:00
|
|
|
/*!
|
|
|
|
* DropOverlay paints a translucent rectangle over another widget. The geometry
|
|
|
|
* of the rectangle is based on the mouse location.
|
|
|
|
*/
|
2015-12-09 19:21:38 +08:00
|
|
|
class DropOverlay : public QFrame
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2016-04-18 13:06:46 +08:00
|
|
|
friend class DropOverlayCross;
|
2015-12-09 19:21:38 +08:00
|
|
|
|
|
|
|
public:
|
2016-04-15 14:21:23 +08:00
|
|
|
DropOverlay(QWidget* parent);
|
2015-12-09 19:21:38 +08:00
|
|
|
virtual ~DropOverlay();
|
2016-04-15 14:21:23 +08:00
|
|
|
|
2016-04-15 18:14:50 +08:00
|
|
|
void setAllowedAreas(DropAreas areas);
|
|
|
|
DropAreas allowedAreas() const;
|
|
|
|
|
2015-12-09 19:21:38 +08:00
|
|
|
DropArea cursorLocation() const;
|
|
|
|
|
2016-04-15 18:14:50 +08:00
|
|
|
DropArea showDropOverlay(QWidget* target);
|
|
|
|
void showDropOverlay(QWidget* target, const QRect& targetAreaRect);
|
2016-04-15 14:21:23 +08:00
|
|
|
void hideDropOverlay();
|
|
|
|
|
2015-12-09 19:21:38 +08:00
|
|
|
protected:
|
|
|
|
virtual void paintEvent(QPaintEvent *e);
|
2016-04-15 18:14:50 +08:00
|
|
|
virtual void showEvent(QShowEvent* e);
|
|
|
|
virtual void hideEvent(QHideEvent* e);
|
2015-12-09 19:21:38 +08:00
|
|
|
virtual void resizeEvent(QResizeEvent* e);
|
|
|
|
virtual void moveEvent(QMoveEvent* e);
|
|
|
|
|
|
|
|
private:
|
2016-04-15 18:14:50 +08:00
|
|
|
DropAreas _allowedAreas;
|
2016-04-18 13:18:50 +08:00
|
|
|
DropOverlayCross* _cross;
|
2015-12-09 19:21:38 +08:00
|
|
|
|
2016-04-15 18:14:50 +08:00
|
|
|
bool _fullAreaDrop;
|
2016-04-15 14:21:23 +08:00
|
|
|
QPointer<QWidget> _target;
|
|
|
|
QRect _targetRect;
|
|
|
|
DropArea _lastLocation;
|
2015-12-09 19:21:38 +08:00
|
|
|
};
|
|
|
|
|
2016-04-18 13:18:50 +08:00
|
|
|
// DropOverlayCross shows a cross with 5 different drop area possibilities.
|
2016-04-18 13:06:46 +08:00
|
|
|
class DropOverlayCross : public QWidget
|
2015-12-09 19:21:38 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-04-18 13:06:46 +08:00
|
|
|
DropOverlayCross(DropOverlay* overlay);
|
2016-04-15 18:14:50 +08:00
|
|
|
void reset();
|
2016-04-15 14:21:23 +08:00
|
|
|
DropArea cursorLocation() const;
|
2016-04-15 18:14:50 +08:00
|
|
|
void setWidgetForArea(QWidget* widget, DropArea area);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void showEvent(QShowEvent* e);
|
2015-12-09 19:21:38 +08:00
|
|
|
|
|
|
|
private:
|
2016-04-15 18:14:50 +08:00
|
|
|
DropOverlay* _overlay;
|
|
|
|
QHash<DropArea, QWidget*> _widgets;
|
|
|
|
QGridLayout* _grid;
|
2015-12-09 19:21:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
ADS_NAMESPACE_END
|
|
|
|
#endif
|