ctkCollapsibleButtonTest1.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 <QDoubleSpinBox>
  17. #include <QPushButton>
  18. #include <QVBoxLayout>
  19. #include <QStyle>
  20. #include <QTimer>
  21. // CTK includes
  22. #include "ctkCollapsibleButton.h"
  23. // STD includes
  24. #include <cstdlib>
  25. #include <iostream>
  26. //-----------------------------------------------------------------------------
  27. int ctkCollapsibleButtonTest1(int argc, char * argv [] )
  28. {
  29. QApplication app(argc, argv);
  30. ctkCollapsibleButton collapsibleButton;
  31. collapsibleButton.setText("top button");
  32. QDoubleSpinBox *spinBox = new QDoubleSpinBox;
  33. QPushButton * button= new QPushButton(QObject::tr("Button"));
  34. ctkCollapsibleButton *collapsibleButton2 = new ctkCollapsibleButton(QObject::tr("Nested Collapsible Button"));
  35. ctkCollapsibleButton *collapsibleButton3 = new ctkCollapsibleButton(QObject::tr("CollapsibleButton"));
  36. // ctkCollapsibleButton::icon is not activated
  37. collapsibleButton3->setIcon(collapsibleButton3->style()->standardIcon(QStyle::SP_FileDialogDetailedView));
  38. QPushButton * button2 = new QPushButton(QObject::tr("Nested PushButton"));
  39. QVBoxLayout *nestedBox = new QVBoxLayout;
  40. nestedBox->addWidget(button2);
  41. collapsibleButton3->setLayout(nestedBox);
  42. QVBoxLayout *vbox = new QVBoxLayout;
  43. vbox->addWidget(spinBox);
  44. vbox->addWidget(button);
  45. vbox->addWidget(collapsibleButton2);
  46. vbox->addWidget(collapsibleButton3);
  47. collapsibleButton.setLayout(vbox);
  48. collapsibleButton.show();
  49. if (collapsibleButton.collapsed())
  50. {
  51. std::cerr<< "Wrong default collapse state." << std::endl;
  52. return EXIT_FAILURE;
  53. }
  54. collapsibleButton.setCollapsed(true);
  55. if (collapsibleButton.collapsed() != true)
  56. {
  57. std::cerr<< "ctkCollapsibleButton::setCollapsed failed." << std::endl;
  58. return EXIT_FAILURE;
  59. }
  60. if (spinBox->isVisible())
  61. {
  62. std::cerr << "ctkCollapsibleButton::setChecked failed. "
  63. << "Children are visible" << std::endl;
  64. return EXIT_FAILURE;
  65. }
  66. collapsibleButton.setChecked(true);
  67. if (collapsibleButton.collapsed() != false)
  68. {
  69. std::cerr<< "ctkCollapsibleButton::setChecked failed." << std::endl;
  70. return EXIT_FAILURE;
  71. }
  72. collapsibleButton2->setCollapsedHeight(40);
  73. if (collapsibleButton2->collapsedHeight() != 40)
  74. {
  75. std::cerr << "ctkCollapsibleButton::setCollapsedHeight failed."
  76. << std::endl;
  77. return EXIT_FAILURE;
  78. }
  79. collapsibleButton.setContentsFrameShape(QFrame::Box);
  80. collapsibleButton2->setContentsFrameShape(QFrame::Box);
  81. if (collapsibleButton2->contentsFrameShape() != QFrame::Box)
  82. {
  83. std::cerr << "ctkCollapsibleButton::setContentsFrameShape failed."
  84. << std::endl;
  85. return EXIT_FAILURE;
  86. }
  87. collapsibleButton2->setContentsFrameShadow(QFrame::Raised);
  88. if (collapsibleButton2->contentsFrameShadow() != QFrame::Raised)
  89. {
  90. std::cerr << "ctkCollapsibleButton::setContentsFrameShadow failed."
  91. << std::endl;
  92. return EXIT_FAILURE;
  93. }
  94. collapsibleButton2->setContentsLineWidth(2);
  95. if (collapsibleButton2->contentsLineWidth() != 2)
  96. {
  97. std::cerr << "ctkCollapsibleButton::setContentsLineWidth failed."
  98. << std::endl;
  99. return EXIT_FAILURE;
  100. }
  101. collapsibleButton2->setContentsMidLineWidth(3);
  102. if (collapsibleButton2->contentsMidLineWidth() != 3)
  103. {
  104. std::cerr << "ctkCollapsibleButton::setContentsLineWidth failed."
  105. << std::endl;
  106. return EXIT_FAILURE;
  107. }
  108. collapsibleButton.setButtonTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
  109. if (collapsibleButton.buttonTextAlignment() != (Qt::AlignRight | Qt::AlignVCenter))
  110. {
  111. std::cerr << "ctkCollapsibleButton::setButtonTextAlignment failed."
  112. << std::endl;
  113. return EXIT_FAILURE;
  114. }
  115. collapsibleButton2->setIndicatorAlignment(Qt::AlignRight);
  116. if (collapsibleButton2->indicatorAlignment() != Qt::AlignRight)
  117. {
  118. std::cerr << "ctkCollapsibleButton::setIndicatorAlignment failed."
  119. << std::endl;
  120. return EXIT_FAILURE;
  121. }
  122. if (argc < 2 || QString(argv[1]) != "-I" )
  123. {
  124. QTimer::singleShot(200, &app, SLOT(quit()));
  125. }
  126. return app.exec();
  127. }