summaryrefslogtreecommitdiff
path: root/src/settings/StylePreviewModel.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
commitd24f813f3f2a05c112e803e4256b53535895fc98 (patch)
tree601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/settings/StylePreviewModel.cpp
Initial mirror commitHEADmaster
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();
+ }
+ }