7
7
* Description : a widget to insert a text over an image.
9
* Copyright (C) 2005-2011 by Gilles Caulier <caulier dot gilles at gmail dot com>
10
* Copyright (C) 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
9
* Copyright (C) 2005-2012 by Gilles Caulier <caulier dot gilles at gmail dot com>
10
* Copyright (C) 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12
12
* This program is free software; you can redistribute it
13
13
* and/or modify it under the terms of the GNU General
104
101
ImageIface* iface;
107
InsertTextWidget::InsertTextWidget(int w, int h, QWidget* parent)
104
InsertTextWidget::InsertTextWidget(int w, int h, QWidget* const parent)
108
105
: QWidget(parent),
109
d(new InsertTextWidgetPriv)
111
108
d->currentMoving = false;
112
109
d->bgColor = palette().color(QPalette::Background);
113
110
d->backgroundColor = QColor(0xCC, 0xCC, 0xCC);
114
111
d->transparency = 210;
116
d->iface = new ImageIface(w, h);
117
d->data = d->iface->getPreviewImage();
118
d->w = d->iface->previewWidth();
119
d->h = d->iface->previewHeight();
113
d->iface = new ImageIface(QSize(w, h));
114
d->w = d->iface->previewSize().width();
115
d->h = d->iface->previewSize().height();
120
116
d->pixmap = new QPixmap(w, h);
121
117
d->pixmap->fill(d->bgColor);
235
230
DImg InsertTextWidget::makeInsertText()
237
int orgW = d->iface->originalWidth();
238
int orgH = d->iface->originalHeight();
232
int orgW = d->iface->originalSize().width();
233
int orgH = d->iface->originalSize().height();
239
234
float ratioW = (float)orgW/(float)d->w;
240
235
float ratioH = (float)orgH/(float)d->h;
256
251
// Get original image
257
DImg image = d->iface->getOriginalImg()->copy();
252
DImg image = d->iface->original()->copy();
258
253
int borderWidth = qMax(1, (int)lroundf(ratioW));
260
255
// compose and draw result on image
270
265
void InsertTextWidget::makePixmap()
272
int orgW = d->iface->originalWidth();
273
int orgH = d->iface->originalHeight();
267
int orgW = d->iface->originalSize().width();
268
int orgH = d->iface->originalSize().height();
274
269
float ratioW = (float)d->w / (float)orgW;
275
270
float ratioH = (float)d->h / (float)orgH;
291
286
// get preview image data
292
QScopedArrayPointer<uchar> data(d->iface->getPreviewImage());
293
DImg image(d->iface->previewWidth(), d->iface->previewHeight(), d->iface->previewSixteenBit(),
294
d->iface->previewHasAlpha(), data.data());
295
image.setIccProfile( d->iface->getOriginalImg()->getIccProfile() );
287
DImg image = d->iface->preview();
288
image.setIccProfile( d->iface->original()->getIccProfile() );
297
290
// paint pixmap for drawing this widget
298
291
// First, fill with background color
330
323
if destPainter is not null, draw directly using the painter.
331
324
Returns modified area of image.
333
QRect InsertTextWidget::composeImage(DImg* image, QPainter* destPainter,
326
QRect InsertTextWidget::composeImage(DImg* const image, QPainter* const destPainter,
335
328
QFont font, float pointSize, int textRotation, QColor textColor,
336
329
int alignMode, const QString& textString,
642
635
blockSignals(true);
643
636
delete d->pixmap;
645
int w = e->size().width();
646
int h = e->size().height();
638
int w = e->size().width();
639
int h = e->size().height();
648
641
int textX = d->textRect.x() - d->rect.x();
649
642
int textY = d->textRect.y() - d->rect.y();
650
643
int old_w = d->w;
651
644
int old_h = d->h;
652
d->data = d->iface->setPreviewImageSize(w, h);
653
d->w = d->iface->previewWidth();
654
d->h = d->iface->previewHeight();
645
d->iface->setPreviewSize(QSize(w, h));
646
d->w = d->iface->previewSize().width();
647
d->h = d->iface->previewSize().height();
656
649
d->pixmap = new QPixmap(w, h);
657
d->rect = QRect(w/2-d->w/2, h/2-d->h/2, d->w, d->h);
650
d->rect = QRect(w/2-d->w/2, h/2-d->h/2, d->w, d->h);
659
652
if (d->textRect.isValid())
661
654
int textWidth = d->textRect.width();
662
655
int textHeight = d->textRect.height();
664
textX = lroundf( textX * (float)d->w / (float)old_w );
665
textY = lroundf( textY * (float)d->h / (float)old_h );
666
textWidth = lroundf(textWidth * (float)d->w / (float)old_w );
667
textHeight = lroundf(textHeight * (float)d->h / (float)old_h );
657
textX = lroundf(textX * (float)d->w / (float)old_w);
658
textY = lroundf(textY * (float)d->h / (float)old_h);
659
textWidth = lroundf(textWidth * (float)d->w / (float)old_w);
660
textHeight = lroundf(textHeight * (float)d->h / (float)old_h);
669
662
d->textRect.setX(textX + d->rect.x());
670
663
d->textRect.setY(textY + d->rect.y());