homescreenapp/hsutils/src/hswallpaperimagereader.cpp
changeset 51 4785f57bf3d4
parent 46 23b5d6a29cce
equal deleted inserted replaced
46:23b5d6a29cce 51:4785f57bf3d4
    22 
    22 
    23 /*!
    23 /*!
    24     Constructor.         
    24     Constructor.         
    25 */
    25 */
    26 HsWallpaperImageReader::HsWallpaperImageReader(QObject *parent):
    26 HsWallpaperImageReader::HsWallpaperImageReader(QObject *parent):
    27     QObject(parent),
    27     QThread(parent),
    28     mCenterTarget(false)
    28     mCenterTarget(false)
    29 {
    29 {
    30 
    30 
    31 }
    31 }
    32 
    32 
    47 }
    47 }
    48 
    48 
    49 /*!
    49 /*!
    50     Returns image source path
    50     Returns image source path
    51 */
    51 */
    52 QString HsWallpaperImageReader::getSourcePath() const
    52 QString HsWallpaperImageReader::sourcePath() const
    53 {
    53 {
    54     return mSourcePath;
    54     return mSourcePath;
    55 }
    55 }
    56 
    56 
    57 /*!
    57 /*!
    63 }
    63 }
    64 
    64 
    65 /*!
    65 /*!
    66     Returns source rect
    66     Returns source rect
    67 */
    67 */
    68 QRect HsWallpaperImageReader::getSourceRect() const
    68 QRect HsWallpaperImageReader::sourceRect() const
    69 {
    69 {
    70     return mSourceRect;
    70     return mSourceRect;
    71 }
    71 }
    72 
    72 
    73 /*!
    73 /*!
    79 }
    79 }
    80 
    80 
    81 /*!
    81 /*!
    82     Returns target rect
    82     Returns target rect
    83 */
    83 */
    84 QRect HsWallpaperImageReader::getTargetRect() const
    84 QRect HsWallpaperImageReader::targetRect() const
    85 {
    85 {
    86     return mTargetRect;
    86     return mTargetRect;
    87 }
    87 }
    88 
    88 
    89 /*!
    89 /*!
    95 }
    95 }
    96 
    96 
    97 /*!
    97 /*!
    98     Returns target centering
    98     Returns target centering
    99 */
    99 */
   100 bool HsWallpaperImageReader::getCenterTarget()
   100 bool HsWallpaperImageReader::centerTarget()
   101 {
   101 {
   102     return mCenterTarget;
   102     return mCenterTarget;
   103 }
   103 }
   104 
   104 
   105 /*!
   105 /*!
   106     Returns processed image
   106     Returns processed image
   107 */
   107 */
   108 QImage HsWallpaperImageReader::getProcessedImage() const
   108 QImage HsWallpaperImageReader::processedImage() const
   109 {
   109 {
   110     return mProcessedImage;
   110     return mProcessedImage;
   111 }
   111 }
   112 
   112 
   113 /*!
   113 /*!
   115     Scales and crops (if needed) image using target rect. 
   115     Scales and crops (if needed) image using target rect. 
   116     Centers target rect automatically if mCenterTarget is true.
   116     Centers target rect automatically if mCenterTarget is true.
   117     Pass empty set sourceRect to empty to use full size source image as starting point. 
   117     Pass empty set sourceRect to empty to use full size source image as starting point. 
   118     Returns processed image or null image if operation fails.
   118     Returns processed image or null image if operation fails.
   119 */
   119 */
   120 void HsWallpaperImageReader::processImage() 
   120 void HsWallpaperImageReader::run() 
   121 {
   121 {
   122     QImageReader imageReader(mSourcePath);
   122     QImageReader imageReader(mSourcePath);
   123     
   123 
   124     QRect tempTargetRect = mTargetRect;
   124     QRect tempTargetRect = mTargetRect;
   125     QRect tempSourceRect = mSourceRect;
   125     QRect tempSourceRect = mSourceRect;
   126     
   126     
   127     if (imageReader.canRead()) {
   127     if (imageReader.canRead()) {
   128         QSize sourceSize = imageReader.size();
   128         QSize sourceSize = imageReader.size();
   129         if (tempSourceRect.isEmpty()) {
   129         if (tempSourceRect.isEmpty()) {
   130             // If sourceRect not defined, uses full size image as source.
   130             // If sourceRect not defined, uses full size image as source.
   131             tempSourceRect.setRect(0, 0, sourceSize.width(), sourceSize.height());
   131             tempSourceRect.setRect(0, 0, sourceSize.width(), sourceSize.height());
   132         }
   132         }
   133         sourceSize.scale(tempTargetRect.width(), tempTargetRect.height(), 
   133         sourceSize.scale(tempTargetRect.width(), tempTargetRect.height(),
   134                          Qt::KeepAspectRatioByExpanding);
   134                          Qt::KeepAspectRatioByExpanding);
   135         imageReader.setScaledSize(sourceSize);
   135         imageReader.setScaledSize(sourceSize);
   136 
   136 
   137         if (mCenterTarget) {
   137         if (mCenterTarget) {
   138             tempTargetRect.moveCenter(QPoint(sourceSize.width() / 2, sourceSize.height() / 2));
   138             tempTargetRect.moveCenter(QPoint(sourceSize.width() / 2, sourceSize.height() / 2));
   140         imageReader.setScaledClipRect(tempTargetRect);
   140         imageReader.setScaledClipRect(tempTargetRect);
   141         mProcessedImage = imageReader.read();
   141         mProcessedImage = imageReader.read();
   142     } else {
   142     } else {
   143         mProcessedImage = QImage();
   143         mProcessedImage = QImage();
   144     }
   144     }
   145     emit processingFinished();
       
   146 }
   145 }