summaryrefslogtreecommitdiff
path: root/src/settings/StylePreviewModel.cpp
blob: e07c809616a0daed44f4637d4d71e0c0112344b5 (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
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
#include "StylePreviewModel.h"
#include "../field-styles/FieldStyleFactory.h"

#include <QBrush>

QVariant StylePreviewModel::data( const QModelIndex &index, int role ) const
    {
    if( !index.isValid())
         return QVariant();
    if( index.row() >= rowCount() || index.column() >= columnCount() )
         return QVariant();

    QString styleName = m_parent->styleFactory()->getStyleNames().value( index.row() );
    FieldStyle fieldStyle = m_parent->styleFactory()->getStyle( styleName );
    switch( index.column() )
        {
        case 0:
        switch( role )
            {
            case Qt::DisplayRole:
                return fieldStyle.prefix + styleName + fieldStyle.suffix;
            case Qt::FontRole:
                return fieldStyle.font;
            case Qt::BackgroundRole:
                return QBrush( m_parent->styleFactory()->cardBgColor );
            case Qt::ForegroundRole:
                return fieldStyle.color;
            case Qt::TextAlignmentRole:
                return Qt::AlignCenter;
            default:
                return QVariant();
            }
        case 1:
        if( fieldStyle.hasKeyword )
            switch( role )
                {
                case Qt::DisplayRole:
                    return tr("keyword");
                case Qt::FontRole:
                    return fieldStyle.getKeywordStyle().font;
                case Qt::BackgroundRole:
                    return QBrush( m_parent->styleFactory()->cardBgColor );
                case Qt::ForegroundRole:
                    return fieldStyle.keywordColor;
                case Qt::TextAlignmentRole:
                    return Qt::AlignCenter;
                default:
                    return QVariant();
                }
        else
            switch( role )
                {
                case Qt::DisplayRole:
                    return QVariant();
                case Qt::BackgroundRole:
                    return QBrush( m_parent->styleFactory()->cardBgColor );
                default:
                    return QVariant();
                }
        default:
            return QVariant();
        }
    }