Browse Source

ENH: ctkVTKRenderView - backgroundColor/setBackgroundColor now using QColor instead of double

Also added corresponding slots using Q_PROPERTY macro
Jean-Christophe Fillion-Robin 15 years ago
parent
commit
1b05e01934

+ 14 - 3
Libs/Visualization/VTK/Widgets/ctkVTKRenderView.cpp

@@ -184,11 +184,22 @@ QString ctkVTKRenderView::cornerAnnotationText() const
 }
 
 // --------------------------------------------------------------------------
-void ctkVTKRenderView::setBackgroundColor(double r, double g, double b)
+void ctkVTKRenderView::setBackgroundColor(const QColor& newBackgroundColor)
 {
   CTK_D(ctkVTKRenderView);
-  double background_color[3] = {r, g, b};
-  d->Renderer->SetBackground(background_color);
+
+  d->Renderer->SetBackground(newBackgroundColor.redF(),
+                             newBackgroundColor.greenF(),
+                             newBackgroundColor.blueF());
+}
+
+//----------------------------------------------------------------------------
+QColor ctkVTKRenderView::backgroundColor() const
+{
+  CTK_D(const ctkVTKRenderView);
+  double color[3] = {0, 0, 0};
+  d->Renderer->GetBackground(color);
+  return QColor::fromRgbF(color[0], color[1], color[2]);
 }
 
 //----------------------------------------------------------------------------

+ 4 - 2
Libs/Visualization/VTK/Widgets/ctkVTKRenderView.h

@@ -40,6 +40,7 @@ class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKRenderView : public QWidget
 {
   Q_OBJECT
   Q_PROPERTY(QString cornerAnnotationText READ cornerAnnotationText WRITE setCornerAnnotationText)
+  Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
   Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
 public:
   /// Constructors
@@ -67,8 +68,9 @@ public:
   void setCornerAnnotationText(const QString& text);
   QString cornerAnnotationText() const;
 
-  /// Set background color
-  void setBackgroundColor(double r, double g, double b);
+  /// Set/Get background color
+  void setBackgroundColor(const QColor& newBackgroundColor);
+  QColor backgroundColor() const;
 
   /// Get active camera
   vtkCamera* activeCamera();