Browse Source

ENH: Add ctkVTKTextPropertyWidget that represents a vtkTextProperty

Julien Finet 15 years ago
parent
commit
a487b4b479

+ 4 - 0
Libs/Visualization/VTK/Widgets/CMakeLists.txt

@@ -34,6 +34,8 @@ SET(KIT_SRCS
   ctkVTKSliceView.cpp
   ctkVTKSliceView.h
   ctkVTKSliceView_p.h
+  ctkVTKTextPropertyWidget.cpp
+  ctkVTKTextPropertyWidget.h
   )
 
 # Headers that should run through moc
@@ -44,10 +46,12 @@ SET(KIT_MOC_SRCS
   ctkVTKRenderView_p.h
   ctkVTKSliceView.h
   ctkVTKSliceView_p.h
+  ctkVTKTextPropertyWidget.h
   )
 
 # UI files
 SET(KIT_UI_FORMS
+  Resources/UI/ctkVTKTextPropertyWidget.ui
 )
 
 # Resources

+ 3 - 0
Libs/Visualization/VTK/Widgets/Plugins/CMakeLists.txt

@@ -17,6 +17,8 @@ SET(PLUGIN_SRCS
   ctkVTKRenderViewPlugin.h
   ctkVTKSliceViewPlugin.cpp
   ctkVTKSliceViewPlugin.h
+  ctkVTKTextPropertyWidgetPlugin.cpp
+  ctkVTKTextPropertyWidgetPlugin.h
   )
 
 # Headers that should run through moc
@@ -25,6 +27,7 @@ SET(PLUGIN_MOC_SRCS
 
   ctkVTKRenderViewPlugin.h
   ctkVTKSliceViewPlugin.h
+  ctkVTKTextPropertyWidgetPlugin.h
   )
 
 # Resources

+ 62 - 0
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKTextPropertyWidgetPlugin.cpp

