ctkPixmapIconEngine.h 2.6 KB

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