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

« back to all changes in this revision

Viewing changes to libs/widgets/imageplugins/imagewidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luka Renko
  • Date: 2010-02-04 07:46:57 UTC
  • mfrom: (3.2.10 sid)
  • Revision ID: james.westby@ubuntu.com-20100204074657-hqzwjn4timlfw265
Tags: 2:1.1.0-1ubuntu1
* New upstream release:
  - Rename in BQM fails with multi dot names (LP: #501135)
  - Add collection with similar name fails (LP: #500581)
  - Add SMB folder error message (LP: #350280)
  - Zoom indicators indicate wrong magnification (LP: #510346)
* Merge with Debian, remaining changes:
  - Export .pot name and copy to plugins in debian/rules
  - Build-depend on libkipi7-dev, libkexiv2-8-dev and 
    libkdcraw8-dev (KDE 4.3 -> 4.4)
  - Build-depend on libmarble-dev (was disabled temporarily 
    in Debian due to 4.3.4 regression)

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        : 2006-02-01
7
 
 * Description : a widget to display an image preview with some
8
 
 *               modes to compare effect results.
9
 
 *
10
 
 * Copyright (C) 2006-2009 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
 
 *
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)
16
 
 * any later version.
17
 
 *
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.
22
 
 *
23
 
 * ============================================================ */
24
 
 
25
 
#include "imagewidget.moc"
26
 
 
27
 
// Qt includes
28
 
 
29
 
#include <QButtonGroup>
30
 
#include <QFrame>
31
 
#include <QGridLayout>
32
 
#include <QLayout>
33
 
#include <QPixmap>
34
 
#include <QToolButton>
35
 
#include <QVBoxLayout>
36
 
 
37
 
// KDE includes
38
 
 
39
 
 
40
 
#include <kapplication.h>
41
 
#include <kconfig.h>
42
 
#include <kdialog.h>
43
 
#include <kglobal.h>
44
 
#include <kiconloader.h>
45
 
#include <klocale.h>
46
 
#include <ksqueezedtextlabel.h>
47
 
#include <kstandarddirs.h>
48
 
 
49
 
namespace Digikam
50
 
{
51
 
 
52
 
class ImageWidgetPriv
53
 
{
54
 
public:
55
 
 
56
 
    ImageWidgetPriv()
57
 
    {
58
 
        spotInfoLabel       = 0;
59
 
        previewButtons      = 0;
60
 
        underExposureButton = 0;
61
 
        overExposureButton  = 0;
62
 
        previewWidget       = 0;
63
 
        prevBBox            = 0;
64
 
        expoBBox            = 0;
65
 
    }
66
 
 
67
 
    QWidget            *prevBBox;
68
 
    QWidget            *expoBBox;
69
 
 
70
 
    QString             settingsSection;
71
 
 
72
 
    QButtonGroup       *previewButtons;
73
 
 
74
 
    QToolButton        *underExposureButton;
75
 
    QToolButton        *overExposureButton;
76
 
 
77
 
    KSqueezedTextLabel *spotInfoLabel;
78
 
 
79
 
    ImageGuideWidget   *previewWidget;
80
 
};
81
 
 
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)
86
 
{
87
 
    d->settingsSection = settingsSection;
88
 
 
89
 
    // -------------------------------------------------------------
90
 
 
91
 
    QGridLayout* grid = new QGridLayout(this);
92
 
    d->spotInfoLabel  = new KSqueezedTextLabel(this);
93
 
    d->spotInfoLabel->setAlignment(Qt::AlignRight);
94
 
 
95
 
    // -------------------------------------------------------------
96
 
 
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);
101
 
    hlay->setSpacing(0);
102
 
    hlay->setMargin(0);
103
 
 
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." ) );
111
 
 
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 "
118
 
                                               "split vertically. "
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.") );
122
 
 
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.") );
133
 
 
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 "
140
 
                                                        "split vertically. "
141
 
                                                        "The same part of the original and the target image "
142
 
                                                        "will be shown side by side.") );
143
 
 
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.") );
153
 
 
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." ) );
161
 
 
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." ) );
170
 
 
171
 
    // -------------------------------------------------------------
172
 
 
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);
178
 
    hlay2->setMargin(0);
