#include "StylePreviewModel.h" #include "../field-styles/FieldStyleFactory.h" #include 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(); } }