ctkCursorPixmapWidgetTest1.cpp 4.0 KB

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