ctkVTKTextPropertyWidgetTest1.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.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 <QApplication>
  16. #include <QTimer>
  17. // CTK includes
  18. #include "ctkVTKTextPropertyWidget.h"
  19. // VTK includes
  20. #include <vtkTextProperty.h>
  21. // STD includes
  22. #include <iostream>
  23. //-----------------------------------------------------------------------------
  24. int ctkVTKTextPropertyWidgetTest1(int argc, char * argv [] )
  25. {
  26. QApplication app(argc, argv);
  27. ctkVTKTextPropertyWidget textPropertyWidget(0);
  28. if (textPropertyWidget.isEnabled())
  29. {
  30. std::cerr << "No vtkTextProperty provided, should be disabled."
  31. << std::endl;
  32. return EXIT_FAILURE;
  33. }
  34. vtkTextProperty* textProperty = vtkTextProperty::New();
  35. double color[3];
  36. textProperty->GetColor(color);
  37. double opacity = textProperty->GetOpacity();
  38. QString fontFamily = textProperty->GetFontFamilyAsString();
  39. bool bold = textProperty->GetBold();
  40. bool italic = textProperty->GetItalic();
  41. bool shadow = textProperty->GetShadow();
  42. textPropertyWidget.setTextProperty(textProperty);
  43. //textProperty->Delete();
  44. if (textPropertyWidget.textProperty() != textProperty)
  45. {
  46. std::cerr << "ctkVTKTextPropertyWidget::setTextProperty() failed."
  47. << textPropertyWidget.textProperty() << std::endl;
  48. return EXIT_FAILURE;
  49. }
  50. if (textPropertyWidget.color() != QColor::fromRgbF(color[0],color[1],color[2]))
  51. {
  52. std::cerr << "Wrong color" << std::endl;
  53. return EXIT_FAILURE;
  54. }
  55. if (textPropertyWidget.opacity() != opacity)
  56. {
  57. std::cerr << "Wrong opacity" << textPropertyWidget.opacity() << std::endl;
  58. return EXIT_FAILURE;
  59. }
  60. if (textPropertyWidget.font() != fontFamily)
  61. {
  62. std::cerr << "Wrong font" << textPropertyWidget.font().toStdString() << std::endl;
  63. return EXIT_FAILURE;
  64. }
  65. if (textPropertyWidget.isBold() != bold)
  66. {
  67. std::cerr << "Wrong bold" << textPropertyWidget.isBold() << std::endl;
  68. return EXIT_FAILURE;
  69. }
  70. if (textPropertyWidget.isItalic() != italic)
  71. {
  72. std::cerr << "Wrong italic" << textPropertyWidget.isItalic() << std::endl;
  73. return EXIT_FAILURE;
  74. }
  75. if (textPropertyWidget.hasShadow() != shadow)
  76. {
  77. std::cerr << "Wrong shadow" << textPropertyWidget.hasShadow() << std::endl;
  78. return EXIT_FAILURE;
  79. }
  80. textProperty->SetColor(0., 0.5, 1.);
  81. if (textPropertyWidget.color() != QColor::fromRgbF(0., 0.5, 1.))
  82. {
  83. std::cerr << "vtkTextProperty::SetColor() failed" << std::endl;
  84. return EXIT_FAILURE;
  85. }
  86. textPropertyWidget.setColor(QColor::fromRgbF(0.333, 0.666, 0.999));
  87. textProperty->GetColor(color);
  88. if (qFuzzyCompare(color[0], 0.333) ||
  89. qFuzzyCompare(color[1], 0.666) ||
  90. qFuzzyCompare(color[2], 0.999))
  91. {
  92. std::cerr << "ctkVTKTextPropertyWidget::setColor() failed" << std::endl;
  93. return EXIT_FAILURE;
  94. }
  95. textProperty->SetOpacity(0.2);
  96. if (textPropertyWidget.opacity() != 0.2)
  97. {
  98. std::cerr << "vtkTextProperty::SetOpacity() failed" << std::endl;
  99. return EXIT_FAILURE;
  100. }
  101. textPropertyWidget.setOpacity(0.6);
  102. if (textProperty->GetOpacity() != 0.6)
  103. {
  104. std::cerr << "ctkVTKTextPropertyWidget::setOpacity() failed" << std::endl;
  105. return EXIT_FAILURE;
  106. }
  107. textProperty->SetFontFamilyToCourier();
  108. if (textPropertyWidget.font() != "Courier")
  109. {
  110. std::cerr << "vtkTextProperty::SetFontFamily() failed" << std::endl;
  111. return EXIT_FAILURE;
  112. }
  113. textPropertyWidget.setFont("Arial");
  114. if (QString(textProperty->GetFontFamilyAsString()) != "Arial")
  115. {
  116. std::cerr << "ctkVTKTextPropertyWidget::setFont() failed" << std::endl;
  117. return EXIT_FAILURE;
  118. }
  119. textProperty->SetBold(!bold);
  120. if (textPropertyWidget.isBold() == bold)
  121. {
  122. std::cerr << "vtkTextProperty::SetBold() failed" << std::endl;
  123. return EXIT_FAILURE;
  124. }
  125. textPropertyWidget.setBold(bold);
  126. if ((textProperty->GetBold() != 0) != bold)
  127. {
  128. std::cerr << "ctkVTKTextPropertyWidget::setBold() failed" << std::endl;
  129. return EXIT_FAILURE;
  130. }
  131. textProperty->SetItalic(!italic);
  132. if (textPropertyWidget.isItalic() == italic)
  133. {
  134. std::cerr << "vtkTextProperty::SetItalic() failed" << std::endl;
  135. return EXIT_FAILURE;
  136. }
  137. textPropertyWidget.setItalic(italic);
  138. if ((textProperty->GetItalic() != 0) != italic)
  139. {
  140. std::cerr << "ctkVTKTextPropertyWidget::setItalic() failed" << std::endl;
  141. return EXIT_FAILURE;
  142. }
  143. textProperty->SetShadow(!shadow);
  144. if (textPropertyWidget.hasShadow() == shadow)
  145. {
  146. std::cerr << "vtkTextProperty::SetShadow() failed" << std::endl;
  147. return EXIT_FAILURE;
  148. }
  149. textPropertyWidget.setShadow(shadow);
  150. if ((textProperty->GetShadow() != 0) != shadow)
  151. {
  152. std::cerr << "ctkVTKTextPropertyWidget::setShadow() failed" << std::endl;
  153. return EXIT_FAILURE;
  154. }
  155. textPropertyWidget.setText("My custom VTK text");
  156. if (textPropertyWidget.text() != "My custom VTK text")
  157. {
  158. std::cerr << "ctkVTKTextPropertyWidget::setText() failed"
  159. << textPropertyWidget.text().toStdString() << std::endl;
  160. return EXIT_FAILURE;
  161. }
  162. textPropertyWidget.setTextLabel("My text:");
  163. if (textPropertyWidget.textLabel() != "My text:")
  164. {
  165. std::cerr << "ctkVTKTextPropertyWidget::setTextLabel() failed"
  166. << textPropertyWidget.textLabel().toStdString() << std::endl;
  167. return EXIT_FAILURE;
  168. }
  169. textPropertyWidget.show();
  170. if (argc < 2 || QString(argv[1]) != "-I" )
  171. {
  172. QTimer::singleShot(200, &app, SLOT(quit()));
  173. }
  174. return app.exec();
  175. }