ctkVTKTextPropertyWidget.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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.commontk.org/LICENSE
  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. // Qt includes
  15. #include <QDebug>
  16. // CTK includes
  17. #include "ctkVTKTextPropertyWidget.h"
  18. #include "ui_ctkVTKTextPropertyWidget.h"
  19. // VTK includes
  20. #include <vtkTextProperty.h>
  21. //-----------------------------------------------------------------------------
  22. class ctkVTKTextPropertyWidgetPrivate
  23. : public ctkPrivate<ctkVTKTextPropertyWidget>
  24. , public Ui_ctkVTKTextPropertyWidget
  25. {
  26. public:
  27. void init();
  28. ctkVTKTextPropertyWidgetPrivate();
  29. vtkTextProperty* TextProperty;
  30. };
  31. //-----------------------------------------------------------------------------
  32. ctkVTKTextPropertyWidgetPrivate::ctkVTKTextPropertyWidgetPrivate()
  33. {
  34. this->TextProperty = 0;
  35. }
  36. //-----------------------------------------------------------------------------
  37. void ctkVTKTextPropertyWidgetPrivate::init()
  38. {
  39. CTK_P(ctkVTKTextPropertyWidget);
  40. this->setupUi(p);
  41. p->setEnabled(this->TextProperty != 0);
  42. QObject::connect(this->TextLineEdit, SIGNAL(textChanged(const QString&)),
  43. p, SIGNAL(textChanged(const QString&)));
  44. QObject::connect(this->ColorPickerButton, SIGNAL(colorChanged(QColor)),
  45. p, SLOT(setColor(const QColor&)));
  46. QObject::connect(this->OpacitySlider, SIGNAL(valueChanged(double)),
  47. p, SLOT(setOpacity(double)));
  48. QObject::connect(this->FontComboBox, SIGNAL(currentIndexChanged(const QString&)),
  49. p, SLOT(setFont(const QString&)));
  50. QObject::connect(this->BoldCheckBox, SIGNAL(toggled(bool)),
  51. p, SLOT(setBold(bool)));
  52. QObject::connect(this->ItalicCheckBox, SIGNAL(toggled(bool)),
  53. p, SLOT(setItalic(bool)));
  54. QObject::connect(this->ShadowCheckBox, SIGNAL(toggled(bool)),
  55. p, SLOT(setShadow(bool)));
  56. }
  57. //-----------------------------------------------------------------------------
  58. ctkVTKTextPropertyWidget::ctkVTKTextPropertyWidget(QWidget* parentWidget)
  59. :QWidget(parentWidget)
  60. {
  61. CTK_INIT_PRIVATE(ctkVTKTextPropertyWidget);
  62. CTK_D(ctkVTKTextPropertyWidget);
  63. d->init();
  64. }
  65. //-----------------------------------------------------------------------------
  66. ctkVTKTextPropertyWidget::ctkVTKTextPropertyWidget(vtkTextProperty* textProperty, QWidget* parentWidget)
  67. :QWidget(parentWidget)
  68. {
  69. CTK_INIT_PRIVATE(ctkVTKTextPropertyWidget);
  70. CTK_D(ctkVTKTextPropertyWidget);
  71. d->init();
  72. this->setTextProperty(textProperty);
  73. }
  74. //-----------------------------------------------------------------------------
  75. void ctkVTKTextPropertyWidget::setTextProperty(vtkTextProperty* textProperty)
  76. {
  77. CTK_D(ctkVTKTextPropertyWidget);
  78. qvtkReconnect(d->TextProperty, textProperty, vtkCommand::ModifiedEvent,
  79. this, SLOT(updateFromTextProperty()));
  80. d->TextProperty = textProperty;
  81. this->updateFromTextProperty();
  82. }
  83. //-----------------------------------------------------------------------------
  84. vtkTextProperty* ctkVTKTextPropertyWidget::textProperty()const
  85. {
  86. CTK_D(const ctkVTKTextPropertyWidget);
  87. return d->TextProperty;
  88. }
  89. //-----------------------------------------------------------------------------
  90. void ctkVTKTextPropertyWidget::updateFromTextProperty()
  91. {
  92. CTK_D(ctkVTKTextPropertyWidget);
  93. this->setEnabled(d->TextProperty != 0);
  94. if (d->TextProperty == 0)
  95. {
  96. return;
  97. }
  98. double* color = d->TextProperty->GetColor();
  99. d->ColorPickerButton->setColor(
  100. QColor::fromRgbF(color[0],color[1],color[2]));
  101. d->OpacitySlider->setValue(d->TextProperty->GetOpacity());
  102. d->FontComboBox->setCurrentIndex(
  103. d->FontComboBox->findText(d->TextProperty->GetFontFamilyAsString()));
  104. d->BoldCheckBox->setChecked(d->TextProperty->GetBold() != 0);
  105. d->ItalicCheckBox->setChecked(d->TextProperty->GetItalic() != 0);
  106. d->ShadowCheckBox->setChecked(d->TextProperty->GetShadow() != 0);
  107. }
  108. //-----------------------------------------------------------------------------
  109. void ctkVTKTextPropertyWidget::setTextVisible(bool visible)
  110. {
  111. CTK_D(ctkVTKTextPropertyWidget);
  112. d->TextLabel->setVisible(visible);
  113. d->TextLineEdit->setVisible(visible);
  114. }
  115. //-----------------------------------------------------------------------------
  116. bool ctkVTKTextPropertyWidget::isTextVisible()const
  117. {
  118. CTK_D(const ctkVTKTextPropertyWidget);
  119. Q_ASSERT(d->TextLabel->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this))
  120. == d->TextLineEdit->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this)));
  121. return d->TextLineEdit->isVisibleTo(const_cast<ctkVTKTextPropertyWidget*>(this));
  122. }
  123. //-----------------------------------------------------------------------------
  124. void ctkVTKTextPropertyWidget::setText(const QString& textString)
  125. {
  126. CTK_D(ctkVTKTextPropertyWidget);
  127. d->TextLineEdit->setText(textString);
  128. }
  129. //-----------------------------------------------------------------------------
  130. QString ctkVTKTextPropertyWidget::text()const
  131. {
  132. CTK_D(const ctkVTKTextPropertyWidget);
  133. return d->TextLineEdit->text();
  134. }
  135. //-----------------------------------------------------------------------------
  136. void ctkVTKTextPropertyWidget::setTextLabel(const QString& label)
  137. {
  138. CTK_D(ctkVTKTextPropertyWidget);
  139. d->TextLabel->setText(label);
  140. }
  141. //-----------------------------------------------------------------------------
  142. QString ctkVTKTextPropertyWidget::textLabel()const
  143. {
  144. CTK_D(const ctkVTKTextPropertyWidget);
  145. return d->TextLabel->text();
  146. }
  147. //-----------------------------------------------------------------------------
  148. void ctkVTKTextPropertyWidget::setColor(const QColor& color)
  149. {
  150. CTK_D(const ctkVTKTextPropertyWidget);
  151. if (d->TextProperty)
  152. {
  153. return;
  154. }
  155. d->TextProperty->SetColor(color.redF(), color.greenF(), color.blueF());
  156. }
  157. //-----------------------------------------------------------------------------
  158. void ctkVTKTextPropertyWidget::setOpacity(double opacity)
  159. {
  160. CTK_D(const ctkVTKTextPropertyWidget);
  161. if (d->TextProperty)
  162. {
  163. return;
  164. }
  165. d->TextProperty->SetOpacity(opacity);
  166. }
  167. //-----------------------------------------------------------------------------
  168. void ctkVTKTextPropertyWidget::setFont(const QString& font)
  169. {
  170. CTK_D(const ctkVTKTextPropertyWidget);
  171. if (d->TextProperty)
  172. {
  173. return;
  174. }
  175. d->TextProperty->SetFontFamilyAsString(font.toStdString().data());
  176. }
  177. //-----------------------------------------------------------------------------
  178. void ctkVTKTextPropertyWidget::setBold(bool enable)
  179. {
  180. CTK_D(const ctkVTKTextPropertyWidget);
  181. if (d->TextProperty)
  182. {
  183. return;
  184. }
  185. d->TextProperty->SetBold(enable);
  186. }
  187. //-----------------------------------------------------------------------------
  188. void ctkVTKTextPropertyWidget::setItalic(bool enable)
  189. {
  190. CTK_D(const ctkVTKTextPropertyWidget);
  191. if (d->TextProperty)
  192. {
  193. return;
  194. }
  195. d->TextProperty->SetItalic(enable);
  196. }
  197. //-----------------------------------------------------------------------------
  198. void ctkVTKTextPropertyWidget::setShadow(bool enable)
  199. {
  200. CTK_D(const ctkVTKTextPropertyWidget);
  201. if (d->TextProperty)
  202. {
  203. return;
  204. }
  205. d->TextProperty->SetShadow(enable);
  206. }