ctkMaterialPropertyWidget.h 5.5 KB

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