55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#ifndef ENHANCEDTOOLBAR_H
|
|
#define ENHANCEDTOOLBAR_H
|
|
|
|
#include <QToolBar>
|
|
#include <QActionGroup>
|
|
#include <QMap>
|
|
|
|
class EnhancedToolBar : public QToolBar
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit EnhancedToolBar(const QString &title, QWidget *parent = nullptr);
|
|
explicit EnhancedToolBar(QWidget *parent = nullptr);
|
|
|
|
// 工具管理接口
|
|
void addTool(const QString &toolType, const QString &toolName,
|
|
const QIcon &icon = QIcon());
|
|
void removeTool(const QString &toolType);
|
|
void setCurrentTool(const QString &toolType);
|
|
QString currentTool() const;
|
|
|
|
// 获取工具信息
|
|
QString toolName(const QString &toolType) const;
|
|
QIcon toolIcon(const QString &toolType) const;
|
|
QStringList availableTools() const;
|
|
|
|
// 批量操作
|
|
void clearTools();
|
|
void addTools(const QList<QPair<QString, QString>> &tools);
|
|
|
|
signals:
|
|
void toolSelected(const QString &toolType);
|
|
void toolAdded(const QString &toolType);
|
|
void toolRemoved(const QString &toolType);
|
|
|
|
protected:
|
|
virtual QAction* createAction(const QString &toolType,
|
|
const QString &toolName,
|
|
const QIcon &icon);
|
|
|
|
private slots:
|
|
void onActionTriggered(QAction *action);
|
|
|
|
private:
|
|
void init();
|
|
|
|
QActionGroup *m_actionGroup;
|
|
QMap<QString, QAction*> m_actions;
|
|
QMap<QAction*, QString> m_actionToType; // 反向映射
|
|
QString m_currentTool;
|
|
};
|
|
|
|
#endif
|