瀏覽代碼

Control visibility of options in ctkMaterialPropertyWidget

Add 3 properties to control the visibility of color, opacity and
backfaceculling.
Reorder items in the ui file.
Minor typo fix
Julien Finet 14 年之前
父節點
當前提交
39d6696eef

+ 45 - 45
Libs/Widgets/Resources/UI/ctkMaterialPropertyWidget.ui

@@ -17,6 +17,50 @@
    <property name="margin">
     <number>0</number>
    </property>
+    <item row="0" column="0">
+      <widget class="QLabel" name="ColorLabel">
+        <property name="text">
+          <string>Color:</string>
+        </property>
+      </widget>
+    </item>
+    <item row="0" column="1" colspan="4">
+      <widget class="ctkColorPickerButton" name="ColorPickerButton">
+        <property name="color">
+          <color>
+            <red>255</red>
+            <green>255</green>
+            <blue>255</blue>
+          </color>
+        </property>
+        <property name="displayColorName">
+          <bool>false</bool>
+        </property>
+        <property name="dialogOptions">
+          <set>ctkColorPickerButton::UseCTKColorDialog</set>
+        </property>
+      </widget>
+    </item>
+    <item row="1" column="0">
+      <widget class="QLabel" name="OpacityLabel">
+        <property name="text">
+          <string>Opacity:</string>
+        </property>
+      </widget>
+    </item>
+    <item row="1" column="1" colspan="4">
+      <widget class="ctkSliderWidget" name="OpacitySliderSpinBox">
+        <property name="singleStep">
+          <double>0.010000000000000</double>
+        </property>
+        <property name="maximum">
+          <double>1.000000000000000</double>
+        </property>
+        <property name="value">
+          <double>1.000000000000000</double>
+        </property>
+      </widget>
+    </item>
    <item row="2" column="0">
     <widget class="QLabel" name="AmbientLabel">
      <property name="text">
@@ -168,52 +212,8 @@
      </property>
     </spacer>
    </item>
-   <item row="1" column="0">
-    <widget class="QLabel" name="OpacityLabel">
-     <property name="text">
-      <string>Opacity:</string>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="1" colspan="4">
-    <widget class="ctkSliderWidget" name="OpacitySliderSpinBox">
-     <property name="singleStep">
-      <double>0.010000000000000</double>
-     </property>
-     <property name="maximum">
-      <double>1.000000000000000</double>
-     </property>
-     <property name="value">
-      <double>1.000000000000000</double>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="0">
-    <widget class="QLabel" name="ColorLabel">
-     <property name="text">
-      <string>Color:</string>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="1" colspan="4">
-    <widget class="ctkColorPickerButton" name="ColorPickerButton">
-     <property name="color">
-      <color>
-       <red>255</red>
-       <green>255</green>
-       <blue>255</blue>
-      </color>
-     </property>
-     <property name="displayColorName">
-      <bool>false</bool>
-     </property>
-     <property name="dialogOptions">
-      <set>ctkColorPickerButton::UseCTKColorDialog</set>
-     </property>
-    </widget>
-   </item>
    <item row="6" column="0">
-    <widget class="QLabel" name="BackFaceCullingLabel">
+    <widget class="QLabel" name="BackfaceCullingLabel">
      <property name="text">
       <string>Backface Culling:</string>
      </property>

+ 2 - 0
Libs/Widgets/Testing/Cpp/CMakeLists.txt

@@ -36,6 +36,7 @@ SET(TEST_SOURCES
   ctkLayoutManagerTest1.cpp
   ctkMaterialPropertyPreviewLabelTest1.cpp
   ctkMaterialPropertyWidgetTest1.cpp
+  ctkMaterialPropertyWidgetTest2.cpp
   ctkMatrixWidgetTest1.cpp
   ctkMatrixWidgetTest2.cpp
   ctkMenuButtonTest1.cpp
@@ -146,6 +147,7 @@ SIMPLE_TEST( ctkFontButtonTest1 )
 SIMPLE_TEST( ctkLayoutManagerTest1 )
 SIMPLE_TEST( ctkMaterialPropertyPreviewLabelTest1 )
 SIMPLE_TEST( ctkMaterialPropertyWidgetTest1 )
+SIMPLE_TEST( ctkMaterialPropertyWidgetTest2 )
 SIMPLE_TEST( ctkMatrixWidgetTest1 )
 SIMPLE_TEST( ctkMatrixWidgetTest2 )
 SIMPLE_TEST( ctkMenuButtonTest1 )

+ 86 - 0
Libs/Widgets/Testing/Cpp/ctkMaterialPropertyWidgetTest2.cpp

@@ -0,0 +1,86 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includse
+#include <QApplication>
+#include <QTimer>
+
+// CTK includes
+#include "ctkMaterialPropertyWidget.h"
+
+// STD includes
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkMaterialPropertyWidgetTest2(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  ctkMaterialPropertyWidget materialWidget;
+  if (!materialWidget.isColorVisible() ||
+      !materialWidget.isOpacityVisible() ||
+      !materialWidget.isBackfaceCullingVisible())
+    {
+    std::cout << "ctkMaterialPropertyWidget::ctkMaterialPropertyWidget(), "
+              << "wrong default values" << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  // here for code coverage
+  materialWidget.setColorVisible(true);
+  materialWidget.setOpacityVisible(true);
+  materialWidget.setBackfaceCullingVisible(true);
+
+  materialWidget.setColorVisible(false);
+  if (materialWidget.isColorVisible())
+    {
+    std::cout << "ctkMaterialPropertyWidget::setColorVisible failed"
+              << std::endl;
+    return EXIT_FAILURE;
+    }
+  materialWidget.setOpacityVisible(false);
+  if (materialWidget.isOpacityVisible())
+    {
+    std::cout << "ctkMaterialPropertyWidget::setColorVisible failed"
+              << std::endl;
+    return EXIT_FAILURE;
+    }
+  materialWidget.setBackfaceCullingVisible(false);
+  if (materialWidget.isBackfaceCullingVisible())
+    {
+    std::cout << "ctkMaterialPropertyWidget::setColorVisible failed"
+              << std::endl;
+    return EXIT_FAILURE;
+    }
+  
+  materialWidget.setColorVisible(true);
+  materialWidget.setOpacityVisible(true);
+  materialWidget.setBackfaceCullingVisible(true);
+  
+  materialWidget.show();
+
+  if (argc < 2 || QString(argv[1]) != "-I" )
+    {
+    QTimer::singleShot(200, &app, SLOT(quit()));
+    }
+
+  return app.exec();
+}
+

+ 48 - 0
Libs/Widgets/ctkMaterialPropertyWidget.cpp

@@ -302,3 +302,51 @@ void ctkMaterialPropertyWidget::resizeEvent(QResizeEvent* resize)
       d->PresetsListWidget->horizontalScrollBar()->sizeHint().height() : 0)
     + d->PresetsListWidget->frameWidth() ); // bottom frame height
 }
