ctkCursorPixmapWidgetTest1.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. // CTK includes
  17. #include "ctkCursorPixmapWidget.h"
  18. // STD includes
  19. #include <cstdlib>
  20. #include <iostream>
  21. //-----------------------------------------------------------------------------
  22. int ctkCursorPixmapWidgetTest1(int argc, char * argv [] )
  23. {
  24. QApplication app(argc, argv);
  25. ctkCursorPixmapWidget cursor;
  26. // check default values
  27. if (!cursor.showCursor() ||
  28. cursor.cursorColor() != cursor.palette().color(QPalette::Highlight) ||
  29. cursor.cursorType() != ctkCursorPixmapWidget::CrossHairCursor ||
  30. cursor.marginColor() != cursor.palette().color(QPalette::Window) ||
  31. cursor.bullsEyeWidth() != 15)
  32. {
  33. std::cerr << "ctkCursorPixmapWidget: Wrong default values. " << std::endl
  34. << " " << cursor.showCursor()
  35. << " " << qPrintable(cursor.cursorColor().name())
  36. << " " << cursor.cursorType()
  37. << " " << qPrintable(cursor.marginColor().name())
  38. << " " << cursor.bullsEyeWidth() << std::endl;
  39. return EXIT_FAILURE;
  40. }
  41. // Show cursor
  42. cursor.setShowCursor(false);
  43. if (cursor.showCursor())
  44. {
  45. std::cerr << "ctkCursorPixmapWidget:setShowCursor failed. "
  46. << cursor.showCursor() << std::endl;
  47. return EXIT_FAILURE;
  48. }
  49. cursor.setShowCursor(true);
  50. // Cursor color
  51. QColor transparentBlue(Qt::blue);
  52. transparentBlue.setAlphaF(0.25);
  53. cursor.setCursorColor(transparentBlue);
  54. if (cursor.cursorColor() != transparentBlue)
  55. {
  56. std::cerr << "ctkCursorPixmapWidget:setCursorColor failed. "
  57. << qPrintable(cursor.cursorColor().name()) << std::endl;
  58. return EXIT_FAILURE;
  59. }
  60. // Cursor type
  61. cursor.setCursorType(ctkCursorPixmapWidget::BullsEyeCursor);
  62. if (cursor.cursorType() != ctkCursorPixmapWidget::BullsEyeCursor)
  63. {
  64. std::cerr << "ctkCursorPixmapWidget:setCursorType failed. "
  65. << cursor.cursorType() << std::endl;
  66. return EXIT_FAILURE;
  67. }
  68. // Margin color - invalid input
  69. QColor origColor = cursor.marginColor();
  70. cursor.setMarginColor(QColor());
  71. if (cursor.marginColor() != origColor)
  72. {
  73. std::cerr << "ctkCursorPixmapWidget:setMarginColor failed - invalid input. "
  74. << qPrintable(cursor.marginColor().name()) << std::endl;
  75. return EXIT_FAILURE;
  76. }
  77. // Margin color - valid input
  78. cursor.setMarginColor(transparentBlue);
  79. if (cursor.marginColor() != transparentBlue)
  80. {
  81. {
  82. std::cerr << "ctkCursorPixmapWidget:setMarginColor failed - valid input. "
  83. << qPrintable(cursor.marginColor().name()) << std::endl;
  84. return EXIT_FAILURE;
  85. }
  86. }
  87. // Bulls eye width
  88. cursor.setBullsEyeWidth(0);
  89. if (cursor.bullsEyeWidth() != 0)
  90. {
  91. std::cerr << "ctkCursorPixmapWidget:setBullsEyeWidth failed. "
  92. << cursor.bullsEyeWidth() << std::endl;
  93. return EXIT_FAILURE;
  94. }
  95. return EXIT_SUCCESS;
  96. }