File indexing completed on 2025-04-27 04:08:16
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2012 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "PaletteColorsModel.h" 0008 #include <KisViewManager.h> 0009 #include <kis_canvas_resource_provider.h> 0010 0011 #include <resources/KoColorSet.h> 0012 0013 class PaletteColorsModel::Private { 0014 public: 0015 Private() 0016 : colorSet(0) 0017 , view(0) 0018 {} 0019 0020 KoColorSetSP colorSet; 0021 KisViewManager* view; 0022 }; 0023 0024 PaletteColorsModel::PaletteColorsModel(QObject *parent) 0025 : QAbstractListModel(parent) 0026 , d(new Private) 0027 { 0028 } 0029 0030 PaletteColorsModel::~PaletteColorsModel() 0031 { 0032 delete d; 0033 } 0034 0035 QHash<int, QByteArray> PaletteColorsModel::roleNames() const 0036 { 0037 QHash<int, QByteArray> roles; 0038 roles[ImageRole] = "image"; 0039 roles[TextRole] = "text"; 0040 0041 return roles; 0042 } 0043 0044 int PaletteColorsModel::rowCount(const QModelIndex &parent) const 0045 { 0046 if (parent.isValid()) 0047 return 0; 0048 if (!d->colorSet) 0049 return 0; 0050 return d->colorSet->colorCount(); 0051 } 0052 0053 QVariant PaletteColorsModel::data(const QModelIndex &/*index*/, int /*role*/) const 0054 { 0055 QVariant result; 0056 /* 0057 QColor color; 0058 if (index.isValid() && d->colorSet) 0059 { 0060 switch(role) 0061 { 0062 case ImageRole: 0063 color = d->colorSet->getColorGlobal(index.row(), index.column()).color().toQColor(); 0064 result = QString("image://color/%1,%2,%3,%4").arg(color.redF()).arg(color.greenF()).arg(color.blueF()).arg(color.alphaF()); 0065 break; 0066 case TextRole: 0067 result = d->colorSet->getColorGlobal(index.row(), index.column()).name(); 0068 break; 0069 default: 0070 break; 0071 } 0072 } 0073 */ 0074 0075 return result; 0076 } 0077 0078 QVariant PaletteColorsModel::headerData(int section, Qt::Orientation orientation, int role) const 0079 { 0080 Q_UNUSED(orientation); 0081 QVariant result; 0082 if (section == 0) 0083 { 0084 switch(role) 0085 { 0086 case ImageRole: 0087 result = QString("Thumbnail"); 0088 break; 0089 case TextRole: 0090 result = QString("Name"); 0091 break; 0092 default: 0093 break; 0094 } 0095 } 0096 return result; 0097 } 0098 0099 void PaletteColorsModel::setColorSet(QObject */*newColorSet*/) 0100 { 0101 // XXX SharedPtr We need to wrap KoColorSet 0102 0103 //d->colorSet = qobject_cast<KoColorSet*>(newColorSet); 0104 beginResetModel(); 0105 endResetModel(); 0106 emit colorSetChanged(); 0107 } 0108 0109 QObject* PaletteColorsModel::colorSet() const 0110 { 0111 // XXX SharedPtr We need to wrap KoColorSet 0112 // return d->colorSet; 0113 return 0; 0114 } 0115 0116 0117 QObject* PaletteColorsModel::view() const 0118 { 0119 return d->view; 0120 } 0121 0122 void PaletteColorsModel::setView(QObject* newView) 0123 { 0124 d->view = qobject_cast<KisViewManager*>( newView ); 0125 emit viewChanged(); 0126 } 0127 0128 void PaletteColorsModel::activateColor(int index, bool /*setBackgroundColor*/) 0129 { 0130 if ( !d->view ) 0131 return; 0132 0133 if (index >= 0 && index < (int)d->colorSet->colorCount()) { 0134 /* 0135 if (setBackgroundColor) 0136 d->view->resourceProvider()->setBGColor(d->colorSet->getColorGlobal(index).color()); 0137 else 0138 d->view->resourceProvider()->setFGColor( d->colorSet->getColorGlobal(index).color()); 0139 emit colorChanged(d->colorSet->getColorGlobal(index).color().toQColor(), setBackgroundColor); 0140 */ 0141 } 0142 } 0143