/** * @RDE_HEADER@ * Draggable Icon with Text for Menus * $Id$ * $HeadURL$ * $Author$ */ #pragma once #include "lts_base.h" #include "lts_drop_handler.h" #include "lts_widgets_export.h" #include #include #include class QButtonGroup; class QHBoxLayout; class QLabel; class QMenu; namespace LtsWidgets { class LtsToolButton; /** @brief Tool button with drag & drop functionality */ 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) //last Q_PROPERTY(LtsWidgets::Designer::ButtonStyle eStyle READ buttonStyleDesigner WRITE setButtonStyleDesigner) /** * @brief Set the ButtonStyle in Designer * @param ButtonStyle to define the possible IconStyles */ void setButtonStyleDesigner(Designer::ButtonStyle t) { setButtonStyle(static_cast(t)); } /** * @brief ButtonStyle Getter for Designer * @return the current ButtonStyle for the DragIcon in the designer */ Designer::ButtonStyle buttonStyleDesigner() const { return static_cast(buttonStyle()); } /** * @brief Set the ButtonSize in Designer * @param ButtonSize */ void setIconSizeDesigner(Designer::ButtonSize t) { setIconSize(static_cast(t)); } /** * @brief OpenType Getter for Designer * @return the current BUttonSize Value for the DragIcon in the designer */ Designer::ButtonSize iconSizeDesigner() const { return static_cast(iconSize()); } public: /** * @brief Constructor for LtsDragIcon * @param parent for the Widget */ explicit LtsDragIcon(QWidget *parent); virtual ~LtsDragIcon() = default; /** * @brief set a QMenu to the Button * @param QMenu to show */ void setMenu(QMenu *menu); /** * @brief get QMenu from the Button * @return QMenu or nullptr if no button or menu is defined */ QMenu* menu() const; /** * @brief set a text to the Button * @param QString as text shown */ void setText(const QString &text); /** * @brief Returns the widget's text value * @return Current text */ QString text() const { return m_text; } /** * @brief set a context to the Button * @param QString as context shown */ void setContext(const QString &context); /** * @brief Returns the widget's context value * @return Current context */ QString context() const { return m_context; } /** * @brief set if the Button should be checkable * By default, the button is not checkable. * @param new checkable state */ void setCheckable(bool checkable); /** * @brief Return if Button is checkable * @return This property holds whether the button is checkable. */ bool isCheckable(); /** * @brief set if the Button should be draggable * By default, the button is draggable. * @param new dragabble state */ void setDraggable(bool draggable); /** * @brief Return if Button is checkable * @return This property holds whether the button is checkable. */ bool isDraggable() const { return m_isDraggable; } /** * @brief (un)check the Button * Only checkable buttons can be checked. By default, the button is unchecked. * @param new checked state */ void setChecked(bool checked); /** * @brief Return the current check state * @return This property holds whether the button is checked. */ bool isChecked() const; /** * @brief Use Icon / Default Icon when dragging * By default, the icon is used. * @param new checked state */ void setShowDragIcon(bool showDragIcon) { m_showDragIcon = showDragIcon; } bool showDragIcon() const { return m_showDragIcon; } /** * @brief set new the SameWidgetDrop State * drag&drop property to allow sameWidgetDrops * @param new drop state */ void setSameWidgetDrop(bool drop); /** * @brief get wether SameWidgetDrop is enabled * @return the drop state */ bool sameWidgetDrop() const; /** * @brief Set the ButtonStyle in Code * @param ButtonStyle to define the possible IconStyles */ void setButtonStyle(ButtonStyle style); /** * @brief Returns the currently used ButtonStyle Value * @return Current ButtonStyle */ ButtonStyle buttonStyle() const { return m_style; } /** * @brief Set the ButtonSize in Code * @param ButtonSize */ void setIconSize(ButtonSize buttonSize); /** * @brief Returns the current used ButtonSize Value * @return Current ButtonSize */ ButtonSize iconSize() const { return m_buttonSize; } /** * @brief set new visibilty fo the Icon * @param New visibilty */ void setButtonVisible(bool visible); /** * @brief set new visibilty fo the Icon * @param New visibilty */ bool buttonVisible() const; /** * @brief set Icon to the Button * @param New QIcon to use */ void setIcon(const QIcon &icon); /** * @brief Return the current used QIcon * @return This property holds the current used QIcon. */ QIcon icon() const { return m_icon; } /** * @brief Set to Force the given IconSize and forbid resizing * By default, the button resizes into given space * @param bool to force the Icon to hold it's given * IconSize even if the LayoutSystem provides more space to fill */ void setForceFixedSize(bool force); /** * @brief Return the current ForeFixedSize value * @return This property holds the set ForceFicedSize value */ bool isForceFixedSize() const { return m_forceFixedSize; } /** * @brief set a QAction to the Button * @param New QAction * the new Action will override the old one and replaces * the ObjectName with the new ActionName */ void setAction(QAction *action); /** Adds dragButton to a button group @param btnGrp button group to add dragButton @param btnGrpId Button identifier in button group */ void addToButtonGroup(QButtonGroup *btnGrp, int btnGrpId); /** * @brief Sets a dropHandler. The dropHandler must be allocated with new operator. The owner ship now has the LtsDragIcon. The LtsDragIcon calls delete in hier dtor * @see LtsDropHandler */ void setDropHandlerKey(qulonglong key) { m_dropHandlerKey = key; } /** * @brief Adds MimeData. * This sets MimeData to the Drag Action * @param QString with MimeType Description * @param QByteArray with MimeData */ void addMimeData(const QString &mimeType, const QByteArray &data); bool removeMimeData(const QString &mimeType); void removeAllMimeData(); /** * @brief Sets the drop acceptance of the Icon * @param bool value to set drop acceptance */ void setAcceptDrops(bool on); qulonglong dropHandlerKey() const { return m_dropHandlerKey; } // Todo: Isn't this something like objectName? 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: /** * @brief The Signal is emitted when the Button is activated * (i.e. pressed down then released while the mouse cursor is inside the button) * @param bool checked = false */ void clicked(); /** * @brief The Signal is emitted when the Button is toggled * @param bool checked */ 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; }; }