Color values are displayed as colored rectangles in tables

c++11
Stanislav Bas 10 years ago
parent f3e040b531
commit d7fb497255

@ -70,6 +70,7 @@ opencs_units (view/world
opencs_units_noqt (view/world
subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate
scripthighlighter idvalidator dialoguecreator physicssystem idcompletiondelegate
colorpickerdelegate
)
opencs_units (view/widget

@ -19,6 +19,7 @@
#include "../world/recordstatusdelegate.hpp"
#include "../world/idtypedelegate.hpp"
#include "../world/idcompletiondelegate.hpp"
#include "../world/colorpickerdelegate.hpp"
#include "../../model/settings/usersettings.hpp"
@ -63,6 +64,9 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
mDelegateFactories->add (CSMWorld::ColumnBase::Display_RefRecordType,
new CSVWorld::IdTypeDelegateFactory());
mDelegateFactories->add (CSMWorld::ColumnBase::Display_Colour,
new CSVWorld::ColorPickerDelegateFactory());
std::vector<CSMWorld::ColumnBase::Display> idCompletionColumns = CSMWorld::IdCompletionManager::getDisplayTypes();
for (std::vector<CSMWorld::ColumnBase::Display>::const_iterator current = idCompletionColumns.begin();
current != idCompletionColumns.end();

@ -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…
Cancel
Save