MauiKit TextEditor

colorschemesmodel.cpp
1#include "colorschemesmodel.h"
2
3#include <QDebug>
4
5ColorSchemesModel::ColorSchemesModel(QObject *parent) : QAbstractListModel(parent)
6{
7
8}
9
10void ColorSchemesModel::classBegin()
11{
12}
13
14void ColorSchemesModel::componentComplete()
15{
16 this->setList();
17}
18
19void ColorSchemesModel::setList()
20{
21 m_list.clear();
22
24
25 auto repository = new KSyntaxHighlighting::Repository();
26
27 m_list = repository->themes();
28
30}
31
32
33int ColorSchemesModel::rowCount(const QModelIndex &parent) const
34{
35 if (parent.isValid())
36 {
37 return 0;
38 }
39
40 return m_list.count();
41}
42
43QVariant ColorSchemesModel::data(const QModelIndex &index, int role) const
44{
45 if (!index.isValid())
46 return QVariant();
47
48 KSyntaxHighlighting::Theme item = m_list[index.row()];
49
50 switch(role)
51 {
52 case Role::Name: return item.name();
53 case Role::Background: return QColor(item.backgroundColor(KSyntaxHighlighting::Theme::Normal));
54 case Role::Foreground: return QColor(item.textColor(KSyntaxHighlighting::Theme::Keyword));
55 case Role::Highlight: return QColor(item.selectedBackgroundColor(KSyntaxHighlighting::Theme::Keyword));
56 case Role::Color3: return QColor(item.textColor(KSyntaxHighlighting::Theme::Variable));
57 case Role::Color4: return QColor(item.textColor(KSyntaxHighlighting::Theme::Function));
58 case Role::Color5: return QColor(item.textColor(KSyntaxHighlighting::Theme::Normal));
59 default: return QVariant();
60 }
61}
62
63QHash<int, QByteArray> ColorSchemesModel::roleNames() const
64{
65 return {{Role::Name, "name"},
66 {Role::Background, "background"},
67 {Role::Foreground, "foreground"},
68 {Role::Highlight, "highlight"},
69 {Role::Color3, "color3"},
70 {Role::Color4, "color4"},
71 {Role::Color5, "color5"}};
72}
QRgb textColor(TextStyle style) const
QRgb selectedBackgroundColor(TextStyle style) const
QRgb backgroundColor(TextStyle style) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
bool isValid() const const
int row() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.