mirror of https://github.com/OpenMW/openmw.git
Color values are displayed as colored rectangles in tables
parent
f3e040b531
commit
d7fb497255
@ -0,0 +1,50 @@
|
||||
#include "colorpickerdelegate.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
|
||||
CSVWorld::ColorPickerDelegate::ColorPickerDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document& document,
|
||||
QObject *parent)
|
||||
: CommandDelegate(dispatcher, document, parent)
|
||||
{}
|
||||
|
||||
QWidget *CSVWorld::ColorPickerDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
return createEditor(parent, option, index, getDisplayTypeFromIndex(index));
|
||||
}
|
||||
|
||||
QWidget *CSVWorld::ColorPickerDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index,
|
||||
CSMWorld::ColumnBase::Display display) const
|
||||
{
|
||||
if (display != CSMWorld::ColumnBase::Display_Colour)
|
||||
{
|
||||
throw std::logic_error("Wrong column for ColorPickerDelegate");
|
||||
}
|
||||
|
||||
return CommandDelegate::createEditor(parent, option, index, display);
|
||||
}
|
||||
|
||||
void CSVWorld::ColorPickerDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QColor color = index.data().value<QColor>();
|
||||
QRect rect(option.rect.x() + option.rect.width() / 4,
|
||||
option.rect.y() + option.rect.height() / 4,
|
||||
option.rect.width() / 2,
|
||||
option.rect.height() / 2);
|
||||
|
||||
painter->fillRect(rect, color);
|
||||
}
|
||||
|
||||
CSVWorld::CommandDelegate *CSVWorld::ColorPickerDelegateFactory::makeDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document &document,
|
||||
QObject *parent) const
|
||||
{
|
||||
return new ColorPickerDelegate(dispatcher, document, parent);
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
#ifndef CSV_WORLD_COLORPICKERDELEGATE_HPP
|
||||
#define CSV_WORLD_COLORPICKERDELEGATE_HPP
|
||||
|
||||
#include "util.hpp"
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class ColorPickerDelegate : public CommandDelegate
|
||||
{
|
||||
public:
|
||||
ColorPickerDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document& document,
|
||||
QObject *parent);
|
||||
|
||||
virtual QWidget *createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
virtual QWidget *createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index,
|
||||
CSMWorld::ColumnBase::Display display) const;
|
||||
|
||||
virtual void paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;/*
|
||||
|
||||
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
|
||||
virtual void setModelData(QWidget *editor,
|
||||
QAbstractItemModel &model,
|
||||
const QModelIndex &index) const;*/
|
||||
};
|
||||
|
||||
class ColorPickerDelegateFactory : public CommandDelegateFactory
|
||||
{
|
||||
public:
|
||||
virtual CommandDelegate *makeDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document &document,
|
||||
QObject *parent) const;
|
||||
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue