summaryrefslogtreecommitdiff
path: root/src/settings/StylePreviewModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings/StylePreviewModel.cpp')
-rw-r--r--src/settings/StylePreviewModel.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/settings/StylePreviewModel.cpp b/src/settings/StylePreviewModel.cpp
new file mode 100644
index 0000000..e07c809
--- /dev/null
+++ b/src/settings/StylePreviewModel.cpp
@@ -0,0 +1,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();
+ }
+ }