// // Created by Josef Rokos on 03.05.2023. // #ifndef COLORITEMDELEGATE_H #define COLORITEMDELEGATE_H #include #include class ColorItemDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit ColorItemDelegate(QObject* parent = nullptr); ~ColorItemDelegate() override = default; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; private slots: void commitAndCloseEditor(); }; class ColorLabel : public QWidget{ Q_OBJECT public: explicit ColorLabel(QWidget* parent = nullptr); QColor color() const; void setColor(const QColor &color); QSize sizeHint() const override; protected: void paintEvent(QPaintEvent *event) override; private: QColor m_color; }; class ColorItemEditor : public QWidget { Q_OBJECT public: explicit ColorItemEditor(QWidget *parent = nullptr); QColor color(){return m_color;} void setColor(const QColor& value); protected: bool eventFilter(QObject *obj, QEvent *event) override; private: void setFocusToParent(); signals: void editingFinished(); private slots: void slotClicked(); private: QColor m_color; QToolButton* m_button; ColorLabel* m_colorIndicator; bool m_buttonPressed; }; #endif //COLORITEMDELEGATE_H