119 lines
2.7 KiB
C++
119 lines
2.7 KiB
C++
|
|
|
|
#pragma once
|
|
#include "lts_widgets_export.h"
|
|
|
|
#include <QMap>
|
|
#include <QObject>
|
|
#include <QShortcut>
|
|
#include <QVector>
|
|
#include <QWidget>
|
|
|
|
class QMenu;
|
|
class QLabel;
|
|
|
|
namespace Ui
|
|
{
|
|
class LtsToolBarArea;
|
|
}
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
class LtsDragIcon;
|
|
|
|
struct ShortCut
|
|
{
|
|
int key = 0;
|
|
QShortcut* shortcut = nullptr;
|
|
QString name;
|
|
QString identifier;
|
|
LtsDragIcon* icon = nullptr;
|
|
|
|
QString keyName() const
|
|
{
|
|
return shortcut ? shortcut->key().toString() : QString();
|
|
}
|
|
|
|
void clear();
|
|
|
|
explicit ShortCut(QWidget* parent = nullptr) : shortcut(new QShortcut(parent)) {}
|
|
|
|
~ShortCut()
|
|
{
|
|
delete shortcut;
|
|
}
|
|
|
|
ShortCut(const ShortCut& o) : key(o.key), name(o.name), identifier(o.identifier), icon(o.icon)
|
|
{
|
|
if (o.shortcut)
|
|
{
|
|
delete shortcut;
|
|
shortcut = new QShortcut(o.shortcut->key(), qobject_cast<QWidget*>(o.shortcut->parent()), nullptr, nullptr,
|
|
o.shortcut->context());
|
|
}
|
|
}
|
|
|
|
ShortCut& operator=(const ShortCut& o)
|
|
{
|
|
if (&o == this)
|
|
return *this;
|
|
|
|
key = o.key;
|
|
name = o.name;
|
|
identifier = o.identifier;
|
|
icon = o.icon;
|
|
QWidget* parent = qobject_cast<QWidget*>(shortcut->parent());
|
|
delete shortcut;
|
|
if (o.shortcut)
|
|
shortcut = new QShortcut(o.shortcut->key(), qobject_cast<QWidget*>(o.shortcut->parent()), nullptr, nullptr,
|
|
o.shortcut->context());
|
|
else
|
|
shortcut = new QShortcut(parent);
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
class LTSWIDGETS_EXPORT LtsToolBarArea : public QWidget
|
|
{
|
|
|
|
Q_OBJECT
|
|
public:
|
|
explicit LtsToolBarArea(QWidget* parent = nullptr);
|
|
~LtsToolBarArea();
|
|
|
|
void addMenuEntry(LtsDragIcon* entry, LtsDragIcon* after = nullptr);
|
|
void clearToolBarArea();
|
|
|
|
void setMenuEntries(const QVector<LtsDragIcon*>& actions);
|
|
QStringList menuEntries() const;
|
|
|
|
bool setFunctionKey(int fkey, const QString& action);
|
|
QMap<int, QString> functionKeys() const;
|
|
|
|
bool removeFunctionKey(const QString& action);
|
|
void removeMenuAction(LtsDragIcon* icon);
|
|
|
|
public slots:
|
|
void showContextMenu(const QPoint& pos);
|
|
void functionKeyMenuTriggered();
|
|
|
|
protected:
|
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
|
void dropEvent(QDropEvent* event) override;
|
|
|
|
private:
|
|
QMenu* functionKeyMenu(QWidget* parent);
|
|
QString m_currentIdentifierForContextMenue;
|
|
|
|
QVector<LtsDragIcon*> m_buttonMap;
|
|
QVector<LtsDragIcon*> m_foreignButtonMap;
|
|
QMap<int, ShortCut> m_functionKeys;
|
|
QLabel* m_dummyLabel;
|
|
|
|
Ui::LtsToolBarArea* m_ui;
|
|
|
|
void saveSettings();
|
|
};
|
|
|
|
} // namespace LtsWidgets
|