~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to core/utilities/imageeditor/q3support/imageregionwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2004-08-17
 
7
 * Description : a widget to draw an image clip region.
 
8
 *
 
9
 * Copyright (C) 2004-2012 by Gilles Caulier <caulier dot gilles at gmail dot com>
 
10
 *
 
11
 * This program is free software; you can redistribute it
 
12
 * and/or modify it under the terms of the GNU General
 
13
 * Public License as published by the Free Software Foundation;
 
14
 * either version 2, or (at your option)
 
15
 * any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 * ============================================================ */
 
23
 
 
24
#include "imageregionwidget.moc"
 
25
 
 
26
// C++ includes
 
27
 
 
28
#include <cmath>
 
29
 
 
30
// Qt includes
 
31
 
 
32
#include <QCursor>
 
33
#include <QPainter>
 
34
#include <QPen>
 
35
#include <QImage>
 
36
#include <QBrush>
 
37
#include <QFont>
 
38
#include <QFontMetrics>
 
39
 
 
40
// KDE includes
 
41
 
 
42
#include <kiconloader.h>
 
43
#include <kcursor.h>
 
44
#include <klocale.h>
 
45
#include <kdebug.h>
 
46
 
 
47
// Local includes
 
48
 
 
49
#include "imageiface.h"
 
50
#include "previewtoolbar.h"
 
51
 
 
52
namespace Digikam
 