+
+// --------------------------------------------------------------------------
+bool ctkMaterialPropertyWidget::isColorVisible()const
+{
+  Q_D(const ctkMaterialPropertyWidget);
+  return d->ColorPickerButton->isVisibleTo(
+    const_cast<ctkMaterialPropertyWidget*>(this));
+}
+
+// --------------------------------------------------------------------------
+void ctkMaterialPropertyWidget::setColorVisible(bool show)
+{
+  Q_D(ctkMaterialPropertyWidget);
+  d->ColorLabel->setVisible(show);
+  d->ColorPickerButton->setVisible(show);
+}
+
+// --------------------------------------------------------------------------
+bool ctkMaterialPropertyWidget::isOpacityVisible()const
+{
+  Q_D(const ctkMaterialPropertyWidget);
+  return d->OpacitySliderSpinBox->isVisibleTo(
+    const_cast<ctkMaterialPropertyWidget*>(this));
+}
+
+// --------------------------------------------------------------------------
+void ctkMaterialPropertyWidget::setOpacityVisible(bool show)
+{
+  Q_D(ctkMaterialPropertyWidget);
+  d->OpacityLabel->setVisible(show);
+  d->OpacitySliderSpinBox->setVisible(show);
+}
+
+// --------------------------------------------------------------------------
+bool ctkMaterialPropertyWidget::isBackfaceCullingVisible()const
+{
+  Q_D(const ctkMaterialPropertyWidget);
+  return d->BackfaceCullingCheckBox->isVisibleTo(
+    const_cast<ctkMaterialPropertyWidget*>(this));
+}
+
+// --------------------------------------------------------------------------
+void ctkMaterialPropertyWidget::setBackfaceCullingVisible(bool show)
+{
+  Q_D(ctkMaterialPropertyWidget);
+  d->BackfaceCullingLabel->setVisible(show);
+  d->BackfaceCullingCheckBox->setVisible(show);
+}

+ 14 - 0
Libs/Widgets/ctkMaterialPropertyWidget.h

@@ -61,6 +61,13 @@ class CTK_WIDGETS_EXPORT ctkMaterialPropertyWidget : public QWidget
   Q_PROPERTY(double specularPower READ specularPower WRITE setSpecularPower);
   /// This property controls weither backface culling should be enabled or not
   Q_PROPERTY(bool backfaceCulling READ backfaceCulling WRITE setBackfaceCulling);
+  /// Control weither the color is shown to the user. Visible by default
+  Q_PROPERTY(bool colorVisible READ isColorVisible WRITE setColorVisible);
+  /// Control weither the opacity is shown to the user. Visible by default
+  Q_PROPERTY(bool opacityVisible READ isOpacityVisible WRITE setOpacityVisible);
+  /// Control weither the backface culling is shown to the user. Visible by default
+  Q_PROPERTY(bool backfaceCullingVisible READ isBackfaceCullingVisible WRITE setBackfaceCullingVisible);
+  
 public:
   /// Superclass typedef
   typedef QWidget Superclass;
@@ -92,6 +99,13 @@ public:
                  double specular, double power,
                  const QString& label);
 
+  bool isColorVisible()const;
+  void setColorVisible(bool show);
+  bool isOpacityVisible()const;
+  void setOpacityVisible(bool show);
+  bool isBackfaceCullingVisible()const;
+  void setBackfaceCullingVisible(bool show);
+
 public slots:
   void setColor(const QColor& newColor);
   void setOpacity(double newOpacity);