File indexing completed on 2025-04-27 04:08:15
0001 /* 0002 * This file is part of the KDE project 0003 * SPDX-FileCopyrightText: 2014 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "ColorProfileModel.h" 0009 #include <libs/pigment/KoColorSpaceRegistry.h> 0010 #include <libs/pigment/KoColorProfile.h> 0011 0012 class ColorProfileModel::Private 0013 { 0014 public: 0015 Private(ColorProfileModel* qq) : q(qq), defaultProfile(-1) { } 0016 0017 void updateProfiles(); 0018 0019 ColorProfileModel* q; 0020 0021 QString colorModelId; 0022 QString colorDepthId; 0023 QString colorSpaceId; 0024 int defaultProfile; 0025 QList<const KoColorProfile*> colorProfiles; 0026 }; 0027 0028 ColorProfileModel::ColorProfileModel(QObject* parent) 0029 : QAbstractListModel(parent), d(new Private(this)) 0030 { 0031 } 0032 0033 ColorProfileModel::~ColorProfileModel() 0034 { 0035 delete d; 0036 } 0037 0038 QHash<int, QByteArray> ColorProfileModel::roleNames() const 0039 { 0040 QHash<int, QByteArray> roleNames; 0041 roleNames.insert(TextRole, "text"); 0042 0043 return roleNames; 0044 } 0045 0046 int ColorProfileModel::rowCount(const QModelIndex& parent) const 0047 { 0048 Q_UNUSED(parent); 0049 return d->colorProfiles.count(); 0050 } 0051 0052 QVariant ColorProfileModel::data(const QModelIndex& index, int role) const 0053 { 0054 if(!index.isValid() || index.row() < 0 || index.row() >= d->colorProfiles.count()) 0055 return QVariant(); 0056 0057 if(role == TextRole) { 0058 return d->colorProfiles.at(index.row())->name(); 0059 } 0060 0061 return QVariant(); 0062 } 0063 0064 QString ColorProfileModel::colorModelId() const 0065 { 0066 return d->colorModelId; 0067 } 0068 0069 void ColorProfileModel::setColorModelId(const QString& id) 0070 { 0071 if(id != d->colorModelId) { 0072 d->colorModelId = id; 0073 d->updateProfiles(); 0074 emit colorModelIdChanged(); 0075 } 0076 } 0077 0078 QString ColorProfileModel::colorDepthId() const 0079 { 0080 return d->colorDepthId; 0081 } 0082 0083 void ColorProfileModel::setColorDepthId(const QString& id) 0084 { 0085 if(id != d->colorDepthId) { 0086 d->colorDepthId = id; 0087 d->updateProfiles(); 0088 emit colorDepthIdChanged(); 0089 } 0090 } 0091 0092 int ColorProfileModel::defaultProfile() const 0093 { 0094 return d->defaultProfile; 0095 } 0096 0097 QString ColorProfileModel::id(int index) 0098 { 0099 return d->colorProfiles.at(index)->name(); 0100 } 0101 0102 void ColorProfileModel::Private::updateProfiles() 0103 { 0104 if(colorDepthId.isEmpty() || colorModelId.isEmpty()) 0105 return; 0106 0107 q->beginResetModel(); 0108 0109 colorSpaceId = KoColorSpaceRegistry::instance()->colorSpaceId(colorModelId, colorDepthId); 0110 colorProfiles = KoColorSpaceRegistry::instance()->profilesFor(colorSpaceId); 0111 0112 QString profile = KoColorSpaceRegistry::instance()->defaultProfileForColorSpace(colorSpaceId); 0113 for(int i = 0; i < colorProfiles.count(); ++i) { 0114 if(colorProfiles.at(i)->name() == profile) { 0115 defaultProfile = i; 0116 break; 0117 } 0118 } 0119 0120 q->endResetModel(); 0121 0122 emit q->defaultProfileChanged(); 0123 }