53
{
 
54
 
 
55
class ImageRegionWidget::Private
 
56
{
 
57
 
 
58
public:
 
59
 
 
60
    Private() :
 
61
        onMouseMovePreviewToggled(true),
 
62
        capturePtMode(false),
 
63
        renderingPreviewMode(PreviewToolBar::PreviewBothImagesVertCont),
 
64
        oldRenderingPreviewMode(PreviewToolBar::PreviewBothImagesVertCont),
 
65
        xpos(0),
 
66
        ypos(0),
 
67
        iface(0)
 
68
    {
 
69
    }
 
70
 
 
71
    bool        onMouseMovePreviewToggled;
 
72
    bool        capturePtMode;
 
73
 
 
74
    int         renderingPreviewMode;
 
75
    int         oldRenderingPreviewMode;
 
76
    int         xpos;
 
77
    int         ypos;
 
78
 
 
79
    QPixmap     pixmapRegion;          // Pixmap of current region to render.
 
80
 
 
81
    QPolygon    hightlightPoints;
 
82
 
 
83
    DImg        image;                 // Entire content image to render pixmap.
 
84
 
 
85
    ImageIface* iface;
 
86
};
 
87
 
 
88
ImageRegionWidget::ImageRegionWidget(QWidget* const parent)
 
89
    : PreviewWidget(parent), d(new Private)
 
90
{
 
91
    d->iface = new ImageIface;
 
92
    d->image = d->iface->original()->copy();
 
93
 
 
94
    setAttribute(Qt::WA_DeleteOnClose);
 
95
    setFrameStyle(QFrame::NoFrame);
 
96
    setMinimumSize(480, 320);
 
97
    setWhatsThis(i18n("<p>Here you can see the original clip image "
 
98
                      "which will be used for the preview computation.</p>"
 
99
                      "<p>Click and drag the mouse cursor in the "
 
100
                      "image to change the clip focus.</p>"));
 
101
 
 
102
    connect(this, SIGNAL(signalZoomFactorChanged(double)),
 
103
            this, SLOT(slotZoomFactorChanged()));
 
104
 
 
105
    connect(this, SIGNAL(signalContentTakeFocus()),
 
106
            this, SLOT(slotContentTakeFocus()));
 
107
 
 
108
    connect(this, SIGNAL(signalContentsMovedEvent(bool)),
 
109
            this, SLOT(slotOriginalImageRegionChanged(bool)));
 
110
}
 
111
 
 
112
ImageRegionWidget::~ImageRegionWidget()
 
113
{
 
114
    delete d->iface;
 
115
    delete d;
 
116
}
 
117
 
 
118
int ImageRegionWidget::previewWidth() const
 
119
{
 
120
    return d->image.width();
 
121
}
 
122
 
 
123
int ImageRegionWidget::previewHeight() const
 
124
{
 
125
    return d->image.height();
 
126
}
 
127
 
 
128
bool ImageRegionWidget::previewIsNull() const
 
129
{
 
130
    return d->image.isNull();
 
131
}
 
132
 
 
133
void ImageRegionWidget::resetPreview()
 
134
{
 
135
    d->image.reset();
 
136
}
 
137
 
 
138
void ImageRegionWidget::paintPreview(QPixmap* const pix, int sx, int sy, int sw, int sh)
 
139
{
 
140
    DImg img     = d->image.smoothScaleSection(sx, sy, sw, sh, tileSize(), tileSize());
 
141
    QPixmap pix2 = d->iface->convertToPixmap(img);
 
142
    QPainter p(pix);
 
143
    p.drawPixmap(0, 0, pix2, 0, 0, pix2.width(), pix2.height());
 
144
    p.end();
 
145
}
 
146
 
 
147
void ImageRegionWidget::setHighLightPoints(const QPolygon& pointsList)
 
148
{
 
149
    d->hightlightPoints = pointsList;
 
150
    repaintContents(false);
 
151
}
 
152
 
 
153
void ImageRegionWidget::setCapturePointMode(bool b)
 
154
{
 
155
    d->capturePtMode = b;
 
156
    viewport()->setMouseTracking(b);
 
157
 
 
158
    if (b)
 
159
    {
 
160
        d->oldRenderingPreviewMode = d->renderingPreviewMode;
 
161
        slotPreviewModeChanged(PreviewToolBar::PreviewOriginalImage);
 
162
        viewport()->setCursor(QCursor(SmallIcon("color-picker", 32), 1, 28));
 
163
    }
 
164
    else
 
165
    {
 
166
        slotPreviewModeChanged(d->oldRenderingPreviewMode);
 
167
        viewport()->unsetCursor();
 
168
    }
 
169
}
 
170
 
 
171
bool ImageRegionWidget::capturePointMode() const
 
172
{
 
173
    return d->capturePtMode;
 
174
}
 
175
 
 
176
void ImageRegionWidget::slotZoomFactorChanged()
 
177
{
 
178
    emit signalContentsMovedEvent(true);
 
179
}
 
180
 
 
181
void ImageRegionWidget::slotPreviewModeChanged(int mode)
 
182
{
 
183
    d->renderingPreviewMode = mode;
 
184
    updateContentsSize();
 
185
    slotZoomFactorChanged();
 
186
}
 
187
 
 
188
void ImageRegionWidget::viewportPaintExtraData()
 
189
{
 
190
    if (!m_movingInProgress && !d->pixmapRegion.isNull())
 
191
    {
 
192
        QPainter p(viewport());
 
193
        p.setRenderHint(QPainter::Antialiasing, true);
 
194
        p.setBackgroundMode(Qt::TransparentMode);
 
195
 
 
196
        QRect region;
 
197
 
 
198
        // Original region.
 
199
        region = getLocalImageRegionToRender();
 
200
        QRect ro(contentsToViewport(region.topLeft()), contentsToViewport(region.bottomRight()));
 
201
 
 
202
        // Target region.
 
203
        QRect rt(contentsToViewport(region.topLeft()), contentsToViewport(region.bottomRight()));
 
204
 
 
205
        p.translate(previewRect().topLeft());
 
206
 
 
207
        // Drawing separate view.
 
208
 
 
209
        if (d->renderingPreviewMode == PreviewToolBar::PreviewOriginalImage ||
 
210
            (d->renderingPreviewMode == PreviewToolBar::PreviewToggleOnMouseOver && !d->onMouseMovePreviewToggled))
 
211
        {
 
212
            drawText(&p, QPoint(rt.topLeft().x() + 20, rt.topLeft().y() + 20), i18n("Before"));
 
213
        }
 
214
        else if (d->renderingPreviewMode == PreviewToolBar::PreviewTargetImage ||
 
215
                 d->renderingPreviewMode == PreviewToolBar::NoPreviewMode      ||
 
216
                 (d->renderingPreviewMode == PreviewToolBar::PreviewToggleOnMouseOver && d->onMouseMovePreviewToggled))
 
217
        {
 
218
            p.drawPixmap(rt.x(), rt.y(), d->pixmapRegion, 0, 0, rt.width(), rt.height());
 
219
 
 
220
            if (d->renderingPreviewMode == PreviewToolBar::PreviewTargetImage ||
 
221
                d->renderingPreviewMode == PreviewToolBar::PreviewToggleOnMouseOver)
 
222
            {
 
223
                drawText(&p, QPoint(rt.topLeft().x() + 20, rt.topLeft().y() + 20), i18n("After"));
 
224
            }
 
225
        }
 
226
        else if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVert ||
 
227
                 d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVertCont)
 
228
        {
 
229
            if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVert)
 
230
            {
 
231
                rt.translate(rt.width(), 0);
 
232
            }
 
233
 
 
234
            if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVertCont)
 
235
            {
 
236
                ro.translate(-ro.width(), 0);
 
237
            }
 
238
 
 
239
            p.drawPixmap(rt.x(), rt.y(), d->pixmapRegion, 0, 0, rt.width(), rt.height());
 
240
 
 
241
            p.setPen(QPen(Qt::white, 2, Qt::SolidLine));
 
242
            p.drawLine(rt.topLeft().x(), rt.topLeft().y(), rt.bottomLeft().x(), rt.bottomLeft().y());
 
243
            p.setPen(QPen(Qt::red, 2, Qt::DotLine));
 
244
            p.drawLine(rt.topLeft().x(), rt.topLeft().y() + 1, rt.bottomLeft().x(), rt.bottomLeft().y() - 1);
 
245
 
 
246
            drawText(&p, QPoint(ro.topLeft().x() + 20, ro.topLeft().y() + 20), i18n("Before"));
 
247
            drawText(&p, QPoint(rt.topLeft().x() + 20, rt.topLeft().y() + 20), i18n("After"));
 
248
        }
 