179
 
 
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." ) );
188
 
 
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." ) );
197
 
 
198
 
    // -------------------------------------------------------------
199
 
 
200
 
    QFrame *frame    = new QFrame(this);
201
 
    frame->setFrameStyle(QFrame::Panel|QFrame::Sunken);
202
 
    QVBoxLayout* l   = new QVBoxLayout(frame);
203
 
    l->setMargin(5);
204
 
    l->setSpacing(0);
205
 
    d->previewWidget = new ImageGuideWidget(480, 320, frame, guideVisible,
206
 
                                            guideMode, Qt::red, 1, false,
207
 
                                            useImageSelection);
208
 
    d->previewWidget->setWhatsThis(previewWhatsThis);
209
 
    l->addWidget(d->previewWidget, 0);
210
 
 
211
 
    // -------------------------------------------------------------
212
 
 
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);
223
 
    grid->setSpacing(0);
224
 
    grid->setMargin(0);
225
 
 
226
 
    // -------------------------------------------------------------
227
 
 
228
 
    connect(d->previewWidget, SIGNAL(signalResized()),
229
 
            this, SIGNAL(signalResized()));
230
 
 
231
 
    connect(d->previewWidget, SIGNAL(spotPositionChangedFromOriginal(const Digikam::DColor&, const QPoint&)),
232
 
            this, SIGNAL(spotPositionChangedFromOriginal(const Digikam::DColor &, const QPoint &)));
233
 
 
234
 
    connect(d->previewWidget, SIGNAL(spotPositionChangedFromOriginal(const Digikam::DColor&, const QPoint&)),
235
 
            this, SLOT(slotUpdateSpotInfo(const Digikam::DColor&, const QPoint&)));
236
 
 
237
 
    connect(d->previewWidget, SIGNAL(spotPositionChangedFromTarget(const Digikam::DColor&, const QPoint&)),
238
 
            this, SIGNAL(spotPositionChangedFromTarget(const Digikam::DColor&, const QPoint&)));
239
 
 
240
 
    connect(d->previewWidget, SIGNAL(spotPositionChangedFromTarget(const Digikam::DColor&, const QPoint&)),
241
 
            this, SLOT(slotUpdateSpotInfo(const Digikam::DColor&, const QPoint&)));
242
 
 
243
 
    connect(d->previewButtons, SIGNAL(buttonReleased(int)),
244
 
            d->previewWidget, SLOT(slotChangeRenderingPreviewMode(int)));
245
 
 
246
 
    connect(d->underExposureButton, SIGNAL(toggled(bool)),
247
 
            d->previewWidget, SLOT(slotToggleUnderExposure(bool)));
248
 
 
249
 
    connect(d->overExposureButton, SIGNAL(toggled(bool)),
250
 
            d->previewWidget, SLOT(slotToggleOverExposure(bool)));
251
 
 
252
 
    // -------------------------------------------------------------
253
 
 
254
 
    if (prevModeOptions)
255
 
    {
256
 
        readSettings();
257
 
    }
258
 
    else
259
 
    {
260
 
        setRenderingPreviewMode(ImageGuideWidget::NoPreviewMode);
261
 
        d->spotInfoLabel->hide();
262
 
        d->prevBBox->hide();
263
 
        d->expoBBox->hide();
264
 
    }
265
 
}
266
 
 
267
 
ImageWidget::~ImageWidget()
268
 
{
269
 
    writeSettings();
270
 
    delete d;
271
 
}
272
 
 
273
 
ImageIface* ImageWidget::imageIface()
274
 
