Warning, file /plasma/latte-dock/app/settings/detailsdialog/colorsmodel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "colorsmodel.h"
0007 
0008 // local
0009 #include "../../layout/abstractlayout.h"
0010 
0011 // KDE
0012 #include <KLocalizedString>
0013 
0014 namespace Latte {
0015 namespace Settings {
0016 namespace Model {
0017 
0018 Colors::Colors(QObject *parent, Latte::Corona *corona)
0019     : QAbstractTableModel(parent),
0020       m_corona(corona)
0021 {
0022     //!find the available colors
0023     m_colorsPath = m_corona->kPackage().path() + "../../shells/org.kde.latte.shell/contents/images/canvas/";
0024 
0025     init();
0026 }
0027 
0028 Colors::~Colors()
0029 {
0030 }
0031 
0032 void Colors::init()
0033 {
0034     QString id;
0035     id = "blue"; add(id, i18n("Blue"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0036     id = "brown"; add(id, i18n("Brown"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0037     id = "darkgrey"; add(id, i18n("Dark Grey"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0038     id = "gold"; add(id, i18n("Gold"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0039     id = "green"; add(id, i18n("Green"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0040     id = "lightskyblue"; add(id, i18n("Light Sky Blue"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0041     id = "orange"; add(id, i18n("Orange"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0042     id = "pink"; add(id, i18n("Pink"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0043     id = "purple"; add(id, i18n("Purple"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0044     id = "red"; add(id, i18n("Red"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0045     id = "wheat"; add(id, i18n("Wheat"), colorPath(id), Layout::AbstractLayout::defaultTextColor(id));
0046 }
0047 
0048 QString Colors::colorPath(const QString &color)
0049 {
0050     return QString(m_colorsPath + color + "print.jpg");
0051 }
0052 
0053 void Colors::add(const QString &newid, const QString &newname, const QString &newpath, const QString &newtextcolor)
0054 {
0055     Latte::Data::LayoutColor color;
0056     color.setData(newid, newname, newpath, newtextcolor);
0057     m_colorsTable << color;
0058 }
0059 
0060 int Colors::rowCount() const
0061 {
0062     return m_colorsTable.count();
0063 }
0064 
0065 int Colors::rowCount(const QModelIndex &parent) const
0066 {
0067     Q_UNUSED(parent);
0068 
0069     return m_colorsTable.count();
0070 }
0071 
0072 int Colors::columnCount(const QModelIndex &parent) const
0073 {
0074     Q_UNUSED(parent);
0075 
0076     return TEXTCOLORROLE+1;
0077 }
0078 
0079 int Colors::row(const QString &id)
0080 {
0081     for (int i=0; i<m_colorsTable.count(); ++i){
0082         if (m_colorsTable[i].id == id) {
0083             return i;
0084         }
0085     }
0086 
0087     return -1;
0088 }
0089 
0090 QVariant Colors::data(const QModelIndex &index, int role) const
0091 {
0092     const int row = index.row();
0093     int column = index.column();
0094 
0095     if (row >= rowCount()) {
0096         return QVariant{};
0097     }
0098 
0099     if (role == NAMEROLE || role == Qt::DisplayRole) {
0100         return m_colorsTable[row].name;
0101     } else if (role == IDROLE) {
0102             return m_colorsTable[row].id;
0103     } else if (role == PATHROLE) {
0104         return m_colorsTable[row].path;
0105     } else if (role == TEXTCOLORROLE) {
0106         return m_colorsTable[row].textColor;
0107     }
0108 
0109     return QVariant{};
0110 }
0111 
0112 }
0113 }
0114 }