249
        else if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorz ||
 
250
                 d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorzCont)
 
251
        {
 
252
            if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorz)
 
253
            {
 
254
                rt.translate(0, rt.height());
 
255
            }
 
256
 
 
257
            if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorzCont)
 
258
            {
 
259
                ro.translate(0, -ro.height());
 
260
            }
 
261
 
 
262
            p.drawPixmap(rt.x(), rt.y(), d->pixmapRegion, 0, 0, rt.width(), rt.height());
 
263
 
 
264
            p.setPen(QPen(Qt::white, 2, Qt::SolidLine));
 
265
            p.drawLine(rt.topLeft().x() + 1, rt.topLeft().y(), rt.topRight().x() - 1, rt.topRight().y());
 
266
            p.setPen(QPen(Qt::red, 2, Qt::DotLine));
 
267
            p.drawLine(rt.topLeft().x()  , rt.topLeft().y(), rt.topRight().x()  , rt.topRight().y());
 
268
 
 
269
            drawText(&p, QPoint(ro.topLeft().x() + 20, ro.topLeft().y() + 20), i18n("Before"));
 
270
            drawText(&p, QPoint(rt.topLeft().x() + 20, rt.topLeft().y() + 20), i18n("After"));
 
271
        }
 
272
 
 
273
        // Drawing highlighted points.
 
274
 
 
275
        if (!d->hightlightPoints.isEmpty())
 
276
        {
 
277
            QPoint pt;
 
278
            QRect  hpArea;
 
279
 
 
280
            for (int i = 0 ; i < d->hightlightPoints.count() ; ++i)
 
281
            {
 
282
                pt = d->hightlightPoints.point(i);
 
283
 
 
284
                if (getOriginalImageRegionToRender().contains(pt))
 
285
                {
 
286
                    int x = (int)(((double)pt.x() * tileSize()) / floor(tileSize() / zoomFactor()));
 
287
                    int y = (int)(((double)pt.y() * tileSize()) / floor(tileSize() / zoomFactor()));
 
288
 
 
289
                    QPoint hp(contentsToViewport(QPoint(x, y)));
 
290
                    hpArea.setSize(QSize((int)(16 * zoomFactor()), (int)(16 * zoomFactor())));
 
291
                    hpArea.moveCenter(hp);
 
292
 
 
293
                    p.setPen(QPen(Qt::white, 2, Qt::SolidLine));
 
294
                    p.drawLine(hp.x(), hpArea.y(), hp.x(), hp.y() - (int)(3 * zoomFactor()));
 
295
                    p.drawLine(hp.x(), hp.y() + (int)(3 * zoomFactor()), hp.x(), hpArea.bottom());
 
296
                    p.drawLine(hpArea.x(), hp.y(), hp.x() - (int)(3 * zoomFactor()), hp.y());
 
297
                    p.drawLine(hp.x() + (int)(3 * zoomFactor()), hp.y(), hpArea.right(), hp.y());
 
298
 
 
299
                    p.setPen(QPen(Qt::red, 2, Qt::DotLine));
 
300
                    p.drawLine(hp.x(), hpArea.y(), hp.x(), hp.y() - (int)(3 * zoomFactor()));
 
301
                    p.drawLine(hp.x(), hp.y() + (int)(3 * zoomFactor()), hp.x(), hpArea.bottom());
 
302
                    p.drawLine(hpArea.x(), hp.y(), hp.x() - (int)(3 * zoomFactor()), hp.y());
 
303
                    p.drawLine(hp.x() + (int)(3 * zoomFactor()), hp.y(), hpArea.right(), hp.y());
 
304
                }
 
305
            }
 
306
        }
 
