diff --git a/plugins/paintops/libpaintop/forms/wdgclipboardbrush.ui b/plugins/paintops/libpaintop/forms/wdgclipboardbrush.ui index eebf22f2a3..69de1c94c9 100644 --- a/plugins/paintops/libpaintop/forms/wdgclipboardbrush.ui +++ b/plugins/paintops/libpaintop/forms/wdgclipboardbrush.ui @@ -1,209 +1,209 @@ KisWdgClipboardBrush 0 0 454 251 5 15 15 15 15 0 0 110 110 QFrame::Box QFrame::Plain 2 0 Qt::Vertical 20 40 - + 60 16777215 Spacing: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Name: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Create mask from color Qt::Vertical 20 40 Qt::Horizontal 40 20 Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Cancel|QDialogButtonBox::Save KisSpacingSelectionWidget QWidget
kis_spacing_selection_widget.h
1
buttonBox accepted() KisWdgClipboardBrush accept() 20 20 20 20 buttonBox rejected() KisWdgClipboardBrush reject() 20 20 20 20
diff --git a/plugins/paintops/libpaintop/forms/wdgcustombrush.ui b/plugins/paintops/libpaintop/forms/wdgcustombrush.ui index 384c4ea30b..6d04007636 100644 --- a/plugins/paintops/libpaintop/forms/wdgcustombrush.ui +++ b/plugins/paintops/libpaintop/forms/wdgcustombrush.ui @@ -1,318 +1,318 @@ KisWdgCustomBrush 0 0 462 311 6 15 15 15 15 0 0 110 110 QFrame::Box Qt::Vertical 20 40 - + Spacing: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Name: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Create mask from color 0 110 Brush Style false 20 20 301 71 3 0 0 Style: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 0 0 Regular Animated 0 0 Selection mode: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false 0 0 2 Constant Random Incremental Pressure Angular Qt::Vertical 20 40 Qt::Horizontal 40 20 Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Cancel|QDialogButtonBox::Save KisSpacingSelectionWidget QWidget
kis_spacing_selection_widget.h
1
buttonBox accepted() KisWdgCustomBrush accept() 20 20 20 20 buttonBox rejected() KisWdgCustomBrush reject() 20 20 20 20
diff --git a/plugins/paintops/libpaintop/kis_clipboard_brush_widget.cpp b/plugins/paintops/libpaintop/kis_clipboard_brush_widget.cpp index cd4f76d048..572104bd0e 100644 --- a/plugins/paintops/libpaintop/kis_clipboard_brush_widget.cpp +++ b/plugins/paintops/libpaintop/kis_clipboard_brush_widget.cpp @@ -1,159 +1,162 @@ /* * Copyright (c) 2005 Bart Coppens * Copyright (c) 2010 Lukáš Tvrdý * Copyright (c) 2013 Somsubhra Bairi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_clipboard_brush_widget.h" #include #include #include #include #include - +#include #include #include #include "kis_image.h" #include "kis_clipboard.h" #include "kis_paint_device.h" #include "kis_gbr_brush.h" #include "KisBrushServerProvider.h" +#include "kis_icon.h" KisClipboardBrushWidget::KisClipboardBrushWidget(QWidget *parent, const QString &caption, KisImageWSP /*image*/) : KisWdgClipboardBrush(parent) { setWindowTitle(caption); preview->setScaledContents(true); preview->setFixedSize(preview->size()); preview->setStyleSheet("border: 2px solid #222; border-radius: 4px; padding: 5px; font: normal 10px;"); m_rServer = KisBrushServerProvider::instance()->brushServer(); m_brush = 0; m_clipboard = KisClipboard::instance(); connect(m_clipboard, SIGNAL(clipChanged()), this, SLOT(slotCreateBrush())); connect(colorAsmask, SIGNAL(toggled(bool)), this, SLOT(slotUpdateUseColorAsMask(bool))); connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotAddPredefined())); + connect(nameEdit, SIGNAL(textEdited(const QString&)), this, SLOT(slotUpdateSaveButton())); spacingWidget->setSpacing(true, 1.0); connect(spacingWidget, SIGNAL(sigSpacingChanged()), SLOT(slotSpacingChanged())); } KisClipboardBrushWidget::~KisClipboardBrushWidget() { } void KisClipboardBrushWidget::slotCreateBrush() { // do nothing if it's hidden otherwise it can break the active brush is something is copied if (m_clipboard->hasClip() && !isHidden()) { pd = m_clipboard->clip(QRect(0, 0, 0, 0), false); //Weird! Don't know how this works! if (pd) { QRect rc = pd->exactBounds(); m_brush = KisBrushSP(new KisGbrBrush(pd, rc.x(), rc.y(), rc.width(), rc.height())); m_brush->setSpacing(spacingWidget->spacing()); m_brush->setAutoSpacing(spacingWidget->autoSpacingActive(), spacingWidget->autoSpacingCoeff()); m_brush->setFilename(TEMPORARY_CLIPBOARD_BRUSH_FILENAME); m_brush->setName(TEMPORARY_CLIPBOARD_BRUSH_NAME); m_brush->setValid(true); preview->setPixmap(QPixmap::fromImage(m_brush->image())); } } else { preview->setText(i18n("Nothing copied\n to Clipboard")); } if (!m_brush) { buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } else { buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); colorAsmask->setChecked(true); // initializing this has to happen here since we need a valid brush for it to work } } void KisClipboardBrushWidget::slotSpacingChanged() { if (m_brush) { m_brush->setSpacing(spacingWidget->spacing()); m_brush->setAutoSpacing(spacingWidget->autoSpacingActive(), spacingWidget->autoSpacingCoeff()); } } void KisClipboardBrushWidget::showEvent(QShowEvent *) { slotCreateBrush(); } void KisClipboardBrushWidget::slotUpdateUseColorAsMask(bool useColorAsMask) { if (m_brush) { static_cast(m_brush.data())->setUseColorAsMask(useColorAsMask); preview->setPixmap(QPixmap::fromImage(m_brush->brushTipImage())); } } void KisClipboardBrushWidget::slotAddPredefined() { if(!m_brush) return; QString dir = KoResourcePaths::saveLocation("data", ResourceType::Brushes); QString extension = ".gbr"; QString name = nameEdit->text(); - QString tempFileName; - QFileInfo fileInfo; - fileInfo.setFile(dir + name + extension); - - int i = 1; - while (fileInfo.exists()) { - fileInfo.setFile(dir + name + QString("%1").arg(i) + extension); - i++; - } - tempFileName = fileInfo.filePath(); - if (m_rServer) { KisGbrBrushSP resource = m_brush->clone().dynamicCast(); - resource->setFilename(tempFileName); if (nameEdit->text().isEmpty()) { resource->setName(QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm")); } else { resource->setName(name); } + resource->setFilename(resource->name().split(" ").join("_") + extension); + + if (colorAsmask->isChecked()) { resource->makeMaskImage(); } m_rServer->addResource(resource.dynamicCast()); emit sigNewPredefinedBrush(resource); } close(); } +void KisClipboardBrushWidget::slotUpdateSaveButton() +{ + if (QFileInfo(m_rServer->saveLocation() + "/" + nameEdit->text().split(" ").join("_") + + ".gbr").exists()) { + buttonBox->button(QDialogButtonBox::Save)->setText(i18n("Overwrite")); + } else { + buttonBox->button(QDialogButtonBox::Save)->setText(i18n("Save")); + } +} + #include "moc_kis_clipboard_brush_widget.cpp" diff --git a/plugins/paintops/libpaintop/kis_clipboard_brush_widget.h b/plugins/paintops/libpaintop/kis_clipboard_brush_widget.h index 4e767e9c10..673fb458d2 100644 --- a/plugins/paintops/libpaintop/kis_clipboard_brush_widget.h +++ b/plugins/paintops/libpaintop/kis_clipboard_brush_widget.h @@ -1,74 +1,75 @@ /* * Copyright (c) 2005 Bart Coppens * Copyright (c) 2013 Somsubhra Bairi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_CLIPBOARD_BRUSH_WIDGET_H #define KIS_CLIPBOARD_BRUSH_WIDGET_H #include #include #include #include #include #include "ui_wdgclipboardbrush.h" const QString TEMPORARY_CLIPBOARD_BRUSH_FILENAME = "/tmp/temporaryClipboardBrush.gbr"; const QString TEMPORARY_CLIPBOARD_BRUSH_NAME = "Temporary clipboard brush"; const double DEFAULT_CLIPBOARD_BRUSH_SPACING = 0.25; class KisClipboard; class KoResource; class KisWdgClipboardBrush : public QDialog, public Ui::KisWdgClipboardBrush { Q_OBJECT public: KisWdgClipboardBrush(QWidget* parent) : QDialog(parent) { setupUi(this); } }; class KisClipboardBrushWidget : public KisWdgClipboardBrush { Q_OBJECT public: KisClipboardBrushWidget(QWidget* parent, const QString& caption, KisImageWSP image); virtual ~KisClipboardBrushWidget(); private Q_SLOTS: void slotCreateBrush(); void slotSpacingChanged(); void slotUpdateUseColorAsMask(bool useColorAsMask); void slotAddPredefined(); + void slotUpdateSaveButton(); protected: void showEvent(QShowEvent *); Q_SIGNALS: void sigNewPredefinedBrush(KoResourceSP ); private: KisClipboard* m_clipboard; KisPaintDeviceSP pd; KisBrushSP m_brush; KoResourceServer *m_rServer; }; #endif // KIS_CLIPBOARD_BRUSH_WIDGET_H diff --git a/plugins/paintops/libpaintop/kis_custom_brush_widget.cpp b/plugins/paintops/libpaintop/kis_custom_brush_widget.cpp index b4acf06c0e..ddfc9061e1 100644 --- a/plugins/paintops/libpaintop/kis_custom_brush_widget.cpp +++ b/plugins/paintops/libpaintop/kis_custom_brush_widget.cpp @@ -1,265 +1,267 @@ /* * Copyright (c) 2005 Bart Coppens * Copyright (c) 2010 Lukáš Tvrdý * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_custom_brush_widget.h" #include #include #include #include #include #include #include #include #include #include #include "kis_image.h" #include "kis_layer.h" #include "kis_paint_device.h" #include "kis_gbr_brush.h" #include "kis_imagepipe_brush.h" #include #include "KisBrushServerProvider.h" #include "kis_paint_layer.h" #include "kis_group_layer.h" #include #include #include "kis_iterator_ng.h" KisCustomBrushWidget::KisCustomBrushWidget(QWidget *parent, const QString& caption, KisImageWSP image) : KisWdgCustomBrush(parent) , m_image(image) { setWindowTitle(caption); preview->setScaledContents(false); preview->setFixedSize(preview->size()); preview->setStyleSheet("border: 2px solid #222; border-radius: 4px; padding: 5px; font: normal 10px;"); m_rServer = KisBrushServerProvider::instance()->brushServer(); m_brush = 0; connect(this, SIGNAL(accepted()), SLOT(slotAddPredefined())); connect(brushStyle, SIGNAL(activated(int)), this, SLOT(slotUpdateCurrentBrush(int))); connect(colorAsMask, SIGNAL(toggled(bool)), this, SLOT(slotUpdateUseColorAsMask(bool))); connect(comboBox2, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateCurrentBrush(int))); colorAsMask->setChecked(true); // use color as mask by default. This is by far the most common way to make tip. spacingWidget->setSpacing(true, 1.0); connect(spacingWidget, SIGNAL(sigSpacingChanged()), SLOT(slotSpacingChanged())); } KisCustomBrushWidget::~KisCustomBrushWidget() { } KisBrushSP KisCustomBrushWidget::brush() { return m_brush; } void KisCustomBrushWidget::setImage(KisImageWSP image){ m_image = image; createBrush(); updatePreviewImage(); } void KisCustomBrushWidget::showEvent(QShowEvent *) { slotUpdateCurrentBrush(0); } void KisCustomBrushWidget::updatePreviewImage() { QImage brushImage = m_brush ? m_brush->brushTipImage() : QImage(); if (!brushImage.isNull()) { brushImage = brushImage.scaled(preview->size(), Qt::KeepAspectRatio); } preview->setPixmap(QPixmap::fromImage(brushImage)); } void KisCustomBrushWidget::slotUpdateCurrentBrush(int) { if (brushStyle->currentIndex() == 0) { comboBox2->setEnabled(false); } else { comboBox2->setEnabled(true); } if (m_image) { createBrush(); updatePreviewImage(); } } void KisCustomBrushWidget::slotSpacingChanged() { if (m_brush) { m_brush->setSpacing(spacingWidget->spacing()); m_brush->setAutoSpacing(spacingWidget->autoSpacingActive(), spacingWidget->autoSpacingCoeff()); } } void KisCustomBrushWidget::slotUpdateUseColorAsMask(bool useColorAsMask) { if (m_brush) { static_cast(m_brush.data())->setUseColorAsMask(useColorAsMask); updatePreviewImage(); } } +void KisCustomBrushWidget::slotUpdateSaveButton() +{ + QString suffix = ".gbr"; + if (brushStyle->currentIndex() != 0) { + suffix = ".gih"; + } + if (QFileInfo(m_rServer->saveLocation() + "/" + nameLineEdit->text().split(" ").join("_") + + suffix).exists()) { + buttonBox->button(QDialogButtonBox::Save)->setText(i18n("Overwrite")); + } else { + buttonBox->button(QDialogButtonBox::Save)->setText(i18n("Save")); + } +} + void KisCustomBrushWidget::slotAddPredefined() { QString dir = KoResourcePaths::saveLocation("data", ResourceType::Brushes); QString extension; if (brushStyle->currentIndex() == 0) { extension = ".gbr"; } else { extension = ".gih"; } QString name = nameLineEdit->text(); - QString tempFileName; - { - QFileInfo fileInfo; - fileInfo.setFile(dir + name + extension); - - int i = 1; - while (fileInfo.exists()) { - fileInfo.setFile(dir + name + QString("%1").arg(i) + extension); - i++; - } - - tempFileName = fileInfo.filePath(); - } // Add it to the brush server, so that it automatically gets to the mediators, and // so to the other brush choosers can pick it up, if they want to if (m_rServer && m_brush) { qDebug() << "m_brush" << m_brush; KisGbrBrushSP resource = m_brush->clone().dynamicCast(); - resource->setFilename(tempFileName); if (nameLineEdit->text().isEmpty()) { resource->setName(QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm")); } else { resource->setName(name); } + resource->setFilename(resource->name().split(" ").join("_") + extension); + if (colorAsMask->isChecked()) { resource->makeMaskImage(); } m_rServer->addResource(resource.dynamicCast()); emit sigNewPredefinedBrush(resource); } close(); } void KisCustomBrushWidget::createBrush() { if (!m_image) return; if (brushStyle->currentIndex() == 0) { KisSelectionSP selection = m_image->globalSelection(); // create copy of the data m_image->lock(); KisPaintDeviceSP dev = new KisPaintDevice(*m_image->projection()); m_image->unlock(); if (!selection) { m_brush = KisBrushSP(new KisGbrBrush(dev, 0, 0, m_image->width(), m_image->height())); } else { // apply selection mask QRect r = selection->selectedExactRect(); dev->crop(r); KisHLineIteratorSP pixelIt = dev->createHLineIteratorNG(r.x(), r.top(), r.width()); KisHLineConstIteratorSP maskIt = selection->projection()->createHLineIteratorNG(r.x(), r.top(), r.width()); for (qint32 y = r.top(); y <= r.bottom(); ++y) { do { dev->colorSpace()->applyAlphaU8Mask(pixelIt->rawData(), maskIt->oldRawData(), 1); } while (pixelIt->nextPixel() && maskIt->nextPixel()); pixelIt->nextRow(); maskIt->nextRow(); } QRect rc = dev->exactBounds(); m_brush = KisBrushSP(new KisGbrBrush(dev, rc.x(), rc.y(), rc.width(), rc.height())); } } else { // For each layer in the current image, create a new image, and add it to the list QVector< QVector > devices; devices.push_back(QVector()); int w = m_image->width(); int h = m_image->height(); m_image->lock(); // We only loop over the rootLayer. Since we actually should have a layer selection // list, no need to elaborate on that here and now KoProperties properties; properties.setProperty("visible", true); QList layers = m_image->root()->childNodes(QStringList("KisLayer"), properties); KisNodeSP node; Q_FOREACH (KisNodeSP node, layers) { devices[0].push_back(node->projection().data()); } QVector modes; switch (comboBox2->currentIndex()) { case 0: modes.push_back(KisParasite::Constant); break; case 1: modes.push_back(KisParasite::Random); break; case 2: modes.push_back(KisParasite::Incremental); break; case 3: modes.push_back(KisParasite::Pressure); break; case 4: modes.push_back(KisParasite::Angular); break; default: modes.push_back(KisParasite::Incremental); } m_brush = KisBrushSP(new KisImagePipeBrush(m_image->objectName(), w, h, devices, modes)); m_image->unlock(); } static_cast(m_brush.data())->setUseColorAsMask(colorAsMask->isChecked()); m_brush->setSpacing(spacingWidget->spacing()); m_brush->setAutoSpacing(spacingWidget->autoSpacingActive(), spacingWidget->autoSpacingCoeff()); m_brush->setFilename(TEMPORARY_FILENAME); m_brush->setName(TEMPORARY_BRUSH_NAME); m_brush->setValid(true); } diff --git a/plugins/paintops/libpaintop/kis_custom_brush_widget.h b/plugins/paintops/libpaintop/kis_custom_brush_widget.h index 51dd3fcdd5..52767e2464 100644 --- a/plugins/paintops/libpaintop/kis_custom_brush_widget.h +++ b/plugins/paintops/libpaintop/kis_custom_brush_widget.h @@ -1,81 +1,82 @@ /* * Copyright (c) 2005 Bart Coppens * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_CUSTOM_BRUSH_H_ #define KIS_CUSTOM_BRUSH_H_ #include #include #include "ui_wdgcustombrush.h" #include #include #include const QString TEMPORARY_FILENAME = "/tmp/temporaryKritaBrush.gbr"; const QString TEMPORARY_BRUSH_NAME = "Temporary custom brush"; const double DEFAULT_SPACING = 0.25; class KoResource; class KisWdgCustomBrush : public QDialog, public Ui::KisWdgCustomBrush { Q_OBJECT public: KisWdgCustomBrush(QWidget *parent) : QDialog(parent) { setupUi(this); } }; class KisCustomBrushWidget : public KisWdgCustomBrush { Q_OBJECT public: KisCustomBrushWidget(QWidget *parent, const QString& caption, KisImageWSP image); virtual ~KisCustomBrushWidget(); KisBrushSP brush(); void setImage(KisImageWSP image); protected: virtual void showEvent(QShowEvent *); private Q_SLOTS: void slotAddPredefined(); void slotUpdateCurrentBrush(int i = 0); // To connect with activated(int) void slotSpacingChanged(); void slotUpdateUseColorAsMask(bool useColorAsMask); + void slotUpdateSaveButton(); Q_SIGNALS: void sigNewPredefinedBrush(KoResourceSP ); private: void createBrush(); void updatePreviewImage(); KisImageWSP m_image; KisBrushSP m_brush; KoResourceServer *m_rServer {0}; }; #endif // KIS_CUSTOM_BRUSH_H_