ctkCheckablePushButtonTest1.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <QCheckBox>
  17. #include <QVBoxLayout>
  18. #include <QStyle>
  19. #include <QTimer>
  20. // CTK includes
  21. #include "ctkCheckablePushButton.h"
  22. // STD includes
  23. #include <cstdlib>
  24. #include <iostream>
  25. //-----------------------------------------------------------------------------
  26. int ctkCheckablePushButtonTest1(int argc, char * argv [] )
  27. {
  28. QApplication app(argc, argv);
  29. QWidget topLevel;
  30. ctkCheckablePushButton button1(QObject::tr("My very long text on button"));
  31. ctkCheckablePushButton button2(QObject::tr("Button2"));
  32. ctkCheckablePushButton button3(QObject::tr("Button3"));
  33. ctkCheckablePushButton button4(QObject::tr("Button4"));
  34. ctkCheckablePushButton button5(QObject::tr("Button5"));
  35. ctkCheckablePushButton button6(QObject::tr("Button6"));
  36. ctkCheckablePushButton button7(QObject::tr("Checkable PushButton"));
  37. QVBoxLayout *layout= new QVBoxLayout;
  38. layout->addWidget(&button1);
  39. layout->addWidget(&button2);
  40. layout->addWidget(&button3);
  41. layout->addWidget(&button4);
  42. layout->addWidget(&button5);
  43. layout->addWidget(&button6);
  44. layout->addWidget(&button7);
  45. topLevel.setLayout(layout);
  46. topLevel.show();
  47. button1.setButtonTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
  48. if (button1.buttonTextAlignment() != (Qt::AlignRight | Qt::AlignVCenter))
  49. {
  50. std::cerr << "ctkCheckablePushButton::setButtonTextAlignment failed."
  51. << std::endl;
  52. return EXIT_FAILURE;
  53. }
  54. button2.setIndicatorAlignment(Qt::AlignRight);
  55. if (button2.indicatorAlignment() != Qt::AlignRight)
  56. {
  57. std::cerr << "ctkCheckablePushButton::setIndicatorAlignment failed."
  58. << std::endl;
  59. return EXIT_FAILURE;
  60. }
  61. button3.setButtonTextAlignment(Qt::AlignCenter);
  62. button3.setIndicatorAlignment(Qt::AlignCenter);
  63. button3.setCheckable(true);
  64. button4.setCheckable(true);
  65. button4.toggle();
  66. button5.setButtonTextAlignment(Qt::AlignCenter);
  67. button5.setIndicatorAlignment(Qt::AlignRight);
  68. button6.setIndicatorAlignment(Qt::AlignTop);
  69. button7.setButtonTextAlignment(Qt::AlignCenter);
  70. button7.setIndicatorAlignment(Qt::AlignLeft);
  71. if (argc < 2 || QString(argv[1]) != "-I" )
  72. {
  73. QTimer::singleShot(200, &app, SLOT(quit()));
  74. }
  75. return app.exec();
  76. }