307
 
 
308
        p.end();
 
309
    }
 
310
}
 
311
 
 
312
QRect ImageRegionWidget::getLocalImageRegionToRender() const
 
313
{
 
314
    QRect region;
 
315
    QRect pr = previewRect();
 
316
    int pX   = pr.x();
 
317
    int pY   = pr.y();
 
318
    int pW   = visibleWidth() > pr.width() ? pr.width() : visibleWidth();
 
319
    int pH   = visibleHeight() > pr.height() ? pr.height() : visibleHeight();
 
320
 
 
321
    if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVertCont)
 
322
    {
 
323
        region = QRect((int)ceilf(contentsX() - pX + visibleWidth() / 2.0),
 
324
                       contentsY(),
 
325
                       (int)ceilf(pW / 2.0),
 
326
                       pH);
 
327
    }
 
328
    else if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVert)
 
329
    {
 
330
        region = QRect(contentsX(),
 
331
                       contentsY(),
 
332
                       (int)ceilf(pW / 2.0),
 
333
                       pH);
 
334
    }
 
335
    else if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorzCont)
 
336
    {
 
337
        region = QRect(contentsX(),
 
338
                       (int)ceilf(contentsY() - pY + visibleHeight() / 2.0),
 
339
                       pW,
 
340
                       (int)ceilf(pH / 2.0));
 
341
    }
 
342
    else if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorz)
 
343
    {
 
344
        region = QRect(contentsX(),
 
345
                       contentsY(),
 
346
                       pW,
 
347
                       (int)ceilf(pH / 2.0));
 
348
    }
 
349
    else
 
350
    {
 
351
        region = QRect(contentsX(),
 
352
                       contentsY(),
 
353
                       pW,
 
354
                       pH);
 
355
    }
 
356
 
 
357
    return (region);
 
358
}
 
359
 
 
360
QRect ImageRegionWidget::getOriginalImageRegion() const
 
361
{
 
362
    QRect region;
 
363
 
 
364
    switch (d->renderingPreviewMode)
 
365
    {
 
366
        case PreviewToolBar::PreviewOriginalImage:
 
367
        case PreviewToolBar::PreviewTargetImage:
 
368
        case PreviewToolBar::PreviewBothImagesVert:
 
369
        case PreviewToolBar::PreviewBothImagesHorz:
 
370
        case PreviewToolBar::PreviewToggleOnMouseOver:
 
371
            region = QRect(contentsX(), contentsY(), visibleWidth(), visibleHeight());
 
372
            break;
 
373
 
 
374
        case PreviewToolBar::PreviewBothImagesVertCont:
 
375
            region = QRect(contentsX(), contentsY(), visibleWidth() / 2, visibleHeight());
 
376
            break;
 
377
 
 
378
        case PreviewToolBar::PreviewBothImagesHorzCont:
 
379
            region = QRect(contentsX(), contentsY(), visibleWidth(), visibleHeight() / 2);
 
380
            break;
 
381
    }
 
382
 
 
383
    return region;
 
384
}
 
385
 
 
386
QRect ImageRegionWidget::getOriginalImageRegionToRender() const
 
387
{
 
388
    QRect r = getLocalImageRegionToRender();
 
389
 
 
390
    int x = (int)(((double)r.x()      / tileSize()) * floor(tileSize() / zoomFactor()));
 
391
    int y = (int)(((double)r.y()      / tileSize()) * floor(tileSize() / zoomFactor()));
 
392
    int w = (int)(((double)r.width()  / tileSize()) * floor(tileSize() / zoomFactor()));
 
393
    int h = (int)(((double)r.height() / tileSize()) * floor(tileSize() / zoomFactor()));
 
394
 
 
395
    QRect rect(x, y, w, h);
 
396
    return (rect);
 
397
}
 
