|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QImageReader> |
|
19 #include <QRect> |
|
20 |
|
21 #include "hswallpaperloaderthread.h" |
|
22 |
|
23 |
|
24 /*! |
|
25 \class HsWallpaperLoaderThread |
|
26 \ingroup group_hsdomainmodel |
|
27 \brief |
|
28 */ |
|
29 |
|
30 /*! |
|
31 |
|
32 */ |
|
33 HsWallpaperLoaderThread::HsWallpaperLoaderThread(QObject *parent) |
|
34 : QThread(parent), |
|
35 mResult(false) |
|
36 { |
|
37 } |
|
38 |
|
39 /*! |
|
40 |
|
41 */ |
|
42 HsWallpaperLoaderThread::~HsWallpaperLoaderThread() |
|
43 { |
|
44 } |
|
45 |
|
46 /*! |
|
47 \internal |
|
48 Scales and crops source image using target rect. |
|
49 Centers target rect automatically. |
|
50 Saves scaled and cropped image as given target. |
|
51 Result can be read when finished by using result(). |
|
52 */ |
|
53 void HsWallpaperLoaderThread::run() |
|
54 { |
|
55 mResult = true; |
|
56 QImageReader imageReader(mSourcePath); |
|
57 QRect clipRect(QPoint(), mTargetSize); |
|
58 |
|
59 if (imageReader.canRead()) { |
|
60 QSize sourceSize = imageReader.size(); |
|
61 |
|
62 //Scale image's size to target's dimensions |
|
63 sourceSize.scale(clipRect.width(), clipRect.height(), |
|
64 Qt::KeepAspectRatioByExpanding); |
|
65 imageReader.setScaledSize(sourceSize); |
|
66 |
|
67 //Crop center part of the scaled image as a target image |
|
68 clipRect.moveCenter(QPoint(sourceSize.width() / 2, sourceSize.height() / 2)); |
|
69 imageReader.setScaledClipRect(clipRect); |
|
70 |
|
71 mResult = imageReader.read().save(mTargetPath); |
|
72 } else { |
|
73 mResult = false; |
|
74 } |
|
75 } |