ctkFittedTextBrowserTest1.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <QTimer>
  18. #include <QVBoxLayout>
  19. // CTK includes
  20. #include "ctkFittedTextBrowser.h"
  21. // STD includes
  22. #include <cstdlib>
  23. #include <iostream>
  24. int ctkFittedTextBrowserTest1(int argc, char * argv [] )
  25. {
  26. QApplication app(argc, argv);
  27. QWidget widget;
  28. QVBoxLayout* layout = new QVBoxLayout;
  29. widget.setLayout(layout);
  30. ctkFittedTextBrowser textBrowserWidget(&widget);
  31. textBrowserWidget.setText(
  32. "<pre>"
  33. "This is a short line.\n"
  34. "This is a very very, very very very, very very, very very very, very very, very very very long line\n"
  35. "Some more lines 1."
  36. "Some more lines 2."
  37. "Some more, some more."
  38. "</pre>");
  39. layout->addWidget(&textBrowserWidget);
  40. ctkFittedTextBrowser textBrowserWidgetCollapsibleText(&widget);
  41. textBrowserWidgetCollapsibleText.setCollapsibleText(
  42. "This is the teaser for auto-text.\n More details are here.\n"
  43. "This is a very very, very very very, very very, very very very, very very, very very very long line\n"
  44. "Some more lines 1.\n"
  45. "Some more lines 2.\n"
  46. "Some more, some more.");
  47. textBrowserWidgetCollapsibleText.setShowDetailsText("&gt;&gt;&gt;");
  48. textBrowserWidgetCollapsibleText.setHideDetailsText("&lt;&lt;&lt;");
  49. layout->addWidget(&textBrowserWidgetCollapsibleText);
  50. ctkFittedTextBrowser textBrowserWidgetCollapsibleHtml(&widget);
  51. textBrowserWidgetCollapsibleHtml.setCollapsibleHtml(
  52. "This is the teaser for html.<br>"
  53. "More details are here."
  54. "This is a very very, very very very, very very, very very very, very very, very very very long line\n"
  55. "Some more lines 1."
  56. "Some more lines 2."
  57. "Some more, some more.");
  58. layout->addWidget(&textBrowserWidgetCollapsibleHtml);
  59. ctkFittedTextBrowser textBrowserWidgetCollapsibleComplexHtml(&widget);
  60. textBrowserWidgetCollapsibleComplexHtml.setCollapsibleHtml(
  61. "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"><html>"
  62. "<head><meta name=\"qrichtext\" content=\"1\" /> <style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head>"
  63. "<body style=\" font-family:'MS Shell Dlg 2'; font-size:12.25pt; font-weight:400; font-style:normal;\">"
  64. "<p>This is the teaser for complex html.<br></p>"
  65. "<p>More details are here.</p>"
  66. "<p>This is a very very, very very very, very very, very very very, very very, very very very long line</p>"
  67. "<p>Some more lines 1."
  68. "Some more lines 2."
  69. "Some more, some more.</p>"
  70. "</body></html>");
  71. layout->addWidget(&textBrowserWidgetCollapsibleComplexHtml);
  72. textBrowserWidgetCollapsibleHtml.setCollapsed(false);
  73. QPushButton expandingButton(&widget);
  74. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  75. sizePolicy.setHorizontalStretch(1);
  76. sizePolicy.setVerticalStretch(1);
  77. expandingButton.setSizePolicy(sizePolicy);
  78. layout->addWidget(&expandingButton);
  79. widget.show();
  80. if (argc < 2 || QString(argv[1]) != "-I")
  81. {
  82. QTimer::singleShot(200, &app, SLOT(quit()));
  83. }
  84. return app.exec();
  85. }