398
 
 
399
void ImageRegionWidget::setCenterImageRegionPosition()
 
400
{
 
401
    center(contentsWidth() / 2, contentsHeight() / 2);
 
402
    slotZoomFactorChanged();
 
403
}
 
404
 
 
405
void ImageRegionWidget::setContentsPosition(int x, int y, bool targetDone)
 
406
{
 
407
    if (targetDone)
 
408
    {
 
409
        m_movingInProgress = false;
 
410
    }
 
411
 
 
412
    setContentsPos(x, y);
 
413
 
 
414
    if (targetDone)
 
415
    {
 
416
        slotZoomFactorChanged();
 
417
    }
 
418
}
 
419
 
 
420
void ImageRegionWidget::backupPixmapRegion()
 
421
{
 
422
    d->pixmapRegion = QPixmap();
 
423
}
 
424
 
 
425
void ImageRegionWidget::restorePixmapRegion()
 
426
{
 
427
    m_movingInProgress = true;
 
428
    viewport()->repaint();
 
429
}
 
430
 
 
431
void ImageRegionWidget::setPreviewImage(const DImg& img)
 
432
{
 
433
    DImg image = img;
 
434
    QRect r    = getLocalImageRegionToRender();
 
435
    image.resize(r.width(), r.height());
 
436
 
 
437
    // Because image plugins are tool witch only work on image data, the DImg container
 
438
    // do not contain metadata from original image. About Color Managed View, we need to
 
439
    // restore the embedded ICC color profile.
 
440
    // However, some plugins may set a profile on the preview image, which we accept of course.
 
441
    if (image.getIccProfile().isNull())
 
442
    {
 
443
        image.setIccProfile(d->image.getIccProfile());
 
444
    }
 
445
 
 
446
    d->pixmapRegion = d->iface->convertToPixmap(image);
 
447
    repaintContents(false);
 
448
}
 
449
 
 
450
DImg ImageRegionWidget::getOriginalRegionImage(bool useDownscaledImage) const
 
451
{
 
452
    DImg image = d->image.copy(getOriginalImageRegionToRender());
 
453
 
 
454
    if (useDownscaledImage)
 
455
    {
 
456
        QRect r = getLocalImageRegionToRender();
 
457
        image.resize(r.width(), r.height());
 
458
    }
 
459
 
 
460
    return (image);
 
461
}
 
462
 
 
463
QImage ImageRegionWidget::previewToQImage() const
 
464
{
 
465
    return d->image.copyQImage();
 
466
}
 
467
 
 
468
void ImageRegionWidget::slotPanIconSelectionMoved(const QRect& rect, bool targetDone)
 
469
{
 
470
    PreviewWidget::slotPanIconSelectionMoved(rect, targetDone);
 
471
    setContentsPosition((int)(rect.x()*zoomFactor()), (int)(rect.y()*zoomFactor()), targetDone);
 
472
}
 
473
 
 
474
void ImageRegionWidget::slotContentTakeFocus()
 
475
{
 
476
    PreviewWidget::slotContentTakeFocus();
 
477
    restorePixmapRegion();
 
478
}
 
479
 
 
480
void ImageRegionWidget::slotContentLeaveFocus()
 
481
{
 
482
    PreviewWidget::slotContentLeaveFocus();
 
483
    setContentsPosition(contentsX(), contentsY(), true);
 
484
}
 
485
 
 
486
void ImageRegionWidget::slotOriginalImageRegionChanged(bool targetDone)
 
487
{
 
488
    if (targetDone)
 
489
    {
 
490
        backupPixmapRegion();
 
491
        emit signalOriginalClipFocusChanged();
 
492
    }
 
493
}
 
494
 
 
495
void ImageRegionWidget::exposureSettingsChanged()
 
496
{
 
497
    clearCache();
 
498
    viewport()->update();
 
499
}
 
500
 
 
501
void ImageRegionWidget::ICCSettingsChanged()
 
502
{
 
503
    clearCache();
 
504
    viewport()->update();
 
505
}
 
506
 
 
507
void ImageRegionWidget::enterEvent(QEvent*)
 
