diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
commit | d24f813f3f2a05c112e803e4256b53535895fc98 (patch) | |
tree | 601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/dic-options/FieldsPreviewModel.cpp |
Diffstat (limited to 'src/dic-options/FieldsPreviewModel.cpp')
-rw-r--r-- | src/dic-options/FieldsPreviewModel.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/dic-options/FieldsPreviewModel.cpp b/src/dic-options/FieldsPreviewModel.cpp new file mode 100644 index 0000000..e6ce1c6 --- /dev/null +++ b/src/dic-options/FieldsPreviewModel.cpp @@ -0,0 +1,34 @@ +#include "FieldsPreviewModel.h" +#include "../dictionary/Field.h" +#include "../field-styles/FieldStyle.h" +#include "../field-styles/FieldStyleFactory.h" + +#include <QBrush> + +QVariant FieldsPreviewModel::data( const QModelIndex &index, int role ) const + { + if (!index.isValid()) + return QVariant(); + if (index.row() >= rowCount()) + return QVariant(); + + Field* field = m_parent->m_dict.fields().value(index.row()); + const FieldStyle fieldStyle = FieldStyleFactory::inst()->getStyle(field->style()); + switch( role ) + { + case Qt::DisplayRole: + return fieldStyle.prefix + field->name() + fieldStyle.suffix; + case Qt::FontRole: + return fieldStyle.font; + case Qt::BackgroundRole: + return QBrush( FieldStyleFactory::inst()->cardBgColor ); + case Qt::ForegroundRole: + return fieldStyle.color; + case Qt::SizeHintRole: + return QSize(0, 50); + case Qt::TextAlignmentRole: + return Qt::AlignCenter; + default: + return QVariant(); + } + } |