1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/* ============================================================
*
* This file is a part of kipi-plugins project
* http://www.kipi-plugins.org
*
* Date : 2003-10-22
* Description : preview raw file widget used in single convert
*
* Copyright (C) 2003-2005 by Renchi Raju <renchi@pooh.tam.uiuc.edu>
* Copyright (C) 2006-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
// Qt includes.
#include <qpainter.h>
#include <qimage.h>
#include <qstring.h>
#include <qevent.h>
#include <qtimer.h>
#include <qfile.h>
// KDE includes.
#include <klocale.h>
// Local includes.
#include "previewwidget.h"
#include "previewwidget.moc"
namespace KIPIRawConverterPlugin
{
class PreviewWidgetPriv
{
public:
PreviewWidgetPriv()
{
pix = 0;
timer = 0;
}
QPixmap *pix;
QPixmap preview;
QTimer *timer;
QString text;
QImage image;
};
PreviewWidget::PreviewWidget(QWidget *parent)
: QFrame(parent, 0, Qt::WRepaintNoErase)
{
d = new PreviewWidgetPriv;
setFrameStyle(QFrame::GroupBoxPanel|QFrame::Plain);
setMargin(0);
setLineWidth(1);
setMinimumSize(QSize(400, 300));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->pix = new QPixmap(400, 300);
d->pix->fill(Qt::black);
d->timer = new QTimer(this);
connect(d->timer, SIGNAL(timeout()),
this, SLOT(slotResize()));
}
PreviewWidget::~PreviewWidget()
{
delete d;
}
void PreviewWidget::load(const QString& file)
{
d->text = "";
d->pix->fill(Qt::black);
d->image.load(file);
if (!d->image.isNull())
{
QImage img = d->image.scale(width(),height(),QImage::ScaleMin);
int x = d->pix->width()/2 - img.width()/2;
int y = d->pix->height()/2 - img.height()/2;
QPainter p(d->pix);
p.drawImage(x, y, img);
p.setPen(QPen(Qt::white));
p.drawRect(x,y,img.width(),img.height());
p.end();
}
else
{
setInfo(i18n( "Failed to load image after processing" ));
return;
}
update();
}
void PreviewWidget::setInfo(const QString& text, const QColor& color, const QPixmap& preview)
{
d->text = text;
d->preview = preview;
d->pix->fill(Qt::black);
QPainter p(d->pix);
p.setPen(QPen(color));
if (!d->preview.isNull())
{
p.drawPixmap(d->pix->width()/2-d->preview.width()/2, d->pix->height()/4-d->preview.height()/2,
d->preview, 0, 0, d->preview.width(), d->preview.height());
p.drawText(0, d->pix->height()/2, d->pix->width(), d->pix->height()/2,
Qt::AlignCenter|Qt::WordBreak, d->text);
}
else
{
p.drawText(0, 0, d->pix->width(), d->pix->height(),
Qt::AlignCenter|Qt::WordBreak, d->text);
}
p.end();
update();
}
void PreviewWidget::paintEvent(QPaintEvent *e)
{
QRect r(e->rect());
bitBlt(this, r.topLeft(), d->pix, r, Qt::CopyROP);
}
void PreviewWidget::resizeEvent(QResizeEvent*)
{
d->timer->start(10,true);
}
void PreviewWidget::slotResize()
{
if (d->timer->isActive()) return;
d->pix->resize(width(),height());
d->pix->fill(Qt::black);
if (!d->text.isEmpty())
{
QPainter p(d->pix);
p.setPen(QPen(Qt::white));
if (!d->preview.isNull())
{
p.drawPixmap(d->pix->width()/2-d->preview.width()/2, d->pix->height()/4-d->preview.height()/2,
d->preview, 0, 0, d->preview.width(), d->preview.height());
p.drawText(0, d->pix->height()/2, d->pix->width(), d->pix->height()/2,
Qt::AlignCenter|Qt::WordBreak, d->text);
}
else
{
p.drawText(0, 0, d->pix->width(), d->pix->height(),
Qt::AlignCenter|Qt::WordBreak, d->text);
}
p.end();
}
else
{
if (!d->image.isNull())
{
QImage img = d->image.scale(width(),height(), QImage::ScaleMin);
int x = d->pix->width()/2 - img.width()/2;
int y = d->pix->height()/2 - img.height()/2;
QPainter p(d->pix);
p.drawImage(x, y, img);
p.setPen(QPen(Qt::white));
p.drawRect(x,y,img.width(),img.height());
p.end();
}
}
update();
}
} // NameSpace KIPIRawConverterPlugin
|