File indexing completed on 2024-05-19 04:48:08
0001 #include "colorschemesmodel.h" 0002 0003 0004 0005 #include <QDebug> 0006 0007 ColorSchemesModel::ColorSchemesModel(QObject *parent) : QAbstractListModel(parent) 0008 { 0009 0010 } 0011 0012 void ColorSchemesModel::classBegin() 0013 { 0014 } 0015 0016 void ColorSchemesModel::componentComplete() 0017 { 0018 this->setList(); 0019 } 0020 0021 void ColorSchemesModel::setList() 0022 { 0023 m_list.clear(); 0024 0025 beginResetModel(); 0026 0027 0028 auto repository = new KSyntaxHighlighting::Repository(); 0029 0030 m_list = repository->themes(); 0031 0032 endResetModel(); 0033 } 0034 0035 0036 int ColorSchemesModel::rowCount(const QModelIndex &parent) const 0037 { 0038 if (parent.isValid()) 0039 { 0040 return 0; 0041 } 0042 0043 return m_list.count(); 0044 } 0045 0046 QVariant ColorSchemesModel::data(const QModelIndex &index, int role) const 0047 { 0048 if (!index.isValid()) 0049 return QVariant(); 0050 0051 KSyntaxHighlighting::Theme item = m_list[index.row()]; 0052 0053 switch(role) 0054 { 0055 case Role::Name: return item.name(); 0056 case Role::Background: return QColor(item.backgroundColor(KSyntaxHighlighting::Theme::Normal)); 0057 case Role::Foreground: return QColor(item.textColor(KSyntaxHighlighting::Theme::Keyword)); 0058 case Role::Highlight: return QColor(item.selectedBackgroundColor(KSyntaxHighlighting::Theme::Keyword)); 0059 case Role::Color3: return QColor(item.textColor(KSyntaxHighlighting::Theme::Variable)); 0060 case Role::Color4: return QColor(item.textColor(KSyntaxHighlighting::Theme::Function)); 0061 case Role::Color5: return QColor(item.textColor(KSyntaxHighlighting::Theme::Normal)); 0062 default: return QVariant(); 0063 } 0064 } 0065 0066 QHash<int, QByteArray> ColorSchemesModel::roleNames() const 0067 { 0068 return {{Role::Name, "name"}, 0069 {Role::Background, "background"}, 0070 {Role::Foreground, "foreground"}, 0071 {Role::Highlight, "highlight"}, 0072 {Role::Color3, "color3"}, 0073 {Role::Color4, "color4"}, 0074 {Role::Color5, "color5"}}; 0075 }