Commit 15065e15 authored by Halla Rempt's avatar Halla Rempt

Fix Sven's unittest and rename it (because I want to test the other methods

of KisPainter, too. It was a good unittest: it uncovered a real bug :-).

svn path=/trunk/koffice/; revision=685557
parent 4b93631f
......@@ -77,7 +77,6 @@ set(kritaimage_LIB_SRCS
kis_perspective_grid.cpp
kis_perspective_math.cpp
kis_mask.cc
kis_transparency_mask.cc
kis_effect_mask.cc
kis_progress_updater.cpp
kis_progress_updater_p.cpp
......
......@@ -883,7 +883,7 @@ QImage KisPaintDevice::convertToQImage(KoColorProfile * dstProfile, float expos
h = image()->height();
}
else {
extent(x1, y1, w, h);
exactBounds(x1, y1, w, h);
}
return convertToQImage(dstProfile, x1, y1, w, h, exposure);
......
......@@ -384,9 +384,11 @@ void KisPainter::bltMask(qint32 dx, qint32 dy,
QRect srcRect = QRect(sx, sy, sw, sh);
if (op != srcdev->colorSpace()->compositeOp( COMPOSITE_COPY )) {
srcRect &= srcdev->extent();
srcRect &= srcdev->exactBounds();
}
srcRect &= selMask->exactBounds();
if (srcRect.isEmpty()) {
return;
}
......
......@@ -251,12 +251,12 @@ public:
* @param sh the height of the region
*/
void bltMask(qint32 dx, qint32 dy,
const KoCompositeOp *op,
const KisPaintDeviceSP src,
const KisPaintDeviceSP selMask,
quint8 opacity,
qint32 sx, qint32 sy,
qint32 sw, qint32 sh);
const KoCompositeOp *op,
const KisPaintDeviceSP src,
const KisPaintDeviceSP selMask,
quint8 opacity,
qint32 sx, qint32 sy,
qint32 sw, qint32 sh);
/**
......
......@@ -41,7 +41,7 @@
KisPixelSelection::KisPixelSelection(KisPaintDeviceSP dev)
: KisMask(dev,
QString("selection for ") + dev->objectName())
QString("selection for ") + dev->objectName())
, m_parentPaintDevice(dev)
, m_dirty(false)
{
......@@ -374,4 +374,4 @@ void KisPixelSelection::renderToProjection(KisSelection* projection)
QRect r = selectedExactRect();
painter.bitBlt(r.x(), r.y(), COMPOSITE_OVER, KisPaintDeviceSP(this), r.x(), r.y(), r.width(), r.height());
painter.end();
}
\ No newline at end of file
}
......@@ -146,10 +146,15 @@ QRect KisSelection::selectedRect() const
QRect KisSelection::selectedExactRect() const
{
if(*(m_datamanager->defaultPixel()) == MIN_SELECTED || !m_parentPaintDevice)
kDebug() << ">>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
if(*(m_datamanager->defaultPixel()) == MIN_SELECTED || !m_parentPaintDevice) {
kDebug() << "bla1\n";
return exactBounds();
else
}
else {
kDebug() << "bla2\n";
return exactBounds().unite(m_parentPaintDevice->exactBounds());
}
}
void KisSelection::paint(QImage* img)
......
......@@ -71,13 +71,13 @@ target_link_libraries(KisImage_View_ConverterTest ${KDE4_KDEUI_LIBS} koguiutils
########### next target ###############
set(kis_selection_bltmask_test_SRCS kis_selection_bltmask_test.cpp )
set(kis_painter_test_SRCS kis_painter_test.cpp )
kde4_automoc(${kis_selection_bltmask_test_SRCS})
kde4_automoc(${kis_painter_test_SRCS})
kde4_add_unit_test(Kis_Selection_BltMask_Test TESTNAME krita-image-Selection-BltMask-Test ${kis_selection_bltmask_test_SRCS})
kde4_add_unit_test(Kis_Painter_Test TESTNAME krita-image-Painter-Test ${kis_painter_test_SRCS})
target_link_libraries(Kis_Selection_BltMask_Test ${KDE4_KDEUI_LIBS} koguiutils komain kritaimage ${QT_QTTEST_LIBRARY})
target_link_libraries(Kis_Painter_Test ${KDE4_KDEUI_LIBS} koguiutils komain kritaimage ${QT_QTTEST_LIBRARY})
########### next target ###############
......@@ -85,7 +85,7 @@ set(kis_threaded_applicator_test_SRCS kis_threaded_applicator_test.cpp )
kde4_automoc(${kis_threaded_applicator_test_SRCS})
kde4_add_unit_test(Kis_Threaded_Applicator_Test TESTNAME krita-image-Selection-BltMask-Test ${kis_threaded_applicator_test_SRCS})
kde4_add_unit_test(Kis_Threaded_Applicator_Test TESTNAME krita-image-Threaded_Applicator-Test ${kis_threaded_applicator_test_SRCS})
target_link_libraries(Kis_Threaded_Applicator_Test ${KDE4_KDEUI_LIBS} koguiutils komain kritaimage ${QT_QTTEST_LIBRARY})
......@@ -95,7 +95,7 @@ set(kis_painterly_overlay_test_SRCS kis_painterly_overlay_test.cpp )
kde4_automoc(${kis_painterly_overlay_test_SRCS})
kde4_add_unit_test(Kis_Painterly_Overlay_Test TESTNAME krita-image-Selection-BltMask-Test ${kis_painterly_overlay_test_SRCS})
kde4_add_unit_test(Kis_Painterly_Overlay_Test TESTNAME krita-image-Painterly-Overlay-Test ${kis_painterly_overlay_test_SRCS})
target_link_libraries(Kis_Painterly_Overlay_Test ${KDE4_KDEUI_LIBS} koguiutils komain kritaimage ${QT_QTTEST_LIBRARY})
......
......@@ -17,8 +17,9 @@
*/
#include <qtest_kde.h>
#include "kis_selection_bltmask_test.h"
#include "kis_painter_test.h"
#include <kdebug.h>
#include <QRect>
#include <KoColorSpace.h>
......@@ -29,30 +30,80 @@
#include "kis_paint_device.h"
#include "kis_painter.h"
#include "kis_pixel_selection.h"
/*
0,0 0,30
+---------+------+
| 10,10 | |
| +----+ |
| |####| |
| |####| |
+----+----+ |
| 20,20 |
| |
| |
+----------------+
30,30
*/
// void KisPainterTest::testPaintDeviceBltMask()
// {
// KisPaintDeviceSP dst = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8(), "dst");
// KisPixelSelectionSP src = new KisPaintDevice( KoColorSpaceRegistry::instance()->rgb8(), "src" );
// src->fill
// QCOMPARE( src->selectedExactRect(), QRect( 0, 0, 20, 20 ) );
// KisPixelSelectionSP mask = KisPixelSelectionSP(new KisPixelSelection(dev));
// mask->select(QRect(10,10,20,20));
// QCOMPARE( mask->selectedExactRect(), QRect( 10, 10, 20, 20 ) );
// KisPixelSelectionSP dst = KisPixelSelectionSP(new KisPixelSelection(dev));
// KisPainter painter(dst);
// painter.bltMask(0, 0,
// dst->colorSpace()->compositeOp(COMPOSITE_OVER),
// src,
// mask,
// OPACITY_OPAQUE,
// 0, 0, 30, 30);
// painter.end();
void KisSelectionBltMaskTest::testSelectionBltMask()
// //dst->convertToQImage(0).save( "bla.png" );
// QCOMPARE( dst->selectedExactRect(), QRect( 10, 10, 10, 10 ) );
// }
void KisPainterTest::testSelectionBltMask()
{
KisPaintDeviceSP dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8(), "temporary");
KisPixelSelectionSP selection1 = KisPixelSelectionSP(new KisPixelSelection(dev));
selection1->select(QRect(0,0,20,20));
KisPixelSelectionSP src = KisPixelSelectionSP(new KisPixelSelection(dev));
src->select(QRect(0,0,20,20));
QCOMPARE( src->selectedExactRect(), QRect( 0, 0, 20, 20 ) );
KisPixelSelectionSP mask = KisPixelSelectionSP(new KisPixelSelection(dev));
mask->select(QRect(10,10,20,20));
QCOMPARE( mask->selectedExactRect(), QRect( 10, 10, 20, 20 ) );
KisPixelSelectionSP selection2 = KisPixelSelectionSP(new KisPixelSelection(dev));
selection1->select(QRect(10,10,20,20));
KisPixelSelectionSP dst = KisPixelSelectionSP(new KisPixelSelection(dev));
KisPainter painter(dst);
KisPixelSelectionSP tmpSel = KisPixelSelectionSP(new KisPixelSelection(dev));
KisPainter painter(tmpSel);
QRect r = QRect(0,0,30,30);
painter.bltMask(r.x(), r.y(), selection1->colorSpace()->compositeOp(COMPOSITE_OVER), KisPaintDeviceSP(selection1.data()),
KisPaintDeviceSP(selection2.data()), OPACITY_OPAQUE, r.x(), r.y(), r.width(), r.height());
painter.bltMask(0, 0,
dst->colorSpace()->compositeOp(COMPOSITE_OVER),
src,
mask,
OPACITY_OPAQUE,
0, 0, 30, 30);
painter.end();
QRect selectionExtent = tmpSel->selectedExactRect();
QCOMPARE( selectionExtent.width(), 10 );
QCOMPARE( selectionExtent.height(), 10 );
//dst->convertToQImage(0).save( "bla.png" );
QCOMPARE( dst->selectedExactRect(), QRect( 10, 10, 10, 10 ) );
}
QTEST_KDEMAIN(KisSelectionBltMaskTest, NoGUI)
#include "kis_selection_bltmask_test.moc"
QTEST_KDEMAIN(KisPainterTest, NoGUI)
#include "kis_painter_test.moc"
......@@ -21,13 +21,14 @@
#include <QtTest/QtTest>
class KisSelectionBltMaskTest : public QObject
class KisPainterTest : public QObject
{
Q_OBJECT
private slots:
void testSelectionBltMask();
// void testPaintDeviceBltMask();
};
......
......@@ -90,7 +90,7 @@ public:
QWidget * optionWidget();
/**
* Quick help is a short help text about the way the tool functions.
* Quick help is a short help text about the way the tool functions.
*
* Deprecated: this method may move to KoToolFactory.
*/
......@@ -227,7 +227,9 @@ public slots:
* This method is called when this tool instance is activated.
* For any main window there is only one tool active at a time, which then gets all
* user input. Switching between tools will call deactivate on one and activate on the
* new tool allowing the tool to flush items (like a selection) when it is not in use.
* new tool allowing the tool to flush items (like a selection)
* when it is not in use.
*
* <p>There is one case where two tools are activated at the same. This is the case
* where one tool delegates work to another temporarily. For example, while shift is
* being held down. The second tool will get activated with temporary=true and
......
......@@ -281,7 +281,9 @@ void KoToolManager::switchTool(KoTool *tool, bool temporary) {
Q_ASSERT(tool);
if (d->canvasData == 0)
return;
bool newActiveTool = d->canvasData->activeTool != 0;
if (newActiveTool) {
d->canvasData->activeTool->repaintDecorations();
// check if this tool is inputDeviceAgnostic and used by other devices, in which case we should not deactivate.
......@@ -294,10 +296,11 @@ void KoToolManager::switchTool(KoTool *tool, bool temporary) {
}
}
}
if(newActiveTool) {
foreach(QAction *action, d->canvasData->activeTool->actions().values())
action->setEnabled(false);
// repaint the decorations before we deactivate the tool as it might deleted
// repaint the decorations before we deactivate the tool as it might deleted
// data needed for the repaint
d->canvasData->activeTool->deactivate();
disconnect(d->canvasData->activeTool, SIGNAL(cursorChanged(QCursor)),
......@@ -308,6 +311,7 @@ void KoToolManager::switchTool(KoTool *tool, bool temporary) {
this, SLOT(switchToolTemporaryRequested(const QString &)));
disconnect(d->canvasData->activeTool, SIGNAL(done()), this, SLOT(switchBackRequested()));
}
d->canvasData->activeTool = tool;
connect(d->canvasData->activeTool, SIGNAL(cursorChanged(QCursor)),
this, SLOT(updateCursor(QCursor)));
......@@ -548,7 +552,7 @@ void KoToolManager::switchInputDevice(const KoInputDevice &device) {
if (device.isMouse() && d->tabletEventTimer.isActive()) {
// Ignore switch to mouse for a short time after a tablet event
// is received, as this is likely to be either the mouse event sent
// to a widget that doesn't accept the tablet event, or, on X11,
// to a widget that doesn't accept the tablet event, or, on X11,
// a core event sent after the tablet event.
return;
}
......
......@@ -229,6 +229,7 @@ void Canvas::paintEvent(QPaintEvent * e) {
}
bool Canvas::event(QEvent *e) {
/*
if (e->type() == QEvent::ToolTip) {
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(e);
......@@ -239,6 +240,7 @@ bool Canvas::event(QEvent *e) {
else
QToolTip::showText(helpEvent->globalPos(), "");
}
*/
return QWidget::event(e);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment