36 lines
846 B
C
36 lines
846 B
C
|
|
// draggabletoolbutton.h
|
||
|
|
#ifndef DRAGGABLETOOLBUTTON_H
|
||
|
|
#define DRAGGABLETOOLBUTTON_H
|
||
|
|
|
||
|
|
#include <QToolButton>
|
||
|
|
|
||
|
|
class DraggableToolButton : public QToolButton
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
explicit DraggableToolButton(QWidget *parent = nullptr);
|
||
|
|
|
||
|
|
void setDragEnabled(bool enabled);
|
||
|
|
bool dragEnabled() const;
|
||
|
|
|
||
|
|
void setToolData(const QString &data);
|
||
|
|
QString toolData() const;
|
||
|
|
|
||
|
|
signals:
|
||
|
|
void dragStarted(const QString &toolData, const QPoint &globalPos);
|
||
|
|
void clicked(); // 自定义点击信号
|
||
|
|
|
||
|
|
protected:
|
||
|
|
void mousePressEvent(QMouseEvent *event) override;
|
||
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||
|
|
|
||
|
|
private:
|
||
|
|
bool m_dragEnabled = true;
|
||
|
|
bool m_isDragging = false;
|
||
|
|
QPoint m_pressPos;
|
||
|
|
QString m_toolData;
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif // DRAGGABLETOOLBUTTON_H
|