aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordenes dezso <matusz@matusz.tietoenator.com>2010-09-09 03:13:12 +0300
committerMike FABIAN <mike.fabian@basyskom.de>2010-09-10 11:41:18 +0200
commit9ae004fb91e21294dd8e9e73f0d830f0b09fb664 (patch)
tree5662a9de182b79cfc30b4449e7d8f3b5df563cba /src
parent2f310f678b56669832e4bfea854a5faa744005a0 (diff)
Fixes: NB#188527 - Message Ui got crashed while playing around sending and Composing SMS and MMS
RevBy: Sergiy Dubovik
Diffstat (limited to 'src')
-rw-r--r--src/corelib/widgets/mimagewidget.cpp108
-rw-r--r--src/corelib/widgets/mimagewidget_p.h15
-rw-r--r--src/views/mimagewidgetview.cpp14
3 files changed, 67 insertions, 70 deletions
diff --git a/src/corelib/widgets/mimagewidget.cpp b/src/corelib/widgets/mimagewidget.cpp
index 501b89f9..a9973e67 100644
--- a/src/corelib/widgets/mimagewidget.cpp
+++ b/src/corelib/widgets/mimagewidget.cpp
@@ -33,19 +33,20 @@ M_REGISTER_WIDGET(MImageWidget)
MImageWidgetPrivate::MImageWidgetPrivate()
: MWidgetControllerPrivate(),
pixmap(0),
- deletePixmap(true)
+ ownPixmap(true)
{
}
MImageWidgetPrivate::~MImageWidgetPrivate()
{
- cleanUp();
+ if (ownPixmap)
+ delete pixmap;
}
void MImageWidgetPrivate::cleanUp()
{
if (pixmap != 0) {
- if (deletePixmap)
+ if (ownPixmap)
delete pixmap;
else
MTheme::releasePixmap(pixmap);
@@ -54,19 +55,18 @@ void MImageWidgetPrivate::cleanUp()
image = QImage();
}
-QSizeF MImageWidgetPrivate::imageDataSize() const
+QSizeF MImageWidgetPrivate::imageDataSize(const QRectF& cropRect) const
{
- Q_Q(const MImageWidget);
QSizeF imageSize = QSizeF(0, 0);
if ((pixmap != 0 && !pixmap->isNull()) || (!image.isNull())) {
- if (q->model()->crop().isEmpty()) {
+ if (cropRect.isEmpty()) {
if (image.isNull())
imageSize = pixmap->size();
else
imageSize = image.size();
} else {
- imageSize = q->model()->crop().size();
+ imageSize = cropRect.size();
}
}
@@ -77,55 +77,42 @@ MImageWidgetPrivate &MImageWidgetPrivate::operator=(const MImageWidgetPrivate &o
{
cleanUp();
- if (other.pixmap != 0) {
- if (other.deletePixmap) {
- if (other.pixmap)
- pixmap = new QPixmap(*(other.pixmap));
- else
- image = other.image;
- }
- else
- setImage(other.q_func()->model()->imageId(), other.q_func()->model()->imageSize());
- }
+ if (other.ownPixmap) {
+ if (other.pixmap)
+ pixmap = new QPixmap(*(other.pixmap));
+ } else
+ pixmap = other.pixmap;
+
+ ownPixmap = other.ownPixmap;
- deletePixmap = other.deletePixmap;
- q_func()->setImage(other.q_func()->model()->imageId(), other.q_func()->model()->imageSize());
+ image = other.image;
return *this;
}
-// initialize from image name
-void MImageWidgetPrivate::setImage(const QString &id, const QSize &s)
+void MImageWidgetPrivate::setPixmap(const QPixmap* pixmap, bool takeOwnership)
{
- Q_Q(MImageWidget);
-
- if (id == q->model()->imageId() && s == q->model()->imageSize())
- return;
-
cleanUp();
- q->model()->beginTransaction();
- q->model()->setImageId(id);
- q->model()->setImageSize(s);
- q->model()->commitTransaction();
-
- deletePixmap = false;
+ this->pixmap = pixmap;
+ ownPixmap = takeOwnership;
}
-void MImageWidgetPrivate::deepCopy(const MImageWidget &other)
+void MImageWidgetPrivate::setImage(const QImage& image)
{
- Q_Q(MImageWidget);
- *q->d_func() = *(other.d_func());
-
- qreal fx(0), fy(0);
+ cleanUp();
- other.zoomFactor(&fx, &fy);
- q->setZoomFactor(fx, fy);
+ this->image = image;
+}
- q->model()->setCrop(other.crop());
- q->model()->setAspectRatioMode(other.aspectRatioMode());
+const QPixmap* MImageWidgetPrivate::getPixmap()
+{
+ return this->pixmap;
+}
- q->d_func()->image = other.d_func()->image;
+const QImage& MImageWidgetPrivate::getImage()
+{
+ return this->image;
}
MImageWidget::MImageWidget(QGraphicsItem *parent) :
@@ -143,7 +130,6 @@ MImageWidget::MImageWidget(const QImage *image, QGraphicsItem *parent) :
MWidgetController(new MImageWidgetPrivate(), new MImageWidgetModel(), parent)
{
Q_D(MImageWidget);
- d->pixmap = NULL;
d->image = *image;
}
@@ -157,14 +143,22 @@ MImageWidget::MImageWidget(const QPixmap *pixmap, QGraphicsItem *parent) :
MImageWidget::MImageWidget(const MImageWidget &other) :
MWidgetController(new MImageWidgetPrivate(), new MImageWidgetModel(), 0)
{
- Q_D(MImageWidget);
- d->deepCopy(other);
+ *this = other;
}
MImageWidget &MImageWidget::operator=(const MImageWidget &other)
{
Q_D(MImageWidget);
- d->deepCopy(other);
+ *d = *other.d_func();
+
+ qreal fx(0), fy(0);
+
+ other.zoomFactor(&fx, &fy);
+ setZoomFactor(fx, fy);
+
+ model()->setCrop(other.crop());
+ model()->setAspectRatioMode(other.aspectRatioMode());
+
return *this;
}
@@ -174,8 +168,10 @@ MImageWidget::~MImageWidget()
void MImageWidget::setImage(const QString &id, const QSize &s)
{
- Q_D(MImageWidget);
- d->setImage(id, s);
+ model()->beginTransaction();
+ model()->setImageId(id);
+ model()->setImageSize(s);
+ model()->commitTransaction();
model()->setCrop(QRect());
@@ -246,7 +242,8 @@ void MImageWidget::zoomFactor(qreal *fx, qreal *fy) const
if ((fx && *fx == 0) || (fy && *fy == 0)) {
// If the zoom factor is 0, calculate it with imageSize, targetSize and widgetSize
QSizeF buffer;
- QSizeF imageSize = d->imageDataSize();
+ QSizeF imageSize = d->imageDataSize(model()->crop());
+
if (imageSize.isEmpty())
return;
@@ -318,11 +315,9 @@ void MImageWidget::setImage(const QString &id)
void MImageWidget::setImage(const QImage &image)
{
Q_D(MImageWidget);
- d->setImage(QString());
+ setImage(QString(), QSize());
- d->cleanUp();
- d->image = image;
- d->deletePixmap = false;
+ d->setImage(image);
model()->setCrop(QRect());
@@ -333,11 +328,10 @@ void MImageWidget::setImage(const QImage &image)
void MImageWidget::setPixmap(const QPixmap &pixmap)
{
Q_D(MImageWidget);
- d->setImage(QString());
+ setImage(QString(), QSize());
- d->cleanUp();
- d->pixmap = new QPixmap(pixmap);
- d->deletePixmap = true;
+ QPixmap* newPixmap = new QPixmap(pixmap);
+ d->setPixmap(newPixmap, true);
model()->setCrop(QRect());
diff --git a/src/corelib/widgets/mimagewidget_p.h b/src/corelib/widgets/mimagewidget_p.h
index 1a7b577a..2967bd93 100644
--- a/src/corelib/widgets/mimagewidget_p.h
+++ b/src/corelib/widgets/mimagewidget_p.h
@@ -34,17 +34,22 @@ public:
void cleanUp();
MImageWidgetPrivate &operator=(const MImageWidgetPrivate &other);
- void setImage(const QString &id, const QSize &s = QSize());
- QSizeF imageDataSize() const;
+ QSizeF imageDataSize(const QRectF& cropRect) const;
- void deepCopy(const MImageWidget &);
+ void setPixmap(const QPixmap* pixmap, bool takeOwnership);
+ void setImage(const QImage& image);
+
+ const QPixmap* getPixmap();
+ const QImage& getImage();
- const QPixmap *pixmap;
mutable QPixmap imagePlaceHolder;
+
+private:
+ const QPixmap *pixmap;
QImage image;
- bool deletePixmap;
+ bool ownPixmap;
};
#endif
diff --git a/src/views/mimagewidgetview.cpp b/src/views/mimagewidgetview.cpp
index 3cf85c39..fd636f59 100644
--- a/src/views/mimagewidgetview.cpp
+++ b/src/views/mimagewidgetview.cpp
@@ -262,17 +262,15 @@ void MImageWidgetView::drawContents(QPainter *painter, const QStyleOptionGraphic
Q_D(const MImageWidgetView);
- const QPixmap *pixmap = d->controller->d_func()->pixmap;
+ const QPixmap *pixmap = d->controller->d_func()->getPixmap();
d->drawBorders(painter, d->drawRect);
if (pixmap) {
const_cast<MImageWidgetViewPrivate*>(d)->checkPixmapSize();
painter->drawPixmap(d->drawRect, *pixmap, d->sourceRect);
- } else {
- QImage image = d->controller->d_func()->image;
- painter->drawImage(d->drawRect, image, d->sourceRect);
- }
+ } else
+ painter->drawImage(d->drawRect, d->controller->d_func()->getImage(), d->sourceRect);
}
void MImageWidgetView::resizeEvent(QGraphicsSceneResizeEvent *event)
@@ -297,7 +295,7 @@ void MImageWidgetView::applyStyle()
d->applyStyle();
if (!model()->imageId().isEmpty())
- d->controller->d_func()->pixmap = d->createPixmapFromTheme();
+ d->controller->d_func()->setPixmap(d->createPixmapFromTheme(), false);
}
void MImageWidgetView::updateData(const QList<const char *> &modifications)
@@ -322,7 +320,7 @@ void MImageWidgetView::updateData(const QList<const char *> &modifications)
}
if (needsPixmap && !model()->imageId().isEmpty())
- d->controller->d_func()->pixmap = d->createPixmapFromTheme();
+ d->controller->d_func()->setPixmap(d->createPixmapFromTheme(), false);
if (needsGeometryUpdate || needsPixmap)
updateGeometry();
@@ -355,7 +353,7 @@ QSize MImageWidgetView::imageDataSize()
{
Q_D(MImageWidgetView);
- return d->controller->d_func()->imageDataSize().toSize();
+ return d->controller->d_func()->imageDataSize(model()->crop()).toSize();
}
M_REGISTER_VIEW_NEW(MImageWidgetView, MImageWidget)