ctkPixmapIconEngine.h 2.7 KB

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