{
275
 
    return d->previewWidget->imageIface();
276
 
}
277
 
 
278
 
void ImageWidget::updatePreview()
279
 
{
280
 
    d->previewWidget->updatePreview();
281
 
}
282
 
 
283
 
void ImageWidget::slotChangeGuideColor(const QColor& color)
284
 
{
285
 
    d->previewWidget->slotChangeGuideColor(color);
286
 
}
287
 
 
288
 
void ImageWidget::slotChangeGuideSize(int size)
289
 
{
290
 
    d->previewWidget->slotChangeGuideSize(size);
291
 
}
292
 
 
293
 
void ImageWidget::resetSpotPosition()
294
 
{
295
 
    d->previewWidget->resetSpotPosition();
296
 
}
297
 
 
298
 
QPoint ImageWidget::getSpotPosition()
299
 
{
300
 
    return ( d->previewWidget->getSpotPosition() );
301
 
}
302
 
 
303
 
DColor ImageWidget::getSpotColor(int getColorFrom)
304
 
{
305
 
    return ( d->previewWidget->getSpotColor(getColorFrom) );
306
 
}
307
 
 
308
 
void ImageWidget::setSpotVisible(bool spotVisible, bool blink)
309
 
{
310
 
    d->previewWidget->setSpotVisible(spotVisible, blink);
311
 
}
312
 
 
313
 
int ImageWidget::getRenderingPreviewMode()
314
 
{
315
 
    return ( d->previewWidget->getRenderingPreviewMode() );
316
 
}
317
 
 
318
 
void ImageWidget::setRenderingPreviewMode(int mode)
319
 
{
320
 
    if (d->previewButtons->button(mode))
321
 
        d->previewButtons->button(mode)->setChecked(true);
322
 
 
323
 
    d->previewWidget->slotChangeRenderingPreviewMode(mode);
324
 
}
325
 
 
326
 
void ImageWidget::slotUpdateSpotInfo(const Digikam::DColor& col, const QPoint& point)
327
 
{
328
 
    DColor color = col;
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()));
333
 
}
334
 
 
335
 
void ImageWidget::readSettings()
336
 
{
337
 
    KSharedConfig::Ptr config = KGlobal::config();
338
 
    KConfigGroup group        = config->group(d->settingsSection);
339
 
 
340
 
    d->underExposureButton->setChecked(group.readEntry("Under Exposure Indicator", false));
341
 
    d->overExposureButton->setChecked(group.readEntry("Over Exposure Indicator", false));
342
 
 
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);
347
 
}
348
 
 
349
 
void ImageWidget::writeSettings()
350
 
{
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());
356
 
    config->sync();
357
 
}
358
 
 
359
 
void ImageWidget::setPoints(const QPolygon& p, bool drawLine)
360
 
{
361
 
    d->previewWidget->setPoints(p, drawLine);
362
 
}
363
 
 
364
 
void ImageWidget::resetPoints()
365
 
{
366
 
    d->previewWidget->resetPoints();
367
 
}
368
 
 
369
 
void ImageWidget::setPaintColor(const QColor& color)
370
 
{
371
 
    d->previewWidget->setPaintColor(color);
372
 
}
373
 
 
374
 
void ImageWidget::setMaskEnabled(bool enabled)
375
 
{
376
 
    d->previewWidget->setMaskEnabled(enabled);
377
 
}
378
 
 
379
 
QImage ImageWidget::getMask() const
380
 
{
381
 
    return d->previewWidget->getMask();
382
 
}
383
 
 
384
 
void ImageWidget::setMaskPenSize(int size)
385
 
{
386
 
    d->previewWidget->setMaskPenSize(size);
387
 
}
388
 
 
389
 
void ImageWidget::setEraseMode(bool erase)
390
 
{
391
 
    d->previewWidget->setEraseMode(erase);
392
 
}
393
 
 
394
 
}  // namespace Digikam