ctkIconEnginePlugin.h 4.6 KB

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