You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
2 years ago
|
//
|
||
|
// Created by Josef Rokos on 03.05.2023.
|
||
|
//
|
||
|
|
||
|
#ifndef COLORITEMDELEGATE_H
|
||
|
#define COLORITEMDELEGATE_H
|
||
|
|
||
|
#include <QStyledItemDelegate>
|
||
|
#include <QToolButton>
|
||
|
|
||
|
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
|