Commit f61547a9 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Merge branch 'master' of git.kde.org:calligra

parents 1de18417 4858d61d
......@@ -22,6 +22,7 @@
#include <KoColorSpace.h>
#include <KoAbstractGradient.h>
#include <KoCachedGradient.h>
#include <KoProgressUpdater.h>
#include <KoUpdater.h>
......@@ -469,6 +470,8 @@ KisGradientPainter::KisGradientPainter(KisPaintDeviceSP device, KisSelectionSP s
{
}
#include <QTime>
bool KisGradientPainter::paintGradient(const QPointF& gradientVectorStart,
const QPointF& gradientVectorEnd,
enumGradientShape shape,
......@@ -547,11 +550,10 @@ bool KisGradientPainter::paintGradient(const QPointF& gradientVectorStart,
KisHLineIteratorSP hit = dev->createHLineIteratorNG(startx, starty, width);
KisProgressUpdateHelper progressHelper(progressUpdater(), 100, height);
KoCachedGradient cachedGradient(gradient(), qMax(endy-starty, endx - startx), colorSpace);
for (int y = starty; y <= endy; y++) {
for (int x = startx; x <= endx; x++) {
double t = shapeStrategy->valueAt(x, y);
t = repeatStrategy->valueAt(t);
......@@ -559,8 +561,7 @@ bool KisGradientPainter::paintGradient(const QPointF& gradientVectorStart,
t = 1 - t;
}
gradient()->colorAt(color, t);
memcpy(hit->rawData(), color.data(), pixelSize);
memcpy(hit->rawData(), cachedGradient.cachedAt(t), pixelSize);
hit->nextPixel();
}
......@@ -571,6 +572,5 @@ bool KisGradientPainter::paintGradient(const QPointF& gradientVectorStart,
bitBlt(startx, starty, dev, startx, starty, width, height);
delete shapeStrategy;
return true;
}
......@@ -38,7 +38,6 @@
#include "kis_painter.h"
#include "kis_mask.h"
#include "kis_effect_mask.h"
#include "kis_transparency_mask.h"
#include "kis_selection_mask.h"
#include "kis_meta_data_store.h"
#include "kis_selection.h"
......@@ -112,7 +111,6 @@ public:
KisImageWSP image;
QBitArray channelFlags;
KisEffectMaskSP previewMask;
KisMetaData::Store* metaDataStore;
KisSafeProjection safeProjection;
KisCloneLayersList clonesList;
......@@ -299,10 +297,6 @@ QList<KisEffectMaskSP> KisLayer::effectMasks() const
{
QList<KisEffectMaskSP> masks;
if (m_d->previewMask && m_d->previewMask->visible()) {
masks.append(m_d->previewMask);
}
if (childCount() > 0) {
KoProperties properties;
properties.setProperty("visible", true);
......@@ -319,7 +313,6 @@ QList<KisEffectMaskSP> KisLayer::effectMasks() const
bool KisLayer::hasEffectMasks() const
{
if (m_d->previewMask && m_d->previewMask->visible()) return true;
if (childCount() == 0) return false;
KoProperties properties;
......@@ -559,25 +552,6 @@ QRect KisLayer::exactBounds() const
return originalDevice ? originalDevice->exactBounds() : QRect();
}
void KisLayer::setPreviewMask(KisEffectMaskSP mask)
{
if (m_d->previewMask) {
m_d->previewMask->setParent(0);
m_d->previewMask = 0;
}
if (mask) {
m_d->previewMask = mask;
m_d->previewMask->setParent(this);
}
}
KisEffectMaskSP KisLayer::previewMask() const
{
return m_d->previewMask;
}
KisLayerSP KisLayer::parentLayer() const
{
return dynamic_cast<KisLayer*>(parent().data());
......
......@@ -234,16 +234,6 @@ public:
QRect changeRect(const QRect &rect, PositionToFilthy pos = N_FILTHY) const;
/**
* Set a temporary effect mask on this layer for filter previews.
*/
void setPreviewMask(KisEffectMaskSP mask);
/**
* Retrieve the current preview effect mask
*/
KisEffectMaskSP previewMask() const;
/**
* Get the group layer that contains this layer.
*/
......
......@@ -157,7 +157,17 @@ bool KisStrokesQueue::checkStrokeState(bool hasStrokeJobsRunning)
KisStrokeSP stroke = m_d->strokesQueue.head();
bool result = false;
if(!stroke->isInitialized()) {
/**
* The stroke may be cancelled very fast. In this case it will
* end up in the state:
*
* !stroke->isInitialized() && stroke->isEnded() && !stroke->hasJobs()
*
* This means that !isInitialised() doesn't imply there are any
* jobs present.
*/
if(!stroke->isInitialized() && stroke->hasJobs()) {
m_d->needsExclusiveAccess = stroke->isExclusive();
result = true;
}
......
......@@ -225,18 +225,6 @@ void KisLayerTest::testMoveLayer()
}
void KisLayerTest::testHasEffectMasks()
{
KisLayerSP layer = new TestLayer(0, "layer1", OPACITY_OPAQUE_U8);
QVERIFY(layer->hasEffectMasks() == false);
KisFilterMaskSP mask = new KisFilterMask();
layer->setPreviewMask(mask);
QVERIFY(layer->hasEffectMasks());
layer->setPreviewMask(0);
QVERIFY(layer->hasEffectMasks() == false);
}
/*
+----------+
|root |
......@@ -269,6 +257,8 @@ void KisLayerTest::testMasksChangeRect()
image->addNode(filterMask1, paintLayer1);
image->addNode(filterMask2, paintLayer1);
QVERIFY(paintLayer1->hasEffectMasks());
QRect testRect(10, 10, 100, 100);
QRect resultRect;
......
......@@ -105,7 +105,6 @@ private slots:
void testOrdering();
void testMoveNode();
void testMoveLayer();
void testHasEffectMasks();
void testMasksChangeRect();
void testMoveLayerWithMaskThreaded();
};
......
......@@ -305,5 +305,17 @@ void KisStrokesQueueTest::testStrokesOverlapping()
VERIFY_EMPTY(jobs[1]);
}
void KisStrokesQueueTest::testImmediateCancel()
{
KisStrokesQueue queue;
KisTestableUpdaterContext context(2);
KisStrokeId id = queue.startStroke(new KisTestingStrokeStrategy("1_", false, false));
queue.cancelStroke(id);
// this should not crash
queue.processQueue(context, false);
}
QTEST_KDEMAIN(KisStrokesQueueTest, NoGUI)
#include "kis_strokes_queue_test.moc"
......@@ -32,6 +32,7 @@ private slots:
void testExclusiveStrokes();
void testBarrierStrokeJobs();
void testStrokesOverlapping();
void testImmediateCancel();
};
#endif /* __KIS_STROKES_QUEUE_TEST_H */
......@@ -81,7 +81,7 @@ void KisClipboardBrushWidget::slotUseBrushClicked(){
}
}
pd = m_clipboard->clip(QRect(0,0,0,0)); //Weird! Don't know how this works!
pd = m_clipboard->clip(QRect(0,0,0,0), false); //Weird! Don't know how this works!
QRect rc = pd->exactBounds();
m_brush = new KisGbrBrush(pd, rc.x(), rc.y(), rc.width(), rc.height());
......@@ -111,7 +111,6 @@ void KisClipboardBrushWidget::slotUpdateSpacing(qreal val){
}
void KisClipboardBrushWidget::showEvent(QShowEvent *){
m_clipboard->assumePasteFromWeb(true);
if(!m_brushCreated){
this->slotUseBrushClicked();
m_brushCreated = true;
......
......@@ -75,7 +75,6 @@ set(kritaui_LIB_SRCS
kis_part2.cpp
kis_factory2.cc
kis_file_layer.cpp
kis_filter_handler.cc
kis_filter_manager.cc
kis_filters_model.cc
kis_flipbook.cpp
......
......@@ -301,7 +301,7 @@ void KisCopyMergedActionFactory::run(KisView2 *view)
void KisPasteActionFactory::run(KisView2 *view)
{
KisImageWSP image = view->image();
KisPaintDeviceSP clip = KisClipboard::instance()->clip(image->bounds());
KisPaintDeviceSP clip = KisClipboard::instance()->clip(image->bounds(), true);
if (clip) {
KisPaintLayer *newLayer = new KisPaintLayer(image.data(), image->nextLayerName() + i18n("(pasted)"), OPACITY_OPAQUE_U8, clip);
......@@ -325,7 +325,7 @@ void KisPasteNewActionFactory::run(KisView2 *view)
{
Q_UNUSED(view);
KisPaintDeviceSP clip = KisClipboard::instance()->clip(QRect());
KisPaintDeviceSP clip = KisClipboard::instance()->clip(QRect(), true);
if (!clip) return;
QRect rect = clip->exactBounds();
......
......@@ -25,32 +25,32 @@
#include <kis_filter_mask.h>
#include <kis_node.h>
#include <kis_layer.h>
#include <kis_selection.h>
#include <kis_view2.h>
#include <kis_config.h>
#include "kis_selection.h"
#include "kis_node_commands_adapter.h"
#include "kis_filter_manager.h"
#include "ui_wdgfilterdialog.h"
struct KisFilterDialog::Private {
Private()
: currentFilter(0)
, mask(0)
, resizeCount(0)
, view(0) {
, view(0)
{
}
KisFilterSP currentFilter;
Ui_FilterDialog uiFilterDialog;
KisFilterMaskSP mask;
KisNodeSP node;
KisImageWSP image;
int resizeCount;
KisView2 *view;
KisFilterManager *filterManager;
};
KisFilterDialog::KisFilterDialog(KisView2 *view, KisNodeSP node, KisImageWSP image, KisSelectionSP selection) :
KisFilterDialog::KisFilterDialog(KisView2 *view, KisNodeSP node, KisFilterManager *filterManager) :
QDialog(view),
d(new Private)
{
......@@ -58,26 +58,14 @@ KisFilterDialog::KisFilterDialog(KisView2 *view, KisNodeSP node, KisImageWSP ima
d->uiFilterDialog.setupUi(this);
d->node = node;
d->image = image;
d->view = view;
d->filterManager = filterManager;
d->uiFilterDialog.filterSelection->setView(view);
d->uiFilterDialog.filterSelection->showFilterGallery(KisConfig().showFilterGallery());
if (d->node->inherits("KisLayer")) {
KisLayer *layer = dynamic_cast<KisLayer*>(node.data());
d->mask = new KisFilterMask();
d->mask->initSelection(selection, layer);
layer->setPreviewMask(d->mask);
d->uiFilterDialog.checkBoxPreview->show();
d->uiFilterDialog.pushButtonCreateMaskEffect->show();
d->uiFilterDialog.pushButtonCreateMaskEffect->setEnabled(true);
connect(d->uiFilterDialog.pushButtonCreateMaskEffect, SIGNAL(pressed()), SLOT(createMask()));
} else {
d->uiFilterDialog.checkBoxPreview->hide();
d->uiFilterDialog.pushButtonCreateMaskEffect->hide();
}
d->uiFilterDialog.pushButtonCreateMaskEffect->show();
connect(d->uiFilterDialog.pushButtonCreateMaskEffect, SIGNAL(pressed()), SLOT(createMask()));
d->uiFilterDialog.filterSelection->setPaintDevice(d->node->original());
d->uiFilterDialog.pushButtonOk->setGuiItem(KStandardGuiItem::ok());
......@@ -104,41 +92,48 @@ void KisFilterDialog::setFilter(KisFilterSP f)
{
Q_ASSERT(f);
setWindowTitle(f->name());
d->currentFilter = f;
d->uiFilterDialog.filterSelection->setFilter(f);
updatePreview();
}
void KisFilterDialog::updatePreview()
void KisFilterDialog::startApplyingFilter(KisSafeFilterConfigurationSP config)
{
if (!d->currentFilter) return;
if (!d->uiFilterDialog.filterSelection->configuration()) return;
if(d->mask && d->uiFilterDialog.checkBoxPreview->isChecked()) {
d->mask->setFilter(d->uiFilterDialog.filterSelection->configuration());
if (d->node->inherits("KisLayer")) {
config->setChannelFlags(qobject_cast<KisLayer*>(d->node.data())->channelFlags());
}
d->node->setDirty();
d->filterManager->apply(config);
}
void KisFilterDialog::updatePreview()
{
if (!d->uiFilterDialog.filterSelection->configuration()) return;
if (d->uiFilterDialog.checkBoxPreview->isChecked()) {
KisSafeFilterConfigurationSP config(d->uiFilterDialog.filterSelection->configuration());
startApplyingFilter(config);
}
d->uiFilterDialog.pushButtonOk->setEnabled(true);
}
void KisFilterDialog::apply()
{
if (!d->currentFilter) return;
KisSafeFilterConfigurationSP config(d->uiFilterDialog.filterSelection->configuration());
if (d->node->inherits("KisLayer")) {
config->setChannelFlags(qobject_cast<KisLayer*>(d->node.data())->channelFlags());
if (!d->filterManager->isStrokeRunning()) {
KisSafeFilterConfigurationSP config(d->uiFilterDialog.filterSelection->configuration());
startApplyingFilter(config);
}
emit(sigPleaseApplyFilter(config));
d->filterManager->finish();
d->uiFilterDialog.pushButtonOk->setEnabled(false);
}
void KisFilterDialog::close()
{
if (d->mask) {
qobject_cast<KisLayer*>(d->node.data())->setPreviewMask(0);;
d->node->setDirty();
if (d->filterManager->isStrokeRunning()) {
d->filterManager->cancel();
}
KisConfig().setShowFilterGallery(d->uiFilterDialog.filterSelection->isFilterGalleryVisible());
......@@ -146,28 +141,29 @@ void KisFilterDialog::close()
void KisFilterDialog::createMask()
{
if (!d->mask) return;
if (d->filterManager->isStrokeRunning()) {
d->filterManager->cancel();
}
KisLayer *layer = dynamic_cast<KisLayer*>(d->node.data());
layer->setPreviewMask(0);
KisFilterMaskSP mask = new KisFilterMask();
mask->initSelection(d->view->selection(), layer);
mask->setFilter(d->uiFilterDialog.filterSelection->configuration());
Q_ASSERT(layer->allowAsChild(d->mask));
Q_ASSERT(d->mask->parent() == 0);
Q_ASSERT(layer->allowAsChild(mask));
KisNodeCommandsAdapter adapter(d->view);
adapter.addNode(d->mask, layer, layer->lastChild());
d->mask = 0;
adapter.addNode(mask, layer, layer->lastChild());
accept();
}
void KisFilterDialog::previewCheckBoxChange(int state)
{
if (!d->mask) return;
d->mask->setVisible(state == Qt::Checked);
updatePreview();
if (state) {
updatePreview();
} else if (d->filterManager->isStrokeRunning()) {
d->filterManager->cancel();
}
KConfigGroup group(KGlobal::config(), "filterdialog");
group.writeEntry("showPreview", d->uiFilterDialog.checkBoxPreview->isChecked());
......@@ -190,7 +186,3 @@ void KisFilterDialog::resizeEvent(QResizeEvent* event)
d->resizeCount++;
}
}
#include "kis_dlg_filter.moc"
......@@ -27,6 +27,7 @@
class KisFilter;
class KisFilterConfiguration;
class KisView2;
class KisFilterManager;
class KisFilterDialog : public QDialog
{
......@@ -35,7 +36,7 @@ class KisFilterDialog : public QDialog
public:
KisFilterDialog(KisView2 *view, KisNodeSP node, KisImageWSP image, KisSelectionSP selection = 0);
KisFilterDialog(KisView2 *view, KisNodeSP node, KisFilterManager *filterManager);
~KisFilterDialog();
......@@ -57,9 +58,8 @@ protected slots:
virtual void resizeEvent(QResizeEvent* );
signals:
void sigPleaseApplyFilter(KisSafeFilterConfigurationSP);
private:
void startApplyingFilter(KisSafeFilterConfigurationSP config);
private:
struct Private;
......
......@@ -50,7 +50,6 @@ KisClipboard::KisClipboard()
{
m_pushedClipboard = false;
m_hasClip = false;
m_pasteFromWeb = false;
// Check that we don't already have a clip ready
clipboardDataChanged();
......@@ -161,7 +160,7 @@ void KisClipboard::setClip(KisPaintDeviceSP dev, const QPoint& topLeft)
}
KisPaintDeviceSP KisClipboard::clip(const QRect &imageBounds)
KisPaintDeviceSP KisClipboard::clip(const QRect &imageBounds, bool showPopup)
{
QByteArray mimeType("application/x-krita-selection");
......@@ -253,11 +252,7 @@ KisPaintDeviceSP KisClipboard::clip(const QRect &imageBounds)
quint32 behaviour = cfg.pasteBehaviour();
if(m_pasteFromWeb){
behaviour = PASTE_ASSUME_WEB;
}
if (behaviour == PASTE_ASK) {
if (behaviour == PASTE_ASK && showPopup) {
// Ask user each time.
behaviour = QMessageBox::question(0, i18n("Pasting data from simple source"), i18n("The image data you are trying to paste has no color profile information.\n\nOn the web and in simple applications the data are supposed to be in sRGB color format.\nImporting as web will show it as it is supposed to look.\nMost monitors are not perfect though so if you made the image yourself\nyou might want to import it as it looked on you monitor.\n\nHow do you want to interpret these data?"), i18n("As &Web"), i18n("As on &Monitor"));
}
......@@ -368,7 +363,4 @@ QSize KisClipboard::clipSize()
}
}
void KisClipboard::assumePasteFromWeb(bool pasteFromWeb){
m_pasteFromWeb = pasteFromWeb;
}
#include "kis_clipboard.moc"
......@@ -62,13 +62,12 @@ public:
/**
* Get the contents of the clipboard in the form of a paint device.
*/
KisPaintDeviceSP clip(const QRect &imageBounds);
KisPaintDeviceSP clip(const QRect &imageBounds, bool showPopup);
bool hasClip();
QSize clipSize();
void assumePasteFromWeb(bool pasteFromWeb);
private slots:
......@@ -83,8 +82,6 @@ private:
bool m_pushedClipboard;
bool m_pasteFromWeb;
signals:
void clipChanged();
};
......
/*
* Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
* Copyright (c) 2007 Boudewijn Rempt <boud@valdyas.org>
*
* 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_filter_handler.h"
#include <kmessagebox.h>
#include "kis_view2.h"
#include "kis_canvas2.h"
#include "kis_filter_manager.h"
#include "dialogs/kis_dlg_filter.h"
#include "strokes/kis_filter_stroke_strategy.h"
#include "krita_utils.h"
#include <kis_bookmarked_configuration_manager.h>
#include <filter/kis_filter.h>
#include <filter/kis_filter_configuration.h>
struct KisFilterHandler::Private {
Private(KisFilterHandler *_q)
: view(0)
, manager(0)
, q(_q)
{
}
~Private() {
}
KisFilterSP filter;
KisView2* view;
KisFilterManager* manager;
KisSafeFilterConfigurationSP lastConfiguration;
KisFilterHandler *q;
void saveConfiguration(KisFilterSP filter, KisSafeFilterConfigurationSP filterConfig);
};
void KisFilterHandler::Private::saveConfiguration(KisFilterSP filter, KisSafeFilterConfigurationSP filterConfig)
{
if (filter->bookmarkManager()) {
filter->bookmarkManager()->save(KisBookmarkedConfigurationManager::ConfigLastUsed.id(),
filterConfig.data());
}
lastConfiguration = filterConfig;
manager->setLastFilterHandler(q);
}
KisFilterHandler::KisFilterHandler(KisFilterManager* parent, KisFilterSP f, KisView2* view)
: QObject(parent)
, m_d(new Private(this))
{
m_d->filter = f;
m_d->view = view;
m_d->manager = parent;
}
KisFilterHandler::~KisFilterHandler()
{
delete m_d;
}
void KisFilterHandler::showDialog()
{
/**
* HACK ALERT:
* Until filters are ported to strokes, there should be a barrier
* to finish all the running strokes in the system