ctkPixmapIconEngine.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.apache.org/licenses/LICENSE-2.0.txt
  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. #ifndef __ctkPixmapIconEngine_h
  16. #define __ctkPixmapIconEngine_h
  17. #include <QtGlobal>
  18. #if QT_VERSION >= 0x050000
  19. # include <QIconEngine>
  20. #else
  21. # include <QIconEngineV2>
  22. #endif
  23. #include <QPixmap>
  24. #include <QVector>
  25. #include "ctkWidgetsExport.h"
  26. /// \ingroup Widgets
  27. struct ctkPixmapIconEngineEntry
  28. {
  29. ctkPixmapIconEngineEntry():mode(QIcon::Normal), state(QIcon::Off){}
  30. ctkPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
  31. :pixmap(pm), size(pm.size()), mode(m), state(s){}
  32. ctkPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
  33. :fileName(file), size(sz), mode(m), state(s){}
  34. QPixmap pixmap;
  35. QString fileName;
  36. QSize size;
  37. QIcon::Mode mode;
  38. QIcon::State state;
  39. bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); }
  40. };
  41. /// \ingroup Widgets
  42. class CTK_WIDGETS_EXPORT ctkPixmapIconEngine
  43. #if QT_VERSION >= 0x050000
  44. : public QIconEngine
  45. #else
  46. : public QIconEngineV2
  47. #endif
  48. {
  49. public:
  50. ctkPixmapIconEngine();
  51. ctkPixmapIconEngine(const ctkPixmapIconEngine &);
  52. ~ctkPixmapIconEngine();
  53. void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
  54. QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
  55. ctkPixmapIconEngineEntry *bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly);
  56. QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
  57. void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state);
  58. void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state);
  59. // v2 functions
  60. QString key() const;
  61. #if QT_VERSION >= 0x050000
  62. QIconEngine *clone() const;
  63. #else
  64. QIconEngineV2 *clone() const;
  65. #endif
  66. bool read(QDataStream &in);
  67. bool write(QDataStream &out) const;
  68. void virtual_hook(int id, void *data);
  69. private:
  70. ctkPixmapIconEngineEntry *tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state);
  71. QVector<ctkPixmapIconEngineEntry> pixmaps;
  72. friend class QIconThemeEngine;
  73. };
  74. #endif