46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
// enhancedtoolbar.h
|
|
#ifndef ENHANCEDTOOLBAR_H
|
|
#define ENHANCEDTOOLBAR_H
|
|
|
|
#include <QToolBar>
|
|
#include <QMap>
|
|
|
|
class DraggableToolButton;
|
|
|
|
class EnhancedToolBar : public QToolBar
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit EnhancedToolBar(QWidget *parent = nullptr);
|
|
|
|
// 添加工具
|
|
void addTool(const QString &toolType, const QString &toolName,
|
|
const QIcon &icon = QIcon());
|
|
|
|
// 获取当前选中的工具
|
|
QString currentTool() const;
|
|
|
|
// 设置当前工具
|
|
void setCurrentTool(const QString &toolType);
|
|
|
|
// 启用/禁用拖拽
|
|
void setDragEnabled(bool enabled);
|
|
bool dragEnabled() const;
|
|
|
|
signals:
|
|
void toolSelected(const QString &toolType);
|
|
void toolDragged(const QString &toolType, const QPoint &globalPos);
|
|
|
|
private slots:
|
|
void onToolButtonClicked();
|
|
void onToolButtonDragStarted(const QString &toolData, const QPoint &globalPos);
|
|
void startDrag(const QString &toolType, const QPoint &globalPos);
|
|
|
|
private:
|
|
QMap<QString, DraggableToolButton*> m_buttons;
|
|
QString m_currentTool;
|
|
bool m_dragEnabled = true;
|
|
};
|
|
|
|
#endif // ENHANCEDTOOLBAR_H
|