examples/QtQuick/contentlauncherexample/mifprovider/mifimageprovider.cpp

00001 /*
00002 * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
00003 * All rights reserved.
00004 * This software, including documentation is protected by copyright controlled
00005 * by Nokia Corporation. Copying, including reproducing, storing, adapting or
00006 * translating, any or all of this material can only be done in accordance
00007 * with the Nokia Symbian License version 1.0 (or any subsequent update) or
00008 * any other license terms expressly agreed between you and Nokia.
00009 * This material contains Nokia's confidential information which
00010 * may not be disclosed to others without the prior written consent of Nokia.
00011 *
00012 * Initial Contributors:
00013 * Nokia Corporation - initial contribution.
00014 *
00015 * Contributors:
00016 *
00017 * Description:
00018 *
00019 */
00020 
00021 #include "mifimageprovider.h"
00022 #include "contentlauncherlog.h"
00023 
00024 #include <aknsutils.h>
00025 #include <e32std.h>
00026 #include <e32base.h>
00027 #include <fbs.h>
00028 #include <e32cmn.h>
00029 #include <e32des8.h>
00030 
00031 #include <QUrl>
00032 #include <QPixmap>
00033 #include <QBitmap>
00034 #include <QFile>
00035 
00036 namespace {
00037   const int KDefaultIconWidth = 32;
00038   const int KDefaultIconHeight = 32;
00039 }
00040 
00041 MifImageProvider::MifImageProvider()
00042          : QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap)
00043      {
00044      }
00045 
00046 QPixmap MifImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
00047      {
00048      QPixmap pixmap;
00049      CFbsBitmap *image = 0;
00050      CFbsBitmap *mask = 0;
00051 
00052      try {
00053          CL_ENTER << "id:" << id << "size:" << size << "requestedSize:" << requestedSize;
00054 
00055          QUrl urlName(id);
00056          QString fname(urlName.toLocalFile().replace("/", "\\"));
00057 
00058          if (QFile::exists(fname)) {
00059              TPtrC16 filenamePtr(reinterpret_cast<const TUint16*>(fname.utf16()));
00060 
00061              CL_QDEBUG << "size:" << *size;
00062 
00063              TSize bmpSize(requestedSize.width() > 0 ? requestedSize.width() : KDefaultIconWidth,
00064                  requestedSize.height() > 0 ? requestedSize.height() : KDefaultIconHeight);
00065 
00066              CL_QDEBUG << "bitmap requested size: " << bmpSize.iWidth << "x" << bmpSize.iHeight;
00067 
00068              QT_TRAP_THROWING(LoadImageL(image, mask, filenamePtr, 1, 1, bmpSize));
00069 
00070              CL_QDEBUG << "bitmap retrieved size:" << image->SizeInPixels().iWidth << "x" << image->SizeInPixels().iHeight;
00071              CL_QDEBUG << "bitmap display mode:" << image->DisplayMode();
00072              CL_QDEBUG << "bitmap data size:" << image->DataSize();
00073 
00074              CL_QDEBUG << "mask retrieved size:" << mask->SizeInPixels().iWidth << "x" << mask->SizeInPixels().iHeight;
00075              CL_QDEBUG << "mask display mode:" << mask->DisplayMode();
00076              CL_QDEBUG << "mask data size:" << mask->DataSize();
00077 
00078              pixmap = QPixmap::fromSymbianCFbsBitmap(image);
00079              QBitmap pixmapMask = QPixmap::fromSymbianCFbsBitmap(mask).createMaskFromColor(Qt::white, Qt::MaskOutColor);
00080              pixmap.setMask(pixmapMask);
00081 
00082              if (size) {
00083                  size->setWidth(pixmap.width());
00084                  size->setHeight(pixmap.height());
00085              }
00086 
00087          } else {
00088              CL_QDEBUG << "could not find given file:" << fname;
00089          }
00090 
00091          CL_QDEBUG << "pixmap:" << pixmap.size();
00092      } catch (const std::exception &e) {
00093          CL_QDEBUG << "exception:" << e.what();
00094      }
00095      delete mask;
00096      delete image;
00097 
00098      CL_EXIT;
00099      return pixmap;
00100 }
00101 
00102 void MifImageProvider::LoadImageL(CFbsBitmap *&aImage, CFbsBitmap *&aMask, const TDesC& aFileName, TInt aImg,
00103         TInt aMsk, const TSize& aSize)
00104 {
00105     CL_ENTER;
00106     TInt MaskId(aMsk);
00107     TInt UseIndex(aImg);
00108     if (AknIconUtils::IsMifFile(aFileName)) {
00109         AknIconUtils::ValidateLogicalAppIconId(aFileName, UseIndex, MaskId);
00110     }
00111     AknIconUtils::CreateIconL(aImage, aMask, aFileName, UseIndex, MaskId);
00112     AknIconUtils::SetSize(aImage, aSize, EAspectRatioPreserved);
00113     AknIconUtils::SetSize(aMask, aSize, EAspectRatioPreserved);
00114     aMask->SetDisplayMode(EGray2);
00115     CL_EXIT;
00116 }

Generated by  doxygen 1.6.2