@@ -0,0 +1,62 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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.
+
+=========================================================================*/
+
+// CTK includes
+#include "ctkVTKTextPropertyWidget.h"
+#include "ctkVTKTextPropertyWidgetPlugin.h"
+
+//-----------------------------------------------------------------------------
+ctkVTKTextPropertyWidgetPlugin::ctkVTKTextPropertyWidgetPlugin(QObject *_parent):QObject(_parent)
+{
+}
+
+//-----------------------------------------------------------------------------
+QWidget *ctkVTKTextPropertyWidgetPlugin::createWidget(QWidget *parentWidget)
+{
+  ctkVTKTextPropertyWidget* newWidget =
+    new ctkVTKTextPropertyWidget(parentWidget);
+  return newWidget;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKTextPropertyWidgetPlugin::domXml() const
+{
+  return "<widget class=\"ctkVTKTextPropertyWidget\" \
+          name=\"VTKTextProperty\">\n"
+          "</widget>\n";
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKTextPropertyWidgetPlugin::includeFile() const
+{
+  return "ctkVTKTextPropertyWidget.h";
+}
+
+//-----------------------------------------------------------------------------
+bool ctkVTKTextPropertyWidgetPlugin::isContainer() const
+{
+  return false;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKTextPropertyWidgetPlugin::name() const
+{
+  return "ctkVTKTextPropertyWidget";
+}

+ 43 - 0
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKTextPropertyWidgetPlugin.h

@@ -0,0 +1,43 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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.
+
+=========================================================================*/
+
+#ifndef __ctkVTKTextPropertyWidgetPlugin_h
+#define __ctkVTKTextPropertyWidgetPlugin_h
+
+// CTK includes
+#include "ctkVTKWidgetsAbstractPlugin.h"
+
+class CTK_VISUALIZATION_VTK_WIDGETS_PLUGINS_EXPORT ctkVTKTextPropertyWidgetPlugin :
+  public QObject,
+  public ctkVTKWidgetsAbstractPlugin
+{
+  Q_OBJECT
+
+public:
+  ctkVTKTextPropertyWidgetPlugin(QObject *_parent = 0);
+
+  QWidget *createWidget(QWidget *_parent);
+  QString domXml() const;
+  QString includeFile() const;
+  bool isContainer() const;
+  QString name() const;
+};
+
+#endif

+ 2 - 1
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKWidgetsPlugins.h

@@ -28,7 +28,7 @@
 #include "CTKVisualizationVTKWidgetsPluginsExport.h"
 #include "ctkVTKRenderViewPlugin.h"
 #include "ctkVTKSliceViewPlugin.h"
-
+#include "ctkVTKTextPropertyWidgetPlugin.h"
 
 /// \class Group the plugins in one library
 class CTK_VISUALIZATION_VTK_WIDGETS_PLUGINS_EXPORT ctkVTKWidgetsPlugins :
@@ -44,6 +44,7 @@ public:
     QList<QDesignerCustomWidgetInterface *> plugins;
     plugins << new ctkVTKRenderViewPlugin;
     plugins << new ctkVTKSliceViewPlugin;
+    plugins << new ctkVTKTextPropertyWidgetPlugin;
     return plugins;
     }
 };

+ 130 - 0
Libs/Visualization/VTK/Widgets/Resources/UI/ctkVTKTextPropertyWidget.ui

@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkVTKTextPropertyWidget</class>
+ <widget class="QWidget" name="ctkVTKTextPropertyWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>271</width>
+    <height>169</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>vtkTextProperty</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <property name="margin">
+    <number>0</number>
+   </property>
+   <item row="0" column="0">
+    <widget class="QLabel" name="TextLabel">
+     <property name="text">
+      <string>Text:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1" colspan="3">
+    <widget class="QLineEdit" name="TextLineEdit"/>
+   </item>
+   <item row="1" column="0">
+    <widget class="QLabel" name="ColorLabel">
+     <property name="text">
+      <string>Color:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1" colspan="3">
+    <widget class="ctkColorPickerButton" name="ColorPickerButton"/>
+   </item>
+   <item row="2" column="0">
+    <widget class="QLabel" name="OpacityLabel">
+     <property name="text">
+      <string>Opacity:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="1" colspan="3">
+    <widget class="ctkDoubleSlider" name="OpacitySlider">
+     <property name="singleStep">
+      <double>0.100000000000000</double>
+     </property>
+     <property name="maximum">
+      <double>1.000000000000000</double>
+     </property>
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0">
+    <widget class="QLabel" name="FontLabel">
+     <property name="text">
+      <string>Font:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="1" colspan="3">
+    <widget class="QComboBox" name="FontComboBox">
+     <item>
+      <property name="text">
+       <string>Arial</string>
+      </property>
+     </item>
+     <item>
+      <property name="text">
+       <string>Courier</string>
+      </property>
+     </item>
+     <item>
+      <property name="text">
+       <string>Times</string>
+      </property>
+     </item>
+    </widget>
+   </item>
+   <item row="4" column="0">
+    <widget class="QLabel" name="StyleLabel">
+     <property name="text">
+      <string>Style:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="1">
+    <widget class="QCheckBox" name="BoldCheckBox">
+     <property name="text">
+      <string>bold</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="2">
+    <widget class="QCheckBox" name="ItalicCheckBox">
+     <property name="text">
+      <string>italic</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="3">
+    <widget class="QCheckBox" name="ShadowCheckBox">
+     <property name="text">
+      <string>shadow</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ctkColorPickerButton</class>
+   <extends>QPushButton</extends>
+   <header>ctkColorPickerButton.h</header>
+  </customwidget>
+  <customwidget>
+   <class>ctkDoubleSlider</class>
+   <extends>QWidget</extends>
+   <header>ctkDoubleSlider.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

+ 236 - 0
Libs/Visualization/VTK/Widgets/ctkVTKTextPropertyWidget.cpp

@@ -0,0 +1,236 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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 includes
+#include <QDebug>
+
+// CTK includes
+#include "ctkVTKTextPropertyWidget.h"
+#include "ui_ctkVTKTextPropertyWidget.h"
+
+// VTK includes
+#include <vtkTextProperty.h>
+
+//-----------------------------------------------------------------------------
+class ctkVTKTextPropertyWidgetPrivate
+  : public ctkPrivate<ctkVTKTextPropertyWidget>
+  , public Ui_ctkVTKTextPropertyWidget
+{
+public:
+  void init();
+  ctkVTKTextPropertyWidgetPrivate();
+  vtkTextProperty* TextProperty;
+};
+
+//-----------------------------------------------------------------------------
+ctkVTKTextPropertyWidgetPrivate::ctkVTKTextPropertyWidgetPrivate()
+{
+  this->TextProperty = 0;
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidgetPrivate::init()
+{
+  CTK_P(ctkVTKTextPropertyWidget);
+  this->setupUi(p);
+  p->setEnabled(this->TextProperty != 0);
+  QObject::connect(this->TextLineEdit, SIGNAL(textChanged(const QString&)),
+                   p, SIGNAL(textChanged(const QString&)));
+  QObject::connect(this->ColorPickerButton, SIGNAL(colorChanged(QColor)),
+                   p, SLOT(setColor(const QColor&)));
+  QObject::connect(this->OpacitySlider, SIGNAL(valueChanged(double)),
+                   p, SLOT(setOpacity(double)));
+  QObject::connect(this->FontComboBox, SIGNAL(currentIndexChanged(const QString&)),
+                   p, SLOT(setFont(const QString&)));
+  QObject::connect(this->BoldCheckBox, SIGNAL(toggled(bool)),
+                   p, SLOT(setBold(bool)));
+  QObject::connect(this->ItalicCheckBox, SIGNAL(toggled(bool)),
+                   p, SLOT(setItalic(bool)));
+  QObject::connect(this->ShadowCheckBox, SIGNAL(toggled(bool)),
+                   p, SLOT(setShadow(bool)));
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKTextPropertyWidget::ctkVTKTextPropertyWidget(QWidget* parentWidget)
+  :QWidget(parentWidget)
+{
+  CTK_INIT_PRIVATE(ctkVTKTextPropertyWidget);
+  CTK_D(ctkVTKTextPropertyWidget);
+  d->init();
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKTextPropertyWidget::ctkVTKTextPropertyWidget(vtkTextProperty* textProperty, QWidget* parentWidget)
+  :QWidget(parentWidget)
+{
+  CTK_INIT_PRIVATE(ctkVTKTextPropertyWidget);
+  CTK_D(ctkVTKTextPropertyWidget);
+  d->init();
+  this->setTextProperty(textProperty);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setTextProperty(vtkTextProperty* textProperty)
+{
+  CTK_D(ctkVTKTextPropertyWidget);
+  qvtkReconnect(d->TextProperty, textProperty, vtkCommand::ModifiedEvent,
+                this, SLOT(updateFromTextProperty()));
+  d->TextProperty = textProperty;
+  this->updateFromTextProperty();
+}
+
+//-----------------------------------------------------------------------------
+vtkTextProperty* ctkVTKTextPropertyWidget::textProperty()const
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  return d->TextProperty;
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::updateFromTextProperty()
+{
+  CTK_D(ctkVTKTextPropertyWidget);
+  this->setEnabled(d->TextProperty != 0);
+  if (d->TextProperty == 0)
+    {
+    return;
+    }
+
+  double* color = d->TextProperty->GetColor();
+  d->ColorPickerButton->setColor(
+    QColor::fromRgbF(color[0],color[1],color[2]));
+  d->OpacitySlider->setValue(d->TextProperty->GetOpacity());
+  d->FontComboBox->setCurrentIndex(
+    d->FontComboBox->findText(d->TextProperty->GetFontFamilyAsString()));
+  d->BoldCheckBox->setChecked(d->TextProperty->GetBold() != 0);
+  d->ItalicCheckBox->setChecked(d->TextProperty->GetItalic() != 0);
+  d->ShadowCheckBox->setChecked(d->TextProperty->GetShadow() != 0);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setTextVisible(bool visible)
+{
+  CTK_D(ctkVTKTextPropertyWidget);
+  d->TextLabel->setVisible(visible);
+  d->TextLineEdit->setVisible(visible);
+}
+
+//-----------------------------------------------------------------------------
+bool ctkVTKTextPropertyWidget::isTextVisible()const
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  Q_ASSERT(d->TextLabel->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this))
+           == d->TextLineEdit->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this)));
+  return d->TextLineEdit->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this));
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setText(const QString& textString)
+{
+  CTK_D(ctkVTKTextPropertyWidget);
+  d->TextLineEdit->setText(textString);
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKTextPropertyWidget::text()const
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  return d->TextLineEdit->text();
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setTextLabel(const QString& label)
+{
+  CTK_D(ctkVTKTextPropertyWidget);
+  d->TextLabel->setText(label);
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKTextPropertyWidget::textLabel()const
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  return d->TextLabel->text();
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setColor(const QColor& color)
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  if (d->TextProperty)
+    {
+    return;
+    }
+  d->TextProperty->SetColor(color.redF(), color.greenF(), color.blueF());
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setOpacity(double opacity)
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  if (d->TextProperty)
+    {
+    return;
+    }
+  d->TextProperty->SetOpacity(opacity);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setFont(const QString& font)
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  if (d->TextProperty)
+    {
+    return;
+    }
+  d->TextProperty->SetFontFamilyAsString(font.toStdString().data());
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setBold(bool enable)
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  if (d->TextProperty)
+    {
+    return;
+    }
+  d->TextProperty->SetBold(enable);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setItalic(bool enable)
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  if (d->TextProperty)
+    {
+    return;
+    }
+  d->TextProperty->SetItalic(enable);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKTextPropertyWidget::setShadow(bool enable)
+{
+  CTK_D(const ctkVTKTextPropertyWidget);
+  if (d->TextProperty)
+    {
+    return;
+    }
+  d->TextProperty->SetShadow(enable);
+}

+ 78 - 0
Libs/Visualization/VTK/Widgets/ctkVTKTextPropertyWidget.h

@@ -0,0 +1,78 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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.
+
+=========================================================================*/
+
+#ifndef __ctkVTKTextPropertyWidget_h
+#define __ctkVTKTextPropertyWidget_h
+
+// Qt includes
+#include <QWidget>
+
+// CTK includes
+#include "ctkPimpl.h"
+#include "ctkVTKObject.h"
+#include "CTKVisualizationVTKWidgetsExport.h"
+
+class ctkVTKTextPropertyWidgetPrivate;
+class vtkTextProperty;
+
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKTextPropertyWidget : public QWidget
+{
+  Q_OBJECT;
+  QVTK_OBJECT;
+  Q_PROPERTY(bool showText READ isTextVisible WRITE setTextVisible);
+  Q_PROPERTY(QString text READ text WRITE setText);
+  Q_PROPERTY(QString textLabel READ textLabel WRITE setTextLabel);
+
+public:
+  /// Constructors
+  ctkVTKTextPropertyWidget(QWidget* parentWidget);
+  ctkVTKTextPropertyWidget(vtkTextProperty* textProperty, QWidget* parentWidget);
+
+  vtkTextProperty* textProperty()const;
+
+  void setTextVisible(bool visible);
+  bool isTextVisible()const;
+
+  QString text()const;
+  QString textLabel()const;
+
+public slots:
+  void setTextProperty(vtkTextProperty* textProperty);
+  void setText(const QString& text);
+  void setTextLabel(const QString& label);
+
+  void setColor(const QColor& color);
+  void setOpacity(double opacity);
+  void setFont(const QString& font);
+  void setBold(bool enable);
+  void setItalic(bool enable);
+  void setShadow(bool enable);
+
+signals:
+  void textChanged(const QString& text);
+
+protected slots:
+  void updateFromTextProperty();
+
+private:
+  CTK_DECLARE_PRIVATE(ctkVTKTextPropertyWidget);
+};
+
+#endif