ctkMaterialPropertyWidget.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 __ctkMaterialPropertyWidget_h
  15. #define __ctkMaterialPropertyWidget_h
  16. // Qt includes
  17. #include <QWidget>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkMaterialPropertyWidgetPrivate;
  21. class QListWidgetItem;
  22. /// \ingroup Widgets
  23. /// ctkMaterialPropertyWidget is a panel to control material properties
  24. /// such as color and lighting coefficients. It contains a preview icon
  25. /// and a list of presets.
  26. /// Anytime a property is modified, the preview icon is updated with the
  27. /// new lighting coefficient.
  28. class CTK_WIDGETS_EXPORT ctkMaterialPropertyWidget : public QWidget
  29. {
  30. Q_OBJECT
  31. /// This property holds the color of the material.
  32. Q_PROPERTY(QColor color READ color WRITE setColor);
  33. /// Opacity component of the material property.
  34. Q_PROPERTY(double opacity READ opacity WRITE setOpacity);
  35. /// This property holds the ambient lighting coefficient,
  36. /// it is a nondirectional property.
  37. /// Its range is [0,1], where 0 means no ambient light, and 1 means
  38. /// full ambient light
  39. /// Hint: A range of [0.1,0.5] is more realistic.
  40. Q_PROPERTY(double ambient READ ambient WRITE setAmbient);
  41. /// This property holds the diffuse lighting coefficient.
  42. /// Its range is [0,1], where 0 means no diffuse light, and 1 means
  43. /// full diffuse light
  44. Q_PROPERTY(double diffuse READ diffuse WRITE setDiffuse);
  45. /// This property holds the specular lighting coefficient.
  46. /// Its range is [0,1], where 0 means no specular light, and 1 means
  47. /// full specular light
  48. Q_PROPERTY(double specular READ specular WRITE setSpecular);
  49. /// This property holds the power of specular lighting coefficient.
  50. /// Its range is [1,50].
  51. Q_PROPERTY(double specularPower READ specularPower WRITE setSpecularPower);
  52. /// This property controls weither backface culling should be enabled or not
  53. Q_PROPERTY(bool backfaceCulling READ backfaceCulling WRITE setBackfaceCulling);
  54. /// Control weither the color is shown to the user. Visible by default
  55. Q_PROPERTY(bool colorVisible READ isColorVisible WRITE setColorVisible);
  56. /// Control weither the opacity is shown to the user. Visible by default
  57. Q_PROPERTY(bool opacityVisible READ isOpacityVisible WRITE setOpacityVisible);
  58. /// Control weither the backface culling is shown to the user. Visible by default
  59. Q_PROPERTY(bool backfaceCullingVisible READ isBackfaceCullingVisible WRITE setBackfaceCullingVisible);
  60. public:
  61. /// Superclass typedef
  62. typedef QWidget Superclass;
  63. /// Constructor
  64. explicit ctkMaterialPropertyWidget(QWidget* parent = 0);
  65. /// Destructor
  66. virtual ~ctkMaterialPropertyWidget();
  67. QColor color()const;
  68. double opacity()const;
  69. double ambient()const;
  70. double diffuse()const;
  71. double specular()const;
  72. double specularPower()const;
  73. bool backfaceCulling()const;
  74. /// Add a preset to the preset list. A preview icon will be generated and be
  75. /// added on the bottom right corner list. If space is needed, a scrollbar
  76. /// will appear. When the user clicks on the icon representing the preset,
  77. /// all the preset properties will be applied.
  78. /// If color is invalid, the preset color is synchronized with the current
  79. /// color property.
  80. void addPreset(const QColor& color, double opacity,
  81. double ambient, double diffuse,
  82. double specular, double power,
  83. const QString& label);
  84. bool isColorVisible()const;
  85. void setColorVisible(bool show);
  86. bool isOpacityVisible()const;
  87. void setOpacityVisible(bool show);
  88. bool isBackfaceCullingVisible()const;
  89. void setBackfaceCullingVisible(bool show);
  90. public Q_SLOTS:
  91. void setColor(const QColor& newColor);
  92. void setOpacity(double newOpacity);
  93. void setAmbient(double newAmbient);
  94. void setDiffuse(double newDiffuse);
  95. void setSpecular(double newSpecular);
  96. void setSpecularPower(double newSpecularPower);
  97. void setBackfaceCulling(bool enable);
  98. Q_SIGNALS:
  99. void colorChanged(QColor newColor);
  100. void opacityChanged(double newOpacity);
  101. void ambientChanged(double newAmbient);
  102. void diffuseChanged(double newDiffuse);
  103. void specularChanged(double newSpecular);
  104. void specularPowerChanged(double newSpecularPower);
  105. void backfaceCullingChanged(bool newBackfaceCulling);
  106. protected Q_SLOTS:
  107. virtual void onColorChanged(const QColor& newColor);
  108. virtual void onOpacityChanged(double newOpacity);
  109. virtual void onAmbientChanged(double newAmbient);
  110. virtual void onDiffuseChanged(double newDiffuse);
  111. virtual void onSpecularChanged(double newSpecular);
  112. virtual void onSpecularPowerChanged(double newSpecularPower);
  113. virtual void onBackfaceCullingChanged(bool newBackFaceCulling);
  114. void selectPreset(QListWidgetItem*);
  115. protected:
  116. QScopedPointer<ctkMaterialPropertyWidgetPrivate> d_ptr;
  117. virtual void resizeEvent(QResizeEvent* resize);
  118. private:
  119. Q_DECLARE_PRIVATE(ctkMaterialPropertyWidget);
  120. Q_DISABLE_COPY(ctkMaterialPropertyWidget);
  121. };
  122. #endif