1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
/*
* SPDX-FileCopyrightText: 2013-2020 Mattia Basaglia
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef COLOR_DELEGATE_HPP
#define COLOR_DELEGATE_HPP
#include "colorwidgets_global.hpp"
#include <QStyledItemDelegate>
namespace color_widgets {
class QCP_EXPORT ReadOnlyColorDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
using QStyledItemDelegate::QStyledItemDelegate;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setSizeHintForColor(const QSize& size_hint);
const QSize& sizeHintForColor() const;
protected:
void paintItem(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index, const QBrush& brush) const;
private:
QSize size_hint{24, 16};
};
/**
Delegate to use a ColorSelector in a color list
*/
class QCP_EXPORT ColorDelegate : public ReadOnlyColorDelegate
{
Q_OBJECT
public:
using ReadOnlyColorDelegate::ReadOnlyColorDelegate;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const Q_DECL_OVERRIDE;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
protected:
bool eventFilter(QObject * watched, QEvent * event) Q_DECL_OVERRIDE;
private Q_SLOTS:
void close_editor();
void color_changed();
};
} // namespace color_widgets
#endif // COLOR_DELEGATE_HPP
|