1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : a widget to display an image preview with some
8
* modes to compare effect results.
10
* Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option)
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* ============================================================ */
25
#include "imagewidget.moc"
29
#include <QButtonGroup>
31
#include <QGridLayout>
34
#include <QToolButton>
35
#include <QVBoxLayout>
40
#include <kapplication.h>
44
#include <kiconloader.h>
46
#include <ksqueezedtextlabel.h>
47
#include <kstandarddirs.h>
60
underExposureButton = 0;
61
overExposureButton = 0;
70
QString settingsSection;
72
QButtonGroup *previewButtons;
74
QToolButton *underExposureButton;
75
QToolButton *overExposureButton;
77
KSqueezedTextLabel *spotInfoLabel;
79
ImageGuideWidget *previewWidget;
82
ImageWidget::ImageWidget(const QString& settingsSection, QWidget *parent,
83
const QString& previewWhatsThis, bool prevModeOptions,
84
int guideMode, bool guideVisible, bool useImageSelection)
85
: QWidget(parent), d(new ImageWidgetPriv)
87
d->settingsSection = settingsSection;
89
// -------------------------------------------------------------
91
QGridLayout* grid = new QGridLayout(this);
92
d->spotInfoLabel = new KSqueezedTextLabel(this);
93
d->spotInfoLabel->setAlignment(Qt::AlignRight);
95
// -------------------------------------------------------------
97
d->prevBBox = new QWidget(this);
98
QHBoxLayout *hlay = new QHBoxLayout(d->prevBBox);
99
d->previewButtons = new QButtonGroup(d->prevBBox);
100
d->previewButtons->setExclusive(true);
104
QToolButton *previewOriginalButton = new QToolButton( d->prevBBox );
105
d->previewButtons->addButton(previewOriginalButton, ImageGuideWidget::PreviewOriginalImage);
106
hlay->addWidget(previewOriginalButton);
107
previewOriginalButton->setIcon(QPixmap(KStandardDirs::locate("data", "digikam/data/original.png")));
108
previewOriginalButton->setCheckable(true);
109
previewOriginalButton->setWhatsThis( i18n( "If this option is enabled, the original image "
110
"will be shown." ) );
112
QToolButton *previewBothButtonVert = new QToolButton( d->prevBBox );
113
d->previewButtons->addButton(previewBothButtonVert, ImageGuideWidget::PreviewBothImagesVertCont);
114
hlay->addWidget(previewBothButtonVert);
115
previewBothButtonVert->setIcon(QPixmap(KStandardDirs::locate("data", "digikam/data/bothvert.png")));
116
previewBothButtonVert->setCheckable(true);
117
previewBothButtonVert->setWhatsThis( i18n( "If this option is enabled, the preview area will "
119
"A contiguous area of the image will be shown, "
120
"with one half from the original image, "
121
"the other half from the target image.") );
123
QToolButton *previewBothButtonHorz = new QToolButton( d->prevBBox );
124
d->previewButtons->addButton(previewBothButtonHorz, ImageGuideWidget::PreviewBothImagesHorzCont);
125
hlay->addWidget(previewBothButtonHorz);
126
previewBothButtonHorz->setIcon(QPixmap(KStandardDirs::locate("data", "digikam/data/bothhorz.png")));
127
previewBothButtonHorz->setCheckable(true);
128
previewBothButtonHorz->setWhatsThis( i18n( "If this option is enabled, the preview area will "
129
"split horizontally. "
130
"A contiguous area of the image will be shown, "
131
"with one half from the original image, "
132
"the other half from the target image.") );
134
QToolButton *previewDuplicateBothButtonVert = new QToolButton( d->prevBBox );
135
d->previewButtons->addButton(previewDuplicateBothButtonVert, ImageGuideWidget::PreviewBothImagesVert);
136
hlay->addWidget(previewDuplicateBothButtonVert);
137
previewDuplicateBothButtonVert->setIcon(QPixmap(KStandardDirs::locate("data", "digikam/data/duplicatebothvert.png")));
138
previewDuplicateBothButtonVert->setCheckable(true);
139
previewDuplicateBothButtonVert->setWhatsThis( i18n( "If this option is enabled, the preview area will "
141
"The same part of the original and the target image "
142
"will be shown side by side.") );
144
QToolButton *previewDupplicateBothButtonHorz = new QToolButton( d->prevBBox );
145
d->previewButtons->addButton(previewDupplicateBothButtonHorz, ImageGuideWidget::PreviewBothImagesHorz);
146
hlay->addWidget(previewDupplicateBothButtonHorz);
147
previewDupplicateBothButtonHorz->setIcon(QPixmap(KStandardDirs::locate("data", "digikam/data/duplicatebothhorz.png")));
148
previewDupplicateBothButtonHorz->setCheckable(true);
149
previewDupplicateBothButtonHorz->setWhatsThis( i18n( "If this option is enabled, the preview area will "
150
"split horizontally. "
151
"The same part of the original and the target image "
152
"will be shown side by side.") );
154
QToolButton *previewtargetButton = new QToolButton( d->prevBBox );
155
d->previewButtons->addButton(previewtargetButton, ImageGuideWidget::PreviewTargetImage);
156
hlay->addWidget(previewtargetButton);
157
previewtargetButton->setIcon(QPixmap(KStandardDirs::locate("data", "digikam/data/target.png")));
158
previewtargetButton->setCheckable(true);
159
previewtargetButton->setWhatsThis( i18n( "If this option is enabled, the target image "
160
"will be shown." ) );
162
QToolButton *previewToggleMouseOverButton = new QToolButton( d->prevBBox );
163
d->previewButtons->addButton(previewToggleMouseOverButton, ImageGuideWidget::PreviewToggleOnMouseOver);
164
hlay->addWidget(previewToggleMouseOverButton);
165
previewToggleMouseOverButton->setIcon(QPixmap(KStandardDirs::locate("data", "digikam/data/togglemouseover.png")));
166
previewToggleMouseOverButton->setCheckable(true);
167
previewToggleMouseOverButton->setWhatsThis( i18n( "If this option is enabled, the original image will "
168
"be shown when the mouse is over image area; otherwise, "
169
"the target image will be shown." ) );
171
// -------------------------------------------------------------
173
d->expoBBox = new QWidget(this);
174
QHBoxLayout *hlay2 = new QHBoxLayout(d->expoBBox);
175
QButtonGroup *exposureButtons = new QButtonGroup(d->expoBBox);
176
exposureButtons->setExclusive(false);
177
hlay2->setSpacing(0);
180
d->underExposureButton = new QToolButton(d->expoBBox);
181
exposureButtons->addButton(d->underExposureButton, UnderExposure);
182
hlay2->addWidget(d->underExposureButton);
183
d->underExposureButton->setIcon(SmallIcon("underexposure"));
184
d->underExposureButton->setCheckable(true);
185
d->underExposureButton->setWhatsThis( i18n("Set this option to display black "
186
"overlaid on the preview. This will help you to avoid "
187
"under-exposing the image." ) );
189
d->overExposureButton = new QToolButton(d->expoBBox);
190
exposureButtons->addButton(d->overExposureButton, OverExposure);
191
hlay2->addWidget(d->overExposureButton);
192
d->overExposureButton->setIcon(SmallIcon("overexposure"));
193
d->overExposureButton->setCheckable(true);
194
d->overExposureButton->setWhatsThis( i18n("Set this option to display white "
195
"overlaid on the preview. This will help you to avoid "
196
"over-exposing the image." ) );
198
// -------------------------------------------------------------
200
QFrame *frame = new QFrame(this);
201
frame->setFrameStyle(QFrame::Panel|QFrame::Sunken);
202
QVBoxLayout* l = new QVBoxLayout(frame);
205
d->previewWidget = new ImageGuideWidget(480, 320, frame, guideVisible,
206
guideMode, Qt::red, 1, false,
208
d->previewWidget->setWhatsThis(previewWhatsThis);
209
l->addWidget(d->previewWidget, 0);
211
// -------------------------------------------------------------
213
grid->addWidget(d->prevBBox, 1, 0, 1, 1);
214
grid->addWidget(d->spotInfoLabel, 1, 1, 1, 1);
215
grid->addWidget(d->expoBBox, 1, 3, 1, 1);
216
grid->addWidget(frame, 3, 0, 1, 4 );
217
grid->setColumnMinimumWidth(2, KDialog::spacingHint());
218
grid->setColumnMinimumWidth(1, KDialog::spacingHint());
219
grid->setRowMinimumHeight(0, KDialog::spacingHint());
220
grid->setRowMinimumHeight(2, KDialog::spacingHint());
221
grid->setRowStretch(3, 10);
222
grid->setColumnStretch(1, 10);
226
// -------------------------------------------------------------
228
connect(d->previewWidget, SIGNAL(signalResized()),
229
this, SIGNAL(signalResized()));
231
connect(d->previewWidget, SIGNAL(spotPositionChangedFromOriginal(const Digikam::DColor&, const QPoint&)),
232
this, SIGNAL(spotPositionChangedFromOriginal(const Digikam::DColor &, const QPoint &)));
234
connect(d->previewWidget, SIGNAL(spotPositionChangedFromOriginal(const Digikam::DColor&, const QPoint&)),
235
this, SLOT(slotUpdateSpotInfo(const Digikam::DColor&, const QPoint&)));
237
connect(d->previewWidget, SIGNAL(spotPositionChangedFromTarget(const Digikam::DColor&, const QPoint&)),
238
this, SIGNAL(spotPositionChangedFromTarget(const Digikam::DColor&, const QPoint&)));
240
connect(d->previewWidget, SIGNAL(spotPositionChangedFromTarget(const Digikam::DColor&, const QPoint&)),
241
this, SLOT(slotUpdateSpotInfo(const Digikam::DColor&, const QPoint&)));
243
connect(d->previewButtons, SIGNAL(buttonReleased(int)),
244
d->previewWidget, SLOT(slotChangeRenderingPreviewMode(int)));
246
connect(d->underExposureButton, SIGNAL(toggled(bool)),
247
d->previewWidget, SLOT(slotToggleUnderExposure(bool)));
249
connect(d->overExposureButton, SIGNAL(toggled(bool)),
250
d->previewWidget, SLOT(slotToggleOverExposure(bool)));
252
// -------------------------------------------------------------
260
setRenderingPreviewMode(ImageGuideWidget::NoPreviewMode);
261
d->spotInfoLabel->hide();
267
ImageWidget::~ImageWidget()
273
ImageIface* ImageWidget::imageIface()
275
return d->previewWidget->imageIface();
278
void ImageWidget::updatePreview()
280
d->previewWidget->updatePreview();
283
void ImageWidget::slotChangeGuideColor(const QColor& color)
285
d->previewWidget->slotChangeGuideColor(color);
288
void ImageWidget::slotChangeGuideSize(int size)
290
d->previewWidget->slotChangeGuideSize(size);
293
void ImageWidget::resetSpotPosition()
295
d->previewWidget->resetSpotPosition();
298
QPoint ImageWidget::getSpotPosition()
300
return ( d->previewWidget->getSpotPosition() );
303
DColor ImageWidget::getSpotColor(int getColorFrom)
305
return ( d->previewWidget->getSpotColor(getColorFrom) );
308
void ImageWidget::setSpotVisible(bool spotVisible, bool blink)
310
d->previewWidget->setSpotVisible(spotVisible, blink);
313
int ImageWidget::getRenderingPreviewMode()
315
return ( d->previewWidget->getRenderingPreviewMode() );
318
void ImageWidget::setRenderingPreviewMode(int mode)
320
if (d->previewButtons->button(mode))
321
d->previewButtons->button(mode)->setChecked(true);
323
d->previewWidget->slotChangeRenderingPreviewMode(mode);
326
void ImageWidget::slotUpdateSpotInfo(const Digikam::DColor& col, const QPoint& point)
329
d->spotInfoLabel->setText(i18n("(%1,%2) RGBA:%3,%4,%5,%6",
330
point.x(), point.y(),
331
color.red(), color.green(),
332
color.blue(), color.alpha()));
335
void ImageWidget::readSettings()
337
KSharedConfig::Ptr config = KGlobal::config();
338
KConfigGroup group = config->group(d->settingsSection);
340
d->underExposureButton->setChecked(group.readEntry("Under Exposure Indicator", false));
341
d->overExposureButton->setChecked(group.readEntry("Over Exposure Indicator", false));
343
int mode = group.readEntry("Separate View", (int)ImageGuideWidget::PreviewBothImagesVertCont);
344
mode = qMax((int)ImageGuideWidget::PreviewOriginalImage, mode);
345
mode = qMin((int)ImageGuideWidget::NoPreviewMode, mode);
346
setRenderingPreviewMode(mode);
349
void ImageWidget::writeSettings()
351
KSharedConfig::Ptr config = KGlobal::config();
352
KConfigGroup group = config->group(d->settingsSection);
353
group.writeEntry("Separate View", getRenderingPreviewMode());
354
group.writeEntry("Under Exposure Indicator", d->underExposureButton->isChecked());
355
group.writeEntry("Over Exposure Indicator", d->overExposureButton->isChecked());
359
void ImageWidget::setPoints(const QPolygon& p, bool drawLine)
361
d->previewWidget->setPoints(p, drawLine);
364
void ImageWidget::resetPoints()
366
d->previewWidget->resetPoints();
369
void ImageWidget::setPaintColor(const QColor& color)
371
d->previewWidget->setPaintColor(color);
374
void ImageWidget::setMaskEnabled(bool enabled)
376
d->previewWidget->setMaskEnabled(enabled);
379
QImage ImageWidget::getMask() const
381
return d->previewWidget->getMask();
384
void ImageWidget::setMaskPenSize(int size)
386
d->previewWidget->setMaskPenSize(size);
389
void ImageWidget::setEraseMode(bool erase)
391
d->previewWidget->setEraseMode(erase);
394
} // namespace Digikam