53
56
KoResourceServer<KisBrush>* rServer = KisBrushServer::instance()->brushServer();
54
57
m_rServerAdapter = new KoResourceServerAdapter<KisBrush>(rServer);
60
m_brushCreated = false;
56
62
connect(addButton, SIGNAL(pressed()), this, SLOT(slotAddPredefined()));
57
63
connect(brushButton, SIGNAL(pressed()), this, SLOT(slotUpdateCurrentBrush()));
58
// connect(exportButton, SIGNAL(pressed()), this, SLOT(slotExport()));
59
64
connect(brushStyle, SIGNAL(activated(int)), this, SLOT(slotUpdateCurrentBrush(int)));
60
connect(colorAsMask, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateCurrentBrush(int)));
65
connect(colorAsMask, SIGNAL(toggled(bool)), this, SLOT(slotUpdateUseColorAsMask(bool)));
66
connect(spacingSlider, SIGNAL(valueChanged(qreal)), this, SLOT(slotUpdateSpacing(qreal)));
61
67
slotUpdateCurrentBrush();
75
81
void KisCustomBrushWidget::showEvent(QShowEvent *)
77
slotUpdateCurrentBrush(0);
84
slotUpdateCurrentBrush(0);
85
m_brushCreated = true;
80
89
void KisCustomBrushWidget::slotUpdateCurrentBrush(int)
85
preview->setPixmap(QPixmap::fromImage(m_brush->image()));
87
emit sigBrushChanged();
90
void KisCustomBrushWidget::slotExport()
94
preview->setPixmap(QPixmap::fromImage( m_brush->image() ));
97
emit sigBrushChanged();
100
void KisCustomBrushWidget::slotUpdateSpacing(qreal spacing)
103
m_brush->setSpacing(spacing);
105
emit sigBrushChanged();
108
void KisCustomBrushWidget::slotUpdateUseColorAsMask(bool useColorAsMask)
111
static_cast<KisGbrBrush*>( m_brush.data() )->setUseColorAsMask( useColorAsMask );
112
preview->setPixmap(QPixmap::fromImage( m_brush->image() ));
114
emit sigBrushChanged();
95
118
void KisCustomBrushWidget::slotAddPredefined()
105
128
extension = ".gih";
131
QString name = nameLineEdit->text();
108
132
QString tempFileName;
112
file.setSuffix(extension);
113
file.setAutoRemove(false);
115
tempFileName = file.fileName();
135
fileInfo.setFile(dir + name + extension);
138
while (fileInfo.exists()) {
139
fileInfo.setFile(dir + name + QString("%1").arg(i) + extension);
143
tempFileName = fileInfo.filePath();
118
// Save it to that file
119
m_brush->setFilename(tempFileName);
120
m_brush->setValid(true);
122
146
// Add it to the brush server, so that it automatically gets to the mediators, and
123
147
// so to the other brush choosers can pick it up, if they want to
124
if (m_rServerAdapter)
125
m_rServerAdapter->addResource(static_cast<KisGbrBrush*>(m_brush.data())->clone());
148
if (m_rServerAdapter) {
149
KisGbrBrush * resource = static_cast<KisGbrBrush*>( m_brush.data() )->clone();
150
resource->setFilename(tempFileName);
152
if (nameLineEdit->text().isEmpty()){
153
resource->setName(QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm"));
155
resource->setName( name );
158
if (colorAsMask->isChecked()){
159
resource->makeMaskImage();
162
m_rServerAdapter->addResource( resource );
128
166
void KisCustomBrushWidget::createBrush()
172
// don't delete shared pointer, please
173
bool removedCorrectly = KisBrushServer::instance()->brushServer()->removeResourceFromServer( m_brush.data(), false );
174
if (!removedCorrectly){
175
kWarning() << "Brush was not removed correctly for the resource server";
133
179
if (brushStyle->currentIndex() == 0) {
134
m_brush = new KisGbrBrush(m_image->mergedImage().data(), 0, 0, m_image->width(), m_image->height());
135
if (colorAsMask->isChecked())
136
static_cast<KisGbrBrush*>(m_brush.data())->makeMaskImage();
140
// For each layer in the current image, create a new image, and add it to the list
141
QVector< QVector<KisPaintDevice*> > devices;
142
devices.push_back(QVector<KisPaintDevice*>());
143
int w = m_image->width();
144
int h = m_image->height();
146
// We only loop over the rootLayer. Since we actually should have a layer selection
147
// list, no need to elaborate on that here and now
148
KisLayer* layer = dynamic_cast<KisLayer*>(m_image->rootLayer()->firstChild().data());
150
KisPaintLayer* paint = 0;
151
if (layer->visible() && (paint = dynamic_cast<KisPaintLayer*>(layer)))
152
devices[0].push_back(paint->paintDevice().data());
153
layer = dynamic_cast<KisLayer*>(layer->nextSibling().data());
155
QVector<KisParasite::SelectionMode> modes;
157
switch (comboBox2->currentIndex()) {
158
case 0: modes.push_back(KisParasite::Constant); break;
159
case 1: modes.push_back(KisParasite::Random); break;
160
case 2: modes.push_back(KisParasite::Incremental); break;
161
case 3: modes.push_back(KisParasite::Pressure); break;
162
case 4: modes.push_back(KisParasite::Angular); break;
163
default: modes.push_back(KisParasite::Incremental);
166
m_brush = new KisImagePipeBrush(m_image->objectName(), w, h, devices, modes);
167
if (colorAsMask->isChecked())
168
static_cast<KisGbrBrush*>(m_brush.data())->makeMaskImage();
180
KisSelectionSP selection = m_image->globalSelection();
181
// create copy of the data
183
KisPaintDeviceSP dev = new KisPaintDevice(*m_image->mergedImage());
187
m_brush = new KisGbrBrush(dev, 0, 0, m_image->width(), m_image->height());
189
dev->applySelectionMask(selection);
190
QRect rc = dev->exactBounds();
191
m_brush = new KisGbrBrush(dev, rc.x(), rc.y(), rc.width(), rc.height());
195
// For each layer in the current image, create a new image, and add it to the list
196
QVector< QVector<KisPaintDevice*> > devices;
197
devices.push_back(QVector<KisPaintDevice*>());
198
int w = m_image->width();
199
int h = m_image->height();
201
// We only loop over the rootLayer. Since we actually should have a layer selection
202
// list, no need to elaborate on that here and now
203
KisLayer* layer = dynamic_cast<KisLayer*>(m_image->rootLayer()->firstChild().data());
205
KisPaintLayer* paint = 0;
206
if (layer->visible() && (paint = dynamic_cast<KisPaintLayer*>(layer)))
207
devices[0].push_back(paint->paintDevice().data());
208
layer = dynamic_cast<KisLayer*>(layer->nextSibling().data());
210
QVector<KisParasite::SelectionMode> modes;
212
switch (comboBox2->currentIndex()) {
213
case 0: modes.push_back(KisParasite::Constant); break;
214
case 1: modes.push_back(KisParasite::Random); break;
215
case 2: modes.push_back(KisParasite::Incremental); break;
216
case 3: modes.push_back(KisParasite::Pressure); break;
217
case 4: modes.push_back(KisParasite::Angular); break;
218
default: modes.push_back(KisParasite::Incremental);
221
m_brush = new KisImagePipeBrush(m_image->objectName(), w, h, devices, modes);
224
static_cast<KisGbrBrush*>( m_brush.data() )->setUseColorAsMask( colorAsMask->isChecked() );
225
m_brush->setSpacing(spacingSlider->value());
226
m_brush->setFilename(TEMPORARY_FILENAME);
227
m_brush->setName(TEMPORARY_BRUSH_NAME);
228
m_brush->setValid(true);
230
KisBrushServer::instance()->brushServer()->addResource( m_brush.data() , false);
171
233
void KisCustomBrushWidget::setImage(KisImageWSP image)