1
/* ============================================================
3
* This file is a part of kipi-plugins project
4
* http://www.kipi-plugins.org
7
* Description : a preview widget to display correction results
9
* Copyright (C) 2008-2009 by Andi Clemens <andi dot clemens at gmx dot net>
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)
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.
22
* ============================================================ */
24
#include "previewwidget.moc"
28
#include <QGraphicsScene>
29
#include <QStackedWidget>
34
#include <kmessagebox.h>
39
#include "controlwidget.h"
40
#include "infomessagewidget.h"
42
namespace KIPIRemoveRedEyesPlugin
45
struct PreviewWidgetPriv
63
QLabel* noSelectionLabel;
64
QLabel* originalLabel;
65
QLabel* correctedLabel;
68
QStackedWidget* stack;
72
ControlWidget* controller;
74
InfoMessageWidget* modeInfo;
77
PreviewWidget::PreviewWidget(QWidget* parent)
78
: QGraphicsView(parent), d(new PreviewWidgetPriv)
80
QString whatsThis = i18n("<p>This widget will display a correction "
81
"preview for the currently selected image.</p>"
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>"
87
"<p>The zoom buttons and panning widget allow you to view certain parts of the image "
90
setWhatsThis(whatsThis);
92
// --------------------------------------------------------
94
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
95
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
96
setCacheMode(QGraphicsView::CacheBackground);
98
// --------------------------------------------------------
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;
108
d->correctedLabel->setScaledContents(true);
109
d->maskLabel->setScaledContents(true);
110
d->originalLabel->setScaledContents(true);
112
d->noSelectionLabel->clear();
114
d->busyLabel->setText(i18n("<h2>generating preview...</h2>"));
115
d->busyLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
117
// --------------------------------------------------------
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);
126
// --------------------------------------------------------
128
QGraphicsScene* scene = new QGraphicsScene;
129
scene->addWidget(d->stack);
132
// --------------------------------------------------------
135
d->modeInfo = new InfoMessageWidget(this);
136
d->controller = new ControlWidget(this);
138
// --------------------------------------------------------
140
connect(this, SIGNAL(settingsChanged()),
141
this, SLOT(updateSettings()));
143
connect(d->controller, SIGNAL(zoomInClicked()),
144
this, SLOT(zoomInClicked()));
146
connect(d->controller, SIGNAL(zoomOutClicked()),
147
this, SLOT(zoomOutClicked()));
149
connect(d->controller, SIGNAL(originalClicked()),
150
this, SLOT(originalClicked()));
152
connect(d->controller, SIGNAL(correctedClicked()),
153
this, SLOT(correctedClicked()));
155
connect(d->controller, SIGNAL(maskClicked()),
156
this, SLOT(maskClicked()));
158
// --------------------------------------------------------
163
PreviewWidget::~PreviewWidget()
168
QString& PreviewWidget::currentImage() const
173
void PreviewWidget::setCurrentImage(const QString& image)
175
if (d->image == image)
182
emit settingsChanged();
185
void PreviewWidget::setPreviewImage(ImageType type, const QString& filename)
190
d->originalLabel->setPixmap(openFile(filename));
194
d->correctedLabel->setPixmap(openFile(filename));
198
d->maskLabel->setPixmap(openFile(filename));
202
emit settingsChanged();
205
QPixmap PreviewWidget::openFile(const QString& filename)
209
if (!filename.isEmpty())
211
image.load(filename);
215
QString message = i18n("<p>Can not open preview image<br/>'%1'</p>.", filename);
217
KMessageBox::information(this, message, i18n("Error loading preview file"));
225
void PreviewWidget::originalClicked()
232
setMode(OriginalMode);
235
void PreviewWidget::correctedClicked()
242
setMode(CorrectedMode);
245
void PreviewWidget::maskClicked()
252
if (d->stack->currentIndex() == MaskMode)
254
setMode(OriginalMode);
262
void PreviewWidget::resizeEvent(QResizeEvent* e)
264
QWidget::resizeEvent(e);
266
d->controller->move((width()/2) - (d->controller->width()/2),
267
(height()/2) - (d->controller->width()/2));
270
void PreviewWidget::setMode(DisplayMode mode)
272
d->stack->setCurrentIndex(mode);
277
d->modeInfo->display(i18n("Original Image"));
278
d->modeInfo->raise();
279
d->controller->raise();
283
d->modeInfo->display(i18n("Corrected Image"));
284
d->modeInfo->raise();
285
d->controller->raise();
289
d->modeInfo->display(i18n("Correction Mask"));
290
d->modeInfo->raise();
291
d->controller->raise();
295
d->modeInfo->display(i18n("No image selected"), InfoMessageWidget::Warning);
296
d->modeInfo->raise();
297
d->controller->hide();
298
d->controller->lower();
302
d->modeInfo->lower();
303
d->controller->hide();
304
d->controller->lower();
308
d->stack->adjustSize();
311
void PreviewWidget::reset()
317
void PreviewWidget::resetPreviews()
319
d->originalLabel->setPixmap(0);
320
d->correctedLabel->setPixmap(0);
321
d->maskLabel->setPixmap(0);
325
bool PreviewWidget::previewsComplete()
327
if (d->originalLabel->pixmap()->isNull() ||
328
d->correctedLabel->pixmap()->isNull() ||
329
d->maskLabel->pixmap()->isNull())
337
void PreviewWidget::updateSettings()
339
if (d->image.isEmpty())
346
if (!previewsComplete())
350
d->modeInfo->reset();
355
setMode(CorrectedMode);
358
void PreviewWidget::zoomInClicked()
363
void PreviewWidget::zoomOutClicked()
365
scale(1.0 / 1.5, 1.0 / 1.5);
368
void PreviewWidget::enterEvent(QEvent*)
370
d->controller->triggerShow();
373
} // namspace KIPIRemoveRedEyesPlugin