ctkFontButtonTest1.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <QSignalSpy>
  17. #include <QTimer>
  18. #include <QVBoxLayout>
  19. // CTK includes
  20. #include "ctkFontButton.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. int ctkFontButtonTest1(int argc, char * argv [] )
  26. {
  27. QApplication app(argc, argv);
  28. QFont customFont(QFont("Helvetica", 8));
  29. QFont customFont2(QFont("Arial", 12));
  30. QWidget topLevel;
  31. ctkFontButton button;
  32. ctkFontButton button2(customFont);
  33. QVBoxLayout* layout = new QVBoxLayout(&topLevel);
  34. layout->addWidget(&button);
  35. layout->addWidget(&button2);
  36. button.setCurrentFont(customFont);
  37. if (button.currentFont() != customFont)
  38. {
  39. std::cerr << "ctkFontButton::setFont() failed." << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. QSignalSpy spyFontChanged(&button, SIGNAL(currentFontChanged(const QFont&)));
  43. button.setCurrentFont(customFont2);
  44. if ( button.currentFont() != customFont2 ||
  45. spyFontChanged.count() != 1)
  46. {
  47. std::cerr<< "ctkFontButton::setCurrentFont failed" << button.currentFont().toString().toStdString() << std::endl;
  48. return EXIT_FAILURE;
  49. }
  50. topLevel.show();
  51. if (argc < 2 || QString(argv[1]) != "-I" )
  52. {
  53. QTimer::singleShot(200, &app, SLOT(quit()));
  54. }
  55. QTimer::singleShot(100, &button, SLOT(browseFont()));
  56. return app.exec();
  57. }