ctkIconEnginePlugin.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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. #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 QIconEngineV2* create(const QString& filename=QString());
  39. /// Support all the Qt image formats by default
  40. virtual QStringList keys()const;
  41. /// Directory list given to the created icon engines
  42. /// Subdirectories where the icons should be searched, typically:
  43. /// "Small", "Medium", "Large", "XLarge" or
  44. /// "16x16", "32x32", "64x64", "128x128" or
  45. /// "LowDef", "HighDef"
  46. /// \sa ctkIconEnginePlugin::setSizeDirectories
  47. void setSizeDirectories(const QStringList& sizeDirectories);
  48. QStringList sizeDirectories()const;
  49. private:
  50. CTK_DECLARE_PRIVATE(ctkIconEnginePlugin);
  51. };
  52. //------------------------------------------------------------------------------
  53. /// ctkIconEngine is an icon engine that behaves like the default Qt icon engine
  54. /// QPixmapIconEngine(ctkPixmapIconEngine)), but can automatically support icons
  55. /// in multiple size. When adding a file to an icon, it will automatically check
  56. /// if the same file name exists in a different directory. This allows the
  57. /// application to contains icons in different size,e.g. :/Icons/Small/edit.png
  58. /// and :/Icons/Large/edit.png.
  59. /// Without ctkIconEngine, QIcon already support mutltiple files:
  60. /// \code
  61. /// QIcon editIcon;
  62. /// editIcon.addFile(":/Icons/Small/edit.png");
  63. /// editIcon.addFile(":/Icons/Large/edit.png");
  64. /// \endcode
  65. /// Using ctkIconEngine, adding a file to an icon will automatically search for
  66. /// any icon in a different directory:
  67. /// \code
  68. /// ctkIconEngine* autoIconEngine;
  69. /// autoIconEngine->setSizeDirectories(QStringList() << "Large" << "Small";
  70. /// QIcon editIcon(autoIconEngine);
  71. /// editIcon.addFile(":/Icons/Small/edit.png");
  72. /// \endcode
  73. /// where the large version of the icon is automatically added.
  74. /// It is mostly useful when using the designer, where only 1 icon file can
  75. /// be specified. It must be used with ctkIconEnginePlugin
  76. /// TODO: support more than just files in ressources.
  77. class CTK_WIDGETS_EXPORT ctkIconEngine: public ctkPixmapIconEngine
  78. {
  79. public:
  80. typedef ctkPixmapIconEngine Superclass;
  81. ctkIconEngine();
  82. virtual void addFile(const QString& fileName, const QSize& size,
  83. QIcon::Mode mode, QIcon::State state);
  84. /// Subdirectories where the icons should be searched, typically:
  85. /// "Small", "Medium", "Large", "XLarge" or
  86. /// "16x16", "32x32", "64x64", "128x128" or
  87. /// "LowDef", "HighDef"
  88. void setSizeDirectories(const QStringList& sizeDirectories);
  89. QStringList sizeDirectories()const;
  90. private:
  91. CTK_DECLARE_PRIVATE(ctkIconEngine);
  92. };
  93. #endif