krita/ui

kis_composite_ops_model.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kis_composite_ops_model.h"
00020 #include <KoCompositeOp.h>
00021 
00022 #include <kcategorizedsortfilterproxymodel.h>
00023 #include "kis_debug.h"
00024 
00025 static QStringList opsInOrder;
00026 
00027 KisCompositeOpsModel::KisCompositeOpsModel(const QList<KoCompositeOp*>& list)
00028 {
00029     foreach(KoCompositeOp* op, list) {
00030         if (op->userVisible()) {
00031             m_list.push_back(CompositeOpInfo(op->id(), op->description(), op->category()));
00032         }
00033     }
00034     if (opsInOrder.isEmpty()) {
00035         opsInOrder <<
00036         COMPOSITE_OVER <<
00037         COMPOSITE_ERASE <<
00038         COMPOSITE_COPY <<
00039         COMPOSITE_ALPHA_DARKEN <<
00040         COMPOSITE_IN <<
00041         COMPOSITE_OUT <<
00042         COMPOSITE_ATOP <<
00043         COMPOSITE_XOR <<
00044         COMPOSITE_PLUS <<
00045         COMPOSITE_MINUS <<
00046         COMPOSITE_ADD <<
00047         COMPOSITE_SUBTRACT <<
00048         COMPOSITE_DIFF <<
00049         COMPOSITE_MULT <<
00050         COMPOSITE_DIVIDE <<
00051         COMPOSITE_DODGE <<
00052         COMPOSITE_BURN <<
00053         COMPOSITE_BUMPMAP <<
00054         COMPOSITE_CLEAR <<
00055         COMPOSITE_DISSOLVE <<
00056         COMPOSITE_DISPLACE <<
00057         COMPOSITE_NO <<
00058         COMPOSITE_DARKEN <<
00059         COMPOSITE_LIGHTEN <<
00060         COMPOSITE_HUE <<
00061         COMPOSITE_SATURATION <<
00062         COMPOSITE_VALUE <<
00063         COMPOSITE_COLOR <<
00064         COMPOSITE_COLORIZE <<
00065         COMPOSITE_LUMINIZE <<
00066         COMPOSITE_SCREEN <<
00067         COMPOSITE_OVERLAY <<
00068         COMPOSITE_UNDEF <<
00069         COMPOSITE_COPY_RED <<
00070         COMPOSITE_COPY_GREEN <<
00071         COMPOSITE_COPY_BLUE <<
00072         COMPOSITE_COPY_OPACITY;
00073     }
00074 }
00075 
00076 KisCompositeOpsModel::~KisCompositeOpsModel()
00077 {
00078 }
00079 
00080 int KisCompositeOpsModel::rowCount(const QModelIndex & /*parent*/) const
00081 {
00082     return m_list.count();
00083 }
00084 
00085 QVariant KisCompositeOpsModel::data(const QModelIndex & index, int role) const
00086 {
00087     if (index.isValid()) {
00088         switch (role) {
00089         case Qt::DisplayRole: {
00090             return m_list[index.row()].description;
00091         }
00092         case CompositeOpSortRole: {
00093             int idx = opsInOrder.indexOf(m_list[index.row()].id);
00094             if (idx == -1) return opsInOrder.count();
00095             return idx;
00096         }
00097         case KCategorizedSortFilterProxyModel::CategoryDisplayRole:
00098         case KCategorizedSortFilterProxyModel::CategorySortRole:
00099             return m_list[index.row()].category;
00100         }
00101     }
00102     return QVariant();
00103 }
00104 
00105 const QString& KisCompositeOpsModel::itemAt(const QModelIndex & index) const
00106 {
00107     if (!index.isValid()) return COMPOSITE_OVER;
00108     return m_list[index.row()].id;
00109 }
00110 
00111 QModelIndex KisCompositeOpsModel::indexOf(const KoCompositeOp* op) const
00112 {
00113     if (!op) return QModelIndex();
00114 
00115     return indexOf(op->id());
00116 }
00117 
00118 QModelIndex KisCompositeOpsModel::indexOf(const QString& id) const
00119 {
00120     int index = 0;
00121     foreach(const CompositeOpInfo&  op2, m_list) {
00122         if (id == op2.id)
00123             break;
00124         ++index;
00125     }
00126     if (index < m_list.count()) {
00127         return createIndex(index, 0);
00128     } else {
00129         return QModelIndex();
00130     }
00131 
00132 }