summaryrefslogtreecommitdiff
path: root/src/dic-options/FieldsPreviewModel.cpp
blob: e6ce1c6e206afcdcbc3faf3d15f9964c7943262c (plain)
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
#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();
        }
    }