ctkPixmapIconEngine.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 <QIconEngineV2>
  18. #include <QPixmap>
  19. #include <QVector>
  20. #include "ctkWidgetsExport.h"
  21. /// \ingroup Widgets
  22. struct ctkPixmapIconEngineEntry
  23. {
  24. ctkPixmapIconEngineEntry():mode(QIcon::Normal), state(QIcon::Off){}
  25. ctkPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
  26. :pixmap(pm), size(pm.size()), mode(m), state(s){}
  27. ctkPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
  28. :fileName(file), size(sz), mode(m), state(s){}
  29. QPixmap pixmap;
  30. QString fileName;
  31. QSize size;
  32. QIcon::Mode mode;
  33. QIcon::State state;
  34. bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); }
  35. };
  36. /// \ingroup Widgets
  37. class CTK_WIDGETS_EXPORT ctkPixmapIconEngine : public QIconEngineV2 {
  38. public:
  39. ctkPixmapIconEngine();
  40. ctkPixmapIconEngine(const ctkPixmapIconEngine &);
  41. ~ctkPixmapIconEngine();
  42. void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
  43. QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
  44. ctkPixmapIconEngineEntry *bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly);
  45. QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
  46. void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state);
  47. void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state);
  48. // v2 functions
  49. QString key() const;
  50. QIconEngineV2 *clone() const;
  51. bool read(QDataStream &in);
  52. bool write(QDataStream &out) const;
  53. void virtual_hook(int id, void *data);
  54. private:
  55. ctkPixmapIconEngineEntry *tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state);
  56. QVector<ctkPixmapIconEngineEntry> pixmaps;
  57. friend class QIconThemeEngine;
  58. };
  59. #endif