src/gui/image/qimagepixmapcleanuphooks.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qimagepixmapcleanuphooks_p.h"
       
    43 #include "qpixmapdata_p.h"
       
    44 
       
    45 
       
    46 QT_BEGIN_NAMESPACE
       
    47 
       
    48 // Legacy, single instance hooks: ### Qt 5: remove
       
    49 typedef void (*_qt_pixmap_cleanup_hook)(int);
       
    50 typedef void (*_qt_pixmap_cleanup_hook_64)(qint64);
       
    51 typedef void (*_qt_image_cleanup_hook)(int);
       
    52 Q_GUI_EXPORT _qt_pixmap_cleanup_hook qt_pixmap_cleanup_hook = 0;
       
    53 Q_GUI_EXPORT _qt_pixmap_cleanup_hook_64 qt_pixmap_cleanup_hook_64 = 0;
       
    54 Q_GUI_EXPORT _qt_image_cleanup_hook qt_image_cleanup_hook = 0;
       
    55 Q_GUI_EXPORT _qt_image_cleanup_hook_64 qt_image_cleanup_hook_64 = 0;
       
    56 
       
    57 
       
    58 QImagePixmapCleanupHooks* qt_image_and_pixmap_cleanup_hooks = 0;
       
    59 
       
    60 
       
    61 QImagePixmapCleanupHooks::QImagePixmapCleanupHooks()
       
    62 {
       
    63     qt_image_and_pixmap_cleanup_hooks = this;
       
    64 }
       
    65 
       
    66 QImagePixmapCleanupHooks *QImagePixmapCleanupHooks::instance()
       
    67 {
       
    68     if (!qt_image_and_pixmap_cleanup_hooks)
       
    69         qt_image_and_pixmap_cleanup_hooks = new QImagePixmapCleanupHooks;
       
    70     return qt_image_and_pixmap_cleanup_hooks;
       
    71 }
       
    72 
       
    73 void QImagePixmapCleanupHooks::addPixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook)
       
    74 {
       
    75     pixmapModificationHooks.append(hook);
       
    76 }
       
    77 
       
    78 void QImagePixmapCleanupHooks::addPixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook)
       
    79 {
       
    80     pixmapDestructionHooks.append(hook);
       
    81 }
       
    82 
       
    83 
       
    84 void QImagePixmapCleanupHooks::addImageHook(_qt_image_cleanup_hook_64 hook)
       
    85 {
       
    86     imageHooks.append(hook);
       
    87 }
       
    88 
       
    89 void QImagePixmapCleanupHooks::removePixmapModificationHook(_qt_pixmap_cleanup_hook_pm hook)
       
    90 {
       
    91     pixmapModificationHooks.removeAll(hook);
       
    92 }
       
    93 
       
    94 void QImagePixmapCleanupHooks::removePixmapDestructionHook(_qt_pixmap_cleanup_hook_pm hook)
       
    95 {
       
    96     pixmapDestructionHooks.removeAll(hook);
       
    97 }
       
    98 
       
    99 void QImagePixmapCleanupHooks::removeImageHook(_qt_image_cleanup_hook_64 hook)
       
   100 {
       
   101     imageHooks.removeAll(hook);
       
   102 }
       
   103 
       
   104 
       
   105 void QImagePixmapCleanupHooks::executePixmapModificationHooks(QPixmap* pm)
       
   106 {
       
   107     Q_ASSERT(qt_image_and_pixmap_cleanup_hooks);
       
   108     for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->pixmapModificationHooks.count(); ++i)
       
   109         qt_image_and_pixmap_cleanup_hooks->pixmapModificationHooks[i](pm);
       
   110 
       
   111     if (qt_pixmap_cleanup_hook_64)
       
   112         qt_pixmap_cleanup_hook_64(pm->cacheKey());
       
   113 }
       
   114 
       
   115 void QImagePixmapCleanupHooks::executePixmapDestructionHooks(QPixmap* pm)
       
   116 {
       
   117     Q_ASSERT(qt_image_and_pixmap_cleanup_hooks);
       
   118     for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->pixmapDestructionHooks.count(); ++i)
       
   119         qt_image_and_pixmap_cleanup_hooks->pixmapDestructionHooks[i](pm);
       
   120 
       
   121     if (qt_pixmap_cleanup_hook_64)
       
   122         qt_pixmap_cleanup_hook_64(pm->cacheKey());
       
   123 }
       
   124 
       
   125 void QImagePixmapCleanupHooks::executeImageHooks(qint64 key)
       
   126 {
       
   127     Q_ASSERT(qt_image_and_pixmap_cleanup_hooks);
       
   128     for (int i = 0; i < qt_image_and_pixmap_cleanup_hooks->imageHooks.count(); ++i)
       
   129         qt_image_and_pixmap_cleanup_hooks->imageHooks[i](key);
       
   130 
       
   131     if (qt_image_cleanup_hook_64)
       
   132         qt_image_cleanup_hook_64(key);
       
   133 }
       
   134 
       
   135 QT_END_NAMESPACE