ctkDirectoryButtonTest1.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <QStyle>
  17. #include <QTimer>
  18. #include <QVBoxLayout>
  19. // CTK includes
  20. #include "ctkDirectoryButton.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. int ctkDirectoryButtonTest1(int argc, char * argv [] )
  26. {
  27. QApplication app(argc, argv);
  28. QWidget topLevel;
  29. ctkDirectoryButton button;
  30. QIcon defaultIcon = button.style()->standardIcon(QStyle::SP_DirIcon);
  31. QIcon icon = button.style()->standardIcon(QStyle::SP_MessageBoxQuestion);
  32. QIcon icon2 = button.style()->standardIcon(QStyle::SP_DesktopIcon);
  33. ctkDirectoryButton button2(".");
  34. ctkDirectoryButton button3(icon, "..");
  35. QVBoxLayout* layout = new QVBoxLayout;
  36. layout->addWidget(&button);
  37. layout->addWidget(&button2);
  38. layout->addWidget(&button3);
  39. topLevel.setLayout(layout);
  40. button.setCaption("Select a directory");
  41. if (button.caption() != "Select a directory")
  42. {
  43. std::cerr << "ctkDirectoryButton::setCaption() failed." << std::endl;
  44. return EXIT_FAILURE;
  45. }
  46. if (button.icon().pixmap(20).toImage() !=
  47. defaultIcon.pixmap(20).toImage())
  48. {
  49. std::cerr << "ctkDirectoryButton::icon() failed." << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. button3.setIcon(icon2);
  53. if (button3.icon().pixmap(20).toImage() !=
  54. icon2.pixmap(20).toImage())
  55. {
  56. std::cerr << "ctkDirectoryButton::setIcon() failed." << std::endl;
  57. return EXIT_FAILURE;
  58. }
  59. #ifdef USE_QFILEDIALOG_OPTIONS
  60. button.setOptions(QFileDialog::ShowDirsOnly | QFileDialog::ReadOnly);
  61. if (button.options() != (QFileDialog::ShowDirsOnly |
  62. QFileDialog::ReadOnly))
  63. #else
  64. button.setOptions(ctkDirectoryButton::ShowDirsOnly |
  65. ctkDirectoryButton::ReadOnly);
  66. if (button.options() != (ctkDirectoryButton::ShowDirsOnly |
  67. ctkDirectoryButton::ReadOnly))
  68. #endif
  69. {
  70. std::cerr<< "ctkDirectoryButton::setOptions failed" << std::endl;
  71. return EXIT_FAILURE;
  72. }
  73. button.setDirectory(QDir::home().absolutePath());
  74. if ( QDir(button.directory()) != QDir::home())
  75. {
  76. std::cerr<< "ctkDirectoryButton::setDirectory failed" << button.directory().toStdString() << std::endl;
  77. return EXIT_FAILURE;
  78. }
  79. //button.browse();
  80. topLevel.show();
  81. if (argc < 2 || QString(argv[1]) != "-I" )
  82. {
  83. QTimer::singleShot(200, &app, SLOT(quit()));
  84. }
  85. return app.exec();
  86. }