ctkPixmapIconEngine.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // ctkPixmapIconEngine is based on QPixmapIconEngine in qicon_p.h
  15. /****************************************************************************
  16. **
  17. ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
  18. ** All rights reserved.
  19. ** Contact: Nokia Corporation (qt-info@nokia.com)
  20. **
  21. ** This file is part of the QtGui module of the Qt Toolkit.
  22. **
  23. ** $QT_BEGIN_LICENSE:LGPL$
  24. ** Commercial Usage
  25. ** Licensees holding valid Qt Commercial licenses may use this file in
  26. ** accordance with the Qt Commercial License Agreement provided with the
  27. ** Software or, alternatively, in accordance with the terms contained in
  28. ** a written agreement between you and Nokia.
  29. **
  30. ** GNU Lesser General Public License Usage
  31. ** Alternatively, this file may be used under the terms of the GNU Lesser
  32. ** General Public License version 2.1 as published by the Free Software
  33. ** Foundation and appearing in the file LICENSE.LGPL included in the
  34. ** packaging of this file. Please review the following information to
  35. ** ensure the GNU Lesser General Public License version 2.1 requirements
  36. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  37. **
  38. ** In addition, as a special exception, Nokia gives you certain additional
  39. ** rights. These rights are described in the Nokia Qt LGPL Exception
  40. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  41. **
  42. ** GNU General Public License Usage
  43. ** Alternatively, this file may be used under the terms of the GNU
  44. ** General Public License version 3.0 as published by the Free Software
  45. ** Foundation and appearing in the file LICENSE.GPL included in the
  46. ** packaging of this file. Please review the following information to
  47. ** ensure the GNU General Public License version 3.0 requirements will be
  48. ** met: http://www.gnu.org/copyleft/gpl.html.
  49. **
  50. ** If you have questions regarding the use of this file, please contact
  51. ** Nokia at qt-info@nokia.com.
  52. ** $QT_END_LICENSE$
  53. **
  54. ****************************************************************************/
  55. #ifndef __ctkPixmapIconEngine_h
  56. #define __ctkPixmapIconEngine_h
  57. #include <QIconEngineV2>
  58. #include <QPixmap>
  59. #include <QVector>
  60. #include "ctkWidgetsExport.h"
  61. struct ctkPixmapIconEngineEntry
  62. {
  63. ctkPixmapIconEngineEntry():mode(QIcon::Normal), state(QIcon::Off){}
  64. ctkPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
  65. :pixmap(pm), size(pm.size()), mode(m), state(s){}
  66. ctkPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
  67. :fileName(file), size(sz), mode(m), state(s){}
  68. QPixmap pixmap;
  69. QString fileName;
  70. QSize size;
  71. QIcon::Mode mode;
  72. QIcon::State state;
  73. bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); }
  74. };
  75. class CTK_WIDGETS_EXPORT ctkPixmapIconEngine : public QIconEngineV2 {
  76. public:
  77. ctkPixmapIconEngine();
  78. ctkPixmapIconEngine(const ctkPixmapIconEngine &);
  79. ~ctkPixmapIconEngine();
  80. void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
  81. QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
  82. ctkPixmapIconEngineEntry *bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly);
  83. QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
  84. void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state);
  85. void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state);
  86. // v2 functions
  87. QString key() const;
  88. QIconEngineV2 *clone() const;
  89. bool read(QDataStream &in);
  90. bool write(QDataStream &out) const;
  91. void virtual_hook(int id, void *data);
  92. private:
  93. ctkPixmapIconEngineEntry *tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state);
  94. QVector<ctkPixmapIconEngineEntry> pixmaps;
  95. friend class QIconThemeEngine;
  96. };
  97. #endif