ctkIconEnginePlugin_qt5.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #ifndef __ctkIconEnginePlugin_qt5_h
  15. #define __ctkIconEnginePlugin_qt5_h
  16. // Qt includes
  17. # include <QIconEngine>
  18. # include <QIconEnginePlugin>
  19. // CTK includes
  20. #include "ctkPimpl.h"
  21. #include "ctkPixmapIconEngine.h"
  22. #include "ctkWidgetsExport.h"
  23. class ctkIconEnginePluginPrivate;
  24. class ctkIconEnginePrivate;
  25. /// \ingroup Widgets
  26. /// ctkIconEnginePlugin must be loaded when starting the application.
  27. /// \code
  28. /// QApplication myApp;
  29. /// QCoreApplication::addLibraryPath("MyApp-build/plugins");
  30. /// \endcode
  31. /// where the plugin must be located in "MyApp-build/plugins/iconengines"
  32. /// don't forget to declare in the cpp file:
  33. /// Q_EXPORT_PLUGIN2(yourpluginName, ctkIconEnginePlugin)
  34. class CTK_WIDGETS_EXPORT ctkIconEnginePlugin
  35. : public QIconEnginePlugin
  36. {
  37. Q_OBJECT;
  38. public:
  39. ctkIconEnginePlugin(QObject* parent = 0);
  40. virtual ~ctkIconEnginePlugin();
  41. virtual QIconEngine* create(const QString& filename=QString());
  42. /// Support all the Qt image formats by default
  43. virtual QStringList keys()const;
  44. /// Directory list given to the created icon engines
  45. /// Subdirectories where the icons should be searched, typically:
  46. /// "Small", "Medium", "Large", "XLarge" or
  47. /// "16x16", "32x32", "64x64", "128x128" or
  48. /// "LowDef", "HighDef"
  49. /// \sa ctkIconEnginePlugin::setSizeDirectories
  50. void setSizeDirectories(const QStringList& sizeDirectories);
  51. QStringList sizeDirectories()const;
  52. protected:
  53. QScopedPointer<ctkIconEnginePluginPrivate> d_ptr;
  54. private:
  55. Q_DECLARE_PRIVATE(ctkIconEnginePlugin);
  56. Q_DISABLE_COPY(ctkIconEnginePlugin);
  57. };
  58. //------------------------------------------------------------------------------
  59. /// \ingroup Widgets
  60. /// ctkIconEngine is an icon engine that behaves like the default Qt icon engine
  61. /// QPixmapIconEngine(ctkPixmapIconEngine)), but can automatically support icons
  62. /// in multiple size. When adding a file to an icon, it will automatically check
  63. /// if the same file name exists in a different directory. This allows the
  64. /// application to contains icons in different size,e.g. :/Icons/Small/edit.png
  65. /// and :/Icons/Large/edit.png.
  66. /// Without ctkIconEngine, QIcon already support mutltiple files:
  67. /// \code
  68. /// QIcon editIcon;
  69. /// editIcon.addFile(":/Icons/Small/edit.png");
  70. /// editIcon.addFile(":/Icons/Large/edit.png");
  71. /// \endcode
  72. /// Using ctkIconEngine, adding a file to an icon will automatically search for
  73. /// any icon in a different directory:
  74. /// \code
  75. /// ctkIconEngine* autoIconEngine;
  76. /// autoIconEngine->setSizeDirectories(QStringList() << "Large" << "Small";
  77. /// QIcon editIcon(autoIconEngine);
  78. /// editIcon.addFile(":/Icons/Small/edit.png");
  79. /// \endcode
  80. /// where the large version of the icon is automatically added.
  81. /// It is mostly useful when using the designer, where only 1 icon file can
  82. /// be specified. It must be used with ctkIconEnginePlugin
  83. /// TODO: support more than just files in ressources.
  84. class CTK_WIDGETS_EXPORT ctkIconEngine: public ctkPixmapIconEngine
  85. {
  86. public:
  87. typedef ctkPixmapIconEngine Superclass;
  88. ctkIconEngine();
  89. virtual ~ctkIconEngine();
  90. virtual void addFile(const QString& fileName, const QSize& size,
  91. QIcon::Mode mode, QIcon::State state);
  92. /// Subdirectories where the icons should be searched, typically:
  93. /// "Small", "Medium", "Large", "XLarge" or
  94. /// "16x16", "32x32", "64x64", "128x128" or
  95. /// "LowDef", "HighDef"
  96. void setSizeDirectories(const QStringList& sizeDirectories);
  97. QStringList sizeDirectories()const;
  98. virtual QString key()const;
  99. protected:
  100. QScopedPointer<ctkIconEnginePrivate> d_ptr;
  101. private:
  102. Q_DECLARE_PRIVATE(ctkIconEngine);
  103. Q_DISABLE_COPY(ctkIconEngine);
  104. };
  105. #endif