ctkColorDialogTest1.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <QTimer>
  17. // CTK includes
  18. #include "ctkColorDialog.h"
  19. #include "ctkColorPickerButton.h"
  20. #include "ctkTest.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. int ctkColorDialogTest1(int argc, char * argv [] )
  26. {
  27. QApplication app(argc, argv);
  28. ctkColorDialog colorDialog;
  29. ctkColorDialog colorDialog1(Qt::red);
  30. ctkColorPickerButton* extraPanel = new ctkColorPickerButton;
  31. QObject::connect(extraPanel, SIGNAL(colorChanged(QColor)),
  32. &colorDialog, SLOT(setColor(QColor)));
  33. colorDialog.addTab(extraPanel, "Extra");
  34. int index = colorDialog.indexOf(extraPanel);
  35. if (index != 1 ||
  36. extraPanel != colorDialog.widget(index) ||
  37. colorDialog.widget(-1) != 0)
  38. {
  39. std::cerr << "ctkColorDialog::addTab failed:" << index << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. // fake removeTab
  43. colorDialog.removeTab(-1);
  44. index = colorDialog.indexOf(extraPanel);
  45. if (index != 1 ||
  46. colorDialog.widget(1) != extraPanel)
  47. {
  48. std::cerr << "ctkColorDialog::removeTab failed:" << index << std::endl;
  49. return EXIT_FAILURE;
  50. }
  51. // true removeTab
  52. colorDialog.removeTab(index);
  53. index = colorDialog.indexOf(extraPanel);
  54. if (index != -1 ||
  55. // still the default tab
  56. colorDialog.widget(0) == 0 ||
  57. // extra panel doesn't exist anymore
  58. colorDialog.widget(1) != 0)
  59. {
  60. std::cerr << "ctkColorDialog::removeTab failed" << std::endl;
  61. return EXIT_FAILURE;
  62. }
  63. // Add the panel back
  64. colorDialog.addTab(extraPanel, "Extra chooser");
  65. extraPanel->setColor(Qt::darkBlue);
  66. if (colorDialog.currentColor() != Qt::darkBlue)
  67. {
  68. std::cerr << "ctkColorDialog::setColor failed" << std::endl;
  69. return EXIT_FAILURE;
  70. }
  71. colorDialog.open();
  72. // the following is only in interactive mode
  73. if (argc < 2 || QString(argv[1]) != "-I" )
  74. {
  75. #if (QT_VERSION >= 0x50000)
  76. QTest::qWaitForWindowActive(&colorDialog);
  77. #else
  78. QTest::qWaitForWindowShown(&colorDialog);
  79. #endif
  80. colorDialog.accept();
  81. return EXIT_SUCCESS;
  82. }
  83. return app.exec();
  84. }