krita/ui
kis_composite_ops_model.ccGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 & ) 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 }
|