~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to extra/kipi-plugins/removeredeyes/widgets/previewwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of kipi-plugins project
 
4
 * http://www.kipi-plugins.org
 
5
 *
 
6
 * Date        : 2008-11-29
 
7
 * Description : a preview widget to display correction results
 
8
 *
 
9
 * Copyright (C) 2008-2009 by Andi Clemens <andi dot clemens at gmx dot net>
 
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 "previewwidget.moc"
 
25
 
 
26
// Qt includes
 
27
 
 
28
#include <QGraphicsScene>
 
29
#include <QStackedWidget>
 
30
 
 
31
// KDE includes
 
32
 
 
33
#include <klocale.h>
 
34
#include <kmessagebox.h>
 
35
#include <kurl.h>
 
36
 
 
37
// Local includes
 
38
 
 
39
#include "controlwidget.h"
 
40
#include "infomessagewidget.h"
 
41
 
 
42
namespace KIPIRemoveRedEyesPlugin
 
43
{
 
44
 
 
45
struct PreviewWidgetPriv
 
46
{
 
47
    PreviewWidgetPriv() :
 
48
        locked(false),
 
49
        busyLabel(0),
 
50
        noSelectionLabel(0),
 
51
        originalLabel(0),
 
52
        correctedLabel(0),
 
53
        maskLabel(0),
 
54
        stack(0),
 
55
        controller(0),
 
56
        modeInfo(0)
 
57
    {
 
58
    }
 
59
 
 
60
    bool                locked;
 
61
 
 
62
    QLabel*             busyLabel;
 
63
    QLabel*             noSelectionLabel;
 
64
    QLabel*             originalLabel;
 
65
    QLabel*             correctedLabel;
 
66
    QLabel*             maskLabel;
 
67
 
 
68
    QStackedWidget*     stack;
 
69
 
 
70
    QString             image;
 
71
 
 
72
    ControlWidget*      controller;
 
73
 
 
74
    InfoMessageWidget*  modeInfo;
 
75
};
 
76
 
 
77
PreviewWidget::PreviewWidget(QWidget* parent)
 
78
    : QGraphicsView(parent), d(new PreviewWidgetPriv)
 
79
{
 
80
    QString whatsThis = i18n("<p>This widget will display a correction "
 
81
                             "preview for the currently selected image.</p>"
 
82
                             "<p><ul>"
 
83
                             "<li>Move the mouse <b>over</b> the preview to display the original image.</li>"
 
84
                             "<li>Move the mouse <b>out of</b> the preview to display the corrected image.</li>"
 
85
                             "<li><b>Click on</b> the preview to display the correction mask.</li>"
 
86
                             "</ul></p>"
 
87
                             "<p>The zoom buttons and panning widget allow you to view certain parts of the image "
 
88
                             "more closely.</p>");
 
89
 
 
90
    setWhatsThis(whatsThis);
 
91
 
 
92
    // --------------------------------------------------------
 
93
 
 
94
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
 
95
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
 
96
    setCacheMode(QGraphicsView::CacheBackground);
 
97
 
 
98
    // --------------------------------------------------------
 
99
 
 
100
    d->locked               = true;
 
101
 
 
102
    d->busyLabel            = new QLabel;
 
103
    d->correctedLabel       = new QLabel;
 
104
    d->maskLabel            = new QLabel;
 
105
    d->noSelectionLabel     = new QLabel;
 
106
    d->originalLabel        = new QLabel;
 
107
 
 
108
    d->correctedLabel->setScaledContents(true);
 
109
    d->maskLabel->setScaledContents(true);
 
110
    d->originalLabel->setScaledContents(true);
 
111
 
 
112
    d->noSelectionLabel->clear();
 
113
 
 
114
    d->busyLabel->setText(i18n("<h2>generating preview...</h2>"));
 
115
    d->busyLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
 
116
 
 
117
    // --------------------------------------------------------
 
118
 
 
119
    d->stack = new QStackedWidget;
 
120
    d->stack->insertWidget(BusyMode,          d->busyLabel);
 
121
    d->stack->insertWidget(LockedMode,        d->noSelectionLabel);
 
122
    d->stack->insertWidget(OriginalMode,      d->originalLabel);
 
123
    d->stack->insertWidget(CorrectedMode,     d->correctedLabel);
 
124
    d->stack->insertWidget(MaskMode,          d->maskLabel);
 
125
 
 
126
    // --------------------------------------------------------
 
127
 
 
128
    QGraphicsScene* scene = new QGraphicsScene;
 
129
    scene->addWidget(d->stack);
 
130
    setScene(scene);
 
131
 
 
132
    // --------------------------------------------------------
 
133
 
 
134
    // floating widgets
 
135
    d->modeInfo = new InfoMessageWidget(this);
 
136
    d->controller = new ControlWidget(this);
 
137
 
 
138
    // --------------------------------------------------------
 
139
 
 
140
    connect(this, SIGNAL(settingsChanged()),
 
141
            this, SLOT(updateSettings()));
 
142
 
 
143
    connect(d->controller, SIGNAL(zoomInClicked()),
 
144
            this, SLOT(zoomInClicked()));
 
145
 
 
146
    connect(d->controller, SIGNAL(zoomOutClicked()),
 
147
            this, SLOT(zoomOutClicked()));
 
148
 
 
149
    connect(d->controller, SIGNAL(originalClicked()),
 
150
            this, SLOT(originalClicked()));
 
151
 
 
152
    connect(d->controller, SIGNAL(correctedClicked()),
 
153
            this, SLOT(correctedClicked()));
 
154
 
 
155
    connect(d->controller, SIGNAL(maskClicked()),
 
156
            this, SLOT(maskClicked()));
 
157
 
 
158
    // --------------------------------------------------------
 
159
 
 
160
    reset();
 
161
}
 
162
 
 
163
PreviewWidget::~PreviewWidget()
 
164
{
 
165
    delete d;
 
166
}
 
167
 
 
168
QString& PreviewWidget::currentImage() const
 
169
{
 
170
    return d->image;
 
171
}
 
172
 
 
173
void PreviewWidget::setCurrentImage(const QString& image)
 
174
{
 
175
    if (d->image == image)
 
176
    {
 
177
        return;
 
178
    }
 
179
 
 
180
    d->image = image;
 
181
    resetPreviews();
 
182
    emit settingsChanged();
 
183
}
 
184
 
 
185
void PreviewWidget::setPreviewImage(ImageType type, const QString& filename)
 
186
{
 
187
    switch (type)
 
188
    {
 
189
        case OriginalImage:
 
190
            d->originalLabel->setPixmap(openFile(filename));
 
191
            break;
 
192
 
 
193
        case CorrectedImage:
 
194
            d->correctedLabel->setPixmap(openFile(filename));
 
195
            break;
 
196
 
 
197
        case MaskImage:
 
198
            d->maskLabel->setPixmap(openFile(filename));
 
199
            break;
 
200
    }
 
201
 
 
202
    emit settingsChanged();
 
203
}
 
204
 
 
205
QPixmap PreviewWidget::openFile(const QString& filename)
 
206
{
 
207
    QPixmap image;
 
208
 
 
209
    if (!filename.isEmpty())
 
210
    {
 
211
        image.load(filename);
 
212
 
 
213
        if (image.isNull())
 
214
        {
 
215
            QString message = i18n("<p>Can not open preview image<br/>'%1'</p>.", filename);
 
216
 
 
217
            KMessageBox::information(this, message, i18n("Error loading preview file"));
 
218
            return QPixmap();
 
219
        }
 
220
    }
 
221
 
 
222
    return image;
 
223
}
 
224
 
 
225
void PreviewWidget::originalClicked()
 
226
{
 
227
    if (d->locked)
 
228
    {
 
229
        return;
 
230
    }
 
231
 
 
232
    setMode(OriginalMode);
 
233
}
 
234
 
 
235
void PreviewWidget::correctedClicked()
 
236
{
 
237
    if (d->locked)
 
238
    {
 
239
        return;
 
240
    }
 
241
 
 
242
    setMode(CorrectedMode);
 
243
}
 
244
 
 
245
void PreviewWidget::maskClicked()
 
246
{
 
247
    if (d->locked)
 
248
    {
 
249
        return;
 
250
    }
 
251
 
 
252
    if (d->stack->currentIndex() == MaskMode)
 
253
    {
 
254
        setMode(OriginalMode);
 
255
    }
 
256
    else
 
257
    {
 
258
        setMode(MaskMode);
 
259
    }
 
260
}
 
261
 
 
262
void PreviewWidget::resizeEvent(QResizeEvent* e)
 
263
{
 
264
    QWidget::resizeEvent(e);
 
265
 
 
266
    d->controller->move((width()/2) - (d->controller->width()/2),
 
267
                        (height()/2) - (d->controller->width()/2));
 
268
}
 
269
 
 
270
void PreviewWidget::setMode(DisplayMode mode)
 
271
{
 
272
    d->stack->setCurrentIndex(mode);
 
273
 
 
274
    switch (mode)
 
275
    {
 
276
        case OriginalMode:
 
277
            d->modeInfo->display(i18n("Original Image"));
 
278
            d->modeInfo->raise();
 
279
            d->controller->raise();
 
280
            break;
 
281
 
 
282
        case CorrectedMode:
 
283
            d->modeInfo->display(i18n("Corrected Image"));
 
284
            d->modeInfo->raise();
 
285
            d->controller->raise();
 
286
            break;
 
287
 
 
288
        case MaskMode:
 
289
            d->modeInfo->display(i18n("Correction Mask"));
 
290
            d->modeInfo->raise();
 
291
            d->controller->raise();
 
292
            break;
 
293
 
 
294
        case LockedMode:
 
295
            d->modeInfo->display(i18n("No image selected"), InfoMessageWidget::Warning);
 
296
            d->modeInfo->raise();
 
297
            d->controller->hide();
 
298
            d->controller->lower();
 
299
            break;
 
300
 
 
301
        case BusyMode:
 
302
            d->modeInfo->lower();
 
303
            d->controller->hide();
 
304
            d->controller->lower();
 
305
            break;
 
306
    }
 
307
 
 
308
    d->stack->adjustSize();
 
309
}
 
310
 
 
311
void PreviewWidget::reset()
 
312
{
 
313
    d->image.clear();
 
314
    resetPreviews();
 
315
}
 
316
 
 
317
void PreviewWidget::resetPreviews()
 
318
{
 
319
    d->originalLabel->setPixmap(0);
 
320
    d->correctedLabel->setPixmap(0);
 
321
    d->maskLabel->setPixmap(0);
 
322
    updateSettings();
 
323
}
 
324
 
 
325
bool PreviewWidget::previewsComplete()
 
326
{
 
327
    if (d->originalLabel->pixmap()->isNull()  ||
 
328
        d->correctedLabel->pixmap()->isNull() ||
 
329
        d->maskLabel->pixmap()->isNull())
 
330
    {
 
331
        return false;
 
332
    }
 
333
 
 
334
    return true;
 
335
}
 
336
 
 
337
void PreviewWidget::updateSettings()
 
338
{
 
339
    if (d->image.isEmpty())
 
340
    {
 
341
        d->locked = true;
 
342
        setMode(LockedMode);
 
343
        return;
 
344
    }
 
345
 
 
346
    if (!previewsComplete())
 
347
    {
 
348
        d->locked = true;
 
349
        setMode(BusyMode);
 
350
        d->modeInfo->reset();
 
351
        return;
 
352
    }
 
353
 
 
354
    d->locked = false;
 
355
    setMode(CorrectedMode);
 
356
}
 
357
 
 
358
void PreviewWidget::zoomInClicked()
 
359
{
 
360
    scale(1.5, 1.5);
 
361
}
 
362
 
 
363
void PreviewWidget::zoomOutClicked()
 
364
{
 
365
    scale(1.0 / 1.5, 1.0 / 1.5);
 
366
}
 
367
 
 
368
void PreviewWidget::enterEvent(QEvent*)
 
369
{
 
370
    d->controller->triggerShow();
 
371
}
 
372
 
 
373
} // namspace KIPIRemoveRedEyesPlugin