5 from PyQt4
import QtCore, QtGui
6 from immutable_gradient_info_handler
import ImmutableGradientInfoHandler
7 from gradient_info_handler
import GradientInfoHandler
13 MUTABLE_GRADIENTS_PATH =
"user_gradients.xml"
16 QtCore.QAbstractListModel.__init__(self, parent, *args)
21 self.
immutable_infoh_ = ImmutableGradientInfoHandler(GradientListModel.IMMUTABLE_GRADIENTS_PATH)
22 self.
infoh_ = GradientInfoHandler(GradientListModel.MUTABLE_GRADIENTS_PATH)
25 def AddItem(self, name, gradient, row, editable, save):
29 self.
data_[row] = [name, gradient, icon, editable]
30 model_index = self.createIndex(row,0)
31 index = self.index(row)
32 end_index = self.createIndex(self.
rowCount(),0)
35 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, end_index)
40 return self.
data_[row][3]
44 name = self.
data_[row][0]
46 model_index = self.createIndex(row,0)
47 self.infoh_.RemoveGradient(name)
48 self.emit(QtCore.SIGNAL(
"dataChanged"),model_index, model_index)
53 self.infoh_.StoreQGradient(gradient,str(name))
57 qgradients = self.immutable_infoh_.GetQGradients()
58 for k, v
in qgradients.iteritems():
61 qgradients = self.infoh_.GetQGradients()
62 for k, v
in qgradients.iteritems():
66 if model_index.isValid():
67 return self.
data_[model_index.row()][1]
74 pixmap = QtGui.QPixmap(64, 64)
75 pixmap.fill(QtCore.Qt.transparent)
76 painter = QtGui.QPainter()
77 if painter.begin(pixmap):
78 gradient.setStart(QtCore.QPointF(0, 0))
79 gradient.setFinalStop(QtCore.QPointF(64, 0))
80 brush = QtGui.QBrush(gradient)
81 painter.setBrush(brush)
82 painter.drawRect(0, 0, 64, 64)
85 return QtGui.QIcon(pixmap)
90 for values
in self.
data_:
91 if string == values[0]:
96 def rowCount(self, parent=QtCore.QModelIndex()):
97 return len(self.
data_)
99 def data(self, index, role):
100 if index.isValid()
and index.row()< self.
rowCount():
101 data = self.
data_[index.row()]
102 if role == QtCore.Qt.DisplayRole:
103 return QtCore.QVariant(data[0])
104 elif role == QtCore.Qt.DecorationRole:
105 return QtCore.QVariant(data[2])
106 return QtCore.QVariant()
111 if not self.
data_[row]:
112 self.
data_[row] = list()
113 if role == QtCore.Qt.EditRole
and self.
NameIsValid(value.toString()):
114 old_name = str(self.
data_[row][0])
115 new_name = value.toString()
116 self.
data_[row][0] = new_name
117 self.infoh_.RenameGradient(old_name,str(new_name))
118 self.emit(QtCore.SIGNAL(
"dataChanged"),index, index)
120 elif role == QtCore.Qt.DisplayRole:
121 self.
data_[row][0] = value.toString()
122 elif role == QtCore.Qt.DecorationRole:
123 self.dat_[row][2] = value.toPyObject()
128 flags = QtCore.QAbstractItemModel.flags(self,index)
130 return flags | QtCore.Qt.ItemIsEditable
133 return QtCore.Qt.ItemIsEnabled
136 self.beginInsertRows(index, position, position)
137 self.data_.insert(position,list())
142 self.beginRemoveRows(index, position, position)
143 del self.
data_[position]
String DLLEXPORT_OST_BASE GetSharedDataPath()