File indexing completed on 2024-05-12 05:39:51

0001 /***************************************************************************
0002  *  Copyright (C) 2015 by Renaud Guezennec                                *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   Rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef PALETTEMODEL_H
0021 #define PALETTEMODEL_H
0022 
0023 #include <QAbstractTableModel>
0024 #include <QColor>
0025 #include <QJsonObject>
0026 #include <QPalette>
0027 #include <core_global.h>
0028 /**
0029  * @brief The PaletteColor class
0030  */
0031 class CORE_EXPORT PaletteColor
0032 {
0033 public:
0034     PaletteColor(QColor, QString, QPalette::ColorGroup group, QPalette::ColorRole role);
0035     void setColor(QColor);
0036     void setName(QString);
0037 
0038     QColor getColor() const;
0039     QString getName() const;
0040     QPalette::ColorGroup getGroup() const;
0041     QPalette::ColorRole getRole() const;
0042     void writeTo(QJsonObject& json);
0043     bool readFrom(QJsonObject& json);
0044 
0045 private:
0046     QColor m_color;
0047     QString m_name;
0048     QPalette::ColorGroup m_group;
0049     QPalette::ColorRole m_role;
0050 };
0051 /**
0052  * @brief The PaletteModel class
0053  */
0054 class CORE_EXPORT PaletteModel : public QAbstractTableModel
0055 {
0056     Q_OBJECT
0057 public:
0058     PaletteModel(QObject* parent= nullptr);
0059     virtual ~PaletteModel();
0060 
0061     void initData();
0062     int rowCount(const QModelIndex& parent) const;
0063     int columnCount(const QModelIndex& parent) const;
0064     QVariant data(const QModelIndex& index, int role) const;
0065     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
0066 
0067     void setPalette(QPalette);
0068     QPalette getPalette();
0069     void writeTo(QJsonObject& json);
0070     bool readFrom(const QJsonObject& json);
0071     void setColor(int pos, QColor);
0072     const QList<PaletteColor*>& data() const;
0073 
0074 private:
0075     QList<PaletteColor*> m_data;
0076     QStringList m_header;
0077     QStringList m_groupList;
0078 };
0079 
0080 #endif // PALETTEMODEL_H