ctkIconEnginePlugin.h 4.6 KB

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