ctkFlowLayoutTest1.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <QPushButton>
  17. #include <QSignalSpy>
  18. #include <QTimer>
  19. // CTK includes
  20. #include "ctkFlowLayout.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. //-----------------------------------------------------------------------------
  25. int ctkFlowLayoutTest1(int argc, char * argv [] )
  26. {
  27. QApplication app(argc, argv);
  28. QWidget widget1(0);
  29. widget1.setWindowTitle("1) Horizontal");
  30. ctkFlowLayout* flowLayout1 = new ctkFlowLayout(&widget1);
  31. flowLayout1->setAlignItems(false);
  32. flowLayout1->addWidget(new QPushButton("1 text text text text"));
  33. flowLayout1->addWidget(new QPushButton("2 text text text text text text text text"));
  34. flowLayout1->addWidget(new QPushButton("3 text"));
  35. flowLayout1->addWidget(new QPushButton("4 text text text text text text"));
  36. flowLayout1->addWidget(new QPushButton("5 text text"));
  37. flowLayout1->addWidget(new QPushButton("6 text text text text"));
  38. flowLayout1->addWidget(new QPushButton("7 text text text text text text text"));
  39. flowLayout1->addWidget(new QPushButton("8 text text text"));
  40. flowLayout1->addWidget(new QPushButton("9"));
  41. flowLayout1->addWidget(new QPushButton("10 text text text text text text text text text"));
  42. widget1.setLayout(flowLayout1);
  43. widget1.show();
  44. QWidget widget1justified(0);
  45. widget1justified.setWindowTitle("1) Horizontal, justified");
  46. ctkFlowLayout* flowLayout1justified = new ctkFlowLayout(&widget1justified);
  47. flowLayout1justified->setAlignItems(false);
  48. flowLayout1justified->setAlignment(Qt::AlignJustify);
  49. flowLayout1justified->addWidget(new QPushButton("1 text text text text"));
  50. flowLayout1justified->addWidget(new QPushButton("2 text text text text text text text text"));
  51. flowLayout1justified->addWidget(new QPushButton("3 text"));
  52. flowLayout1justified->addWidget(new QPushButton("4 text text text text text text"));
  53. flowLayout1justified->addWidget(new QPushButton("5 text text"));
  54. flowLayout1justified->addWidget(new QPushButton("6 text text text text"));
  55. flowLayout1justified->addWidget(new QPushButton("7 text text text text text text text"));
  56. flowLayout1justified->addWidget(new QPushButton("8 text text text"));
  57. flowLayout1justified->addWidget(new QPushButton("9"));
  58. flowLayout1justified->addWidget(new QPushButton("10 text text text text text text text text text"));
  59. widget1justified.setLayout(flowLayout1justified);
  60. widget1justified.show();
  61. QWidget widget2(0);
  62. widget2.setWindowTitle("2) Horizontal");
  63. ctkFlowLayout* flowLayout2 = new ctkFlowLayout;
  64. flowLayout2->addWidget(new QPushButton("one"));
  65. flowLayout2->addWidget(new QPushButton("two"));
  66. flowLayout2->addWidget(new QPushButton("three"));
  67. flowLayout2->addWidget(new QPushButton("four"));
  68. flowLayout2->addWidget(new QPushButton("five"));
  69. flowLayout2->addWidget(new QPushButton("six"));
  70. flowLayout2->addWidget(new QPushButton("seven"));
  71. //flowLayout2->setHorizontalSpacing(20);
  72. widget2.setLayout(flowLayout2);
  73. widget2.show();
  74. QWidget widget3(0);
  75. widget3.setWindowTitle("3) Vertical");
  76. ctkFlowLayout* flowLayout3 = new ctkFlowLayout(Qt::Vertical);
  77. flowLayout3->addWidget(new QPushButton("one"));
  78. flowLayout3->addWidget(new QPushButton("two"));
  79. flowLayout3->addWidget(new QPushButton("three"));
  80. flowLayout3->addWidget(new QPushButton("four"));
  81. flowLayout3->addWidget(new QPushButton("five"));
  82. flowLayout3->addWidget(new QPushButton("six"));
  83. flowLayout3->addWidget(new QPushButton("seven"));
  84. flowLayout3->setHorizontalSpacing(20);
  85. widget3.setLayout(flowLayout3);
  86. widget3.show();
  87. QWidget widget4(0);
  88. widget4.setWindowTitle("4) Horizontal -> Vertical");
  89. ctkFlowLayout* flowLayout4 = new ctkFlowLayout();
  90. flowLayout4->addWidget(new QPushButton("one"));
  91. flowLayout4->addWidget(new QPushButton("two"));
  92. flowLayout4->addWidget(new QPushButton("three"));
  93. flowLayout4->addWidget(new QPushButton("four"));
  94. flowLayout4->addWidget(new QPushButton("five"));
  95. flowLayout4->addWidget(new QPushButton("six"));
  96. flowLayout4->addWidget(new QPushButton("seven"));
  97. widget4.setLayout(flowLayout4);
  98. widget4.show();
  99. flowLayout4->setOrientation(Qt::Vertical);
  100. flowLayout4->setVerticalSpacing(0);
  101. flowLayout4->setHorizontalSpacing(0);
  102. if (argc < 2 || QString(argv[1]) != "-I")
  103. {
  104. QTimer::singleShot(200, &app, SLOT(quit()));
  105. }
  106. return app.exec();
  107. }