ctkScreenshotDialogTest1.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.apache.org/licenses/LICENSE-2.0.txt
  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 <QDir>
  17. #include <QTimer>
  18. // CTK includes
  19. #include "ctkScreenshotDialog.h"
  20. // STD includes
  21. #include <cstdlib>
  22. #include <iostream>
  23. //-----------------------------------------------------------------------------
  24. int ctkScreenshotDialogTest1(int argc, char * argv [] )
  25. {
  26. QApplication app(argc, argv);
  27. QWidget topLevel;
  28. ctkScreenshotDialog screenshotDialog;
  29. // Check default values
  30. if (screenshotDialog.widgetToGrab() != 0 ||
  31. screenshotDialog.baseFileName() != "Untitled" ||
  32. !screenshotDialog.directory().isEmpty() ||
  33. screenshotDialog.delay() != 0)
  34. {
  35. std::cerr << "ctkScreenshotDialog, bad default values: "
  36. << screenshotDialog.widgetToGrab() << " "
  37. << qPrintable(screenshotDialog.baseFileName()) << " "
  38. << qPrintable(screenshotDialog.directory()) << " "
  39. << screenshotDialog.delay() << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. screenshotDialog.setWidgetToGrab(&topLevel);
  43. if (screenshotDialog.widgetToGrab() != &topLevel)
  44. {
  45. std::cerr << "ctkScreenshotDialog::setWidgetToGrab failed: "
  46. << screenshotDialog.widgetToGrab() << " instead of "
  47. << &topLevel << std::endl;
  48. return EXIT_FAILURE;
  49. }
  50. screenshotDialog.setBaseFileName("screenshot");
  51. if (screenshotDialog.baseFileName() != "screenshot")
  52. {
  53. std::cerr << "ctkScreenshotDialog::setBaseFileName failed: "
  54. << qPrintable(screenshotDialog.baseFileName()) << " instead of "
  55. << "\"screenshot\"." << std::endl;
  56. return EXIT_FAILURE;
  57. }
  58. screenshotDialog.setDirectory("..");
  59. if (screenshotDialog.directory() != "..")
  60. {
  61. std::cerr << "ctkScreenshotDialog::setDirectory failed: "
  62. << qPrintable(screenshotDialog.directory()) << " instead of "
  63. << ".." << std::endl;
  64. return EXIT_FAILURE;
  65. }
  66. screenshotDialog.setDelay(1);
  67. if (screenshotDialog.delay() != 1)
  68. {
  69. std::cerr << "ctkScreenshotDialog::setDelay failed: "
  70. << screenshotDialog.delay() << " instead of 2." << std::endl;
  71. return EXIT_FAILURE;
  72. }
  73. topLevel.show();
  74. if (argc < 2 || QString(argv[1]) != "-I" )
  75. {
  76. QTimer::singleShot(1400, &app, SLOT(quit()));
  77. }
  78. screenshotDialog.saveScreenshot(); // 1000msecs should be enough
  79. return screenshotDialog.exec();
  80. }