ctkIconEnginePlugin.h 4.3 KB

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