508
{
 
509
    if (d->renderingPreviewMode == PreviewToolBar::PreviewToggleOnMouseOver)
 
510
    {
 
511
        d->onMouseMovePreviewToggled = false;
 
512
        viewport()->repaint();
 
513
    }
 
514
}
 
515
 
 
516
void ImageRegionWidget::leaveEvent(QEvent*)
 
517
{
 
518
    if (d->renderingPreviewMode == PreviewToolBar::PreviewToggleOnMouseOver)
 
519
    {
 
520
        d->onMouseMovePreviewToggled = true;
 
521
        viewport()->repaint();
 
522
    }
 
523
}
 
524
 
 
525
void ImageRegionWidget::contentsMousePressEvent(QMouseEvent* e)
 
526
{
 
527
    if (d->capturePtMode)
 
528
    {
 
529
        QRect  region = getLocalImageRegionToRender();
 
530
        // Original region.
 
531
        QRect  ro(contentsToViewport(region.topLeft()), contentsToViewport(region.bottomRight()));
 
532
        // Target region.
 
533
        QRect rt(contentsToViewport(region.topLeft()), contentsToViewport(region.bottomRight()));
 
534
        QPoint tl = previewRect().topLeft();
 
535
        ro.translate(tl);
 
536
        rt.translate(tl);
 
537
 
 
538
        QPoint pt(contentsToViewport(e->pos()));
 
539
 
 
540
        // Drawing separate view.
 
541
 
 
542
        if (d->renderingPreviewMode == PreviewToolBar::PreviewOriginalImage ||
 
543
            (d->renderingPreviewMode == PreviewToolBar::PreviewToggleOnMouseOver && !d->onMouseMovePreviewToggled))
 
544
        {
 
545
            if (ro.contains(pt))
 
546
            {
 
547
                emitCapturedPointFromOriginal(pt - ro.topLeft());
 
548
            }
 
549
        }
 
550
        else if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVert ||
 
551
                 d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVertCont)
 
552
        {
 
553
            if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVert)
 
554
            {
 
555
                rt.translate(rt.width(), 0);
 
556
            }
 
557
 
 
558
            if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesVertCont)
 
559
            {
 
560
                ro.translate(-ro.width(), 0);
 
561
            }
 
562
 
 
563
            if (!rt.contains(pt) && ro.contains(pt))
 
564
            {
 
565
                emitCapturedPointFromOriginal(pt - ro.topLeft());
 
566
            }
 
567
        }
 
568
        else if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorz ||
 
569
                 d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorzCont)
 
570
        {
 
571
            if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorz)
 
572
            {
 
573
                rt.translate(0, rt.height());
 
574
            }
 
575
 
 
576
            if (d->renderingPreviewMode == PreviewToolBar::PreviewBothImagesHorzCont)
 
577
            {
 
578
                ro.translate(0, -ro.height());
 
579
            }
 
580
 
 
581
            if (!rt.contains(pt) && ro.contains(pt))
 
582
            {
 
583
                emitCapturedPointFromOriginal(pt - ro.topLeft());
 
584
            }
 
585
        }
 
586
 
 
587
        return;
 
588
    }
 
589
 
 
590
    PreviewWidget::contentsMousePressEvent(e);
 
591
}
 
592
 
 
593
void ImageRegionWidget::emitCapturedPointFromOriginal(const QPoint& pt)
 
594
{
 
595
    int x = (int)(((double)pt.x() / tileSize()) * floor(tileSize() / zoomFactor()));
 
596
    int y = (int)(((double)pt.y() / tileSize()) * floor(tileSize() / zoomFactor()));
 
597
    QPoint imgPt(x, y);
 
598
    DColor color = d->image.getPixelColor(x, y);
 
599
    kDebug() << "Captured point from image : " << imgPt;
 
600
    emit signalCapturedPointFromOriginal(color, imgPt);
 
601
}
 
602
 
 
603
void ImageRegionWidget::contentsMouseReleaseEvent(QMouseEvent* e)
 
604
{
 
605
    if (d->capturePtMode)
 
606
    {
 
607
        setCapturePointMode(false);
 
608
        return;
 
609
    }
 
610
 
 
611
    PreviewWidget::contentsMouseReleaseEvent(e);
 
612
}
 
613
 
 
614
}  // namespace Digikam