232 lines
4.7 KiB
C++
232 lines
4.7 KiB
C++
|
|
|
|
#pragma once
|
|
#include "lts_base.h"
|
|
#include "lts_drop_handler.h"
|
|
#include "lts_widgets_export.h"
|
|
|
|
#include <QIcon>
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QWidget>
|
|
|
|
class QButtonGroup;
|
|
class QHBoxLayout;
|
|
class QLabel;
|
|
class QMenu;
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
|
|
class LtsToolButton;
|
|
|
|
class LTSWIDGETS_EXPORT LtsDragIcon : public QWidget
|
|
{
|
|
public:
|
|
Q_OBJECT
|
|
Q_PROPERTY(QString text READ text WRITE setText)
|
|
Q_PROPERTY(QString context READ context WRITE setContext)
|
|
Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier)
|
|
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
|
Q_PROPERTY(LtsWidgets::Designer::ButtonSize eButtonSize READ iconSizeDesigner WRITE setIconSizeDesigner)
|
|
Q_PROPERTY(bool eForceFixedSize READ isForceFixedSize WRITE setForceFixedSize)
|
|
Q_PROPERTY(bool isCheckable READ isCheckable WRITE setCheckable)
|
|
Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked)
|
|
Q_PROPERTY(bool showDragIcon READ showDragIcon WRITE setShowDragIcon)
|
|
Q_PROPERTY(bool isDraggable READ isDraggable WRITE setDraggable)
|
|
|
|
Q_PROPERTY(LtsWidgets::Designer::ButtonStyle eStyle READ buttonStyleDesigner WRITE setButtonStyleDesigner)
|
|
|
|
void setButtonStyleDesigner(Designer::ButtonStyle t)
|
|
{
|
|
setButtonStyle(static_cast<ButtonStyle>(t));
|
|
}
|
|
|
|
Designer::ButtonStyle buttonStyleDesigner() const
|
|
{
|
|
return static_cast<Designer::ButtonStyle>(buttonStyle());
|
|
}
|
|
|
|
void setIconSizeDesigner(Designer::ButtonSize t)
|
|
{
|
|
setIconSize(static_cast<ButtonSize>(t));
|
|
}
|
|
|
|
Designer::ButtonSize iconSizeDesigner() const
|
|
{
|
|
return static_cast<Designer::ButtonSize>(iconSize());
|
|
}
|
|
|
|
public:
|
|
explicit LtsDragIcon(QWidget* parent);
|
|
|
|
virtual ~LtsDragIcon() = default;
|
|
|
|
void setMenu(QMenu* menu);
|
|
|
|
QMenu* menu() const;
|
|
|
|
void setText(const QString& text);
|
|
|
|
QString text() const
|
|
{
|
|
return m_text;
|
|
}
|
|
|
|
void setContext(const QString& context);
|
|
|
|
QString context() const
|
|
{
|
|
return m_context;
|
|
}
|
|
|
|
void setCheckable(bool checkable);
|
|
|
|
bool isCheckable();
|
|
|
|
void setDraggable(bool draggable);
|
|
|
|
bool isDraggable() const
|
|
{
|
|
return m_isDraggable;
|
|
}
|
|
|
|
void setChecked(bool checked);
|
|
|
|
bool isChecked() const;
|
|
|
|
void setShowDragIcon(bool showDragIcon)
|
|
{
|
|
m_showDragIcon = showDragIcon;
|
|
}
|
|
|
|
bool showDragIcon() const
|
|
{
|
|
return m_showDragIcon;
|
|
}
|
|
|
|
void setSameWidgetDrop(bool drop);
|
|
|
|
bool sameWidgetDrop() const;
|
|
|
|
void setButtonStyle(ButtonStyle style);
|
|
|
|
ButtonStyle buttonStyle() const
|
|
{
|
|
return m_style;
|
|
}
|
|
|
|
void setIconSize(ButtonSize buttonSize);
|
|
|
|
ButtonSize iconSize() const
|
|
{
|
|
return m_buttonSize;
|
|
}
|
|
|
|
void setButtonVisible(bool visible);
|
|
|
|
bool buttonVisible() const;
|
|
|
|
void setIcon(const QIcon& icon);
|
|
|
|
QIcon icon() const
|
|
{
|
|
return m_icon;
|
|
}
|
|
|
|
void setForceFixedSize(bool force);
|
|
|
|
bool isForceFixedSize() const
|
|
{
|
|
return m_forceFixedSize;
|
|
}
|
|
|
|
void setAction(QAction* action);
|
|
|
|
void addToButtonGroup(QButtonGroup* btnGrp, int btnGrpId);
|
|
|
|
void setDropHandlerKey(qulonglong key)
|
|
{
|
|
m_dropHandlerKey = key;
|
|
}
|
|
|
|
void addMimeData(const QString& mimeType, const QByteArray& data);
|
|
bool removeMimeData(const QString& mimeType);
|
|
void removeAllMimeData();
|
|
|
|
void setAcceptDrops(bool on);
|
|
|
|
qulonglong dropHandlerKey() const
|
|
{
|
|
return m_dropHandlerKey;
|
|
}
|
|
|
|
void setIdentifier(const QString& id)
|
|
{
|
|
m_identifier = id;
|
|
}
|
|
|
|
QString identifier() const
|
|
{
|
|
return m_identifier;
|
|
}
|
|
|
|
void setModification(const QString& id)
|
|
{
|
|
m_modification = id;
|
|
setIcon(m_icon);
|
|
}
|
|
|
|
QString modification() const
|
|
{
|
|
return m_modification;
|
|
}
|
|
|
|
void removeModification()
|
|
{
|
|
m_modification = QString();
|
|
setIcon(m_icon);
|
|
}
|
|
|
|
signals:
|
|
|
|
void clicked();
|
|
|
|
void toggled(bool);
|
|
void newDropEvent(QDropEvent* e);
|
|
void dropSuc();
|
|
|
|
void enabledChanged(bool);
|
|
|
|
protected:
|
|
void dragEnterEvent(QDragEnterEvent* e) override;
|
|
void dropEvent(QDropEvent* e) override;
|
|
void initButton();
|
|
|
|
private:
|
|
void setStyleToButton();
|
|
QIcon modifyIcon(const QIcon& icon);
|
|
void generateToolTip();
|
|
|
|
protected slots:
|
|
void changeEvent(QEvent* event) override;
|
|
|
|
private:
|
|
QHBoxLayout* m_lay;
|
|
LtsToolButton* m_toolButton;
|
|
QIcon m_icon;
|
|
QLabel* m_dragLabel;
|
|
QString m_text;
|
|
QString m_identifier;
|
|
QString m_modification;
|
|
ButtonStyle m_style;
|
|
bool m_forceFixedSize;
|
|
bool m_isDraggable;
|
|
qulonglong m_dropHandlerKey;
|
|
ButtonSize m_buttonSize;
|
|
bool m_showDragIcon;
|
|
QString m_context;
|
|
};
|
|
|
|
} // namespace LtsWidgets
|