Qt-Advanced-Docking-System/AdvancedDockingSystem/include/ads/DropOverlay.h

81 lines
1.7 KiB
C
Raw Normal View History

2015-12-09 19:21:38 +08:00
#ifndef DROP_OVERLAY_H
#define DROP_OVERLAY_H
#include <QPointer>
#include <QHash>
#include <QRect>
#include <QFrame>
class QGridLayout;
2015-12-09 19:21:38 +08:00
#include "ads/API.h"
2015-12-09 19:21:38 +08:00
ADS_NAMESPACE_BEGIN
class DropOverlayCross;
2015-12-09 19:21:38 +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
friend class DropOverlayCross;
2015-12-09 19:21:38 +08:00
public:
DropOverlay(QWidget* parent);
2015-12-09 19:21:38 +08:00
virtual ~DropOverlay();
void setAllowedAreas(DropAreas areas);
DropAreas allowedAreas() const;
2015-12-09 19:21:38 +08:00
DropArea cursorLocation() const;
DropArea showDropOverlay(QWidget* target);
void showDropOverlay(QWidget* target, const QRect& targetAreaRect);
void hideDropOverlay();
2015-12-09 19:21:38 +08:00
protected:
virtual void paintEvent(QPaintEvent *e);
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:
DropAreas _allowedAreas;
DropOverlayCross* _cross;
2015-12-09 19:21:38 +08:00
bool _fullAreaDrop;
QPointer<QWidget> _target;
QRect _targetRect;
DropArea _lastLocation;
2015-12-09 19:21:38 +08:00
};
// DropOverlayCross shows a cross with 5 different drop area possibilities.
class DropOverlayCross : public QWidget
2015-12-09 19:21:38 +08:00
{
Q_OBJECT
friend class DropOverlay;
2015-12-09 19:21:38 +08:00
public:
DropOverlayCross(DropOverlay* overlay);
virtual ~DropOverlayCross();
void setAreaWidgets(const QHash<DropArea, QWidget*>& widgets);
DropArea cursorLocation() const;
protected:
virtual void showEvent(QShowEvent* e);
2015-12-09 19:21:38 +08:00
private:
void reset();
2015-12-09 19:21:38 +08:00
private:
DropOverlay* _overlay;
QHash<DropArea, QWidget*> _widgets;
QGridLayout* _grid;
2015-12-09 19:21:38 +08:00
};
ADS_NAMESPACE_END
#endif