ctkCrosshairLabelTest1.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "ctkCrosshairLabel.h"
  19. // STD includes
  20. #include <cstdlib>
  21. #include <iostream>
  22. //-----------------------------------------------------------------------------
  23. int ctkCrosshairLabelTest1(int argc, char * argv [] )
  24. {
  25. QApplication app(argc, argv);
  26. ctkCrosshairLabel crosshair;
  27. // check default values
  28. if (!crosshair.showCrosshair() ||
  29. crosshair.crosshairPen().color()
  30. != crosshair.palette().color(QPalette::Highlight) ||
  31. crosshair.crosshairPen().width() != 0 ||
  32. crosshair.crosshairPen().joinStyle() != Qt::MiterJoin ||
  33. crosshair.crosshairType() != ctkCrosshairLabel::SimpleCrosshair ||
  34. crosshair.marginColor() != crosshair.palette().color(QPalette::Window) ||
  35. crosshair.bullsEyeWidth() != 15)
  36. {
  37. std::cerr << "ctkCrosshairLabel: Wrong default values. " << std::endl
  38. << " " << crosshair.showCrosshair()
  39. << " " << qPrintable(crosshair.crosshairPen().color().name())
  40. << " " << crosshair.crosshairPen().width()
  41. << " " << static_cast<int>(crosshair.crosshairPen().joinStyle())
  42. << " " << crosshair.crosshairType()
  43. << " " << qPrintable(crosshair.marginColor().name())
  44. << " " << crosshair.bullsEyeWidth() << std::endl;
  45. return EXIT_FAILURE;
  46. }
  47. // Show crosshair
  48. crosshair.setShowCrosshair(false);
  49. if (crosshair.showCrosshair())
  50. {
  51. std::cerr << "ctkCrosshairLabel:setShowCrosshair failed. "
  52. << crosshair.showCrosshair() << std::endl;
  53. return EXIT_FAILURE;
  54. }
  55. crosshair.setShowCrosshair(true);
  56. // Crosshair pen
  57. QPen crosshairPen(Qt::yellow);
  58. crosshairPen.setJoinStyle(Qt::MiterJoin);
  59. crosshair.setCrosshairPen(crosshairPen);
  60. if (crosshair.crosshairPen() != crosshairPen)
  61. {
  62. std::cerr << "ctkCrosshairLabel:setCrosshairPen failed. "
  63. << qPrintable(crosshair.crosshairPen().color().name()) << std::endl;
  64. return EXIT_FAILURE;
  65. }
  66. // Crosshair type
  67. crosshair.setCrosshairType(ctkCrosshairLabel::BullsEyeCrosshair);
  68. if (crosshair.crosshairType() != ctkCrosshairLabel::BullsEyeCrosshair)
  69. {
  70. std::cerr << "ctkCrosshairLabel:setCrosshairType failed. "
  71. << crosshair.crosshairType() << std::endl;
  72. return EXIT_FAILURE;
  73. }
  74. // Margin color - invalid input
  75. QColor transparentBlue(Qt::blue);
  76. transparentBlue.setAlphaF(0.25);
  77. QColor origColor = crosshair.marginColor();
  78. crosshair.setMarginColor(QColor());
  79. if (crosshair.marginColor() != origColor)
  80. {
  81. std::cerr << "ctkCrosshairLabel:setMarginColor failed - invalid input. "
  82. << qPrintable(crosshair.marginColor().name()) << std::endl;
  83. return EXIT_FAILURE;
  84. }
  85. // Margin color - should ignore alpha channel
  86. crosshair.setMarginColor(transparentBlue);
  87. if (crosshair.marginColor() != Qt::blue)
  88. {
  89. {
  90. std::cerr << "ctkCrosshairLabel:setMarginColor failed - valid input. "
  91. << qPrintable(crosshair.marginColor().name()) << std::endl;
  92. return EXIT_FAILURE;
  93. }
  94. }
  95. // Bulls eye width
  96. crosshair.setBullsEyeWidth(0);
  97. if (crosshair.bullsEyeWidth() != 0)
  98. {
  99. std::cerr << "ctkCrosshairLabel:setBullsEyeWidth failed. "
  100. << crosshair.bullsEyeWidth() << std::endl;
  101. return EXIT_FAILURE;
  102. }
  103. crosshair.show();
  104. if (argc < 2 || QString(argv[1]) != "-I" )
  105. {
  106. QTimer::singleShot(200, &app, SLOT(quit()));
  107. }
  108. return app.exec();
  109. }